<!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">
        <link rel="stylesheet" href="{{URL::to('/')}}/style.css">
        <title>{{config('settings.app_name')}} - Order {{$order->id}}</title>

        <style type="text/css">
            table {
                border: 1px dashed;
            }
            td { 
            border: 1px dashed;
             }
             th {
                border: 1px dashed;
             }
             tr {
                border: 0;
             }
        </style>
    </head>
    <body>
        <div class="ticket" style="max-width: 100% !important; width: 100% !important; margin: 0 !important;">

            <div class="centered" style="margin-top: 5px; "> <b> {{config('settings.app_name')}}  </b>

                <span style="font-size:15px; /overflow-x: scroll;">
                <br>{{config('settings.address')}}

                </span>


            </div>


       


                <table border="0" style="text-align: center; width: 100%; border: 0; ">
                    <tr style="border: 0;">
                        <td style="border: 0px dashed;">
                            Invoice : {{$order->id}}
                        </td>
                        <td style="border: 0px dashed;">
                             {{$order->created_at}} 
                        </td>
                    </tr>

                    <tr style="border: 0;">
                        <td style="border: 0px dashed;">
                            User : 
<?php
  $user_data = auth()->user();
  echo $user_data->first_name." ".$user_data->last_name;
?>
                        </td>
                        <td style="border: 0px dashed;">
                         

    <?php $customer_id = \App\Models\Order::where('id',$order->id)
    ->first()->customer_id;

    $cust_data = \App\Models\Customer::where('id',$customer_id)->first();

    echo $cust_data->first_name. " ".$cust_data->last_name;

      ?>
        
                        </td>
                    </tr>
                </table>


            <table border="0" style="width:100%; max-width: 100%; border: 1px dashed;">
                <thead>
                    <tr style="border: 1px dashed;">
                        <th class="description" style="border: 1px dashed;" >Description</th>
                        <th class="description" style="border: 1px dashed;" >Bonus</th>
                        <th class="quantity">Q.</th>
                        <th class="price">Price</th>
                        <th class="price">Total</th>

                        <th class="price">Expiry Date</th>



                    </tr>
                </thead>
                <tbody>

                    <?php
                    $get_orders = \App\Models\OrderItem::where('order_id',$order->id)
                    ->orderby('id','asc')
                    ->get();


                    $bankak = \App\Models\Payment::where('order_id',$order->id)->first()->bankak;
                    $cash = \App\Models\Payment::where('order_id',$order->id)->first()->cash;
                    $shake = \App\Models\Payment::where('order_id',$order->id)->first()->shake;




                    $paid = \App\Models\Payment::where('order_id',$order->id)->first()->amount;
                    $discount = \App\Models\Payment::where('order_id',$order->id)->first()->discount;

                    ?>

                    <?php $total = 0; ?>

                    @foreach($get_orders as $r)

                    <?php $buy_price = \App\Models\Product::where('id',$r->product_id)->first()->buy_price; ?>

                   
                    <tr>
                        <td class="description" style="text-align: center; border: 1px dashed;">{{$r->product->name}}</td>

                        <td class="description" style="text-align: center; border: 1px dashed;">
                            -
                        </td>

                        <td class="quantity" style="text-align: center ; border: 1px dashed;">{{$r->quantity}}</td>
                        <td class="price" style="text-align: center; border: 1px dashed;">
                            @if($r->type == "purchase") 

                            {{number_format($buy_price,0)}}

                            <?php 

                         //   $the_price = $r->price * $r->quantity;
                            $total = $total + ($buy_price * $r->quantity);
                            ?>

                            @else

                            {{number_format($r->price,0)}}

                            <?php 

                         //   $the_price = $r->price * $r->quantity;
                            $total = $total + ($r->price * $r->quantity);
                            ?>

                            @endif


                        </td>
                        <td style="text-align: center;">

                            @if($r->type == "purchase") 

                            {{number_format($r->quantity * $buy_price,0)}}

                            @else

                            {{number_format($r->quantity * $r->price,0)}}

                            @endif


                        </td>

                        @if($r->type == "purchase")

                        <td style="text-align: center;">
                            {{$r->expire_date}}
                        </td>

                        @else

                        <td style="text-align: center;">
                            -
                        </td>

                        @endif

                    </tr>
                    @endforeach


           

                     <tr>
                        <td class="quantity" colspan="3" style="text-align: center; font-weight: bolder; font-size: 16px; ">Total </td>
                       

                        <td class="price" colspan="3" style="text-align: center;  font-weight: bolder; font-size: 16px;">{{number_format($total,0)}} </td>
                    </tr>

                     <tr>
                        <td class="quantity" colspan="3" style="text-align: center; font-weight: bolder; font-size: 16px; ">Discount </td>
                     

                        <td class="price" colspan="3" style="text-align: center;  font-weight: bolder; font-size: 16px;">{{number_format($discount,0)}} </td>
                    </tr>

                     <tr>
                        <td class="quantity" colspan="3" style="text-align: center; font-weight: bolder; font-size: 16px; ">Paid </td>
                       

                        <td class="price" colspan="3" style="text-align: center;  font-weight: bolder; font-size: 16px;">{{number_format($bankak + $cash + $shake - $discount,0)}} </td>
                    </tr>



                </tbody>
            </table>
            <br>
  <center><span class="centered" style="
    /* visibility: hidden; */
    text-align: center !important;
">شكرا لكم لزيارتنا 

{{config('settings.phones')}}
                </span>


</center>
            
        </div>


<!--
        <div class="break"></div> 

    -->

        <div class="ticket" style="max-width: 100% !important; width: 100% !important; margin: 0 !important; text-align: center;
line-height: 9px;">

            <div class="centered" style="margin-top: 0px; padding-top:0px; direction: rtl;
text-align: center !important;
line-height: 14px; "> <b>{{config('settings.app_name')}} </b> |  Ticket : <b>{{$order->id}}</b> 
<br>
 نشكر لكم انتظاركم  </div>


            <br>
                <span style="font-size: 9px; text-align: center;">
                تطوير ايسن لتقنية المعلومات 
                  0123003721 - 0926225530
                </span>

            
        </div>


        <button id="btnPrint" style="" class="hidden-print">اطبع الفاتورة</button>
      
        <script src="{{URL::to('/')}}/script.js"></script>
    </body>
</html>