<?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" name="date" >
                    <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 required name="fixed_expense" id="fixed_expense" class="form-control" required>
                                <option value="all">كل المصاريف</option>
                                <?php $__currentLoopData = $fixed_expenses; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $fixed): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($fixed->id); ?>"><?php echo e($fixed->fixed_expense); ?></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="bills">
                                    <thead>
                                    <tr>
                                        <th>رقم المصروف</th>
                                        <th>بيان المصروف</th>
                                        <th>نوع المصروف</th>
                                        <th>المبلغ</th>
                                        <th>الصورة</th>
                                        <th>خزنة الدفع</th>
                                        <th>التاريخ</th>
                                        <th>المسؤول</th>
                                    </tr>
                                    </thead>
                                    <tbody class="tbody">
                                    </tbody>
                                </table>
                            </div>
                            
                        </div>

                <div class="divider"></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-warning">
                إجمالي المصاريف  : 
                <span class="badge bg-warning rounded-pill" id="total_expenses"></span>
                <?php echo e($company->currency); ?>

              </li>
            </ul>
          </div>
        </div>
      </div>
      </center>
	</section>

	</div>
      </div>
    </div>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('script'); ?>
<script src="<?php echo e(asset('app-assets/js/lightbox.min.js')); ?>"></script>

<script>
    lightbox.option({
      'resizeDuration': 300,
      'wrapAround': true
    })



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

var fixed_expense = $('#fixed_expense').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('client.report14.post')); ?>",
    type: "POST",
    data: {
        "_token": "<?php echo e(csrf_token()); ?>",
        "fixed_expense": fixed_expense,
        "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) {
        var expenses = 0 ; 
        $('#loader').hide();
        table.show();
        $('.tbody').empty();
        $('#header').show();
        $.each( data.expenses, function( key, value ) {

            if(value.expense_pic == ""){
                img = "";
            }else{
                var img = '<a class="'+key+'-image-link" data-lightbox="'+key+'-set" href="<?php echo e(asset('')); ?>'+value.expense_pic+'">عرض</a>';
            }

             if(value.safe){
              var safe = '<b>خزنة : </b>'+value.safe.safe_name
             }else if(value.bank){
              var safe = '<b> بنك : </b>'+value.bank.bank_name
             }

              expenses +=  parseFloat(value.amount);

            $('#bills').append(
                '<tr>'+
                '<td>'+(value.expense_number)+'</td>'+
                '<td>'+(value.expense_details)+'</td>'+
                '<td>'+(value.fixed.fixed_expense)+'</td>'+
                '<td>'+(formatMoney(parseFloat(value.amount)))+'</td>'+
                '<td>'+(img)+'</td>'+
                '<td>'+safe+'</td>'+
                '<td>'+(value.created_at.split('T')[0])+'</td>'+
                '<td>'+value.client.name+'</td>'+
                '</tr>'
            );

           
        });

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

        $('#total_expenses').text(formatMoney(parseFloat(expenses)));



          },
   error: function (data) {

    }
});
};


var selectForm = $('#search');

if (selectForm) {
    selectForm.validate({

        rules: {
      'fixed_expense': {
        required: true,
      }
    }
  });
}
   </script>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('style'); ?>
<link rel="stylesheet" href="<?php echo e(asset('app-assets/css/lightbox.css')); ?>">
<?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/reports/report14.blade.php ENDPATH**/ ?>