<div class="mb-3">
    <div class="d-flex align-items-center justify-content-between">
        <div class="">
            <div class="d-block">
                <h6>BATCH NUMBER {{ $batch?->batch_no ?? '' }}</h6>
            </div>
            <div class="d-block">
                <h6>{{ $batch?->chart_of_account?->code ?? '' }}</h6>
            </div>
        </div>

        <div class="">
            <h4>BATCH COSTING REPORT</h4>
        </div>

        <div class="">
            <div class="d-block">
                <h6>BATCH SIZE:- {{ $batch?->batch_size ?? '' }}</h6>
            </div>
            <div class="d-block">
                <h6>ACTUAL PROD:-
                    {{ number_format(collect($reportItems)->sum(fn($i) => $i['actual_qty']), 2) ?? 0 }}
                </h6>
            </div>
            <div class="d-block">
                <h6>GRNs {{ $batch?->status == 'completed' ? 'Completed' : 'In-Process' }}</h6>
            </div>
        </div>
    </div>
</div>

<div class="table-responsive">
    {{-- <table
        class="border-top border-start border-end table table-bordered table-hover text-center "> --}}
    <table class="table table-excel table-bordered table-hover text-center text-black">

        <thead class="border-top">
            <tr class="border-top">
                <th colspan="2"></th>
                <th colspan="3" class="border-1" style="font-size: 14px !important;"><b>Consumption as per
                        Formulation</b></th>
                <th colspan="3" class="border-1" style="font-size: 14px !important;"><b>Actual Consumption</b></th>
                <th colspan="3" class="border-1" style="font-size: 14px !important;"><b>Discrepancy</b></th>
            </tr>
            <tr>
                <!-- Column labels -->
                <th>Code</th>
                <th>Particular</th>

                <th>Qty.</th>
                <th>Price</th>
                <th>Amount</th>

                <th>Qty.</th>
                <th>Price</th>
                <th>Amount</th>

                <th>Qty.</th>
                <th>Price</th>
                <th>Amount</th>
            </tr>
        </thead>

        <tbody>
            @if (count($reportItems) > 0)
                @foreach ($reportItems as $item)
                    <tr>
                        <td class="text-start text-black">{{ $item['code'] }}</td>
                        <td class="text-start text-black">{{ $item['name'] }}</td>

                        <td class="text-black">{{ number_format($item['expected_qty'] ?? 0, 4) }}</td>
                        <td class="text-black">{{ number_format($item['expected_price'] ?? 0, 4) }}</td>
                        <td class="text-black">{{ number_format($item['expected_amt'] ?? 0, 4) }}</td>

                        <td class="text-black">{{ number_format($item['actual_qty'] ?? 0, 4) }}</td>
                        <td class="text-black">{{ number_format($item['actual_price'] ?? 0, 4) }}</td>
                        <td class="text-black">{{ number_format($item['actual_amt'] ?? 0, 4) }}</td>

                        <td class="text-black">{{ number_format($item['disc_qty'] ?? 0, 4) }}</td>
                        <td class="text-black">{{ number_format($item['disc_price'] ?? 0, 4) }}</td>
                        <td class="text-black">{{ number_format($item['disc_amt'] ?? 0, 4) }}</td>
                    </tr>
                @endforeach

                {{-- Totals --}}
                <tr class="fw-bold">
                    <td colspan="2" class="text-center text-black">
                        <h6><b>GRAND TOTAL:</b></h6>
                    </td>

                    <td class="text-black">
                        {{ number_format(collect($reportItems)->sum(fn($i) => $i['expected_qty']), 4) }}
                    </td>
                    <td>-</td>
                    <td class="text-black">
                        {{ number_format(collect($reportItems)->sum(fn($i) => $i['expected_amt']), 4) }}
                    </td>

                    <td class="text-black">
                        {{ number_format(collect($reportItems)->sum(fn($i) => $i['actual_qty']), 4) }}
                    </td>
                    <td>-</td>
                    <td class="text-black">
                        {{ number_format(collect($reportItems)->sum(fn($i) => abs($i['actual_amt'])), 4) }}
                    </td>

                    <td class="text-black">
                        {{ number_format(collect($reportItems)->sum(fn($i) => $i['disc_qty']), 4) }}
                    </td>
                    <td>-</td>
                    <td class="text-black">
                        {{ number_format(collect($reportItems)->sum(fn($i) => abs($i['disc_amt'])), 4) }}
                    </td>
                </tr>
            @else
                <tr class="text-center">
                    <td colspan="11">No data found for selected batch</td>
                </tr>
            @endif
        </tbody>
    </table>
</div>
