Exemplo n.º 1
0
 /**
  * Creates a new GoodsMovement model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate($type = null)
 {
     $model = new GoodsMovement();
     $model->type = $type;
     $model->description = $type == GoodsMovement::TYPE_RECEIVE ? 'Penerimaan Pembelian' : 'Pengeluaran Manual';
     $model->date = date('Y-m-d');
     if ($model->load(Yii::$app->request->post())) {
         $model->status = GoodsMovement::STATUS_DRAFT;
         $transaction = Yii::$app->db->beginTransaction();
         try {
             $model->items = Yii::$app->request->post('GoodsMovementDtl', []);
             if ($model->save()) {
                 $transaction->commit();
                 return $this->redirect(['view', 'id' => $model->id]);
             }
         } catch (\Exception $exc) {
             $transaction->rollBack();
             throw $exc;
         }
         $transaction->rollBack();
     }
     return $this->render('create', ['model' => $model]);
 }
Exemplo n.º 2
0
 public function adjustStock()
 {
     $gm = new GoodsMovement(['warehouse_id' => $this->warehouse_id, 'type' => GoodsMovement::TYPE_RECEIVE, 'date' => date('Y-m-d'), 'reff_type' => self::REFF_SELF, 'reff_id' => $this->id, 'description' => 'stock opname adjustment', 'status' => GoodsMovement::STATUS_RELEASED]);
     //$gm->items->scenario = GoodsMovementDtl::SCENARIO_ADJUSTMENT;
     $query = (new \yii\db\Query())->select(['p.id', 'selisih' => 'COALESCE(o.qty,0)-COALESCE(s.qty,0)'])->from(['p' => '{{%product}}'])->innerJoin(['s' => '{{%product_stock}}'], '[[s.product_id]]=[[p.id]] and [[s.warehouse_id]]=:whse', [':whse' => $this->warehouse_id])->leftJoin(['o' => '{{%stock_opname_dtl}}'], '[[o.product_id]]=[[p.id]] and [[o.opname_id]]=:opid', [':opid' => $this->id])->where('COALESCE(o.qty,0)<>COALESCE(s.qty,0)');
     $items = [];
     foreach ($query->all() as $row) {
         $items[] = ['product_id' => $row['id'], 'qty' => $row['selisih'], 'uom_id' => 1];
     }
     $gm->items = $items;
     if ($gm->save()) {
         return true;
     }
     print_r($gm->firstErrors);
     return false;
 }
Exemplo n.º 3
0
 public function actionCreateReceipt($type, $id, $desc = null)
 {
     $model = new GoodsMovement(['reff_type' => $type, 'reff_id' => $id, 'description' => $desc]);
     if (($reff = $model->updateFromReceipt()) !== false) {
         list($reffModel, $reff) = $reff;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
     if ($type == GoodsMovement::REFF_TRANSFER) {
         $model->vendor_id = 12;
         $model->vendor_name = 'Internal';
     }
     $model->date = date('Y-m-d');
     $model->type = GoodsMovement::TYPE_RECEIVE;
     if ($model->load(Yii::$app->request->post())) {
         $model->status = GoodsMovement::STATUS_DRAFT;
         $transaction = Yii::$app->db->beginTransaction();
         try {
             $model->items = Yii::$app->request->post('GoodsMovementDtl', []);
             if ($model->save()) {
                 $transaction->commit();
                 return $this->redirect(['view', 'id' => $model->id]);
             }
         } catch (\Exception $exc) {
             $transaction->rollBack();
             throw $exc;
         }
         $transaction->rollBack();
     }
     return $this->render('create', ['model' => $model, 'reffModel' => $reffModel, 'reff' => $reff]);
 }