<?php $__env->startSection('title','تعديل مورد'); ?>
<?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">تعديل مورد</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.suppliers.index')); ?>">الموردين</a>
                  </li>
                  <li class="breadcrumb-item active"><?php echo e($supplier->supplier_name); ?>

                </li>
                  <li class="breadcrumb-item active">تعديل
                  </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.suppliers.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 id="multiple-column-form">
<div class="row">
  <div class="col-12">
    <div class="card">
      <div class="card-header">
        <h4 class="card-title">البيانات الاساسية</h4>
      </div>
      <div class="card-body">
        <form class="form" id="addForm" action="#">
            <input type="hidden" name="company_id" value="<?php echo e($company_id); ?>">
            <input type="hidden" name="id" value="<?php echo e($supplier->id); ?>">

            <?php echo csrf_field(); ?>
          <div class=" row">

            <div class="col-xl-6 col-md-6 col-12" >

            <div class="col-6 md-6 col-12">
              <div class="mb-1">
                <b class="form-label" for="supplier_name">اسم المورد</b>

                <input
                  type="text"
                  id="supplier_name"
                  class="form-control"
                  placeholder="اسم المورد"
                  name="supplier_name"
                  value="<?php echo e($supplier->supplier_name); ?>"
                />
                
              </div>
            </div>
            
            <div class="col-6 md-6 col-12">
                <div class="mb-1">
                  <b class="form-label" for="notes">ملاحظات المورد 
                    <a type="button" id="add_note" 
                    style=" float: left">إضافة
                    <i data-feather='plus'></i>
                  </a></b>
                  <?php if($supplier->notes->isEmpty()): ?>
                  <input type="text" name="notes[]" class="form-control"
                  style="width:90%; display: inline; float: right;" placeholder="ملاحظات المورد">

                    <?php else: ?>
                    <?php $__currentLoopData = $supplier->notes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $note): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?> 
                    <div>
                        <input type='text' class='form-control note' name='notes[]'  style='margin :5px 0;width:90%;display:inline;float:right;' value="<?php echo e($note->supplier_note); ?>" placeholder="ملاحظات المورد" /> 
                        <button type='button' class='btn btn-md btn-danger delete_note' style="width:7%;height: 35px;display: inline; float: left;padding: 5px; margin-top: 10px">
                            <i class="la la-trash"></i>
                        </button>
                        <div class='clearfix'></div>
                        </div>

                          <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    <?php endif; ?>

                    <div class="dom2"></div>

                </div>
              </div>
               
            </div>

            <div class="col-xl-6 col-md-6 col-12 " >
        
             <div class="col-xl-12 col-md-12 col-12 row" >
          
            <div class="col-md-6 col-12">
              <div class="mb-1">
                <b class="form-label" for="prev_balance">المديونية :  </b>
                <input  type="radio" value="for" name="balance" <?php if($supplier->prev_balance < 0): ?> checked <?php endif; ?>  /> له
                <input   type="radio" value="on" name="balance"<?php if($supplier->prev_balance >= 0): ?> checked <?php endif; ?> /> عليه
                <input  type="text"  name="prev_balance" class="form-control" placeholder="مديونية المورد"  value="<?php echo e(abs($supplier->prev_balance)); ?>">
                 </div>
            </div>

            <div class="col-md-6 col-12">
                <div class="mb-1">
                    <b class="form-label" for="phone">رقم الهاتف    
                        <a type="button" id="add_phone" 
                        style=" float: left">إضافة
                        <i data-feather='plus'></i>
                    </a></b>
                                    <?php if($supplier->phones->isEmpty()): ?>
                <input type="text" name="phones[]" class="form-control"
               style="width:80%; display: inline; float: right;" placeholder="رقم الهاتف بمفتاح الدولة">

                  <?php else: ?>
                  <?php $__currentLoopData = $supplier->phones; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $phone): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?> 
                  <div>
                  <input type="text" name="phones[]" class="form-control" value="<?php echo e($phone->supplier_phone); ?>"
                  style="width:80%; display: inline; float: right;" placeholder="رقم الهاتف بمفتاح الدولة">
                  <button type="button" class="btn btn-danger btn-sm delete_phone" style="width:15%;height: 30px;display: inline; float: left;padding: 5px; margin-top: 10px"><i style="" class="la la-trash"></i></button>
                 </button>
                    <div class='clearfix'></div></div>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                  <?php endif; ?>              
                            <div class="dom1"></div>
                </div>
            </div>

        

            </div>

            <div class="col-6 md-6 col-12">
                <div class="mb-1">
                    <b class="form-label" for="address"> عنوان المورد 
                               <a type="button" id="add_address" 
                        style=" float: left">إضافة
                        <i data-feather='plus'></i>
                    </a></b>

                  
                        <?php if($supplier->addresses->isEmpty()): ?>
                        <input type="text" name="addresses[]" class="form-control"
                        placeholder="عنوان المورد "
                           style="width:90%; display: inline; float: right;">
      
                          <?php else: ?>
                          <?php $__currentLoopData = $supplier->addresses; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $address): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?> 
                          <div>
                              <input type='text' class='form-control ' name='addresses[]'  style='margin :5px 0;width:90%;display:inline;float:right;' value="<?php echo e($address->supplier_address); ?>" placeholder="عنوان المورد "
                              style="width:90%; display: inline; float: right;"/> 
                              <button type='button' class='btn btn-md btn-danger delete_address' style="width:7%;height: 35px;display: inline; float: left;padding: 5px; margin-top: 10px">
                                  <i class="la la-trash"></i>
                              </button>
                              <div class='clearfix'></div>
                              </div>
      
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                          <?php endif; ?>

                    <div class="dom3"></div>

                </div>
              </div>
              
            </div>
        </div>
