<?php
$company = \App\Models\Company::FindOrFail($outer_client_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($outer_client_k) && !empty($outer_client_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($outer_client_k->client_number); ?></td>
                            <td><?php echo e($outer_client_k->client_name); ?></td>
                            <td><?php echo e($outer_client_k->client_category); ?></td>
                            <td><?php echo e($outer_client_k->client_street); ?></td>
                            <td><?php echo e($outer_client_k->shop_name); ?></td>
                            <td><?php echo e($outer_client_k->client_email); ?></td>
                            <td><?php echo e($outer_client_k->client_national); ?></td>
                            <td><?php echo e($outer_client_k->tax_number); ?></td>
                            <td>
                                <?php if($outer_client_k->prev_balance > 0 ): ?>
                                عليه
                                <?php echo e(number_format($outer_client_k->prev_balance)); ?>

                                 <?php elseif($outer_client_k->prev_balance < 0): ?>
                                له
                                <?php echo e(number_format(abs($outer_client_k->prev_balance))); ?>

                                <?php else: ?>
                                0
                                <?php endif; ?>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            <?php endif; ?>
            <div class="clearfix"></div>
            <?php if(isset($gifts) && !$gifts->isEmpty()): ?>
                <p class="alert alert-sm alert-success 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 = $gifts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $gift): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <tr>
                                <td><?php echo e(++$i); ?></td>
                                <td><?php echo e($gift->outerClient->client_name); ?></td>
                                <td><?php echo e($gift->product->product_name); ?></td>
                                <td>
                                    <?php echo e(number_format($gift->amount)); ?>

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

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

                                </td>
                                <td><?php echo e($gift->store->store_name); ?></td>
                                <td><?php echo e($gift->created_at); ?></td>
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </tbody>
                    </table>
                </div>
            <?php endif; ?>
            <div class="clearfix"></div>
            <?php if(isset($quotations) && !$quotations->isEmpty()): ?>
                <p class="alert alert-sm alert-info mt-3 text-center">
                    عروض أسعار العميل
                </p>
                <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>
                    </thead>
                    <tbody>
                    <?php $i = 0; $total = 0; ?>
                    <?php $__currentLoopData = $quotations; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $quotation): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <tr>
                            <td><?php echo e(++$i); ?></td>
                            <td><?php echo e($quotation->quotation_number); ?></td>
                            <td><?php echo e($quotation->start_date); ?></td>
                            <td><?php echo e($quotation->expiration_date); ?></td>
                            <td>
                                <?php $sum = 0; ?>
                                <?php $__currentLoopData = $quotation->elements; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $element): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <?php $sum = $sum + $element->quantity_price; ?>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                <?php
                                $extras = $quotation->extras;
                                foreach ($extras as $key) {
                                    if ($key->action == "discount") {
                                        if ($key->action_type == "pound") {
                                            $quotation_discount_value = $key->value;
                                            $quotation_discount_type = "pound";
                                        } else {
                                            $quotation_discount_value = $key->value;
                                            $quotation_discount_type = "percent";
                                        }
                                    } else {
                                        if ($key->action_type == "pound") {
                                            $quotation_extra_value = $key->value;
                                            $quotation_extra_type = "pound";
                                        } else {
                                            $quotation_extra_value = $key->value;
                                            $quotation_extra_type = "percent";
                                        }
                                    }
                                }
                                if ($extras->isEmpty()) {
                                    $quotation_discount_value = 0;
                                    $quotation_extra_value = 0;
                                    $quotation_discount_type = "pound";
                                    $quotation_extra_type = "pound";
                                }
                                if ($quotation_extra_type == "percent") {
                                    $quotation_extra_value = $quotation_extra_value / 100 * $sum;
                                }
                                $after_discount = $sum + $quotation_extra_value;

                                if ($quotation_discount_type == "percent") {
                                    $quotation_discount_value = $quotation_discount_value / 100 * $sum;
                                }
                                $after_discount = $sum - $quotation_discount_value;
                                $after_discount = $sum - $quotation_discount_value + $quotation_extra_value;
                                $tax_value_added = $company->tax_value_added;
                                $percentage = ($tax_value_added / 100) * $after_discount;
                                $after_total = $after_discount + $percentage;
                                echo number_format($after_total) . " " . $currency;
                                ?>
                                <?php $total = $total + $after_total; ?>
                            </td>
                            <td><?php echo e($quotation->elements->count()); ?></td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </tbody>
                </table>
            <?php endif; ?>
            <div class="clearfix"></div>
            <?php if(isset($saleBills) && !$saleBills->isEmpty()): ?>
                <p class="alert alert-sm alert-info mt-3 text-center">
                    فواتير البيع لهذا العميل
                </p>
                <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 = $saleBills; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $sale_bill): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <tr>
                            <td><?php echo e(++$i); ?></td>
                            <td><a href="<?php echo e(route('client.sale_bills.print',$sale_bill->sale_bill_number)); ?>"><?php echo e($sale_bill->sale_bill_number); ?></a></td>
                            <td><?php echo e($sale_bill->date); ?></td>
                            <td><?php echo e($sale_bill->time); ?></td>
                            <td><?php echo e($sale_bill->final_total); ?> <?php echo e($currency); ?></td>
                            <td><?php echo e($sale_bill->paid); ?> <?php echo e($currency); ?></td>
                            <td><?php echo e($sale_bill->elements->count()); ?> </td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </tbody>
                </table>
            <?php endif; ?>
            <div class="clearfix"></div>
            <?php if(isset($returns) && !$returns->isEmpty()): ?>
                <p class="alert alert-sm alert-dark 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>
                            <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->outerClient->client_name); ?></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($cashs) && !$cashs->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>
                        </tr>
                        </thead>
                        <tbody>
                        <?php
                            $i=0;
                        ?>
                        <?php $__currentLoopData = $cashs; $__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($cash->outerClient->client_name); ?></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($borrows) && !$borrows->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>
                        </tr>
                        </thead>
                        <tbody>
                        <?php
                            $i=0;
                        ?>
                        <?php $__currentLoopData = $borrows; $__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($cash->outerClient->client_name); ?></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><?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($bankcashs) && !$bankcashs->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>
                            <th class="text-center">ملاحظات</th>
                        </tr>
                        </thead>
                        <tbody>
                        <?php
                            $i=0;
                        ?>
                        <?php $__currentLoopData = $bankcashs; $__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($cash->outerClient->client_name); ?></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($outer_client_k) && !empty($outer_client_k)): ?>
                <div class="col-lg-12 text-center mt-3 mb-3">
                    <span class="alert alert-info text-center ">
                        مديونية العميل الحالية
                        
                        <?php if($outer_client_k->prev_balance > 0 ): ?>
                        عليه
                        <?php echo e(number_format($outer_client_k->prev_balance)); ?>

                         <?php elseif($outer_client_k->prev_balance < 0): ?>
                        له
                        <?php echo e(number_format(abs($outer_client_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 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($outer_client_k) && !empty($outer_client_k)): ?>
                            <?php if(!empty($outer_client_k->client_email)): ?>
                                <form class="d-inline" action="<?php echo e(route('client.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($outer_client_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(!$outer_client_k->phones->isEmpty()): ?>
                                <?php
                                $url = url()->full() . '&ref=email';
                                $text = "مرفق رابط لكشف حسابك " ."%0a". $url;
                                $text = str_replace("&", "%26", $text);
                                $phone_number = $outer_client_k->phones[0]->client_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 /home/barasys/public_html/resources/views/client/summary/clients_post.blade.php ENDPATH**/ ?>