<?php
$company = \App\Models\Company::FindOrFail($supplier_k->company_id);
$extra_settings = \App\Models\ExtraSettings::where('company_id', $company->id)->first();
$currency = $extra_settings->currency;
?>

    <!DOCTYPE html>
<html>
<head>
    <title>
        كشف حساب مورد
    </title>
    <meta charset="utf-8"/>
    <link href="<?php echo e(asset('app-assets/css/bootstrap.min.css')); ?>" rel="stylesheet"/>
    <style type="text/css" media="screen">
        @font-face {
            font-family: 'Cairo';
            src: url(<?php echo e(asset('fonts/Cairo.ttf')); ?>);
        }

        body, html {
            font-family: 'Cairo' !important;
            direction: rtl !important;
            text-align: center !important;
            font-size: 13px;
        }

        h1, h2, h3, h4, h5, h6 {
            font-family: 'Cairo' !important;
        }

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

        .no-print {
            bottom: 0;
            right: 30px;
            border-radius: 0;
            z-index: 9999;
        }

        table tr th, table tr td {
            text-align: center !important;
        }
    </style>
    <style type="text/css" media="print">
            @font-face {
            font-family: 'Cairo';
            src: url(<?php echo e(asset('fonts/Cairo.ttf')); ?>);
        }
        h1, h2, h3, h4, h5, h6 {
            font-family: 'Cairo' !important;
        }
        
        body, html {
            font-family: 'Cairo' !important;
            direction: rtl !important;
            text-align: center !important;
            font-size: 13px;
            -webkit-print-color-adjust: exact !important;
            -moz-print-color-adjust: exact !important;
            print-color-adjust: exact !important;
            -o-print-color-adjust: exact !important;
        }

        table tr th, table tr td {
            text-align: center !important;
        }

        .no-print {
            display: none;
        }
    </style>
