Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function actionCreate() {
- $model = new StockTransfer;
- $details = array();
- if (Yii::app()->user->branch_id != Branch::ROOT_BRANCH) {
- $model->source_branch_id = Yii::app()->user->branch_id;
- }
- if (!Yii::app()->user->checkAccess('create.any.stocktransfer')){
- $model->source_keeper_id = Yii::app()->user->id;
- }
- if (isset($_POST['StockTransfer'])) {
- $model->attributes = $_POST['StockTransfer'];
- $valid = $model->validate();
- if (isset($_POST['StockTransferDetail'])) {
- $details = array();
- foreach ($_POST['StockTransferDetail'] as $key => $stockTransferDetail) {
- $details[$key] = new StockTransferDetail('batchSave'); // so that item_header_id will not be required
- $details[$key]->attributes = $stockTransferDetail;
- $details[$key]->stockTransfer = $model;
- $valid = $details[$key]->validate() && $valid;
- $details[$key]->stockTransfer = null;
- }
- }
- if ($valid) {
- $model->save();
- $model->refresh();
- foreach ($details as $detail) {
- $detail->stockTransfer = $model;
- $detail->save(false);
- }
- $model->refresh();
- $model->markStocksForTransferring(); // will update the item_details
- $this->checkStockLevels($model->item_header_ids);
- $this->redirect(array('view', 'id' => $model->id));
- }
- }
- $this->render('create', array(
- 'model' => $model,
- 'details' => $details
- ));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement