From 15bac966b0ddb37a051b27fc7e71d4805480e0b3 Mon Sep 17 00:00:00 2001 From: KhatamNugraha Date: Mon, 4 Mar 2024 14:56:56 +0700 Subject: [PATCH] restore function rundem number --- Http/Controllers/KonfirmasiBankController.php | 243 +++++++++++++++++- 1 file changed, 240 insertions(+), 3 deletions(-) diff --git a/Http/Controllers/KonfirmasiBankController.php b/Http/Controllers/KonfirmasiBankController.php index 20f8582..f011e17 100644 --- a/Http/Controllers/KonfirmasiBankController.php +++ b/Http/Controllers/KonfirmasiBankController.php @@ -105,9 +105,246 @@ return json_encode($Accounts ); } - /* - ----- export pdf ----- + + + + public function postInfoSurat(Request $request){ + $noSurat = $this->generateNomorSurat(); + + + // $request->validate([ + // 'signer' => ['required'], + // 'no_req_surat' => ['required', 'max:100'], + // 'tgl_req_surat' => ['required'], + // 'email' => ['email'], + // 'tlp' => ['numeric', 'max:10'], + // 'nama_tujuan' => ['required'], + // 'alamat' => ['required'] + // ]); + + //Validate the request + //Validate the request + $currentDate = Carbon::now(); + $tglSurat = $currentDate->format('Y-m-d'); + + $letter = new Letters(); + $letter->no_cif = $request->cus_no; + $letter->no_surat = $noSurat; + $letter->tgl_surat = $tglSurat; + $letter->no_req_surat = $request->no_req_surat; + $letter->tgl_req_surat = $request->tgl_req_surat; + $letter->email = $request->email ; + $letter->tlp = $request->tlp ; + $letter->nama_tujuan = $request->nama_tujuan ; + $letter->alamat = $request->alamat ; + $letter->created_at = $currentDate; + $letter->status = 1; + $letter->save(); + + echo json_encode(['status' => 'success', 'message' => ' Info Surat created successfully.']); + + } + + private function generateNomorSurat(){ + $latesNoSurat = ''; + $latestRecord = letters::latest('no_surat')->select('no_surat')->first(); + $tanggal = now(); + $tahun = $tanggal->format('Y'); + // Fungsi untuk mengonversi angka bulan menjadi romawi + $bulanRomawi = $this->numberToRoman($tanggal->format('n')); + + if($latestRecord){ + $squence = substr($latestRecord['no_surat'], 0, 3); + $latesNoSurat = str_pad(intval($squence), 3, '0', STR_PAD_LEFT); + $NoUrut = str_pad(intval($latesNoSurat + 1), 3, '0', STR_PAD_LEFT); + $noSurat = " $NoUrut/SUBDIT.OPS/$bulanRomawi/$tahun"; + return $noSurat; + }else { + $noSurat = "001/SUBDIT.OPS/$bulanRomawi/$tahun"; + return $noSurat; + } + + } + + function numberToRoman($num) + { + // Be sure to convert the given parameter into an integer + $n = intval($num); + $result = ''; + + // Declare a lookup array that we will use to traverse the number: + $lookup = array( + 'M' => 1000, 'CM' => 900, 'D' => 500, 'CD' => 400, + 'C' => 100, 'XC' => 90, 'L' => 50, 'XL' => 40, + 'X' => 10, 'IX' => 9, 'V' => 5, 'IV' => 4, 'I' => 1 + ); + + foreach ($lookup as $roman => $value) + { + // Look for number of matches + $matches = intval($n / $value); + + // Concatenate characters + $result .= str_repeat($roman, $matches); + + // Substract that from the number + $n = $n % $value; + } + + return $result; + } + + + + public function signer(Request $request){ + if (is_null($this->user) || !$this->user->can('konfirmasibank.create')) { + abort(403, 'Sorry !! You are Unauthorized to view any master data !'); + } + + $data = []; + // $signer = Signer::paginate(10); + $signer = Signer::where('status',1)->paginate(10); + $data['signer'] = $signer; + // dd( $data['signer']); + + return view('konfirmasibank::pages.index_signer',compact('data')); + + } + + + public function convertToRupiah($amount) + { + $formattedAmount = number_format($amount, 0, ',', '.'); + return $formattedAmount; + } + + public function postSigner(Request $request){ + + if (is_null($this->user) || !$this->user->can('konfirmasibank.create')) { + abort(403, 'Sorry !! You are Unauthorized to create any konfirmasibank.create !'); + } + + dd($request); + + + $currentDate = Carbon::now(); + $validated = $request->validate([ + 'deputy_director' => 'required|string', + 'executive_officer' => 'required|string', + 'signer_type' => 'required|string' + ]); + + if ($validated) { + try { + // Create New User + $signer = new Signer(); + $signer->deputy_director_name = $request->deputy_director; + $signer->executive_officer_name = $request->executive_officer; + $signer->signer_type = $request->signer_type; + $signer->created_at = $currentDate; + $signer->status = 1; + $signer->save(); + // return redirect()->route('konfirmasibank.addFasilitas')->with('success', 'Data berhasil ditambahkan'); + echo json_encode(['status' => 'success', 'message' => ' Add signer successfully .']); + + } catch (Exception $e) { + return json_encode([ + 'status' => 'error', + 'message' => $e->getMessage() + ]); + } + } + + return false; + + } + + /** + * Show the form for editing the specified resource. + * + * @param int $id + * + * @return Response */ + public function editSigner(Request $request) + { + + if (is_null($this->user) || !$this->user->can('konfirmasibank.update')) { + abort(403, 'Sorry !! You are Unauthorized to edit any role !'); + } + + $signer = Signer::find($request->id); + + return json_encode( $signer); + } + + + public function fasilitas(Request $request){ + + if (is_null($this->user) || !$this->user->can('konfirmasibank.create')) { + abort(403, 'Sorry !! You are Unauthorized to view any master data !'); + } + + $data = []; + + $fasilitas = Fasilitas::where('status',1)->where('nomor_cif',$request->query()['cus_no_fasilitas'])->paginate(10)->appends($request->query()['cus_no_fasilitas'],$request->query()['company_name'],$request->query()['startDateFasilitas']); + + $Category = Category::all(); + $Company = Company::all(); + // dd($fasilitas); + $limitReference = LimitReference::all(); + $data['queryParam'] = $request->query(); + $data['fasilitas'] = $fasilitas; + $data['limitReference'] = $limitReference; + $data['Category'] = $Category; + $data['Company'] = $Company; + + return view('konfirmasibank::pages.index_fasilitas',compact('data')); + + } + + + + public function updateSigner(Request $request) + { + + if (is_null($this->user) || !$this->user->can('konfirmasibank.update')) { + abort(403, 'Sorry !! You are Unauthorized to edit any role !'); + } + + $today = Carbon::now(); + + $validator = Validator::make($request->all(), [ + 'deputy_director' => 'required|string', + 'executive_officer' => 'required|string', + 'signer_type' => 'required|string' + ]); + + if ($validator->fails()) { + return response()->json(['errors' => $validator->errors()], 422); // Return validation errors as JSON + } + + + if ($validator) { + try { + $signer = Signer::findOrFail($request->id); + $signer->deputy_director_name = $request->deputy_director; + $signer->executive_officer_name = $request->executive_officer; + $signer->signer_type = $request->signer_type; + $signer->updated_at = $today; + $signer->save(); + + echo json_encode(['status' => 'success', 'message' => ' signer updated successfully.']); + + } catch (Exception $e) { + echo json_encode(['status' => 'error', 'message' => ' signer updated failed.']); + } + + return; + + } + echo json_encode(['status' => 'error', 'message' => ' signer updated failed.']); + } public function export(Request $request){ $arrAccount = explode("," , $request['accNo']); @@ -413,4 +650,4 @@ } - } \ No newline at end of file + }