Skip to content

Commit

Permalink
my warehouses page initiated
Browse files Browse the repository at this point in the history
  • Loading branch information
b1rdex committed Apr 8, 2014
1 parent f856d7b commit 004de05
Show file tree
Hide file tree
Showing 9 changed files with 181 additions and 49 deletions.
32 changes: 29 additions & 3 deletions apps/frontend/modules/warehouse/actions/actions.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,39 @@
*/
class warehouseActions extends sfActions
{
public function preExecute()
{
$this->id = $this->getRequest()->getParameter("id");
}

public function postExecute()
{
if (!$this->id and isset($this->form)) {
$this->id = $this->form->getObject()->getId();
}
}

public function executeIndex(sfWebRequest $request)
{
$this->warehouses = Doctrine_Query::create()
->from("Warehouse w")
->addOrderBy("w.name")
$this->warehouses = WarehouseTable::getOwnWarehousesQuery()
->andWhereIn("w.id", $this->id ? [$this->id] : [])
->execute()
;

$this->filter = new sfForm();
$this->filter->getWidgetSchema()
->offsetSet("id", new sfWidgetFormDoctrineChoice([
"model" => "Warehouse",
"add_empty" => true,
"query" => WarehouseTable::getOwnWarehousesQuery(),
], [
"class" => "chzn-select",
"data-placeholder" => "Выберите склад",
]))
;
$this->filter->setDefaults([
"id" => $this->id,
]);
}

public function executeNew(sfWebRequest $request)
Expand Down
2 changes: 1 addition & 1 deletion apps/frontend/modules/warehouse/templates/_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<div class="form-actions">
<button type="submit" class="btn btn-primary">Сохранить</button>
<a href="<?php echo url_for('warehouse/index') ?>" class="btn">Назад к списку</a>
<a href="<?php echo url_for('warehouse/index?id=' . $form->getObject()->getId()) ?>" class="btn">Назад к списку</a>

<?php if (!$form->getObject()->isNew()): ?>
<?php echo link_to('Удалить', 'warehouse/delete?id='.$form->getObject()->getId(), array(
Expand Down
74 changes: 55 additions & 19 deletions apps/frontend/modules/warehouse/templates/indexSuccess.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,60 @@
<h1 class="page-header">
Склады
<?php if ($sf_user->hasCredential("can edit warehouses")): ?>
<small>
<a href="<?php echo url_for('warehouse/new') ?>" class="btn btn-primary">Добавить склад</a>
</small>
<?php endif ?>
</h1>

<div class="btn-toolbar">
<div class="btn-group">
<a href="<?php echo url_for('warehouse/new') ?>" class="btn btn-primary">Добавить</a>
</div>
</div>
<form action="?filter" method="get" class="well well-small submit-on-select-change">
<span>Фильтр по наименованию:</span>
<?php echo $filter["id"] ?>
</form>

<table class="table table-condensed table-bordered table-hover">
<thead>
<tr>
<th>Id</th>
<th>Наименование</th>
</tr>
</thead>
<tbody><?php foreach ($warehouses as $warehouse): ?>
<tr>
<td><a href="<?php echo url_for('warehouse/edit?id='.$warehouse->getId()) ?>"><?php echo $warehouse->getId() ?></a></td>
<td><?php echo $warehouse->getName() ?></td>
</tr>
<?php endforeach; ?></tbody>
</table>
<h2>Остатки</h2>

<?php if ($warehouses and count($warehouses)): ?>
<?php foreach ($warehouses as $warehouse): ?>
<h3>
<?php echo $warehouse ?>
<?php if ($sf_user->hasCredential("can edit warehouses")): ?>
<small>
<a href="<?php echo url_for('warehouse/edit?id='.$warehouse->getId()) ?>">Редактировать</a>
</small>
<?php endif ?>
</h3>
<?php
$balance = $warehouse->getBalance();
if (count($balance)):
?>
<table class="table table-hover table-bordered">
<thead>
<tr>
<th>Материал</th>
<th>Остаток</th>
<?php if ($sf_user->hasCredential("can view material costs")): ?>
<th>Цена => остаток</th>
<?php endif ?>
</tr>
</thead>
<tbody><?php foreach ($balance as $material): ?>
<tr>
<td><?php echo $material["name"]; ?></td>
<td><?php echo $material["amount"]; ?></td>
<?php if ($sf_user->hasCredential("can view material costs")): ?>
<td><pre><?php echo str_replace(["Array\n(\n", " ", ")\n"], "", print_r($material["amounts"]->getRawValue(), 1)); ?></pre></td>
<?php endif ?>
</tr>
<?php endforeach ?></tbody>
</table>
<?php else: ?>
<div class="alert alert-info">Нет материалов</div>
<?php endif ?>


<?php endforeach ?>

<?php else: ?>
<div class="alert alert-info">Нет складов</div>
<?php endif ?>
12 changes: 6 additions & 6 deletions apps/frontend/templates/_topnav.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@
"isActive" => $sf_context->getModuleName() == "arrival",
"href" => url_for("arrival/index"),
],

"Склады" => [
"credentials" => $sf_user->hasCredential("can edit warehouses"),
"isActive" => $sf_context->getModuleName() == "warehouse",
"href" => url_for("warehouse/index"),
],
],

"Справочники" => [
Expand Down Expand Up @@ -75,6 +69,12 @@
"isActive" => $sf_context->getModuleName() == "plan",
"href" => url_for("plan/index"),
],

"Мои склады" => [
"credentials" => count($sf_user->getGuardUser()->getWarehouses()),
"isActive" => $sf_context->getModuleName() == "warehouse",
"href" => url_for("warehouse/index"),
],
];
?>

