act == 'convert' and $request->k) { $invoice = Invoice::findorFail($request->k); }else{ $invoice = ''; } $detail_inv = DetailInvoice::orderBy('id_invoice')->get(); $invoices = Invoice::where('status','UNPAID')->get(); $banks = Bank::all(); $payment = PaymentReceived::orderBy('id','desc')->first(); if ($payment) { $payment = $payment->id + 1; }else{ $payment = 1; } return view('staff.payment-received-create',compact('invoice','invoices','detail_inv','banks','payment')); } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $pr = PaymentReceived::create([ 'id_invoice' => $request->id_invoice, 'amount' => preg_replace('/[^0-9]/', '',$request->amount), 'bank_changes' => $request->bank_changes, 'payment_date' => $request->payment_date, 'payment_mode' => $request->payment_mode, 'id_bank' => $request->id_bank, 'reference' => $request->reference, 'notes' => $request->notes, 'id_user' => Auth::user()->id ]); $pr->invoice->status = 'PAID'; $pr->invoice->save(); $pr->bank->saldo = $pr->bank->saldo + $pr->amount; $pr->bank->save(); BankTransaction::create([ 'id_bank' => $pr->id_bank, 'id_payment_received' => $pr->id, 'deposit' => $pr->amount, 'date' => $pr->payment_date ]); return redirect()->route('payment_received.index')->with('msg','data berhasil dibuat'); } /** * 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'] == 'invoicedata') { $invoice = Invoice::findorFail($id); $amount = 0; foreach($invoice->detailInvoice as $d): if($d->id_invoice == $invoice->id): if($invoice->ppn == '10%'): $amount += ($d->qty * $d->rate) + ($d->qty * $d->rate * 0.1); else: $amount += ($d->qty * $d->rate); endif; endif; endforeach; if($invoice->diskon_invoice == 0 || $invoice->diskon_invoice == NULL): $diskon = 0; else: $diskon = $invoice->diskon_invoice / 100; endif; $amount = $amount - ($amount * $diskon); return response()->json(['amount' => $amount]); }elseif ($_GET['act'] == 'paymentData') { $columns = array( 0 => 'id', ); $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 = PaymentReceived::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'))) { $payments = PaymentReceived::offset($start) ->limit($limit) ->orderBy($order, $dir) ->get(); } else { $search = $request->input('search.value'); $payments = PaymentReceived::whereHas('invoice', function ($q) use ($search) { $q->where('invoice.no_invoice', 'LIKE', "%{$search}%"); })->orWhereHas('invoice.project.owner', function ($q) use ($search) { $q->where('fullname', 'LIKE', "%{$search}%"); }) ->offset($start) ->limit($limit) ->orderBy($order, $dir) ->get(); $totalFiltered = PaymentReceived::whereHas('invoice', function ($q) use ($search) { $q->where('invoice.no_invoice', 'LIKE', "%{$search}%"); })->orWhereHas('invoice.project.owner', function ($q) use ($search) { $q->where('fullname', 'LIKE', "%{$search}%"); }) ->count(); } } else { $totalData = PaymentReceived::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'))) { $payments = PaymentReceived::where('id_user', Auth::user()->id) ->offset($start) ->limit($limit) ->orderBy($order, $dir) ->get(); } else { $search = $request->input('search.value'); $payments = PaymentReceived::whereHas('invoice', function ($q) use ($search) { $q->where('invoice.no_invoice', 'LIKE', "%{$search}%"); })->orWhereHas('invoice.project.owner', function ($q) use ($search) { $q->where('fullname', 'LIKE', "%{$search}%"); }) ->where('id_user', Auth::user()->id) ->offset($start) ->limit($limit) ->orderBy($order, $dir) ->get(); $totalFiltered = PaymentReceived::whereHas('invoice', function ($q) use ($search) { $q->where('invoice.no_invoice', 'LIKE', "%{$search}%"); })->orWhereHas('invoice.project.owner', function ($q) use ($search) { $q->where('fullname', 'LIKE', "%{$search}%"); }) ->where('id_user', Auth::user()->id) ->count(); } } $data = array(); if (!empty($payments) && $payments->count() > 0) { foreach ($payments as $row) { $nestedData['date'] = $row->payment_date; $nestedData['payment'] = $row->id; if($row->invoice->project) { $nestedData['customer'] = $row->invoice->project->owner->fullname; } else if($row->invoice->client) { $nestedData['customer'] = $row->invoice->client->fullname; } else { $nestedData['customer'] = '-'; } $nestedData['invoice'] = $row->invoice->no_invoice; $nestedData['mode'] = $row->payment_mode; $nestedData['amount'] = 'Rp '.number_format($row->amount,0,"","."); $nestedData['created_by'] = $row->user->fullname; $nestedData['opsi'] = " detail "; if(RoleController::access('payment_received', 'delete') > 0) { if($row->invoice->project) { $nestedData['opsi'] .= "
" . csrf_field() . " " . method_field('delete') . "
"; } else if($row->invoice->client) { $nestedData['opsi'] .= "
" . csrf_field() . " " . method_field('delete') . "
"; } } $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 ($request->act == 'print') { $payment = PaymentReceived::findOrFail($id); $company = Company::all()->first(); $pdf = PDF::loadView('staff.payment-received-print',compact('payment', 'company'))->setPaper('a4')->output('payment-'.($payment->invoice->no_invoice).'.pdf'); return Response::make($pdf,200,[ 'Content-Disposition' => 'inline; filename=\"payment-'.($payment->invoice->no_invoice).'.pdf\"', 'Content-Type' => 'application/pdf', ]); }else{ $payment = PaymentReceived::findorFail($id); $company = Company::all()->first(); return view('staff.payment-received-detail',compact('payment', 'company')); } } } /** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { // } /** * 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) { $payment_received = PaymentReceived::findOrFail($id); $id_invoice = $payment_received->id_invoice; $cash = BankTransaction::where('id_payment_received', $id)->first(); $old_saldo_bank = Bank::findorFail($cash->id_bank)->saldo; // Update Bank $bank = Bank::findOrFail($cash->id_bank); $bank->saldo = $old_saldo_bank - $payment_received->amount; $bank->save(); // Delete Cash BankTransaction::where('id_payment_received', $id)->delete(); // Delete Payment Received PaymentReceived::findOrFail($id)->delete(); // Update Invoice $invoice = Invoice::findOrFail($id_invoice); $invoice->status = 'UNPAID'; $invoice->save(); return redirect()->route('payment_received.index')->with('msg', 'Payment Received Successfully Deleted'); } public static function penyebut($nilai) { $nilai = abs($nilai); $huruf = array("", "satu", "dua", "tiga", "empat", "lima", "enam", "tujuh", "delapan", "sembilan", "sepuluh", "sebelas"); $temp = ""; if ($nilai < 12) { $temp = " " . $huruf[$nilai]; } else if ($nilai < 20) { $temp = PaymentReceivedController::penyebut($nilai - 10) . " belas"; } else if ($nilai < 100) { $temp = PaymentReceivedController::penyebut($nilai / 10) . " puluh" . PaymentReceivedController::penyebut($nilai % 10); } else if ($nilai < 200) { $temp = " seratus" . PaymentReceivedController::penyebut($nilai - 100); } else if ($nilai < 1000) { $temp = PaymentReceivedController::penyebut($nilai / 100) . " ratus" . PaymentReceivedController::penyebut($nilai % 100); } else if ($nilai < 2000) { $temp = " seribu" . PaymentReceivedController::penyebut($nilai - 1000); } else if ($nilai < 1000000) { $temp = PaymentReceivedController::penyebut($nilai / 1000) . " ribu" . PaymentReceivedController::penyebut($nilai % 1000); } else if ($nilai < 1000000000) { $temp = PaymentReceivedController::penyebut($nilai / 1000000) . " juta" . PaymentReceivedController::penyebut($nilai % 1000000); } else if ($nilai < 1000000000000) { $temp = PaymentReceivedController::penyebut($nilai / 1000000000) . " milyar" . PaymentReceivedController::penyebut(fmod($nilai, 1000000000)); } else if ($nilai < 1000000000000000) { $temp = PaymentReceivedController::penyebut($nilai / 1000000000000) . " trilyun" . PaymentReceivedController::penyebut(fmod($nilai, 1000000000000)); } return $temp; } public static function bulan($tgl) { $namabulan = date('m', strtotime($tgl)); $daftar_bulan = [ '01' => 'Januari', '02' => 'Februari', '03' => 'Maret', '04' => 'April', '05' => 'Mei', '06' => 'Juni', '07' => 'Juli', '08' => 'Agustus', '09' => 'September', '10' => 'Oktober', '11' => 'November', '12' => 'Desember' ]; return $daftar_bulan[$namabulan]; } }