<!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->v_id}}</title>

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

            @if($order->type == 'sale' && $order->special == '0')
            <div class="centered" style="margin-top: 5px; display:none; "> <b> 
                فاتورة مبيعات 
              </b>

            </div>
            @endif 


            @if($order->type == 'purchase')
            <div class="centered" style="margin-top: 5px; display:none; "> <b> 
                فاتورة مشتريات 
              </b>

            </div>
            @endif 


            @if($order->special == '1')
            <div class="centered" style="margin-top: 5px; display:none; "> <b> 
                فاتورة  خاصه
              </b>

            </div>
            @endif 
			<center>
			<img src="/tos.jpg" style="height:150px; width:150px;">
			</center>
            <div class="centered" style="margin-top: 5px; font-size:30px; "> {{config('settings.app_name')}}  

            <div class="centered" style="margin-top: 5px; font-size:33px; font-weight:bolder;">  {{$order->v_id}}  </div>
  

 
                <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;" cellspan="2">
                             {{$order->created_at->format('Y-m-d h:i A') }}
                        </td>
                    </tr>

                    <tr style="border: 0;">

                        <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>

                        <td style="border: 0px dashed;">
                            الموظف  : 
<?php
  $user_data = auth()->user();
  echo $user_data->first_name." ".$user_data->last_name;
?>
                        </td>

                    </tr>
					

<?php if($cust_data->id <> 4) { ?>
                        <td style="border: 0px dashed;">
                         
                        العنوان : 
    <?php 
    echo $cust_data->address;

      ?>
        
                        </td>

                        <td style="border: 0px dashed;">
                            رقم الهاتف  : 
    <?php 
    echo $cust_data->phone;

      ?>
                        </td>
<?php } ?>
                    </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;" >المنتج</th>
                        <th class="quantity">الكمية.</th>
                        <th class="quantity"> الوحدة  </th>
                        <th class="price">السعر</th>
                        <th class="price">المجموع</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="quantity" style="text-align: center ; border: 1px dashed;">{{$r->quantity}}</td>


                        <td class="quantity" style="text-align: center ; border: 1px dashed;">{{$r->unit->unit}}</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>

     
                    </tr>
                    @endforeach


           

                     <tr>
                        <td class="quantity" colspan="3" style="text-align: center; font-weight: bolder; font-size: 16px; ">المجموع </td>
                       

                        <td class="price" colspan="2" 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; ">التخفيض </td>
                     

                        <td class="price" colspan="2" 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; ">المدفوع </td>
                       

                        <td class="price" colspan="2" style="text-align: center;  font-weight: bolder; font-size: 16px;">{{number_format($bankak + $cash + $shake ,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; "> 
<br>
<div style="font-size:44px; text-align:center; margin:20px 0 20px 0;"> {{$order->v_id}} </div>

<b>{{config('settings.app_name')}} </b> |  Ticket : <b>{{$order->v_id}}</b> 
<br>
 نشكر لكم انتظاركم  </div>


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

            
        </div>


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