<?php $__env->startSection('content'); ?>

<?php
use App\Models\AccountsDefaultData;
$Def=AccountsDefaultData::orderBy('id','desc')->first();
?>

     <title><?php echo e(trans('admin.AddBorrow')); ?></title>

<main id="js-page-content" role="main" class="page-content">
                    <ol class="breadcrumb page-breadcrumb">
                        <li class="breadcrumb-item"><a href="javascript:void(0);"><?php echo e(trans('admin.HR')); ?> </a></li>
                        <li class="breadcrumb-item active"><?php echo e(trans('admin.AddBorrow')); ?>  </li>
                        <li class="position-absolute pos-top pos-right d-none d-sm-block"><span
                                class="js-get-date"></span></li>
                    </ol>

                    <form action="<?php echo e(url('PostAddBorrow')); ?>" method="post">
                         <?php echo csrf_field(); ?>

                              <?php echo view('honeypot::honeypotFormFields'); ?>
                            <div class="row">
                                    <div class="col-xl-12">
                                        <div  class="panel">
                                            <div class="panel-container show">
                                                 <span id="ex"> <?php echo $__env->make('admin.layouts.messages', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?></span>
                                                <div class="panel-content">
                                                    <div class="modal-header">
                                                        <h5 class="modal-title"><?php echo e(trans('admin.AddBorrow')); ?>  </h5>
                                                    </div>
                                                    <div class="panel-container show">
                                                        <div class="panel-content">
                                        <div class="form-row">
                                      <div class="form-group col-lg-3">
                                            <label class="form-label" for="simpleinput"><?php echo e(trans('admin.Code')); ?> </label>
                                            <input type="text" value="<?php echo e($Code); ?>" class="form-control " disabled>
                                            <input type="hidden" name="Code" value="<?php echo e($Code); ?>" class="form-control">
                                        </div>
                                        <div class="form-group col-lg-3">
                                            <label class="form-label" for="simpleinput"><?php echo e(trans('admin.Date')); ?></label>
                           <input type="date" name="Date" value="<?php echo e(date('Y-m-d')); ?>" class="form-control" required>
                                        </div>
                                        <div class="form-group col-lg-3">
                               <label class="form-label" for="simpleinput"><?php echo e(trans('admin.Borrow_Month')); ?></label>
                <input onchange="Check()" type="month" id="Month" name="Month" value="<?php echo e(date('Y-m')); ?>" class="form-control" required>
                                        </div>
                                        <div class="form-group col-lg-3">
                                            <label class="form-label" for=""><?php echo e(trans('admin.Safe')); ?></label>
                                            <select class="select2 form-control w-100" name="Safe" id="Safe" required>
                                                 <option value=""> <?php echo e(trans('admin.Safe')); ?></option>
                                            <?php $__currentLoopData = $Safes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $safe): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <option value="<?php echo e($safe->id); ?>">

                                     <?php echo e(app()->getLocale() == 'ar' ?$safe->Name :$safe->NameEn); ?>

                                                </option>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            </select>
                                        </div>
                                            <div class="form-group col-lg-3">
                                            <label class="form-label" for=""><?php echo e(trans('admin.Coin')); ?></label>
                                            <select class="select2 form-control w-100" name="Coin" required>
                                                 <option value=""> <?php echo e(trans('admin.Coin')); ?></option>
                                            <?php $__currentLoopData = $Coins; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $coin): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <option value="<?php echo e($coin->id); ?>" <?php if($Def->Coin == $coin->id): ?> selected <?php endif; ?>>

                                       <?php echo e(app()->getLocale() == 'ar' ?$coin->Arabic_Name :$coin->English_Name); ?>

                                                </option>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            </select>
                                        </div>
                                        <div class="form-group col-lg-3">
                                            <label class="form-label" for="simpleinput"><?php echo e(trans('admin.Draw')); ?></label>
                                            <input type="text" name="Draw" value="1" class="form-control" required>
                                        </div>
                                            <div class="form-group col-lg-3">
                                            <label class="form-label" for=""> <?php echo e(trans('admin.Cost_Center')); ?> </label>
                                            <select class="select2 form-control w-100" name="Cost_Center">
                                            <option value=""> <?php echo e(trans('admin.Cost_Center')); ?></option>
                                            <?php $__currentLoopData = $CostCenters; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $cost): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <option value="<?php echo e($cost->id); ?>">

                                       <?php echo e(app()->getLocale() == 'ar' ?$cost->Arabic_Name :$cost->English_Name); ?>

                                                </option>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            </select>
                                        </div>
                                        <div class="form-group col-lg-3">
                                            <label class="form-label" for=""><?php echo e(trans('admin.Employee')); ?></label>
                               <select onchange="Check()" class="js-data-example-ajax form-control w-100" id="Emp" name="Emp" required>

                                            </select>


                                        </div>
                                        <div class="form-group col-lg-3">
                                 <label class="form-label" for="simpleinput">   <?php echo e(trans('admin.Total_Borrow')); ?>    </label>
                                   <input type="text" id="TotalBorrow"  disabled class="form-control">
                                        </div>
                                        <div class="form-group col-lg-3">
                                 <label class="form-label" for="simpleinput">   <?php echo e(trans('admin.Salary')); ?>     </label>
                                            <input type="text" id="Salary"  disabled  class="form-control">
                                        </div>

                                             <div class="form-group col-lg-3">
                                 <label class="form-label" for="simpleinput">   <?php echo e(trans('admin.Residual')); ?>     </label>
                                            <input type="text" id="Res"  disabled  class="form-control">
                                        </div>

                                        <div class="form-group col-lg-3">
                                   <label class="form-label" for="simpleinput">  <?php echo e(trans('admin.Borroww')); ?>     </label>
               <input type="number"  onkeyup="Check()" step="any" id="Amount" value="0" name="Amount"  class="form-control" required>
                                        </div>

                                        <div class="form-group col-lg-12">
                                            <label class="form-label" for="simpleinput"><?php echo e(trans('admin.Notes')); ?>  </label>
                                            <input type="text" name="Note" value="<?php echo e(old('Note')); ?>" class="form-control">
                                        </div>


                                    <div class="form-row" style="display: none" id="Alert">
                                      <span id="ALertText" class="alert alert-danger"></span>
                                            </div>

                                    <div class="form-row" style="display: none" id="Submit">
                                              <input type="hidden" class="form-control btn btn-primary" id="SafeBalance" value="0">
                            <button type="submit" class="btn btn-primary">
                                        <?php echo e(trans('admin.Save')); ?>

                                        </button>
                                            </div>

                                        </div>



                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                </div>
    </div>
               </form>
