From fa207d010d788470e0257a0903b5c436d0dc0dca Mon Sep 17 00:00:00 2001 From: KhatamNugraha Date: Wed, 29 May 2024 08:45:05 +0700 Subject: [PATCH] fix export --- Entities/Account.php | 16 ++-- Http/Controllers/KonfirmasiBankController.php | 74 +++++++++++++++---- 2 files changed, 68 insertions(+), 22 deletions(-) diff --git a/Entities/Account.php b/Entities/Account.php index 2c701d3..e74cce8 100644 --- a/Entities/Account.php +++ b/Entities/Account.php @@ -67,7 +67,7 @@ class Account extends Model public function getAccount($cif, $arrAccount, $startDate) { //$uppercaseKodeCabang = Str::upper($kodecabang); - $dateString = $startDate->format('m/d/Y'); + // $dateString = $startDate->format('m/d/Y'); $data = DB::connection("db2")->table("STG_DB.ACCOUNT AS AC") ->selectRaw('AC.CUSTOMER_NO,AC.CATEGORY,AC.ACCOUNT_NUMBER,AC.CURRENCY, AC.SHORT_TITLE,AC.OPENING_DATE,AC.WORKING_BALANCE, AC.CATEGORY,CT.SHORT_NAME,CP.COMPANY_NAME,AC.BATCH_DATE') @@ -75,7 +75,7 @@ class Account extends Model ->join('STG_DB.COMPANY AS CP', 'AC.CO_CODE', '=', 'CP.ID') ->where('CUSTOMER_NO', $cif) ->where('LIMIT_REF', null) - ->where('AC.BATCH_DATE', $dateString) + ->where('AC.BATCH_DATE', $startDate) ->whereIn('AC.ACCOUNT_NUMBER', $arrAccount) ->whereIn(DB::raw("LEFT(CATEGORY, 3)"),['100','600','660','101']) // ->groupBy('CUSTOMER_NO', 'ACCOUNT_NUMBER', 'SHORT_TITLE', 'SHORT_NAME', 'COMPANY_NAME', 'CATEGORY', 'LIMIT_REF') @@ -129,11 +129,11 @@ class Account extends Model public function getArr($cust, $acc, $dataCore) { //$uppercaseKodeCabang = Str::upper($kodecabang); - $dateString = $dataCore->format('m/d/Y'); + //$dateString = $dataCore->format('m/d/Y'); // dd($dateString); - $timestamp = strtotime($dataCore); + //$timestamp = strtotime($dataCore); // Format the timestamp into a date format - $Year = date("Y", $timestamp); + //$Year = date("Y", $timestamp); $data = DB::connection("db2")->table("STG_DB.VW_AA_DETAIL") ->selectRaw('ARRANGEMENT_ID,CUSTOMER,LINKED_APPL_ID,PRODUCT_LINE,MATURITY_DATE,RENEWAL_DATE,START_DATE,ARR_STATUS,BATCH_DATE,BASE_DATE') @@ -206,12 +206,14 @@ class Account extends Model public function getFixedRate($arrangementId, $startDate) { + $timestamp = strtotime($startDate); + $Year = date("Y", $timestamp); $data = []; $data = DB::connection("db2")->table("STG_DB.AA_ARR_INTEREST") ->select('FIXED_RATE') // ->whereYear('BATCH_DATE',$startDate->format('Y')) ->where(DB::raw("LEFT(ID, 12)"), $arrangementId) - ->where(DB::raw("RIGHT(ID, 10)"), 'like', "%" .$startDate->format('Y') ."%") + ->where(DB::raw("RIGHT(ID, 10)"), 'like', "%" .$Year ."%") ->orderBy('ID', 'DESC') ->limit(1); @@ -364,4 +366,4 @@ class Account extends Model -} +} \ No newline at end of file diff --git a/Http/Controllers/KonfirmasiBankController.php b/Http/Controllers/KonfirmasiBankController.php index 1906463..00da332 100644 --- a/Http/Controllers/KonfirmasiBankController.php +++ b/Http/Controllers/KonfirmasiBankController.php @@ -101,12 +101,33 @@ class KonfirmasiBankController extends Controller $data = []; $Account = new Account(); $arrAccount = []; + $dataAccount = []; $startDate = Carbon::parse($request->startDate); - $dateCore = $startDate->addDays(2)->format('m/d/Y'); - $Accounts = $Account->getSearchAccount($request->cif, $arrAccount, $request->kodecabang, $dateCore)->get(); + //$dateCore = $startDate->format('m/d/Y'); + $Accounts = $Account->getSearchAccount($request->cif, $arrAccount, $request->kodecabang, $startDate)->get(); + + if ($Accounts->isEmpty()) { + $Accounts = $Account->getSearchAccount($request->cif, $arrAccount, $request->kodecabang, $startDate->subDays(1)->format('m/d/Y'))->get(); + if($Accounts->isEmpty()){ + $Accounts = $Account->getSearchAccount($request->cif, $arrAccount, $request->kodecabang, $startDate->subDays(2)->format('m/d/Y'))->get(); + if ($Accounts->isEmpty()) { + $Accounts = $Account->getSearchAccount($request->cif, $arrAccount, $request->kodecabang, $startDate->subDays(3)->format('m/d/Y'))->get(); + if ($Accounts->isEmpty()) { + $Accounts = $Account->getSearchAccount($request->cif, $arrAccount, $request->kodecabang, $startDate->subDays(4)->format('m/d/Y'))->get(); + if ($Accounts->isEmpty()) { + $Accounts = $Account->getSearchAccount($request->cif, $arrAccount, $request->kodecabang, $startDate->subDays(5)->format('m/d/Y'))->get(); + } + } + } + } + } else { + $Accounts = $Account->getSearchAccount($request->cif, $arrAccount, $request->kodecabang, $startDate)->get(); + } + foreach ($Accounts as $key => $value) { + $data[$key]['ACCOUNT_NUMBER'] = $value->ACCOUNT_NUMBER; $data[$key]['COMPANY_NAME'] = $value->COMPANY_NAME; $data[$key]['SHORT_NAME'] = $value->SHORT_NAME; @@ -346,8 +367,9 @@ class KonfirmasiBankController extends Controller public function export(Request $request) { $arrAccount = explode(",", $request['accNo']); - $startDate = Carbon::parse($request['startDate2']); - $dateCore = $startDate->addDays(2); + // $startDate = Carbon::parse($request['startDate2']); + // dd($tanggal1 ); + $dateCore = Carbon::parse($request['startDate2']);; // dd( $dateCore); $Account = new Account(); $data = []; @@ -358,10 +380,31 @@ class KonfirmasiBankController extends Controller $rekEscrow = []; $DataAnjak = []; $GetCustomer = $Account->getCustomer($request['cusNo'])->first(); - $listAccount = $Account->getAccount($request['cusNo'], $arrAccount, $dateCore)->get(); - // DD($listAccount); + $listAccount = $Account->getAccount($request['cusNo'], $arrAccount, $dateCore->format('m/d/Y'))->get(); - try { + if ($listAccount->isEmpty()) { + $dateCore = $dateCore->subDays(1)->format('m/d/Y'); + $listAccount = $Account->getAccount($request['cusNo'], $arrAccount, $dateCore)->get(); + + if($listAccount->isEmpty()){ + $dateCore = $dateCore->subDays(2)->format('m/d/Y'); + $listAccount = $Account->getAccount($request['cusNo'], $arrAccount, $dateCore)->get(); + if ($listAccount->isEmpty()) { + $dateCore = $dateCore->subDays(3)->format('m/d/Y'); + $listAccount = $Account->getAccount($request['cusNo'], $arrAccount, $dateCore)->get(); + if ($listAccount->isEmpty()) { + $dateCore = $dateCore->subDays(4)->format('m/d/Y'); + $listAccount = $Account->getAccount($request['cusNo'], $arrAccount, $dateCore)->get(); + if ($listAccount->isEmpty()) { + $dateCore = $dateCore->subDays(5)->format('m/d/Y'); + $listAccount = $Account->getAccount($request['cusNo'], $arrAccount, $dateCore)->get(); + } + } + } + } + } + + // try { foreach ($listAccount as $key1 => $account) { $dataAADepo = $Account->getArr($request['cusNo'], $account->ACCOUNT_NUMBER, $dateCore)->first(); @@ -373,11 +416,12 @@ class KonfirmasiBankController extends Controller $tglRenewal = $tanggal_1->format('d'); $tanggal_2 = date_create($dataAADepo->BASE_DATE); $tenor = date_diff($tanggal_1, $tanggal_2); - $batchDate = $dateCore->format('Y-m-d'); - $maturityDate = Carbon::createFromFormat('Y-m-d', $batchDate); + $batchDate = strtotime($dateCore); + $startDate = date("Y-m-d", $batchDate); // Tanggal mulai pinjaman + $maturityDate = Carbon::createFromFormat('Y-m-d', $startDate); $tenorFix = $tenor->days >= 30 ? intval($tenor->days / 30) : 1; - $startDate = $batchDate; // Tanggal mulai pinjaman + $startDate = date("Y-m-d", $batchDate); // Tanggal mulai pinjaman // // Konversi tanggal mulai ke objek Carbon $tanggalMulai = Carbon::parse($startDate); // // Hitung tanggal jatuh tempo dengan menambahkan durasi hari @@ -499,9 +543,9 @@ class KonfirmasiBankController extends Controller $ListLimits = $Account->getLimit($request['cusNo'], $request['startDate2'])->get(); $signer = Signer::where('id', $request['signerId'])->where('status', 1)->get(); - $batchDateSearch = Carbon::parse($request['startDate2']); + $batchDate = Carbon::parse($request['startDate2']); $currentDate = Carbon::now(); - $tanggalIndonesia = strtoupper($batchDateSearch->locale('id')->isoFormat('D MMMM YYYY')); // Mengubah seluruh string menjadi huruf besar + $tanggalIndonesia = strtoupper($batchDate->locale('id')->isoFormat('D MMMM YYYY')); // Mengubah seluruh string menjadi huruf besar $today = strtoupper($currentDate->locale('id')->isoFormat('D MMMM YYYY')); $letter = new Letters(); $infoSuratNew = $letter->where('no_cif', $request['cusNo'])->orderBy('id', 'DESC')->first(); @@ -561,9 +605,9 @@ class KonfirmasiBankController extends Controller return $pdf->stream($filename); - } catch (Exception $e) { - echo json_encode(['status' => 'error', 'message' => $e->getMessage()]); - } + // } catch (Exception $e) { + // echo json_encode(['status' => 'error', 'message' => $e->getMessage()]); + // } // return false;