@extends('client.layouts.app-main')
@section('title','تعديل فاتورة مبيعات')
@section('content')
    @if (session('success'))
        <div class="alert alert-success alert-dismissable fade show text-center">
            <button class="close" data-dismiss="alert" aria-label="Close">×</button>
            {{ session('success') }}
        </div>
    @endif
    <div class="alert alert-success alert-dismissable text-center box_success d-none no-print">
        <button class="close" data-dismiss="alert" aria-label="Close">×</button>
        <span class="msg_success"></span>
    </div>

    <div class="alert alert-dark alert-dismissable text-center box_error d-none no-print">
        <button class="close" data-dismiss="alert" aria-label="Close">×</button>
        <span class="msg_error"></span>
    </div>
    @if (count($errors) > 0)
        <div class="alert alert-dark no-print">
            <button aria-label="Close" class="close" data-dismiss="alert" type="button">
                <span aria-hidden="true">&times;</span>
            </button>
            <strong>الاخطاء :</strong>
            <ul>
                @foreach ($errors->all() as $error)
                    <li>{{ $error }}</li>
                @endforeach
            </ul>
        </div>
    @endif
    <form target="_blank" action="#" method="POST">
        @csrf
        @method('POST')
        @if(isset($open_sale_bill) && !empty($open_sale_bill))
            <input type="hidden" value="{{$open_sale_bill->sale_bill_number}}" id="sale_bill_number"/>
        @else
            <input type="hidden" value="{{$pre_bill}}" id="sale_bill_number"/>
        @endif
        <h6 class="alert alert-success alert-sm text-center no-print" dir="rtl">
            <center>
                @if(isset($open_sale_bill) && !empty($open_sale_bill))
                    تعديل فاتورة مبيعات عملاء
                @else
                    اضافة فاتورة مبيعات عملاء جديدة
                @endif

                <span>
                        ( رقم العملية  :
                    @if(isset($open_sale_bill) && !empty($open_sale_bill))
                        {{$open_sale_bill->sale_bill_number}}
                    @else
                        {{$pre_bill}}
                    @endif
                    )</span></center>
        </h6>
        <div class="col-lg-3 pull-right no-print">
            <label for="" class="d-block">اسم العميل</label>
            <select required name="outer_client_id" id="outer_client_id" class="selectpicker"
                    data-style="btn-danger" data-live-search="true" title="اكتب او اختار اسم العميل">
                <option
                    @if(isset($open_sale_bill) && !empty($open_sale_bill) && empty($open_sale_bill->outer_client_id))
                    selected
                    @endif
                    value="">فاتورة بيع نقدى
                </option>
                @foreach($outer_clients as $outer_client)
                    <option
                        @if(isset($open_sale_bill) && !empty($open_sale_bill) && $outer_client->id == $open_sale_bill->outer_client_id)
                        selected value="{{$open_sale_bill->outer_client_id}}"
                        @else
                        value="{{$outer_client->id}}"
                        @endif
                    >{{$outer_client->client_name}}</option>
                @endforeach
            </select>
            <a target="_blank" href="{{route('client.outer_clients.create')}}" role="button"
               style="width: 15%;display: inline;"
               class="btn btn-sm btn-danger open_popup">
                <i class="fa fa-plus"></i>
            </a>
        </div>
        <div class="col-lg-3 col-md-3 col-sm-3 pull-right no-print">
            <div class="form-group" dir="rtl">
                <label for="date">تاريخ الفاتورة</label>
                <input type="date" required name="date"
                       @if(isset($open_sale_bill) && !empty($open_sale_bill))
                       value="{{$open_sale_bill->date}}"
                       @else
                       value="<?php echo date("Y-m-d"); ?>"
                       @endif
                       id="date"
                       class="form-control"/>
            </div>
        </div>
        <div class="col-lg-3 col-md-3 col-sm-3 pull-right no-print">
            <div class="form-group" dir="rtl">
                <label for="time">وقت الفاتورة</label>
                <input type="time" required name="time"
                       @if(isset($open_sale_bill) && !empty($open_sale_bill))
                       value="{{$open_sale_bill->time}}"
                       @else
                       value="<?php echo date("H:i:s"); ?>"
                       @endif
                       id="time"
                       class="form-control"/>
            </div>
        </div>
        <div class="col-lg-3 pull-right">
            <label for=""> اختر المخزن </label>
            <select name="store_id" id="store_id" class="selectpicker"
                    data-style="btn-danger" data-live-search="true" title="اختر المخزن">
                <?php $i = 0; ?>
                @foreach($stores as $store)
                    @if($stores->count() == 1)
                        <option selected value="{{$store->id}}">{{$store->store_name}}</option>
                    @else
                        @if($i ==  0)
                            <option selected value="{{$store->id}}">{{$store->store_name}}</option>
                        @else
                            <option value="{{$store->id}}">{{$store->store_name}}</option>
                        @endif
                    @endif
                    <?php $i++; ?>
                @endforeach
            </select>
            <a target="_blank" href="{{route('client.stores.create')}}" role="button"
               style="width: 15%;display: inline;"
               class="btn btn-sm btn-danger open_popup">
                <i class="fa fa-plus"></i>
            </a>
        </div>


        <div class="clearfix no-print"></div>

        <div class="outer_client_details no-print"
             @if(!isset($open_sale_bill) || empty($open_sale_bill) || empty($open_sale_bill->outer_client_id))
             style="display: none !important;"
            @endif>
            <div class="col-lg-3 pull-right">
                <label for=""> الفئة </label>
                <input type="text" class="form-control"
                       @if(isset($open_sale_bill) && !empty($open_sale_bill) && !empty($open_sale_bill->outer_client_id))
                       value="{{$open_sale_bill->OuterClient->client_category}}"
                       @endif
                       readonly id="category"/>
            </div>
            <div class="col-lg-3 pull-right">
                <label for="">مديونية العميل قبل الفاتورة</label>
                <input type="text"
                       @if(isset($open_sale_bill) && !empty($open_sale_bill) && !empty($open_sale_bill->outer_client_id))
                       value="{{$open_sale_bill->OuterClient->balance}}"
                       @endif
                       class="form-control" readonly id="balance_before"/>
            </div>
            <div class="col-lg-3 pull-right">
                <label for="">جنسية العميل</label>
                <input type="text" class="form-control"
                       @if(isset($open_sale_bill) && !empty($open_sale_bill) && !empty($open_sale_bill->outer_client_id))
                       value="{{$open_sale_bill->OuterClient->client_national}}"
                       @endif
                       readonly id="client_national"/>
            </div>
            <div class="col-lg-3 col-md-3 col-sm-3 pull-right no-print">
                <div class="form-group" dir="rtl">
                    <label for="time">ملاحظات على الفاتورة</label>
                    <input type="text" name="notes"
                           @if(isset($open_sale_bill) && !empty($open_sale_bill))
                           value="{{$open_sale_bill->notes}}"
                           @endif id="notes"
                           class="form-control"/>
                </div>
            </div>
            <div class="clearfix"></div>
        </div>
        <div class="clearfix"></div>
        <hr class="no-print">
        <div class="options no-print">
            <div class="col-lg-3 pull-right">
                <label for=""> كود المنتج او الاسم </label>
                <select name="product_id" id="product_id" class="selectpicker"
                        data-style="btn-success" data-live-search="true" title="كود المنتج او الاسم">
                    @foreach($all_products as $product)
                        <option value="{{$product->id}}">{{$product->product_name}}-{{$product->id}}</option>
                    @endforeach
                </select>
                <a target="_blank" href="{{route('client.products.create')}}" role="button"
                   style="width: 15%;display: inline;"
                   class="btn btn-sm btn-danger open_popup">
                    <i class="fa fa-plus"></i>
                </a>
                <div class="available text-center" style="color: #000; font-size: 14px; margin-top: 10px;"></div>

            </div>
            <div class="col-lg-3 pull-right">
                <label for="">سعر المنتج</label>
                <input style="margin-right:5px;margin-left:5px;" type="radio" name="price" id="sector" checked/> قطاعى
                <input style="margin-right:5px;margin-left:5px;" type="radio" name="price" id="wholesale"/> جملة
                <input
                    @cannot('تعديل السعر في فاتورة البيع')
                    readonly
                    @endcan
                    type="text" name="product_price" value="0" id="product_price" class="form-control"/>
            </div>
            <div class="col-lg-3 pull-right">
                <label class="d-block" for=""> الكمية </label>
                <input style="width: 50%;" type="text" name="quantity" id="quantity" min="1" value="1"
                       class="form-control d-inline float-left"/>
                <select style="width: 50%;" class="form-control d-inline float-right" name="unit_id" id="unit_id">
                    <option value="">اختر الوحدة</option>
                    @foreach($units as $unit)
                        <option value="{{$unit->id}}">{{$unit->unit_name}}</option>
                    @endforeach
                </select>

            </div>
            <div class="col-lg-3 pull-right">
                <label for=""> الاجمالى </label>
                <input @cannot('تعديل السعر في فاتورة البيع')
                       readonly
                       @endcan
                       type="text" name="quantity_price" id="quantity_price" class="form-control"/>
            </div>
            <div class="clearfix"></div>
        </div>
        <div class="clearfix"></div>
        <div class="col-lg-12 text-center">
            <button type="button" id="add" class="btn btn-info btn-md mt-3">
                <i class="fa fa-plus"></i>
                اضافة الى فاتورة المبيعات
            </button>
            <button type="button" id="edit" style="display: none" class="btn btn-success btn-md mt-3">
                <i class="fa fa-pencil"></i>
                تعديل
            </button>
        </div>
        <hr>
        </div>
        <div class="company_details printy" style="display: none;">
            <div class="text-center">
                <img class="logo" style="width: 20%;" src="{{asset($company->company_logo)}}" alt="">
            </div>
            <div class="text-center">
                <div class="col-lg-12 text-center justify-content-center">
                    <p class="alert alert-secondary text-center alert-sm"
                       style="margin: 10px auto; font-size: 17px;line-height: 1.9;" dir="rtl">
                        {{$company->company_name}} -- {{$company->business_field}} <br>
                        {{$company->company_owner}} -- {{$company->phone_number}} <br>
                    </p>
                </div>
            </div>
        </div>
        <div class="col-lg-12 col-md-12 col-sm-12 bill_details">
            <h6 class="alert alert-sm alert-dark text-center">
                <i class="fa fa-success-circle"></i>
                بيانات عناصر فاتورة المبيعات رقم

                @if(isset($open_sale_bill) && !empty($open_sale_bill))
                    {{$open_sale_bill->sale_bill_number}}
                @else
                    {{$pre_bill}}
                @endif
            </h6>

            <?php
            if (isset($open_sale_bill) && !empty($open_sale_bill)) {
                $elements = \App\Models\SaleBillElement::where('sale_bill_id', $open_sale_bill->id)->get();
                $extras = \App\Models\SaleBillExtra::where('sale_bill_id', $open_sale_bill->id)->get();
                $extra_settings = \App\Models\ExtraSettings::where('company_id', $company_id)->first();
                $currency = $extra_settings->currency;
                $tax_value_added = $company->tax_value_added;
                $sum = array();
                if (!$elements->isEmpty()) {
                    $i = 0;
                    echo "<div class='table-responsive'><table class='table table-condensed table-striped table-bordered productsTable'>";
                    echo "<thead>";
                    echo "<th>  # </th>";
                    echo "<th> اسم المنتج </th>";
                    echo "<th> سعر الوحدة </th>";
                    echo "<th> الكمية </th>";
                    echo "<th>  الاجمالى </th>";
                    echo "<th class='no-print'>  تحكم </th>";
                    echo "</thead>";
                    echo "<tbody>";
                    echo "</div>";

                    foreach ($elements as $element) {
                        array_push($sum, $element->quantity_price);
                        echo "<tr>";
                        echo "<td>" . ++$i . "</td>";
                        echo "<td>" . $element->product->product_name . "</td>";
                        echo "<td>" . $element->product_price . "</td>";
                        echo "<td>" . $element->quantity . " " . $element->unit->unit_name . "</td>";
                        echo "<td>" . $element->quantity_price . "</td>";
                        echo "<td class='no-print'>
                            <button type='button' sale_bill_number='" . $element->SaleBill->sale_bill_number . "' element_id='" . $element->id . "' class='btn btn-sm btn-info edit_element'>
                                <i class='fa fa-pencil'></i> تعديل
                            </button>
                            <button type='button' sale_bill_number='" . $element->SaleBill->sale_bill_number . "' element_id='" . $element->id . "' class='btn btn-sm btn-danger remove_element'>
                                <i class='fa fa-trash'></i> حذف
                            </button>
                        </td>";
                        echo "</tr>";
                    }
                    echo "</tbody>";
                    echo "</table>";
                    $total = array_sum($sum);
                    $percentage = ($tax_value_added / 100) * $total;
                    $after_total = $total + $percentage;
                    echo "
            <div class='clearfix'></div>
            <div class='alert alert-dark alert-sm text-center'>
                <div class='pull-right col-lg-6 '>
                     اجمالى الفاتورة
                    " . $total . " " . $currency . "
                </div>
                <div class='pull-left col-lg-6 '>
                    اجمالى الفاتورة  بعد القيمة المضافة
                    " . $after_total . " " . $currency . "
                </div>
                <div class='clearfix'></div>
            </div>";
                }
            }
            ?>
        </div>
        <div class="col-lg-12 col-md-12 col-sm-12 after_totals">
            <?php
            if (isset($open_sale_bill) && !empty($open_sale_bill)) {
                $tax_value_added = $company->tax_value_added;
                $sum = array();
                foreach ($elements as $element) {
                    array_push($sum, $element->quantity_price);
                }
                $total = array_sum($sum);
                $previous_extra = \App\Models\SaleBillExtra::where('sale_bill_id', $open_sale_bill->id)
                    ->where('action', 'extra')->first();
                if (!empty($previous_extra)) {
                    $previous_extra_type = $previous_extra->action_type;
                    $previous_extra_value = $previous_extra->value;
                    if ($previous_extra_type == "percent") {
                        $previous_extra_value = $previous_extra_value / 100 * $total;
                    }
                    $after_discount = $total + $previous_extra_value;
                }
                $previous_discount = \App\Models\SaleBillExtra::where('sale_bill_id', $open_sale_bill->id)
                    ->where('action', 'discount')->first();
                if (!empty($previous_discount)) {
                    $previous_discount_type = $previous_discount->action_type;
                    $previous_discount_value = $previous_discount->value;
                    if ($previous_discount_type == "percent") {
                        $previous_discount_value = $previous_discount_value / 100 * $total;
                    }
                    $after_discount = $total - $previous_discount_value;

                }
                if (!empty($previous_extra) && !empty($previous_discount)) {
                    $after_discount = $total - $previous_discount_value + $previous_extra_value;
                } else {
                    $after_discount = $total;
                }
                if (isset($after_discount) && $after_discount != 0) {
                    $percentage = ($tax_value_added / 100) * $after_discount;
                    $after_total_all = $after_discount + $percentage;
                } else {
                    $percentage = ($tax_value_added / 100) * $total;
                    $after_total_all = $total + $percentage;
                }
                echo "
                <div class='clearfix'></div>
                <div class='alert alert-secondary alert-sm text-center'>
                       اجمالى الفاتورة النهائى بعد الضريبة والشحن والخصم :
                        " . $after_total_all . " " . $currency . "
                </div>";
            }
            ?>
        </div>

        <div class="clearfix no-print"></div>
        <hr class="no-print">
        <div class="row no-print" style="margin: 20px auto;">
            <div class="col-lg-12">
                <div class="col-lg-6 col-md-6 col-xs-6 pull-right">
                    <div class="form-group" dir="rtl">
                        <label for="discount">خصم على اجمالى الفاتورة</label> <br>
                        <?php
                        if (isset($open_sale_bill) && !empty($open_sale_bill)) {
                            foreach ($extras as $key) {
                                if ($key->action == "discount") {
                                    if ($key->action_type == "pound") {
                                        $sale_bill_discount_value = $key->value;
                                        $sale_bill_discount_type = "pound";
                                    } else {
                                        $sale_bill_discount_value = $key->value;
                                        $sale_bill_discount_type = "percent";
                                    }
                                } else {
                                    if ($key->action_type == "pound") {
                                        $sale_bill_extra_value = $key->value;
                                        $sale_bill_extra_type = "pound";
                                    } else {
                                        $sale_bill_extra_value = $key->value;
                                        $sale_bill_extra_type = "percent";
                                    }
                                }
                            }
                        }
                        if(empty($sale_bill_discount_type)){
                         $sale_bill_discount_type = "pound";
                         $sale_bill_discount_value=0;
                        }
                        ?>
                        @if (isset($open_sale_bill) && !empty($open_sale_bill))
                            <select name="discount_type" id="discount_type" class="form-control"
                                    style="width: 20%;display: inline;float: right; margin-left:5px;">
                                <option @if($sale_bill_discount_type == "pound") selected
                                        @endif value="pound">{{$extra_settings->currency}}</option>
                                <option @if($sale_bill_discount_type == "percent") selected @endif value="percent">%
                                </option>
                            </select>
                            <input type="number" value="{{$sale_bill_discount_value}}" name="discount_value" min="1"
                                   style="width: 50%;display: inline;float: right;"
                                   id="discount_value" class="form-control "/>
                        @else
                            <select name="discount_type" id="discount_type" class="form-control" disabled
                                    style="width: 20%;display: inline;float: right; margin-left:5px;">
                                <option value="pound">{{$extra_settings->currency}}</option>
                                <option value="percent">%</option>
                            </select>
                            <input type="number" value="0" name="discount_value" min="1"
                                   style="width: 50%;display: inline;float: right;"
                                   disabled id="discount_value" class="form-control "/>
                        @endif
                    </div>
                </div>
                <div class="col-lg-6 col-md-6 col-xs-6 pull-right">
                    <div class="form-group" dir="rtl">
                        <label for="extra">مصاريف الشحن</label> <br>
                        @if (isset($open_sale_bill) && !empty($open_sale_bill))
                            <select name="extra_type" id="extra_type" class="form-control"
                                    style="width: 20%;display: inline;float: right;margin-left: 5px">
                                <option @if($sale_bill_extra_type == "pound") selected
                                        @endif value="pound">{{$extra_settings->currency}}</option>
                                <option @if($sale_bill_extra_type == "percent") selected @endif value="percent">%
                                </option>
                            </select>
                            <input value="{{$sale_bill_extra_value}}" type="number" name="extra_value"
                                   style="width: 50%;display: inline;float: right;" min="1"
                                   id="extra_value" class="form-control"/>
                        @else
                            <select disabled name="extra_type" id="extra_type" class="form-control"
                                    style="width: 20%;display: inline;float: right;margin-left: 5px">
                                <option value="pound">{{$extra_settings->currency}}</option>
                                <option value="percent">%</option>
                            </select>
                            <input disabled value="0" type="number" name="extra_value" min="1"
                                   style="width: 50%;display: inline;float: right;"
                                   id="extra_value" class="form-control"/>
                        @endif
                    </div>
                </div>
                <div class="clearfix"></div>
            </div> <!--  End Col-lg-12 -->
        </div><!--  End Row -->
    </form>
    <div class="col-lg-12 no-print" style="padding-top: 25px;height: 40px !important;">
        <button type="button"
                @if (!isset($open_sale_bill) || empty($open_sale_bill))
                disabled
                @endif
                data-toggle="modal"
                data-target="#myModal2"
                class="btn btn-md btn-dark pay_btn pull-right">
            <i class="fa fa-money"></i>
            تسجيل الدفع
        </button>

        <form class="d-inline" method="POST" action="{{route('client.sale_bills.cancel')}}">
            @csrf
            @method('POST')
            @if (isset($open_sale_bill) && !empty($open_sale_bill))
                <input type="hidden" value="{{$open_sale_bill->sale_bill_number}}" name="sale_bill_number"/>
            @else
                <input type="hidden" value="{{$pre_bill}}" name="sale_bill_number"/>
            @endif
            <button href="" type="submit" @if (!isset($open_sale_bill) || empty($open_sale_bill)) disabled @endif
            class="btn btn-md close_btn btn-danger pull-right ml-3"><i
                    class="fa fa-check"></i>
                الغاء وخروج
            </button>
        </form>
        <a href="javascript:;" role="button"
           class="btn @if (!isset($open_sale_bill) || empty($open_sale_bill)) disabled @endif save_btn btn-md btn-success pull-right ml-3"><i
                class="fa fa-check"></i>
            حفظ وطباعة وخروج
        </a>
    </div>

    <div class="modal fade" dir="rtl" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel2">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header w-100">
                    <h4 class="modal-title text-center" id="myModalLabel2">دفع نقدى</h4>
                </div>
                <div class="modal-body">
                    @if((isset($sale_bill_cash) && !$sale_bill_cash->isEmpty()) || (isset($sale_bill_bank_cash) && !$sale_bill_bank_cash->isEmpty()))
                        <table class="table table-condensed table-striped table-hover">
                            <thead>
                            <tr>
                                <th>#</th>
                                <th>المبلغ</th>
                                <th>طريقة الدفع</th>
                                <th>حذف</th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php $j = 0; ?>
                            @if(isset($sale_bill_cash) && !$sale_bill_cash->isEmpty())
                                @foreach($sale_bill_cash as $cash)
                                    <tr>
                                        <td>{{++$j}}</td>
                                        <td>{{$cash->amount}}</td>
                                        <td>دفع كاش نقدى
                                            <br>
                                            ( {{$cash->safe->safe_name}} )
                                        </td>
                                        <td>
                                            <button type="button" payment_method="cash" cash_id="{{$cash->id}}"
                                                    class="btn btn-danger delete_pay">حذف
                                            </button>
                                        </td>
                                    </tr>
                                @endforeach
                            @endif
                            @if(isset($sale_bill_bank_cash) && !$sale_bill_bank_cash->isEmpty())
                                @foreach($sale_bill_bank_cash as $cash)
                                    <tr>
                                        <td>{{++$j}}</td>
                                        <td>{{$cash->amount}}</td>
                                        <td>دفع بنكى شبكة
                                            <br>
                                            ( {{$cash->bank->bank_name}} )
                                            <br>
                                            ( {{$cash->bank_check_number}} )
                                        </td>
                                        <td>
                                            <button type="button" payment_method="bank" cash_id="{{$cash->id}}"
                                                    class="btn btn-danger delete_pay">حذف
                                            </button>
                                        </td>
                                    </tr>
                                @endforeach
                            @endif
                            </tbody>
                        </table>
                    @endif
                    <input type="hidden" id="company_id" value="{{$company_id}}">
                    <h5 class="col-lg-12 d-block mb-2">البيانات الاساسية</h5>
                    <hr>
                    <div class="row mb-3">
                        <div class="col-md-4">
                            <label> رقم العملية <span class="text-danger">*</span></label>
                            <input required readonly value="{{$pre_cash}}" class="form-control"
                                   id="cash_number" type="text">
                        </div>
                        <div class="col-md-4">
                            <label> المبلغ المدفوع <span class="text-danger">*</span></label>
                            <input required class="form-control"
                                   id="amount" type="text" dir="ltr">
                        </div>
                        <div class="col-md-4">
                            <label> طريقة الدفع <span class="text-danger">*</span></label>
                            <select required id="payment_method" name="payment_method" class="form-control">
                                <option value="">اختر طريقة الدفع</option>
                                <option value="cash">دفع كاش نقدى</option>
                                @if(count($banks) > 0)
                                    <option value="bank">دفع بنكى شبكة</option>
                                @endif    
                            </select>
                        </div>
                    </div>

                    <div class="row mb-3 cash" style="display: none;">
                        <div class="col-md-4">
                            <label> خزنة الدفع <span class="text-danger">*</span></label>
                            <select style="width: 80% !important; display: inline !important;" required id="safe_id"
                                    class="form-control">
                                <option value="">اختر خزنة الدفع</option>
                                @foreach($safes as $safe)
                                    <option
                                    value="{{$safe->id}}" @if($safe->safe_name=="الخزنة الرئيسية") selected  @endif >{{$safe->safe_name}}</option>
                                @endforeach
                            </select>
                            <a target="_blank" href="{{route('client.safes.create')}}" role="button"
                               style="width: 15%;display: inline;"
                               class="btn btn-sm btn-danger open_popup">
                                <i class="fa fa-plus"></i>
                            </a>
                        </div>
                    </div>
                    <div class="row mb-3 bank" style="display: none;">
                        <div class="col-md-4">
                            <label class="d-block"> البنك <span class="text-danger">*</span></label>
                            <select style="width: 80% !important; display: inline !important;" required id="bank_id"
                                    class="form-control">
                                <option value="">اختر البنك</option>
                                @foreach($banks as $bank)
                                    <option
                                        value="{{$bank->id}}">{{$bank->bank_name}}</option>
                                @endforeach
                            </select>
                            <a target="_blank" href="{{route('client.banks.create')}}" role="button"
                               style="width: 15%;display: inline;"
                               class="btn btn-sm btn-danger open_popup">
                                <i class="fa fa-plus"></i>
                            </a>
                        </div>
                        <div class="col-md-4">
                            <label for="">رقم المعاملة</label>
                            <input type="text" class="form-control" id="bank_check_number"/>
                        </div>
                        <div class="col-md-4">
                            <label for="">ملاحظات</label>
                            <input type="text" class="form-control" id="bank_notes"/>
                        </div>
                    </div>
                    <div class="col-xs-12 col-sm-12 col-md-12 text-center">
                        <button class="btn btn-success pd-x-20 pay_cash" type="button">تسجيل الدفع</button>
                    </div>
                </div>
                <div class="modal-footer">
                    <input type="hidden" name="client_name" id="client_name"/>
                    <button type="button" class="btn btn-default" data-dismiss="modal"><i class="fa fa-close"></i> اغلاق
                    </button>
                </div>
            </div>
        </div>
    </div>
    <input type="hidden" id="final_total"
           @if (isset($open_sale_bill) && !empty($open_sale_bill)) value="{{$open_sale_bill->final_total}}" @endif />
    <input type="hidden" id="product" placeholder="product" name="product"/>
    <input type="hidden" id="total" placeholder="اجمالى قبل الخصم" name="total"/>
    <input type="hidden" value="0" id="check"/>

@endsection
@section('script')
<script src="{{asset('js/pages/edit_sales.js')}}"></script>
@endsection
@section('style')
<style>
    .btn.dropdown-toggle.bs-placeholder, .form-control {
        height: 40px !important;
    }

    a, a:hover {
        text-decoration: none;
        color: #444;
    }

    .bootstrap-select {
        width: 80% !important;
    }

    .bill_details {
        margin-top: 30px !important;
        min-height: 150px !important;
    }
</style>
@endsection