@extends('layouts.jform')
@section('content')
    <?php Fun::lang()?>
    <?php
    if ($master->type === 'purchase') {
        $invoice = $master->purchase;
    } else {
        $invoice = $master->sale;
    }
    $customer = $master->customer;
    $supplier = $master->supplier;
    $tailor = $master->tailor;
    $amount = $master->payment_amount;
    $currency = findCurrency($master->currency_id);
    $currency = $currency ? $currency->symbol : '';
    ?>
    <style>
        .payment_info div{
            padding: 3px;
        }
    </style>
    <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12" style="margin-top: 10px">
        <h3 style="margin-bottom: 5px">{{__('administrator.payment')}}</h3>
        <hr>
    </div>
    <div class="payment_info">
        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 text-left">
            <b>{{__('administrator.date')}}
                :</b> {{ date('d-m-Y',strtotime($master->payment_date))}}
        </div>
        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 text-left">
            <b>{{__('administrator.invoice')}}
                :</b> {{$invoice->invoice_number}}
        </div>
        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 text-left">
            <?php
            $text = $customer ? 'customer' : ($supplier ? 'supplier' : 'tailor');
            ?>
            <b>{{__('administrator.'.$text)}}
                :</b>
            {{ $customer->name??'' }}
            {{ $suppler->suppler_name??'' }}
            {{ $tailor->name??'' }}
        </div>
        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 text-left">
            <b>{{__('administrator.phone')}}
                :</b> {{ $customer->phone??'' }}{{ $suppler->suppler_phone??'' }}{{ $tailor->phone??'' }}
        </div>
    </div>
    <br>
    &nbsp;
    <br>
    <table class="table table-striped">
        <thead>
        <tr>
            <th width="6%">#</th>
            <th>{{__('administrator.date')}}</th>
            <th>{{__('administrator.user')}}</th>
            <th>{{__('administrator.amount')}}</th>
            <th>{{__('administrator.refund')}}</th>
            <th>{{__('administrator.owed')}}</th>
            <th>{{__('administrator.note')}}</th>
            <th>{{__('administrator.status')}}</th>
        </tr>
        </thead>
        <tbody>
        <?php  $subtotal = $amount; ?>
        @if($detail->count()>0)
            @foreach ($detail as  $key => $row)

                <tr role="row">
                    <td>{{ $key+1 }}</td>
                    <td>{{ date('d-m-Y',strtotime($row->payment_date)) }}</td>
                    <td>{{ findUser($row->payment_by)->name??''  }}</td>
                    <td>{{$currency}}{{ number_format($subtotal,2) }}</td>
                    <td>{{$currency}}{{ number_format($row->paid_amount,2) }}</td>
                    <?php
                    $subtotal -= $row->paid_amount;
                    ?>
                    <td>{{$currency}}{{ number_format($subtotal,2) }}</td>
                    <td>{{  $row->note }}</td>
                    @php
                        if(($subtotal)==$master->payment_amount){
                            $text =__('administrator.due');
                            $color = 'danger';
                        }else{
                            if(($subtotal)>0){
                            $text =__('administrator.partial');
                             $color = 'warning';
                            }
                            else{
                            $text =__('administrator.paid');
                             $color = 'success';
                            }
                        }

                    @endphp
                    <td><span class="label label-{{$color}}">{{$text}}</span></td>

                </tr>
            @endforeach
        @else
            <tr role="row">
                <td colspan="8" class="text-center">{{__('administrator.no_data_available')}}</td>
            </tr>
        @endif
        </tbody>

    </table>

@endsection

