<?php Fun::lang() ?>
<div class="print_this_form">
    <h3>{{__('administrator.sale_history')}}</h3>
    <table id="print_table" width="100%" class="table table-striped table-hover " style="margin-top: 30px">
        <thead>
        <tr>
            <th>#</th>
            <th>{{__('administrator.date')}}</th>
            <th>{{__('administrator.invoice')}}</th>
            <th>{{__('administrator.customer_name')}}</th>
            <th>{{__('administrator.customer_phone')}}</th>
            <th>{{__('administrator.products')}}</th>
            <th>{{__('administrator.barcode')}}</th>
            <th>{{__('administrator.qty')}}</th>
        </tr>
        </thead>
        <tbody class="tbody">
        @php $total_qty = 0; @endphp
        @foreach($data as $key=>$row)
            <?php
            $customer = findCustomer($row->customer_id);
            $product = getProductById($row->product_id);
            $customer_phone =$customer?$customer->phone:'';
            $customer = $customer?$customer->name:'';
            $total_qty += $row->qty ;
            ?>
            <tr>
                <td>{{$key+1}}</td>
                <td>{{date('d-m-Y',strtotime($row->sale_date))}}</td>
                <td><a class="under-line cursor text-primary btn_purchase_invoice_public" data-href="{{route("get-wholesale-invoice", $row->sale_id)}}">{{$row->invoice_number}}</a></td>
                <td><a class="under-line cursor text-primary btn_show_customer_info_public" data-href="{{route("customer.show", $row->customer_id)}}">{{$customer}}</a></td>
                <td>{{$customer_phone}}</td>
                <td>{{$product->product_name}}</td>
                <td>{{$row->barcode}}</td>
                <td>{{$row->qty}}</td>
            </tr>
        @endforeach
        </tbody>
        <tfoot>
            <tr>
                <td colspan="7" class="text-right">{{__('administrator.total_qty')}}</td>
                <td>{{$total_qty}}</td>
            </tr>
        </tfoot>
    </table>
    <div class="col-sm-12 col-xs-12">
        <div class="pagin">
            {!! Form::hidden('barcode_hide', @$row?$row->barcode:'') !!}
            {!! Form::hidden('warehouse_hide', @$row?$row->warehouse_id:'') !!}
        @if(@$data)
                {!! $data->render() !!}
            @endif
        </div>
    </div>
</div>
