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') { $berita_acara = BeritaAcara::orderBy('id', 'desc')->get(); } else { $berita_acara = BeritaAcara::where('id_user', Auth::user()->id)->orderBy('id', 'desc')->get(); } $project = Project::whereHas('invoice', function ($q) { $q->where('status', 'paid')->take(1); })->get(); return view('staff.berita-acara', compact('berita_acara', 'project')); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { // } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $id_project = $request->get('id_project'); $pembayaran_ke = $request->get('pembayaran_ke'); $progress = str_replace(',', '.', $request->get('progress')); $lampiran = $request->get('lampiran'); $nilai_pekerjaan_tambah = str_replace(',', '.', str_replace('.', '', $request->get('nilai_pekerjaan_tambah'))); $nilai_pekerjaan_kurang = str_replace(',', '.', str_replace('.', '', $request->get('nilai_pekerjaan_kurang'))); $nilai_kontrak_akhir = str_replace(',', '.', str_replace('.', '', $request->get('nilai_kontrak_akhir'))); $nilai_saat_ini = str_replace(',', '.', str_replace('.', '', $request->get('nilai_pekerjaan_saat_ini'))); $uang_muka = str_replace(',', '.', str_replace('.', '', $request->get('pembayaran_uang_muka'))); $sub_total_1 = str_replace(',', '.', str_replace('.', '', $request->get('sub_total_1'))); $pengurangan_uang_muka = str_replace(',', '.', str_replace('.', '', $request->get('pengembalian_uang_muka'))); $sub_total_2 = str_replace(',', '.', str_replace('.', '', $request->get('sub_total_2'))); $pengurangan_retensi = str_replace(',', '.', str_replace('.', '', $request->get('retensi'))); $sub_total_3 = str_replace(',', '.', str_replace('.', '', $request->get('sub_total_3'))); $telah_dibayar = str_replace(',', '.', str_replace('.', '', $request->get('terbayar'))); $total_bayar = str_replace(',', '.', str_replace('.', '', $request->get('total_pembayaran'))); $berita = new BeritaAcara(); $berita->id_project = $id_project; $berita->pembayaran_ke = $pembayaran_ke; $berita->progress = $progress; $berita->lampiran = $lampiran; $berita->nilai_pekerjaan_tambah = $nilai_pekerjaan_tambah; $berita->nilai_pekerjaan_kurang = $nilai_pekerjaan_kurang; $berita->nilai_kontrak_akhir = $nilai_kontrak_akhir; $berita->nilai_saat_ini = $nilai_saat_ini; $berita->uang_muka = $uang_muka; $berita->sub_total_1 = $sub_total_1; $berita->pengurangan_uang_muka = $pengurangan_uang_muka; $berita->sub_total_2 = $sub_total_2; $berita->pengurangan_retensi = $pengurangan_retensi; $berita->sub_total_3 = $sub_total_3; $berita->telah_dibayar = $telah_dibayar; $berita->total_bayar = $total_bayar; $berita->created_at = date('Y-m-d H:i:s'); $berita->id_user = Auth::user()->id; $berita->save(); return redirect()->route('berita-acara.index')->with('msg', 'Berita Acara Berhasil Ditambahkan'); } /** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { $berita = BeritaAcara::findOrFail($id); $company = Company::all()->first(); $pdf = PDF::loadView('staff.berita_acara_print', compact('berita', 'company'))->setPaper('a4')->stream('berita-acara-' . $id . '.pdf'); return Response::make($pdf, 200, [ 'Content-Disposition' => 'inline; filename=\"berita-acara-pembayaran-' . $id . '.pdf\"', 'Content-Type' => 'application/pdf', ]); } /** * 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) { $berita = BeritaAcara::findOrFail($id); $pembayaran_ke = $request->get('pembayaran_ke'); $progress = str_replace(',', '.', $request->get('progress')); $lampiran = $request->get('lampiran'); $nilai_pekerjaan_tambah = str_replace(',', '.', str_replace('.', '', $request->get('nilai_pekerjaan_tambah'))); $nilai_pekerjaan_kurang = str_replace(',', '.', str_replace('.', '', $request->get('nilai_pekerjaan_kurang'))); $nilai_kontrak_akhir = str_replace(',', '.', str_replace('.', '', $request->get('nilai_kontrak_akhir'))); $nilai_saat_ini = str_replace(',', '.', str_replace('.', '', $request->get('nilai_saat_ini'))); $uang_muka = str_replace(',', '.', str_replace('.', '', $request->get('uang_muka'))); $sub_total_1 = str_replace(',', '.', str_replace('.', '', $request->get('sub_total_1'))); $pengurangan_uang_muka = str_replace(',', '.', str_replace('.', '', $request->get('pengurangan_uang_muka'))); $sub_total_2 = str_replace(',', '.', str_replace('.', '', $request->get('sub_total_2'))); $pengurangan_retensi = str_replace(',', '.', str_replace('.', '', $request->get('pengurangan_retensi'))); $sub_total_3 = str_replace(',', '.', str_replace('.', '', $request->get('sub_total_3'))); $telah_dibayar = str_replace(',', '.', str_replace('.', '', $request->get('telah_dibayar'))); $total_bayar = str_replace(',', '.', str_replace('.', '', $request->get('total_bayar'))); $berita->pembayaran_ke = $pembayaran_ke; $berita->progress = $progress; $berita->lampiran = $lampiran; $berita->nilai_pekerjaan_tambah = $nilai_pekerjaan_tambah; $berita->nilai_pekerjaan_kurang = $nilai_pekerjaan_kurang; $berita->nilai_kontrak_akhir = $nilai_kontrak_akhir; $berita->nilai_saat_ini = $nilai_saat_ini; $berita->uang_muka = $uang_muka; $berita->sub_total_1 = $sub_total_1; $berita->pengurangan_uang_muka = $pengurangan_uang_muka; $berita->sub_total_2 = $sub_total_2; $berita->pengurangan_retensi = $pengurangan_retensi; $berita->sub_total_3 = $sub_total_3; $berita->telah_dibayar = $telah_dibayar; $berita->total_bayar = $total_bayar; $berita->save(); return redirect()->route('berita-acara.index')->with('msg', 'Berita Acara Berhasil Disimpan'); } /** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { BeritaAcara::destroy($id); return redirect()->route('berita-acara.index')->with('msg', 'Berita Acara Berhasil Dihapus'); } public function getProject(Request $request) { $id_project = $request->get('id_project'); $project = Project::where('id', $id_project)->first(); $progress = BeritaAcaraController::getTotalProgress($id_project); $invoice_first = Invoice::select('id', 'ppn', 'diskon_invoice')->where('id_projects', $id_project)->first(); $invoice_detail_first = DetailInvoice::where('id_invoice', $invoice_first->id)->get(); // Perhitungan DP $dp = 0; // Cek Jika PPN if ($invoice_first->ppn == '10%') { $ppn = 0.1; } else { $ppn = 0; } // Cek Jika Diskon if ($invoice_first->diskon_invoice == NULL) { $diskon = 0; } else { $diskon = $invoice_first->diskon_invoice / 100; } foreach ($invoice_detail_first as $in) { $dp = $dp + ($in->qty * $in->rate) + ($in->qty * $in->rate * $ppn) - ($in->qty * $in->rate * $diskon); } // Jumlah yang Telah Dibayar $invoice = Invoice::where([['id_projects', $id_project], ['status', 'PAID']])->get(); $terbayar = 0; foreach ($invoice as $inv) { $invoice_detail = DetailInvoice::where('id_invoice', $inv->id)->get(); // Cek Jika PPN if ($inv->ppn == '10%') { $ppn_inv = 0.1; } else { $ppn_inv = 0; } // Cek Jika Diskon if ($inv->diskon_invoice == NULL) { $diskon_inv = 0; } else { $diskon_inv = $inv->diskon_invoice / 100; } foreach ($invoice_detail as $ind) { $terbayar = $terbayar + ($ind->qty * $ind->rate) + ($ind->qty * $ind->rate * $ppn_inv) - ($ind->qty * $ind->rate * $diskon_inv); } } $html = ''; $html .= '
'; // Nama Pemberi Tugas $html .= '
'; $html .= ''; $html .= '
'; $html .= ''; $html .= '
'; $html .= '
'; // No Kotrak $html .= '
'; $html .= ''; $html .= '
'; $html .= ''; $html .= '
'; $html .= '
'; // Pembayaran Ke $html .= '
'; $html .= ''; $html .= '
'; $html .= ''; $html .= '
'; $html .= '
'; // Progress $html .= '
'; $html .= ''; $html .= '
'; $html .= ''; $html .= '
'; $html .= '
'; // Lampiran $html .= '
'; $html .= ''; $html .= '
'; $html .= ''; $html .= '
'; $html .= '
'; // Nilai Kontrak Awal $html .= '
'; $html .= ''; $html .= '
'; $html .= ''; $html .= '
'; $html .= '
'; // Nilai Pekerjaan Tambah $html .= '
'; $html .= ''; $html .= '
'; $html .= ''; $html .= '
'; $html .= '
'; // Nilai Pekerjaan Kurang $html .= '
'; $html .= ''; $html .= '
'; $html .= ''; $html .= '
'; $html .= '
'; // Nilai Kontrak Akhir $html .= '
'; $html .= ''; $html .= '
'; $html .= ''; $html .= '
'; $html .= '
'; // Nilai Pekerjaan yang Telah Dilaksanakan Saat Ini $html .= '
'; $html .= ''; $html .= '
'; $html .= ''; $html .= '
'; $html .= '
'; // Pembayaran Uang Muka $html .= '
'; $html .= ''; $html .= '
'; $html .= ''; $html .= '
'; $html .= '
'; // Sub Total 1 $html .= '
'; $html .= ''; $html .= '
'; $html .= ''; $html .= '
'; $html .= '
'; // Pengurangan Pengembalian Uang Muka $html .= '
'; $html .= ''; $html .= '
'; $html .= ''; $html .= '
'; $html .= '
'; // Sub Total 2 $html .= '
'; $html .= ''; $html .= '
'; $html .= ''; $html .= '
'; $html .= '
'; // Pengurangan Retensi $html .= '
'; $html .= ''; $html .= '
'; $html .= ''; $html .= '
'; $html .= '
'; // Subtotal 3 $html .= '
'; $html .= ''; $html .= '
'; $html .= ''; $html .= '
'; $html .= '
'; // Pembayaran yang Telah Dibayarkan Sampai Saat Ini $html .= '
'; $html .= ''; $html .= '
'; $html .= ''; $html .= '
'; $html .= '
'; // Total Pembayaran yang Dapat Dibayarkan Sekarang $html .= '
'; $html .= ''; $html .= '
'; $html .= ''; $html .= '
'; $html .= '
'; $html .= '
'; echo $html; } 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 = BeritaAcaraController::penyebut($nilai - 10) . " belas"; } else if ($nilai < 100) { $temp = BeritaAcaraController::penyebut($nilai / 10) . " puluh" . BeritaAcaraController::penyebut($nilai % 10); } else if ($nilai < 200) { $temp = " seratus" . BeritaAcaraController::penyebut($nilai - 100); } else if ($nilai < 1000) { $temp = BeritaAcaraController::penyebut($nilai / 100) . " ratus" . BeritaAcaraController::penyebut($nilai % 100); } else if ($nilai < 2000) { $temp = " seribu" . BeritaAcaraController::penyebut($nilai - 1000); } else if ($nilai < 1000000) { $temp = BeritaAcaraController::penyebut($nilai / 1000) . " ribu" . BeritaAcaraController::penyebut($nilai % 1000); } else if ($nilai < 1000000000) { $temp = BeritaAcaraController::penyebut($nilai / 1000000) . " juta" . BeritaAcaraController::penyebut($nilai % 1000000); } else if ($nilai < 1000000000000) { $temp = BeritaAcaraController::penyebut($nilai / 1000000000) . " milyar" . BeritaAcaraController::penyebut(fmod($nilai, 1000000000)); } else if ($nilai < 1000000000000000) { $temp = BeritaAcaraController::penyebut($nilai / 1000000000000) . " trilyun" . BeritaAcaraController::penyebut(fmod($nilai, 1000000000000)); } return $temp; } public static function hari($tgl) { $namahari = date('l', strtotime($tgl)); $daftar_hari = [ 'Sunday' => 'Ahad', 'Monday' => 'Senin', 'Tuesday' => 'Selasa', 'Wednesday' => 'Rabu', 'Thursday' => 'Kamis', 'Friday' => 'Jumat', 'Saturday' => 'Sabtu' ]; return $daftar_hari[$namahari]; } 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]; } public function getTotalProgress($id) { $project = Project::findOrFail($id); $bobot_kerja = 0; foreach ($project->progress as $row2) { foreach ($row2->progress_details as $row3) { if ($row3->rab_detail->ahs) { $bobot_kerja += round(TimeLineController::getProgressDetail($row2->id, $row3->rab_detail->id, 'bobot_kerja'), 2); } else { $progress = round((TimeLineController::getProgressDetail($row2->id, $row3->rab_detail->id, 'volume_progress') / $row3->rab_detail->volume * 100), 2); $bobot = round($row3->rab_detail->subtotal / $project->rab->harga_deal * 100, 2) / 100; $bobot_kerja += $bobot * $progress; } } } return $bobot_kerja; } public function convertToInvoice(Request $request) { $id_berita = $request->get('b'); $berita = BeritaAcara::where('id', $id_berita)->first(); $project = Project::where('id', $berita->id_project)->first(); $no_inv = Invoice::orderBy('no_invoice', 'DESC') ->where('id_site_project', Auth::user()->curr_siteproject)->first(); if (!$no_inv) { $no_inv = 'BD-001/INV-' . Auth::user()->siteProject->code . '/' . $this->bulantoRomawi(date('m')) . '/' . date('Y'); } else { $no_inv = explode('/', $no_inv->no_invoice)[0]; $no_inv = (int) substr($no_inv, -3) + 1; $no_inv = 'BD-' . sprintf('%03s', $no_inv) . '/INV-' . Auth::user()->siteProject->code . '/' . $this->bulantoRomawi(date('m')) . '/' . date('Y'); } $no_inv = strtoupper($no_inv); return view('staff.convert-berita-invoice', compact('project', 'no_inv', 'id_berita', 'berita')); } private function bulantoRomawi($num) { if ($num <= 12) { $ro = $arrayName = array( 1 => 'I', 2 => 'II', 3 => 'III', 4 => 'IV', 5 => 'V', 6 => 'VI', 7 => 'VII', 8 => 'VIII', 9 => 'IX', 10 => 'X', 11 => 'XI', 12 => 'XII' ); return $ro[(int) $num]; } else { dd('jumlah bulan hanya ada 12'); } } public function createInvoice(Request $request) { $id_project = $request->get('id_project'); $id_berita = $request->get('id_berita'); $no_invoice = $request->get('no_invoice'); $due_date = date('Y-m-d', strtotime($request->get('due_date'))); $ppn = $request->get('ppn'); $jasa = $request->get('jasa'); $deskripsi = $request->get('deskripsi'); $qty = $request->get('qty'); $rate = $request->get('rate'); $diskon = $request->get('discount'); $invoice = new Invoice(); $invoice->id_projects = $id_project; $invoice->id_site_project = Auth::user()->curr_siteproject; $invoice->no_invoice = $no_invoice; $invoice->term = NULL; $invoice->status = 'DRAFT'; $invoice->ppn = $ppn; $invoice->diskon_invoice = $diskon; $invoice->due_date = $due_date; $invoice->created_invoice = date('Y-m-d'); $invoice->id_user = Auth::user()->id; $invoice->save(); $id_invoice = $invoice->id; for ($i = 0; $i <= count($jasa) - 1; $i++) { $detail_invoice = new DetailInvoice(); $detail_invoice->id_invoice = $invoice->id; $detail_invoice->jasa = $jasa[$i]; $detail_invoice->qty = $qty[$i]; $detail_invoice->rate = $rate[$i]; $detail_invoice->description = $deskripsi[$i]; $detail_invoice->save(); } // Update Berita $berita = BeritaAcara::findOrFail($id_berita); $berita->id_invoice = $id_invoice; $berita->save(); return redirect()->route('berita-acara.index')->with('msg', 'Invoice Berhasil Dibuat'); } public function getEditModal(Request $request) { $id_berita = $request->get('id_berita'); $berita = BeritaAcara::where('id', $id_berita)->with('project.owner', 'project.rab')->first(); return $berita; } }