Merge remote-tracking branch 'origin/prod-kopkb' into test/merge-prod-kopkb
This commit is contained in:
@@ -30,6 +30,7 @@ use App\Status;
|
||||
use App\LookupStatus;
|
||||
use App\ARFiles;
|
||||
use App\WTDDraft;
|
||||
use App\WTDSimulasi;
|
||||
use App\SerahBaki;
|
||||
use App\WTD;
|
||||
use App\StokAudit1;
|
||||
@@ -2363,19 +2364,84 @@ class AdminPageController extends Controller
|
||||
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$request->kodcaw)->first();
|
||||
|
||||
$latestbatch = SerahBaki::on($cawangan['mysql'])->where('norujukan','baru')->get()->toArray();
|
||||
//$latestbatch = SerahBaki::on($cawangan['mysql'])->where('norujukan','baru')->get()->toArray();
|
||||
//new added
|
||||
$serahBaki = SerahBaki::on($cawangan['mysql'])
|
||||
->where('norujukan', 'baru')
|
||||
->get();
|
||||
|
||||
$allBatchNo = $serahBaki->pluck('batchno')->unique()->toArray();
|
||||
|
||||
$wtddraftData = WTDDraft::on('mysql7')
|
||||
->selectRaw("
|
||||
batchno_serah,
|
||||
YEAR(t_jual) as tahun,
|
||||
GROUP_CONCAT(
|
||||
DISTINCT MONTH(t_jual)
|
||||
ORDER BY MONTH(t_jual)
|
||||
SEPARATOR ','
|
||||
) as bulan
|
||||
")
|
||||
->where('kodcaw', $request->kodcaw)
|
||||
->whereIn('batchno_serah', $allBatchNo)
|
||||
->groupBy('batchno_serah', DB::raw('YEAR(t_jual)'))
|
||||
->get()
|
||||
->groupBy('batchno_serah')
|
||||
->map(function ($rows) {
|
||||
return $rows->map(function ($row) {
|
||||
return [
|
||||
'tahun' => $row->tahun,
|
||||
'bulan' => $row->bulan
|
||||
];
|
||||
})->values();
|
||||
});
|
||||
|
||||
$finalData = $serahBaki->map(function ($item) use ($wtddraftData) {
|
||||
$batchno = $item->batchno;
|
||||
|
||||
$tahun = null;
|
||||
$bulan = [];
|
||||
|
||||
if (!empty($wtddraftData[$batchno])) {
|
||||
// ambil tahun pertama (kebiasaannya satu tahun sahaja)
|
||||
$tahun = $wtddraftData[$batchno][0]['tahun'];
|
||||
|
||||
// convert string "2,3,4,5" → array
|
||||
$bulan = explode(',', $wtddraftData[$batchno][0]['bulan']);
|
||||
}
|
||||
|
||||
return [
|
||||
'batchno' => $batchno,
|
||||
'norujukan' => $item->norujukan,
|
||||
'tarikh' => $item->tarikh,
|
||||
't_jual' => $item->t_jual,
|
||||
'baki' => $item->baki,
|
||||
't_htr_ag' => $item->t_htr_ag,
|
||||
'aktif' => $item->aktif,
|
||||
'tahun' => $tahun,
|
||||
'bulan' => implode(',',$bulan),
|
||||
// field lain kekal
|
||||
];
|
||||
});
|
||||
|
||||
$finalDataArray = $finalData->toArray();
|
||||
//end new added
|
||||
|
||||
$batch_old = WTDDraft::on('mysql7')->select('kodcaw')->where('batchno_serah',0)->where('kodcaw',$request->kodcaw)
|
||||
->groupBy('kodcaw')->get();
|
||||
|
||||
$batch_old_noruj = WTDDraft::on('mysql7')->where('batchno_serah',0)->where('kodcaw',$request->kodcaw)->pluck('norujukan');
|
||||
$lelong_data = Lelong::on($cawangan['mysql'])->whereIn('norujukan',$batch_old_noruj)->get();
|
||||
|
||||
|
||||
foreach($batch_old as $index=>$bo)
|
||||
{
|
||||
array_push($latestbatch,['recno' => 0,'norujukan' => 'lama','batchno' => 0,'baki' => $lelong_data->sum('baki'),'aktif' => 1]);
|
||||
//array_push($latestbatch,['recno' => 0,'norujukan' => 'lama','batchno' => 0,'baki' => $lelong_data->sum('baki'),'aktif' => 1]);
|
||||
array_push($finalDataArray,['recno' => 0,'norujukan' => 'lama','batchno' => 0,'baki' => $lelong_data->sum('baki'),'aktif' => 1]);
|
||||
|
||||
}
|
||||
|
||||
$data = $this->paginate($latestbatch,8);
|
||||
//$data = $this->paginate($latestbatch,8);
|
||||
$data = $this->paginate($finalDataArray,8);
|
||||
|
||||
return response()->json($data,200);
|
||||
|
||||
@@ -2697,8 +2763,9 @@ class AdminPageController extends Controller
|
||||
't_update' => $current->toDateString()));
|
||||
}
|
||||
|
||||
$serahbakiupdate = SerahBaki::on($cawangan['mysql'])->where('batchno',$batchno)->update(array('aktif' => 1,'t_jual' => $current->toDateString(),'nopelanggan' => $request->nocek));;
|
||||
|
||||
//$serahbakiupdate = SerahBaki::on($cawangan['mysql'])->where('batchno',$batchno)->update(array('aktif' => 1,'t_jual' => $current->toDateString(),'nopelanggan' => $request->nocek));;
|
||||
$serahbakiupdate = SerahBaki::on($cawangan['mysql'])->where('batchno',$batchno)->update(array('aktif' => 1,'t_jual' => $current->toDateString(),'nopelanggan' => $request->nocek,'t_htr_ag' => $request->tarikhAG));
|
||||
|
||||
return response()->json('success',200);
|
||||
|
||||
}catch (\Throwable $e){
|
||||
@@ -3080,34 +3147,83 @@ class AdminPageController extends Controller
|
||||
|
||||
|
||||
|
||||
public function BilanganPengadai(Request $request){
|
||||
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$request->kodcaw)->first();
|
||||
|
||||
|
||||
$gadai = Gadai::on($cawangan['mysql'])
|
||||
->where([['t_gadai','>=',$request->mula],['t_gadai','<=',$request->hingga]])
|
||||
->where('sttebus','=','')
|
||||
->select('nokp','sttebus')
|
||||
->groupBy('nokp')->get();
|
||||
|
||||
$gadai_pluck_nokp = $gadai->pluck('nokp');
|
||||
|
||||
if($request->jenis == 'pekerja'){
|
||||
|
||||
$customers = Customer::on('mysql7')
|
||||
->selectRaw('COUNT(*) AS bilangangadai')
|
||||
->addSelect(DB::connection($cawangan['mysql'])
|
||||
->raw('keterangan as keterangan'))
|
||||
->whereIn('kpbaru', $gadai_pluck_nokp)
|
||||
->orWhereIn('kplama', $gadai_pluck_nokp)
|
||||
->join('pekerjaan','customer.kodkerja','=','pekerjaan.kodkerja')
|
||||
->groupBy('pekerjaan.kodkerja')
|
||||
->get();
|
||||
|
||||
public function BilanganPengadai(Request $request)
|
||||
{
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw', $request->kodcaw)->first();
|
||||
|
||||
$gadai = Gadai::on($cawangan['mysql'])
|
||||
->where('t_gadai', '>=', $request->mula)
|
||||
->where('t_gadai', '<=', $request->hingga)
|
||||
->where('sttebus', '')
|
||||
->select('nokp')
|
||||
->groupBy('nokp')
|
||||
->get();
|
||||
|
||||
$gadai_pluck_nokp = $gadai->pluck('nokp');
|
||||
$jenis = $request->jenis;
|
||||
$filter_value = $request->value ?? null;
|
||||
|
||||
$customers = [];
|
||||
|
||||
if ($jenis === 'pekerja') {
|
||||
$customers = Customer::on('mysql7')
|
||||
->selectRaw('pekerjaan.keterangan, COUNT(*) AS bilangangadai')
|
||||
->whereIn('kpbaru', $gadai_pluck_nokp)
|
||||
->orWhereIn('kplama', $gadai_pluck_nokp)
|
||||
->join('pekerjaan', 'customer.kodkerja', '=', 'pekerjaan.kodkerja')
|
||||
->groupBy('pekerjaan.kodkerja')
|
||||
->get();
|
||||
|
||||
} elseif ($jenis === 'agama') {
|
||||
$agamaMap = [
|
||||
'01' => 'Islam',
|
||||
'02' => 'Hindu',
|
||||
'03' => 'Buddha',
|
||||
'04' => 'Kristian',
|
||||
'05' => 'Lain-lain',
|
||||
'' => 'Tiada Data',
|
||||
];
|
||||
|
||||
$query = Customer::on('mysql7')
|
||||
->selectRaw('kodugama as keterangan, COUNT(*) as bilangangadai')
|
||||
->whereIn('kpbaru', $gadai_pluck_nokp)
|
||||
->orWhereIn('kplama', $gadai_pluck_nokp);
|
||||
|
||||
if ($filter_value) {
|
||||
$query->where('kodugama', $filter_value); // contoh: '01'
|
||||
}
|
||||
|
||||
|
||||
|
||||
$customers = $query->groupBy('kodugama')->get();
|
||||
|
||||
foreach ($customers as $customer) {
|
||||
$customer->keterangan = $agamaMap[$customer->keterangan] ?? $customer->keterangan;
|
||||
}
|
||||
|
||||
} elseif ($jenis === 'bangsa') {
|
||||
$bangsaMap = [
|
||||
'M' => 'Melayu',
|
||||
'C' => 'Cina',
|
||||
'I' => 'India',
|
||||
'L' => 'Lain-lain',
|
||||
'' => 'Tiada Data',
|
||||
];
|
||||
|
||||
$query = Customer::on('mysql7')
|
||||
->selectRaw('bangsa as keterangan, COUNT(*) as bilangangadai')
|
||||
->whereIn('kpbaru', $gadai_pluck_nokp)
|
||||
->orWhereIn('kplama', $gadai_pluck_nokp);
|
||||
|
||||
if ($filter_value) {
|
||||
$query->where('bangsa', $filter_value); // contoh: 'M'
|
||||
}
|
||||
|
||||
$customers = $query->groupBy('bangsa')->get();
|
||||
|
||||
foreach ($customers as $customer) {
|
||||
$customer->keterangan = $bangsaMap[$customer->keterangan] ?? $customer->keterangan;
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json($customers);
|
||||
}
|
||||
|
||||
@@ -3708,16 +3824,16 @@ class AdminPageController extends Controller
|
||||
|
||||
$get_imbangduga = imbangdugabackup::on($cawangan['mysql'])->where('tarikh', $lastDayOfYear)->first();
|
||||
$get_imbangduga = optional($get_imbangduga)->toArray() ?? [];
|
||||
if(empty($get_imbangduga)){
|
||||
$requestData = new Request([
|
||||
'tarikh' => $request->tarikh,
|
||||
'kodcaw' => $kodcaw,
|
||||
]);
|
||||
$exception_case = $this->AkruKeuntunganSebenar($requestData);
|
||||
}
|
||||
// if(empty($get_imbangduga)){
|
||||
// $requestData = new Request([
|
||||
// 'tarikh' => $request->tarikh,
|
||||
// 'kodcaw' => $kodcaw,
|
||||
// ]);
|
||||
// $exception_case = $this->AkruKeuntunganSebenar($requestData);
|
||||
// }
|
||||
|
||||
$backdate_keun_sebenar += isset($get_imbangduga['keun_sebenar']) ? $get_imbangduga['keun_sebenar'] : 0;
|
||||
$backdate_keun_sebenar += $exception_case;
|
||||
$backdate_keun_sebenar += (float) ($exception_case ?? 0);
|
||||
$recentDate->subYear()->startOfYear();
|
||||
}
|
||||
|
||||
@@ -3906,4 +4022,222 @@ class AdminPageController extends Controller
|
||||
'result' => $status === 'completed' ? $result : null,
|
||||
]);
|
||||
}
|
||||
|
||||
//function wtd baru
|
||||
public function janaSimulasiWTD(Request $request)
|
||||
{
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw', '=', $request->kodcaw)->first();
|
||||
|
||||
//listing sag belum tuntut cwgn
|
||||
$sag_cwgn = collect(
|
||||
Lelong::on($cawangan['mysql'])
|
||||
->selectRaw('norujukan')
|
||||
->whereYear('t_jual', $request->tahun)
|
||||
->whereNull('trkhtuntut')
|
||||
->where('baki', '>', 0)
|
||||
->pluck('norujukan') // lebih bersih
|
||||
);
|
||||
|
||||
//listing sag blocked
|
||||
$sag_online = collect(
|
||||
WTDDraft::on('mysql7')
|
||||
->selectRaw('norujukan')
|
||||
->where('kodcaw', '=', $request->kodcaw)
|
||||
->pluck('norujukan')
|
||||
);
|
||||
//dd($sag_online);
|
||||
//filter sag yg tk wujud dlm wtd_draft
|
||||
$filtersag = $sag_cwgn->diff($sag_online);
|
||||
|
||||
//query baru
|
||||
$tarikh_belum_tuntut = Lelong::on($cawangan['mysql'])
|
||||
->selectRaw('
|
||||
MONTH(t_jual) as bulan,
|
||||
SUM(pinjaman) as pembiayaan,
|
||||
ABS(SUM(baki)) as baki,
|
||||
COUNT(DISTINCT norujukan) as jumlah_norujukan,
|
||||
kodcaw
|
||||
')
|
||||
->whereIn('norujukan', $filtersag)
|
||||
->groupBy('bulan', 'kodcaw')
|
||||
->orderBy('bulan')
|
||||
->get();
|
||||
|
||||
$tarikh_belum_tuntut = $tarikh_belum_tuntut->map(function ($item) {
|
||||
$item->bulan = \Carbon\Carbon::create()->month($item->bulan)->format('F');
|
||||
return $item;
|
||||
});
|
||||
|
||||
return response()->json($tarikh_belum_tuntut);
|
||||
}
|
||||
|
||||
public function RekodSimulasiWTD(Request $request)
|
||||
{
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw', '=', $request->kodcaw)->first();
|
||||
|
||||
$rekod_simulasi = Lelong::on($cawangan['mysql'])
|
||||
->join('gadai','lelong.norujukan','=','gadai.norujukan')
|
||||
->selectRaw('ABS(lelong.baki) as baki, lelong.t_lelong, lelong.pinjaman, lelong.norujukan, gadai.nokp')
|
||||
->whereMonth('lelong.t_jual', $request->month)
|
||||
->whereYear('lelong.t_jual', $request->year)
|
||||
->whereNull('lelong.trkhtuntut')
|
||||
->where('lelong.baki', '>', 0)
|
||||
->get();
|
||||
|
||||
return response()->json($rekod_simulasi);
|
||||
}
|
||||
|
||||
public function prosesSimulasiWTD(Request $request)
|
||||
{
|
||||
$proses = $request->input;
|
||||
|
||||
// dd($proses, $cawangan);
|
||||
|
||||
$baki = 0;
|
||||
$jumlahPembiayaan = 0;
|
||||
$simulasi = WTDSimulasi::max('simulasi')+1;
|
||||
|
||||
foreach ($proses as $item) {
|
||||
WTDSimulasi::create([
|
||||
'bulan' => $item['bulan'],
|
||||
'tahun' => $item['tahun'],
|
||||
'kodcaw' => $item['kodcaw'],
|
||||
'jumlah_sag' => $item['jumlah_sag'],
|
||||
'pembiayaan'=> $item['pembiayaan'],
|
||||
'baki'=> $item['baki'],
|
||||
'simulasi' => $simulasi,
|
||||
]);
|
||||
$baki += $item['baki'];
|
||||
$jumlahPembiayaan = $item['pembiayaan'];
|
||||
}
|
||||
|
||||
return response()->json(['status' => 'success','simulasi' => $simulasi,'baki' => $baki,'pinjaman' => $jumlahPembiayaan]);
|
||||
}
|
||||
|
||||
public function pengesahanSimulasiWTD(Request $request)
|
||||
{
|
||||
// Decode the JSON records from the request
|
||||
$records = json_decode($request->records, true);
|
||||
|
||||
// Retrieve and clean 'kodcaw' from the request
|
||||
$kodcaw = $request->kodcaw;
|
||||
$kodcaw_clean = str_replace('"', '', $kodcaw);
|
||||
|
||||
// Get the database connection for the branch (cawangan)
|
||||
$cawangan = Cawangan::where('kodcaw', $kodcaw_clean)->first();
|
||||
|
||||
// Check if 'Cawangan' exists
|
||||
if (!$cawangan) {
|
||||
return response()->json(['status' => 'error', 'message' => 'Invalid branch code (kodcaw).'], 404);
|
||||
}
|
||||
|
||||
$cawangan_connection = $cawangan->mysql;
|
||||
|
||||
// Get the latest batch number and increment it
|
||||
$latestBatch = SerahBaki::on($cawangan_connection)->max('batchno') + 1;
|
||||
|
||||
// Initialize total variables
|
||||
$totalPembiayaan = 0;
|
||||
$totalBaki = 0;
|
||||
|
||||
|
||||
try {
|
||||
// Iterate through the records and save them to the WTDDraft table
|
||||
foreach ($records as $record) {
|
||||
// Check if 'bulan' and 'tahun' exist in the record
|
||||
if (!isset($record['bulan']) || !isset($record['tahun'])) {
|
||||
return response()->json(['status' => 'error', 'message' => 'Missing bulan or tahun in records.'], 400);
|
||||
}
|
||||
$month = DateTime::createFromFormat('F', $record["bulan"])->format('n');
|
||||
|
||||
|
||||
// Query norujukan records from the database
|
||||
$query_norujukan = Lelong::on($cawangan_connection)
|
||||
->join('gadai', 'lelong.norujukan', '=', 'gadai.norujukan')
|
||||
->selectRaw('ABS(lelong.baki) as baki, lelong.t_lelong, lelong.pinjaman, lelong.norujukan, gadai.nokp, lelong.t_jual')
|
||||
->whereMonth('lelong.t_jual', $month)
|
||||
->whereYear('lelong.t_jual', $record["tahun"])
|
||||
->whereNull('lelong.trkhtuntut')
|
||||
->where('lelong.baki', '>', 0)
|
||||
->get();
|
||||
|
||||
// Save each record to the WTDDraft table
|
||||
foreach ($query_norujukan as $query) {
|
||||
$wtddraft = new WTDDraft();
|
||||
$wtddraft->nokp = $query['nokp'];
|
||||
$wtddraft->kodcaw = $kodcaw_clean;
|
||||
$wtddraft->norujukan = $query['norujukan'];
|
||||
$wtddraft->t_jual = $query['t_jual'];
|
||||
$wtddraft->t_gadai = $query['t_gadai'] ?? null; // Optional: ensure 't_gadai' exists
|
||||
$wtddraft->t_lelong = $query['t_lelong'];
|
||||
$wtddraft->batchno_serah = $latestBatch;
|
||||
$wtddraft->save();
|
||||
}
|
||||
|
||||
// Accumulate totals
|
||||
$totalPembiayaan += $record['pembiayaan'] ?? 0;
|
||||
$totalBaki += $record['baki'] ?? 0;
|
||||
}
|
||||
|
||||
// Create a new record in the SerahBaki table
|
||||
SerahBaki::on($cawangan_connection)->create([
|
||||
'norujukan' => 'baru',
|
||||
'batchno' => $latestBatch,
|
||||
'hargajual' => 0.00,
|
||||
'pinjaman' => $totalPembiayaan,
|
||||
'upah' => 0.00,
|
||||
'cajlel' => 0.00,
|
||||
'gst_cl' => 0.00,
|
||||
'gst_hj' => 0.00,
|
||||
'baki' => $totalBaki,
|
||||
'tarikh' => Carbon::now()->toDateString(),
|
||||
't_jual' => Carbon::now()->toDateString(),
|
||||
'nopelanggan' => '',
|
||||
'aktif' => 0,
|
||||
]);
|
||||
|
||||
// Return a success response with the new batch number
|
||||
return response()->json(['status' => 'success', 'batchno' => $latestBatch], 200);
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
// Log the error and return a failure response
|
||||
Log::error($e->getMessage());
|
||||
Log::error($e->getLine());
|
||||
return response()->json(['status' => 'error', 'message' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function simulasiToDraft(Request $request)
|
||||
{
|
||||
$bulan = $request->bulan;
|
||||
|
||||
if (!$bulan || count($bulan) === 0) {
|
||||
return response()->json(['error' => 'Sila pilih sekurang-kurangnya satu bulan.'], 400);
|
||||
}
|
||||
|
||||
$simulasi = WTDSimulasi::whereIn('bulan', $bulan)->get();
|
||||
|
||||
if ($simulasi->isEmpty()) {
|
||||
return response()->json(['error' => 'Tiada data untuk bulan yang dipilih.'], 404);
|
||||
}
|
||||
|
||||
// foreach ($simulasi as $data) {
|
||||
// WTDDraft::create([
|
||||
// 'nokp' => $data->nokp ?? null,
|
||||
// 'kodcaw' => $data->kodcaw ?? null,
|
||||
// 'norujukan' => $data->norujukan ?? null,
|
||||
// 't_jual' => $data->t_jual ?? null,
|
||||
// 't_gadai' => $data->t_gadai ?? null,
|
||||
// 't_lelong' => $data->t_lelong ?? null,
|
||||
// 'batchno_serah' => $data->simulasi, // Simpan sebagai rujukan
|
||||
// ]);
|
||||
// }
|
||||
|
||||
//dd($bulan, $simulasi);
|
||||
|
||||
return response()->json(['message' => 'Data berjaya dipindahkan ke WTD Draft!']);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Audit;
|
||||
use App\Polis;
|
||||
use App\Cawangan;
|
||||
use App\LookupAlasan;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class BarangkesController extends Controller
|
||||
{
|
||||
public function LaporanBarangKes(Request $request)
|
||||
{
|
||||
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw', $request->kodcaw)->first();
|
||||
|
||||
if (!$cawangan) {
|
||||
return response()->json(['error' => 'Invalid kodcaw'], 403);
|
||||
}
|
||||
|
||||
$query = DB::connection($cawangan['mysql'])->table('palsu')
|
||||
->select([
|
||||
'tarikh',
|
||||
'norujukan',
|
||||
'nota',
|
||||
'pembiayaan',
|
||||
'nilaimarhun',
|
||||
'jbg',
|
||||
'untung',
|
||||
'untungonepercent',
|
||||
'untungcajlain'
|
||||
])
|
||||
->whereBetween('tarikh', [$request->tarikh_mula, $request->tarikh_akhir]);
|
||||
|
||||
$result = $query->get();
|
||||
|
||||
return response()->json($result);
|
||||
}
|
||||
}
|
||||
@@ -462,7 +462,7 @@ class CallCenterController extends Controller
|
||||
if($fasa == 1){
|
||||
|
||||
$datagadai = Gadai::on($cawangan['mysql'])
|
||||
->where([['t_matang','<=',$monthscoming],['lelong_tawarruq','=',1],['tempoh','>=',5],['tempoh','<=',5.5],['tagpalsu','=',0],['sttebus','=',''],['taglel','=',0],['tagnotis','=',0]])
|
||||
->where([['t_matang','<=',$monthscoming],['lelong_tawarruq','=',1],['tempoh','>=',5],['tempoh','<=',7],['tagpalsu','=',0],['sttebus','=',''],['taglel','=',0],['tagnotis','=',0]])
|
||||
->orderBy('t_gadai', 'ASC')
|
||||
->orderBy('sirig', 'ASC');
|
||||
// ->get();
|
||||
@@ -470,7 +470,7 @@ class CallCenterController extends Controller
|
||||
|
||||
}elseif($fasa == 2){
|
||||
$datagadai = Gadai::on($cawangan['mysql'])
|
||||
->where([['t_matang1','<=',$monthscoming],['lelong_tawarruq','=',0],['tempoh','>=',11],['tempoh','<=',11.5],['tagpalsu','=',0],['sttebus','=',''],['taglel','=',0],['tagnotis','=',0]])
|
||||
->where([['t_matang1','<=',$monthscoming],['lelong_tawarruq','=',0],['tempoh','>=',11],['tagpalsu','=',0],['sttebus','=',''],['taglel','=',0],['tagnotis','=',0]])
|
||||
->orderBy('t_gadai', 'ASC')
|
||||
->orderBy('sirig', 'ASC');
|
||||
// ->get();
|
||||
@@ -510,12 +510,12 @@ class CallCenterController extends Controller
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
|
||||
if($fasa == 1){
|
||||
$datagadai = Gadai::on($cawangan['mysql'])
|
||||
->where([['t_matang','<=',$monthscoming],['lelong_tawarruq','=',1],['tempoh','>=',5],['tempoh','<=',5.5],['tagpalsu','=',0],['sttebus','=',''],['taglel','=',0],['tagnotis','=',0]])
|
||||
->where([['t_matang','<=',$monthscoming],['lelong_tawarruq','=',1],['tempoh','>=',5],['tempoh','<=',7],['tagpalsu','=',0],['sttebus','=',''],['taglel','=',0],['tagnotis','=',0]])
|
||||
->orderBy('t_gadai', 'ASC')
|
||||
->orderBy('sirig', 'ASC');
|
||||
}elseif($fasa == 2){
|
||||
$datagadai = Gadai::on($cawangan['mysql'])
|
||||
->where([['t_matang1','<=',$monthscoming],['lelong_tawarruq','=',0],['tempoh','>=',11],['tempoh','<=',11.5],['tagpalsu','=',0],['sttebus','=',''],['taglel','=',0]])
|
||||
->where([['t_matang1','<=',$monthscoming],['lelong_tawarruq','=',0],['tempoh','>=',11],['tagpalsu','=',0],['sttebus','=',''],['taglel','=',0]])
|
||||
->orderBy('t_gadai', 'ASC')
|
||||
->orderBy('sirig', 'ASC');
|
||||
}
|
||||
@@ -530,7 +530,7 @@ class CallCenterController extends Controller
|
||||
$caw_notis->kodcaw = $kodcaw;
|
||||
$caw_notis->peringatan = 1;
|
||||
$caw_notis->daritempoh = 5;
|
||||
$caw_notis->hinggatempoh = 5;
|
||||
$caw_notis->hinggatempoh = 7;
|
||||
$caw_notis->status = 1;
|
||||
$caw_notis->save();
|
||||
|
||||
@@ -540,7 +540,7 @@ class CallCenterController extends Controller
|
||||
$caw_notis->kodcaw = $kodcaw;
|
||||
$caw_notis->peringatan = 1;
|
||||
$caw_notis->daritempoh = 11;
|
||||
$caw_notis->hinggatempoh = 11;
|
||||
$caw_notis->hinggatempoh = 12;
|
||||
$caw_notis->status = 1;
|
||||
$caw_notis->save();
|
||||
|
||||
@@ -599,7 +599,7 @@ class CallCenterController extends Controller
|
||||
$notis = Notis::create([
|
||||
'tarikh_notis' => $tarikh_notis,
|
||||
'daritempoh' => 5,
|
||||
'hinggatempoh' => 5,
|
||||
'hinggatempoh' => 7,
|
||||
'sts_notis' => 1,
|
||||
'peringatan' => 1
|
||||
]);
|
||||
@@ -607,7 +607,7 @@ class CallCenterController extends Controller
|
||||
$notis = Notis::create([
|
||||
'tarikh_notis' => $tarikh_notis,
|
||||
'daritempoh' => 11,
|
||||
'hinggatempoh' => 11,
|
||||
'hinggatempoh' => 12,
|
||||
'sts_notis' => 1,
|
||||
'peringatan' => 1
|
||||
]);
|
||||
@@ -1564,4 +1564,162 @@ class CallCenterController extends Controller
|
||||
}
|
||||
return response()->json($cawnotis_all);
|
||||
}
|
||||
|
||||
public function rekodgadai(Request $request)
|
||||
{
|
||||
$nokp = $request->nokp;
|
||||
$kodcaw = $request->kodcaw;
|
||||
// Dapatkan maklumat cawangan
|
||||
$cawangan = Cawangan::on('mysql7')
|
||||
->where('kodcaw', $kodcaw)
|
||||
->first();
|
||||
|
||||
if (!$cawangan || empty($cawangan->mysql)) {
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Cawangan tidak dijumpai atau konfigurasi DB tidak lengkap',
|
||||
'data' => []
|
||||
], 404);
|
||||
}
|
||||
|
||||
try {
|
||||
// Query rekod gadai dari DB cawangan yang betul
|
||||
$gadai = Gadai::on($cawangan->mysql)
|
||||
->where('nokp', $nokp)
|
||||
->get();
|
||||
|
||||
return response()->json([
|
||||
'status' => !$gadai->isEmpty(),
|
||||
'message' => $gadai->isEmpty() ? 'Tiada rekod gadai' : 'Rekod gadai dijumpai',
|
||||
'data' => $gadai
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Ralat semasa ambil data: ' . $e->getMessage(),
|
||||
'data' => []
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function rekodgadaiBatch(Request $request)
|
||||
{
|
||||
$nokpList = $request->input('nokp_list', []);
|
||||
$kodcaw = $request->input('kodcaw');
|
||||
|
||||
if (empty($nokpList) || empty($kodcaw)) {
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Parameter tidak lengkap',
|
||||
'data' => []
|
||||
], 400);
|
||||
}
|
||||
|
||||
$cawangan = Cawangan::on('mysql7')
|
||||
->where('kodcaw', $kodcaw)
|
||||
->first();
|
||||
|
||||
if (!$cawangan || empty($cawangan->mysql)) {
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Cawangan tidak dijumpai',
|
||||
'data' => []
|
||||
], 404);
|
||||
}
|
||||
|
||||
try {
|
||||
$gadai = Gadai::on($cawangan->mysql)
|
||||
->whereIn('nokp', $nokpList)
|
||||
->get();
|
||||
|
||||
return response()->json([
|
||||
'status' => !$gadai->isEmpty(),
|
||||
'message' => $gadai->isEmpty() ? 'Tiada rekod gadai' : 'Rekod gadai dijumpai',
|
||||
'data' => $gadai
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Ralat semasa ambil data: ' . $e->getMessage(),
|
||||
'data' => []
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public function customerUpdate($nokp,Request $request){
|
||||
$poskod = Poskod::on('mysql7')->where('poskod','=',$request->poskod)->first();
|
||||
$customer_update = Customer::on('mysql7')
|
||||
->where('kplama','=',$nokp)
|
||||
->orWhere('kpbaru','=',$nokp)
|
||||
->update(array(
|
||||
'nota_arcc'=>$request->nota_arcc,
|
||||
));
|
||||
|
||||
return response()->json($customer_update, 200);
|
||||
}
|
||||
|
||||
|
||||
public function customerUpdateKaunter($nokp,$kodcaw, Request $request){
|
||||
$current = Carbon::now();
|
||||
|
||||
DB::connection('mysql7')->beginTransaction();
|
||||
|
||||
try{
|
||||
$poskod = Poskod::on('mysql7')->where('poskod','=',$request->poskod)->first();
|
||||
|
||||
$customer_info = DB::connection('mysql7')->table('customer')
|
||||
->select('kodcaw','kodkerja','nota_pekerjaan','nota_arcc','tarikhdaftar','nopelanggan','kpbaru','kplama','nama','t_lahir','jantina','poskod')
|
||||
->where('kplama','=',$nokp)
|
||||
->orWhere('kpbaru','=',$nokp)
|
||||
->get()->toArray();
|
||||
|
||||
|
||||
$old_data = json_encode($customer_info);
|
||||
|
||||
$customer_update = Customer::on('mysql7')
|
||||
->where('kplama','=',$nokp)
|
||||
->orWhere('kpbaru','=',$nokp)
|
||||
->update(array(
|
||||
'nota_arcc' => $request->nota_arcc,
|
||||
));
|
||||
|
||||
if($customer_update)
|
||||
{
|
||||
$customer_info_new = DB::connection('mysql7')->table('customer')
|
||||
->select('kodcaw','kodkerja','nota_pekerjaan','nota_arcc','tarikhdaftar','nopelanggan','kpbaru','kplama','nama','t_lahir','jantina','alamat1','poskod')
|
||||
->where('kplama','=',$nokp)
|
||||
->orWhere('kpbaru','=',$nokp)
|
||||
->get()->toArray();
|
||||
|
||||
$new_data = json_encode($customer_info_new);
|
||||
|
||||
$audit_customer = DB::connection('mysql7')
|
||||
->table('audit_customer')
|
||||
->insert([
|
||||
'username' => $request->namateller,
|
||||
'old_data' => $old_data,
|
||||
'new_data' => $new_data,
|
||||
'kodcaw' => $customer_info[0]->kodcaw,
|
||||
'created_at' => Carbon::now()->toDateTimeString(),
|
||||
'updated_at' => Carbon::now()->toDateTimeString(),
|
||||
'customer_name' => $customer_info[0]->nama,
|
||||
'customer_nokp' => $nokp,
|
||||
]);
|
||||
}
|
||||
|
||||
DB::connection('mysql7')->commit();
|
||||
|
||||
return response()->json($customer_update, 200);
|
||||
|
||||
}catch (\Exception $e) {
|
||||
DB::connection('mysql7')->rollback();
|
||||
return response()->json($e->getMessage(),400);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,6 +14,7 @@ use App\Blacklist;
|
||||
use App\AuditCustomer;
|
||||
use Illuminate\Http\Request;
|
||||
use App\TuntutBaki;
|
||||
use App\Anggota;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
@@ -23,11 +24,27 @@ use DB;
|
||||
class CustomerController extends Controller
|
||||
{
|
||||
|
||||
public function showAllCustomers(){
|
||||
$customer = Customer::on('mysql7')->get();
|
||||
public function showAllCustomers(Request $request)
|
||||
{
|
||||
$nama = $request->query('nama');
|
||||
$kodcaw = $request->query('kodcaw');
|
||||
|
||||
$query = Customer::on('mysql7');
|
||||
|
||||
if ($nama) {
|
||||
$query->where('nama', 'LIKE', '%' . $nama . '%');
|
||||
}
|
||||
|
||||
if ($kodcaw) {
|
||||
$query->where('kodcaw', $kodcaw);
|
||||
}
|
||||
|
||||
$customer = $query->get();
|
||||
|
||||
return response()->json($customer);
|
||||
}
|
||||
|
||||
|
||||
public function getLatestCustomer($kodcaw){
|
||||
$customer = Customer::on('mysql7')->orderBy('tarikhdaftar','desc')->orderBy('nosiri','desc')->first();
|
||||
|
||||
@@ -346,6 +363,7 @@ class CustomerController extends Controller
|
||||
'nota'=>$request->nota,
|
||||
'kodkerja'=>$request->kodkerja,
|
||||
'nota_pekerjaan'=>$request->nota_pekerjaan,
|
||||
// 'nota_arcc'=>$request->nota_arcc,
|
||||
'tujuangadai'=>$request->tujuangadai
|
||||
]);
|
||||
|
||||
@@ -374,13 +392,40 @@ class CustomerController extends Controller
|
||||
'kodnegeri' => $poskod['kodnegeri'],
|
||||
'kodkerja'=>$request->kodkerja,
|
||||
'nota_pekerjaan'=>$request->nota_pekerjaan,
|
||||
// 'nota_arcc'=>$request->nota_arcc,
|
||||
'telefon' => $request->telefon1,
|
||||
'telefon2' => $request->telefon2
|
||||
'telefon2' => $request->telefon2,
|
||||
));
|
||||
|
||||
return response()->json($customer_update, 200);
|
||||
}
|
||||
|
||||
public function assignAnggota($noic, Request $request)
|
||||
{
|
||||
// Semak sama ada pelanggan wujud
|
||||
$customer = Customer::on('mysql7')
|
||||
->where('kpbaru', $noic)
|
||||
->orWhere('kplama', $noic)
|
||||
->first();
|
||||
|
||||
if (!$customer) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Pelanggan tidak dijumpai.'
|
||||
], 404);
|
||||
}
|
||||
|
||||
// Kemaskini tag_anggota
|
||||
$customer->tag_anggota = 1;
|
||||
$customer->save();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Tag anggota berjaya dikemaskini.',
|
||||
'data' => $customer
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function customerUpdateKaunter($nokp,$kodcaw, Request $request){
|
||||
$current = Carbon::now();
|
||||
|
||||
@@ -408,6 +453,7 @@ class CustomerController extends Controller
|
||||
'kodkerja' => $request->kodkerja,
|
||||
// 'nota_pekerjaan' => $request->nota_pekerjaan,
|
||||
'nota_pekerjaan' => $request->kodkerja === '6' ? $request->nota_pekerjaan : null,
|
||||
// 'nota_arcc' => $request->nota_arcc,
|
||||
'noakaun' => $request->noakaun,
|
||||
'nota' => $request->nota,
|
||||
'alamat1' => $request->alamat,
|
||||
@@ -485,6 +531,7 @@ class CustomerController extends Controller
|
||||
'kodbank' => $request->kodbank,
|
||||
'kodkerja' => $request->kodkerja,
|
||||
'nota_pekerjaan' => $request->nota_pekerjaan,
|
||||
// 'nota_arcc' => $request->nota_arcc,
|
||||
'noakaun' => $request->noakaun,
|
||||
'nota' => $request->nota,
|
||||
'nama' => $request->nama,
|
||||
@@ -805,6 +852,14 @@ class CustomerController extends Controller
|
||||
return response()->json($blacklist);
|
||||
}
|
||||
|
||||
public function anggotaKoperasi(Request $request){
|
||||
|
||||
$anggota = Anggota::where('noic',$request->noic)->first();
|
||||
|
||||
return response()->json($anggota);
|
||||
}
|
||||
|
||||
|
||||
public function showCustomerByEachCawangan($ic)
|
||||
{
|
||||
$cawangan_all = Cawangan::on('mysql7')->get();
|
||||
@@ -962,4 +1017,41 @@ class CustomerController extends Controller
|
||||
return json_encode(['status'=> 'success']);
|
||||
|
||||
}
|
||||
|
||||
public function searchByName(Request $request)
|
||||
{
|
||||
$nama = $request->query('nama');
|
||||
$kodcaw = $request->query('kodcaw');
|
||||
|
||||
$query = Customer::query();
|
||||
|
||||
if ($kodcaw) {
|
||||
$query->where('kodcaw', $kodcaw);
|
||||
}
|
||||
|
||||
if ($nama) {
|
||||
$query->where('nama', 'like', '%' . $nama . '%');
|
||||
}
|
||||
|
||||
$results = $query->get();
|
||||
|
||||
return response()->json($results);
|
||||
}
|
||||
|
||||
// public function createNotaArcc($kodcaw, Request $request)
|
||||
// {
|
||||
// $current = Carbon::now();
|
||||
|
||||
// $customer = Customer::on('mysql7')->create([
|
||||
// 'kodcaw' => $kodcaw,
|
||||
// 'tarikhdaftar' => $current->toDateString(),
|
||||
// 'nota_arcc' => $request->nota_arcc,
|
||||
// 'teller' => $request->teller,
|
||||
// 'aktif' => 'A'
|
||||
// ]);
|
||||
|
||||
// return response()->json($customer, 201);
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -120,6 +120,25 @@ class GadaiController extends Controller
|
||||
return response()->json($gadai_all);
|
||||
}
|
||||
|
||||
public function showOneGadaiByNorujukanKodcaw($kodcaw,$norujukan){
|
||||
|
||||
$cawangan_all = Cawangan::on('mysql7')
|
||||
->where('kodcaw','=',$kodcaw)
|
||||
->get();
|
||||
|
||||
$gadai_all = [];
|
||||
|
||||
foreach($cawangan_all as $index=>$cawangan){
|
||||
$gadai = Gadai::on($cawangan['mysql'])->where('norujukan','=',$norujukan)->get();
|
||||
if(sizeof($gadai) != 0){
|
||||
array_push($gadai_all,$gadai);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return response()->json($gadai_all);
|
||||
}
|
||||
|
||||
public function showOneGadaiByCawanganOnly($kodcaw,$tarikh){
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
|
||||
$gadai = Gadai::on($cawangan['mysql'])
|
||||
@@ -981,77 +1000,188 @@ class GadaiController extends Controller
|
||||
return response()->json($ansuran);
|
||||
}
|
||||
|
||||
public function getLaporanAnsuranUjrah($kodcaw,Request $request){
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
|
||||
|
||||
public function getLaporanAnsuranUjrah($kodcaw, Request $request)
|
||||
{
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw', '=', $kodcaw)->first();
|
||||
|
||||
$ansuran_data = Transaction::on('mysql7')
|
||||
->select('transaction.norujukan',
|
||||
'trans.tarikh_bayaran',
|
||||
'transaction.nokp',
|
||||
'transaction.kodcaw',
|
||||
'transaction.trans_type',
|
||||
'cust.nama','trans.bayaran_pembiayaan',
|
||||
'transaction.duit_masuk',
|
||||
'trans.bayaran_keuntungan',
|
||||
'transaction.teller',
|
||||
'trans.ujrah',
|
||||
'trans.onepercent')
|
||||
->leftJoin('transaksi_keuntungan as trans', function($join)
|
||||
{
|
||||
$join->on('transaction.norujukan', '=', 'trans.norujukan');
|
||||
$join->on('transaction.created_at', '=', 'trans.tarikh_bayaran');
|
||||
})
|
||||
->leftJoin('customer as cust', function($join)
|
||||
{
|
||||
$join->on('transaction.nokp', '=', 'cust.kpbaru');
|
||||
$join->orOn('transaction.nokp', '=', 'cust.kplama');
|
||||
})
|
||||
->where('transaction.kodcaw','=',$kodcaw)
|
||||
->where('transaction.trans_type','=','A')
|
||||
->whereDate('transaction.created_at', '>=', $request->mula)
|
||||
->whereDate('transaction.created_at', '<=', $request->akhir)
|
||||
->orderBy('transaction.teller')
|
||||
->orderBy('trans.tarikh_bayaran')
|
||||
->get();
|
||||
// Bina query asas dahulu
|
||||
$query = Transaction::on('mysql7')
|
||||
->select(
|
||||
'transaction.norujukan',
|
||||
'trans.tarikh_bayaran',
|
||||
'transaction.nokp',
|
||||
'transaction.kodcaw',
|
||||
'transaction.trans_type',
|
||||
'cust.nama',
|
||||
'trans.bayaran_pembiayaan',
|
||||
'transaction.duit_masuk',
|
||||
'trans.bayaran_keuntungan',
|
||||
'transaction.teller',
|
||||
'trans.ujrah',
|
||||
'trans.onepercent'
|
||||
)
|
||||
->leftJoin('transaksi_keuntungan as trans', function ($join) {
|
||||
$join->on('transaction.norujukan', '=', 'trans.norujukan');
|
||||
$join->on('transaction.created_at', '=', 'trans.tarikh_bayaran');
|
||||
})
|
||||
->leftJoin('customer as cust', function ($join) {
|
||||
$join->on('transaction.nokp', '=', 'cust.kpbaru');
|
||||
$join->orOn('transaction.nokp', '=', 'cust.kplama');
|
||||
})
|
||||
->where('transaction.kodcaw', '=', $kodcaw)
|
||||
->where('transaction.trans_type', '=', 'A')
|
||||
->whereDate('transaction.created_at', '>=', $request->mula)
|
||||
->whereDate('transaction.created_at', '<=', $request->akhir);
|
||||
|
||||
$ansuran = [];
|
||||
// Tambah filter berdasarkan jenis
|
||||
if ($request->jenis == 'arrahnpay') {
|
||||
$query->where('transaction.teller', '=', 'Online');
|
||||
} elseif ($request->jenis == 'kaunter') {
|
||||
$query->where('transaction.teller', '!=', 'Online');
|
||||
}
|
||||
|
||||
if($ansuran_data){
|
||||
foreach($ansuran_data as $index=>$ansuranData){
|
||||
$gadai = Gadai::on($cawangan['mysql'])->where('norujukan',$ansuranData['norujukan'])->first();
|
||||
// Dapatkan data selepas filter
|
||||
$ansuran_data = $query
|
||||
->orderBy('transaction.teller')
|
||||
->orderBy('trans.tarikh_bayaran')
|
||||
->get();
|
||||
|
||||
array_push($ansuran,[
|
||||
"norujukan" => $ansuranData['norujukan'],
|
||||
"tarikh_bayaran" => $ansuranData['tarikh_bayaran'],
|
||||
"nokp" => $ansuranData['nokp'],
|
||||
"kodcaw" => $ansuranData['kodcaw'],
|
||||
"trans_type" => $ansuranData['trans_type'],
|
||||
"nama" => $ansuranData['nama'],
|
||||
"tempoh" => $gadai['tempoh'],
|
||||
"bakipjm" => $gadai['bakipjm'],
|
||||
"bayaran_pembiayaan" => $ansuranData['bayaran_pembiayaan'],
|
||||
"duit_masuk" => $ansuranData['duit_masuk'],
|
||||
"bayaran_keuntungan" => $ansuranData['bayaran_keuntungan'],
|
||||
"teller" => $ansuranData['teller'],
|
||||
"ansuranujrah" => $ansuranData['ujrah'],
|
||||
"ansuranonepercent" => $ansuranData['onepercent'],
|
||||
"t_gadai" => $gadai['t_gadai'],
|
||||
]);
|
||||
}
|
||||
$ansuran = [];
|
||||
|
||||
// Loop data dan tambahkan maklumat dari jadual gadai
|
||||
if ($ansuran_data) {
|
||||
foreach ($ansuran_data as $index => $ansuranData) {
|
||||
$gadai = Gadai::on($cawangan['mysql'])->where('norujukan', $ansuranData['norujukan'])->first();
|
||||
|
||||
array_push($ansuran, [
|
||||
"norujukan" => $ansuranData['norujukan'],
|
||||
"tarikh_bayaran" => $ansuranData['tarikh_bayaran'],
|
||||
"nokp" => $ansuranData['nokp'],
|
||||
"kodcaw" => $ansuranData['kodcaw'],
|
||||
"trans_type" => $ansuranData['trans_type'],
|
||||
"nama" => $ansuranData['nama'],
|
||||
"tempoh" => optional($gadai)->tempoh,
|
||||
"bakipjm" => optional($gadai)->bakipjm,
|
||||
"bayaran_pembiayaan" => $ansuranData['bayaran_pembiayaan'],
|
||||
"duit_masuk" => $ansuranData['duit_masuk'],
|
||||
"bayaran_keuntungan" => $ansuranData['bayaran_keuntungan'],
|
||||
"teller" => $ansuranData['teller'],
|
||||
"ansuranujrah" => $ansuranData['ujrah'],
|
||||
"ansuranonepercent" => $ansuranData['onepercent'],
|
||||
"t_gadai" => optional($gadai)->t_gadai,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// Susun ikut teller dan tarikh bayar
|
||||
usort($ansuran, function ($a, $b) {
|
||||
$compare_teller = strcmp($a['teller'], $b['teller']);
|
||||
|
||||
if ($compare_teller === 0) {
|
||||
return strcmp($a['tarikh_bayaran'], $b['tarikh_bayaran']);
|
||||
}
|
||||
|
||||
usort($ansuran, function ($a, $b) {
|
||||
$compare_teller = strcmp($a['teller'], $b['teller']);
|
||||
return $compare_teller;
|
||||
});
|
||||
|
||||
if ($compare_teller === 0) {
|
||||
return strcmp($a['tarikh_bayaran'], $b['tarikh_bayaran']);
|
||||
}
|
||||
return response()->json($ansuran);
|
||||
}
|
||||
|
||||
return $compare_teller;
|
||||
});
|
||||
|
||||
return response()->json($ansuran);
|
||||
}
|
||||
// public function getLaporanAnsuranUjrah($kodcaw, Request $request)
|
||||
// {
|
||||
// $cawangan = Cawangan::on('mysql7')->where('kodcaw', '=', $kodcaw)->first();
|
||||
// $semuaDescpt = Transaction::on('mysql7')
|
||||
// ->where('kodcaw', '=', $kodcaw)
|
||||
// ->pluck('descpt');
|
||||
|
||||
// dd($semuaDescpt);
|
||||
|
||||
// Dapatkan connection cawangan
|
||||
// $connection = $cawangan['mysql'];
|
||||
|
||||
// // Mula query utama ansuran
|
||||
// $query = Transaction::on('mysql7')
|
||||
// ->select(
|
||||
// 'transaction.norujukan',
|
||||
// 'trans.tarikh_bayaran',
|
||||
// 'transaction.nokp',
|
||||
// 'transaction.kodcaw',
|
||||
// 'transaction.trans_type',
|
||||
// 'cust.nama',
|
||||
// 'trans.bayaran_pembiayaan',
|
||||
// 'transaction.duit_masuk',
|
||||
// 'trans.bayaran_keuntungan',
|
||||
// 'transaction.teller',
|
||||
// 'trans.ujrah',
|
||||
// 'trans.onepercent'
|
||||
// )
|
||||
// ->leftJoin('transaksi_keuntungan as trans', function ($join) {
|
||||
// $join->on('transaction.norujukan', '=', 'trans.norujukan');
|
||||
// $join->on('transaction.created_at', '=', 'trans.tarikh_bayaran');
|
||||
// })
|
||||
// ->leftJoin('customer as cust', function ($join) {
|
||||
// $join->on('transaction.nokp', '=', 'cust.kpbaru');
|
||||
// $join->orOn('transaction.nokp', '=', 'cust.kplama');
|
||||
// })
|
||||
// ->where('transaction.kodcaw', '=', $kodcaw)
|
||||
// ->where('transaction.trans_type', '=', 'A')
|
||||
// ->whereDate('transaction.created_at', '>=', $request->mula)
|
||||
// ->whereDate('transaction.created_at', '<=', $request->akhir);
|
||||
|
||||
|
||||
// // 💡 Tambah filter ikut jenis
|
||||
// if ($request->jenis == 'online') {
|
||||
// $query->where('transaction.descpt', 'LIKE', 'Laporan Ansuran Pembiayaan (Arrahn Pay)%');
|
||||
// } elseif ($request->jenis == 'kaunter') {
|
||||
// $query->where('transaction.descpt', 'LIKE', 'Laporan Ansuran Pembiayaan (Kaunter aros)%');
|
||||
// } else {
|
||||
// $query->where('transaction.descpt', 'LIKE', 'Laporan Ansuran Pembiayaan%');
|
||||
// }
|
||||
|
||||
// // Order by
|
||||
// $query->orderBy('transaction.teller')->orderBy('trans.tarikh_bayaran');
|
||||
|
||||
// // Dapatkan data
|
||||
// $ansuran_data = $query->get();
|
||||
|
||||
// // Proses data
|
||||
// $ansuran = [];
|
||||
// if ($ansuran_data) {
|
||||
// foreach ($ansuran_data as $index => $ansuranData) {
|
||||
// $gadai = Gadai::on($connection)->where('norujukan', $ansuranData['norujukan'])->first();
|
||||
|
||||
// array_push($ansuran, [
|
||||
// "norujukan" => $ansuranData['norujukan'],
|
||||
// "tarikh_bayaran" => $ansuranData['tarikh_bayaran'],
|
||||
// "nokp" => $ansuranData['nokp'],
|
||||
// "kodcaw" => $ansuranData['kodcaw'],
|
||||
// "trans_type" => $ansuranData['trans_type'],
|
||||
// "nama" => $ansuranData['nama'],
|
||||
// "tempoh" => $gadai['tempoh'] ?? null,
|
||||
// "bakipjm" => $gadai['bakipjm'] ?? null,
|
||||
// "bayaran_pembiayaan" => $ansuranData['bayaran_pembiayaan'],
|
||||
// "duit_masuk" => $ansuranData['duit_masuk'],
|
||||
// "bayaran_keuntungan" => $ansuranData['bayaran_keuntungan'],
|
||||
// "teller" => $ansuranData['teller'],
|
||||
// "ansuranujrah" => $ansuranData['ujrah'],
|
||||
// "ansuranonepercent" => $ansuranData['onepercent'],
|
||||
// "t_gadai" => $gadai['t_gadai'] ?? null,
|
||||
// ]);
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Susun data
|
||||
// usort($ansuran, function ($a, $b) {
|
||||
// $compare_teller = strcmp($a['teller'], $b['teller']);
|
||||
// return $compare_teller === 0
|
||||
// ? strcmp($a['tarikh_bayaran'], $b['tarikh_bayaran'])
|
||||
// : $compare_teller;
|
||||
// });
|
||||
|
||||
// return response()->json($ansuran);
|
||||
// }
|
||||
|
||||
public function getAnsuranSummary($kodcaw,Request $request){
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
|
||||
@@ -3802,4 +3932,11 @@ class GadaiController extends Controller
|
||||
|
||||
return response()->json($view);
|
||||
}
|
||||
|
||||
public function getApprovalFromOperation(Request $request){
|
||||
$ansuranserv = new AnsServ($request->kodcaw);
|
||||
$view = $ansuranserv->getApprovalFromOperation($request);
|
||||
|
||||
return response()->json($view);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,10 +6,13 @@ use App\Audit;
|
||||
use App\Mohon;
|
||||
use App\Cawangan;
|
||||
use App\Mohonid;
|
||||
use App\MohonAnggota;
|
||||
use App\Customer;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class KelulusanController extends Controller
|
||||
{
|
||||
@@ -201,6 +204,98 @@ class KelulusanController extends Controller
|
||||
return response()->json($kelulusan,201);
|
||||
}
|
||||
|
||||
public function updateAnggota($kodcaw, Request $request)
|
||||
{
|
||||
$harini = Carbon::now();
|
||||
|
||||
// Dapatkan sambungan database cawangan
|
||||
$cawangan = Cawangan::on('mysql7')
|
||||
->where('kodcaw', '=', $kodcaw)
|
||||
->first();
|
||||
|
||||
if (!$cawangan) {
|
||||
return response()->json(['success' => false, 'message' => 'Kod cawangan tidak sah'], 404);
|
||||
}
|
||||
|
||||
$nokp = $request->nokp;
|
||||
$komen = $request->komenkelulusan;
|
||||
$namaoperasi = $request->namaoperasi;
|
||||
$status = $request->sahkan; // 1 = Lulus, 2 = Batal
|
||||
|
||||
// Debug log masuk
|
||||
Log::info('UpdateKelulusanAnggota triggered', [
|
||||
'kodcaw' => $kodcaw,
|
||||
'nokp' => $nokp,
|
||||
'status' => $status,
|
||||
'komen' => $komen,
|
||||
'namaoperasi' => $namaoperasi
|
||||
]);
|
||||
|
||||
// Kalau LULUS
|
||||
if ($status == 1) {
|
||||
$kelulusan = MohonAnggota::on($cawangan['mysql'])
|
||||
->where('nokp', '=', $nokp)
|
||||
->update([
|
||||
'status' => 'DILULUSKAN',
|
||||
'komen' => $komen,
|
||||
'peloperasi' => $namaoperasi,
|
||||
'datetime_pelulus' => $harini,
|
||||
'updated_at' => $harini,
|
||||
]);
|
||||
|
||||
// Update CUSTOMER di pusat (mysql7)
|
||||
Customer::on('mysql7')
|
||||
->where('kpbaru', '=', $nokp)
|
||||
->update([
|
||||
'tag_anggota' => 1,
|
||||
]);
|
||||
}
|
||||
// Kalau BATAL / TOLAK
|
||||
else if ($status == 2) {
|
||||
$kelulusan = MohonAnggota::on($cawangan['mysql'])
|
||||
->where('nokp', '=', $nokp)
|
||||
->update([
|
||||
'status' => 'DITOLAK',
|
||||
'komen' => $komen,
|
||||
'peloperasi' => $namaoperasi,
|
||||
'datetime_pelulus' => $harini,
|
||||
'updated_at' => $harini,
|
||||
]);
|
||||
} else {
|
||||
return response()->json(['success' => false, 'message' => 'Status tidak sah'], 400);
|
||||
}
|
||||
|
||||
// 🧾 Simpan audit log
|
||||
$audit = new Audit();
|
||||
$audit->users = $namaoperasi;
|
||||
$audit->actions = ($status == 1)
|
||||
? "Kelulusan anggota oleh operasi (tag_anggota=1)"
|
||||
: "Pembatalan / tolak anggota oleh operasi";
|
||||
$audit->new_data = json_encode([
|
||||
'nokp' => $nokp,
|
||||
'status' => $status,
|
||||
'komen' => $komen,
|
||||
]);
|
||||
$audit->kodcaw = $kodcaw;
|
||||
$audit->created_at = $harini;
|
||||
$audit->updated_at = $harini;
|
||||
$audit->save();
|
||||
|
||||
Log::info('Kelulusan anggota dikemas kini', [
|
||||
'nokp' => $nokp,
|
||||
'status' => $status,
|
||||
'updated_tag_anggota' => ($status == 1) ? 1 : 0
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'status' => ($status == 1) ? 'DILULUSKAN' : 'DITOLAK',
|
||||
'updated_rows' => $kelulusan
|
||||
], 200);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function updatekomen($kodcaw,$norujukan,Request $request)
|
||||
{
|
||||
$harini = Carbon::now();
|
||||
@@ -284,6 +379,64 @@ public function create(REQUEST $request,$kodcaw,$norujukan,$roles)
|
||||
return response()->json($kelulusan);
|
||||
}
|
||||
|
||||
public function createKelulusanAnggota(Request $request, $kodcaw)
|
||||
{
|
||||
try {
|
||||
$harini = Carbon::now();
|
||||
|
||||
// ✅ Dapatkan maklumat cawangan (database connection)
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw', $kodcaw)->first();
|
||||
|
||||
if (!$cawangan) {
|
||||
return response()->json(['success' => false, 'message' => 'Cawangan tidak dijumpai'], 404);
|
||||
}
|
||||
|
||||
// ✅ Simpan ke dalam model MohonAnggota
|
||||
$kelulusan = new MohonAnggota();
|
||||
$kelulusan->setConnection($cawangan['mysql']); // guna connection cawangan dinamik
|
||||
$kelulusan->tarikh = $harini->toDateString();
|
||||
$kelulusan->nokp = $request->nokp;
|
||||
$kelulusan->nama = $request->nama ?? null;
|
||||
$kelulusan->status = 'MENUNGGU OPERASI';
|
||||
$kelulusan->komen = $request->komen;
|
||||
$kelulusan->teller = $request->teller;
|
||||
$kelulusan->peloperasi = null;
|
||||
$kelulusan->created_at = $harini;
|
||||
$kelulusan->updated_at = $harini;
|
||||
$kelulusan->save();
|
||||
|
||||
// ✅ Simpan audit trail
|
||||
$audit = new Audit();
|
||||
$audit->users = $request->teller;
|
||||
$audit->actions = 'Mohon kelulusan anggota';
|
||||
$audit->new_data = json_encode(['mohon_anggota_id' => $kelulusan->id]);
|
||||
$audit->kodcaw = $kodcaw;
|
||||
$audit->created_at = $harini;
|
||||
$audit->updated_at = $harini;
|
||||
$audit->save();
|
||||
|
||||
// ✅ Return JSON response ke frontend
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Permohonan kelulusan anggota berjaya dihantar kepada operasi.',
|
||||
'data' => [
|
||||
'id' => $kelulusan->id,
|
||||
'nokp' => $kelulusan->nokp,
|
||||
'status' => $kelulusan->status,
|
||||
'komen' => $kelulusan->komen,
|
||||
'teller' => $kelulusan->teller,
|
||||
],
|
||||
], 201);
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
Log::error('❌ createKelulusanAnggota error: ' . $th->getMessage());
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => $th->getMessage(),
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
//KEPOHONAN EDIT DAN HAPUS
|
||||
|
||||
public function kepohonancreate(REQUEST $request,$kodcaw,$norujukan)
|
||||
@@ -298,13 +451,16 @@ public function create(REQUEST $request,$kodcaw,$norujukan,$roles)
|
||||
'tarikh'=> $harini->toDateString(),
|
||||
'mohon' => $request->mohon,
|
||||
'norujukan' => $norujukan,
|
||||
'katalaluan' => '',
|
||||
'katalaluan' => $request->komen,
|
||||
'pinjaman' => $request->pinjaman,
|
||||
'nilaimarhun' => $request->nilaimarhun,
|
||||
'berat' => $request->berat,
|
||||
'margin' => $request->margin,
|
||||
'benar' => '0',
|
||||
'teller' => $request->teller
|
||||
'teller' => $request->teller,
|
||||
'tagoperasi'=> ($request->tagoperasi) ? true : false,
|
||||
'masa' => $harini->toTimeString(),
|
||||
'ansuran' => ($request->ansuran) ? $request->ansuran : 0.00,
|
||||
]);
|
||||
|
||||
return response()->json($mohonid,201);
|
||||
@@ -322,18 +478,24 @@ public function create(REQUEST $request,$kodcaw,$norujukan,$roles)
|
||||
$kelulusan=Mohonid::on($cawangan['mysql'])
|
||||
->where('tarikh','=',$harini->toDateString())
|
||||
->where('norujukan','=',$norujukan)
|
||||
->where('recno','=',$request->recno)
|
||||
->update(array(
|
||||
'katalaluan' => $request->komen,
|
||||
'benar' => '2',
|
||||
'id' => $request->khazanah
|
||||
'id' => $request->khazanah,
|
||||
'timestamp_approved_by_pc' => $harini,
|
||||
));
|
||||
}else{
|
||||
$benar = ($request->tagoperasi == 1) ? 0 : 1;
|
||||
|
||||
$kelulusan=Mohonid::on($cawangan['mysql'])
|
||||
->where('tarikh','=',$harini->toDateString())
|
||||
->where('norujukan','=',$norujukan)
|
||||
->where('recno','=',$request->recno)
|
||||
->update(array(
|
||||
'benar' => '1',
|
||||
'id' => $request->khazanah
|
||||
'benar' => $benar,
|
||||
'id' => $request->khazanah,
|
||||
'timestamp_approved_by_pc' => $harini,
|
||||
));
|
||||
}
|
||||
|
||||
@@ -381,16 +543,30 @@ public function create(REQUEST $request,$kodcaw,$norujukan,$roles)
|
||||
$arraykelulusan = [];
|
||||
|
||||
foreach($cawangan_all as $index=>$cawangan){
|
||||
$kelulusan=Mohon::on($cawangan['mysql'])
|
||||
->where('tarikh','=',$harini->toDateString())
|
||||
->where('masalulus','=','')
|
||||
->where('pelulus','=','operasi')
|
||||
->get();
|
||||
$kelulusan = Mohon::on($cawangan['mysql'])
|
||||
->where('tarikh','=',$harini->toDateString())
|
||||
->where('masalulus','=','')
|
||||
->where('pelulus','=','operasi')
|
||||
->get();
|
||||
|
||||
if(sizeof($kelulusan) != 0){
|
||||
array_push($arraykelulusan,["kelulusanall" => $kelulusan,"cawangan" => $cawangan['details_caw'],"cawangankod" => $cawangan['kodcaw']]);
|
||||
$mohonid_data = Mohonid::on($cawangan['mysql'])
|
||||
->where('tarikh','=',$harini->toDateString())
|
||||
->whereNotNull('id')
|
||||
->whereNotNull('timestamp_approved_by_pc')
|
||||
->where('tagoperasi', '1')
|
||||
->whereNull('operasi')
|
||||
->get();
|
||||
|
||||
// Check if EITHER has data (not just $kelulusan)
|
||||
if(sizeof($kelulusan) != 0 || sizeof($mohonid_data) != 0){
|
||||
array_push($arraykelulusan,[
|
||||
"kelulusanall" => $kelulusan,
|
||||
"kelulusanMohonid" => $mohonid_data,
|
||||
"cawangan" => $cawangan['details_caw'],
|
||||
"cawangankod" => $cawangan['kodcaw']
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json($arraykelulusan,200);
|
||||
}
|
||||
@@ -417,4 +593,124 @@ public function create(REQUEST $request,$kodcaw,$norujukan,$roles)
|
||||
return response()->json($arraykelulusan,200);
|
||||
}
|
||||
|
||||
public function UpdateHapusAnsuranOperasi(Request $request){
|
||||
$harini = Carbon::now();
|
||||
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$request->kodcaw)->first();
|
||||
|
||||
if($request->sahkan === 1){
|
||||
$kelulusan=Mohonid::on($cawangan['mysql'])
|
||||
->where('tarikh','=',$harini->toDateString())
|
||||
->where('norujukan','=',$request->norujukan)
|
||||
->where('recno','=',$request->siri)
|
||||
->where('tagoperasi', '=', 1)
|
||||
->update(array(
|
||||
'operasi' => $request->namaoperasi,
|
||||
'timestamp_approved_by_operasi' => $harini,
|
||||
'benar' => 1,
|
||||
));
|
||||
}else if($request->sahkan === 2){
|
||||
$kelulusan=Mohonid::on($cawangan['mysql'])
|
||||
->where('tarikh','=',$harini->toDateString())
|
||||
->where('norujukan','=',$request->norujukan)
|
||||
->where('recno','=',$request->siri)
|
||||
->where('tagoperasi', '=', 1)
|
||||
->update(array(
|
||||
'operasi' => $request->namaoperasi,
|
||||
'timestamp_approved_by_operasi' => $harini,
|
||||
'benar' => 2,
|
||||
));
|
||||
}
|
||||
|
||||
return response()->json($kelulusan,202);
|
||||
|
||||
}
|
||||
|
||||
public function getApproval(Request $request){
|
||||
$harini = Carbon::now();
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$request->kodcaw)->first();
|
||||
$kelulusan = Mohonid::on($cawangan['mysql'])
|
||||
->where('tarikh','=',$harini->toDateString())
|
||||
->where('teller','=',$request->teller)
|
||||
->where('mohon','=',$request->mohon)
|
||||
->where('benar','=',0)
|
||||
->latest('masa')
|
||||
->first();
|
||||
|
||||
return response()->json($kelulusan, 200);
|
||||
}
|
||||
|
||||
public function getApprovalList(Request $request){
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$request->kodcaw)->first();
|
||||
$kelulusan = Mohonid::on($cawangan['mysql'])
|
||||
->groupBy('mohon')
|
||||
->pluck('mohon');
|
||||
|
||||
return response()->json($kelulusan, 200);
|
||||
}
|
||||
|
||||
public function getApprovalLaporan(Request $request){
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$request->kodcaw)->first();
|
||||
$kelulusan = Mohonid::on($cawangan['mysql'])
|
||||
->selectRaw('recno, benar, tarikh, onlineid, mohon, norujukan, id, katalaluan, benar, operasi, pinjaman, ansuran, nilaimarhun, berat, margin, teller ,masa, timestamp_approved_by_pc, timestamp_approved_by_operasi')
|
||||
->whereBetween('tarikh', [$request->tarikh_mula, $request->tarikh_akhir])
|
||||
->where('mohon', $request->mohon)
|
||||
->orderBy('tarikh', 'desc')
|
||||
->orderBy('masa', 'desc')
|
||||
->get();
|
||||
|
||||
|
||||
return response()->json($kelulusan, 200);
|
||||
}
|
||||
|
||||
public function listKelulusanAnggota(Request $request)
|
||||
{
|
||||
$harini = Carbon::now();
|
||||
Log::info($request->all());
|
||||
$cawangan = Cawangan::on('mysql7')->get();
|
||||
|
||||
$array_kelulusan = [];
|
||||
|
||||
foreach ($cawangan as $caw) {
|
||||
|
||||
$kelulusan = MohonAnggota::on($caw['mysql'])
|
||||
->whereDate('tarikh', $harini->toDateString())
|
||||
->where(function ($query) {
|
||||
$query->where('peloperasi', '=', 0)
|
||||
->orWhereNull('peloperasi');
|
||||
})
|
||||
->orderBy('id', 'desc')
|
||||
->get();
|
||||
|
||||
if ($kelulusan->isNotEmpty()) {
|
||||
|
||||
// Kumpul semua nokp daripada senarai kelulusan
|
||||
$nokpList = $kelulusan->pluck('nokp')->unique()->toArray();
|
||||
|
||||
// Ambil semua nama daripada table customer (main DB)
|
||||
$customers = Customer::whereIn('kpbaru', $nokpList)
|
||||
->pluck('nama', 'kpbaru')
|
||||
->toArray();
|
||||
|
||||
// Masukkan nama ke dalam setiap item kelulusan
|
||||
$kelulusan = $kelulusan->map(function ($item) use ($customers) {
|
||||
$item->nama = $customers[$item->nokp] ?? '-';
|
||||
return $item;
|
||||
});
|
||||
|
||||
// Tambah ke array utama
|
||||
$array_kelulusan[] = [
|
||||
"kelulusanall" => $kelulusan,
|
||||
"cawangan" => $caw['details_caw'],
|
||||
"cawangankod" => $caw['kodcaw']
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json($array_kelulusan, 200);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ use Carbon\Carbon;
|
||||
use App\imbangdugalama;
|
||||
use App\Services\Reports\ImbangDugaService;
|
||||
use App\Services\Reports\Account\GeneralLedger;
|
||||
use App\Mohonid;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
@@ -845,7 +846,8 @@ $date = new Carbon($request->tarikh);
|
||||
$bilangan_gadai = $gadai->count();
|
||||
$bilangan_tebus = $tebus->count();
|
||||
// $bilangan_ansuran = $ansuran->count();
|
||||
$bilangan_customer_baru = Customer::on($cawangan['mysql'])->where([['tarikhdaftar','>=',$request->mula],['tarikhdaftar','<=',$request->akhir]])->count();
|
||||
//$bilangan_customer_baru = Customer::on($cawangan['mysql'])->where([['tarikhdaftar','>=',$request->mula],['tarikhdaftar','<=',$request->akhir]])->count();
|
||||
$bilangan_customer_baru = Customer::on('mysql7')->whereBetween('tarikhdaftar', [$request->mula, $request->akhir])->where('kodcaw', $request->kodcaw)->count();
|
||||
|
||||
//f
|
||||
$data_lelong = Lelong::on($cawangan['mysql'])->where([['t_jual','>=',$request->mula],['t_jual','<=',$request->akhir]])->get();
|
||||
@@ -1698,4 +1700,47 @@ $date = new Carbon($request->tarikh);
|
||||
|
||||
return response()->json($array_imbangduga,200);
|
||||
}
|
||||
|
||||
public function getLaporanKelulusan(Request $request){
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$request->kodcaw)->first();
|
||||
|
||||
$laporan_kelulusan = Mohonid::on($cawangan['mysql'])
|
||||
->whereBetween('tarikh', [$request->mula, $request->akhir])
|
||||
->when($request->mohon, function($query, $mohon) {
|
||||
return $query->where('mohon', $mohon);
|
||||
})
|
||||
->get();
|
||||
|
||||
if($laporan_kelulusan->isEmpty()){
|
||||
return response()->json(['message' => 'No data found'], 404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Laporan kelulusan retrieved successfully',
|
||||
'data' => $laporan_kelulusan,
|
||||
'count' => $laporan_kelulusan->count(),
|
||||
'timestamp' => Carbon::now()->toISOString()
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function getListofKelulusan(Request $request){
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$request->kodcaw)->first();
|
||||
|
||||
$laporan_kelulusan = Mohonid::on($cawangan['mysql'])
|
||||
->groupBy('mohon')
|
||||
->pluck('mohon');
|
||||
|
||||
if($laporan_kelulusan->isEmpty()){
|
||||
return response()->json(['message' => 'No data found'], 404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'List of Type Kelulusan retrieved successfully',
|
||||
'data' => $laporan_kelulusan,
|
||||
'count' => $laporan_kelulusan->count(),
|
||||
'timestamp' => Carbon::now()->toISOString()
|
||||
], 200);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,8 @@ use App\Services\RingkasanHarianServices;
|
||||
use App\Services\OnePercentServices;
|
||||
use App\Services\MasterServices;
|
||||
use App\Support\v2\Calculation;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
|
||||
use Log;
|
||||
use DB;
|
||||
@@ -223,16 +225,12 @@ class LelongController extends Controller
|
||||
|
||||
$rugitotal=$rugilelong + $ansrugi;
|
||||
|
||||
if($kodcaw == 'APM')
|
||||
// $bakilelong += 4498.1;
|
||||
$bakilelong += 1228.07;
|
||||
|
||||
if($kodcaw == '010617')
|
||||
$rugitotal -= 6.1;
|
||||
|
||||
if($kodcaw == '011229'){
|
||||
$rugitotal -= 919.7;
|
||||
$bakilelong -= 144;
|
||||
}
|
||||
|
||||
if($kodcaw == '011412')
|
||||
@@ -240,31 +238,13 @@ class LelongController extends Controller
|
||||
|
||||
if($kodcaw == '020303')
|
||||
{
|
||||
$bakilelong -= 542.6;
|
||||
$rugitotal += 0.01;
|
||||
}
|
||||
|
||||
if($kodcaw === '011232')
|
||||
{
|
||||
$bakilelong += 6;
|
||||
}
|
||||
|
||||
if($kodcaw === 'ARP'){
|
||||
$rugitotal += 119;
|
||||
}
|
||||
|
||||
if($kodcaw == '020301'){
|
||||
$bakilelong -= 719.50;
|
||||
}
|
||||
|
||||
if($kodcaw == '011227'){
|
||||
$bakilelong -= 896.65;
|
||||
}
|
||||
|
||||
if($kodcaw == 'GC'){
|
||||
$bakilelong += 2135.75;
|
||||
$bakilelong -= 3; //added 15/10/2024 sebab ada kemusykilan 3 ringgit daripada rugi lelong
|
||||
}
|
||||
|
||||
$arraylelong = ['bakilelong' => $bakilelong, 'rugilelong' => $rugitotal];
|
||||
|
||||
@@ -625,9 +605,9 @@ class LelongController extends Controller
|
||||
|
||||
if($cawangan['tagarrahnbid'] == 1){
|
||||
if(env('APP_ENV') != 'production'){
|
||||
$link = 'http://niklah.arrahn.com.my/api/portalApi';
|
||||
$link = 'https://adminbid-kopkb.erahn.com.my/api/portalApi';
|
||||
}else{
|
||||
$link = 'http://adminbid.arrahn/api/portalApi';
|
||||
$link = 'https://adminbid-kopkb.erahn.com.my/api/portalApi';
|
||||
}
|
||||
|
||||
$lelong = Http::withOptions(['verify' => true])->get($link,[
|
||||
@@ -1772,5 +1752,147 @@ class LelongController extends Controller
|
||||
return response()->json($tuntutbaki,200);
|
||||
}
|
||||
|
||||
public function LaporanLelong(Request $request)
|
||||
{
|
||||
// Validate required input
|
||||
$validator = Validator::make($request->all(), [
|
||||
'kodcaw' => 'required|string',
|
||||
'tarikhmula' => 'required|date',
|
||||
'tarikhhingga' => 'required|date|after_or_equal:tarikhmula',
|
||||
'batchno' => 'nullable|string'
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json(['error' => $validator->errors()], 400);
|
||||
}
|
||||
|
||||
|
||||
// Get cawangan details
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw', $request->kodcaw)->first();
|
||||
|
||||
if (!$cawangan) {
|
||||
return response()->json(['error' => 'Invalid kodcaw'], 403);
|
||||
}
|
||||
|
||||
// Query lelong data
|
||||
$lelong_query = Lelong::on($cawangan['mysql'])
|
||||
->leftJoin('gadai', 'gadai.norujukan', '=', 'lelong.norujukan')
|
||||
->join('lelmarhun', 'lelmarhun.norujukan', '=', 'lelong.norujukan')
|
||||
->join('pembeli', 'pembeli.nopembeli', '=', 'lelong.nopembeli')
|
||||
->whereBetween('lelong.t_lelong', [$request->tarikhmula, $request->tarikhhingga]);
|
||||
|
||||
// Optional: Filter by batch number
|
||||
if ($request->has('batchno') && !empty($request->batchno)) {
|
||||
$lelong_query->where('lelong.batchno', $request->batchno);
|
||||
}
|
||||
// Select required fields
|
||||
$lelong_data = $lelong_query->select(
|
||||
'lelong.batchno', 'lelong.t_lelong', 'gadai.t_gadai', 'gadai.nokp', 'lelong.pinjaman',
|
||||
'lelong.baki', 'lelong.norujukan', 'gadai.marhun', 'lelong.nilaimarhun',
|
||||
'lelong.bakiupah', 'lelong.cajlelong', 'lelong.hargajual', 'lelong.hargaasas',
|
||||
'pembeli.nama', 'pembeli.nokp AS nokppembeli', 'lelong.tagujrah', 'lelong.ujrah',
|
||||
'lelong.onepercent', 'lelong.teller'
|
||||
)
|
||||
->distinct()
|
||||
->orderByRaw("
|
||||
SUBSTRING_INDEX(SUBSTRING_INDEX(lelong.norujukan, '-', 1), '^[A-Za-z]+', -1),
|
||||
CAST(SUBSTRING_INDEX(lelong.norujukan, '-', -1) AS UNSIGNED)
|
||||
")
|
||||
->get();
|
||||
// dd($lelong_data);
|
||||
|
||||
// If no data found, return a message
|
||||
if ($lelong_data->isEmpty()) {
|
||||
return response()->json([
|
||||
'message' => 'Tiada lelongan dalam tarikh dipilih.',
|
||||
'data' => [],
|
||||
'totals' => [
|
||||
'total_pinjaman' => 0,
|
||||
'total_nilaimarhun' => 0,
|
||||
'total_keuntungan' => 0,
|
||||
'total_onepercent' => 0,
|
||||
'total_ujrah' => 0,
|
||||
'total_cajlelong' => 0,
|
||||
'total_hargajual' => 0,
|
||||
'total_baki' => 0,
|
||||
'total_hargaasas' => 0
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
// Calculate totals safely (prevent null values)
|
||||
$totals = [
|
||||
'total_pinjaman' => $lelong_data->sum(fn($item) => $item->pinjaman ?? 0),
|
||||
'total_nilaimarhun' => $lelong_data->sum(fn($item) => $item->nilaimarhun ?? 0),
|
||||
'total_keuntungan' => $lelong_data->sum(fn($item) => $item->bakiupah ?? 0),
|
||||
'total_onepercent' => $lelong_data->sum(fn($item) => $item->onepercent ?? 0),
|
||||
'total_ujrah' => $lelong_data->sum(fn($item) => $item->ujrah ?? 0),
|
||||
'total_cajlelong' => $lelong_data->sum(fn($item) => $item->cajlelong ?? 0),
|
||||
'total_hargajual' => $lelong_data->sum(fn($item) => $item->hargajual ?? 0),
|
||||
'total_baki' => $lelong_data->sum(fn($item) => $item->baki ?? 0),
|
||||
'total_hargaasas' => $lelong_data->sum(fn($item) => $item->hargaasas ?? 0)
|
||||
];
|
||||
|
||||
$tarikh_lelongs = $lelong_data->pluck('t_lelong')->first(); // Get first date
|
||||
|
||||
// Return JSON response
|
||||
return response()->json([
|
||||
'data' => $lelong_data,
|
||||
'totals' => $totals,
|
||||
'tarikh_lelong' => $tarikh_lelongs
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function LookupBatchLel($kodcaw,Request $request)
|
||||
{
|
||||
$harini = Carbon::now();
|
||||
$harini = new Carbon;
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
|
||||
|
||||
$batchlel = BatchLel::on($cawangan['mysql'])
|
||||
->select('batchno','tarikh')
|
||||
->when($kodcaw, function ($query, $kodcaw) {
|
||||
return $query->where('kodcaw', $kodcaw);
|
||||
})
|
||||
->orderBy('tarikh', 'DESC')
|
||||
->get();
|
||||
|
||||
return response()->json($batchlel);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function showBelumTuntutBakiRangeDate($kodcaw,Request $request){
|
||||
|
||||
$current = Carbon::now();
|
||||
$current = new Carbon();
|
||||
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
|
||||
|
||||
$belumtuntutbaki = Lelong::on($cawangan['mysql'])
|
||||
->select('lelong.t_jual','lelong.norujukan','lelong.baki','gadai.nokp','gadai.pinjaman','lelong.bakiupah','lelong.cajlelong','lelong.hargajual','lelong.hargaasas','lelong.nilaimarhun')
|
||||
->leftJoin('gadai', 'gadai.norujukan', '=', 'lelong.norujukan')
|
||||
->where('t_jual','>=',$request->mula)
|
||||
->where('t_jual','<=',$request->akhir)
|
||||
->where('baki','>',0)
|
||||
->whereNull('trkhtuntut');
|
||||
|
||||
$belumtuntut = $belumtuntutbaki->get();
|
||||
|
||||
$arrayblm = [];
|
||||
foreach($belumtuntut as $index=>$blm)
|
||||
{
|
||||
$customer = Customer::on('mysql7')
|
||||
->select('nama','telefon','telefon2','alamat1','alamat2','poskod','koddaerah')
|
||||
->where('kpbaru','=',$blm['nokp'])
|
||||
->orWhere('kplama','=',$blm['nokp'])
|
||||
->first();
|
||||
array_push($arrayblm,['nama'=>$customer['nama'],'nokp'=>$blm['nokp'],'norujukan'=>$blm['norujukan'],'t_jual'=>$blm['t_jual'],'hargajual'=>$blm['hargajual'],'pinjaman'=>$blm['pinjaman'],'bakiupah'=>$blm['bakiupah'],'cajlelong'=>$blm['cajlelong'],'baki'=>$blm['baki'],'hargaasas'=>$blm['hargaasas'],'nilaimarhun'=>$blm['nilaimarhun']]);
|
||||
|
||||
}
|
||||
|
||||
return response()->json($arrayblm);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -94,16 +94,19 @@ class PendahuluanSerahanController extends Controller
|
||||
->where('pendahuluan','>',0)
|
||||
->orderby('tarikh','desc')
|
||||
->get();
|
||||
}else if($request->jenis == 'serahan'){
|
||||
|
||||
$gldetail=GlDetail::on($cawangan['mysql'])
|
||||
->where('kodcaw','=',$kodcaw)
|
||||
->where([['tarikh','>=',$request->mula],['tarikh','<=',$request->hingga]])
|
||||
->where('descpt','NOT LIKE','SERAHAN BAYAR ONLINE%')
|
||||
->where('serahan','>',0)
|
||||
->orderby('tarikh','desc')
|
||||
->get();
|
||||
}else{
|
||||
}else if($request->jenis == 'serahan'){
|
||||
$gldetail = GlDetail::on($cawangan['mysql'])
|
||||
->where('kodcaw', '=', $kodcaw)
|
||||
->whereBetween('tarikh', [$request->mula, $request->hingga])
|
||||
->where(function ($query) {
|
||||
$query->where('descpt', 'NOT LIKE', 'SERAHAN BAYAR ONLINE%')
|
||||
->where('descpt', 'NOT LIKE', 'SERAHAN LELONG%'); // Using AND instead of OR
|
||||
})
|
||||
->where('serahan', '>', 0)
|
||||
->orderBy('tarikh', 'desc')
|
||||
->get();
|
||||
|
||||
}else if($request->jenis == 'online'){
|
||||
$gldetail=GlDetail::on($cawangan['mysql'])
|
||||
->where('kodcaw','=',$kodcaw)
|
||||
->where([['tarikh','>=',$request->mula],['tarikh','<=',$request->hingga]])
|
||||
@@ -111,7 +114,43 @@ class PendahuluanSerahanController extends Controller
|
||||
->where('serahan','>',0)
|
||||
->orderby('tarikh','desc')
|
||||
->get();
|
||||
}
|
||||
}else if($request->jenis == 'serahanlelong'){
|
||||
$gldetail=GlDetail::on($cawangan['mysql'])
|
||||
->where('kodcaw','=',$kodcaw)
|
||||
->where([['tarikh','>=',$request->mula],['tarikh','<=',$request->hingga]])
|
||||
->where('descpt','LIKE','SERAHAN LELONG%')
|
||||
->where('serahan','>',0)
|
||||
->orderby('tarikh','desc')
|
||||
->get();
|
||||
}else if($request->jenis == 'serahankepadav3'){
|
||||
$gldetail=GlDetail::on($cawangan['mysql'])
|
||||
->where('kodcaw','=',$kodcaw)
|
||||
->where([['tarikh','>=',$request->mula],['tarikh','<=',$request->hingga]])
|
||||
->where('descpt','LIKE','Serahan Kepada V3%')
|
||||
->where('teller','LIKE','%AUTO%')
|
||||
->where('serahan','>',0)
|
||||
->orderby('tarikh','desc')
|
||||
->get();
|
||||
|
||||
}else if($request->jenis == 'serahanonline'){
|
||||
$gldetail = GlDetail::on($cawangan['mysql'])
|
||||
->where('kodcaw', '=', $kodcaw)
|
||||
->whereBetween('tarikh', [$request->mula, $request->hingga])
|
||||
->where(function ($query) {
|
||||
$query->where('descpt', 'LIKE', 'SERAHAN%')
|
||||
->orWhere('descpt', 'LIKE', 'Serahan%')
|
||||
->orWhere('descpt', 'LIKE', 'serahan%'); // Add more variations if needed
|
||||
})
|
||||
->where('serahan', '>', 0)
|
||||
->orderBy('tarikh', 'desc')
|
||||
->get();
|
||||
}else{
|
||||
$gldetail = GlDetail::on($cawangan['mysql'])
|
||||
->where('kodcaw', '=', $kodcaw)
|
||||
->whereBetween('tarikh', [$request->mula, $request->hingga])
|
||||
->orderBy('tarikh', 'desc')
|
||||
->get();
|
||||
}
|
||||
|
||||
|
||||
return response()->json($gldetail,200);
|
||||
|
||||
@@ -0,0 +1,239 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Reports;
|
||||
|
||||
use App\Cawangan;
|
||||
use App\Gadai;
|
||||
use App\Helper;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Reports\AgingService as ReportAgingService;
|
||||
use App\Transaction;
|
||||
use Illuminate\Http\Request;
|
||||
use Carbon\Carbon;
|
||||
use App\StokAudit1;
|
||||
use App\StokAudit2;
|
||||
use App\StokAudit3;
|
||||
use App\StokAudit4;
|
||||
use App\StokAudit5;
|
||||
use App\StokAudit6;
|
||||
use App\StokAudit7;
|
||||
use App\StokAudit8;
|
||||
use App\StokAudit9;
|
||||
use App\StokAudit10;
|
||||
use App\StokAudit11;
|
||||
use App\StokAudit12;
|
||||
|
||||
class AgingController extends Controller
|
||||
{
|
||||
|
||||
public function getLaporanCawangan(string $kod_cawangan, Request $request)
|
||||
{
|
||||
$reportAgingService = new ReportAgingService($kod_cawangan, $request);
|
||||
return $reportAgingService->getCawanganReport();
|
||||
}
|
||||
|
||||
public function getSummaryLaporanAgingbackup(Request $request)
|
||||
{
|
||||
$online_array_db_connection = Helper::getOnlineArrahnConnection();
|
||||
$cawangan_available = Cawangan::on($online_array_db_connection)->select('kodcaw', 'details_caw', 'mysql')->get();
|
||||
|
||||
$kodcaw_array = array_column($cawangan_available->toArray(), 'kodcaw');
|
||||
$kod_caw_with_cawangan_detail_array = $cawangan_available->pluck('details_caw', 'kodcaw')->toArray();
|
||||
|
||||
// Step 1: Fetch the ansuran data grouped by cawangan
|
||||
$ansuran_query = Transaction::on($online_array_db_connection)
|
||||
->leftJoin('transaksi_keuntungan', function ($join) {
|
||||
$join->on('transaction.norujukan', '=', 'transaksi_keuntungan.norujukan');
|
||||
$join->on('transaction.created_at', '=', 'transaksi_keuntungan.tarikh_bayaran');
|
||||
})
|
||||
->where('transaction.trans_type', '=', 'A')
|
||||
->whereDate('transaction.created_at', '>=', date($request->startDate))
|
||||
->whereDate('transaction.created_at', '<=', date($request->endDate))
|
||||
->selectRaw('
|
||||
transaction.kodcaw as kod_cawangan,
|
||||
count(transaction.norujukan) as bilangan_ansuran,
|
||||
sum(transaksi_keuntungan.bayaran_pembiayaan) as bayaran_pembiayaan,
|
||||
sum(transaksi_keuntungan.bayaran_keuntungan) as bayaran_kos_keuntungan,
|
||||
sum(transaction.duit_masuk) as jumlah_bayaran,
|
||||
GROUP_CONCAT(transaction.norujukan) as norujukan_list
|
||||
')
|
||||
->groupBy('transaction.kodcaw')
|
||||
->get();
|
||||
|
||||
$total_nilai_marhun_by_cawangan = [];
|
||||
|
||||
// Step 2: Loop through ansuran_query and fetch nilai_marhun per kodcaw
|
||||
foreach ($ansuran_query as $ansuran_cawangan) {
|
||||
$kodcaw = $ansuran_cawangan->kod_cawangan;
|
||||
$norujukan_list = explode(',', $ansuran_cawangan->norujukan_list); // Convert to array
|
||||
|
||||
// Get database connection for this branch
|
||||
$mysql_connection = $cawangan_available->where('kodcaw', $kodcaw)->first()->mysql ?? null;
|
||||
if (!$mysql_connection) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Sum nilai_marhun for matching norujukan in gadai table
|
||||
$total_nilai_marhun_by_cawangan[$kodcaw] = Gadai::on($mysql_connection)
|
||||
->whereIn('norujukan', $norujukan_list)
|
||||
->sum('nilaimarhun');
|
||||
}
|
||||
|
||||
// Step 3: Merge ansuran summary with total_nilai_marhun
|
||||
$summary_ansuran_by_cawangan = $ansuran_query
|
||||
->filter(function ($ansuran_cawangan) use ($kodcaw_array) {
|
||||
return in_array($ansuran_cawangan['kod_cawangan'], $kodcaw_array);
|
||||
})
|
||||
->map(function ($ansuran_cawangan) use ($kod_caw_with_cawangan_detail_array, $total_nilai_marhun_by_cawangan) {
|
||||
$kodcaw = $ansuran_cawangan->kod_cawangan;
|
||||
$ansuran_cawangan->cawangan_detail = $kod_caw_with_cawangan_detail_array[$kodcaw] ?? 'Unknown';
|
||||
$ansuran_cawangan->total_nilai_marhun = $total_nilai_marhun_by_cawangan[$kodcaw] ?? 0;
|
||||
unset($ansuran_cawangan->norujukan_list); // Remove unnecessary field
|
||||
return $ansuran_cawangan;
|
||||
})
|
||||
->values();
|
||||
|
||||
// Step 4: Calculate overall totals
|
||||
$total_summary = [
|
||||
'bilangan_ansuran' => 0,
|
||||
'bayaran_pembiayaan' => 0,
|
||||
'bayaran_kos_keuntungan' => 0,
|
||||
'jumlah_bayaran' => 0,
|
||||
'total_nilai_marhun' => 0,
|
||||
];
|
||||
|
||||
foreach ($summary_ansuran_by_cawangan as $ansuran_cawangan) {
|
||||
$total_summary['bilangan_ansuran'] += $ansuran_cawangan->bilangan_ansuran ?? 0;
|
||||
$total_summary['bayaran_pembiayaan'] += $ansuran_cawangan->bayaran_pembiayaan ?? 0;
|
||||
$total_summary['bayaran_kos_keuntungan'] += $ansuran_cawangan->bayaran_kos_keuntungan ?? 0;
|
||||
$total_summary['jumlah_bayaran'] += $ansuran_cawangan->jumlah_bayaran ?? 0;
|
||||
$total_summary['total_nilai_marhun'] += $ansuran_cawangan->total_nilai_marhun ?? 0;
|
||||
}
|
||||
|
||||
// Step 5: Prepare the overall ansuran summary
|
||||
$summary_ansuran = [
|
||||
'bilangan_ansuran' => $total_summary['bilangan_ansuran'],
|
||||
'bayaran_pembiayaan' => $total_summary['bayaran_pembiayaan'],
|
||||
'bayaran_kos_keuntungan' => $total_summary['bayaran_kos_keuntungan'],
|
||||
'jumlah_bayaran' => $total_summary['jumlah_bayaran'],
|
||||
'total_nilai_marhun' => $total_summary['total_nilai_marhun'],
|
||||
];
|
||||
|
||||
$response = [
|
||||
'summary_aging_by_cawangan' => $summary_ansuran_by_cawangan,
|
||||
'summary_aging' => $summary_ansuran, // Now contains the grand totals
|
||||
];
|
||||
|
||||
return json_encode($response);
|
||||
}
|
||||
|
||||
public function getSummaryLaporanAging(Request $request)
|
||||
{
|
||||
$online_array_db_connection = Helper::getOnlineArrahnConnection();
|
||||
$cawangan_available = Cawangan::on($online_array_db_connection)
|
||||
->select('kodcaw', 'details_caw', 'mysql')->get();
|
||||
|
||||
$kod_caw_with_cawangan_detail_array = $cawangan_available->pluck('details_caw', 'kodcaw')->toArray();
|
||||
|
||||
$current = Carbon::now();
|
||||
$endDate = Carbon::parse($request->endDate);
|
||||
$bulan = $endDate->month;
|
||||
$tahun = $endDate->year;
|
||||
|
||||
$result = [];
|
||||
|
||||
foreach ($kod_caw_with_cawangan_detail_array as $kodcaw => $details_caw) {
|
||||
$cawangan = $cawangan_available->firstWhere('kodcaw', $kodcaw);
|
||||
if (!$cawangan) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Determine which table to query
|
||||
if ($current->month == $bulan && $current->year == $tahun) {
|
||||
$audit = Gadai::on($cawangan->mysql)
|
||||
->where(function ($q) use ($endDate) {
|
||||
$q->where([
|
||||
['tagpalsu', '=', 0],
|
||||
['t_gadai', '<=', $endDate->toDateString()],
|
||||
['sttebus', '=', '']
|
||||
])
|
||||
->orWhere([
|
||||
['tagpalsu', '=', 0],
|
||||
['t_update', '>', $endDate->toDateString()],
|
||||
['sttebus', '!=', ''],
|
||||
['t_gadai', '<=', $endDate->toDateString()]
|
||||
]);
|
||||
});
|
||||
} else {
|
||||
$tableMap = [
|
||||
1 => StokAudit1::class, 2 => StokAudit2::class, 3 => StokAudit3::class,
|
||||
4 => StokAudit4::class, 5 => StokAudit5::class, 6 => StokAudit6::class,
|
||||
7 => StokAudit7::class, 8 => StokAudit8::class, 9 => StokAudit9::class,
|
||||
10 => StokAudit10::class, 11 => StokAudit11::class, 12 => StokAudit12::class,
|
||||
];
|
||||
|
||||
$model = $tableMap[$bulan] ?? null;
|
||||
if (!$model) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$audit = $model::on($cawangan->mysql)->where('tahun', $tahun);
|
||||
}
|
||||
|
||||
// Categorize data by tempoh
|
||||
$summary = [];
|
||||
|
||||
for ($i = 1; $i <= 13; $i++) {
|
||||
$query = clone $audit;
|
||||
|
||||
if ($i == 13) {
|
||||
$filtered = $query->where('tempoh', '>', 12);
|
||||
} elseif ($i == 1) {
|
||||
$filtered = $query->whereBetween('tempoh', [0.01, 1.5]);
|
||||
} elseif ($i == 12) {
|
||||
$filtered = $query->where('tempoh', 12);
|
||||
} else {
|
||||
$filtered = $query->where([['tempoh','>',$i-(0.5)],['tempoh','<=',$i+(0.5)]]);
|
||||
}
|
||||
|
||||
$labelMap = [
|
||||
1 => '1 Bulan',
|
||||
2 => '2 Bulan',
|
||||
3 => '3 Bulan',
|
||||
4 => '4 Bulan',
|
||||
5 => '5 Bulan',
|
||||
6 => '6 Bulan',
|
||||
7 => '7 bulan',
|
||||
8 => '8 Bulan',
|
||||
9 => '9 Bulan',
|
||||
10 => '10 Bulan',
|
||||
11 => '11 Bulan',
|
||||
12 => '12 Bulan',
|
||||
13 => '> 12 Bulan'
|
||||
];
|
||||
|
||||
$summary[] = [
|
||||
'label' => $labelMap[$i],
|
||||
'count' => $filtered->count(),
|
||||
'sum_bakipjm' => $filtered->sum('bakipjm'),
|
||||
];
|
||||
}
|
||||
|
||||
$result[] = [
|
||||
'kodcaw' => $kodcaw,
|
||||
'cawangan' => $details_caw,
|
||||
'tahun' => $tahun,
|
||||
'bulan' => $bulan,
|
||||
'summary_by_tempoh' => $summary
|
||||
];
|
||||
}
|
||||
|
||||
return response()->json($result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Reports;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Cawangan;
|
||||
use App\Gadai;
|
||||
use App\Customer;
|
||||
use App\Tebus;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Services\Reports\GadaianService as ReportGadaianService;
|
||||
use App\Helper;
|
||||
use App\Services\Reports\RingkasanHarianService as ReportRingkasanHarianService;
|
||||
|
||||
|
||||
class AnalisaController extends Controller
|
||||
{
|
||||
public function getLaporanCawangan(string $kod_cawangan, Request $request)
|
||||
{
|
||||
$reportGadaianService = new ReportGadaianService($kod_cawangan, $request);
|
||||
return $reportGadaianService->getCawanganReport();
|
||||
}
|
||||
|
||||
public function getSummaryLaporanPelangganBaru(Request $request)
|
||||
{
|
||||
$startDate = $request->startDate;
|
||||
$endDate = $request->endDate;
|
||||
|
||||
// Get active branch DBs from helper
|
||||
$active_cawangan_db_connection = Helper::getActiveCawanganDbConnection();
|
||||
|
||||
// Fetch branch details with mysql info
|
||||
$cawangan_available = Cawangan::select('kodcaw', 'details_caw', 'mysql')
|
||||
->whereIn('mysql', $active_cawangan_db_connection)
|
||||
->get();
|
||||
|
||||
$active_cawangan_db_connection = array_column($cawangan_available->toArray(), 'mysql');
|
||||
|
||||
$active_cawangan_detail = $cawangan_available->map(function ($c) {
|
||||
return [
|
||||
'kodcaw' => $c->kodcaw,
|
||||
'details_caw' => $c->details_caw,
|
||||
];
|
||||
})->values()->toArray();
|
||||
|
||||
// Iterate through each branch and get data
|
||||
$response = array_map(function ($db_connection, $cawangan_detail) use ($request) {
|
||||
// Pass the required parameters to the service constructor
|
||||
$reportRingkasanHarianService = new ReportRingkasanHarianService($cawangan_detail['kodcaw'], $request);
|
||||
|
||||
// Get the customer count from the service
|
||||
$bilangan_customer_baru = $reportRingkasanHarianService->getCustomerSummary(); // Call public method
|
||||
|
||||
// Return the response
|
||||
return [
|
||||
'kodcaw' => $cawangan_detail['kodcaw'],
|
||||
'details_caw' => $cawangan_detail['details_caw'],
|
||||
'total_pelanggan_baru' => $bilangan_customer_baru,
|
||||
];
|
||||
}, $active_cawangan_db_connection, $active_cawangan_detail);
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
|
||||
// public function getSummaryLaporanPelangganAktif(Request $request)
|
||||
// {
|
||||
// $startDate = $request->startDate;
|
||||
// $endDate = $request->endDate;
|
||||
|
||||
// // Dapatkan senarai cawangan aktif
|
||||
// $active_cawangan_db_connection = Helper::getActiveCawanganDbConnection();
|
||||
|
||||
// // Dapatkan maklumat cawangan
|
||||
// $cawangan_available = Cawangan::select('kodcaw', 'details_caw', 'mysql')
|
||||
// ->whereIn('mysql', $active_cawangan_db_connection)
|
||||
// ->get();
|
||||
|
||||
// $active_cawangan_detail = $cawangan_available->map(function ($c) {
|
||||
// return [
|
||||
// 'kodcaw' => $c->kodcaw,
|
||||
// 'details_caw' => $c->details_caw,
|
||||
// 'mysql' => $c->mysql,
|
||||
// ];
|
||||
// })->toArray();
|
||||
|
||||
// $response = array_map(function ($cawangan) use ($startDate, $endDate) {
|
||||
// $db_connection = $cawangan['mysql'];
|
||||
|
||||
// $total_aktif = Gadai::on($db_connection)
|
||||
// ->where(function ($query) use ($startDate) {
|
||||
// $query->where('sttebus', '')
|
||||
// ->where('t_update', '>=', $startDate);
|
||||
// })
|
||||
// ->where('t_gadai', '<=', $endDate)
|
||||
// ->distinct('nokp')
|
||||
// ->count('nokp');
|
||||
|
||||
// return [
|
||||
// 'kodcaw' => $cawangan['kodcaw'],
|
||||
// 'details_caw' => $cawangan['details_caw'],
|
||||
// 'total_pelanggan_aktif' => $total_aktif,
|
||||
// ];
|
||||
// }, $active_cawangan_detail);
|
||||
|
||||
|
||||
// return response()->json($response);
|
||||
// }
|
||||
|
||||
|
||||
public function getSummaryLaporanPelangganAktif(Request $request)
|
||||
{
|
||||
$startDate = $request->startDate;
|
||||
$endDate = $request->endDate;
|
||||
|
||||
$active_cawangan = Cawangan::select('kodcaw', 'details_caw', 'mysql')
|
||||
->whereIn('mysql', Helper::getActiveCawanganDbConnection())
|
||||
->get();
|
||||
|
||||
$response = $active_cawangan->map(function ($cawangan) use ($startDate, $endDate) {
|
||||
$db = $cawangan->mysql;
|
||||
|
||||
// Ambil nokp dari Gadai
|
||||
$nokp_gadai = DB::connection($db)->table('gadai')
|
||||
->whereBetween('t_gadai', [$startDate, $endDate])
|
||||
->pluck('nokp')
|
||||
->toArray();
|
||||
|
||||
// Ambil nokp dari Tebus
|
||||
$nokp_tebus = DB::connection($db)->table('tebus as t')
|
||||
->join('gadai as g', 't.norujukan', '=', 'g.norujukan')
|
||||
->whereBetween('t.t_tebus', [$startDate, $endDate])
|
||||
->pluck('g.nokp')
|
||||
->toArray();
|
||||
|
||||
// Gabung semua nokp
|
||||
$semua_nokp = collect(array_merge($nokp_gadai, $nokp_tebus))
|
||||
->filter(fn($item) => !empty($item))
|
||||
->unique()
|
||||
->values();
|
||||
|
||||
if ($semua_nokp->isEmpty()) {
|
||||
// Jika array kosong, kita kembalikan hasil kosong
|
||||
$pelanggan_aktif = collect();
|
||||
} else {
|
||||
$pelanggan_aktif = Customer::on($db)
|
||||
->where(function ($query) use ($semua_nokp) {
|
||||
$query->whereIn('kpbaru', $semua_nokp)
|
||||
->orWhereIn('kplama', $semua_nokp);
|
||||
})
|
||||
->get(['nama', 'kpbaru', 'kplama'])
|
||||
->toArray();;
|
||||
}
|
||||
|
||||
return [
|
||||
'kodcaw' => $cawangan->kodcaw,
|
||||
'details_caw' => $cawangan->details_caw,
|
||||
'total_pelanggan_aktif' => count($semua_nokp),
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers\Reports;
|
||||
|
||||
use App\Cawangan;
|
||||
use App\Gadai;
|
||||
use App\Helper;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Reports\AnsuranService as ReportAnsuranService;
|
||||
@@ -19,46 +20,99 @@ class AnsuranController extends Controller
|
||||
}
|
||||
|
||||
public function getSummaryLaporanAnsuran(Request $request)
|
||||
{
|
||||
$online_array_db_connection = Helper::getOnlineArrahnConnection();
|
||||
{
|
||||
$online_array_db_connection = Helper::getOnlineArrahnConnection();
|
||||
$cawangan_available = Cawangan::on($online_array_db_connection)->select('kodcaw', 'details_caw', 'mysql')->get();
|
||||
|
||||
$ansuran_query = Transaction::on($online_array_db_connection)
|
||||
->leftJoin('transaksi_keuntungan', function ($join) {
|
||||
$join->on('transaction.norujukan', '=', 'transaksi_keuntungan.norujukan');
|
||||
$join->on('transaction.created_at', '=', 'transaksi_keuntungan.tarikh_bayaran');
|
||||
})
|
||||
->where('transaction.trans_type', '=', 'A')
|
||||
->whereDate('transaction.created_at', '>=', date($request->startDate))
|
||||
->whereDate('transaction.created_at', '<=', date($request->endDate))
|
||||
->selectRaw('
|
||||
count(transaction.norujukan) as bilangan_ansuran,
|
||||
sum(transaksi_keuntungan.bayaran_pembiayaan) as bayaran_pembiayaan,
|
||||
sum(transaksi_keuntungan.bayaran_keuntungan) as bayaran_kos_keuntungan,
|
||||
sum(transaction.duit_masuk) as jumlah_bayaran
|
||||
');
|
||||
$kodcaw_array = array_column($cawangan_available->toArray(), 'kodcaw');
|
||||
$kod_caw_with_cawangan_detail_array = $cawangan_available->pluck('details_caw', 'kodcaw')->toArray();
|
||||
|
||||
$summary_ansuran = (clone $ansuran_query)->get()->toArray()[0];
|
||||
// Step 1: Fetch the ansuran data grouped by cawangan
|
||||
$ansuran_query = Transaction::on($online_array_db_connection)
|
||||
->leftJoin('transaksi_keuntungan', function ($join) {
|
||||
$join->on('transaction.norujukan', '=', 'transaksi_keuntungan.norujukan');
|
||||
$join->on('transaction.created_at', '=', 'transaksi_keuntungan.tarikh_bayaran');
|
||||
})
|
||||
->where('transaction.trans_type', '=', 'A')
|
||||
->whereDate('transaction.created_at', '>=', date($request->startDate))
|
||||
->whereDate('transaction.created_at', '<=', date($request->endDate))
|
||||
->selectRaw('
|
||||
transaction.kodcaw as kod_cawangan,
|
||||
count(transaction.norujukan) as bilangan_ansuran,
|
||||
sum(transaksi_keuntungan.bayaran_pembiayaan) as bayaran_pembiayaan,
|
||||
sum(transaksi_keuntungan.bayaran_keuntungan) as bayaran_kos_keuntungan,
|
||||
sum(transaction.duit_masuk) as jumlah_bayaran,
|
||||
GROUP_CONCAT(transaction.norujukan) as norujukan_list
|
||||
')
|
||||
->groupBy('transaction.kodcaw')
|
||||
->get();
|
||||
|
||||
$summary_ansuran_by_cawangan = (clone $ansuran_query)
|
||||
->addSelect('transaction.kodcaw as kod_cawangan')
|
||||
->groupBy('transaction.kodcaw')
|
||||
->get();
|
||||
$total_nilai_marhun_by_cawangan = [];
|
||||
|
||||
$cawangan_available = Cawangan::on($online_array_db_connection)->select('kodcaw', 'details_caw')->get()->toArray();
|
||||
$kodcaw_array = array_column($cawangan_available, 'kodcaw');
|
||||
$cawangan_detail_array = array_column($cawangan_available, 'details_caw');
|
||||
$kod_caw_with_cawangan_detail_array = array_combine($kodcaw_array, $cawangan_detail_array);
|
||||
// Step 2: Loop through ansuran_query and fetch nilai_marhun per kodcaw
|
||||
foreach ($ansuran_query as $ansuran_cawangan) {
|
||||
$kodcaw = $ansuran_cawangan->kod_cawangan;
|
||||
$norujukan_list = explode(',', $ansuran_cawangan->norujukan_list); // Convert to array
|
||||
|
||||
$summary_ansuran_by_cawangan = $summary_ansuran_by_cawangan->map(function ($ansuran_cawangan) use ($kod_caw_with_cawangan_detail_array) {
|
||||
$ansuran_cawangan->cawangan_detail = $kod_caw_with_cawangan_detail_array[$ansuran_cawangan['kod_cawangan']];
|
||||
return $ansuran_cawangan;
|
||||
});
|
||||
// Get database connection for this branch
|
||||
$mysql_connection = $cawangan_available->where('kodcaw', $kodcaw)->first()->mysql ?? null;
|
||||
if (!$mysql_connection) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$response = [
|
||||
'summary_ansuran_by_cawangan' => $summary_ansuran_by_cawangan,
|
||||
'summary_ansuran' => $summary_ansuran,
|
||||
];
|
||||
|
||||
return json_encode($response);
|
||||
// Sum nilai_marhun for matching norujukan in gadai table
|
||||
$total_nilai_marhun_by_cawangan[$kodcaw] = Gadai::on($mysql_connection)
|
||||
->whereIn('norujukan', $norujukan_list)
|
||||
->sum('nilaimarhun');
|
||||
}
|
||||
|
||||
// Step 3: Merge ansuran summary with total_nilai_marhun
|
||||
$summary_ansuran_by_cawangan = $ansuran_query
|
||||
->filter(function ($ansuran_cawangan) use ($kodcaw_array) {
|
||||
return in_array($ansuran_cawangan['kod_cawangan'], $kodcaw_array);
|
||||
})
|
||||
->map(function ($ansuran_cawangan) use ($kod_caw_with_cawangan_detail_array, $total_nilai_marhun_by_cawangan) {
|
||||
$kodcaw = $ansuran_cawangan->kod_cawangan;
|
||||
$ansuran_cawangan->cawangan_detail = $kod_caw_with_cawangan_detail_array[$kodcaw] ?? 'Unknown';
|
||||
$ansuran_cawangan->total_nilai_marhun = $total_nilai_marhun_by_cawangan[$kodcaw] ?? 0;
|
||||
unset($ansuran_cawangan->norujukan_list); // Remove unnecessary field
|
||||
return $ansuran_cawangan;
|
||||
})
|
||||
->values();
|
||||
|
||||
// Step 4: Calculate overall totals
|
||||
$total_summary = [
|
||||
'bilangan_ansuran' => 0,
|
||||
'bayaran_pembiayaan' => 0,
|
||||
'bayaran_kos_keuntungan' => 0,
|
||||
'jumlah_bayaran' => 0,
|
||||
'total_nilai_marhun' => 0,
|
||||
];
|
||||
|
||||
foreach ($summary_ansuran_by_cawangan as $ansuran_cawangan) {
|
||||
$total_summary['bilangan_ansuran'] += $ansuran_cawangan->bilangan_ansuran ?? 0;
|
||||
$total_summary['bayaran_pembiayaan'] += $ansuran_cawangan->bayaran_pembiayaan ?? 0;
|
||||
$total_summary['bayaran_kos_keuntungan'] += $ansuran_cawangan->bayaran_kos_keuntungan ?? 0;
|
||||
$total_summary['jumlah_bayaran'] += $ansuran_cawangan->jumlah_bayaran ?? 0;
|
||||
$total_summary['total_nilai_marhun'] += $ansuran_cawangan->total_nilai_marhun ?? 0;
|
||||
}
|
||||
|
||||
// Step 5: Prepare the overall ansuran summary
|
||||
$summary_ansuran = [
|
||||
'bilangan_ansuran' => $total_summary['bilangan_ansuran'],
|
||||
'bayaran_pembiayaan' => $total_summary['bayaran_pembiayaan'],
|
||||
'bayaran_kos_keuntungan' => $total_summary['bayaran_kos_keuntungan'],
|
||||
'jumlah_bayaran' => $total_summary['jumlah_bayaran'],
|
||||
'total_nilai_marhun' => $total_summary['total_nilai_marhun'],
|
||||
];
|
||||
|
||||
$response = [
|
||||
'summary_ansuran_by_cawangan' => $summary_ansuran_by_cawangan,
|
||||
'summary_ansuran' => $summary_ansuran, // Now contains the grand totals
|
||||
];
|
||||
|
||||
return json_encode($response);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Reports;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\TransactionOnline;
|
||||
|
||||
class BayaranOnlineController extends Controller
|
||||
{
|
||||
|
||||
public function __invoke(Request $request)
|
||||
{
|
||||
$transactionOnlineQuery = TransactionOnline::filter($request);
|
||||
|
||||
$formatMoney = fn($x) => number_format($x, 2, '.', ',');
|
||||
|
||||
$sumTotalPayments = (clone $transactionOnlineQuery)->sum('total_payment');
|
||||
$sumTotalPayments = $formatMoney($sumTotalPayments);
|
||||
$nosPayments = (clone $transactionOnlineQuery)->count('total_payment');
|
||||
|
||||
$transactions = (clone $transactionOnlineQuery)->select('kodcaw', DB::raw('sum(total_payment) as totalCawanganPayment'), DB::raw('count(reference_no) as totalReferenceNo'))
|
||||
->groupBy('kodcaw')
|
||||
->get()
|
||||
->map(function($x) use($formatMoney) {
|
||||
$x['totalCawanganPayment'] = $formatMoney($x['totalCawanganPayment']);
|
||||
return $x;
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'nosPayments' => $nosPayments,
|
||||
'sumTotalPayments' => $sumTotalPayments,
|
||||
'transactions' => $transactions,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Reports;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\TransactionOnline;
|
||||
|
||||
class BayaranOnlineDetailController extends Controller
|
||||
{
|
||||
|
||||
public function __invoke(Request $request)
|
||||
{
|
||||
|
||||
$transactionOnlineQuery = TransactionOnline::filter($request);
|
||||
|
||||
$formatMoney = fn($x) => number_format($x, 2, '.', ',');
|
||||
|
||||
$sumTotalPayments = (clone $transactionOnlineQuery)->sum('total_payment');
|
||||
$sumTotalPayments = $formatMoney($sumTotalPayments);
|
||||
$sumPaymentNos = (clone $transactionOnlineQuery)->count('total_payment');
|
||||
|
||||
$transactions = (clone $transactionOnlineQuery)->select('nokp', 'customer_name', 'norujukan', 'reference_no', 'kodcaw', 'total_payment', 'tarikh', 'masa', 'status')
|
||||
->get()
|
||||
->groupBy('nokp')
|
||||
->map(fn($x) => $x->groupBy('cawangan.details_caw'))
|
||||
->map(function ($cawangan) {
|
||||
|
||||
$all_entries = $cawangan->collapse();
|
||||
|
||||
$first = $all_entries->first();
|
||||
|
||||
$payment_details = $cawangan->map(function ($cawangan_payments) {
|
||||
return [
|
||||
'paymentNos' => $cawangan_payments->count(),
|
||||
'paymentSum' => $cawangan_payments->sum('total_payment'),
|
||||
'paymentDetails' => $cawangan_payments->map(function ($x) {
|
||||
|
||||
$payment_details = collect($x)->except('nokp', 'customer_name', 'kodcaw', 'cawangan');
|
||||
|
||||
return $payment_details;
|
||||
}),
|
||||
];
|
||||
});
|
||||
|
||||
return [
|
||||
'customer_name' => $first->customer_name,
|
||||
'nokp' => $first->nokp,
|
||||
'payments' => $payment_details,
|
||||
];
|
||||
})
|
||||
->values();
|
||||
|
||||
|
||||
return response()->json([
|
||||
'sumTotalPayments' => $sumTotalPayments,
|
||||
'sumPaymentNos' => $sumPaymentNos,
|
||||
'transactions' => $transactions,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -26,18 +26,29 @@ class GadaianController extends Controller
|
||||
$startDate = $request->startDate;
|
||||
$endDate = $request->endDate;
|
||||
|
||||
// Get active branch DBs from helper
|
||||
$active_cawangan_db_connection = Helper::getActiveCawanganDbConnection();
|
||||
|
||||
$active_cawangan_db_name = array_map(function ($db_connection) {
|
||||
return config('database.connections' . '.' . $db_connection . '.' . 'database');
|
||||
}, $active_cawangan_db_connection);
|
||||
|
||||
$active_cawangan_detail = Cawangan::select('kodcaw', 'details_caw')->whereIn('db_name', $active_cawangan_db_name)->get()->toArray();
|
||||
|
||||
// Fetch branch details with mysql info
|
||||
$cawangan_available = Cawangan::select('kodcaw', 'details_caw', 'mysql')
|
||||
->whereIn('mysql', $active_cawangan_db_connection)
|
||||
->get();
|
||||
|
||||
// Get db connections
|
||||
$active_cawangan_db_connection = array_column($cawangan_available->toArray(), 'mysql');
|
||||
|
||||
// Map branch info for response
|
||||
$active_cawangan_detail = $cawangan_available->map(function ($c) {
|
||||
return [
|
||||
'kodcaw' => $c->kodcaw,
|
||||
'details_caw' => $c->details_caw,
|
||||
];
|
||||
})->values()->toArray();
|
||||
|
||||
$summary_gadaian_data = array_map(function ($db_connection) use ($request) {
|
||||
$query = Gadai::on($db_connection);
|
||||
|
||||
$query->select(DB::raw('count(norujukan) as total_gadaian, sum(berat) as sum_berat, sum(nilaimarhun) as sum_nilai_marhun, sum(pinjaman) as sum_pinjaman'));
|
||||
$query->select(DB::raw('count(norujukan) as total_gadaian, sum(berat) as sum_berat, sum(nilaimarhun) as sum_nilai_marhun, sum(pinjaman) as sum_pinjaman, sum(upah12) as sum_upah_12'));
|
||||
|
||||
$query->when($request->filled('startDate') and $request->filled('endDate'), function ($q) use ($request) {
|
||||
return $q->where('t_gadai', '>=', $request->startDate)
|
||||
@@ -54,4 +65,131 @@ class GadaianController extends Controller
|
||||
|
||||
return json_encode($response);
|
||||
}
|
||||
|
||||
public function getSummaryLaporanGadaiTebus(Request $request)
|
||||
{
|
||||
$startDate = $request->startDate;
|
||||
$endDate = $request->endDate;
|
||||
|
||||
// Get active branch DBs from helper
|
||||
$active_cawangan_db_connection = Helper::getActiveCawanganDbConnection();
|
||||
|
||||
// Fetch branch details with mysql info
|
||||
$cawangan_available = Cawangan::select('kodcaw', 'details_caw', 'mysql')
|
||||
->whereIn('mysql', $active_cawangan_db_connection)
|
||||
->get();
|
||||
|
||||
// Get db connections
|
||||
$active_cawangan_db_connection = array_column($cawangan_available->toArray(), 'mysql');
|
||||
|
||||
// Map branch info for response
|
||||
$active_cawangan_detail = $cawangan_available->map(function ($c) {
|
||||
return [
|
||||
'kodcaw' => $c->kodcaw,
|
||||
'details_caw' => $c->details_caw,
|
||||
];
|
||||
})->values()->toArray();
|
||||
|
||||
// Loop through each DB
|
||||
$summary_data = array_map(function ($db_connection) use ($startDate, $endDate) {
|
||||
$result = DB::connection($db_connection)->table('gadai as g')
|
||||
->join('tebus as t', function ($join) {
|
||||
$join->on(DB::raw('DATE(g.t_gadai)'), '=', DB::raw('DATE(t.t_tebus)'))
|
||||
->on('g.norujukan', '=', 't.norujukan');
|
||||
})
|
||||
->whereDate('g.t_gadai', '>=', $startDate)
|
||||
->whereDate('g.t_gadai', '<=', $endDate)
|
||||
->whereDate('t.t_tebus', '>=', $startDate)
|
||||
->whereDate('t.t_tebus', '<=', $endDate)
|
||||
->where('g.upah12', '>=', 0.00)
|
||||
->selectRaw('
|
||||
COUNT(DISTINCT g.norujukan) as total_gadai_tebus_samahari,
|
||||
SUM(g.pinjaman) as jumlah_pinjaman
|
||||
')
|
||||
->first(); // ambil satu hasil, bukan collection
|
||||
|
||||
return (array) $result ?: [
|
||||
'total_gadai_tebus_samahari' => 0,
|
||||
'jumlah_pinjaman' => 0.00
|
||||
];
|
||||
}, $active_cawangan_db_connection);
|
||||
|
||||
|
||||
// Gabung cawangan + hasil
|
||||
$response = array_map(function ($cawangan_detail, $summary_row) {
|
||||
return array_merge($cawangan_detail, $summary_row ?: [
|
||||
'total_gadai_tebus_samahari' => 0,
|
||||
'jumlah_pinjaman' => 0.00
|
||||
]);
|
||||
}, $active_cawangan_detail, $summary_data);
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
public function getSummaryLaporanGadaiTebusMasa(Request $request)
|
||||
{
|
||||
$startDate = $request->startDate;
|
||||
$endDate = $request->endDate;
|
||||
|
||||
// Ambil connection aktif
|
||||
$active_cawangan_db_connection = Helper::getActiveCawanganDbConnection();
|
||||
|
||||
// Dapatkan butiran cawangan
|
||||
$cawangan_available = Cawangan::select('kodcaw', 'details_caw', 'mysql')
|
||||
->whereIn('mysql', $active_cawangan_db_connection)
|
||||
->get();
|
||||
|
||||
$active_cawangan_db_connection = array_column($cawangan_available->toArray(), 'mysql');
|
||||
|
||||
// Map branch info for response
|
||||
$active_cawangan_detail = $cawangan_available->map(function ($c) {
|
||||
return [
|
||||
'kodcaw' => $c->kodcaw,
|
||||
'details_caw' => $c->details_caw,
|
||||
];
|
||||
})->values()->toArray();
|
||||
|
||||
// Loop through each DB
|
||||
$summary_data = array_map(function ($db_connection) use ($startDate, $endDate) {
|
||||
$result = DB::connection($db_connection)->table('gadai as g')
|
||||
->join('tebus as t', function ($join) {
|
||||
$join->on(DB::raw('DATE(g.t_gadai)'), '=', DB::raw('DATE(t.t_tebus)'))
|
||||
->on('g.norujukan', '=', 't.norujukan');
|
||||
})
|
||||
->whereDate('g.t_gadai', '>=', $startDate)
|
||||
->whereDate('g.t_gadai', '<=', $endDate)
|
||||
->whereDate('t.t_tebus', '>=', $startDate)
|
||||
->whereDate('t.t_tebus', '<=', $endDate)
|
||||
->where('g.upah12', '>=', 0.00)
|
||||
->selectRaw('
|
||||
COUNT(DISTINCT g.norujukan) as total_gadai_tebus_samahari,
|
||||
SUM(g.pinjaman) as jumlah_pinjaman
|
||||
')
|
||||
->first(); // ambil satu hasil, bukan collection
|
||||
|
||||
return (array) $result ?: [
|
||||
'total_gadai_tebus_samahari' => 0,
|
||||
'jumlah_pinjaman' => 0.00
|
||||
];
|
||||
}, $active_cawangan_db_connection);
|
||||
|
||||
|
||||
// Gabung cawangan + hasil
|
||||
$response = array_map(function ($cawangan_detail, $summary_row) {
|
||||
return array_merge($cawangan_detail, $summary_row ?: [
|
||||
'total_gadai_tebus_samahari' => 0,
|
||||
'jumlah_pinjaman' => 0.00
|
||||
]);
|
||||
}, $active_cawangan_detail, $summary_data);
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
|
||||
public function getLaporanGadaiTebusMasaCawangan(string $kod_cawangan, Request $request)
|
||||
{
|
||||
$ReportGadaianService = new ReportGadaianService($kod_cawangan, $request);
|
||||
return $ReportGadaianService->getCawanganReportGadaiTebusMasa();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Reports;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Cawangan;
|
||||
use App\Lelong;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Services\Reports\LelonganService as ReportLelonganService;
|
||||
use App\Helper;
|
||||
|
||||
|
||||
class LelonganController extends Controller
|
||||
{
|
||||
|
||||
public function getLaporanCawangan(string $kod_cawangan, Request $request)
|
||||
{
|
||||
$reportLelonganService = new ReportLelonganService($kod_cawangan, $request);
|
||||
return $reportLelonganService->getCawanganReport();
|
||||
}
|
||||
|
||||
public function getSummaryLaporanLelong(Request $request)
|
||||
{
|
||||
$onDate = $request->onDate;
|
||||
$startDate = $request->startDate;
|
||||
$endDate = $request->endDate;
|
||||
|
||||
// Get active branches in the order we want
|
||||
$active_cawangan_db_connection = Helper::getActiveCawanganDbConnection();
|
||||
|
||||
// Preserve keys while mapping database names
|
||||
$active_cawangan_db_name = array_combine(
|
||||
$active_cawangan_db_connection,
|
||||
array_map(function ($db_connection) {
|
||||
return config('database.connections.' . $db_connection . '.database');
|
||||
}, $active_cawangan_db_connection)
|
||||
);
|
||||
// dd($active_cawangan_db_name);
|
||||
|
||||
// Retrieve branch details and re-index by db_name
|
||||
$active_cawangan_detail = Cawangan::select('kodcaw', 'details_caw', 'db_name')
|
||||
->whereIn('db_name', array_values($active_cawangan_db_name))
|
||||
->get()
|
||||
->keyBy('db_name')
|
||||
->toArray();
|
||||
// dd($active_cawangan_detail);
|
||||
|
||||
// Retrieve lelong summary data and re-index by db_connection
|
||||
$summary_lelongan_data = [];
|
||||
foreach ($active_cawangan_db_connection as $db_connection) {
|
||||
$query = Lelong::on($db_connection)
|
||||
->join('gadai', 'gadai.norujukan', '=', 'lelong.norujukan')
|
||||
->select(DB::raw('count(lelong.norujukan) as total_lelongan,
|
||||
sum(lelong.berat) as sum_berat,
|
||||
sum(lelong.nilaimarhun) as sum_nilai_marhun,
|
||||
sum(gadai.pinjaman) as sum_pinjaman,
|
||||
sum(lelong.pinjaman) as sum_bakipjm,
|
||||
sum(lelong.bakiupah) as sum_bakiupah,
|
||||
sum(lelong.cajlain) as sum_cajlain,
|
||||
sum(lelong.cajlelong) as sum_cajlelong,
|
||||
sum(lelong.hargajual) as sum_hargajual,
|
||||
sum(lelong.baki) as sum_baki'));
|
||||
|
||||
|
||||
if ($request->filled('startDate') && $request->filled('endDate')) {
|
||||
$query->whereBetween('lelong.t_jual', [$request->startDate, $request->endDate]);
|
||||
}
|
||||
|
||||
$summary_lelongan_data[$db_connection] = $query->first()->toArray();
|
||||
}
|
||||
|
||||
// Ensure data is sorted according to getActiveCawanganDbConnection()
|
||||
$response = [];
|
||||
foreach ($active_cawangan_db_connection as $db_connection) {
|
||||
$db_name = $active_cawangan_db_name[$db_connection] ?? null;
|
||||
if ($db_name && isset($active_cawangan_detail[$db_name])) {
|
||||
$response[] = array_merge(
|
||||
$active_cawangan_detail[$db_name],
|
||||
$summary_lelongan_data[$db_connection] ?? []
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return json_encode($response);
|
||||
}
|
||||
|
||||
public function getSummaryLaporanBakiLelongBelumTuntut(Request $request)
|
||||
{
|
||||
$onDate = $request->onDate;
|
||||
$startDate = $request->startDate;
|
||||
$endDate = $request->endDate;
|
||||
|
||||
// Get active branches in the order we want
|
||||
$active_cawangan_db_connection = Helper::getActiveCawanganDbConnection();
|
||||
|
||||
// Preserve keys while mapping database names
|
||||
$active_cawangan_db_name = array_combine(
|
||||
$active_cawangan_db_connection,
|
||||
array_map(function ($db_connection) {
|
||||
return config('database.connections.' . $db_connection . '.database');
|
||||
}, $active_cawangan_db_connection)
|
||||
);
|
||||
// dd($active_cawangan_db_name);
|
||||
|
||||
// Retrieve branch details and re-index by db_name
|
||||
$active_cawangan_detail = Cawangan::select('kodcaw', 'details_caw', 'db_name')
|
||||
->whereIn('db_name', array_values($active_cawangan_db_name))
|
||||
->get()
|
||||
->keyBy('db_name')
|
||||
->toArray();
|
||||
// dd($active_cawangan_detail);
|
||||
|
||||
// Retrieve lelong summary data and re-index by db_connection
|
||||
$summary_lelongan_data = [];
|
||||
foreach ($active_cawangan_db_connection as $db_connection) {
|
||||
$query = Lelong::on($db_connection)
|
||||
->join('gadai', 'gadai.norujukan', '=', 'lelong.norujukan')
|
||||
->select(DB::raw('count(lelong.norujukan) as total_lelongan,
|
||||
sum(lelong.berat) as sum_berat,
|
||||
sum(lelong.nilaimarhun) as sum_nilai_marhun,
|
||||
sum(gadai.pinjaman) as sum_pinjaman,
|
||||
sum(lelong.pinjaman) as sum_bakipjm,
|
||||
sum(lelong.bakiupah) as sum_bakiupah,
|
||||
sum(lelong.cajlain) as sum_cajlain,
|
||||
sum(lelong.cajlelong) as sum_cajlelong,
|
||||
sum(lelong.hargajual) as sum_hargajual,
|
||||
sum(lelong.baki) as sum_baki'))
|
||||
->where(function ($query) use ($request) {
|
||||
$query->whereNull('lelong.trkhtuntut')
|
||||
->orWhere('lelong.trkhtuntut', '>', $request->endDate); // or use a specific date: '2025-06-01'
|
||||
})
|
||||
->where('lelong.baki', '>', 0.00)
|
||||
->orderBy('lelong.norujukan', 'asc');
|
||||
|
||||
|
||||
if ($request->filled('startDate') && $request->filled('endDate')) {
|
||||
$query->whereBetween('lelong.t_lelong', [$request->startDate, $request->endDate]);
|
||||
}
|
||||
|
||||
$summary_lelongan_data[$db_connection] = $query->first()->toArray();
|
||||
}
|
||||
|
||||
// Ensure data is sorted according to getActiveCawanganDbConnection()
|
||||
$response = [];
|
||||
foreach ($active_cawangan_db_connection as $db_connection) {
|
||||
$db_name = $active_cawangan_db_name[$db_connection] ?? null;
|
||||
if ($db_name && isset($active_cawangan_detail[$db_name])) {
|
||||
$response[] = array_merge(
|
||||
$active_cawangan_detail[$db_name],
|
||||
$summary_lelongan_data[$db_connection] ?? []
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return json_encode($response);
|
||||
}
|
||||
|
||||
public function getLaporanBakiLelongBelumTuntutCawangan(string $kod_cawangan, Request $request)
|
||||
{
|
||||
$reportLelonganService = new ReportLelonganService($kod_cawangan, $request);
|
||||
return $reportLelonganService->getCawanganReportBakiLelongBelumTuntut();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Reports;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Cawangan;
|
||||
use App\Gadai;
|
||||
use App\Vault;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Services\Reports\OutstandingService as ReportOutstandingService;
|
||||
use App\Helper;
|
||||
|
||||
|
||||
class OutstandingController extends Controller
|
||||
{
|
||||
|
||||
public function getLaporanCawangan(string $kod_cawangan, Request $request)
|
||||
{
|
||||
$reportOutstandingService = new ReportOutstandingService($kod_cawangan, $request);
|
||||
return $reportOutstandingService->getCawanganReport();
|
||||
}
|
||||
|
||||
public function getSummaryLaporanOutstanding(Request $request)
|
||||
{
|
||||
$endDate = $request->endDate;
|
||||
|
||||
// Get active branch DBs from helper
|
||||
$active_cawangan_db_connection = Helper::getActiveCawanganDbConnection();
|
||||
|
||||
// Fetch branch details with mysql info
|
||||
$cawangan_available = Cawangan::select('kodcaw', 'details_caw', 'mysql')
|
||||
->whereIn('mysql', $active_cawangan_db_connection)
|
||||
->get();
|
||||
|
||||
// Get db connections
|
||||
$active_cawangan_db_connection = array_column($cawangan_available->toArray(), 'mysql');
|
||||
|
||||
// Map branch info for response
|
||||
$active_cawangan_detail = $cawangan_available->map(function ($c) {
|
||||
return [
|
||||
'kodcaw' => $c->kodcaw,
|
||||
'details_caw' => $c->details_caw,
|
||||
];
|
||||
})->values()->toArray();
|
||||
|
||||
// Query outstanding summary for each branch
|
||||
$summary_Outstanding_data = array_map(function ($db_connection) use ($endDate) {
|
||||
// SAG LAMA
|
||||
$queryLama = Gadai::on($db_connection)
|
||||
->selectRaw('COUNT(norujukan) as total_gadaian, SUM(pinjaman) as sum_pinjaman')
|
||||
->where('tagbaru', 0)
|
||||
->where('sttebus', '');
|
||||
|
||||
// SAG BARU
|
||||
$queryBaru = Gadai::on($db_connection)
|
||||
->selectRaw('COUNT(norujukan) as total_gadaian2, SUM(pinjaman) as sum_pinjaman2')
|
||||
->where('tagbaru', 1)
|
||||
->where('sttebus', '');
|
||||
|
||||
// SEMUA
|
||||
$queryAll = Gadai::on($db_connection)
|
||||
->selectRaw('COUNT(norujukan) as total_gadaian_all, SUM(pinjaman) as sum_pinjaman_all')
|
||||
->where('sttebus', '');
|
||||
|
||||
if (!empty($endDate)) {
|
||||
$queryLama->where('t_gadai', '<=', $endDate);
|
||||
$queryBaru->where('t_gadai', '<=', $endDate);
|
||||
$queryAll->where('t_gadai', '<=', $endDate);
|
||||
}
|
||||
|
||||
return array_merge(
|
||||
$queryLama->first()->toArray(),
|
||||
$queryBaru->first()->toArray(),
|
||||
$queryAll->first()->toArray()
|
||||
);
|
||||
}, $active_cawangan_db_connection);
|
||||
|
||||
// Combine data with branch info
|
||||
$response = array_map(function ($cawangan_detail, $outstanding_data) {
|
||||
return array_merge($cawangan_detail, $outstanding_data);
|
||||
}, $active_cawangan_detail, $summary_Outstanding_data);
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
|
||||
public function getSummaryLaporanPetibesi(Request $request)
|
||||
{
|
||||
$endDate = $request->endDate;
|
||||
|
||||
// Get active branch DBs from helper
|
||||
$active_cawangan_db_connection = Helper::getActiveCawanganDbConnection();
|
||||
|
||||
// Fetch branch details with mysql info
|
||||
$cawangan_available = Cawangan::select('kodcaw', 'details_caw', 'mysql')
|
||||
->whereIn('mysql', $active_cawangan_db_connection)
|
||||
->get();
|
||||
|
||||
// Get db connections
|
||||
$active_cawangan_db_connection = array_column($cawangan_available->toArray(), 'mysql');
|
||||
|
||||
// Map branch info for response
|
||||
$active_cawangan_detail = $cawangan_available->map(function ($c) {
|
||||
return [
|
||||
'kodcaw' => $c->kodcaw,
|
||||
'details_caw' => $c->details_caw,
|
||||
];
|
||||
})->values()->toArray();
|
||||
|
||||
// Query petibesi summary for each branch
|
||||
$summary_petibesi_data = array_map(function ($db_connection) use ($endDate) {
|
||||
|
||||
|
||||
// SEMUA
|
||||
$queryAll = Vault::on($db_connection)
|
||||
->selectRaw('bakieod');
|
||||
|
||||
if (!empty($endDate)) {
|
||||
$queryAll->where('tarikh', '=', $endDate);
|
||||
}
|
||||
|
||||
return array_merge(
|
||||
$queryAll->first()->toArray()
|
||||
);
|
||||
}, $active_cawangan_db_connection);
|
||||
|
||||
// Combine data with branch info
|
||||
$response = array_map(function ($cawangan_detail, $petibesi_data) {
|
||||
return array_merge($cawangan_detail, $petibesi_data);
|
||||
}, $active_cawangan_detail, $summary_petibesi_data);
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -21,14 +21,24 @@ class PenebusanController extends Controller
|
||||
|
||||
public function getSummaryLaporanTebus(Request $request)
|
||||
{
|
||||
|
||||
// Get active branch DBs from helper
|
||||
$active_cawangan_db_connection = Helper::getActiveCawanganDbConnection();
|
||||
|
||||
$active_cawangan_db_name = array_map(function ($db_connection) {
|
||||
return config('database.connections' . '.' . $db_connection . '.' . 'database');
|
||||
}, $active_cawangan_db_connection);
|
||||
|
||||
$active_cawangan_detail = Cawangan::select('kodcaw', 'details_caw')->whereIn('db_name', $active_cawangan_db_name)->get()->toArray();
|
||||
|
||||
// Fetch branch details with mysql info
|
||||
$cawangan_available = Cawangan::select('kodcaw', 'details_caw', 'mysql')
|
||||
->whereIn('mysql', $active_cawangan_db_connection)
|
||||
->get();
|
||||
|
||||
// Get db connections
|
||||
$active_cawangan_db_connection = array_column($cawangan_available->toArray(), 'mysql');
|
||||
|
||||
// Map branch info for response
|
||||
$active_cawangan_detail = $cawangan_available->map(function ($c) {
|
||||
return [
|
||||
'kodcaw' => $c->kodcaw,
|
||||
'details_caw' => $c->details_caw,
|
||||
];
|
||||
})->values()->toArray();
|
||||
|
||||
$summary_penebusan_data = array_map(function ($db_connection) use ($request) {
|
||||
$penebusan = Tebus::on($db_connection)
|
||||
@@ -39,8 +49,8 @@ class PenebusanController extends Controller
|
||||
->select(DB::raw('
|
||||
count(tebus.norujukan) as bilangan_tebus,
|
||||
sum(gadai.berat) as berat,
|
||||
sum(gadai.bakipjm) as nilai_pinjaman,
|
||||
sum(tebus.pinjaman) as baki_pinjaman,
|
||||
sum(gadai.pinjaman) as nilai_pinjaman,
|
||||
sum(gadai.bakipjm) as baki_pinjaman,
|
||||
sum(tebus.nilaimarhun) as nilai_marhun,
|
||||
sum(tebus.bakiupah) as keuntungan_asal,
|
||||
sum(tebus.bakipjm - gadai.bakipjm) as keuntungan_rebet,
|
||||
|
||||
@@ -51,16 +51,66 @@ class StokAuditController extends Controller
|
||||
// dd($request->kodcaw);
|
||||
$daritempoh = $request->daritempoh;
|
||||
$hinggatempoh = $request->hinggatempoh;
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$request->kodcaw)->first();
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw', '=', $request->kodcaw)->first();
|
||||
|
||||
// Query asal gadai
|
||||
$audit = Gadai::on($cawangan['mysql'])
|
||||
->where([['tagpalsu','=',0],['tempoh','>=',$daritempoh],['tempoh','<=',$hinggatempoh],['sttebus','=',''],['taglel','=',0]])
|
||||
->where([
|
||||
['tagpalsu', '=', 0],
|
||||
['tempoh', '>=', $daritempoh],
|
||||
['tempoh', '<=', $hinggatempoh],
|
||||
['sttebus', '=', ''],
|
||||
['taglel', '=', 0],
|
||||
])
|
||||
->orderBy('t_gadai', 'ASC')
|
||||
->orderBy('sirig', 'ASC');
|
||||
// ->get();
|
||||
// dd($audit);
|
||||
->orderBy('sirig', 'ASC')
|
||||
->get();
|
||||
|
||||
// Dapatkan semua norujukan awal
|
||||
$arraynorujukan = $audit->pluck('norujukan')->toArray();
|
||||
$rekodaudit = $audit->get();
|
||||
|
||||
// Dapatkan tarikh terkini untuk setiap norujukan ikut trans_type T
|
||||
$tarikhTerkiniT = Transaction::on('mysql7')
|
||||
->select('norujukan', DB::raw('MAX(created_at) as tarikh_max'))
|
||||
->where('trans_type', 'T')
|
||||
->whereIn('norujukan', $arraynorujukan)
|
||||
->groupBy('norujukan')
|
||||
->pluck('tarikh_max', 'norujukan')
|
||||
->toArray();
|
||||
|
||||
// Dapatkan tarikh terkini untuk setiap norujukan ikut trans_type A
|
||||
$tarikhTerkiniA = Transaction::on('mysql7')
|
||||
->select('norujukan', DB::raw('MAX(created_at) as tarikh_max'))
|
||||
->where('trans_type', 'A')
|
||||
->whereIn('norujukan', $arraynorujukan)
|
||||
->groupBy('norujukan')
|
||||
->pluck('tarikh_max', 'norujukan')
|
||||
->toArray();
|
||||
|
||||
// Filter audit ikut tarikh masing-masing
|
||||
$rekodaudit = $audit->filter(function ($item) use ($tarikhTerkiniT, $tarikhTerkiniA) {
|
||||
$norujukan = $item->norujukan;
|
||||
|
||||
$adaTebusTerkini = isset($tarikhTerkiniT[$norujukan]) &&
|
||||
Transaction::on('mysql7')
|
||||
->where('norujukan', $norujukan)
|
||||
->where('trans_type', 'T')
|
||||
->whereDate('created_at', '>=', date('Y-m-d', strtotime($tarikhTerkiniT[$norujukan])))
|
||||
->exists();
|
||||
|
||||
$adaAnsuranTerkini = isset($tarikhTerkiniA[$norujukan]) &&
|
||||
Transaction::on('mysql7')
|
||||
->where('norujukan', $norujukan)
|
||||
->where('trans_type', 'A')
|
||||
->whereDate('created_at', '>=', date('Y-m-d', strtotime($tarikhTerkiniA[$norujukan])))
|
||||
->exists();
|
||||
|
||||
return !$adaTebusTerkini && !$adaAnsuranTerkini;
|
||||
})->values();
|
||||
|
||||
// Gunakan hanya norujukan yang dah ditapis
|
||||
$arraynorujukan = $rekodaudit->pluck('norujukan')->toArray();
|
||||
|
||||
$gadainokp = Gadai::on($cawangan['mysql'])->whereIn('norujukan', $arraynorujukan)
|
||||
->select('nokp')
|
||||
->groupBy('nokp')
|
||||
@@ -68,28 +118,23 @@ class StokAuditController extends Controller
|
||||
|
||||
// dd($gadainokp);
|
||||
|
||||
foreach($gadainokp as $index1=>$cal){
|
||||
$customer = Customer::on('mysql7')->where('kpbaru','=',$cal['nokp'])
|
||||
->orWhere('kplama','=',$cal['nokp'])
|
||||
foreach ($gadainokp as $index1 => $cal) {
|
||||
$customer = Customer::on('mysql7')->where('kpbaru', '=', $cal['nokp'])
|
||||
->orWhere('kplama', '=', $cal['nokp'])
|
||||
->first();
|
||||
|
||||
$listsag = Gadai::on($cawangan['mysql'])->whereIn('norujukan', $arraynorujukan)
|
||||
// ->where('nokp','=',$cal['nokp'])
|
||||
->where('nokp', 'like', '%'.$cal['nokp'].'%')
|
||||
->where('nokp', 'like', '%' . $cal['nokp'] . '%')
|
||||
->get();
|
||||
|
||||
foreach($listsag as $index2=>$cal2){
|
||||
|
||||
if($cal2){
|
||||
$checkingnokp = null;
|
||||
foreach ($listsag as $index2 => $cal2) {
|
||||
if ($cal2) {
|
||||
$checkingnokp = BlastWasap::on('mysql7')
|
||||
->where('nokp','=',$cal['nokp'])
|
||||
->where('norujukan','=',$cal2['norujukan'])
|
||||
->where('kodcaw','=',$kodcaw)
|
||||
->where('nokp', '=', $cal['nokp'])
|
||||
->where('norujukan', '=', $cal2['norujukan'])
|
||||
->where('kodcaw', '=', $kodcaw)
|
||||
->first();
|
||||
|
||||
// $gadainokp[$index1]['blasted'] = $checkingnokp;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,17 +142,24 @@ class StokAuditController extends Controller
|
||||
$gadainokp[$index1]['listsag'] = $listsag;
|
||||
$gadainokp[$index1]['blasted'] = $checkingnokp;
|
||||
}
|
||||
|
||||
$totalrekod = $audit->sum('pinjaman');
|
||||
$totalberat = $audit->sum('berat');
|
||||
$totalnilaimarhun = $audit->sum('nilaimarhun');
|
||||
$totalpinjaman = $audit->sum('pinjaman');
|
||||
$totalbakipjm = $audit->sum('bakipjm');
|
||||
$totaltunggakan = $audit->sum('tunggakan');
|
||||
// Total dikira berdasarkan hasil audit yang telah ditapis
|
||||
$totalrekod = $rekodaudit->sum('pinjaman');
|
||||
$totalberat = $rekodaudit->sum('berat');
|
||||
$totalnilaimarhun = $rekodaudit->sum('nilaimarhun');
|
||||
$totalpinjaman = $rekodaudit->sum('pinjaman');
|
||||
$totalbakipjm = $rekodaudit->sum('bakipjm');
|
||||
$totaltunggakan = $rekodaudit->sum('tunggakan');
|
||||
|
||||
$arrayrekod = ['rekod' => $gadainokp, 'total' => $totalrekod,'totalberat' => $totalberat,'totalnilaimarhun' => $totalnilaimarhun,'totalpinjaman'=>$totalpinjaman,'totalbakipjm'=>$totalbakipjm,'totaltunggakan'=>$totaltunggakan];
|
||||
// dd($arrayrekod);
|
||||
return response()->json($arrayrekod,200);
|
||||
$arrayrekod = [
|
||||
'rekod' => $gadainokp,
|
||||
'total' => $totalrekod,
|
||||
'totalberat' => $totalberat,
|
||||
'totalnilaimarhun' => $totalnilaimarhun,
|
||||
'totalpinjaman' => $totalpinjaman,
|
||||
'totalbakipjm' => $totalbakipjm,
|
||||
'totaltunggakan' => $totaltunggakan,
|
||||
];
|
||||
return response()->json($arrayrekod, 200);
|
||||
}
|
||||
|
||||
|
||||
@@ -380,4 +432,151 @@ class StokAuditController extends Controller
|
||||
'totaltunggakan'=>$totaltunggakan ?? null];
|
||||
return response()->json($arrayrekod,200);
|
||||
}
|
||||
|
||||
|
||||
public function LaporanAuditKhasByNorujukan($kodcaw, Request $request)
|
||||
{
|
||||
$daritempoh = $request->daritempoh;
|
||||
$hinggatempoh = $request->hinggatempoh;
|
||||
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw', '=', $request->kodcaw)->first();
|
||||
|
||||
// Ambil semua rekod gadai asas
|
||||
$audit = Gadai::on($cawangan['mysql'])
|
||||
->where([
|
||||
['tagpalsu', '=', 0],
|
||||
['tempoh', '>=', $daritempoh],
|
||||
['tempoh', '<=', $hinggatempoh],
|
||||
['sttebus', '=', ''],
|
||||
['taglel', '=', 0],
|
||||
])
|
||||
->orderBy('norujukan', 'ASC') // susun ikut norujukan
|
||||
->get();
|
||||
|
||||
$arraynorujukan = $audit->pluck('norujukan')->toArray();
|
||||
|
||||
// Tarikh terkini ikut trans_type T
|
||||
$tarikhTerkiniT = Transaction::on('mysql7')
|
||||
->select('norujukan', DB::raw('MAX(created_at) as tarikh_max'))
|
||||
->where('trans_type', 'T')
|
||||
->whereIn('norujukan', $arraynorujukan)
|
||||
->groupBy('norujukan')
|
||||
->pluck('tarikh_max', 'norujukan')
|
||||
->toArray();
|
||||
|
||||
// Tarikh terkini ikut trans_type A
|
||||
$tarikhTerkiniA = Transaction::on('mysql7')
|
||||
->select('norujukan', DB::raw('MAX(created_at) as tarikh_max'))
|
||||
->where('trans_type', 'A')
|
||||
->whereIn('norujukan', $arraynorujukan)
|
||||
->groupBy('norujukan')
|
||||
->pluck('tarikh_max', 'norujukan')
|
||||
->toArray();
|
||||
|
||||
// Filter audit
|
||||
$rekodaudit = $audit->filter(function ($item) use ($tarikhTerkiniT, $tarikhTerkiniA) {
|
||||
$norujukan = $item->norujukan;
|
||||
|
||||
$adaTebusTerkini = isset($tarikhTerkiniT[$norujukan]) &&
|
||||
Transaction::on('mysql7')
|
||||
->where('norujukan', $norujukan)
|
||||
->where('trans_type', 'T')
|
||||
->whereDate('created_at', '>=', date('Y-m-d', strtotime($tarikhTerkiniT[$norujukan])))
|
||||
->exists();
|
||||
|
||||
$adaAnsuranTerkini = isset($tarikhTerkiniA[$norujukan]) &&
|
||||
Transaction::on('mysql7')
|
||||
->where('norujukan', $norujukan)
|
||||
->where('trans_type', 'A')
|
||||
->whereDate('created_at', '>=', date('Y-m-d', strtotime($tarikhTerkiniA[$norujukan])))
|
||||
->exists();
|
||||
|
||||
return !$adaTebusTerkini && !$adaAnsuranTerkini;
|
||||
})->values();
|
||||
|
||||
// Attach customer info + blast untuk setiap norujukan
|
||||
foreach ($rekodaudit as $index => $rekod) {
|
||||
$customer = Customer::on('mysql7')
|
||||
->where('kpbaru', '=', $rekod->nokp)
|
||||
->orWhere('kplama', '=', $rekod->nokp)
|
||||
->first();
|
||||
|
||||
$rekodaudit[$index]['customer'] = $customer;
|
||||
|
||||
$rekodaudit[$index]['blasted'] = BlastWasap::on('mysql7')
|
||||
->where('nokp', $rekod->nokp)
|
||||
->where('norujukan', $rekod->norujukan)
|
||||
->where('kodcaw', $kodcaw)
|
||||
->first();
|
||||
|
||||
// 👉 Kira keuntungan (tunggakan sebenar) guna function
|
||||
$upah = $this->kiraupahUjrahOnePercent($kodcaw, $rekod->norujukan);
|
||||
$keuntungan = $upah['ujrah'] + $upah['onepercent'];
|
||||
|
||||
// Save ke dalam rekod
|
||||
$rekodaudit[$index]['tunggakan'] = $this->floorTo5SenFrom2dp($keuntungan);
|
||||
}
|
||||
|
||||
// Summary total
|
||||
$summary = [
|
||||
'totalrekod' => $rekodaudit->count(),
|
||||
'totalberat' => $rekodaudit->sum('berat'),
|
||||
'totalnilaimarhun'=> $rekodaudit->sum('nilaimarhun'),
|
||||
'totalpinjaman' => $rekodaudit->sum('pinjaman'),
|
||||
'totalbakipjm' => $rekodaudit->sum('bakipjm'),
|
||||
'totaltunggakan' => $rekodaudit->sum('tunggakan'),
|
||||
];
|
||||
|
||||
return response()->json([
|
||||
'rekod' => $rekodaudit,
|
||||
'summary' => $summary,
|
||||
]);
|
||||
}
|
||||
|
||||
public function kiraupahUjrahOnePercent($kodcaw,$norujukan){
|
||||
$onepercentservices = new OnePercentServices();
|
||||
|
||||
$cawangan = Cawangan::on('mysql7')
|
||||
->where('kodcaw','=',$kodcaw)
|
||||
->first();
|
||||
|
||||
$gadai_data = Gadai::on($cawangan['mysql'])
|
||||
->where('norujukan','=',$norujukan)
|
||||
->first();
|
||||
|
||||
if($gadai_data['tempoh'] >= 12.0){
|
||||
$tempoh = 12;
|
||||
}else{
|
||||
$tempoh = $gadai_data['tempoh'];
|
||||
}
|
||||
|
||||
$bilang_bln = $tempoh - $gadai_data['tempohbayar'];
|
||||
$array_upah = $onepercentservices->kiraanKeuntunganSebenar($gadai_data['pinjaman'],$gadai_data['nilaimarhun'],$gadai_data['kadarupah'],$gadai_data['percentpinj']);
|
||||
$ujrah = $bilang_bln * $array_upah['ujrah'];
|
||||
$onepercent = $bilang_bln * $array_upah['onepercent'];
|
||||
$onepercent_semasa = $onepercent;
|
||||
$ujrah_semasa = $ujrah;
|
||||
|
||||
return ['ujrah' => $ujrah_semasa, 'onepercent' => $onepercent_semasa];
|
||||
}
|
||||
|
||||
// dalam Controller (private/protected)
|
||||
private function floorTo5SenFrom2dp($amount)
|
||||
{
|
||||
// pastikan numeric
|
||||
$amount = (float) $amount;
|
||||
|
||||
// 1) Tukar ke sen dan buang sebarang pecahan sen (hanya baca 2 dp)
|
||||
// tambah epsilon kecil untuk elak isu floating point
|
||||
$cents = (int) floor($amount * 100 + 0.0000001);
|
||||
|
||||
// 2) Floor ke gandaan 5 sen
|
||||
$cents5 = (int) (floor($cents / 5) * 5);
|
||||
|
||||
// balik ke ringgit
|
||||
return $cents5 / 100;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -669,11 +669,45 @@ class TebusController extends Controller
|
||||
}
|
||||
|
||||
public function listhistorypenebusan($kodcaw,Request $request){
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw', $kodcaw)->first();
|
||||
|
||||
$listtebus = Tebus::on($cawangan['mysql'])
|
||||
->where('norujukan','=',$request->norujukan)
|
||||
->get();
|
||||
->where('norujukan', $request->norujukan)
|
||||
->get();
|
||||
|
||||
foreach ($listtebus as $tebus) {
|
||||
// Cari transaction padan berdasarkan norujukan dan trans_type = 'A'
|
||||
$transaction = \DB::connection('mysql7')
|
||||
->table('transaction')
|
||||
->where('norujukan', $tebus->norujukan)
|
||||
->whereIn('trans_type', ['T', 'AT'])
|
||||
->first();
|
||||
|
||||
// Jika wujud, cari transaksi_keuntungan yang padan ikut tarikh
|
||||
if ($transaction) {
|
||||
$createdDate = Carbon::parse($transaction->created_at)->toDateString();
|
||||
|
||||
$keuntungan = \DB::connection('mysql7')
|
||||
->table('transaksi_keuntungan')
|
||||
->where('norujukan', $tebus->norujukan)
|
||||
->whereDate('tarikh_bayaran', $createdDate)
|
||||
->first();
|
||||
|
||||
if ($transaction->trans_type == 'T') {
|
||||
$tebus->bayaran_keuntungan = number_format($keuntungan->keuntungan_rebet ?? 0, 2);
|
||||
} elseif ($transaction->trans_type == 'AT') {
|
||||
$tebus->bayaran_keuntungan = number_format($keuntungan->bayaran_keuntungan ?? 0, 2);
|
||||
}
|
||||
|
||||
$tebus->bayaran_pembiayaan = number_format($keuntungan->bayaran_pembiayaan ?? 0, 2);
|
||||
$tebus->duit_masuk = number_format($transaction->duit_masuk ?? 0, 2);
|
||||
$tebus->trans_type = $transaction->trans_type ?? null;
|
||||
} else {
|
||||
$tebus->bayaran_keuntungan = null;
|
||||
$tebus->bayaran_pembiayaan = null;
|
||||
$tebus->duit_masuk = null;
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json($listtebus);
|
||||
}
|
||||
|
||||
@@ -57,9 +57,24 @@ class TransactionController extends Controller
|
||||
|
||||
public function getTransactionByRujukan($norujukan){
|
||||
|
||||
$transaction = Transaction::on('mysql7')->where([['norujukan','=',$norujukan],['trans_type','=','A']])->get();
|
||||
$transactions = Transaction::on('mysql7')
|
||||
->where('norujukan', $norujukan)
|
||||
->where('trans_type', 'A')
|
||||
->get();
|
||||
|
||||
return response()->json($transaction);
|
||||
foreach ($transactions as $transaction) {
|
||||
$createdDate = Carbon::parse($transaction->created_at)->toDateString();
|
||||
|
||||
$keuntungan = \DB::connection('mysql7')
|
||||
->table('transaksi_keuntungan')
|
||||
->whereDate('tarikh_bayaran', $createdDate)
|
||||
->where('norujukan', $transaction->norujukan)
|
||||
->first(); // ambil seluruh rekod
|
||||
|
||||
$transaction->bayaran_keuntungan = number_format($keuntungan->bayaran_keuntungan ?? 0, 2);
|
||||
$transaction->bayaran_pembiayaan = number_format($keuntungan->bayaran_pembiayaan ?? 0, 2);
|
||||
}
|
||||
return response()->json($transactions);
|
||||
}
|
||||
|
||||
public function getTransactionByid($id){
|
||||
|
||||
@@ -25,8 +25,7 @@ class TransactionOnlineController extends Controller
|
||||
{
|
||||
public function getTransactionOnline(Request $request)
|
||||
{
|
||||
$transactionOnline = TransactionOnline::on('mysql7')->where('billplz_id', $request->billplz_id)->first();
|
||||
|
||||
$transactionOnline = TransactionOnline::on('mysql7')->where('norujukan',$request->norujukan)->where('billplz_id', $request->billplz_id)->first();
|
||||
return response()->json($transactionOnline);
|
||||
}
|
||||
|
||||
@@ -117,6 +116,13 @@ class TransactionOnlineController extends Controller
|
||||
$transactions = TransactionOnline::on('mysql7')->where([['status', '=', 'PAID'], ['update_status', 0]])->get();
|
||||
$current = Carbon::now();
|
||||
$current = new Carbon();
|
||||
|
||||
$checkTime = $this->checkTime();
|
||||
|
||||
if($checkTime == 'rejected'){
|
||||
return response()->json('rejected-time');
|
||||
}
|
||||
|
||||
foreach ($transactions as $index => $transaction) {
|
||||
$cawangan = Cawangan::on('mysql7')
|
||||
->where('kodcaw', '=', $transaction['kodcaw'])
|
||||
@@ -138,6 +144,7 @@ class TransactionOnlineController extends Controller
|
||||
'descpt' => 'SERAHAN BAYAR ONLINE - ' . $transaction['norujukan'],
|
||||
'serahan' => $transaction['total_payment'],
|
||||
'teller' => 'ONLINE',
|
||||
'date_created' => $current
|
||||
];
|
||||
|
||||
try {
|
||||
@@ -451,8 +458,10 @@ class TransactionOnlineController extends Controller
|
||||
$ujrah_calculation = $this->getUjrah($kodcaw, $norujukan);
|
||||
|
||||
$onepercent = new Calculation();
|
||||
$ujrahasal = $onepercent->getRoundedMethod($ujrahasal);
|
||||
$onepercentasal = $onepercent->getRoundedMethod($onepercentasal);
|
||||
$ujrah = $onepercent->getRoundedMethod($ujrahasal * $bilang_bln);
|
||||
$ujrah_rebate = $onepercent->getRoundedMethod($ujrah_calculation['ujrah_sebenar'] - $ujrah_calculation['ujrah_rebet']);
|
||||
$ujrah_rebate = $onepercent->getRoundedMethod($keuntungan['ujrah'] * $bilang_bln);
|
||||
$keun = $onepercent->getRoundedMethod($onepercentasal * $bilang_bln);
|
||||
$keuntungan_rebate = $onepercent->getRoundedMethod($keuntungan['onepercent'] * $bilang_bln);
|
||||
|
||||
@@ -745,5 +754,21 @@ class TransactionOnlineController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
private function checkTime(){
|
||||
$current = Carbon::now();
|
||||
|
||||
$startRange1 = Carbon::today()->setTime(19, 0);
|
||||
$endRange1 = Carbon::today()->setTime(19, 30);
|
||||
|
||||
$startRange2 = Carbon::today()->setTime(23, 0);
|
||||
$endRange2 = Carbon::today()->setTime(23, 30);
|
||||
|
||||
if ($current->between($startRange1, $endRange1) || $current->between($startRange2, $endRange2)) {
|
||||
return 'rejected';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,9 @@ use App\Vault;
|
||||
use App\Cawangan;
|
||||
use App\Tunai;
|
||||
use App\AddTunai;
|
||||
use App\ApprovalWithdrawal;
|
||||
use App\Audit;
|
||||
use App\DenoPendSer;
|
||||
use App\GlDetail;
|
||||
use App\imbangdugalama;
|
||||
use App\GlCode;
|
||||
@@ -14,6 +16,7 @@ use App\Tebus;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class VaultController extends Controller
|
||||
{
|
||||
@@ -283,7 +286,8 @@ class VaultController extends Controller
|
||||
'ktacct' => '1000/010',
|
||||
'descpt' => 'SERAHAN BAYAR ONLINE',
|
||||
'serahan' => $request->amaun,
|
||||
'teller' => 'ONLINE'
|
||||
'teller' => 'ONLINE',
|
||||
'date_created' => $current
|
||||
]);
|
||||
|
||||
// $audit = new Audit();
|
||||
@@ -314,7 +318,8 @@ class VaultController extends Controller
|
||||
'ktacct' => $request->ktacct,
|
||||
'descpt' => $request->keterangan,
|
||||
'pendahuluan' => $request->amaun,
|
||||
'teller' => $request->teller
|
||||
'teller' => $request->teller,
|
||||
'date_created' => $current
|
||||
]);
|
||||
}else if($request->jenisgldetail == 'serahan')
|
||||
{
|
||||
@@ -325,7 +330,9 @@ class VaultController extends Controller
|
||||
'ktacct' => $request->ktacct,
|
||||
'descpt' => $request->keterangan,
|
||||
'serahan' => $request->amaun,
|
||||
'teller' => $request->teller
|
||||
'teller' => $request->teller,
|
||||
'date_created' => $current
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -718,6 +725,4 @@ class VaultController extends Controller
|
||||
return response()->json($vault);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user