id_bills_po); $bpo = BillsPo::create([ 'id_project' => $request->switch_to, 'bill' => $bills_po->bill, 'bill_date' => $request->date, 'due_date' => $bills_po->due_date, 'amount' => 0, 'status' => 'open', ]); $amount = 0; if ($request->id_detail) { foreach ($request->id_detail as $key => $value) { $bill_po_d = BillsPoDetail::where('id',$value)->first(); $bill_po_d->qty -= str_replace(',', '.', $request->qty[$key]); $bill_po_d->save(); BillsPoDetail::create([ 'id_bills_po' => $bpo->id, 'id_crap' => $bill_po_d->id_crap, 'harga' => $bill_po_d->harga, 'qty' => str_replace(',', '.', $request->qty[$key]), ]); $amount += $bill_po_d->harga * str_replace(',', '.', $request->qty[$key]); } } $bills_po->amount = $bills_po->amount - $amount; $bills_po->save(); $bpo->amount = $amount; $bpo->save(); return redirect()->route('bills_po.index')->with('msg','Bills PO berhasil di switch'); } /** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show(Request $request,$id) { if (\Request::ajax()) { if (isset($_GET['act'])) { if ($_GET['act'] == 'switchmdata') { $columns = array( 0 => 'id', ); $totalData = Project::count(); $totalFiltered = $totalData; $limit = $request->input('length'); $start = $request->input('start'); $order = $columns[$request->input('order.0.column')]; $dir = $request->input('order.0.dir'); if (empty($request->input('search.value'))) { $projects = Project::offset($start) ->limit($limit) ->orderBy($order, $dir) ->get(); }else{ $search = $request->input('search.value'); $projects = Project::where('projects.name', 'LIKE', "%{$search}%") ->offset($start) ->limit($limit) ->orderBy($order, $dir) ->get(); $totalFiltered = Project::where('projects.name', 'LIKE', "%{$search}%") ->count(); } $data = array(); if (!empty($projects)) { foreach ($projects as $row) { $nestedData['project'] = $row->name; $nestedData['opsi'] = "