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],
|
||||
])
|
||||
->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')
|
||||
->where('trans_type', 'T')
|
||||
->max('created_at');
|
||||
->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')
|
||||
->where('trans_type', 'A')
|
||||
->max('created_at');
|
||||
->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;
|
||||
|
||||
// Filter audit berdasarkan tiada transaksi T/A pada tarikh terkini
|
||||
$rekodaudit = $audit->get()->filter(function ($item) use ($cawangan, $tarikhTerkiniT, $tarikhTerkiniA) {
|
||||
$adaTebusTerkini = Transaction::on('mysql7')
|
||||
->where('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)))
|
||||
->whereDate('created_at', '>=', date('Y-m-d', strtotime($tarikhTerkiniT[$norujukan])))
|
||||
->exists();
|
||||
|
||||
$adaAnsuranTerkini = Transaction::on('mysql7')
|
||||
->where('norujukan', $item->norujukan)
|
||||
$adaAnsuranTerkini = isset($tarikhTerkiniA[$norujukan]) &&
|
||||
Transaction::on('mysql7')
|
||||
->where('norujukan', $norujukan)
|
||||
->where('trans_type', 'A')
|
||||
->whereDate('created_at', '>=', date('Y-m-d', strtotime($tarikhTerkiniA)))
|
||||
->whereDate('created_at', '>=', date('Y-m-d', strtotime($tarikhTerkiniA[$norujukan])))
|
||||
->exists();
|
||||
|
||||
return !$adaTebusTerkini && !$adaAnsuranTerkini;
|
||||
|
||||
Reference in New Issue
Block a user