</main>
<input type="hidden" id="TakeSalary" value="0">
<?php $__env->stopSection(); ?>

<?php $__env->startPush('js'); ?>
    <link rel="stylesheet" media="screen, print" href="<?php echo e(asset('Admin/css/datagrid/datatables/datatables.bundle.css')); ?>">
    <link rel="stylesheet" media="screen, print" href="<?php echo e(asset('Admin/css/formplugins/select2/select2.bundle.css')); ?>">
    <script src="<?php echo e(asset('Admin/js/formplugins/select2/select2.bundle.js')); ?>"></script>
    <script src="<?php echo e(asset('Admin/js/datagrid/datatables/datatables.export.js')); ?>"></script>
    <script src="<?php echo e(asset('Admin/js/datagrid/datatables/datatables.bundle.js')); ?>"></script>

    <script>
        //_fnFeatureHtmlLength();
        $(document).ready(function () {
            // Setup - add a text input to each footer cell
            $('#dt-basic-example thead tr').clone(true).appendTo('#dt-basic-example thead');
            $('#dt-basic-example thead tr:eq(1) th').each(function (i) {
                var title = $(this).text();
                $(this).html('<input type="text" class="form-control form-control-sm" placeholder="Search ' + title + '" />');

                $('input', this).on('keyup change', function () {
                    if (table.column(i).search() !== this.value) {
                        table
                            .column(i)
                            .search(this.value)
                            .draw();
                    }
                });
            });
            var table = $('#dt-basic-example').DataTable(
                {
                    responsive: true,
                    orderCellsTop: true,
                    fixedHeader: true,
                    lengthChange: true,

                    dom: "<'row mb-3'<'col-sm-12 col-md-3 d-flex align-items-center justify-content-start'f><'col-sm-12 col-md-9 d-flex align-items-center justify-content-end'B>>" +
                        "<'row'<'col-sm-12'tr>>" +
                        "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",

                    buttons: [
                        {
                            extend: 'pageLength',
                            className: 'btn-outline-default'
                        },
                        {
                            extend: 'colvis',
                            text: 'Column Visibility',
                            titleAttr: 'Col visibility',
                            className: 'btn-outline-default'
                        },
                        {
                            extend: 'pdfHtml5',
                            text: 'PDF',
                            titleAttr: 'Generate PDF',
                            className: 'btn-outline-danger btn-sm mr-1'
                        },
                        {
                            extend: 'excelHtml5',
                            text: 'Excel',
                            titleAttr: 'Generate Excel',
                            className: 'btn-outline-success btn-sm mr-1'
                        },
                        {
                            extend: 'csvHtml5',
                            text: 'CSV',
                            titleAttr: 'Generate CSV',
                            className: 'btn-outline-primary btn-sm mr-1'
                        },
                        {
                            extend: 'copyHtml5',
                            text: 'Copy',
                            titleAttr: 'Copy to clipboard',
                            className: 'btn-outline-primary btn-sm mr-1'
                        },
                        {
                            extend: 'print',
                            text: 'Print',
                            titleAttr: 'Print Table',
                            className: 'btn-outline-primary btn-sm'
                        }
                    ],
                });
            $('.js-thead-colors a').on('click', function () {
                var theadColor = $(this).attr("data-bg");
                console.log(theadColor);
                $('#dt-basic-example thead').removeClassPrefix('bg-').addClass(theadColor);
            });

            $('.js-tbody-colors a').on('click', function () {
                var theadColor = $(this).attr("data-bg");
                console.log(theadColor);
                $('#dt-basic-example').removeClassPrefix('bg-').addClass(theadColor);
            });

        });

    </script>


