
    <!DOCTYPE html>
<html>
<head>
    <title>
        @if (!empty($sale_bill->outer_client_id))
            <?php echo $sale_bill->OuterClient->client_name . " - فاتورة رقم " . $sale_bill->sale_bill_number;  ?>
        @else
            <?php echo "فاتورة بيع نقدى" . " - فاتورة رقم " . $sale_bill->sale_bill_number;  ?>
        @endif
    </title>
    <meta charset="utf-8"/>
    <link href="{{asset('/assets/css/bootstrap.min.css')}}" rel="stylesheet"/>
    <style type="text/css" media="screen">
        @font-face {
            font-family: 'Cairo';
            src: url({{asset('fonts/Cairo.ttf')}});
        }

        body, html {
            font-family: 'Cairo' !important;
        }

        .table-container {
            width: 50%;
            margin: 10px auto;
        }

        .no-print {
            position: fixed;
            bottom: 0;
            right: 30px;
            border-radius: 0;
            z-index: 9999;
        }
    </style>
    <style type="text/css" media="print">
            @font-face {
            font-family: 'Cairo';
            src: url({{asset('fonts/Cairo.ttf')}});
        }
        
        body, html {
            font-family: 'Cairo' !important;
        }

        .no-print {
            display: none;
        }
    </style>
