Merged in izzati-hotfix-laporan-SA-filtered (pull request #338)
improve code laporan SA
This commit is contained in:
@@ -63,29 +63,46 @@ class StokAuditController extends Controller
|
|||||||
['taglel', '=', 0],
|
['taglel', '=', 0],
|
||||||
])
|
])
|
||||||
->orderBy('t_gadai', 'ASC')
|
->orderBy('t_gadai', 'ASC')
|
||||||
->orderBy('sirig', 'ASC');
|
->orderBy('sirig', 'ASC')
|
||||||
|
->get();
|
||||||
|
|
||||||
// Dapatkan tarikh terkini untuk trans_type 'T' dan 'A'
|
// Dapatkan semua norujukan awal
|
||||||
|
$arraynorujukan = $audit->pluck('norujukan')->toArray();
|
||||||
|
|
||||||
|
// Dapatkan tarikh terkini untuk setiap norujukan ikut trans_type T
|
||||||
$tarikhTerkiniT = Transaction::on('mysql7')
|
$tarikhTerkiniT = Transaction::on('mysql7')
|
||||||
->where('trans_type', 'T')
|
->select('norujukan', DB::raw('MAX(created_at) as tarikh_max'))
|
||||||
->max('created_at');
|
->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')
|
$tarikhTerkiniA = Transaction::on('mysql7')
|
||||||
->where('trans_type', 'A')
|
->select('norujukan', DB::raw('MAX(created_at) as tarikh_max'))
|
||||||
->max('created_at');
|
->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;
|
||||||
|
|
||||||
// Filter audit berdasarkan tiada transaksi T/A pada tarikh terkini
|
$adaTebusTerkini = isset($tarikhTerkiniT[$norujukan]) &&
|
||||||
$rekodaudit = $audit->get()->filter(function ($item) use ($cawangan, $tarikhTerkiniT, $tarikhTerkiniA) {
|
Transaction::on('mysql7')
|
||||||
$adaTebusTerkini = Transaction::on('mysql7')
|
->where('norujukan', $norujukan)
|
||||||
->where('norujukan', $item->norujukan)
|
|
||||||
->where('trans_type', 'T')
|
->where('trans_type', 'T')
|
||||||
->whereDate('created_at', '>=', date('Y-m-d', strtotime($tarikhTerkiniT)))
|
->whereDate('created_at', '>=', date('Y-m-d', strtotime($tarikhTerkiniT[$norujukan])))
|
||||||
->exists();
|
->exists();
|
||||||
|
|
||||||
$adaAnsuranTerkini = Transaction::on('mysql7')
|
$adaAnsuranTerkini = isset($tarikhTerkiniA[$norujukan]) &&
|
||||||
->where('norujukan', $item->norujukan)
|
Transaction::on('mysql7')
|
||||||
|
->where('norujukan', $norujukan)
|
||||||
->where('trans_type', 'A')
|
->where('trans_type', 'A')
|
||||||
->whereDate('created_at', '>=', date('Y-m-d', strtotime($tarikhTerkiniA)))
|
->whereDate('created_at', '>=', date('Y-m-d', strtotime($tarikhTerkiniA[$norujukan])))
|
||||||
->exists();
|
->exists();
|
||||||
|
|
||||||
return !$adaTebusTerkini && !$adaAnsuranTerkini;
|
return !$adaTebusTerkini && !$adaAnsuranTerkini;
|
||||||
|
|||||||
Reference in New Issue
Block a user