fix: exclude lanjut and ansuran from stok audit khas blast
This commit is contained in:
@@ -53,7 +53,6 @@ class StokAuditController extends Controller
|
||||
$hinggatempoh = $request->hinggatempoh;
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw', '=', $request->kodcaw)->first();
|
||||
|
||||
// Query asal gadai
|
||||
$audit = Gadai::on($cawangan['mysql'])
|
||||
->where([
|
||||
['tagpalsu', '=', 0],
|
||||
@@ -66,47 +65,7 @@ class StokAuditController extends Controller
|
||||
->orderBy('sirig', 'ASC')
|
||||
->get();
|
||||
|
||||
// Dapatkan semua norujukan awal
|
||||
$arraynorujukan = $audit->pluck('norujukan')->toArray();
|
||||
|
||||
// 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();
|
||||
$rekodaudit = $this->filterRekodAuditKhas($audit);
|
||||
|
||||
// Gunakan hanya norujukan yang dah ditapis
|
||||
$arraynorujukan = $rekodaudit->pluck('norujukan')->toArray();
|
||||
@@ -179,13 +138,17 @@ class StokAuditController extends Controller
|
||||
$audit = Gadai::on($cawangan['mysql'])
|
||||
->where([['tagpalsu','=',0],['tempoh','>=',$daritempoh],['tempoh','<=',$hinggatempoh],['sttebus','=',''],['taglel','=',0]])
|
||||
->orderBy('t_gadai', 'ASC')
|
||||
->orderBy('sirig', 'ASC');
|
||||
// ->get();
|
||||
// dd($audit);
|
||||
$rekodaudit = $audit->get();
|
||||
$arraynorujukan = $audit->pluck('norujukan')->toArray();
|
||||
->orderBy('sirig', 'ASC')
|
||||
->get();
|
||||
|
||||
$rekodaudit = $this->filterRekodAuditKhas($audit);
|
||||
$arraynorujukan = $rekodaudit->pluck('norujukan')->toArray();
|
||||
$keybynorujukan = $rekodaudit->keyBy('norujukan');
|
||||
|
||||
if (empty($arraynorujukan)) {
|
||||
return response()->json('success');
|
||||
}
|
||||
|
||||
$gadainokp = Gadai::on($cawangan['mysql'])->whereIn('norujukan', $arraynorujukan)
|
||||
->select('nokp')
|
||||
->groupBy('nokp')
|
||||
@@ -261,12 +224,17 @@ class StokAuditController extends Controller
|
||||
$audit = Gadai::on($cawangan['mysql'])
|
||||
->where([['tagpalsu','=',0],['tempoh','>=',$daritempoh],['tempoh','<=',$hinggatempoh],['sttebus','=',''],['taglel','=',0]])
|
||||
->orderBy('t_gadai', 'ASC')
|
||||
->orderBy('sirig', 'ASC');
|
||||
->orderBy('sirig', 'ASC')
|
||||
->get();
|
||||
|
||||
$rekodaudit = $audit->get();
|
||||
$arraynorujukan = $audit->pluck('norujukan')->toArray();
|
||||
$rekodaudit = $this->filterRekodAuditKhas($audit);
|
||||
$arraynorujukan = $rekodaudit->pluck('norujukan')->toArray();
|
||||
$keybynorujukan = $rekodaudit->keyBy('norujukan');
|
||||
|
||||
if (empty($arraynorujukan)) {
|
||||
return response()->json('success');
|
||||
}
|
||||
|
||||
$gadainokp = Gadai::on($cawangan['mysql'])->whereIn('norujukan', $arraynorujukan)
|
||||
// ->select('nokp')
|
||||
// ->groupBy('nokp')
|
||||
@@ -441,7 +409,6 @@ class StokAuditController extends Controller
|
||||
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw', '=', $request->kodcaw)->first();
|
||||
|
||||
// Ambil semua rekod gadai asas
|
||||
$audit = Gadai::on($cawangan['mysql'])
|
||||
->where([
|
||||
['tagpalsu', '=', 0],
|
||||
@@ -450,52 +417,10 @@ class StokAuditController extends Controller
|
||||
['sttebus', '=', ''],
|
||||
['taglel', '=', 0],
|
||||
])
|
||||
->orderBy('norujukan', 'ASC') // susun ikut norujukan
|
||||
->orderBy('norujukan', 'ASC')
|
||||
->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) {
|
||||
if ($item->lelong_tawarruq == 0) {
|
||||
return true;
|
||||
}
|
||||
$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();
|
||||
$rekodaudit = $this->filterRekodAuditKhas($audit);
|
||||
|
||||
// Attach customer info + blast untuk setiap norujukan
|
||||
foreach ($rekodaudit as $index => $rekod) {
|
||||
@@ -563,7 +488,50 @@ class StokAuditController extends Controller
|
||||
return ['ujrah' => $ujrah_semasa, 'onepercent' => $onepercent_semasa];
|
||||
}
|
||||
|
||||
// dalam Controller (private/protected)
|
||||
/**
|
||||
* SAG untuk blast Stok Audit Khas:
|
||||
* - Fasa 1 (belum lanjut): buang jika dah ada tebus (T) atau bayaran ansuran (A).
|
||||
* - Fasa 2 (dah lanjut, lelong_tawarruq=0): buang jika masih sekitar matang pertama (tempoh < 11).
|
||||
* Kekalkan tempoh >= 11 untuk peringatan tamat kontrak.
|
||||
*/
|
||||
private function filterRekodAuditKhas($audit)
|
||||
{
|
||||
$arraynorujukan = $audit->pluck('norujukan')->filter()->unique()->values()->all();
|
||||
|
||||
$norujukanWithT = [];
|
||||
$norujukanWithA = [];
|
||||
|
||||
if (!empty($arraynorujukan)) {
|
||||
$norujukanWithT = array_flip(
|
||||
Transaction::on('mysql7')
|
||||
->where('trans_type', 'T')
|
||||
->whereIn('norujukan', $arraynorujukan)
|
||||
->distinct()
|
||||
->pluck('norujukan')
|
||||
->all()
|
||||
);
|
||||
|
||||
$norujukanWithA = array_flip(
|
||||
Transaction::on('mysql7')
|
||||
->where('trans_type', 'A')
|
||||
->whereIn('norujukan', $arraynorujukan)
|
||||
->distinct()
|
||||
->pluck('norujukan')
|
||||
->all()
|
||||
);
|
||||
}
|
||||
|
||||
return $audit->filter(function ($item) use ($norujukanWithT, $norujukanWithA) {
|
||||
if ((int) $item->lelong_tawarruq === 0) {
|
||||
return (float) $item->tempoh >= 11;
|
||||
}
|
||||
|
||||
$norujukan = $item->norujukan;
|
||||
|
||||
return !isset($norujukanWithT[$norujukan]) && !isset($norujukanWithA[$norujukan]);
|
||||
})->values();
|
||||
}
|
||||
|
||||
private function floorTo5SenFrom2dp($amount)
|
||||
{
|
||||
// pastikan numeric
|
||||
|
||||
Reference in New Issue
Block a user