</head>
<body style="background: #fff">
<table class="table table-bordered table-container">
    <tbody>
    <tr>
        <td class="thisTD">
            <h3 class="alert alert-sm alert-light text-center" style="margin:20px auto;">
                كشف حساب مورد 
                <br>
                <br>
                 <?php if(empty($to_date) || empty($from_date)): ?>
                 كامل
                 <?php else: ?>
                  من تاريخ <?php echo e($from_date); ?> إلي تاريخ <?php echo e($to_date); ?>

                 <?php endif; ?>
            </h3>
            <?php if(isset($supplier_k) && !empty($supplier_k)): ?>
                <p class="alert alert-sm alert-danger text-center">
                    عرض بيانات المورد
                </p>
                <div class="table-responsive">
                    <table class="table table-condensed table-striped table-bordered text-center table-hover">
                        <thead>
                        <tr>
                            <th class="text-center">#</th>
                            <th class="text-center">الاسم</th>
                            <th class="text-center">الفئة</th>
                            <th class="text-center">العنوان</th>
                            <th class="text-center">اسم المحل</th>
                            <th class="text-center">البريد الالكترونى</th>
                            <th class="text-center">الهاتف</th>
                            <th class="text-center">الرقم الضريبى</th>
                            <th class="text-center"> مستحقات</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr>
                            <td><?php echo e($supplier_k->id); ?></td>
                            <td><?php echo e($supplier_k->supplier_name); ?></td>
                            <td><?php echo e($supplier_k->supplier_category); ?></td>
                            <td><?php echo e($supplier_k->addresses[0]->supplier_address); ?></td>
                            <td><?php echo e($supplier_k->shop_name); ?></td>
                            <td><?php echo e($supplier_k->supplier_email); ?></td>
                            <td><?php echo e($supplier_k->phones[0]->supplier_phone); ?></td>
                            <td><?php echo e($supplier_k->tax_number); ?></td>
                            <td>
                            <?php if($supplier_k->prev_balance > 0 ): ?>
                            له
                            <?php echo e(number_format($supplier_k->prev_balance)); ?>


                             <?php elseif($supplier_k->prev_balance < 0): ?>
                            علية
                            <?php echo e(number_format(abs($supplier_k->prev_balance))); ?>

                             <?php else: ?>
                             0
                            <?php endif; ?>                        
                        </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            <?php endif; ?>
            <div class="clearfix"></div>
            <?php if(isset($buyBills) && !$buyBills->isEmpty()): ?>
                <p class="alert alert-sm alert-primary mt-3 text-center">
                    فواتير المشتريات لهذا المورد
                </p>
                <div class="table-responsive">
                    <table class='table table-condensed table-striped table-bordered'>
                        <thead class="text-center">
                        <th>#</th>
                        <th>رقم الفاتورة</th>
                        <th>تاريخ الفاتورة</th>
                        <th> وقت الفاتورة</th>
                        <th>الاجمالى النهائى</th>
                        <th>المدفوع</th>
                        <th>عدد العناصر</th>
                        </thead>
                        <tbody>
                        <?php $i = 0; $total = 0; ?>
                        <?php $__currentLoopData = $buyBills; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $buy_bill): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <tr>
                                <td><?php echo e(++$i); ?></td>
                                <td><a href="<?php echo e(route('client.buy_bills.print',$buy_bill->buy_bill_number)); ?>"><?php echo e($buy_bill->buy_bill_number); ?></a></td>
                                <td><?php echo e($buy_bill->date); ?></td>
                                <td><?php echo e($buy_bill->time); ?></td>
                                <td>
                                    <?php echo e(number_format($buy_bill->final_total)); ?> <?php echo e($currency); ?>

                                </td>
                                <td>
                                    <?php echo e(number_format($buy_bill->paid)); ?> <?php echo e($currency); ?>

                                </td>
                                <td><?php echo e($buy_bill->elements->count()); ?></td>
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </tbody>
                    </table>
                </div>

            <?php endif; ?>
            <div class="clearfix"></div>
            <?php if(isset($returns) && !$returns->isEmpty()): ?>
                <p class="alert alert-sm alert-dark text-center">
                    مرتجعات المورد
                </p>
                <div class="table-responsive">
                    <table class="table table-condensed table-striped table-bordered text-center table-hover">
                        <thead>
                        <tr>
                            <th class="text-center">رقم الفاتورة</th>
                            <th class="text-center"> المنتج</th>
                            <th class="text-center"> الكمية المرتجعة</th>
                            <th class="text-center"> الوقت</th>
                            <th class="text-center"> التاريخ</th>
                            <th class="text-center"> سعر المنتج</th>
                            <th class="text-center"> سعر الكمية</th>
                            <th class="text-center"> مستحقات المورد قبل الارتجاع</th>
                            <th class="text-center"> مستحقات المورد بعد الارتجاع</th>
                            <th class="text-center"> رصيد المنتج قبل الارتجاع</th>
                            <th class="text-center"> رصيد المنتج بعد الارتجاع</th>
                        </tr>
                        </thead>
                        <tbody>
                        <?php
                            $i=0;
                        ?>
                        <?php $__currentLoopData = $returns; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $return): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <tr>
                                <td><?php echo e($return->bill_id); ?></td>
                                <td><?php echo e($return->product->product_name); ?></td>
                                <td><?php echo e(number_format( $return->return_quantity  )); ?></td>
                                <td><?php echo e($return->date); ?></td>
                                <td><?php echo e($return->time); ?></td>
                                <td><?php echo e(number_format( $return->product_price  )); ?></td>
                                <td><?php echo e(number_format( $return->quantity_price  )); ?></td>

                                <td><?php echo e(number_format( $return->balance_before  )); ?></td>
                                <td><?php echo e(number_format( $return->balance_after  )); ?></td>

                                <td><?php echo e(number_format( $return->before_return  )); ?></td>
                                <td><?php echo e(number_format( $return->after_return  )); ?></td>
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </tbody>
                    </table>
                </div>
            <?php endif; ?>
            <div class="clearfix"></div>
            <?php if(isset($buyBorrows) && !$buyBorrows->isEmpty()): ?>
                <p class="alert alert-sm alert-warning mt-3 text-center">
                    سلفيات من المورد
                </p>
                <div class="table-responsive">
                    <table class="table table-condensed table-striped table-bordered text-center table-hover">
                        <thead>
                        <tr>
                            <th class="text-center">رقم العملية</th>
                            <th class="text-center">المبلغ</th>
                            <th class="text-center">رصيد قبل</th>
                            <th class="text-center">رصيد بعد</th>
                            <th class="text-center">رقم الفاتورة</th>
                            <th class="text-center">التاريخ</th>
                            <th class="text-center">الوقت</th>
                            <th class="text-center">خزنة الدفع</th>
                        </tr>
                        </thead>
                        <tbody>
                        <?php
                            $i=0;
                        ?>
                        <?php $__currentLoopData = $buyBorrows; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $cash): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <tr>
                                <td><?php echo e($cash->cash_number); ?></td>
                                <td><?php echo e(number_format( abs($cash->amount)  )); ?></td>
                                <td><?php echo e(number_format( $cash->balance_before  )); ?></td>
                                <td><?php echo e(number_format( $cash->balance_after  )); ?></td>
                                <td> سلفة نقدية </td>
                                <td><?php echo e($cash->date); ?></td>
                                <td><?php echo e($cash->time); ?></td>
                                <td><?php echo e($cash->safe->safe_name); ?></td>
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </tbody>
                    </table>
                </div>
            <?php endif; ?>
            <?php if(isset($buyCashs) && !$buyCashs->isEmpty()): ?>
                <p class="alert alert-sm alert-warning mt-3 text-center">
                    مدفوعات نقدية لهذا المورد
                </p>
                <div class="table-responsive">
                    <table class="table table-condensed table-striped table-bordered text-center table-hover">
                        <thead>
                        <tr>
                            <th class="text-center">رقم العملية</th>
                            <th class="text-center">المبلغ</th>
                            <th class="text-center">رصيد قبل</th>
                            <th class="text-center">رصيد بعد</th>
                            <th class="text-center">رقم الفاتورة</th>
                            <th class="text-center">التاريخ</th>
                            <th class="text-center">الوقت</th>
                            <th class="text-center">خزنة الدفع</th>
                        </tr>
                        </thead>
                        <tbody>
                        <?php
                            $i=0;
                        ?>
                        <?php $__currentLoopData = $buyCashs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $cash): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <tr>
                                <td><?php echo e($cash->cash_number); ?></td>
                                <td><?php echo e(number_format( $cash->amount  )); ?></td>
                                <td><?php echo e(number_format( $cash->balance_before  )); ?></td>
                                <td><?php echo e(number_format( $cash->balance_after  )); ?></td>
                                <td><?php if(!empty($cash->bill_id)): ?>  فاتورة # <?php echo e($cash->bill_id); ?> <?php else: ?> تسديد نقدي <?php endif; ?></td>
                                <td><?php echo e($cash->date); ?></td>
                                <td><?php echo e($cash->time); ?></td>
                                <td><?php echo e($cash->safe->safe_name); ?></td>
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </tbody>
                    </table>
                </div>
            <?php endif; ?>
            <?php if(isset($bankbuyCashs) && !$bankbuyCashs->isEmpty()): ?>
                <p class="alert alert-sm alert-warning mt-3 text-center">
                    مدفوعات بنكية لهذا المورد
                </p>
                <div class="table-responsive">
                    <table class="table table-condensed table-striped table-bordered text-center table-hover">
                        <thead>
                        <tr>
                            <th class="text-center">رقم العملية</th>
                            <th class="text-center">المبلغ</th>
                            <th class="text-center">رصيد قبل</th>
                            <th class="text-center">رصيد بعد</th>
                            <th class="text-center">رقم الفاتورة</th>
                            <th class="text-center">التاريخ</th>
                            <th class="text-center">الوقت</th>
                            <th class="text-center">البنك</th>
                            <th class="text-center">رقم المعاملة</th>
                            <th class="text-center">ملاحظات</th>
                        </tr>
                        </thead>
                        <tbody>
                        <?php
                            $i=0;
                        ?>
                        <?php $__currentLoopData = $bankbuyCashs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $cash): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <tr>
                                <td><?php echo e($cash->cash_number); ?></td>
                                <td><?php echo e(number_format( $cash->amount  )); ?></td>
                                <td><?php echo e(number_format( $cash->balance_before  )); ?></td>
                                <td><?php echo e(number_format( $cash->balance_after  )); ?></td>
                                <td><?php if(!empty($cash->bill_id)): ?>  فاتورة # <?php echo e($cash->bill_id); ?>  <?php else: ?> تسديد بنكي <?php endif; ?></td>
                                <td><?php echo e($cash->date); ?></td>
                                <td><?php echo e($cash->time); ?></td>
                                <td><?php echo e($cash->bank->bank_name); ?></td>
                                <td><?php echo e($cash->bank_check_number); ?></td>
                                <td><?php echo e($cash->notes); ?></td>
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </tbody>
                    </table>
                </div>
            <?php endif; ?>
            <?php if(isset($supplier_k) && !empty($supplier_k)): ?>
                <div class="col-lg-12 text-center mt-3 mb-3">
                            <span class="alert alert-secondary text-center ">
                                مستحقات المورد الحالية

                                <?php if($supplier_k->prev_balance > 0 ): ?>
                                له
                                <?php echo e(number_format($supplier_k->prev_balance)); ?>

    
                                 <?php elseif($supplier_k->prev_balance < 0): ?>
                                علية
                                <?php echo e(number_format(abs($supplier_k->prev_balance))); ?>

                                 <?php else: ?>
                                 0
                                <?php endif; ?>    
                                
                                <?php echo e($currency); ?>

                            </span>
                </div>
            <?php endif; ?>
            <?php if(auth()->guard('client-web')->check()): ?>
            <div class="row mt-1 mb-1 text-center no-print">
                <div class="col-lg-12 text-center">
                    <button onclick="window.print()" type="button" class="btn btn-md btn-info">
                        <i class="fa fa-print"></i>
                        طباعة تقرير كشف الحساب
                    </button>
                    <?php if(isset($_GET['ref']) && $_GET['ref'] == "email"): ?>

                    <?php else: ?>
                        <?php if(isset($supplier_k) && !empty($supplier_k)): ?>
                            <?php if(!empty($supplier_k->supplier_email)): ?>
                                <form class="d-inline" action="<?php echo e(route('supplier.summary.send')); ?>" method="post">
                                    <?php echo csrf_field(); ?>
                                    <?php echo method_field('POST'); ?>
                                    <input type="hidden" value="<?php echo e(url()->full().'&ref=email'); ?>" name="url"/>
                                    <input type="hidden" value="<?php echo e($supplier_k->id); ?>" name="id"/>
                                    <button type="submit" class="btn btn-md btn-warning">
                                        <i class="fa fa-envelope-o"></i>
                                        ارسال كشف الحساب الى بريد المورد
                                    </button>
                                </form>
                            <?php else: ?>
                                <span class="alert alert-sm alert-warning text-center">
                                    خانه البريد الالكترونى للمورد فارغة
                                </span>
                            <?php endif; ?>
                            <?php if(!$supplier_k->phones->isEmpty()): ?>
                                <?php
                                $url = url()->full() . '&ref=email';
                                $text = "مرفق رابط لكشف حسابك " . "%0a" . $url;
                                $text = str_replace("&", "%26", $text);
                                $phone_number = $supplier_k->phones[0]->supplier_phone;
                                ?>
                                <a class="btn btn-success btn-md" target="_blank"
                                   href="https://wa.me/<?php echo e($phone_number); ?>?text=<?php echo e($text); ?>">
                                    ارسال الى واتساب المورد
                                </a>
                            <?php else: ?>
                                <span class="alert alert-sm alert-warning text-center">
                                    خانه رقم الهاتف للمورد فارغة
                                </span>
                            <?php endif; ?>
                        <?php endif; ?>
                    <?php endif; ?>
                </div>
            </div>
            <?php endif; ?>
        </td>
    </tr>
    </tbody>
</table>
<script src="<?php echo e(asset('app-assets/js/jquery.min.js')); ?>"></script>
<script type="text/javascript">

</script>
</body>
</html>
<?php /**PATH E:\xampp\htdocs\sales\resources\views/client/summary/suppliers_post.blade.php ENDPATH**/ ?>