/** * Store a newly created resource in storage. * * @return Response */ public function store(Request $request) { $po_no = trim($request->input('po_no')); $path = explode('/', $po_no); $values = ['pb_id' => $request->input('pb_id'), 'po_no' => $po_no, 'po_tgl_buat' => $request->input('po_tgl_buat'), 'po_tgl_kedatangan' => $request->input('po_tgl_kedatangan'), 'po_note' => trim($request->input('po_note')), 'po_is_ppn' => $path[0] == 'P' ? 1 : 2, 'po_is_use_ppn' => $request->input('po_is_use_ppn'), 'po_status' => 1, 'po_sudden' => 2]; $po = PoModel::create($values); for ($x = 0; $x < count($_POST['pbs_id']); $x++) { $values = ['po_id' => $po->po_id, 'pbs_id' => $_POST['pbs_id'][$x], 'pos_harga' => $_POST['pos_harga'][$x], 'pos_discount' => $_POST['pos_discount'][$x]]; Po_sub::create($values); } $pb = Pb::find($request->input('pb_id')); $pb->pb_status = 4; $pb->save(); if (isset($_POST['save'])) { Session::flash('inserted', '<div class="info success">PO dengan nomor <strong>' . $po_no . '</strong> berhasil dibuat.</div>'); return redirect('po'); } elseif (isset($_POST['save_print'])) { return redirect('printing/po/' . $po->po_id); } }
public function requestStore(Request $req) { $values = ['sup_id' => $req->input('sup_id'), 'pb_no' => trim($req->input('pb_no')), 'pb_tgl_butuh' => $req->input('pb_tgl_butuh'), 'pb_note' => trim($req->input('pb_note')), 'visibility' => 1, 'userid_input' => Auth::user()->user_id]; #pb_status, wether sudden-PO or not $values['pb_status'] = $req->input('create_po') == 1 ? 4 : 1; #End of sudden-PO $pb = Pb::create($values); #If sudden-PO then create PO head directly and a notification if ($req->input('create_po') == 1) { $get = Po::generateNumb('non'); $values = ['pb_id' => $pb->pb_id, 'po_no' => generatePoNumb($get), 'po_tgl_buat' => now(), 'po_tgl_kedatangan' => $req->input('pb_tgl_butuh'), 'po_is_ppn' => 2, 'po_status' => 1, 'po_sudden' => 1]; $po = Po::create($values); $values = ['gn_desc' => 'Pembuatan <i>Sudden-PO</i> oleh Rawmat dengan nomor PO: <strong>' . $po->po_no . '</strong>', 'gn_date' => now(true), 'gn_role' => 2, 'gn_read' => 2]; Notif::create($values); } #Endif $x = 0; foreach ($_POST['mat_id'] as $val) { $values = ['pb_id' => $pb->pb_id, 'mat_id' => $val, 'pbs_jml' => $_POST['pbs_jml'][$x]]; $pbs = Pbs::create($values); #If sudden-PO then create PO sub directly if ($req->input('create_po') == 1) { $values = ['po_id' => $po->po_id, 'pbs_id' => $pbs->pbs_id, 'pos_harga' => $_POST['mat_harga'][$x]]; Po_sub::create($values); } #Endif $x++; } if ($req->input('create_po') == 1) { $message = 'Permintaan material telah dibuat berikut PO-nya dengan nomor: <strong>' . $po->po_no . '</strong>'; } else { $message = 'Permintaan material telah dibuat.'; } Session::flash('inserted', '<div class="info success">' . $message . '</div>'); return redirect('material/request'); }