/** * Store a newly created resource in storage. * * @return Response */ public function store(Request $request) { $dateCusId = DB::select('select * from orders where cast(created_at as DATE) = ? and CustomerId = ?', array($request['Date'], $request['CustomerId'])); $customers = Customers::where('id', '=', $request->CustomerId)->get(); foreach ($request['quantity'] as $key => $tee) { $products = Products::where('id', '=', $key)->get(); $count = DB::select('select count(*) as a from orders where cast(created_at As Date) = ? and CustomerId = ? and ProductId = ?', array($request['Date'], $request['CustomerId'], $key)); if ($count[0]->a == 0) { $InsertDb = DB::table('orders')->insert(array('ProductName' => $products[0]->Name, 'ProductId' => $key, 'CustomerId' => $request->CustomerId, 'CustomerName' => $customers[0]->name, 'quantity' => $tee, 'Alish' => $products[0]->Alish, 'AlishCem' => $tee * $products[0]->Alish, 'Satish' => $products[0]->Satish, 'SatishCem' => $tee * $products[0]->Satish, 'Income' => $products[0]->Income, 'IncomeCem' => $tee * ($products[0]->Satish - $products[0]->Alish), 'created_at' => $request['Date'], 'updated_at' => $request['Date'])); } else { $selectOld = Orders::where('ProductId', $key)->where('CustomerId', $request->CustomerId)->where('created_at', $request['Date'])->get(); DB::table('orders')->where('ProductId', $key)->where('CustomerId', $request->CustomerId)->where('created_at', $request['Date'])->update(array('quantity' => $tee, 'AlishCem' => $tee * $selectOld[0]->Alish, 'SatishCem' => $tee * $selectOld[0]->Satish, 'IncomeCem' => $tee * $selectOld[0]->Income)); } } //////////////////////////buna bax asahi // $datePurchase = DB::select('select * from purchases where cast(created_at as DATE) = ? and CustomerId = ?', array($request['Date'], $request['CustomerId'])); // DB::table('purchases') // ->where('id', $datePurchase[0]->id) // ->update(array('Borc' => $borc)); //////////////////////////////////// // DB::table('users') // ->where('id', 1) // ->update(array('votes' => 1)); // $test = Products::where('CustomerId', '=', $request['CustomerId'])->get(); // foreach ($test as $key => $t2) { // DB::table('orders')->insert( // ['ProductName' => $t2->Name, // 'CustomerId' => $request['CustomerName'], // 'CustomerName' => $request['CustomerName'], // 'quantity' => Input::get("quantity.$key"), // 'Alish' => $t2->Alish, // 'Satish' => $t2->Satish, // 'Income' => Input::get("quantity.$key") * ($t2->Satish - $t2->Alish), // 'created_at' => Carbon::now(), // 'updated_at' => Carbon::now()] // ); // } // Orders::create($request->all()); return redirect('orders/create'); }
/** * Reorder items * * @param items list * @return items from @param */ public function getReorder(ReorderRequest $request) { $list = $request->list; $items = explode(",", $list); $order = 1; foreach ($items as $value) { if ($value != '') { Customers::where('id', '=', $value)->update(array('position' => $order)); $order++; } } return $list; }