<!-- Search Selecet -->
<script>
    $(document).ready(function () {
        $(function () {
            $(".select2").select2();

            $(".select2-placeholder-multiple").select2({
                placeholder: "Select State",
            });
            $(".js-hide-search").select2({
                minimumResultsForSearch: 1 / 0,
            });
            $(".js-max-length").select2({
                maximumSelectionLength: 2,
                placeholder: "Select maximum 2 items",
            });
            $(".select2-placeholder").select2({
                placeholder: "Select a state",
                allowClear: true,
            });

            $(".js-select2-icons").select2({
                minimumResultsForSearch: 1 / 0,
                templateResult: icon,
                templateSelection: icon,
                escapeMarkup: function (elm) {
                    return elm;
                },
            });

            function icon(elm) {
                elm.element;
                return elm.id ? "<i class='" + $(elm.element).data("icon") + " mr-2'></i>" + elm.text : elm.text;
            }

            $("#Emp").select2({
                placeholder: "select...",
                ajax: {
                    type: "GET",
                    dataType: "json",
                    url: "AllEmps",
                    processResults: function (data) {
                        return {
                            results: $.map(data, function (obj, index) {
                                return { id: index, text: obj };
                            }),
                        };

                        console.log(data);
                    },
                   data: function (params) {


                   var query = {
                            search: params.term,
                        };


              $.ajax({
                              url: 'AllEmpsJ/'+params.term,
                              type:"GET",
                              dataType:"json",
                              beforeSend: function(){
                                  $('#loader').css("visibility", "visible");
                              },

                              success:function(data) {
                                          $('#Emp').empty();
                                  $.each(data, function(key, value){

                         $('#Emp').append('<option value="'+ key +'">' + value + '</option>');

                                  });
                              },
                              complete: function(){
                                  $('#loader').css("visibility", "hidden");
                              }
                          });



        }
                },
            });

            $("#Emp").on("select2:select", function (e) {
                console.log("select done", e.params.data);
            });
        });
    });
