
<?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.products.index')); ?>">المنتجات</a>
                  </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.products.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-xl-12 col-md-12 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="is_product" id="is_product" value="1">


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


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

                <div class="col-md-6 col-12" >
                  <div class="mb-1">
                <b class="form-label" for="store_id"> الفئة</b>

                <select name="category_id" id="category" class="form-control" >
                  <option value="">اختر الفئة</option>
                      <?php $__currentLoopData = $categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index=>$category): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                              <option type="<?php echo e($category->category_type); ?>" <?php if($index==0): ?> selected <?php endif; ?>
                                      value="<?php echo e($category->id); ?>">
                                  <?php echo e($category->category_name); ?>

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

              </select>

                </div>
                </div>

                <div class="col-md-6 col-12 " >
                  <div class="mb-1">
                    <b class="form-label" for="store_id">الكود العالمى </b>
                    <input type="text" class="form-control"  placeholder="الكود العالمى" style="width:80%; display: inline; float: right;"
                           id="order_universal" name="code_universal" />
                           <button type="button" id="generate_code_universal" class="btn btn-md btn-primary"
                            style="width:15%;height: 45px;display: inline; float: left;padding: 5px;">
                            <i class="las la-magic" style="font-size : 20px"></i>
                            توليد
                        </button>

                    </div>
                </div>

                <div class="col-md-6 col-12 " >
                  <div class="mb-1">
                    <b class="form-label" for="store_id">اسم المنتج</b>
                    <input type="text" name="product_name" id="order_name" class="form-control" placeholder="اسم المنتج"  autofocus>

                    </div>
                </div>
                <div class="col-md-6 col-12 " >
                  <div class="mb-1">
                    <b class="form-label" for="unit_id">الوحدة</b>
                    <select  name="unit_id" class="form-control" id="unit_id">
                    <option value="">اختر وحدة</option>
                    <?php $__currentLoopData = $units; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $unit): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($unit->id); ?>"><?php echo e($unit->unit_name); ?></option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select>
                    </div>
                </div>

            </div>
          </div>

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

                <div class="col-md-6 col-12">
                    <div class="mb-1">
                    <b for="first_balance">رصيد المخازن</b>
                    <input   type="text" name="first_balance" id="first_balance"
                           class="form-control " placeholder="رصيد المخازن" >
                    </div>
                </div>
                  <div class="col-md-6 col-12" >

                    <div class="mb-1">
                    <b for="purchasing_price">سعر التكلفة</b>
                    <input  type="text" name="purchasing_price" id='purchasing_price'
                           class="form-control "  placeholder="سعر التكلفة" >
                    </div>
                </div>
                <div class="clearfix"></div>
                <div class=" col-md-4 col-12" >
                    <div class="mb-1">
                    <b for="wholesale_price">سعر الجملة</b>
                    <input  type="text" name="wholesale_price" id="wholesale_price"
                           class="form-control " placeholder="سعر الجملة" 
                           >
                    </div>
                </div>
                <div class="col-md-4 col-12">
                    <div class="mb-1">
                    <b for="sector_price">سعر القطاعى</b>
                    <input  type="text"  name="sector_price" id="sector_price" placeholder="سعر القطاعى"
                           class="form-control ">
                    </div>
                </div>
                <div class="col-md-4 col-12">
                    <div class="mb-1">
                    <b for="min_balance"> حد أدنى المخازن</b>
                    <input   type="text" name="min_balance" id="min_balance" placeholder="رصيد حد أدنى المخازن"
                           class="form-control "
                           />
                    </div>
                </div>

            </div>
          </div>


            <div class="clearfix"></div>
            <a href="javascript:;" class="btn btn-link open_extras">
                خيارات إضافية
            </a>

            <div class="extras row" style="display: none;">
              <div class="col-xl-12 col-md-12 col-12 row">
                
                <div class="col-md-3 col-12">
                  <div class="mb-1">
                    <label for="model"> موديل المنتج</label>
                    <input type="text" name="product_model"
                           class="form-control text-right" id='model'>
                  </div>
                </div>

                <div class="col-md-3 col-12">
                  <div class="mb-1">
                    <label for="category"> المخزن</label>
                    <select   name="store_id" id="store" class="form-control">
                      <option value="">اختر المخزن</option>
                          <?php $i = 0; ?>
                              <?php $__currentLoopData = $stores; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $store): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                   <?php if($stores->count() == 1): ?>
                                        <option selected value="<?php echo e($store->id); ?>"><?php echo e($store->store_name); ?></option>
                                       <?php else: ?>
                                        <?php if($i ==  0): ?>
                                       <option selected value="<?php echo e($store->id); ?>"><?php echo e($store->store_name); ?></option>
                                        <?php else: ?>
                                         <option value="<?php echo e($store->id); ?>"><?php echo e($store->store_name); ?></option>
                                        <?php endif; ?>
                                      <?php endif; ?>
                                   <?php $i++; ?>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                          </select>
                </div>
              </div>

                <div class="col-md-3 col-12">
                  <div class="mb-1">
                    <label for="size"> مقاس </label>
                    <select data-live-search="true" data-style="btn-primary" name="sizes[]"
                            class="form-control show-tick selectpicker" id="basic" multiple
                            title="اختر مقاس">
                            <?php $__currentLoopData = $sizes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $size): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($size->id); ?>"><?php echo e($size->size); ?></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                    </div>
                </div>

                <div class="col-md-3 col-12">
                  <div class="mb-1">
                    <label for="color"> لون </label>
                    <select data-live-search="true" data-style="btn-warning" name="colors[]"
                            class="form-control show-tick selectpicker" style="height: 50px" id="basic"
                            multiple
                            title="اختر لون">
                            <?php $__currentLoopData = $colors; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $color): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($color->id); ?>"><?php echo e($color->color); ?></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                  </div>
                </div>
                <div class="clearfix"></div>

                <div class="col-md-3 col-12">
                  <div class="mb-1">
                    <label for="description">وصف المنتج</label>
                    <input type="text" name="description" id="description" class="form-control text-right"
                            />
                  </div>
                </div>
                <div class="col-md-3 col-12">
                  <div class="mb-1">
                    <label for=""> اختر صورة لرفعها </label>
                    <input accept=".jpg,.png,.jpeg" type="file"
                           oninput="pic.src=window.URL.createObjectURL(this.files[0])" id="file"
                           name="product_pic" class="form-control">
                  </div>
                  <div class="mb-1">

                    <label for="" class="d-block mt-2"> معاينة الصورة </label>
                    <img id="pic" src=""
                         style="width: 100px; height:100px;"/>

                </div>
              </div>
                <div class="clearfix"></div>


            </div>
            </div>
            </div>
            
            <div class="clearfix"></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>
        </div>
        </section>

