<?php Fun::lang() ?>
<div class="print_cash_advance">
    <div class="text-center"><h3>{{__('administrator.cash_advance')}}</h3></div>
    <table width="100%" style="margin-top: 10px">
        <tr>
            <td>
                <table class="text-left">
                    <tr>
                        <td>{{__('administrator.date')}}</td>
                        <td> : {{date('d-m-Y',strtotime($payment->payment_date))}}</td>
                    </tr>
                    <tr>
                        <td>{{__('administrator.invoice_number')}}</td>
                        <td> : {{$cutting->invoice_number}}</td>
                    </tr>
                    <tr>
                        <td>{{__('administrator.tailor')}}</td>
                        <td> : {{findTailor($payment->tailor_id)->name}}</td>
                    </tr>
                </table>
            </td>
            <td>
                <table class="text-left">
                    <tr>
                        <td>{{__('administrator.total_amount')}}</td>
                        <td> : {{findCurrency($payment->currency_id)->symbol.' '.number_format($payment->payment_amount,2)}}</td>
                    </tr>
                    <tr>
                        <td>{{__('administrator.description')}}</td>
                        <td> : {{$cutting->description}}</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>

    <table class="table table-striped" style="margin-top: 10px">
        <thead>
        <tr>
            <th width="6%">#</th>
            <th col>{{__('administrator.date')}}</th>
            <th col>{{__('administrator.amount')}}</th>
            <th col>{{__('administrator.refund')}}</th>
            <th col>{{__('administrator.owed')}}</th>
            <th col>{{__('administrator.note')}}</th>
            <th col>{{__('administrator.status')}}</th>
        </tr>
        </thead>
        <tbody>
        <?php  $subtotal = 0;  $amount = $payment->payment_amount; $total_paid = 0; $row_total = 0;?>
        @if($payment_detail->count()>0)
            @foreach ($payment_detail as  $key => $row)

                <tr role="row">
                    <td>{{ $key+1 }}</td>
                    <td>{{ date('d-m-Y',strtotime($row->payment_date)) }}</td>
                    <td>${{ $amount-$subtotal }}</td>
                    <td>${{ $row->paid_amount }}</td>
                    <?php  $subtotal += $row->paid_amount; $row_total = $amount - $subtotal ?>
                    <td>${{ number_format($row_total,2) }}</td>
                    <td>{{  $row->note }}</td>

                    @php
                        $total_paid+=$row->paid_amount;
                        if($row_total==0){
                            $text =__('administrator.paid');
                                     $color = 'success';
                        }else{
                            if(($amount-$row->paid_amount)==$payment->payment_amount){
                                $text =__('administrator.due');
                                $color = 'danger';
                            }else{
                                if(($amount-$row->paid_amount)>0){
                                $text =__('administrator.partial');
                                 $color = 'warning';
                                }
                            }
                        }
                    @endphp
                    <td><span class="label label-{{$color}}">{{$text}}</span></td>
                </tr>

            @endforeach
            <tr>
                <td colspan="3" class="text-right">{{__('administrator.total')}}</td>
                <td>${{number_format($total_paid,2)}}</td>
                <td>${{number_format($row_total,2)}}</td>
                <td colspan="2"></td>
            </tr>
        @else
            <tr role="row">
                <td colspan="7" class="text-center">{{__('administrator.no_data_available')}}</td>
            </tr>
        @endif
        </tbody>

    </table>
</div>
