<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <style>
            * {
                font-size: 12px;
                font-family: 'Times New Roman';
            }
            
            td,
            th,
            tr,
            table {
                /*border-top: 1px solid black;*/
                border-collapse: collapse;
            }
            
            th.description {
                width: 75px;
                max-width: 75px;
            }
            td.description {
                width: 100%;
                max-width: 100%;
            }
            
            td.quantity,
            th.quantity {
                width: 40px;
                max-width: 40px;
                word-break: break-all;
            }
            
            td.price,
            th.price {
                width: 40px;
                max-width: 40px;
                word-break: break-all;
            }
            
            .centered {
                text-align: center;
                align-content: center;
            }
            
            .ticket {
                width: 155px;
                max-width: 155px;
            }
            
            img {
                max-width: inherit;
                width: inherit;
            }
            
            @media print {
                .hidden-print,
                .hidden-print * {
                    display: none !important;
                }
            }
        </style>
        <title>Receipt example</title>
    </head>
    <body>
        <div class="ticket">
            {!!DNS1D::getBarcodeSVG($mr->request_no, 'C39')!!}
            <p class="centered">MR NO:{{$mr->prefix ?? 0}}{{$mr->request_no ?? 0}}
                <br>Date:{{date('d-m-Y',strtotime($mr->request_date))}}
                <br>{{$mr->customer_name}}
                <br>{{$mr->parent->name}}, {{$mr->customer->address ?? ''}}
                <br>Mob No: {{$mr->customer->mobileno ?? ''}}
                <br>Veicle No: {{$mr->customer_vehicleno}}
                <br>Salesman: {{$mr->entered->name}}</p>
                <input type="hidden" name="mr_id" id="mr_id" value="{{$mr->id}}">
            <table>
                <thead>
                    <tr>
                        <th class="quantity">Sl</th>
                        <th class="description">Product Name</th>
                        <th class="price">Packing</th>
                        <th class="price">Unit</th>
                        <th class="price">Qty</th>
                        <th class="price">Unit Price</th>
                    </tr>
                </thead>
                <tbody>
                    <?php $c=1;$tot=0;$wgt=0;?>
                    @foreach($products as $prd)
                    <tr>
                      <td class="price">{{$c++}}</td>
                      <td class="description">{{utf8_encode($prd->product['name'])}} @if($prd->remarks != null) ({{utf8_encode($prd->remarks)}}) @endif</td>
                    <!--</tr>-->
                    <!--<tr>-->
                    <!--  <td class="price"></td>-->
                    <!--  <td class="price"></td>-->
                      <td style="text-align: left;">{{utf8_encode($prd->grade['grade'])}}</td>
                      <td style="text-align: left;">{{utf8_encode($prd->unit['unit'])}}</td>
                      <td style="text-align: left;">{{utf8_encode($prd->qty)}}</td>
                      <td style="text-align: left;">{{($prd->price > 0)? $prd->price : ''}}</td>
                    </tr>
                    @endforeach
                    <tr>
                      <th colspan="3" style="text-align: right;"></th>
                      <th></th>
                      <th colspan="1" style="text-align: right;">Total:</th>
                      <th><b style="font-family:times New Roman; "></th>
                    </tr>
                </tbody>
            </table>
        </div>
        <div class="row no-print" >
        <div class="col-xs-12">
          @if($mr->print == 1) 
          <a  target="_blank"  class="btn btn-default pull-right" id="print" onclick="window.print();" style="background: green;color: white"><i class="fa fa-print" style="color: white"></i> Print</a>
          @else
          <a  target="_blank"  class="btn btn-default pull-right" id="print" onclick="window.print();" style="background: blue;color: white"><i class="fa fa-print" style="color: white"></i> Print</a>

           @endif 
        </div>
      </div>
      <script src="{{asset('lte/bower_components/jquery/dist/jquery.min.js')}}"></script>
        <script src="script.js"></script>
<script>
 

  $(document).ready(function(){
    // window.addEventListener('afterprint', (event) => {
    //     window.close();
    // });
    
    window.onafterprint = (event) => {
       var delayInMilliseconds = 15000; //1 second
       setTimeout(function() {
        window.close();
       }, delayInMilliseconds);
    };
    $("#print").click(function() {
    //   var e = 1;
    //   while(e) {
    //     console.log(e);
    //     if($(".action-button")) {
    //       $(".action-button").trigger('click');
    //       e = 0;     
    //     }
    //   }
      
      var mr_id = $("#mr_id").val();
      $.get("{{url('credit/sale/print')}}", {option: mr_id}, function(mode_data){
        //   window.close();
        });
    });
    // $("#print").trigger('click');
    //window.close();
});
    
    
</script>
    </body>
</html>