<!doctype html>
<?php Fun::lang()?>
<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>NSO POS</title>
    <link rel="stylesheet" type="text/css" href="{{asset('assets/css/pos-invoice.css')}}">
    <style>

    </style>
</head>
<body>
<?php
$hr = '<div style="width: 100%;border-top: 1px dashed rgba(1,1,1,0.5);margin: 10px 0;"></div>';
$br = mainBranch();
?>
<div class="print_invoice_wholesale print_this_form">
    <table class="tb-header">
        <tr>
            <td><img src="{{findImg($br->logo)}}" style="width: 90px;"></td>
        </tr>
        <tr>
            <td>
                 <span>
                     <b class="name_logo">{{$br->name}}</b><br>
                    <i style="font-size: 11px">{{$br->address}}<br>{{$br->phone}}</i>
                </span>
            </td>
        </tr>
    </table>

    <hr width="40%">
    <table>
        <tr style="text-align: left;">
            <td style="width: 70%;">
                <table>
                    <tr class="font_12">
                        <td>{{__('administrator.date')}} </td>
                        <td>:
                            <b>{{myDate($master->date)}}</b>
                        </td>
                    </tr>
                    <tr class="font_12">
                        <td>{{__('administrator.reference_number')}}</td>
                        <td>: {{ $master->reference_number}}</td>
                    </tr>
                    <tr class="font_12">
                        <td>{{__('administrator.cashier')}}</td>
                        <td>: {{$master->user->name??'' }}</td>
                    </tr>
                </table>
            </td>
            <td>
                <table>

                    <tr class="font_12">
                        <td>{{__('administrator.customer')}}</td>
                        <td> : {{ $master->customer->name??'' }}</td>
                    </tr>
                    <tr class="font_12">
                        <td>{{__('administrator.phone')}}</td>
                        <td> : {{ $master->customer->phone??'' }}</td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
    <table class="table m-top-30">
        <thead>
        <tr>
            <th width="6%">#</th>
            <th>{{__('administrator.code')}}</th>
            <th>{{__('administrator.products')}}</th>
            <th>{{__('administrator.size')}}</th>
            <th>{{__('administrator.color')}}</th>
            <th>{{__('administrator.qty')}}</th>
            <th>{{__('administrator.price')}}</th>
            <th width="10%">{{__('administrator.total')}}</th>
        </tr>
        </thead>
        <tbody>
        <?php
        $grand_total = 0;
        $key = 0;
        $total_qty = 0;
        $currency = findCurrency($master->currency_id)->symbol;
        ?>

        @if($master)
            @foreach ($master->detail  as $row)
                <?php
                $product = getProductById($row->product_id);
                $unit = (findUnit($product->unit_id));
                $total_qty+=$row->qty;
                $op = $row->type==='return'?'+':'-';
                $operation = $row->type==='return'?'-':'+';
                $total = $row->price*$row->qty;
                $grand_total+= (float)("$operation$total");
                ?>
                <tr role="row">
                    <td>{{ $key+=1 }}</td>
                    <td>{{ $row->barcode }}</td>
                    <td>{{ $product->product_name }}</td>
                    <td>{{ findSize($row->size_code)->size }}</td>
                    <td>{{ findColor($row->color_code)->name }}</td>
                    <td>{{ $op.$row->qty.' '.($unit?$unit->name:'') }}</td>
                    <td>{{$currency.number_format($row->price ,2)}}</td>
                    <td>{{$currency.number_format($total,2)}}</td>
                </tr>
            @endforeach
            @php
                $total_row = 10;
                $total_data = count($master->detail);
                $left_row = $total_row-$total_data;
            @endphp
            @if($total_row>$total_data)
                @for ($i=0;$i<$left_row; $i++)
                    <tr>
                        <td>{{ $key += 1}}</td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                    </tr>
                @endfor
            @endif
        @endif
        </tbody>
        <tr class="">
            <td colspan="6" rowspan="8" class="text-left  delivery_info no-border" style="position: relative;"></td>
            <td style="border-left: none" class="my-customer-border"><span></span>{{__('administrator.total_item')}}</td>
            <td class="text-left " style="position: relative;">{{$total_qty}}</td>
        </tr>
        <tr>
            <td style="border-left: none" class="my-customer-border"><span></span>{{__('administrator.grand_total')}}</td>
            <td class="text-left">{{$currency}}{{number_format(($grand_total),2)}}</td>
        </tr>
    </table>
    <hr width="40%">
    <table>
        <tr>
            <td style="text-align: center"><b>{!! $br->invoice_footer !!}</b></td>
        </tr>
    </table>
</div>
</body>
</html>
