-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
310 additions
and
5 deletions.
There are no files selected for viewing
150 changes: 150 additions & 0 deletions
150
apps/frontend/modules/MaterialMovement/actions/actions.class.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
<?php | ||
|
||
/** | ||
* MaterialMovement actions. | ||
* | ||
* @package xxi | ||
* @subpackage MaterialMovement | ||
* @author Saritskiy Roman | ||
* @version SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $ | ||
*/ | ||
class MaterialMovementActions extends sfActions | ||
{ | ||
public function executeIndex(sfWebRequest $request) | ||
{ | ||
$this->material_movements = Doctrine_Query::create() | ||
->from('MaterialMovement m') | ||
->execute() | ||
; | ||
} | ||
|
||
public function executeNewTransfer(sfWebRequest $request) | ||
{ | ||
$this->warehouse = Doctrine_Core::getTable("Warehouse")->find($request->getParameter("from")); | ||
$this->forward404Unless($this->warehouse); | ||
$this->balance = $this->warehouse->getBalance(); | ||
|
||
if ($request->isMethod("post")) { | ||
$transfer = MaterialMovementTransfer::createFromArray($request->getParameter("Transfer")); | ||
$transfer->save(); | ||
|
||
$movement = MaterialMovement::createFromArray([ | ||
"from_id" => $request->getParameter("from"), | ||
"to_id" => $request->getParameter("to"), | ||
"type" => "transfer", | ||
"transfer_id" => $transfer->getId(), | ||
]); | ||
$movement->save(); | ||
|
||
$list = new Doctrine_Collection("MaterialMovementMaterials"); | ||
foreach ($request->getParameter("materials") as $id => $amount) { | ||
if ($amount > 0) { | ||
$material = &$this->balance[$id]; | ||
while ($amount) { | ||
arsort($material["amounts"]); | ||
array_filter($material["amounts"]); | ||
|
||
list($price, $availableToMove) = [array_keys($material["amounts"])[0], current($material["amounts"])]; | ||
|
||
$moved = $availableToMove >= $amount | ||
? $amount | ||
: $availableToMove | ||
; | ||
|
||
$materialsMovement = MaterialMovementMaterials::createFromArray([ | ||
"movement_id" => $movement->getId(), | ||
"material_id" => $id, | ||
"amount" => $moved, | ||
"price" => $price, | ||
]); | ||
$list->add($materialsMovement); | ||
|
||
$amount -= $moved; | ||
$material["amount"] -= $moved; | ||
$material["amounts"][$price] -= $moved; | ||
} | ||
} | ||
} | ||
$list->save(); | ||
|
||
$this->redirect("warehouse/index"); | ||
} else { | ||
$this->form = new sfForm(); | ||
$this->form->getWidgetSchema() | ||
->offsetSet("to", new sfWidgetFormDoctrineChoice([ | ||
"model" => "Warehouse", | ||
"add_empty" => false, | ||
"query" => Doctrine_Query::create() | ||
->from("Warehouse w") | ||
->addWhere("w.id != ?", $request->getParameter("from")) | ||
->addOrderby("w.name"), | ||
])) | ||
->offsetSet("from", new sfWidgetFormInputHidden()) | ||
; | ||
|
||
$this->form->embedForm("Transfer", new MaterialMovementTransferForm()); | ||
$this->form->getWidgetSchema() | ||
->setLabels([ | ||
"to" => "Склад-получатель", | ||
"Transfer" => "Комментарий к перемещению", | ||
]) | ||
->setDefaults([ | ||
"from" => $request->getParameter("from"), | ||
]) | ||
; | ||
} | ||
} | ||
|
||
public function executeNew(sfWebRequest $request) | ||
{ | ||
$this->form = new MaterialMovementForm(); | ||
} | ||
|
||
public function executeCreate(sfWebRequest $request) | ||
{ | ||
$this->forward404Unless($request->isMethod(sfRequest::POST)); | ||
|
||
$this->form = new MaterialMovementForm(); | ||
|
||
$this->processForm($request, $this->form); | ||
|
||
$this->setTemplate('new'); | ||
} | ||
|
||
public function executeEdit(sfWebRequest $request) | ||
{ | ||
$this->forward404Unless($material_movement = Doctrine_Core::getTable('MaterialMovement')->find(array($request->getParameter('id'))), sprintf('Object material_movement does not exist (%s).', $request->getParameter('id'))); | ||
$this->form = new MaterialMovementForm($material_movement); | ||
} | ||
|
||
public function executeUpdate(sfWebRequest $request) | ||
{ | ||
$this->forward404Unless($request->isMethod(sfRequest::POST) || $request->isMethod(sfRequest::PUT)); | ||
$this->forward404Unless($material_movement = Doctrine_Core::getTable('MaterialMovement')->find(array($request->getParameter('id'))), sprintf('Object material_movement does not exist (%s).', $request->getParameter('id'))); | ||
$this->form = new MaterialMovementForm($material_movement); | ||
|
||
$this->processForm($request, $this->form); | ||
|
||
$this->setTemplate('edit'); | ||
} | ||
|
||
public function executeDelete(sfWebRequest $request) | ||
{ | ||
$request->checkCSRFProtection(); | ||
|
||
$this->forward404Unless($material_movement = Doctrine_Core::getTable('MaterialMovement')->find(array($request->getParameter('id'))), sprintf('Object material_movement does not exist (%s).', $request->getParameter('id'))); | ||
$material_movement->delete(); | ||
|
||
$this->redirect('MaterialMovement/index'); | ||
} | ||
|
||
protected function processForm(sfWebRequest $request, sfForm $form) | ||
{ | ||
$form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName())); | ||
if ($form->isValid()) { | ||
$material_movement = $form->save(); | ||
|
||
$this->redirect('MaterialMovement/edit?id='.$material_movement->getId()); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
apps/frontend/modules/MaterialMovement/templates/_form.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php use_stylesheets_for_form($form) ?> | ||
<?php use_javascripts_for_form($form) ?> | ||
|
||
<form action="<?php echo url_for('MaterialMovement/' | ||
. ($form->getObject()->isNew() ? 'create' : 'update') | ||
. (!$form->getObject()->isNew() ? '?id='.$form->getObject()->getId() : '')) | ||
?>" method="post" <?php $form->isMultipart() and print 'enctype="multipart/form-data" ' ?>> | ||
|
||
<?php echo $form->renderUsing('bootstrap') ?> | ||
|
||
<?php if (!$form->getObject()->isNew()): ?> | ||
<input type="hidden" name="sf_method" value="put" /> | ||
<?php endif ?> | ||
|
||
<div class="form-actions"> | ||
<button type="submit" class="btn btn-primary">Save</button> | ||
<a href="<?php echo url_for('MaterialMovement/index') ?>" class="btn">Back to list</a> | ||
|
||
<?php if (!$form->getObject()->isNew()): ?> | ||
<?php echo link_to('Delete', 'MaterialMovement/delete?id='.$form->getObject()->getId(), array( | ||
'method' => 'delete', | ||
'confirm' => 'Are you sure?', | ||
'class' => 'btn btn-warning pull-right', | ||
)) ?> | ||
<?php endif ?> | ||
</div> | ||
</form> |
7 changes: 7 additions & 0 deletions
7
apps/frontend/modules/MaterialMovement/templates/editSuccess.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php slot('title', 'Edit Material movement') ?> | ||
|
||
<h1 class="page-header"> | ||
Edit Material movement | ||
</h1> | ||
|
||
<?php include_partial('form', array('form' => $form)) ?> |
48 changes: 48 additions & 0 deletions
48
apps/frontend/modules/MaterialMovement/templates/indexSuccess.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php slot('title', 'Material movements List') ?> | ||
|
||
<h1 class="page-header"> | ||
Material movements List | ||
</h1> | ||
|
||
<div class="btn-toolbar"> | ||
<div class="btn-group"> | ||
<a href="<?php echo url_for('MaterialMovement/new') ?>" class="btn btn-primary">New</a> | ||
</div> | ||
</div> | ||
|
||
<table class="table table-condensed table-bordered table-hover"> | ||
<thead> | ||
<tr> | ||
<th>Id</th> | ||
<th>Type</th> | ||
<th>From</th> | ||
<th>To</th> | ||
<th>Transfer</th> | ||
<th>Arrival</th> | ||
<th>Utilization</th> | ||
<th>Writeoff</th> | ||
<th>Created at</th> | ||
<th>Updated at</th> | ||
<th>Created by</th> | ||
<th>Updated by</th> | ||
<th>Deleted at</th> | ||
</tr> | ||
</thead> | ||
<tbody><?php foreach ($material_movements as $material_movement): ?> | ||
<tr> | ||
<td><a href="<?php echo url_for('MaterialMovement/edit?id='.$material_movement->getId()) ?>"><?php echo $material_movement->getId() ?></a></td> | ||
<td><?php echo $material_movement->getType() ?></td> | ||
<td><?php echo $material_movement->getFromId() ?></td> | ||
<td><?php echo $material_movement->getToId() ?></td> | ||
<td><?php echo $material_movement->getTransferId() ?></td> | ||
<td><?php echo $material_movement->getArrivalId() ?></td> | ||
<td><?php echo $material_movement->getUtilizationId() ?></td> | ||
<td><?php echo $material_movement->getWriteoffId() ?></td> | ||
<td><?php echo $material_movement->getCreatedAt() ?></td> | ||
<td><?php echo $material_movement->getUpdatedAt() ?></td> | ||
<td><?php echo $material_movement->getCreatedBy() ?></td> | ||
<td><?php echo $material_movement->getUpdatedBy() ?></td> | ||
<td><?php echo $material_movement->getDeletedAt() ?></td> | ||
</tr> | ||
<?php endforeach; ?></tbody> | ||
</table> |
7 changes: 7 additions & 0 deletions
7
apps/frontend/modules/MaterialMovement/templates/newSuccess.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php slot('title', 'New Material movement') ?> | ||
|
||
<h1 class="page-header"> | ||
New Material movement | ||
</h1> | ||
|
||
<?php include_partial('form', array('form' => $form)) ?> |
38 changes: 38 additions & 0 deletions
38
apps/frontend/modules/MaterialMovement/templates/newTransferSuccess.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<form action="?submit" method="post"> | ||
<?php echo $form->renderUsing("bootstrap"); ?> | ||
|
||
<fieldset> | ||
<legend>Список материалов</legend> | ||
<?php foreach ($balance->getRawValue() as $material): ?> | ||
<div class="control-group"> | ||
<label for="materials[<?php echo $material["id"]; ?>]" class="control-label"><?php echo $material["name"]; ?></label> | ||
<div class="controls"> | ||
<div class="input-append copy-number-inputs-max-to-value"> | ||
<input type="number" value="0" min="0" max="<?php echo $material["amount"]; ?>" step="0.0001" class="span2" name="materials[<?php echo $material["id"]; ?>]" id="materials[<?php echo $material["id"]; ?>]"> | ||
<button class="btn" type="button">Выбрать всё (<?php echo $material["amount"]; ?>)</button> | ||
</div> | ||
</div> | ||
</div> | ||
<?php endforeach ?> | ||
</fieldset> | ||
|
||
<div class="form-actions"> | ||
<button type="submit" class="btn btn-primary">Переместить</button> | ||
</div> | ||
</form> | ||
|
||
<script> | ||
$(function() { | ||
$(".copy-number-inputs-max-to-value .btn").click(function(e) { | ||
e.preventDefault(); | ||
|
||
var $this = $(this) | ||
, input = $this.siblings("input[type=number]") | ||
; | ||
|
||
if (input.length) { | ||
input.val(input.attr("max")); | ||
} | ||
}); | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
include(dirname(__FILE__).'/../../bootstrap/functional.php'); | ||
|
||
$browser = new sfTestFunctional(new sfBrowser()); | ||
|
||
$browser-> | ||
get('/MaterialMovement/index')-> | ||
|
||
with('request')->begin()-> | ||
isParameter('module', 'MaterialMovement')-> | ||
isParameter('action', 'index')-> | ||
end()-> | ||
|
||
with('response')->begin()-> | ||
isStatusCode(200)-> | ||
checkElement('body', '!/This is a temporary page/')-> | ||
end() | ||
; |