Expand Down
8 changes: 8 additions & 0 deletions lib/form/doctrine/MaterialMovementForm.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,13 @@ public function configure()
, $this['created_by']
, $this['updated_by']
);

$this->embedRelations([
"Materials" => [
"considerNewFormEmptyFields" => ["amount", "price"],
"multipleNewForms" => true,
"newFormsInitialCount" => 1,
],
]);
}
}
44 changes: 42 additions & 2 deletions lib/model/doctrine/Warehouse.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,54 @@

/**
* Warehouse
*
*
* This class has been auto-generated by the Doctrine ORM Framework
*
*
* @package xxi
* @subpackage model
* @author Saritskiy Roman
* @version SVN: $Id: Builder.php 7490 2010-03-29 19:53:27Z jwage $
*/
class Warehouse extends BaseWarehouse
{
public function getBalance()
{
$materials = Doctrine_Query::create()
->from("Material m")
->leftJoin("m.Dimension d")
->innerJoin("m.MaterialMovementMaterials lists")
->innerJoin("lists.Movement move")
->addWhere("move.to_id = ? or move.from_id = ?", [$this->getId(), $this->getId()])
->addOrderBy("m.name")
->execute()
;

$balance = [];
foreach ($materials as $material) {
if (!isset($balance[$material->getId()])) {
$balance[$material->getId()] = [
"id" => $material->getId(),
"name" => $material->getNameWithDimension(),
"amount" => 0,
"amounts" => [],
];
}

foreach ($material->getMaterialMovementMaterials() as $row) {
if (!isset($balance[$material->getId()]["amounts"][$row->getPrice()])) {
$balance[$material->getId()]["amounts"][$row->getPrice()] = 0;
}

if ($row->getMovement()->getToId() === $this->getId()) { // in
$balance[$material->getId()]["amount"] += $row["amount"];
$balance[$material->getId()]["amounts"][$row->getPrice()] += $row["amount"];
} else { // out
$balance[$material->getId()]["amount"] -= $row["amount"];
$balance[$material->getId()]["amounts"][$row->getPrice()] -= $row["amount"];
}
}
}

return $balance;
}
}
34 changes: 23 additions & 11 deletions lib/model/doctrine/WarehouseTable.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,30 @@

/**
* WarehouseTable
*
*
* This class has been auto-generated by the Doctrine ORM Framework
*/
class WarehouseTable extends Doctrine_Table
{
/**
* Returns an instance of this class.
*
* @return object WarehouseTable
*/
public static function getInstance()
{
return Doctrine_Core::getTable('Warehouse');
}
}
/**
* Returns an instance of this class.
*
* @return object WarehouseTable
*/
public static function getInstance()
{
return Doctrine_Core::getTable('Warehouse');
}

