/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $model = $this->loadModel($id); //$actual_quantity=$model->current_quantity; // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Items'])) { $model->attributes = $_POST['Items']; //echo "DUE ADTE ".$model->factory_due_date; if ($model->save()) { $original_quantity = $_POST['original_quantity']; $original_available_quantity = $_POST['original_available_quantity']; //echo "Actual ".$original_quantity; //echo "Current ".$model->current_quantity; if ($original_quantity == $model->current_quantity && $original_available_quantity == $model->available_quantity) { //echo "value is same"; $this->redirect(array('view', 'id' => $model->item_id)); } elseif ($original_quantity > $model->current_quantity && $original_available_quantity == $model->available_quantity) { //echo "ORIGINAL QUANTITY WAS MORE, ITEM REMOVED"; $OutModel = new OutboundItemsHistory(); $OutModel->main_item_id = $model->item_id; $OutModel->quantity_moved = $original_quantity - $model->current_quantity; //current_quantity is already having quantity_moved value also,so it is not subtracted here as it will be subtracted again in beforeSave() func. $OutModel->current_quantity_in_stock = $model->current_quantity + $OutModel->quantity_moved; $OutModel->available_quantity_in_stock = $model->current_quantity + $OutModel->quantity_moved; //$OutModel->quantity_moved=$original_quantity-$model->current_quantity; if ($OutModel->save()) { $this->redirect(array('view', 'id' => $model->item_id)); //echo "SAVED"; } else { echo $OutModel->getError(); } //$this->redirect(array('view','id'=>$model->item_id)); } elseif ($original_quantity < $model->current_quantity && $original_available_quantity == $model->available_quantity) { //echo "ORIGINAL QUANTITY WAS LESS, ITEM ADDED"; $InModel = new InboundItemsHistory(); $InModel->main_item_id = $model->item_id; $InModel->quantity_moved = $model->current_quantity - $original_quantity; //current_quantity is already having quantity_moved value also,so it is not added here as it will be added again in beforeSave() func. $InModel->current_quantity_in_stock = $model->current_quantity - $InModel->quantity_moved; $InModel->available_quantity_in_stock = $model->current_quantity - $InModel->quantity_moved; //$original_available_quantity=$original_available_quantity+ //$InModel->quantity_moved=0; //$InModel->quantity_moved=$model->current_quantity-$original_quantity; if ($InModel->save()) { //$model->available_quantity=$model->current_quantity; $this->redirect(array('view', 'id' => $model->item_id)); //echo "SAVED"; } else { echo $InModel->getError(); } //$this->redirect(array('view','id'=>$model->item_id)); } elseif ($original_quantity == $model->current_quantity && $original_available_quantity > $model->available_quantity) { //echo "ORIGINAL AVAILABLE QUANTITY WAS MORE, ITEM REMOVED"; $OutModel = new OutboundItemsHistory(); $OutModel->main_item_id = $model->item_id; $OutModel->quantity_moved = $original_available_quantity - $model->available_quantity; //current_quantity is already having quantity_moved value also,so it is not subtracted here as it will be subtracted again in beforeSave() func. $OutModel->current_quantity_in_stock = $model->current_quantity + $OutModel->quantity_moved; $OutModel->available_quantity_in_stock = $model->current_quantity + $OutModel->quantity_moved; //$OutModel->quantity_moved=$original_quantity-$model->current_quantity; if ($OutModel->save()) { $this->redirect(array('view', 'id' => $model->item_id)); //echo "SAVED"; } else { echo $OutModel->getError(); } //$this->redirect(array('view','id'=>$model->item_id)); } elseif ($original_quantity == $model->current_quantity && $original_available_quantity < $model->available_quantity) { //echo "ORIGINAL QUANTITY WAS LESS, ITEM ADDED"; $InModel = new InboundItemsHistory(); $InModel->main_item_id = $model->item_id; $InModel->quantity_moved = $model->available_quantity - $original_available_quantity; //current_quantity is already having quantity_moved value also,so it is not added here as it will be added again in beforeSave() func. $InModel->current_quantity_in_stock = $model->current_quantity - $InModel->quantity_moved; $InModel->available_quantity_in_stock = $model->current_quantity - $InModel->quantity_moved; //$original_available_quantity=$original_available_quantity+ //$InModel->quantity_moved=0; //$InModel->quantity_moved=$model->current_quantity-$original_quantity; if ($InModel->save()) { //$model->available_quantity=$model->current_quantity; $this->redirect(array('view', 'id' => $model->item_id)); //echo "SAVED"; } else { echo $InModel->getError(); } //$this->redirect(array('view','id'=>$model->item_id)); } //end of 4th elseif } //end of if(model->save()) } //if(isset($_POST['Items'])) $this->render('update', array('model' => $model)); }