@include(branchMenu())
@section('content')
    <?php Fun::lang()?>
    <style>
        tfoot td:first-child {
            border: none !important;
            border-top: none !important;
        }

    </style>

    <div class="container-fluid">
        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
                <div class="container-fluid" style="background: white; padding:10px">
                    <div class="row">
                        <div class="col-xs-9 col-sm-9 col-md-9 col-lg-9"
                             style="background: #16c2c2; height: 40px;"></div>
                        <div class="col-xs-2 col-sm-2 col-md-2 col-lg-2 text-center" style="font-size: 30px;">
                            <b>Invoice </b>
                        </div>
                        <div class="col-xs-1 col-sm-1 col-md-1 col-lg-1"
                             style="background: #16c2c2; height: 40px;"></div>
                    </div>
                    <br>
                    <div class="row">
                        <div class="col-xs-10 col-sm-10 col-md-10 col-lg-10"></div>

                    </div>
                    <br>
                    <div class="row">
                        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
                            <h3>{{__('administrator.customer')}}</h3>
                        </div>
                        <div class="col-xs-10 col-sm-10 col-md-10 col-lg-10 " style="line-height: 25px">
                            <div class="row">
                                <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 text-left">
                                    <b>{{__('administrator.name')}}
                                        :</b> {{ findCustomer($pos->customer_id)->customer_name }}
                                </div>
                                <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 text-left">
                                    <b>{{__('administrator.phone')}}
                                        :</b>{{ findCustomer($pos->customer_id)->customer_phone }}
                                </div>
                                <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 text-left">
                                    <b>{{__('administrator.email')}}
                                        :</b> {{ findCustomer($pos->customer_id)->customer_email }}
                                </div>
                            </div>
                        </div>
                        <div class="col-xs-2 col-sm-2 col-md-2 col-lg-2">
                            <div class="row">
                                <div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">
                                    <b>Date:</b>
                                </div>
                                <div class="col-xs-8 col-sm-8 col-md-8 col-lg-8 ">
                                    {{ date('d-m-Y',strtotime($pos->sale_date))}}
                                </div>
                                <div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">
                                    <b>Invoice:</b>
                                </div>
                                <div class="col-xs-8 col-sm-8 col-md-8 col-lg-8 ">
                                    {{ $pos->invoice_number}}
                                </div>
                            </div>
                        </div>
                    </div>
                    <br>
                    <div class="table-responsive">
                        <table class="table">
                            <thead>
                            <tr>
                                <th width="6%">#</th>
                                <th col>{{__('administrator.code')}}</th>
                                <th col>{{__('administrator.products')}}</th>
                                <th col>{{__('administrator.qty')}}</th>
                                <th col>{{__('administrator.price')}}</th>
                                <th col>{{__('administrator.discount')}}(%)</th>
                                <th width="10%">{{__('administrator.total')}}</th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php  $subtotal = 0; ?>
                            @if($pos_detail)
                                @foreach ($pos_detail as  $key => $row)
                                    <?php
                                    $product = getProductById($row->product_id);
                                    $total = $row->sale_price * $row->qty;
                                    $total = $total - ($total * $row->dis / 100);

                                    if ($product->currency == '1') {
                                        $currency = '៛';
                                        $subtotal += $total / $pos->rate;
                                    } else {
                                        $currency = '$';
                                        $subtotal += $total;
                                    }

                                    $unit = (findUnit($row->unit_id));
                                    if (\App\Fun\Fun::lang() == 'km') {
                                        $unit = $unit->unit_name_km;
                                    } else {
                                        $unit = $unit->unit_name_en;
                                    }
                                    ?>
                                    <tr role="row">
                                        <td>{{ $key+1 }}</td>
                                        <td>{{ $product->barcode }}</td>
                                        <td>{{ $product->product_name }}</td>
                                        <td>{{ $row->qty.' '.$unit }}</td>
                                        <td>{{ $currency.' '.number_format($row->sale_price, 2) }}</td>
                                        <td>{{ number_format($row->dis) }}%</td>
                                        <td>{{ $currency.' '.number_format($total, 2)  }}</td>
                                    </tr>
                                @endforeach
                            @endif
                            </tbody>
                            <tfoot>
                            <tr>
                                <td colspan="6" class="text-right"><b>{{__('administrator.subtotal')}}($):</b></td>
                                <td> {{ number_format($subtotal, 2) }}</td>
                            </tr>
                            <tr>
                                <td colspan="6" class="text-right"><b>{{__('administrator.discount')}}:</b></td>
                                <td>{{ number_format($pos->discount, 0) }}%</td>
                            </tr>
                            <tr>
                                <td colspan="6" class="text-right"><b>{{__('administrator.grand_total')}}(៛):</b></td>
                                <td> {{ number_format(($subtotal-($subtotal*$pos->discount/100))*$pos->rate, 2) }}</td>
                            </tr>
                            <tr>
                                <td colspan="6" class="text-right"><b>{{__('administrator.grand_total')}}($):</b></td>
                                <td> {{ number_format(($subtotal-($subtotal*$pos->discount/100)), 2) }}</td>
                            </tr>
                            <tr>
                                <td colspan="6" class="text-right"><b>{{__('administrator.paid')}}(៛):</b></td>
                                <td> {{ number_format($pos->paid_amount_kh, 2) }}</td>
                            </tr>
                            <tr>
                                <td colspan="6" class="text-right"><b>{{__('administrator.paid')}}($):</b></td>
                                <td>{{ number_format($pos->paid_amount_usd  , 2) }}</td>
                            </tr>
                            </tfoot>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection
@section('script')
@endsection