<br>

        <div class="clearfix"></div>
        <center>
        <a href="javascript:;" class="btn btn-link open_extras">
            <i class="fa fa-plus"></i>
            خيارات اضافية
        </a>
        </center>
        <div class="clearfix"></div>
        <div class="extras row" style="display: none">


               <div class="col-md-4 col-12" >
                    <div class="mb-1">
                    <b class="form-label" for="supplier_category">فئة التعامل</b>
                    <select name="supplier_category" class="form-control" required>
                        <option value="">اختر الفئة</option>
                        <option
                            <?php if($supplier->supplier_category == "جملة"): ?>
                            selected
                            <?php endif; ?>
                            value="جملة">جملة
                        </option>
                        <option
                            <?php if($supplier->supplier_category == "قطاعى"): ?>
                            selected
                            <?php endif; ?>
                            value="قطاعى">قطاعى
                        </option>
                    </select>
                    </div>
                </div>

                <div class="col-md-4 col-12" >
                      <div class="mb-1">
                    <b class="form-label" for="supplier_email">البريد الالكترونى</b>
                    <input type="email" name="supplier_email"  placeholder="البريد الالكترونى" value="<?php echo e($supplier->supplier_email); ?>" class="form-control" >
                    
                      </div>
                </div>


                <div class="col-md-4 col-12" >
                  <div class="mb-1">
                    <b class="form-label" >اسم محل / شركة المورد</b>
                    <input type="text" name="shop_name" placeholder="اسم محل / شركة المورد" value="<?php echo e($supplier->shop_name); ?>" class="form-control" >
                           
                  </div>
                </div>

                <div class="col-md-4 col-12" >
                  <div class="mb-1">
                    <b class="form-label" for="supplier_national">جنسية المورد</b>
                    <select name="supplier_national" class="form-control">
                        <option value="">اختر دولة</option>
                        <?php $__currentLoopData = $timezones; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $timezone): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option
                            <?php if($supplier->supplier_national == $timezone->country_name): ?>
                            selected
                            <?php endif; ?>
                            value="<?php echo e($timezone->country_name); ?>"><?php echo e($timezone->country_name); ?></option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                  </div>
                </div>

                <div class="col-md-4 col-12" >
                  <div class="mb-1">
                    <b class="form-label" for="tax_number">الرقم الضريبى</b>
                    <input type="text" name="tax_number"
                           class="form-control"  placeholder="الرقم الضريبى" value="<?php echo e($supplier->tax_number); ?>" >
                </div>
                </div>
                <div class="clearfix"></div>

           
        </div>


            <div class="col-12" align="center">
            <br>
              <button type="submit" class="btn btn-success me-1">تعديل</button>
              <button type="button" class="btn btn-outline-danger" onclick="window.history.back()">رجوع</button>
            </div>
          </div>
          
        </form>
      </div>
    </div>
  </div>
