<?php if(isset($open_quotation) && !empty($open_quotation)): ?>
<?php $__env->startSection('title', ' تعديل عرض سعر '.$open_quotation->quotation_number ); ?>
 <?php else: ?>
<?php $__env->startSection('title', ' إضافة عرض سعر '.$pre_quotation ); ?>
 <?php endif; ?>
 <?php $__env->startSection('content'); ?>
 <!-- BEGIN: Content-->
 <div class="app-content content ">
    <div class="content-overlay"></div>
    <div class="header-navbar-shadow"></div>
    <div class="content-wrapper container-xxl p-0">
      <div class="content-header row">
        <div class="content-header-left col-md-9 col-12 mb-2">
          <div class="row breadcrumbs-top">
            <div class="col-12">

            <h2 class="content-header-title float-start mb-0">
              <?php if(isset($open_quotation) && !empty($open_quotation)): ?>تعديل عرض أسعار <?php else: ?> إضافة عرض أسعار <?php endif; ?>
            </h2>
              <div class="breadcrumb-wrapper">
                <ol class="breadcrumb">
                  <li class="breadcrumb-item"><a href="<?php echo e(route('client.home')); ?>">لوحة التحكم </a>
                  </li>
                  <li class="breadcrumb-item"><a href="<?php echo e(route('client.quotations.index')); ?>">عروض الأسعار</a>
                  </li>
                  <li class="breadcrumb-item active" >               
                    <?php if(isset($open_quotation) && !empty($open_quotation)): ?>تعديل عرض سعر  <?php else: ?> إضافة عرض سعر  <?php endif; ?>
                  </li>
                  <li class="breadcrumb-item active" >               
                    <?php if(isset($open_quotation) && !empty($open_quotation)): ?><?php echo e($open_quotation->quotation_number); ?><?php else: ?><?php echo e($pre_quotation); ?><?php endif; ?>
                  </li>
                </ol>
              </div>
            </div>
          </div>
        </div>
        <div class="content-header-right text-md-end col-md-3 col-12 d-md-block d-none">
          <div class="mb-1 breadcrumb-right">
            <div class="dropdown">
                <a  href="<?php echo e(route('client.quotations.index')); ?>">
                    <button class="btn-icon btn btn-primary" type="button"><i data-feather='eye'> </i></button>
                </a>
            </div>
          </div>
        </div>
      </div>
      <div class="content-body">
        <!-- Basic Horizontal form layout section start -->
        <!-- Basic multiple Column Form section start -->
        <section class="invoice-add-wrapper" data-select2-id="13">
            <form target="_blank" action="#" method="POST" id="invoice" >
                <?php echo csrf_field(); ?>
                <input id="company_id" value="<?php echo e($company_id); ?>" type="hidden">

                <?php if(isset($open_quotation) && !empty($open_quotation)): ?>
                <input id="quotation_id" value="<?php echo e($open_quotation->id); ?>" type="hidden">
                <input type="hidden" value="<?php echo e($open_quotation->quotation_number); ?>" id="quotation_number"/>
                <input type="hidden" value="<?php echo e($open_quotation->status); ?>" id="status"/>
                
                <?php else: ?>
                <input id="quotation_number" value="<?php echo e($pre_quotation); ?>" type="hidden">
                <input type="hidden" value="open" id="status"/>

                <?php endif; ?>

            <div class="row invoice-add">
              <!-- Invoice Add Left starts -->
              <div class="col-xl-9 col-md-8 col-12" data-select2-id="12">
                <div class="card invoice-preview-card" data-select2-id="11">
                  <!-- Header starts -->
                  <div class="card-body invoice-padding pb-0 row">
                    
                    <div class="col-xl-3 col-md-3 col-12" >
                        <div class="mb-1" align="center">
                          <b  class="form-label" for="client_name" >اسم العميل</b>
          
                          <select  name="outer_client_id" id="outer_client_id" class="search select2-selection__placeholder">
                      <?php $__currentLoopData = $outer_clients; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $outer_client): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                      <option value="" selected>اختر العميل</option>
                          <option
                              <?php if(isset($open_quotation) && !empty($open_quotation) && $outer_client->id == $open_quotation->outer_client_id): ?>
                              selected value="<?php echo e($open_quotation->outer_client_id); ?>"
                              <?php else: ?>
                              value="<?php echo e($outer_client->id); ?>"
                              <?php endif; ?>
                          ><?php echo e($outer_client->client_name); ?></option>
                      <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                  </select>
                        </div>
                     </div>

                     <div class="col-xl-3 col-md-3 col-12" >
                        <div class="mb-1" align="center">
                          <b class="form-label" for="date" >تاريخ العرض </b>
                          <input type="date"  name="date"
                                 <?php if(isset($open_quotation) && !empty($open_quotation)): ?>
                                 value="<?php echo e($open_quotation->date); ?>"
                                 <?php else: ?>
                                 value="<?php echo date("Y-m-d"); ?>"
                                 <?php endif; ?>
                                 id="date"
                                 class="form-control"/>
                      </div>
                        </div>

                        <div class="col-xl-3 col-md-3 col-12" >
                            <div class="mb-1" align="center">
                              <b class="form-label" for="time" >وقت العرض </b>
                              <input type="time"  name="time"
                                     <?php if(isset($open_quotation) && !empty($open_quotation)): ?>
                                     value="<?php echo e($open_quotation->time); ?>"
                                     <?php else: ?>
                                     value="<?php echo date("H:i:s"); ?>"
                                     <?php endif; ?>
                                     id="time"
                                     class="form-control"/>
                          </div>
                            </div>

                            <div class="col-xl-3 col-md-3 col-12" >
                                <div class="mb-1" align="center">
                                  <b class="form-label" for="store_id" > مخزن البيع </b>
                                  <select name="store_id" id="store_id" class="search select2-selection__placeholder"
                                          title="اختر المخزن">
                                      <?php $i = 0; ?>
                                      <?php $__currentLoopData = $stores; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $store): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                              <option value="all" selected>جميع المنتجات</option>
                              <option value="<?php echo e($store->id); ?>"><?php echo e($store->store_name); ?></option>
                                      <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                  </select>
                                  
                              </div>
                                </div>
                                <div class=" outer_client_details no-print row"
                                <?php if(!isset($open_quotation) || empty($open_quotation) || empty($open_quotation->outer_client_id)): ?>
                                style="display: none !important;"
                               <?php endif; ?>>
                               <div class="col-xl-3 col-md-3 col-12" >
                                <label class="form-label"> الفئة </label>
                                   <input type="text" class="form-control"
                                          <?php if(isset($open_quotation) && !empty($open_quotation) && !empty($open_quotation->outer_client_id)): ?>
                                          value="<?php echo e($open_quotation->OuterClient->client_category); ?>"
                                          <?php endif; ?>
                                          readonly id="category"/>
                               </div>
                               <div class="col-xl-3 col-md-3 col-12" >
                                   <label class="form-label">المديونية   </label>
                                   <input type="text"
                                          <?php if(isset($open_quotation) && !empty($open_quotation) && !empty($open_quotation->outer_client_id)): ?>
                                          value="<?php if($open_quotation->OuterClient->prev_balance > 0 ): ?> علية <?php else: ?> لة <?php endif; ?> <?php echo e($open_quotation->OuterClient->prev_balance); ?>"
                                          <?php endif; ?>
                                          class="form-control" readonly id="balance_before"/>
                               </div>
                               <div class="col-xl-3 col-md-3 col-12" >
                                   <label class="form-label">جنسية العميل</label>
                                   <input type="text" class="form-control"
                                          <?php if(isset($open_quotation) && !empty($open_quotation) && !empty($open_quotation->outer_client_id)): ?>
                                          value="<?php echo e($open_quotation->OuterClient->client_national); ?>"
                                          <?php endif; ?>
                                          readonly id="client_national"/>
                               </div>
                               <div class="col-xl-3 col-md-3 col-12" >
                                <div class="form-group" dir="rtl">
                                       <label class="form-label">ملاحظات  </label>
                                       <input type="text" name="notes"
                                              <?php if(isset($open_quotation) && !empty($open_quotation)): ?>
                                              value="<?php echo e($open_quotation->notes); ?>"
                                              <?php endif; ?> id="notes"
                                              class="form-control"/>
                                   </div>
                               </div>
                               <div class="clearfix"></div>
                           </div>

                     </div>
                            
                  <!-- Header ends -->
          
                  <hr class="invoice-spacing">
                  <div class="card-body invoice-padding pb-0 row">
                    <form onsubmit="return false;">
                    <div class="col-xl-3 col-md-3 col-12" >
                        <div class="mb-1" align="center">
                          <b  class="form-label" for="product_id" > كود المنتج او الاسم </b>

                        <select name="product_id" id="product_id" class="search">
                          </select>
                <div class="available text-center" style="color: #000; font-size: 14px; margin-top: 10px;"></div>
                        </div>
                     </div>

                     <div class="col-xl-3 col-md-3 col-12" >
                        <div class="mb-2" >
                            <b class="form-label" for="time" >السعر : </b>
                            <span id="priceType" style="display: none">
                          <input style="" type="radio" name="price" id="sector" checked /> قطاعى
                          <input style="" type="radio" name="price" id="wholesale"/> جملة
                            </span>
                          <input
                              <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->denies('تعديل السعر في عرض سعر البيع')): ?>
                              readonly
                              <?php endif; ?>
                              type="text" name="product_price" value="0" id="product_price" class="form-control"/>
                      </div>
                      
                        </div>

                        <div class="col-xl-3 col-md-3 col-12" >
                            <div class="mb-1 row" align="center">
                              <b class="form-label" for="time" >الكمية</b>
                              <input style="width: 50%;" type="number" name="quantity" id="quantity" min="1" value="1"
                              class="form-control "/>
                       <select style="width: 50%;" class="form-control unti" name="unit_id" id="unit_id">
                           <option value="">اختر الوحدة</option>
                           <?php $__currentLoopData = $units; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $unit): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                               <option data-name="<?php echo e($unit->unit_name); ?>" value="<?php echo e($unit->id); ?>"><?php echo e($unit->unit_name); ?></option>
                           <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                       </select>
                       <input type="hidden" value="0" id="product_unit_quantity" >
                          </div>
                            </div>

                            <div class="col-xl-2 col-md-2 col-12" >
                                <div class="mb-1" align="center">
                                  <b class="form-label" for="quantity_price"> الاجمالى</b>
                            <input readonly type="text" name="quantity_price" id="quantity_price" class="form-control"/>
                              </div>
                                </div>
                                <div class="col-xl-1 col-md-1 col-12" >
                                    <div class="mb-1 row" align="center">
                                      <b class="form-label" for="time" >م</b>
                                      <button type="button" id="addRow" class="btn btn-success"><i data-feather='plus'></i></button>
                                  </div>
                                    </div>
                                  </form>
                            </div>

                  <hr class="invoice-spacing">

                  <div class="card-body  bill_details" id="productsTable">
                    <?php $c=0 ?>  
                    <?php if($open_quotation): ?>       
                    <?php $__currentLoopData = $open_quotation->elements; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $element): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?> 

                    <div class="mb-3 invItem" data-repeater-list="group-a" id="row-<?php echo e(++$c); ?>">
                      <div class="repeater-wrapper pt-0 pt-md-4" data-repeater-item="">
                        <div class="d-flex border rounded position-relative pe-0">
                          <div class="row w-100 p-3">

                            <div class="col-md-2 col-12 mb-md-0 mb-3">
                              <p class="mb-2 repeater-title">المنتج</p>
                              <div id="productName_<?php echo e($c); ?>"><?php echo e($element->product->product_name); ?></div><input type="hidden" name="product[]" id="product_<?php echo e($c); ?>"  value="<?php echo e($element->product_id); ?>"  class="form-control product"  autocomplete="off" required>
                            </div>

                            <div class="col-md-2 col-12 mb-md-0 mb-3">
                              <p class="mb-2 repeater-title">الكمية</p>
                              <input class="form-control quantity" type="number" value="<?php echo e($element->quantity); ?>"  name="quantity[]"  id="quantity_<?php echo e($c); ?>" product="<?php echo e($element->product_id); ?>"  <?php if($element->product->is_product == 1): ?> <?php else: ?> max="999999" <?php endif; ?> min="0" step="any" >
                            </div>

                            <div class="col-md-2 col-12 mb-md-0 mb-3">
                              <p class="mb-2 repeater-title">الوحدة</p>
                              <?php echo e($element->unit->unit_name); ?><input type="hidden" name="unit[]" id="unit_<?php echo e($c); ?>"  value="<?php echo e($element->unit_id); ?>"  class="form-control unit"  autocomplete="off" required>
                              <input type="hidden" name="product_unit_quantity[]" id="product_unit_quantity_<?php echo e($c); ?>"  value="<?php echo e($element->elements_unit->quantity); ?>"  class="form-control unit"  autocomplete="off" required>
                            </div>

                            <div class="col-md-3 col-12 mb-md-0 mb-3">
                              <p class="mb-2 repeater-title">السعر</p>
                              
                              <input class="form-control" type="number" step="any" value="<?php echo e($element->product_price); ?>" name="price[]" id="price_<?php echo e($c); ?>" product="<?php echo e($element->product_id); ?>" min="0">
                            </div>

                            <div class="col-md-3 col-12 mb-md-0 mb-3">
                              <p class="mb-2 repeater-title">الإجمالي</p>
                              <input type="text" name="total[]" id="total_<?php echo e($c); ?>" class="form-control total" id="total_<?php echo e($c); ?>" value="<?php echo e($element->quantity_price); ?>" readonly required>
                            </div>

                        </div>

                        <div class="d-flex flex-column align-items-center justify-content-between border-start p-2">
                          <a class="delete" id="removeRows" data-unit="<?php echo e($element->unit_id); ?>" data-div="<?php echo e($c); ?>" data-product="<?php echo e($element->product_id); ?>" data-invoice="<?php echo e($open_quotation->quotation_number); ?>" ><i class="la la-trash" style="font-size:20px;color:red" ></i></a>
                        </div>
                      </div>
                    </div>
                  </div>

                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    <input id="elementCout" type="hidden" value="<?php echo e($open_quotation->elements->count()); ?>">
                    <?php endif; ?>
                  
                  </div>
          
         
          
                  <hr class="invoice-spacing mt-0" >
                  <div class="card-body invoice-padding-extra" <?php if(empty($element)): ?> style="display:none" <?php endif; ?> >
                    <div class="row invoice-sales-total-wrapper">
                      <div class="col-md-6 order-md-1 order-2 mt-md-0 mt-3">
                        <div class="d-flex align-items-center mb-1">
                          <b for="extra_type" class="form-label">&nbsp;  الشحن  &nbsp;</b> 
                          <select name="extra_type" id="extra_type" class="form-control"
                                  style="width: 30%;display: inline;float: right;margin-left: 5px">
                              <option <?php if(!empty($open_quotation) && !empty($open_quotation->extra->action_type) && $open_quotation->extra->action_type =='pound' ): ?> selected <?php endif; ?> value="pound"><?php echo e($extra_settings->currency); ?></option>
                              <option  <?php if(!empty($open_quotation) && !empty($open_quotation->extra->action_type) && $open_quotation->extra->action_type =='percent' ): ?> selected <?php endif; ?> value="percent">نسبة مئوية</option>
                          </select>
                          <input type="number" name="extra_value"min="0"
                                 style="width: 50%;display: inline;float: right;"
                                 id="extra_value" class="form-control" placeholder=" قيمة أو نسبة الشحن "  <?php if(!empty($open_quotation->extra)): ?> value="<?php echo e($open_quotation->extra->value); ?>" <?php endif; ?>/>
                 </div> 
                        <div class="d-flex align-items-center mb-1">
                            <b for="discount_type" class="form-label">&nbsp;  الخصم  &nbsp;</b> 
                            <select name="discount_type" id="discount_type" class="form-control"
                            style="width: 30%;display: inline;float: right;margin-left: 5px">
                        <option <?php if(!empty($open_quotation) && !empty($open_quotation->discount->action_type) && $open_quotation->discount->action_type =='pound' ): ?> selected <?php endif; ?> value="pound"><?php echo e($extra_settings->currency); ?></option>
                        <option <?php if(!empty($open_quotation) && !empty($open_quotation->discount->action_type) && $open_quotation->discount->action_type =='percent' ): ?> selected <?php endif; ?> value="percent">نسبة مئوية</option>
                    </select>
                    <input  type="number" name="discount_value"min="0"  <?php if(!empty($open_quotation) && !empty($open_quotation->discount)): ?> value="<?php echo e($open_quotation->discount->value); ?>" <?php endif; ?>
                           style="width: 50%;display: inline;float: right;"
                           id="discount_value" class="form-control" placeholder=" قيمة أو نسبة الخصم "/>
                          </div>
                      </div>
                      <div class="col-md-6 d-flex justify-content-end order-md-2 order-1">
                        <div class="invoice-calculations">
                          <div class="d-flex justify-content-between mb-2">
                            <p class="w-px-100">الإجمالي : </p>
                            <p class="fw-medium"><div id="subtotal">0</div></p>
                          </div>
                          <div id="taxAndTotalWithTax" <?php if(empty($company->tax_value_added)): ?>style="display: none"<?php endif; ?> >
                          <div class="d-flex justify-content-between mb-2">
                            <p class="w-px-100"> الضريبة : </p>
                            <p class="fw-medium"><div id="tax"><?php if(!empty($company->tax_value_added)): ?><?php echo e($company->tax_value_added); ?><?php else: ?> 0 <?php endif; ?></div>%</p>
                          </div>
                          <div class="d-flex justify-content-between mb-2">
                            <p class="w-px-100">الإجمالي بعد الضريبة : </p>
                            <p class="fw-medium"><div id="totalAfterTax">0</div></p>
                          </div>
                          </div>
                          <div class="d-flex justify-content-between mb-2">
                            <p class="w-px-100"> الشحن : </p>
                            <p class="fw-medium"><?php if(!empty($open_quotation->extra)): ?><div id="extra"><?php echo e($open_quotation->extra->value); ?></div> <div id="exType"><?php if($open_quotation->extra->action_type =='pound'): ?> <?php echo e($extra_settings->currency); ?> <?php else: ?> % <?php endif; ?></div><?php else: ?> <div id="extra">0</div><div id="exType"></div><?php endif; ?></p>
                          </div>
                          <div class="d-flex justify-content-between mb-2">
                            <p class="w-px-100"> الخصم : </p>
                            <p class="fw-medium"><?php if(!empty($open_quotation->discount)): ?> <div id="discount"><?php echo e($open_quotation->discount->value); ?></div> <div id="disType"><?php if($open_quotation->discount->action_type =='pound'): ?> <?php echo e($extra_settings->currency); ?>  <?php else: ?> % <?php endif; ?> </div><?php else: ?> <div id="discount">0</div><div id="disType"></div><?php endif; ?> </p>
                          </div>

                          <hr class="my-50">
                          <div class="d-flex justify-content-between mb-2">
                            <p class="w-px-100"> إجمالي العرض سعر : </p>
                            <p class="fw-medium"><div id="finalTotal"></div></p>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                 
                </div>
              </div>
              <!-- Invoice Add Left ends -->
          
              <!-- Invoice Add Right starts -->
              <div class="col-xl-3 col-md-4 col-12">
                <div class="card">
                  <div class="card-body">
                    <button class="btn btn-primary w-100 mb-75 waves-effect waves-float waves-light submit" id="saveAllWithOutPrint" type="submit"
                     <?php if(!isset($open_buy_bill) || empty($element) || empty($open_buy_bill)): ?> disabled <?php endif; ?>>
                        <?php if(isset($open_buy_bill) && !empty($open_buy_bill) && $open_buy_bill->status == 'done'): ?>
                        تحديث <i class="la la-check"></i>
                        <?php else: ?>
                        حفظ 
                        <?php endif; ?>
                        
                    </button>


                    <button class="btn btn-success w-100 mb-75 waves-effect waves-float waves-light submit" id="saveAll" type="submit"
                     <?php if(!isset($open_buy_bill) || empty($element) || empty($open_buy_bill)): ?> disabled <?php endif; ?>>
                        <?php if(isset($open_buy_bill) && !empty($open_buy_bill) && $open_buy_bill->status == 'done'): ?>
                        تحديث و طباعة
                        <?php else: ?>
                        حفظ و طباعة
                        <?php endif; ?>
                        
                    </button>
                 </form>
                    
                        <?php if(isset($open_quotation) && !empty($open_quotation)): ?>
                            <input type="hidden" value="<?php echo e($open_quotation->quotation_number); ?>" name="quotation_number"/>
                        <?php else: ?>
                            <input type="hidden" value="<?php echo e($pre_quotation); ?>" name="quotation_number"/>
                        <?php endif; ?>
                        <?php if(isset($open_quotation) && !empty($open_quotation) && $open_quotation->status == 'done'): ?>
                           <a href="<?php echo e(route('client.quotations.print',$open_quotation->quotation_number)); ?>"> <button class="btn btn-primary w-100 mb-75 waves-effect waves-float waves-light" id="viewInvoice" type="button">
                                عرض <i data-feather="eye"></i>
                            </button></a>
                            <button type="button" class="btn btn-outline-danger w-100 mb-75 waves-effect " onclick="window.history.back()"> رجوع  <i class="la la-arrow-left"></i></button>
                        <?php else: ?>
                        <form  method="post" action="<?php echo e(route('client.quotations.cancel')); ?>">
                            <?php echo csrf_field(); ?>
                         <?php if(isset($open_quotation) && !empty($open_quotation)): ?>
                            <input type="hidden" value="<?php echo e($open_quotation->quotation_number); ?>" name="quotation_number"/>
                        <?php else: ?>
                            <input type="hidden" value="<?php echo e($pre_quotation); ?>" name="quotation_number"/>
                        <?php endif; ?>                
                        <button  type="submit" id="cancel" <?php if(!isset($open_quotation) || empty($open_quotation)): ?> disabled <?php endif; ?>
                        
                        class="btn btn-outline-danger w-100 mb-75 waves-effect ">
                        الغاء وخروج
                        <i class="la la-arrow-left"></i>
                        </button>
                        
                    </form> 
                    <?php endif; ?>                 
                </div>
                </div>
            
              </div>
              <!-- Invoice Add Right ends -->
            </div>
          </section>
      </div>
    </div>
 </div>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('script'); ?>
<script src="<?php echo e(asset('app-assets/js/select2.min.js')); ?>"></script>
<script src="<?php echo e(asset('app-assets/js/pages/quotations.js')); ?>"></script>
<script>
    
        $('.search').select2();

</script>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('style'); ?>
<link href="<?php echo e(asset('app-assets/css/app-invoice.css')); ?>" rel="stylesheet" />
<?php $__env->stopSection(); ?>

<?php echo $__env->make('client.layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH E:\xampp\htdocs\sales\resources\views/client/quotations/create.blade.php ENDPATH**/ ?>