orWhere('status','partially billed')->get(); return view('staff.bills-po-create',compact('poS')); } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $bill = BillsPo::where('id_purchase_order',$request->id)->orderBy('id','DESC')->first(); if ($bill) { foreach ($bill->billsPoDetail as $row2) { $row2->crap->qty_terambil = $row2->crap->qty_terambil - $row2->qty; $row2->crap->save(); if ($row2->pekerjaans) { foreach ($row2->pekerjaans as $row3) { $rabDetailM = RabDetailMaterial::join('rab_detail','rab_detail_materials.id_rab_detail','rab_detail.id') ->where([ ['rab_detail.id_rab',$row2->crap->id_rab], ['rab_detail.id_ahs',$row3->id_ahs], ['rab_detail_materials.id_material',$row2->crap->id_material] ])->update([ 'rab_detail_materials.qty' => DB::raw('rab_detail_materials.qty + '.str_replace(',', '.', $row3->qty)), 'rab_detail_materials.qty_billed' => DB::raw('rab_detail_materials.qty_billed - '.str_replace(',', '.', $row3->qty)) ]); } } } } $bilss = BillsPo::create([ 'id_purchase_order' => $request->id, 'bill' => $request->bill, 'bill_date' => $request->date, 'due_date' => $request->due_date, 'amount' => $request->amount, 'status' => 'open', 'id_user' => Auth::user()->id ]); $partially_billed = false; foreach ($bilss->purchaseOrder->purchaseOrderDetails as $row) { if ($row->qty_billed < $row->qty or $row->harga_terbayar < $row->harga) { $partially_billed = true; } $billPOD = BillsPoDetail::create([ 'id_bills_po' => $bilss->id, 'id_crap' => $row->id_crap, 'harga' => $row->harga_terbayar, 'qty' => $row->qty_billed, ]); $row->crap->qty_terambil = $row->crap->qty_terambil + $row->qty_billed; $row->crap->save(); if ($row->pekerjaans) { foreach ($row->pekerjaans as $row2) { BillsPoDetailPekerjaan::create([ 'id_bill_detail' => $billPOD->id, 'id_ahs' => $row2->id_ahs, 'qty' => $row2->qty_billed, ]); $rabDetailM = RabDetailMaterial::join('rab_detail','rab_detail_materials.id_rab_detail','rab_detail.id') ->where([ ['rab_detail.id_rab',$row->crap->id_rab], ['rab_detail.id_ahs',$row2->id_ahs], ['rab_detail_materials.id_material',$row->crap->id_material] ])->update([ 'rab_detail_materials.qty' => DB::raw('rab_detail_materials.qty - '.str_replace(',', '.', $row2->qty_billed)), 'rab_detail_materials.qty_billed' => DB::raw('rab_detail_materials.qty_billed + '.str_replace(',', '.', $row2->qty_billed)) ]); } } } foreach ($bilss->purchaseOrder->purchaseOrderDetailManuals as $row) { BillsPoDetailManual::create([ 'id_bills_po' => $bilss->id, 'id_po_manual' => $row->id, 'harga' => $row->harga_terbayar, 'qty' => $row->qty_billed, ]); if ($row->item->qty_billed < $row->qty or $row->harga_terbayar < $row->item->harga) { $partially_billed = true; } } if ($partially_billed) { $bilss->purchaseOrder->status = 'partially billed'; $bilss->purchaseOrder->save(); }else{ $bilss->purchaseOrder->status = 'billed'; $bilss->purchaseOrder->save(); } if ($request->act == 'convert') { return redirect()->route('bills_po.index')->with('msg', 'PO berhasil diconvert'); }else{ return redirect()->route('bills_po.index')->with('msg', 'Data berhasil ditambahkan'); } } /** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show(Request $request, $id) { if (isset($_GET['act'])) { if ($_GET['act'] == 'billsPoData') { $columns = array( 0 => 'id', 1 => 'id', 5 => 'status', ); $level = Auth::user()->level; if (strtoupper($level) == 'SUPERADMIN' || strtoupper($level) == 'GENERAL MANAGER' || strtoupper($level) == 'FINANCE MANAGER' || strtoupper($level) == 'SUPPLY CHAIN MANAGER' || strtoupper($level) == 'MARKETING MANAGER' || strtoupper($level) == 'PROJECT MANAGER') { $totalData = BillsPo::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'))) { $bills = BillsPo::offset($start) ->limit($limit) ->orderBy($order, $dir) ->get(); }else{ $search = $request->input('search.value'); $bills = BillsPo::whereHas('purchaseOrder', function ($q) use ($search) { $q->where('purchase_orders.po_number', 'LIKE', "%{$search}%"); })->orWhereHas('purchaseOrder.suplayer', function ($q) use ($search) { $q->where('suplayers.name', 'LIKE', "%{$search}%"); })->orWhereHas('purchaseOrder.purchaseRequest.project', function ($q) use ($search) { $q->where('projects.name', 'LIKE', "%{$search}%"); })->orWhereHas('project', function ($q) use ($search) { $q->where('name', 'LIKE', "%{$search}%"); }) ->offset($start) ->limit($limit) ->orderBy($order, $dir) ->get(); $totalFiltered = BillsPo::whereHas('purchaseOrder', function ($q) use ($search) { $q->where('purchase_orders.po_number', 'LIKE', "%{$search}%"); })->orWhereHas('purchaseOrder.suplayer', function ($q) use ($search) { $q->where('suplayers.name', 'LIKE', "%{$search}%"); })->orWhereHas('purchaseOrder.purchaseRequest.project', function ($q) use ($search) { $q->where('projects.name', 'LIKE', "%{$search}%"); })->orWhereHas('project', function ($q) use ($search) { $q->where('name', 'LIKE', "%{$search}%"); }) ->count(); } } else { $totalData = BillsPo::where('id_user', Auth::user()->id)->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'))) { $bills = BillsPo::where('id_user', Auth::user()->id) ->offset($start) ->limit($limit) ->orderBy($order, $dir) ->get(); }else{ $search = $request->input('search.value'); $bills = BillsPo::whereHas('purchaseOrder', function ($q) use ($search) { $q->where('purchase_orders.po_number', 'LIKE', "%{$search}%"); })->orWhereHas('purchaseOrder.suplayer', function ($q) use ($search) { $q->where('suplayers.name', 'LIKE', "%{$search}%"); })->orWhereHas('purchaseOrder.purchaseRequest.project', function ($q) use ($search) { $q->where('projects.name', 'LIKE', "%{$search}%"); })->orWhereHas('project', function ($q) use ($search) { $q->where('name', 'LIKE', "%{$search}%"); }) ->where('id_user', Auth::user()->id) ->offset($start) ->limit($limit) ->orderBy($order, $dir) ->get(); $totalFiltered = BillsPo::whereHas('purchaseOrder', function ($q) use ($search) { $q->where('purchase_orders.po_number', 'LIKE', "%{$search}%"); })->orWhereHas('purchaseOrder.suplayer', function ($q) use ($search) { $q->where('suplayers.name', 'LIKE', "%{$search}%"); })->orWhereHas('purchaseOrder.purchaseRequest.project', function ($q) use ($search) { $q->where('projects.name', 'LIKE', "%{$search}%"); })->orWhereHas('project', function ($q) use ($search) { $q->where('name', 'LIKE', "%{$search}%"); }) ->where('id_user', Auth::user()->id) ->count(); } } $data = array(); if (!empty($bills)) { foreach ($bills as $row) { $nestedData['project'] = $row->purchaseOrder?$row->purchaseOrder->purchaseRequest->project->name:$row->project->name; $nestedData['Date'] = $row->bill_date; $nestedData['Bill#'] = $row->bill; $nestedData['Vendor'] = $row->purchaseOrder?$row->purchaseOrder->suplayer->name:'-'; $nestedData['Ref PO'] = $row->purchaseOrder?$row->purchaseOrder->po_number:'-'; $nestedData['Status'] = $row->status; $nestedData['Due Date'] = $row->due_date; $nestedData['Amount'] = 'Rp ' . number_format($row->amount, 0, "", "."); $nestedData['Balance Due'] = $row->status == 'open' ? 'Rp ' . number_format($row->amount, 0, "", ".") : 0; if($row->id_user == NULL) { $nestedData['created_by'] = ''; } else { $nestedData['created_by'] = $row->user->fullname; } $nestedData['opsi'] = " detail "; $data[] = $nestedData; } } $json_data = array( "draw" => intval($request->input('draw')), "recordsTotal" => intval($totalData), "recordsFiltered" => intval($totalFiltered), "data" => $data, ); echo json_encode($json_data); }else if ($_GET['act'] == 'poData') { $po = PurchaseOrder::with('suplayer')->findOrFail($id); return response()->json(['po' => $po]); }else if ($_GET['act'] == 'poItemData') { $po = PurchaseOrder::findOrFail($id); return view('staff.bills-po-create_itemdetail',compact('po')); }elseif ($_GET['act'] == 'print') { $bill = BillsPo::findOrFail($id); $pdf = PDF::loadView('staff.bills-po-print',compact('bill'))->setPaper('a4')->output('bill-'.$bill->bill.'.pdf'); return Response::make($pdf,200,[ 'Content-Disposition' => 'inline; filename=\"bill-'.$bill->bill.'.pdf\"', 'Content-Type' => 'application/pdf', ]); } }else{ $bill = BillsPo::findOrFail($id); return view('staff.bills-po-detail',compact('bill')); } } /** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { $bill = BillsPo::findOrFail($id); $banks = Bank::all(); return view('staff.bills-po-record_payment',compact('bill','banks')); } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { // } /** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { // } }