/**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $array_purchase_order = ['name' => 'PO' . \DB::table('purchase_orders')->max('id'), 'purchase_order_time' => Input::get('sale_datetime'), 'subTotal' => Input::get('subtotal'), 'total' => Input::get('total'), 'partner_id' => Input::get('partner_id')];
     $purchase_order_id = PurchaseOrder::create($array_purchase_order);
     $lines = sizeof(Input::get('sale_order_line_product_id'));
     $products_ids = Input::get('sale_order_line_product_id');
     $products_name_ids = Input::get('sale_order_line_name');
     $products_qty_ids = Input::get('sale_order_line_qty');
     $products_unitPrice_ids = Input::get('sale_order_line_unitPrice');
     $products_subTotal_ids = Input::get('sale_order_line_subtotal');
     for ($i = 0; $i < $lines; $i++) {
         $purchase_line = ['name' => $products_name_ids[$i], 'qty' => $products_qty_ids[$i], 'unitPrice' => $products_unitPrice_ids[$i], 'subTotal' => $products_subTotal_ids[$i], 'purchase_order_id' => $purchase_order_id->id, 'product_id' => $products_ids[$i]];
         PurchaseOrderLine::create($purchase_line);
     }
     return redirect()->route('purchases.index');
 }
Exemplo n.º 2
0
 /**
  * Save 
  */
 public function save($po = null, $data = null)
 {
     DB::transaction(function () use(&$data, &$po) {
         if (is_null($po)) {
             $po = PurchaseOrder::create($data);
         } else {
             $po->fill($data)->save();
         }
         if (!$data['items']) {
             throw new UnprocessableEntityHttpException('Empty line items');
         }
         $po->items()->delete();
         foreach ($data['items'] as $item) {
             $po->items()->create($item);
         }
     });
     return $this->getById($po->id);
 }