public static function getOwnWarehousesQuery()
{
$user = sfContext::getInstance()->getUser();

return Doctrine_Query::create()
->from("Warehouse w")
->leftJoin("w.Users u")
->andWhereIn("u.id", $user->hasCredential("can edit warehouses") ? [] : [$user->getGuardUser()->getId()])
->addOrderBy("w.name")
;
}
}
13 changes: 7 additions & 6 deletions web/css/chosen.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
display: inline-block;
zoom: 1;
*display: inline;
vertical-align: middle;
}
.chzn-container .chzn-drop {
background: #fff;
Expand All @@ -23,12 +24,12 @@
/* @group Single Chosen */
.chzn-container-single .chzn-single {
background-color: #ffffff;
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#eeeeee', GradientType=0 );
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#eeeeee', GradientType=0 );
background-image: -webkit-gradient(linear, 0 0, 0 100%, color-stop(20%, #ffffff), color-stop(50%, #f6f6f6), color-stop(52%, #eeeeee), color-stop(100%, #f4f4f4));
background-image: -webkit-linear-gradient(top, #ffffff 20%, #f6f6f6 50%, #eeeeee 52%, #f4f4f4 100%);
background-image: -moz-linear-gradient(top, #ffffff 20%, #f6f6f6 50%, #eeeeee 52%, #f4f4f4 100%);
background-image: -o-linear-gradient(top, #ffffff 20%, #f6f6f6 50%, #eeeeee 52%, #f4f4f4 100%);
background-image: linear-gradient(#ffffff 20%, #f6f6f6 50%, #eeeeee 52%, #f4f4f4 100%);
background-image: linear-gradient(#ffffff 20%, #f6f6f6 50%, #eeeeee 52%, #f4f4f4 100%);
-webkit-border-radius: 5px;
-moz-border-radius : 5px;
border-radius : 5px;
Expand Down Expand Up @@ -178,12 +179,12 @@
-webkit-background-clip: padding-box;
background-clip : padding-box;
background-color: #e4e4e4;
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f4f4f4', endColorstr='#eeeeee', GradientType=0 );
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f4f4f4', endColorstr='#eeeeee', GradientType=0 );
background-image: -webkit-gradient(linear, 0 0, 0 100%, color-stop(20%, #f4f4f4), color-stop(50%, #f0f0f0), color-stop(52%, #e8e8e8), color-stop(100%, #eeeeee));
background-image: -webkit-linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%);
background-image: -moz-linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%);
background-image: -o-linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%);
background-image: linear-gradient(#f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%);
background-image: linear-gradient(#f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%);
-webkit-box-shadow: 0 0 2px #ffffff inset, 0 1px 0 rgba(0,0,0,0.05);
-moz-box-shadow : 0 0 2px #ffffff inset, 0 1px 0 rgba(0,0,0,0.05);
box-shadow : 0 0 2px #ffffff inset, 0 1px 0 rgba(0,0,0,0.05);
Expand Down Expand Up @@ -256,7 +257,7 @@
}
.chzn-container .chzn-results .highlighted {
background-color: #3875d7;
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#3875d7', endColorstr='#2a62bc', GradientType=0 );
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#3875d7', endColorstr='#2a62bc', GradientType=0 );
background-image: -webkit-gradient(linear, 0 0, 0 100%, color-stop(20%, #3875d7), color-stop(90%, #2a62bc));
background-image: -webkit-linear-gradient(top, #3875d7 20%, #2a62bc 90%);
background-image: -moz-linear-gradient(top, #3875d7 20%, #2a62bc 90%);
Expand Down Expand Up @@ -387,7 +388,7 @@
.chzn-rtl .chzn-search input {
background: #fff url('chosen-sprite.png') no-repeat -38px -22px;
background: url('chosen-sprite.png') no-repeat -38px -22px, -webkit-gradient(linear, 0 0, 0 100%, color-stop(1%, #eeeeee), color-stop(15%, #ffffff));
background: url('chosen-sprite.png') no-repeat -38px -22px, -webkit-linear-gradient(top, #eeeeee 1%, #ffffff 15%);
background: url('chosen-sprite.png') no-repeat -38px -22px, -webkit-linear-gradient(top, #eeeeee 1%, #ffffff 15%);
background: url('chosen-sprite.png') no-repeat -38px -22px, -moz-linear-gradient(top, #eeeeee 1%, #ffffff 15%);
background: url('chosen-sprite.png') no-repeat -38px -22px, -o-linear-gradient(top, #eeeeee 1%, #ffffff 15%);
background: url('chosen-sprite.png') no-repeat -38px -22px, linear-gradient(#eeeeee 1%, #ffffff 15%);
Expand Down
11 changes: 10 additions & 1 deletion web/js/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
$(function() {
$(".submit-on-select-change")
.find("select").eq(0)
.change(function() {
$(this).parents("form").submit();
})
;

$('.rows-clickable tbody')
.find('tr')
.each(function() {
Expand Down Expand Up @@ -37,7 +44,9 @@ $(function() {
.append('<span id="discount" style="padding-left: 10px">Скидка: ' + ($element.data('discount')||0) + '%</span>')
})

$(".chzn-select").chosen()
$(".chzn-select").chosen({
allow_single_deselect: true
})

$('.toggler')
.click(function() {
Expand Down

0 comments on commit 004de05

Please sign in to comment.