コード例 #1
0
 private function saveInSaleItemTable($idArticle, $amount, $idSale)
 {
     try {
         $saleItemsTable = new SaleItem();
         $saleItemsTable->sale_id = $idSale;
         $saleItemsTable->article_id = $idArticle;
         $saleItemsTable->amount = $amount;
         $saleItemsTable->save();
     } catch (Exception $e) {
         die($e . 'No se pudo guardar el articulo ' . $idArticle . ' como item de la venta.');
     }
 }
コード例 #2
0
ファイル: Sale.php プロジェクト: soklux/bakou-pos-apsara
 protected function saveSaleItem($items, $sale_id, $employee_id)
 {
     // Saving sale item to sale_item table
     foreach ($items as $line => $item) {
         $cur_item_info = Item::model()->findbyPk($item['item_id']);
         $qty_in_stock = $cur_item_info->quantity;
         if (substr($item['discount'], 0, 1) == '$') {
             $discount_amount = substr($item['discount'], 1);
             $discount_type = '$';
         } else {
             $discount_amount = $item['discount'];
             $discount_type = '%';
         }
         $sale_item = new SaleItem();
         $sale_item->sale_id = $sale_id;
         $sale_item->item_id = $item['item_id'];
         $sale_item->currency_code = $item['currency_code'];
         $sale_item->line = $line;
         $sale_item->quantity = $item['quantity'];
         $sale_item->cost_price = $cur_item_info->cost_price;
         $sale_item->unit_price = $cur_item_info->unit_price;
         $sale_item->price = $item['price'];
         // The exact selling price
         $sale_item->discount_amount = $discount_amount == null ? 0 : $discount_amount;
         $sale_item->discount_type = $discount_type;
         $sale_item->save();
         $qty_afer_transaction = $qty_in_stock - $item['quantity'];
         //Updating stock quantity
         $cur_item_info->quantity = $qty_afer_transaction;
         $cur_item_info->save();
         //Ramel Inventory Tracking
         $inventory = new Inventory();
         $qty_buy = -$item['quantity'];
         $sale_remarks = 'POS ' . $sale_id;
         $inventory->trans_items = $item['item_id'];
         $inventory->trans_user = $employee_id;
         $inventory->trans_comment = $sale_remarks;
         $inventory->trans_inventory = $qty_buy;
         $inventory->trans_qty = $item['quantity'];
         $inventory->qty_b4_trans = $qty_in_stock;
         // for tracking purpose recording the qty before operation effected
         $inventory->qty_af_trans = $qty_afer_transaction;
         $inventory->trans_date = date('Y-m-d H:i:s');
         $inventory->save();
         //Update quantity in expiry table
         //$this->updateStockExpire($item['item_id'], $item['quantity'], $sale_id);
     }
 }