Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
0
 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.');
     }
 }