
<!-- Modal Add Supply Tank -->
<div class="modal fade" id="addTank" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg modal-simple modal-add-new-address">
      <div class="modal-content">
        <div class="modal-header">
            <h4 class="modal-title"><strong>توزيع كمية جديدة للخزانات</strong></h4>
        </div>
        <div class="modal-body">
            <form id="addNewAddressForm"  class="row g-3 fv-plugins-bootstrap5 fv-plugins-framework needs-validation"  novalidate="" method="POST" action="<?php echo e(route('distribution_quantity_to_tank')); ?>">
                <?php echo csrf_field(); ?>
                <div class="row">
                    <div class="col-md-6 mb-2">
                            <label class="form-label" for="validationCustom01">اسم الموظف<span class="text-danger">*</span>
                            </label>
                                <select class="form-control form-white" data-placeholder="Choose a color..." name="employeeId" required>
                                    <option disabled="disabled" selected value="">الرجاء تحديد الموظف المستلم للكمية</option>
                                    <?php $__currentLoopData = $employees; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $employee): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <?php if($employee->user->role==3): ?>
                                    <option value="<?php echo e($employee->user->id); ?>"><?php echo e($employee->user->name); ?></option>
                                    <?php endif; ?>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                                <div class="invalid-feedback">
                                   يرجاء تحديد اسم الموظف المستلم
                                </div>
                                <?php $__errorArgs = ['employeeId'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                    <div class="text-danger px-2 showModalAdd ">
                                    <?php echo e($message); ?>

                                    </div>
                                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                        </div>

                        <div class="col-md-6 mb-2">
                            <label class="form-label" for="validationCustom05">الخزان
                                <span class="text-danger">*</span>
                            </label>
                                <select class="form-control form-white" data-placeholder="Choose a color..." name="tankId" required>
                                    <option value="" selected disabled>اختر احدى الخزانات</option>
                                    <?php $__currentLoopData = $tanks; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $tank): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                 
                                    <option value="<?php echo e($tank->id); ?>">  الخزان رقم.<?php echo e($tank->id); ?>

                                        <?php if($tank->type==0): ?>
                                        ( بترول ) -
                                    <?php else: ?>
                                        ( ديزل ) -
                                    <?php endif; ?>
                                         المساحة الغارغة <?php echo e($tank->capacity - $tank->quantity); ?> لتر
                                    </option>

                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                                <div class="invalid-feedback">
                                    يرجاء تحديد احدى الخزانات
                                </div>
                                <?php $__errorArgs = ['tankId'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                    <div class="text-danger px-2 showModalAdd ">
                                    <?php echo e($message); ?>

                                    </div>
                                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>

                        </div>

                    <div class="col-md-6 mb-2">
                            <label class="form-label" for="validationCustom05">التوريدة الموزع منها
                                <span class="text-danger">*</span>
                            </label>
                            <select class="form-control form-white" data-placeholder="Choose a color..." name="supplyId" required>
                                <option disabled selected value="">الرجاء اختيار احدى التوريدات</option>
                                <?php $__currentLoopData = $supplies; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $supply): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <?php
                                     $summiton = 0;
                                        foreach ($storeQuantities as $storeQuanty) {
                                            if($storeQuanty->supply_id==$supply->id)
                                              {$summiton+=$storeQuanty->quantity;}
                                        }
                                        $empty = $supply->quantity - $summiton;
                                    ?>
                                <?php if($empty>1): ?>
                                <option value="<?php echo e($supply->id); ?>"><?php echo e($supply->notice); ?> الكمية <?php echo e($empty); ?></option>
                               <?php endif; ?>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </select>
                            <div class="invalid-feedback">
                                يرجاء اختيار احد التوريدات
                            </div>
                            <?php $__errorArgs = ['supplyId'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                <div class="text-danger px-2 showModalAdd ">
                                <?php echo e($message); ?>

                                </div>
                            <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                        </div>
                        <div class="col-md-6">
                            <label class="form-label" for="validationCustom06">الكمية
                                <span class="text-danger">*</span>
                            </label>
                            <div class="col-lg-12">
                                <input name="quantity" value="<?php echo e(old('quantity')); ?>" type="number" class="form-control" id="validationCustom06" placeholder="ادخل الكمية.." required="" required="">
                                <div class="invalid-feedback">
                                    يرجاء ادخل الكمية بشكل صحيح
                                </div>
                                <?php $__errorArgs = ['quantity'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                    <div class="text-danger px-2 showModalAdd ">
                                    <?php echo e($message); ?>

                                    </div>
                                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                            </div>
                        </div>

                    </div>
                    <div class="modal-footer">
                        <button type="submit" class="btn btn-primary me-sm-3 me-1">اضافة</button>
                        <button type="reset" class="btn btn-label-secondary" data-bs-dismiss="modal" aria-label="Close">الغاء</button>
                      </div>
                      <input type="hidden">
            </form>
                  </div>
              </div>
            </div>
</div>

 
 <div class="modal fade" id="editModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="modalEdit" aria-hidden="true">
    <div class="modal-dialog modal-lg modal-simple modal-add-new-address">
        <div class="modal-content">
            <div class="modal-body">
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                <div class="text-center mb-4">
                <h3 class="address-title">التعديل على التوزيع للخزان</h3>
                <p class="address-subtitle">الرجاء التحقق من جميع الحقول</p>
            </div>
            <form id="addNewAddressForm"  class="row g-3 fv-plugins-bootstrap5 fv-plugins-framework needs-validation"  novalidate="" method="POST" action="<?php echo e(route('update_quantity_to_tank')); ?>">
                <?php echo csrf_field(); ?>
                <div class="row">
                    <div class="col-xl-6">
                        <div class="mb-3 row">
                            <label class="col-lg-12 col-form-label" for="validationCustom01">اسم الموظف<span class="text-danger">*</span>
                            </label>
                            <div class="col-lg-12">
                                <select class="form-control  form-white" id="employ_name" data-placeholder="Choose a color..." name="employeeId" required>
                                    <option disabled="disabled" selected value="">الرجاء تحديد الموظف المستلم لكمية</option>
                                    <?php $__currentLoopData = $employees; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $employee): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <?php if($employee->user->role==3): ?>
                                    <option value="<?php echo e($employee->user->id); ?>"><?php echo e($employee->user->name); ?></option>
                                    <?php endif; ?>                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                                <div class="invalid-feedback">
                                   يرجاء تحديد اسم الموظف المستلم
                                </div>
                                <?php $__errorArgs = ['employeeId'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                    <div class="text-danger px-2 showModalEdit ">
                                    <?php echo e($message); ?>

                                    </div>
                                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                            </div>
                        </div>
                        <div class="mb-3 row">
                            <label class="col-lg-12 col-form-label" for="validationCustom05">الخزان
                                <span class="text-danger">*</span>
                            </label>
                            <div class="col-lg-12">
                                <select id="tank_id" class="form-control form-white" data-placeholder="Choose a color..." name="tankId" required>
                                    <option value="" selected disabled>اختر احدى الخزانات</option>
                                    <?php $__currentLoopData = $tanks; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $tank): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <?php if($tank->is_active==1): ?>
                                    <option value="<?php echo e($tank->id); ?>">  الخزان رقم.<?php echo e($tank->id); ?>

                                        <?php if($tank->type==0): ?>
                                        ( بترول ) -
                                    <?php else: ?>
                                        ( ديزل ) -
                                    <?php endif; ?>
                                         المساحة الغارغة <?php echo e($tank->capacity - $tank->quantity); ?> لتر
                                    </option>
                                    <?php endif; ?>

                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                                <div class="invalid-feedback">
                                    يرجاء تحديد احدى الخزانات
                                </div>
                                <?php $__errorArgs = ['tankId'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                    <div class="text-danger px-2 showModalEdit ">
                                    <?php echo e($message); ?>

                                    </div>
                                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                             </div>
                        </div>
                    </div>

                    <div class="col-xl-6">
                        <div class="mb-3 row">
                            <label class="col-lg-12 col-form-label" for="validationCustom05">التوريدة الموزع منها
                                <span class="text-danger">*</span>
                            </label>
                            <select id="supplyId" class="form-control form-white" data-placeholder="Choose a color..." name="supplyId" required>
                                <option disabled selected value="">الرجاء اختيار احدى التوريدات</option>
                                <?php $__currentLoopData = $supplies; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $supply): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <?php
                                     $summiton = 0;
                                        foreach ($storeQuantities as $storeQuanty) {
                                            if($storeQuanty->supply_id==$supply->id)
                                              {$summiton+=$storeQuanty->quantity;}
                                        }
                                        $empty = $supply->quantity - $summiton;
                                    ?> 
                                
                                <option value="<?php echo e($supply->id); ?>" ><?php echo e($supply->notice); ?>  المتبقي  <?php echo e($empty); ?> لتر</option>
                             
                            
                         <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </select>
                            <div class="invalid-feedback">
                                يرجاء اختيار احد التوريدات
                            </div>
                            <?php $__errorArgs = ['supplyId'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                    <div class="text-danger px-2 showModalEdit ">
                                    <?php echo e($message); ?>

                                    </div>
                            <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                        </div>
                        <div class="mb-3 row">
                            <label class="col-lg-12 col-form-label" for="validationCustom06">الكمية
                                <span class="text-danger">*</span>
                            </label>
                            <div class="col-lg-12">
                                <input name="quantity" type="number" class="form-control" id="quantity" placeholder="ادخل الكمية.." required="" required="">
                                <div class="invalid-feedback">
                                    يرجاء ادخل الكمية بشكل صحيح
                                </div>
                                <?php $__errorArgs = ['quantity'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                    <div class="text-danger px-2 showModalEdit ">
                                    <?php echo e($message); ?>

                                    </div>
                                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                            </div>
                        </div>
                        </div>
                    </div>
                    <div class="col-12 text-center">
                        <button type="submit" class="btn btn-primary me-sm-3 me-1">تعديل</button>
                        <button type="reset" class="btn btn-label-secondary" data-bs-dismiss="modal" aria-label="Close">الغاء</button>
                      </div>
                      <input type="hidden" id="id" name="id">
            </form>
            </div>
            </div>
        </div>
    </div>
</div>


<div class="modal fade" id="toggleModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="toggleModal" aria-hidden="true">
    <div class="modal-dialog modal-lg modal-simple modal-add-new-address">
    <div class="modal-content">
        <div class="modal-body">
            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            <div class="text-center mb-4">
            <h3 class="address-title"> ايقاف توزيع هذه الكمية </h3>
            <p class="address-subtitle text-danger">هل انت متأكد من ايقاف هذه الكمية</p>
            </div>
            <form id="addNewAddressForm" method="GET" action="<?php echo e(route('toggle_quantity_to_tank')); ?>" class="row g-3 fv-plugins-bootstrap5 fv-plugins-framework needs-validation" novalidate="">
                <?php echo csrf_field(); ?>
                <input type="hidden" name="id" id="id_toggle">
                <div class="col-12 text-center">
                    <button type="submit" class="btn btn-danger me-sm-3 me-1 ">نعم</button>
                    <button type="reset" class="btn btn-label-secondary" data-bs-dismiss="modal" aria-label="Close">الغاء</button>
                </div>
            </form>
        </div>
    </div>
    </div>
</div>






<?php $__env->startSection('script'); ?>
<script>
//edit modal
const edit =document.querySelectorAll('.edit');
document.querySelectorAll('.edit').forEach(item => {
        item.addEventListener('click', e => {
        document.getElementById("id").value =item.dataset.id;
        document.getElementById("quantity").value =item.dataset.quantity;
       const selectEmploy= document.querySelector("#employ_name");
       const selectTankId = document.querySelector("#tank_id");
       const selectSupply = document.querySelector("#supplyId");
       console.log(item.dataset.supply_id);
       for(var i=0; i < selectEmploy.options.length; i++)
       {
            if(selectEmploy.options[i].text === item.dataset.employ)
            {
                selectEmploy.selectedIndex = i;
                console.log(item.dataset.employ);
                console.log(selectEmploy.options[i].text);
                break;
            }
       }
       for(var i=0; i < selectSupply.options.length; i++)
       {
            if(selectSupply.options[i].value === item.dataset.supply_id)
            {
                selectSupply.selectedIndex = i;
                console.log(item.dataset.supply_id);
                console.log(selectSupply.options[i].text);
                break;
            }
       }
       for(var i=0; i < selectTankId.options.length; i++)
       {
        console.log(selectTankId.options[i].value);
        // console.log(item.dataset.supply_id);

            if(selectTankId.options[i].value === item.dataset.tank_id)
            {
                selectTankId.selectedIndex = i;
                // console.log(item.dataset.employ);
                console.log(selectTankId.options[i].value);
                break;
            }
       }
        $('#editModal').modal('show');
    })
})

//toggle modal
const toggle =document.querySelectorAll('.toggle');
document.querySelectorAll('.toggle').forEach(item => {
        item.addEventListener('click', e => {
        console.log(item.dataset.id);
        const id = item.dataset.id;
        document.getElementById("id_toggle").value =item.dataset.id;
        $('#toggleModal').modal('show');
    })
})
</script>
<script>
    $(document).ready(function () {
    $('table.display').DataTable();
});
</script>
<?php /**PATH C:\Users\Nasser\Desktop\petrol_store\resources\views/supply/modalsTank.blade.php ENDPATH**/ ?>