update
This commit is contained in:
No files matched your search
@@ -845,10 +845,12 @@ class GudangController extends Controller
|
||||
|
||||
$rows = $query->get();
|
||||
$grouped = [];
|
||||
$jenisNames = [];
|
||||
foreach ($rows as $row) {
|
||||
$jenis = $row->jenis ?: 'Tidak Diketahui';
|
||||
if (!isset($grouped[$jenis])) {
|
||||
$grouped[$jenis] = ['jenis' => $jenis, 'masuk' => 0, 'keluar' => 0];
|
||||
$grouped[$jenis] = ['jenis' => $jenis, 'masuk' => 0, 'keluar' => 0, 'sisa' => 0];
|
||||
$jenisNames[] = $jenis;
|
||||
}
|
||||
if (!is_null($row->pemasukan) && (int)$row->pemasukan > 0) {
|
||||
$grouped[$jenis]['masuk'] += $this->extractBaseQty($row, 'pemasukan');
|
||||
@@ -858,6 +860,14 @@ class GudangController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($jenisNames)) {
|
||||
$stockMap = app(SimbhpStockService::class)->getStockBaseByJenisMany($jenisNames);
|
||||
foreach ($grouped as $jenis => &$item) {
|
||||
$item['sisa'] = (int) ($stockMap[$jenis] ?? 0);
|
||||
}
|
||||
unset($item);
|
||||
}
|
||||
|
||||
return array_values($grouped);
|
||||
}
|
||||
|
||||
|
||||
@@ -868,14 +868,10 @@ class ReportController extends Controller
|
||||
$bulan = str_replace('bulan=', '', $bulan);
|
||||
$tahun = str_replace('tahun=', '', $tahun);
|
||||
}
|
||||
|
||||
// Query Periksa
|
||||
$query = Periksa::query()->where('dlp', 'Kultur')->whereNotNull('dokter_id')->whereYear('daftar', $tahun);
|
||||
if ($bulan != 'ALL' && $bulan != 'Pick Month') {
|
||||
$query->whereMonth('daftar', $bulan);
|
||||
}
|
||||
|
||||
// Preview dibuat paginated agar aman saat filter setahun.
|
||||
$orderbydate = $query->orderBy('daftar', 'ASC')->orderBy('id', 'ASC')->paginate(50);
|
||||
$orderbydate->appends(['bulan' => $bulan, 'tahun' => $tahun]);
|
||||
|
||||
|
||||
@@ -329,10 +329,30 @@ class GudangPos extends Component
|
||||
|
||||
$jenisNames = $products->getCollection()->pluck('jenis')->filter()->values()->all();
|
||||
$stockMap = $service->getStockBaseByJenisMany($jenisNames);
|
||||
$latestExpiredMap = [];
|
||||
if (count($jenisNames) > 0) {
|
||||
$expiredRows = SIMBHPReport::query()
|
||||
->select('jenis', DB::raw('MAX(masa_expired) as latest_expired'))
|
||||
->whereIn('jenis', $jenisNames)
|
||||
->whereNotNull('masa_expired')
|
||||
->whereNotNull('pemasukan')
|
||||
->where('pemasukan', '>', 0)
|
||||
->groupBy('jenis')
|
||||
->get();
|
||||
|
||||
foreach ($expiredRows as $row) {
|
||||
$jenisNama = (string) ($row->jenis ?? '');
|
||||
$expired = (string) ($row->latest_expired ?? '');
|
||||
if ($jenisNama !== '' && $expired !== '') {
|
||||
$latestExpiredMap[$jenisNama] = Carbon::parse($expired)->format('d-m-Y');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$selectedJenis = null;
|
||||
$selectedStockDisplay = null;
|
||||
$selectedSetting = null;
|
||||
$selectedLatestExpired = null;
|
||||
$kode = $service->sanitizeKode($this->selectedKode);
|
||||
if ($kode !== '') {
|
||||
$selectedJenis = $service->getJenisByKode($kode);
|
||||
@@ -345,6 +365,7 @@ class GudangPos extends Component
|
||||
(string) ($selectedJenis->satuan_kecil ?? ''),
|
||||
(int) ($selectedJenis->konversi_kecil ?? 1),
|
||||
);
|
||||
$selectedLatestExpired = $latestExpiredMap[(string) $selectedJenis->jenis] ?? null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -352,9 +373,11 @@ class GudangPos extends Component
|
||||
'users' => $users,
|
||||
'products' => $products,
|
||||
'stockMap' => $stockMap,
|
||||
'latestExpiredMap' => $latestExpiredMap,
|
||||
'selectedJenis' => $selectedJenis,
|
||||
'selectedStockDisplay' => $selectedStockDisplay,
|
||||
'selectedSetting' => $selectedSetting,
|
||||
'selectedLatestExpired' => $selectedLatestExpired,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user