<?php $__env->startSection('title','تقرير كشف حساب موظف'); ?>
<?php $__env->startSection('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>
    <div class="content-body">
	<!-- Dashboard Ecommerce Starts -->
		<section id="dashboard-ecommerce">
		<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.reports')); ?>">التقارير </a>

                    <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">
               				
            </div>
          </div>
        </div>
            <div class="col-xl-12 col-md-12 col-12">
                <div class="card">
                    <form  id="search" method="post" action="<?php echo e(route('clients.summary.post')); ?>" >
                      <?php echo csrf_field(); ?>
                      <input name ="company_id" type="hidden" value="<?php echo e($company_id); ?>">
                    <div class="card-body row" align="center">
                        <div class="col-lg-2 col-sm-6-md-6"></div>

                        <div class="col-lg-6 col-sm-6-md-6 ">


                            <div class= "row">
                        <div class="col-lg-4 col-sm-6-md-6 mb-1">
                            <center> <label class="form-label" style="font-weight:bold " > إختر الموظف </label></center>
                        <select  name="employee_id" id="employee_id" class="form-control select2">
                       <option value="">إختر موظف</option>
                       <?php $__currentLoopData = $employees; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $employee): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                           <option value="<?php echo e($employee->id); ?>"><?php echo e($employee->name); ?></option>
                       <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                   </select>   
                        </div>
                        <div class="col-lg-4 col-sm-6-md-6 mb-1">
                            <center> <label class="form-label" style="font-weight:bold " > من تاريخ</label></center>
                   <input type="date" name="from_date" id="from_date" class="form-control" >
                       
                </div>
                <div class="col-lg-4 col-sm-6-md-6 mb-1">
                    <center> <label class="form-label" style="font-weight:bold " > إلي تاريخ</label></center>
                    <input type="date" name="to_date" id="to_date" class="form-control" >
                   </div>
                            </div>
                </div>
                        <div class="col-lg-4 col-sm-6-md-6">
                            <center> <label class="form-label" style="font-weight:bold " ></label></center>
            
                            <button type="submit" class="btn btn-success me-1">بحث</button>
            
                         </div>
                      </div>
                    </form>
                </div>
              </div>
              
      <div class="col-xl-12 col-md-12 col-12" id="data-card" style="display: none">
        <div class="card card-statistics">

      <div class="card-body statistics-body">
        <div class="row">

          <div class="card-body" align="center" id="loader">
              <div class="spinner-border text-primary" style="width: 5rem; height: 5rem" role="status">
              </div>
            </div> 

              <div id="header" style="display: none">
            <center>
                <h3 id="header-title"></h3>
                <br>
            </center>
              </div>
                      <div class="card-datatable">
                          <div class="table-responsive">
                              <table class="table table-condensed table-striped table-bordered text-center table-hover " id="employee">
                                  <thead>
                                  <tr>
                                      <th>اسم الموظف</th>
                                      <th>الراتب </th>
                                      <th>رصيد الداية </th>
                                      <th>الرصيد الحالي </th>


                                  </tr>
                                  </thead>
                                  <tbody class="tbody">
                                  </tbody>
                              </table>
                          </div>
                          
                      </div>

                      <div class="divider"></div>

                      <div class="divider divider-primary table">
                          <div class="divider-text"> <h4 id="header-title">    العمليات  </h4></div>
                          <br>
                      </div>

                    <div class="card-datatable">
                      <div class="table-responsive">
                          <table class="table table-condensed table-striped table-bordered text-center table-hover" id="cash">
                              <thead>
                              <tr>
                                <th>المبلغ </th>
                                <th> نوع العملية </th>
                                <th> الدفع </th>
                                <th> ملاحظات </th>
                                <th> التاريخ </th>
                                <th> المسؤل </th>
                              </tr>
                              </thead>
                              <tbody class="tbody">
                                  
                              </tbody>
                          </table>
                      </div>
                  </div>
          
        </div>
      </div>
    </div>
  </div>
  <center>
    <div class="col-lg-4 col-md-12" style="display: none" id="additionalData">
      <div class="card" >
        <div class="card-header"  >
          <h4 class="card-title">مختصر عن عمليات الموظف</h4>
        </div>
        <div class="card-body">
          <p class="card-text">
           
          </p>
          <ul class="list-group">
            <li class="list-group-item list-group-item-success">
              إجمالي الإستحقاق :
              <span class="badge bg-success rounded-pill" id="deserve"></span>
              <?php echo e($company->currency); ?>

            </li>
            <li class="list-group-item list-group-item-primary">
              إجمالي الدفعات :
              <span class="badge bg-primary rounded-pill" id="total_cash"></span>
              <?php echo e($company->currency); ?>

            </li>
            <li class="list-group-item list-group-item-danger">
              إجمالي السلف :
              <span class="badge bg-danger rounded-pill" id="total_borrow"></span>
              <?php echo e($company->currency); ?>

            </li>
            <li class="list-group-item list-group-item-warning">
              إجمالي المتبقي :
              <span class="badge bg-warning rounded-pill" id="total_net"></span>
              <?php echo e($company->currency); ?>

            </li>
          </ul>
        </div>
      </div>
    </div>
    </center>
            
          </div>
        </div>
      </div>
    </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>
    $(document).ready(function() {
        $('.select2').select2();
    });