</script>

<!-- Check Emp -->
<script>

   function  Check(){

   var Emp = $('#Emp').val();
   var Month = $('#Month').val();

                     if(Emp) {
                         $.ajax({
                             url: 'EmpCheck/'+Emp+'/'+Month,
                             type:"GET",
                             dataType:"json",
                             beforeSend: function(){
                                 $('#loader').css("visibility", "visible");
                             },

                             success:function(data) {
                                 $.each(data, function(key, value){

                       $('#TotalBorrow').val(data.Total);
                       $('#Salary').val(data.Salary);
                       $('#TakeSalary').val(data.TakeSalary);

                        var Sal =  $('#Salary').val();
                        var Tot =  $('#TotalBorrow').val();
                        var Amount =  $('#Amount').val();
                        var z =  parseFloat(Sal) - parseFloat(Tot)  ;
                         $('#Res').val(parseFloat(z));

                         var Res =  $('#Res').val();

                            if(parseFloat(Tot) ==  parseFloat(Sal)){

                     document.getElementById("Submit").style.display = "none";
                    document.getElementById("Alert").style.display = "block";
                      $('#ALertText').text('تم الوصول للحد الاقصي للاستلاف  لهذا الشهر ');


                            }else{


                                if(parseFloat(Res) < parseFloat(Amount)){

                    document.getElementById("Submit").style.display = "none";
                    document.getElementById("Alert").style.display = "block";
                      $('#ALertText').text('لا يمكن استلاف مبلغ اكبر من متبقي الراتب');

                                }else{

                     document.getElementById("Submit").style.display = "block";
                    document.getElementById("Alert").style.display = "none";
                      $('#ALertText').text('');

                                }


                            }


                                 });

          var SafeBalance= $('#SafeBalance').val();
           var Amount= $('#Amount').val();
           var TakeSalary= $('#TakeSalary').val();


            if(parseFloat(Amount) > parseFloat(SafeBalance)){
  alert('المبلغ غير كافي في الخزينه');
                 document.getElementById("Submit").style.display = "none";
         }


if(parseFloat(TakeSalary)  ==  1){

    alert('لقد تم صرف راتب هذا الشهر للموظف من قبل لا يمكن الاستلاف لهذا الشهر');
    document.getElementById("Submit").style.display = "none";

}


                             }
                                 });
                     }
   }


</script>

<!-- Safe Balnces  -->
<script>
   $(document).ready(function() {

                  $('#Safe').on('change', function(){
                      var countryId = $(this).val();
                      if(countryId) {
                          $.ajax({
                              url: 'SafeBalanceFilter/'+countryId,
                              type:"GET",
                              dataType:"json",
                              beforeSend: function(){
                                  $('#loader').css("visibility", "visible");
                              },

                              success:function(data) {
                                  $.each(data, function(key, value){


                    $('#SafeBalance').val(key);
                    $('#SafeBalance').val(value);
                                  });
                                            var SafeBalance= $('#SafeBalance').val();
           var Amount= $('#Amount').val();

            if(parseFloat(Amount) > parseFloat(SafeBalance)){
  alert('المبلغ غير كافي في الخزينه');
                 document.getElementById("Submit").style.display = "none";
         }
                              },
                              complete: function(){
                                  $('#loader').css("visibility", "hidden");
                              }
                          });
                      } else {

                          $('select[name="state"]').empty();
                      }

                  });

              });
</script>



<?php $__env->stopPush(); ?>

<?php echo $__env->make('admin.index', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/klarapps/public_html/test.klarapps.com/resources/views/admin/HR/AddBorrow.blade.php ENDPATH**/ ?>