<?php $__env->stopSection(); ?>
<?php $__env->startSection('script'); ?>
<script>
      $('#generate_code_universal').on('click',function(){
         var code = Math.floor(100000000 + Math.random() * 9999999999);
          $('#order_universal').val(code);

    });


    $('#category').on('change', function () {
        var category_name = $(this).val();
        var category_type = $(this).children("option:selected").attr('type');
        if (category_type == 'خدمية') {
            $('#first_balance').val("").attr('disabled', true);
            $('#model').val("").attr('disabled', true);
            // $('#order_universal').val("").attr('readonly', true);
            $('#min_balance').attr('disabled', true);
            $('#store').attr('disabled', true);
            $('#unit_id').attr('disabled', true);
            $('select[name="colors[]"]').attr('disabled', true);
            $('select[name="sizes[]"]').attr('disabled', true);
            $('#is_product').val("0");
            $('#purchasing_price').val("0");
            $('#wholesale_price').val("0");
            $('#purchasing_price').attr("readonly", true);
            $('#wholesale_price').attr("readonly", true);



        } else {
          $('#unit_id').attr('disabled', false);
            $('#first_balance').attr('disabled', false);
            $('#model').attr('disabled', false);
            // $('#order_universal').attr('readonly', false);
            $('#min_balance').attr('disabled', false);
            $('#store').attr('disabled', false);
            $('select[name="colors[]"]').attr('disabled', false);
            $('select[name="sizes[]"]').attr('disabled', false);
            $('#is_product').val(1);
            $('#purchasing_price').val("");
            $('#wholesale_price').val("");
            $('#purchasing_price').attr("readonly", false);
            $('#wholesale_price').attr("readonly", false);
        }
    });
    
    $('.open_extras').on('click',function () {
        $('.extras').fadeIn(300);
        $(this).hide(300);
    });
    
  
var selectForm = $('#addForm');

if (selectForm) {
    selectForm.validate({

    rules: {
      'store_id': {
        required: true,
      },
      'product_name': {
        required: true
      },
      'unit_id': {
        required: true
      },
      'first_balance': {
        required: true,
        number: true
      },
      'purchasing_price': {
        required: true,
        number: true
      },
      'wholesale_price': {
        required: true,
        number: true
      },
      'sector_price': {
        required: true,
        number: true
      },
      'min_balance': {
        required: true,
        number: true
      },
      'category_id': {
        required: true
      }

      
    }
  });
}

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

e.preventDefault();

$.ajax({

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

  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")
		    });      

    } 
    document.getElementById("addForm").reset();

  },
  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;
    }
    .bootstrap-select{
        width: 80% !important;
    }
    .form-control{
        height: 45px !important;
        padding: 10px !important;
    }

</style>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('client.layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/barasys/public_html/resources/views/client/products/create.blade.php ENDPATH**/ ?>