</div>
</section>
<!-- Basic Floating Label Form section end -->

      </div>
    </div>
  </div>
  <!-- END: Content-->
<?php $__env->stopSection(); ?>
<?php $__env->startSection('script'); ?>

    <script>
        $('.delete_phone').on('click', function () {
            $(this).parent().remove();
        });
        $('#add_phone').on("click", function () {
            $('<div><input autofocus type="text" name="phones[]" class="form-control" dir="ltr" style="margin:10px 0; display:inline;float:right;width:80%" placeholder="رقم الهاتف بمفتاح الدولة" />' +
                '<button type="button" class="btn btn-danger btn-sm delete_phone" style="width:15%;height: 30px;display: inline; float: left;padding: 5px; margin-top: 10px"><i style="" class="la la-trash"></i></button>' +
                '<div class="clearfix"></div></div>').insertBefore('.dom1');
            $('.delete_phone').on('click', function () {
                $(this).parent().remove();
            });
        });
        $('.delete_note').on('click', function () {
            $(this).parent().remove();
        });
        $('#add_note').on("click", function () {
            $('<div><input autofocus type="text" name="notes[]" class="form-control" dir="rtl" style="margin:10px 0; display:inline;float:right;width:90%" placeholder="ملاحظات المورد" />' +
                '<button type="button" class="btn btn-danger btn-sm delete_note" style="width:7%;height: 35px;display: inline; float: left;padding: 5px; margin-top: 10px"><i style="" class="la la-trash"></i></button>' +
                '<div class="clearfix"></div></div>').insertBefore('.dom2');
            $('.delete_note').on('click', function () {
                $(this).parent().remove();
            });
        });

        $('.delete_address').on('click', function () {
            $(this).parent().remove();
        });
        $('#add_address').on("click", function () {
            $('<div><input autofocus type="text" name="addresses[]" class="form-control" dir="rtl" style="margin:10px 0; display:inline;float:right;width:90%"placeholder="عنوان المورد "  />' +
                '<button type="button" class="btn btn-danger btn-sm delete_address" style="width:7%;height: 35px;display: inline; float: left;padding: 5px; margin-top: 10px"><i style="" class="la la-trash"></i></button>' +
                '<div class="clearfix"></div></div>').insertBefore('.dom3');
            $('.delete_address').on('click', function () {
                $(this).parent().remove();
            });
        });

        $('.open_extras').on('click',function () {
            $('.extras').fadeIn(300);
            $(this).fadeOut(300);
        });

        
        var selectForm = $('#addForm');

if (selectForm) {
    selectForm.validate({

        rules: {
      'supplier_name': {
        required: true,
      },
      'supplier_category': {
        required: true
      },
      'prev_balance': {
        required: true
      },'supplier_email': {
        email: true
      }
        
          
    
    }
  });
}


$("#addForm").on('submit',(function(e) {

e.preventDefault();

$.ajax({

  url: "<?php echo e(route('client.suppliers.update')); ?>",

  type: "POST",

  data:  new FormData(this),

  dataType:  'json',

  contentType: false,

  cache: false,

  processData:false,

  beforeSend : function (){var ifConnected = window.navigator.onLine;if (!ifConnected) {toastr.info("يتم الآن إعادة الإتصال","لا يوجد إتصال بالإنترنت",{positionClass: "toast-top-right",tapToDismiss: !1,timeOut: 2e3,rtl: $("html").attr("data-textdirection")});}},


  success: function(response) {

    if(response.status){

            toastr.success("",response.message,{
			positionClass: "toast-top-right",
			tapToDismiss: !1,
			timeOut: 2e3,
			rtl: $("html").attr("data-textdirection")
		    });      

    } 

  },
  error: function(response){
          $.each(response.responseJSON.errors, function (key, item) 
          {
            toastr.error("",item,{
			positionClass: "toast-top-right",
			tapToDismiss: !1,
			timeOut: 2e3,
			rtl: $("html").attr("data-textdirection")
		    });

          });
  },

 });

}));

        </script>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('style'); ?>
<style>
    .btn.dropdown-toggle.bs-placeholder {
        height: 40px;
    }
</style>
<?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/suppliers/edit.blade.php ENDPATH**/ ?>