Example #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = ProductUomModel::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         $query->where('1=0');
         return $dataProvider;
     }
     $query->andFilterWhere(['product_id' => $this->product_id, 'uom_id' => $this->uom_id, 'isi' => $this->isi, 'created_at' => $this->created_at, 'created_by' => $this->created_by, 'updated_at' => $this->updated_at, 'updated_by' => $this->updated_by]);
     return $dataProvider;
 }
 /**
  * Creates a new Product model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Product();
     $dPost = Yii::$app->request->post();
     if ($model->load($dPost)) {
         $conn = \Yii::$app->db->beginTransaction();
         try {
             $allSaved = true;
             if (!$model->save()) {
                 $allSaved = false;
             } else {
                 foreach (Yii::$app->request->post('prodUom', []) as $row) {
                     $modelUom = new \backend\models\master\ProductUom();
                     $modelUom->product_id = $model->id;
                     $modelUom->uom_id = $row['id_uom'];
                     $modelUom->isi = $row['isi'];
                     if (!$modelUom->save()) {
                         $allSaved = false;
                     }
                 }
                 foreach (Yii::$app->request->post('prodBcode', []) as $row) {
                     $modelChild = new \backend\models\master\ProductChild();
                     $modelChild->product_id = $model->id;
                     $modelChild->barcode = $row['barcode'];
                     if (!$modelChild->save()) {
                         $allSaved = false;
                     }
                 }
             }
             if ($allSaved) {
                 $conn->commit();
                 return $this->redirect(['view', 'id' => $model->id]);
             }
         } catch (Exception $ex) {
             $conn->rollBack();
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Example #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getProductUom()
 {
     return $this->hasOne(ProductUom::className(), ['product_id' => 'product_id', 'uom_id' => 'uom_id']);
 }
Example #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getProductUoms()
 {
     return $this->hasMany(ProductUom::className(), ['uom_id' => 'id']);
 }
Example #5
0
 /**
  *
  * @param array $options
  * @return Invoice|boolean
  */
 public function createInvoice($options = [])
 {
     if ($this->status == self::STATUS_RELEASED) {
         $oldInvoice = Invoice::findOne(['reff_type' => Invoice::REFF_GOODS_MOVEMENT, 'reff_id' => $this->id, 'status' => Invoice::STATUS_RELEASED]);
         if ($oldInvoice !== null) {
             return false;
         }
         $invoice = new Invoice();
         $invoice->attributes = array_merge(['date' => date('Y-m-d'), 'due_date' => date('Y-m-d', time() + 30 * 24 * 3600)], $options);
         $invoice->reff_type = Invoice::REFF_GOODS_MOVEMENT;
         $invoice->reff_id = $this->id;
         $invoice->vendor_id = $this->vendor_id;
         $invoice->type = $this->type == self::TYPE_RECEIVE ? Invoice::TYPE_INCOMING : Invoice::TYPE_OUTGOING;
         $invoice->status = Invoice::STATUS_RELEASED;
         $items = [];
         /* @var $item GoodsMovementDtl */
         $total = 0;
         foreach ($this->items as $item) {
             $p_id = $item->product_id;
             $pu = ProductUom::findOne(['product_id' => $p_id, 'uom_id' => $item->uom_id]);
             $qty = ($pu ? $pu->isi : 1) * $item->qty;
             $total += $qty * $item->value;
             $items[] = ['item_type' => 10, 'item_id' => $item->product_id, 'qty' => $qty, 'item_value' => $item->value];
         }
         $invoice->value = $total;
         $invoice->items = $items;
         return $invoice;
     }
     return false;
 }
 protected function findProUom($product_id, $uom_id)
 {
     if (($model = ProductUom::findOne(['product_id' => $product_id, 'uom_id' => $uom_id])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }