@foreach($variables['raw_materials'] as $index => $rm)
@php
$existingDetail = null;
if(isset($data->details)) {
$existingDetail = $data->details->where('raw_material_id', $rm->id)->first();
}
// Get conversion data
$mapping = $variables['mappings']->get($rm->id);
$hasMapping = $mapping && $mapping->is_active;
$convKey = $rm->id . '_' . ($mapping->dc_id ?? '');
$conv = $variables['conversions']->get($convKey);
$hasConversion = $conv && $conv->conversion_factor_utuh_pakai && $conv->conversion_factor_utuh_pakai > 0;
$conversionFactor = $hasConversion ? $conv->conversion_factor_utuh_pakai : 1;
$uomUtuh = $conv->uom_utuh ?? $rm->uom;
$uomKirim = $conv->uom_kirim ?? $rm->uom;
$conversionKirimUtuh = $conv->conversion_factor_kirim_utuh ?? 1;
$uomPakai = $rm->uom_pakai ?? $rm->uom;
@endphp
{{ $index + 1 }}
@if(!$hasConversion)
@endif
|
{{ $rm->code }} | {{ $rm->name }}
UOM: {{ $uomPakai }}
@if($hasConversion)
(1 {{ $uomUtuh }} = {{ number_format($conversionFactor, 2, '.', '') }} {{ $uomPakai }})
@endif
@if($hasMapping && $mapping->period)
| {{ $mapping->tipe_dokumen.' '. $mapping->period->code }}
@endif
@if(!$hasConversion)
Tidak ada mapping
@endif
|
|
|
@php
$mapping = $variables['mappings']->get($rm->id);
$hasRestan = $rm->adj_restan_flag;
$hasExtras = $rm->adj_extras_flag;
$hasRingkas = $rm->adj_ringkas_flag;
$hasSelisih = $rm->adj_selisih_flag;
$hasAnyAdjustment = $hasRestan || $hasExtras || $hasRingkas || $hasSelisih;
// Calculate total adjustment
$totalAdj = 0;
if ($existingDetail) {
$totalAdj = ($existingDetail->adj_ekstra ?? 0) +
($existingDetail->adj_restan ?? 0) +
($existingDetail->adj_ringkas ?? 0) +
($existingDetail->adj_selisih ?? 0);
}
@endphp
@if($hasAnyAdjustment)
@else
@endif
|
{{ $existingDetail ? number_format($existingDetail->lsm_aktual, 2, '.', '') : '0.00' }}
|
{{ $existingDetail && $existingDetail->doi ? number_format($existingDetail->doi, 2, '.', '') : '0.00' }}
|
-
|
@if($data->id > 0)
@else
-
@endif
|
{{-- Adjustment Modal for this item --}}
@if($hasAnyAdjustment)
@endif
{{-- FSTR Sub-lines: Display FSTR components (WIP items) for this RM --}}
@php
// Get all FSTR components (WIP items) that belong to this RM
// Example: DRY0048 (parent) has WIP0029, WIP0030, WIP0031 (components)
// Filter only components with input_lsm_flag = true to show in LSM input
$fstrComponents = $rm->components()
->where('delete_flag', 0)
->where('input_lsm_flag', true)
->with('component')
->get()
->filter(function($comp) {
return $comp->component !== null; // Remove components with null component
});
@endphp
@foreach($fstrComponents as $fstrComponent)
@php
$fstr = $fstrComponent->component; // Changed from parent to component
// Skip if component is null (filtered out)
if (!$fstr) continue;
$componentQtyPerUnit = $fstrComponent->qty;
// Check if this FSTR is also a FSTR (has components)
$isFSTR = $fstr->components()->where('delete_flag', 0)->exists();
// Get existing FSTR qty_pakai from SO detail if exists
$existingFstrQty = 0;
if ($existingDetail && $existingDetail->fstr_qty_pakai) {
$fstrQtyData = is_string($existingDetail->fstr_qty_pakai)
? json_decode($existingDetail->fstr_qty_pakai, true)
: $existingDetail->fstr_qty_pakai;
$existingFstrQty = $fstrQtyData[$fstr->id] ?? 0;
}
@endphp
|
FSTR:
{{ $fstr->code }} -
{{ $fstr->name }} -
{{ $fstr->uom_pakai ?? $fstr->uom; }}
|
{{-- FSTR qty_pakai input --}}
|
|
@endforeach
@endforeach