/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Consumablestock(); //$allocate = new Allocate; // Uncomment the following line if AJAX validation is needed $this->performAjaxValidation($model); /*Executed when you have data SUBMITTED*/ if (isset($_POST['Consumablestock'])) { $model->attributes = $_POST['Consumablestock']; $model->commodity_id = $_GET['commodity_id']; if (!empty($_FILES['Consumablestock']['tmp_name']['document'])) { $file = CUploadedFile::getInstance($model, 'document'); $model->documentFileName = $file->name; $model->documentFileType = $file->type; $fp = fopen($file->tempName, 'r'); $content = fread($fp, filesize($file->tempName)); fclose($fp); $model->document = $content; } if ($model->save()) { $stocknameRow = Stockname::model()->findByAttributes(array('commodity_id' => $model->commodity_id)); /***********Change dynamically**/ $consumable = Consumable::model()->findByAttributes(array('id' => $model->consumable_id)); for ($i = 1; $i <= $model->quantity; $i++) { $allocate = new Allocate(); $allocate->commodity_id = $model->commodity_id; $allocate->cons_id = $model->consumable_id; $allocate->id = $i; $allocate->stock_id = $model->id; $allocate->date_in = $model->date_in; $allocate->stockname = $stocknameRow['prefix'] . $consumable['name'] . '/' . $allocate->id; $allocate->barcode = Common::getItemBarcode(array("itemId" => $allocate->allocate_id, "barcode" => $allocate->stockname)); $allocate->save(); //print_r($allocate->getErrors());die; } //Yii::app()->request->redirect('http://localhost/asset_management/index.php/consumable/admin'); //Yii::app()->request->redirect('Yii::app()->request->returnUrl'); //Yii::app()->request->return; echo "<script type='text/javascript'>self.history.go(-2);</script>"; } } /*Executed when you want to create*/ $this->render('create', array('model' => $model)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Allocate(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Allocate'])) { $model->attributes = $_POST['Allocate']; $model->commodity_id = $_GET['commodity_id']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->allocate_id)); } } $this->render('create', array('model' => $model)); }