/** * Store a newly created order in storage. * * @return Response */ public function store() { $validation = array('customer' => 'required', 'date' => 'required'); $validator = Validator::make(Input::all(), $validation); if ($validator->fails()) { return Redirect::to('orders/create')->withErrors($validator); } else { $postorder = Input::all(); $data = array('customer' => $postorder['customer'], 'date' => $postorder['date'], 'total_amount' => $postorder['total_amount'], 'discount' => $postorder['discount'], 'payable_amount' => $postorder['payable_amount'], 'payment' => $postorder['payment'], 'balance' => $postorder['balance']); $id = DB::table('orders')->insertGetId($data); for ($i = 0; $i < count($postorder['product_id']); $i++) { $data_detail = array('product_id' => $postorder['product_id'][$i], 'item' => $postorder['item'][$i], 'quantity' => $postorder['quantity'][$i], 'price' => $postorder['price'][$i], 'amount_charged' => $postorder['amount_charged'][$i], 'Order_id' => $id); DB::table('order_details')->insert($data_detail); $date = $postorder['date']; $location = Location::findOrFail($postorder['location']); foreach ($data_detail as $item) { $it = Item::findOrFail($postorder['item'][$i]); $quantity = $postorder['quantity'][$i]; Stock::removeStock($it, $location, $quantity, $date); } } return Redirect::route('orders.index')->with('success', 'Item Successfully Added'); } }
$order->type = 'sales'; $order->save(); foreach ($erporderitems as $item) { $itm = Item::findOrFail($item['itemid']); $ord = Erporder::findOrFail($order->id); $location_id = $item['location']; $location = Location::find($location_id); $date = date('Y-m-d', strtotime(array_get($erporder, 'date'))); $orderitem = new Erporderitem(); $orderitem->erporder()->associate($ord); $orderitem->item()->associate($itm); $orderitem->price = $item['price']; $orderitem->quantity = $item['quantity']; $orderitem->duration = $item['duration']; $orderitem->save(); Stock::removeStock($itm, $location, $item['quantity'], $date); } $tax = Input::get('tax'); $rate = Input::get('rate'); for ($i = 0; $i < count($rate); $i++) { $txOrder = new TaxOrder(); $txOrder->tax_id = $rate[$i]; $txOrder->order_number = array_get($erporder, 'order_number'); $txOrder->amount = $tax[$i]; $txOrder->save(); } //Session::flush('orderitems'); //Session::flush('erporder'); return Redirect::to('salesorders')->withFlashMessage('Order Successfully Placed!'); }); Route::get('erppurchase/commit', function () {