<?php Fun::lang()?>
        <!doctype html>
<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')}}">
</head>

<body>
@php
    $customer = findCustomer($master->customer_id);
@endphp
<div class="print_invoice_wholesale">
    <h3>Sale Return</h3>
    <hr width="40%">
    <table>
        <tr style="text-align: left;">
            <td>
                <table>

                    <tr class="font_12">
                        <td  class="width-20">{{__('administrator.invoice')}}</td>
                        <td>: {{ $master->invoice_number}}</td>
                    </tr>
                    <tr class="font_12">
                        @if($master->user_id)
                            <td>{{__('administrator.request_by')}}</td>
                            <td>: {{ findUser($master->user_id)->name}}</td>
                        @endif
                    </tr>
                    <tr class="font_12">
                        <td>{{__('administrator.request_to')}}</td>
                        <td>: {{ findBranch($master->branch_id)->name }}</td>
                    </tr>
                </table>
            </td>
            <td>
                @if($master->customer_id)
                    <table class="table-right-side">
                        <tr class="font_12">
                            <td>{{__('administrator.date')}}</td>
                            <td  width="40%" >: {{ date('d-m-Y',strtotime($master->sale_date))}}</td>
                        </tr>
                        <tr class="font_12">
                            <td>{{__('administrator.customer')}}</td>
                            <td > : {{ $customer?$customer->customer_name:'' }}</td>
                        </tr>

                    </table>
                @endif
            </td>
        </tr>
    </table>
    @php
        $hide=0;
            foreach($detail as $key => $row){
                if($row->dis==0){
                    $hide ++;
                }
            }
    @endphp
    <form class="return_form_stock">
        <input type="text"class="hidden" value="{{$master->id}}" name="sale_id">
        <table class="table m-top-30">
            <thead>
            <tr>
                <th width="6%">#</th>
                <th>{{__('administrator.code')}}</th>
                <th>{{__('administrator.products')}}</th>
                <th>{{__('administrator.qty')}}</th>
                <th>{{__('administrator.size')}}</th>
                <th>{{__('administrator.price')}}</th>
                <th>{{__('administrator.discount')}}(%)</th>
                <th width="10%">{{__('administrator.total')}}</th>
                <th width="10%">{{__('administrator.return_qty')}}</th>

            </tr>
            </thead>
            <tbody>
            <?php
            $subtotal = 0;
            $key = 0;
            ?>
            @if($detail)
                @foreach ($detail as  $key => $row)
                    <?php
                    $product = getProductById($row->product_id);
                    $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>{{ $row->barcode }}<input type="text"class="hidden" value="{{ $row->id}}" name="sale_detail_id[]"></td>
                        <td>{{ $product->product_name }}</td>
                        <td>{{ $row->qty.' '.$unit }}</td>
                        <td>{{ findSize($row->size_id)->size }}</td>
                        <td>{{findCurrency($master->currency_id)->symbol.$row->sale_price}}</td>
                        <td >{{ number_format($row->dis) }}%</td>
                        <td>{{findCurrency($master->currency_id)->symbol.generateTotal($row)}}</td>
                        <td><input class="form-control return_qty" type="text" name="return_qty[]" data-max="{{$row->qty}}" value="0"></td>

                    </tr>
                @endforeach

                @php
                    $total_row = 10;
                    $total_data = count($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>
                            <td></td>
                        </tr>
                    @endfor
                @endif
            @endif
            </tbody>
        </table>
    </form>
</div>
<script>
    $(document).ready(function () {
        $('.return_qty').on('keyup',function () {
            let $qty = $(this).data('max');
            let $return_qty = $(this).val();
            $qty = $qty?parseFloat($qty):0;
            $return_qty = $return_qty?parseFloat($return_qty):0;
            if($qty<$return_qty){
                $(this).val($qty);
            }
        });
    })
</script>
</body>
</html>