</head>
<body style="background: #fff">
<table class="table table-bordered table-container">
    <thead>
        @if(!empty($company->basic_settings->header))
    <tr>
        <td>
            <img class="img-footer" style="width: 700px; height:150px" src="{{asset($company->basic_settings->header)}}"/>
        </td>
    </tr>
    @endif
    </thead>
    <tbody>
    <tr>
        <td class="thisTD">
            <center style="margin:20px auto;">
                @if (!empty($sale_bill->outer_client_id))
                    <span style="font-size:18px;font-weight:bold;border:1px dashed #333; padding: 5px 30px;"> فاتورة مبيعات ضريبية </span>
                @else
                    <span style="font-size:18px;font-weight:bold;border:1px dashed #333; padding: 5px 30px;"> فاتورة مبيعات ضريبية نقدية </span>
                @endif
            </center>

            <hr style="border-bottom:1px solid #000;margin:5px auto; width: 90%;"/>
            <div class="row" dir="rtl">
                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" style="margin:10px auto;">

                    <table class="table  table-bordered text-right" dir="rtl" style="font-size:12px;">
                        <tr>
                            <td style="width:40%;"> تاريخ الفاتورة</td>
                            <td>{{$sale_bill->date}}</td>
                            <td style="width:40%;"> الرقم الضريبى</td>
                            <td>{{$company->tax_number}}</td>
                        </tr>
                        <tr>
                            <td style="width:40%;">رقم الفاتورة</td>
                            <td>{{$sale_bill->sale_bill_number}}</td>
                            <td style="width:40%;">السجل التجارى</td>
                            <td>{{$company->commercial_registration_number}}</td>
                        </tr>
                        <tr>
                            <td style="width:15%;">اسم المؤسسة</td>
                            <td style="width:35%;">{{$company->company_name}}</td>
                            <td colspan="2" style="width:15%;text-align: center;">عنوان المؤسسة</td>
                        </tr>
                        <tr>
                            <td style="width:15%;">رقم التليفون</td>
                            <td style="width:35%;">{{$company->phone_number}}</td>
                            <td colspan="2" style="width:35%;text-align: center;">{{$company->company_address}}</td>
                        </tr>
                    </table>
                </div>
                @if (!empty($sale_bill->outer_client_id))
                    <div class="col-lg-12">
                        <table class="table table-bordered text-right" dir="rtl" style="font-size:12px;">
                            <tr class="text-center">
                                <td colspan="4">بيانات العميل</td>
                            </tr>
                            <tr>
                                <td style="width:15%;">اسم العميل</td>
                                <td style="width:35%;">{{$sale_bill->OuterClient->client_name}}</td>
                                <td style="width:15%;">فئة التعامل</td>
                                <td style="width:35%;">{{$sale_bill->OuterClient->client_category}}</td>
                            </tr>
                            <tr>
                                <td style="width:15%;">رقم التليفون</td>
                                <td style="width:35%;direction:ltr;">{{$sale_bill->OuterClient->phones[0]->client_phone}}</td>
                                <td style="width:15%;">الرقم الضريبى</td>
                                <td style="width:35%;">{{$sale_bill->OuterClient->tax_number}}</td>
                            </tr>
                        </table>
                    </div>
                @endif
            </div>
            
                
                <?php 
                $sum = array();
                $i = 0;
                 ?>
            
            @if (!$sale_bill->elements->isEmpty()) 
               <h6 class="alert alert-sm alert-info text-center">
                        <i class="fa fa-info-circle"></i>
                    بيانات عناصر الفاتورة  رقم
                    {{ $sale_bill->sale_bill_number}} 
                </h6>
                
                <div class='table-responsive'>
               <table style='width:100%;text-align:center' dir='rtl' class='table table-bordered text-right'>
               <thead dir='rtl' class='text-center bg-primary' style='text-align:center;'>
               <td style='border:1px solid #ddd;font-family:Cairo !important;'>م</td>
               <td style='border:1px solid #ddd;font-family:Cairo !important;'>الكود</td>
               <td style='border:1px solid #ddd;font-family:Cairo !important;'>الموديل</td>
               <td style='border:1px solid #ddd;font-family:Cairo !important;'>بيانات المنتج</td>
               <td style='border:1px solid #ddd;font-family:Cairo !important;'>العدد</td>
               <td style='border:1px solid #ddd;font-family:Cairo !important;'> سعر الوحدة </td>
               <td style='border:1px solid #ddd;font-family:Cairo !important;'> سعر الاجمالى</td>
               </thead>
               <tbody>
                @foreach ($sale_bill->elements as $element) 
                   <?php array_push($sum, $element->quantity_price); ?>
                    <tr>
                    <td>{{++$i}}</td>
                    <td>{{{$element->elements_unit->barcode}}} </td>
                    <td>{{$element->product->product_model}}</td>
                    <td>{{$element->product->product_name}}</td>
                    <td>{{$element->quantity}}  {{$element->unit->unit_name}} </td>
                    <td>{{number_format($element->product_price)}}</td>
                    <td>{{number_format($element->quantity_price)}}</td>
                    </tr>
                    
                @endforeach
                </tbody>
                </table>
                </div>
               <?php $total = array_sum($sum);
                $percentage = ($tax_value_added / 100) * $total;
                $after_total = $total + $percentage;
                ?>
            @endif
            <table class='table table-bordered text-right' dir='rtl' style='font-size:12px;'>
                <tr>
                    <td>الاجمالى قبل الخصم والضريبة {{number_format($total)}}  {{$currency}} </td>
            <td>
               
            @foreach ($sale_bill->extras as $key) 
                @if ($key->action == "discount") 
                    @if ($key->action_type == "pound") 
                         خصم  {{$key->value}}  {{$currency}};
                        @php $discount = $key->value; @endphp
                     @else 
                         خصم {{$key->value}}  % ;
                         @php $discount = ($key->value / 100) * $sale_bill->subtotal; @endphp

                    @endif

                @else 
                    <span style='margin-right:30px;'>
                    @if ($key->action_type == "pound") 
                        مصاريف شحن  {{$key->value}}  {{$currency}};
                        @php $extra = $key->value; @endphp

                    @else
                         مصاريف شحن  {{$key->value}}  % 
                            @php $extra = ($key->value / 100) * $sale_bill->subtotal; @endphp
                    @endif
                    </span>
                @endif

            @endforeach

            </td></tr>

            
            <tr>
                    <td>ضريبة القيمة المضافة : (  {{$tax_value_added}} % ) </td>
                    <td>قيمة ضريبة القيمة المضافة    :  {{number_format($sale_bill->subtotal*$sale_bill->tax/100)}}  {{$currency}} </td>
                </tr>
            <tr>
                <td>اجمالى  الفاتورة بعد الخصم والضريبة : {{number_format($sale_bill->final_total)}}  {{$currency}} </td>

                <td>المبلغ المدفوع :  {{number_format($sale_bill->paid)}}  {{$currency}} </td>
 
            </tr>
            <tr style='text-align:center;'>
                    <td style='text-align:center;' colspan='2'> المبلغ المتبقى :  {{number_format($sale_bill->rest)}}  {{$currency}}  </td>
                </tr>
            </table>
            
        </td>
    </tr>
    </tbody>
    @if(!empty($company->basic_settings->footer) &&!empty($company->basic_settings->electronic_stamp))
    <tfoot>
    <tr>
        <td>
                @if(!empty($company->basic_settings->footer))
            <img style="width: 90%; display: inline;float: left;" class="img-footer"
                 src="{{asset($company->basic_settings->footer)}}"/>
                 @endif
                 @if(!empty($company->basic_settings->electronic_stamp))
            <img style="width: 10%;display: inline;float: right; max-height: 60px;" class="img-footer"
                 src="{{asset($company->basic_settings->electronic_stamp)}}"/>
                 @endif
        </td>
    </tr>
    </tfoot>
    @endif
</table>
<button onclick="window.print();" class="no-print btn btn-md btn-success">اضغط للطباعة</button>
<script src="{{asset('app-assets/js/jquery.min.js')}}"></script>
<script type="text/javascript">
    // $(window).on('load',function(){
    // 	var cashid = $('#cashid').val();
    // 	window.open('./print_supplier_receipt.php?cashid='+cashid+'','_blank');
    // });
</script>
</body>
</html>