$("#search").on('submit',(function(e) {
e.preventDefault();
  filter();
}));
  var table = $('.table') ;
  function filter() {

var employee = $('#employee_id').val();
var from_date = $('#from_date').val();
var to_date = $('#to_date').val();

if(from_date == '' || to_date == ''){$('#header-title').text('جميع عمليات الموظف ' )}else{$('#header-title').text(' جميع عمليات الموظف من تاريخ '+from_date+' إلي تاريخ '+to_date )}
$.ajax({
    url: "<?php echo e(route('employees.summary.post')); ?>",
    type: "POST",
    data: {
        "_token": "<?php echo e(csrf_token()); ?>",
        "employee": employee,
        "from_date": $("#from_date").val(),
        "to_date" : $("#to_date").val()
    },
    beforeSend : function (){table.hide(); $('#additionalData').hide(); $('#header').hide(); $('#data-card').show();$('#loader').show(); var ifConnected = window.navigator.onLine;if (!ifConnected) {toastr.info("يتم الآن إعادة الإتصال","لا يوجد إتصال بالإنترنت",{positionClass: "toast-top-right",tapToDismiss: !1,timeOut: 2e3,rtl: $("html").attr("data-textdirection")});}},
    success: function (data) {
        $('#loader').hide();
        table.show();
        $('.tbody').empty();
        $('#header').show();
        $('#additionalData').show();

        if(data.employee.balance < 0){
          var balance = ' علية '+Math.abs(data.employee.balance) ;
        }else if(data.employee.balance > 0){
          var balance = ' لة '+data.employee.balance ;
        }else{  
          var balance = 0 ;
        }

        if(data.employee.balance_start < 0){
          var balance_start_type = ' علية ';
        }else if(data.employee.balance_start > 0){
          var balance_start_type = ' لة ';
        }else{  
          var balance_start_type = ' ';
        }
        var balance_start = Math.abs(data.employee.balance_start);
        var balance_start_with_out_abs = parseFloat(data.employee.balance_start?data.employee.balance_start:0);
        $('#employee').append(
                '<tr>'+
                '<td>'+data.employee.name+'</td>'+
                '<td>'+data.employee.salary+'</td>'+
                '<td>'+balance_start_type+balance_start+'</td>'+
                '<td>'+balance+'</td>'+
                '</tr>'
            );

            var  cash = 0;
            var borrow = 0;

        $.each( data.result, function( key, value ) {
            if(value.safe){
              var safe = '<b>خزنة : </b>'+value.safe.safe_name
             }else if(value.bank){
              var safe = '<b> بنك : </b>'+value.bank.bank_name
             }
             if(value.amount < 0){
              var type = 'سلفة'
              borrow += parseFloat(Math.abs(value.amount));
              }else if(value.amount > 0){
              var type = 'دفعة'
              cash += parseFloat(value.amount);
              }
            $('#cash').append(
                '<tr>'+
                '<td>'+(Math.abs(value.amount))+'</td>'+
                '<td>'+(safe)+'</td>'+
                '<td>'+(type)+'</td>'+
                '<td>'+value.notes+'</td>'+
                '<td>'+(value.date)+'</td>'+
                '<td>'+value.client.name+'</td>'+
                '</tr>'
            );
        });
        $('#total_cash').text(cash);
        $('#total_borrow').text(borrow);
        $('#deserve').text(data.type+data.deserve);
        net = parseFloat(data.deserve -borrow -cash + balance_start_with_out_abs );
        if(net < 0){
          var typeOfNet = 'علية ';
        }else if(net > 0){
          var typeOfNet = 'لة ';
        }else if(net == 0){
          var typeOfNet = 0;
        }

        $('#total_net').text(typeOfNet+Math.abs(net));
        

        if(data.result == ''){ $('#cash').append('<tr style="font-weight:bold;">'+'<td colspan="6">لا يوجد أي معاملات  </td>'+'</tr>')}

          },
   error: function (data) {

    }
});
};


var selectForm = $('#search');

if (selectForm) {
    selectForm.validate({

        rules: {
      'bank_id': {
        required: true,
      }
    }
  });
}
   </script>
<?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/summary/employees.blade.php ENDPATH**/ ?>