fixing query builder
This commit is contained in:
@ -47,16 +47,15 @@ class Account extends Model
|
|||||||
if($arrAccount == null){
|
if($arrAccount == null){
|
||||||
|
|
||||||
$data = DB::connection("db2")->table("STG_DB.ACCOUNT AS AC")
|
$data = DB::connection("db2")->table("STG_DB.ACCOUNT AS AC")
|
||||||
->selectRaw('AC.CUSTOMER_NO , AC.ACCOUNT_NUMBER ,AC.INACTIV_MARKER, AC.CATEGORY ,AC.BATCH_DATE,AC.CURRENCY,AC.SHORT_TITLE,AC.OPENING_DATE,CT.SHORT_NAME,CP.COMPANY_NAME,AC.WORKING_BALANCE')
|
->selectRaw('AC.CUSTOMER_NO, MAX(INACTIV_MARKER) as INACTIV_MARKER,AC.ACCOUNT_NUMBER,MAX(AC.BATCH_DATE) AS BATCH_DATE,MAX(AC.CURRENCY)AS CURRENCY, AC.SHORT_TITLE,MAX(AC.OPENING_DATE) AS OPENING_DATE, MAX(AC.WORKING_BALANCE) AS WORKING_BALANCE, MAX(AC.CATEGORY) AS CATEGORY,CT.SHORT_NAME,CP.COMPANY_NAME')
|
||||||
->join('STG_DB.CATEGORY AS CT', 'AC.CATEGORY', '=', 'CT.ID')
|
->join('STG_DB.CATEGORY AS CT', 'AC.CATEGORY', '=', 'CT.ID')
|
||||||
->join('STG_DB.COMPANY AS CP', 'AC.CO_CODE', '=', 'CP.ID')
|
->join('STG_DB.COMPANY AS CP', 'AC.CO_CODE', '=', 'CP.ID')
|
||||||
->where('CUSTOMER_NO',$cif)
|
->where('CUSTOMER_NO',$cif)
|
||||||
->where('COMPANY_NAME', 'like', "%" .$uppercaseKodeCabang."%")
|
->where('COMPANY_NAME', 'like', "%" .$uppercaseKodeCabang."%")
|
||||||
//->where('INACTIV_MARKER', NULL)
|
// ->where('INACTIV_MARKER', NULL)
|
||||||
->where('AC.BATCH_DATE',$startDate)
|
->where('AC.BATCH_DATE',$startDate)
|
||||||
->whereIn(DB::raw("LEFT(CATEGORY, 3)"),['100','600','660','101'])
|
->whereIn(DB::raw("LEFT(CATEGORY, 3)"),['100','600','660','101'])
|
||||||
->distinct()
|
->groupBy('CUSTOMER_NO','ACCOUNT_NUMBER','SHORT_TITLE','SHORT_NAME','COMPANY_NAME')
|
||||||
// ->groupBy('CUSTOMER_NO','ACCOUNT_NUMBER','SHORT_TITLE','SHORT_NAME','COMPANY_NAME')
|
|
||||||
->limit(100);
|
->limit(100);
|
||||||
}else{
|
}else{
|
||||||
$data = DB::connection("db2")->table("STG_DB.ACCOUNT")
|
$data = DB::connection("db2")->table("STG_DB.ACCOUNT")
|
||||||
@ -74,17 +73,16 @@ class Account extends Model
|
|||||||
// $uppercaseKodeCabang = Str::upper($kodecabang);
|
// $uppercaseKodeCabang = Str::upper($kodecabang);
|
||||||
|
|
||||||
$data = DB::connection("db2")->table("STG_DB.ACCOUNT AS AC")
|
$data = DB::connection("db2")->table("STG_DB.ACCOUNT AS AC")
|
||||||
->selectRaw('AC.CUSTOMER_NO , AC.ACCOUNT_NUMBER ,AC.INACTIV_MARKER, AC.CATEGORY ,AC.BATCH_DATE,AC.CURRENCY,AC.SHORT_TITLE,AC.OPENING_DATE,CT.SHORT_NAME,CP.COMPANY_NAME,AC.WORKING_BALANCE')
|
->selectRaw('AC.CUSTOMER_NO, MAX(INACTIV_MARKER) as INACTIV_MARKER,AC.ACCOUNT_NUMBER,MAX(AC.BATCH_DATE) AS BATCH_DATE,MAX(AC.CURRENCY)AS CURRENCY, AC.SHORT_TITLE,MAX(AC.OPENING_DATE) AS OPENING_DATE, MAX(AC.WORKING_BALANCE) AS WORKING_BALANCE, MAX(AC.CATEGORY) AS CATEGORY,CT.SHORT_NAME,CP.COMPANY_NAME')
|
||||||
->join('STG_DB.CATEGORY AS CT', 'AC.CATEGORY', '=', 'CT.ID')
|
->join('STG_DB.CATEGORY AS CT', 'AC.CATEGORY', '=', 'CT.ID')
|
||||||
->join('STG_DB.COMPANY AS CP', 'AC.CO_CODE', '=', 'CP.ID')
|
->join('STG_DB.COMPANY AS CP', 'AC.CO_CODE', '=', 'CP.ID')
|
||||||
->where('CUSTOMER_NO',$cif)
|
->where('CUSTOMER_NO',$cif)
|
||||||
// ->where('COMPANY_NAME', 'like', "%" .$uppercaseKodeCabang."%")
|
// ->where('COMPANY_NAME', 'like', "%" .$uppercaseKodeCabang."%")
|
||||||
//->where('INACTIV_MARKER', NULL)
|
// ->where('INACTIV_MARKER', NULL)
|
||||||
->where('AC.BATCH_DATE',$startDate)
|
->where('AC.BATCH_DATE',$startDate)
|
||||||
->whereIn('AC.ACCOUNT_NUMBER', $arrAccount)
|
->whereIn('AC.ACCOUNT_NUMBER', $arrAccount)
|
||||||
->distinct()
|
->whereIn(DB::raw("LEFT(CATEGORY, 3)"),['100','600','660','101'])
|
||||||
//->whereIn(DB::raw("LEFT(CATEGORY, 3)"),['100','600','660','101'])
|
->groupBy('CUSTOMER_NO','ACCOUNT_NUMBER','SHORT_TITLE','SHORT_NAME','COMPANY_NAME')
|
||||||
//->groupBy('CUSTOMER_NO','ACCOUNT_NUMBER','SHORT_TITLE','SHORT_NAME','COMPANY_NAME')
|
|
||||||
->limit(100);
|
->limit(100);
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
@ -106,15 +104,20 @@ class Account extends Model
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getPinjaman($cus_no, $dateCore){
|
public function getPinjaman($cus_no, $dateCore){
|
||||||
|
//dd($cus_no, $accNo, $dateCore);
|
||||||
|
|
||||||
$data = [];
|
$data = [];
|
||||||
$data = DB::connection("db2")->table("STG_DB.AA_ARRANGEMENT as AA")
|
$data = DB::connection("db2")->table("STG_DB.AA_ARRANGEMENT")
|
||||||
->select('AA.ARRANGEMENT_ID','AA.PRODUCT_LINE','AA.CO_CODE','AA.START_DATE','AA.CURRENCY','AA.PRODUCT','AA.LINKED_APPL_ID','AD.MATURITY_DATE')
|
->selectRaw('ARRANGEMENT_ID,PRODUCT_LINE,BATCH_DATE,CURRENCY,START_DATE,LINKED_APPL_ID')
|
||||||
->join('STG_DB.AA_ACCOUNT_DETAILS AS AD', 'AA.ARRANGEMENT_ID', '=', 'AD.ID')
|
// ->join('STG_DB.ACCOUNT AS AC', 'AA.LINKED_APPL_ID', '=', 'AC.ACCOUNT_NUMBER')
|
||||||
// ->join('STG_DB.AA_ARR_INTEREST AS AI', 'AA.ARRANGEMENT_ID', '=', DB::raw("LEFT(AI.ID, 12)"))
|
->where('CUSTOMER',$cus_no)
|
||||||
->where('AA.CUSTOMER',$cus_no)
|
// ->whereIn(DB::raw("LINKED_APPL_ID"),$arr)
|
||||||
->where('AA.BATCH_DATE', $dateCore)
|
// ->where('ARR_STATUS' , 'CURRENT')
|
||||||
->where('AA.ARR_STATUS', '<>','CLOSE')
|
// ->orderBy('TERM','DESC');
|
||||||
|
->where('BATCH_DATE', $dateCore)
|
||||||
|
->where('ARR_STATUS','<>', 'CLOSE')
|
||||||
|
//->where('LINKED_APPL_ID', $accNo)
|
||||||
|
// ->groupBy('ARRANGEMENT_ID','ACCOUNT_NUMBER','SHORT_TITLE','SHORT_NAME','COMPANY_NAME')
|
||||||
->limit(100);
|
->limit(100);
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
@ -137,20 +140,20 @@ class Account extends Model
|
|||||||
$data = DB::connection("db2")->table("STG_DB.AA_ACCOUNT_DETAILS")
|
$data = DB::connection("db2")->table("STG_DB.AA_ACCOUNT_DETAILS")
|
||||||
->select('MATURITY_DATE')
|
->select('MATURITY_DATE')
|
||||||
->where('ID' ,$arrangementId)
|
->where('ID' ,$arrangementId)
|
||||||
->where('BATCH_DATE', $startDate)
|
->where('BATCH_DATE' ,$startDate)
|
||||||
->limit(100);
|
->limit(1)
|
||||||
// ->orderBy('TERM','DESC');
|
->orderBy('MATURITY_DATE','DESC');
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTermAmount($arrangementId, $startDate){
|
public function getTermAmount($arrangementId){
|
||||||
$data = [];
|
$data = [];
|
||||||
$data = DB::connection("db2")->table("STG_DB.AA_ARR_TERM_AMOUNT")
|
$data = DB::connection("db2")->table("STG_DB.AA_ARR_TERM_AMOUNT")
|
||||||
->select('TERM')
|
->select('TERM')
|
||||||
->where('BATCH_DATE', $startDate)
|
->where(DB::raw("LEFT(ID, 12)"),$arrangementId)
|
||||||
->where(DB::raw("LEFT(ID, 12)"),$arrangementId);
|
->orderBy('TERM','DESC')
|
||||||
// ->orderBy('TERM','DESC');
|
->limit(1);
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
@ -158,11 +161,13 @@ class Account extends Model
|
|||||||
public function getSingleAccount($acNo, $date){
|
public function getSingleAccount($acNo, $date){
|
||||||
$data = [];
|
$data = [];
|
||||||
$data = DB::connection("db2")->table("STG_DB.ACCOUNT")
|
$data = DB::connection("db2")->table("STG_DB.ACCOUNT")
|
||||||
->select('ACCOUNT_NUMBER','WORKING_BALANCE')
|
->select('WORKING_BALANCE')
|
||||||
->where('ACCOUNT_NUMBER',$acNo)
|
->where('ACCOUNT_NUMBER',$acNo)
|
||||||
->where('BATCH_DATE',$date)
|
->where('BATCH_DATE',$date)
|
||||||
|
->limit(1)
|
||||||
->orderBy('ACCOUNT_NUMBER','DESC');
|
->orderBy('ACCOUNT_NUMBER','DESC');
|
||||||
|
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -363,7 +363,6 @@
|
|||||||
// dd($listAccount);
|
// dd($listAccount);
|
||||||
$GetCustomer = $Account->getCustomer($request['cusNo'])->first();
|
$GetCustomer = $Account->getCustomer($request['cusNo'])->first();
|
||||||
$listAccount = $Account->getAccount($request['cusNo'], $arrAccount, $dateCore )->get();
|
$listAccount = $Account->getAccount($request['cusNo'], $arrAccount, $dateCore )->get();
|
||||||
$Arrangement = $Account->getPinjaman($request['cusNo'], $dateCore)->get();
|
|
||||||
|
|
||||||
foreach ($listAccount as $key1 => $account) {
|
foreach ($listAccount as $key1 => $account) {
|
||||||
$DataAccounts[$key1]['ACCOUNT_NUMBER'] = $account->ACCOUNT_NUMBER;
|
$DataAccounts[$key1]['ACCOUNT_NUMBER'] = $account->ACCOUNT_NUMBER;
|
||||||
@ -382,21 +381,23 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$Arrangement = $Account->getPinjaman($request['cusNo'], $dateCore)->get();
|
||||||
|
|
||||||
foreach ($Arrangement as $key2 => $pinjaman) {
|
foreach ($Arrangement as $key2 => $pinjaman) {
|
||||||
// $MaturityDate = $Account->getMaturityDate($pinjaman->ARRANGEMENT_ID, $startDate )->first();
|
$maturityDate = $Account->getMaturityDate($pinjaman->ARRANGEMENT_ID, $startDate )->first();
|
||||||
$TermAmount = $Account->getTermAmount($pinjaman->ARRANGEMENT_ID,$startDate)->first();
|
$TermAmount = $Account->getTermAmount($pinjaman->ARRANGEMENT_ID,$startDate)->first();
|
||||||
$FixedRate = $Account->getFixedRate($pinjaman->ARRANGEMENT_ID,$startDate)->first();
|
$FixedRate = $Account->getFixedRate($pinjaman->ARRANGEMENT_ID,$startDate)->first();
|
||||||
$balance = $Account->getSingleAccount($pinjaman->LINKED_APPL_ID,$startDate)->first();
|
$balance = $Account->getSingleAccount($pinjaman->LINKED_APPL_ID,$startDate)->first();
|
||||||
|
|
||||||
|
// dd($balance);
|
||||||
$DataPinjaman[$key2]['ARRANGEMENT_ID'] = $pinjaman->ARRANGEMENT_ID;
|
$DataPinjaman[$key2]['ARRANGEMENT_ID'] = $pinjaman->ARRANGEMENT_ID;
|
||||||
$DataPinjaman[$key2]['START_DATE'] = $pinjaman->START_DATE;
|
$DataPinjaman[$key2]['START_DATE'] = $pinjaman->START_DATE;
|
||||||
$DataPinjaman[$key2]['CURRENCY'] = $pinjaman->CURRENCY;
|
$DataPinjaman[$key2]['CURRENCY'] = $pinjaman->CURRENCY;
|
||||||
$DataPinjaman[$key2]['PRODUCT'] = $pinjaman->PRODUCT_LINE;
|
$DataPinjaman[$key2]['PRODUCT'] = $pinjaman->PRODUCT_LINE;
|
||||||
$DataPinjaman[$key2]['WORKING_BALANCE'] = $balance != null ? number_format( $balance->WORKING_BALANCE, 2, ',', '.') : 'NIHIL';
|
$DataPinjaman[$key2]['WORKING_BALANCE'] = number_format($balance->WORKING_BALANCE, 2, ',', '.') ?? '';
|
||||||
$DataPinjaman[$key2]['TERM'] = $TermAmount ? $TermAmount->TERM : '' ;
|
$DataPinjaman[$key2]['TERM'] = $TermAmount->TERM ?? '';
|
||||||
$DataPinjaman[$key2]['FIXED_RATE'] = $FixedRate ? $FixedRate->FIXED_RATE : '';
|
$DataPinjaman[$key2]['FIXED_RATE'] = $FixedRate->FIXED_RATE ?? '';
|
||||||
$DataPinjaman[$key2]['MATURITY_DATE'] = $pinjaman->MATURITY_DATE;
|
$DataPinjaman[$key2]['MATURITY_DATE'] = $maturityDate->MATURITY_DATE ?? '';
|
||||||
$DataPinjaman[$key2]['ACCOUNT_NUMBER'] = $pinjaman->LINKED_APPL_ID;
|
$DataPinjaman[$key2]['ACCOUNT_NUMBER'] = $pinjaman->LINKED_APPL_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user