<!doctype html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>{{ $data['workshop']->shop_name }} Ledger</title>
    <style>
        .table,
        .tcell,
        .thead {
            text-align: center;
            border: 1px solid black;
            text-align: center;
        }

        .table {
            width: 100%;
            border-collapse: collapse;
        }

    </style>
</head>

<body>
<div>
    <table style="width: 100%;border-collapse: collapse; margin-bottom: 10px">
        <tr>
            <td style="width:33.33%; text-align: left"><h4>{{ $business_name->name }}</h4></td>
            <td style="width:33.33%; text-align: center"><b>Workshop Ledger</b></td>
            <td style="width:33.33%; text-align: right"></td>
        </tr>
    </table>

    <table style="width: 100%;border-collapse: collapse; margin-bottom: 10px">
        <tr>
            <td style="width:33.33%; text-align: left">
                <h4>
                    {{ $data['workshop']->shop_name }}  </h4>
            </td>
            <td style="width:33.33%; text-align: center">

            </td>
            <td style="width:33.33%; text-align: right">
                <span style="font-weight: bold">From Date:</span> <span
                    style="text-decoration: underline">{{ $data['form_date'] }}</span><br>
                <span style="font-weight: bold">To Date:</span> <span
                    style="text-decoration: underline">{{ $data['to_date'] }}</span>
            </td>
        </tr>
    </table>
</div>

<br>

<table class="table">
    <thead>
    <tr>
        <th class="thead">Date</th>
        <th class="thead">Particular</th>
        <th class="thead">Debit</th>
        <th class="thead">Credit</th>
        <th class="thead">Balance</th>
        {{-- <th class="thead">Status</th> --}}
    </tr>
    </thead>
    <tbody>
    @php
        $balance = 0;
        $total_debit = 0;
        $total_credit = 0;

    @endphp
    @forelse ($data['ledgers'] as $key =>$ledger)
        @php
            $balance= ( $balance + $ledger->credit) - $ledger->debit;
                $total_debit = $total_debit + $ledger->debit;
                $total_credit = $total_credit + $ledger->credit;
        @endphp
        <tr>
            <td class="thead">{{ date('M j, Y', strtotime($ledger->date)) }}</td>
            <td class="thead">{{ $ledger->description }}</td>
            <td class="thead">{{ number_format($ledger->debit,0) }}</td>
            <td class="thead">{{ number_format($ledger->credit,0) }}</td>
            <td class="thead">{{ number_format($balance,0) }}</td>

        </tr>
    @empty
        <tr>
            <td class="tcell" style="text-align: center" colspan="5"> No Data Available</td>
        </tr>
    @endforelse
    <tr>
        <th class="tcell" style="text-align: right" colspan="2"> Total:</th>
        <td class="tcell" colspan="" style="text-align: center; padding-left:30px">
            {{ number_format($total_debit, 0) }}
        </td>
        <td class="tcell" colspan="" style="text-align: center; padding-left:30px">
            {{ number_format($total_credit, 0) }}
        </td>
        <td class="tcell" colspan="" style="text-align: center; padding-left:30px">
            {{ number_format($total_credit - $total_debit , 0) }}
        </td>

    </tr>
    </tbody>
</table>

{{-- <div>
<div style="text-align: right;">
    Total: {{ $data['total_amount'] }}
</div>
</div> --}}
</body>

</html>
