Example #1
0
 /**
  * 
  * @param \biz\base\Event $event
  */
 public function purchaseReceiveBody($event)
 {
     /* @var $detail \biz\models\PurchaseDtl */
     $detail = $event->params[1];
     $smallest_uom = Helper::getSmallestProductUom($detail->id_product);
     $this->updatePrice(['id_product' => $detail->id_product, 'id_uom' => $smallest_uom, 'price' => $detail->selling_price, 'app' => 'purchase', 'id_ref' => $detail->id_purchase_dtl]);
 }
Example #2
0
 protected function updateCogs($params)
 {
     $cogs = Cogs::findOne(['id_product' => $params['id_product']]);
     if (!$cogs) {
         $smallest_uom = Helper::getSmallestProductUom($params['id_product']);
         $cogs = new Cogs();
         $cogs->setAttributes(['id_product' => $params['id_product'], 'id_uom' => $smallest_uom, 'cogs' => 0.0]);
     }
     $current_stock = Helper::getCurrentStockAll($params['id_product']);
     $qty_per_uom = Helper::getQtyProductUom($params['id_product'], $params['id_uom']);
     $added_stock = $params['added_stock'] * $qty_per_uom;
     $cogs->cogs = 1.0 * ($cogs->cogs * $current_stock + $params['price'] * $params['added_stock']) / ($current_stock + $added_stock);
     if ($cogs->canSetProperty('logParams')) {
         $cogs->logParams = ['app' => $params['app'], 'id_ref' => $params['id_ref']];
     }
     if (!$cogs->save()) {
         throw new UserException(implode(",\n", $cogs->firstErrors));
     }
     return true;
 }
Example #3
0
 /**
  * 
  * @param array $params
  * Required field id_warehouse, id_product, id_uom, qty
  * Optional field app, id_ref
  * @return boolean
  * @throws UserException
  */
 public function updateStock($params)
 {
     $stock = ProductStock::findOne(['id_warehouse' => $params['id_warehouse'], 'id_product' => $params['id_product']]);
     $qty_per_uom = Helper::getQtyProductUom($params['id_product'], $params['id_uom']);
     if (!$stock) {
         $smallest_uom = Helper::getSmallestProductUom($params['id_product']);
         $stock = new ProductStock();
         $stock->setAttributes(['id_warehouse' => $params['id_warehouse'], 'id_product' => $params['id_product'], 'id_uom' => $smallest_uom, 'qty_stock' => 0]);
     }
     $stock->qty_stock = $stock->qty_stock + $params['qty'] * $qty_per_uom;
     if ($stock->canSetProperty('logParams')) {
         $logParams = ['mv_qty' => $params['qty'] * $qty_per_uom];
         foreach (['app', 'id_ref'] as $key) {
             if (isset($params[$key]) || array_key_exists($key, $params)) {
                 $logParams[$key] = $params[$key];
             }
         }
         $stock->logParams = $logParams;
     }
     if (!$stock->save()) {
         throw new UserException(implode(",\n", $stock->firstErrors));
     }
     return true;
 }
Example #4
0
 public function purchaseReceiveBody($event, $model, $detail)
 {
     $smallest_uom = Helper::getSmallestProductUom($detail->id_product);
     $this->updatePrice(['id_product' => $detail->id_product, 'id_uom' => $smallest_uom, 'price' => $detail->selling_price, 'app' => 'purchase', 'id_ref' => $detail->id_purchase_dtl]);
 }