Esempio n. 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]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id_product' => $this->id_product, 'id_uom' => $this->id_uom, 'isi' => $this->isi, 'create_at' => $this->create_at, 'create_by' => $this->create_by, 'update_at' => $this->update_at, 'update_by' => $this->update_by]);
     return $dataProvider;
 }
Esempio n. 2
0
 public function convertReceive($attribute)
 {
     if ($this->id_uom_receive === null || $this->id_uom == $this->id_uom_receive) {
         $this->purch_qty_receive += $this->qty_receive;
     } else {
         $uoms = ProductUom::find()->where(['id_product' => $this->id_product])->indexBy('id_uom')->all();
         $this->purch_qty_receive += $this->qty_receive * $uoms[$this->id_uom_receive]->isi / $uoms[$this->id_uom]->isi;
     }
     if ($this->purch_qty_receive > $this->purch_qty) {
         $this->addError($attribute, 'Total qty receive large than purch qty');
     }
 }
Esempio n. 3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getProductUoms()
 {
     return $this->hasMany(ProductUom::className(), ['id_uom' => 'id_uom']);
 }
 public function actionDeleteUom($id_product, $id_uom)
 {
     $puom = ProductUom::findOne(['id_product' => $id_product, 'id_uom' => $id_uom]);
     $puom->delete();
     Yii::$app->session->setFlash('_flash_action', 'uom');
     return $this->redirect(['view', 'id' => $id_product]);
 }
Esempio n. 5
0
 /**
  * @return integer
  */
 public static function getQtyProductUom($id_product, $id_uom)
 {
     $pu = ProductUom::findOne(['id_product' => $id_product, 'id_uom' => $id_uom]);
     return $pu ? $pu->isi : false;
 }
 /**
  * Finds the ProductUom model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param  integer               $id_product
  * @param  integer               $id_uom
  * @return ProductUom            the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id_product, $id_uom)
 {
     if (($model = ProductUom::findOne(['id_product' => $id_product, 'id_uom' => $id_uom])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Esempio n. 7
0
 public function convertQtyReceive($attribute)
 {
     if ($this->id_uom_receive === null || $this->id_uom == $this->id_uom_receive) {
         $qty = $this->qty_receive;
     } else {
         $uoms = ProductUom::find()->where(['id_product' => $this->id_product])->indexBy('id_uom')->all();
         $qty = $this->qty_receive * $uoms[$this->id_uom_send]->isi / $uoms[$this->id_uom]->isi;
     }
     $this->transfer_qty_receive += $qty;
 }
 /**
  *
  * @param Event $event
  */
 public function adjustmentApplied($event)
 {
     /* @var $model StockAdjustment */
     $model = $event->params[0];
     $data = ['movement_type' => MStockMovement::TYPE_ADJUSTMENT, 'id_reff' => $model->id_adjustment];
     $data['details'] = [];
     $query_isi = ProductUom::find()->select('isi');
     foreach ($model->stockAdjustmentDtls as $detail) {
         $isi = $query_isi->where(['id_product' => $detail->id_product, 'id_uom' => $detail->id_uom])->scalar();
         $data['details'][] = ['id_warehouse' => $model->id_warehouse, 'id_product' => $detail->id_product, 'movement_qty' => $detail->qty * $isi, 'item_value' => $detail->item_value];
     }
     $this->createMovementDoc($data);
 }
 /**
  * 
  * @param StockOpname $opname
  * @param MStockAdjustment $model
  * @return mixed
  * @throws \Exception
  */
 public static function createFromOpname($opname, $model = null)
 {
     // info product
     $currentStocks = ProductStock::find()->select(['id_product', 'qty_stock'])->where(['id_warehouse' => $opname->id_warehouse])->indexBy('id_product')->asArray()->all();
     $isiProductUoms = [];
     foreach (ProductUom::find()->asArray()->all() as $row) {
         $isiProductUoms[$row['id_product']][$row['id_uom']] = $row['isi'];
     }
     // ***
     $data = ['id_warehouse' => $opname->id_warehouse, 'adjustment_date' => date('Y-m-d'), 'id_reff' => $opname->id_opname, 'description' => "Stock adjustment from stock opname no \"{$opname->opname_num}\"."];
     $details = [];
     foreach ($opname->stockOpnameDtls as $detail) {
         $cQty = $currentStocks[$detail->id_product] / $isiProductUoms[$detail->id_product][$detail->id_uom];
         $details[] = ['id_product' => $detail->id_product, 'id_uom' => $detail->id_uom, 'qty' => $detail->qty - $cQty];
     }
     $data['details'] = $details;
     return static::create($data, $model);
 }