<?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-6 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-6 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>

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


                        <div class="divider"></div>
                        <div class="divider divider-primary table">
                          <div class="divider-text"> <h4>الخزن</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="safe">
                                  <thead>
                                  <tr>
                                      <th>م</th>
                                      <th>الإجمالي</th>

                                  </tr>
                                  </thead>
                                  <tbody class="tbody">
                                  </tbody>
                              </table>
                          </div>  
                      </div>
                      <br>
                      <br>
                      <div class="divider"></div>
                      <div class="divider divider-primary table">
                        <div class="divider-text"> <h4>البنوك</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="bank">
                                <thead>
                                <tr>
                                    <th>م</th>
                                    <th>الإجمالي</th>

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

                      <div class="divider"></div>
                      <div class="divider divider-primary table">
                        <div class="divider-text"> <h4> المخازن و المنتجات</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="products">
                                <thead>
                                <tr>
                                    <th>م</th>
                                    <th>الإجمالي</th>

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

        </div>
      </div>
    </div>
	</section>

	</div>
      </div>
    </div>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('script'); ?>
<script>



$("#search").on('submit',(function(e) {
e.preventDefault();
  filter();
}));
  var table = $('.table') ;
  function filter() {
    
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.report16.post')); ?>",
    type: "POST",
    data: {
        "_token": "<?php echo e(csrf_token()); ?>",
        "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 profit = 0 ; 
        var sales = 0 ; 
        var cashs_in = 0 ;
        var cashs_out = 0 ; 
        var suppliersAdvance = 0 ;
        var bankSafeTransfer = 0
        var capitals = 0
        var safeBankTransfer = 0
        var buy = 0 ; 
        var safe_expenses = 0 ; 
        var revenues_safe = 0 ;
        var bank_expenses = 0 ; 
        var revenues_bank = 0 ;
        var expenses = 0 ; 
        var employeesCashs = 0 ; 
        var employeesBanks = 0 ;
        var buy_cashs_in = 0 ;
        var buy_cashs_out = 0 ; 
        var clientAdvance = 0 ; 
        var bankCashs_in = 0 ;
        var bankCashs_out = 0 ;
        var bankDeposit = 0 ;
        var bank_buy_cash_in = 0 ;
        var bank_buy_cash_out = 0 ;
        var withdrawal = 0 ;
        var productsBuy = 0 ;
        var productsSell = 0 ;
        var stores = 0 ;
        var profit = 0 ;
        var outerClientsBalance = 0 ;
        var employeeBalance =0;
        var suppliersBalance = 0 ;
        var product_profit = 0 ;
        var safes_start_balance = 0 ;
        var banks_start_balance = 0 ;



        $('#loader').hide();
        table.show();
        $('.tbody').empty();
        $('#header').show();

        $.each( data.safes, function( key, value ) {
          safes_start_balance +=  parseFloat(value.balance_start);         
        });

        $.each( data.banks, function( key, value ) {
          banks_start_balance +=  parseFloat(value.balance_start);         
        });

        $.each( data.sale_bills, function( key, value ) {
              sales +=  parseFloat(value.final_total);
              profit += parseFloat(value.updated_at)           
        });
        $('#bills').append('<tr><td>إجمالي المبيعات</td><td>'+formatMoney(sales)+' <?php echo e($company->currency); ?> </td></tr>');


        $.each( data.buy_bills, function( key, value ) {
              buy +=  parseFloat(value.final_total);         
        });
        $('#bills').append('<tr><td>إجمالي المشتريات</td><td>'+formatMoney(buy)+' <?php echo e($company->currency); ?> </td></tr>');

        $('#bills').append('<tr><td>إجمالي الأرياح</td><td>'+formatMoney(profit)+' <?php echo e($company->currency); ?> </td></tr>');

        $.each( data.cashs, function( key, value ) {

          if(value.amount > 0){
            cashs_in +=  parseFloat(Math.abs(value.amount)); 
          }else{
            cashs_out +=  parseFloat(Math.abs(value.amount)); 
          }

        });
        $.each( data.bank_safe_transfer, function( key, value ) {
            bankSafeTransfer +=  Math.abs(parseFloat(value.amount));         
        });
        $.each( data.capitals, function( key, value ) {
            capitals +=  parseFloat(value.amount);         
        });
        $.each( data.suppliersAdvance, function( key, value ) {
            suppliersAdvance +=  Math.abs(parseFloat(value.amount));         
        });


        $.each( data.buy_cashs, function( key, value ) {

          if(value.amount < 0){
            buy_cashs_in +=  parseFloat(Math.abs(value.amount)); 
          }else{
            buy_cashs_out +=  parseFloat(Math.abs(value.amount)); 
          }       
        });

        $.each( data.safe_expenses, function( key, value ) {
          if(value.type == 'إيراد'){
            revenues_safe +=  parseFloat(value.amount);   
          }else if(value.type == 'مصروف'){
            safe_expenses +=  parseFloat(Math.abs(value.amount));   
          }
        
        });

        var safeIn = cashs_in+bankSafeTransfer+capitals+suppliersAdvance+buy_cashs_in+revenues_safe ;

        $('#safe').append('<tr><td>إجمالي الداخل إلي الخزن</td><td>'+formatMoney(safeIn)+' <?php echo e($company->currency); ?> </td></tr>');



        $.each( data.bank_expenses, function( key, value ) {
           
          if(value.type == 'إيراد'){
            revenues_bank +=  parseFloat(value.amount);   
          }else if(value.type == 'مصروف'){
            bank_expenses +=  parseFloat(Math.abs(value.amount));   
          }      
        });

        $.each( data.employees_cashs, function( key, value ) {
            employeesCashs +=  parseFloat(Math.abs(value.amount));         
        });
        $.each( data.clientAdvance, function( key, value ) {
            clientAdvance +=  Math.abs(parseFloat(value.amount));         
        });
        $.each( data.safe_bank_transfer, function( key, value ) {
            safeBankTransfer +=  Math.abs(parseFloat(value.amount));         
        });

        var safeOut = cashs_out+buy_cashs_out+safeBankTransfer+safe_expenses+employeesCashs+clientAdvance;
        $('#safe').append('<tr><td>إجمالي الخارج من الخزن</td><td>'+formatMoney(safeOut)+' <?php echo e($company->currency); ?> </td></tr>');
        $('#safe').append('<tr><td>إجمالي المتبقي في الخزن</td><td>'+formatMoney(safeIn-safeOut+safes_start_balance)+' <?php echo e($company->currency); ?> </td></tr>');
            
        //////
        $.each( data.bank_cash, function( key, value ) {

          if(value.amount > 0){
            bankCashs_in +=  parseFloat(Math.abs(value.amount)); 
          }else{
            bankCashs_out +=  parseFloat(Math.abs(value.amount)); 
          }   
        });

        $.each( data.deposit, function( key, value ) {
          bankDeposit +=  parseFloat(value.amount);         
        });

        $.each( data.bank_buy_cash, function( key, value ) {
          if(value.amount < 0){
            bank_buy_cash_in +=  parseFloat(Math.abs(value.amount)); 
          }else{
            bank_buy_cash_out +=  parseFloat(Math.abs(value.amount)); 
          }   
        });

        $.each( data.employees_banks, function( key, value ) {
            employeesBanks +=  parseFloat(Math.abs(value.amount));         
        });
        
        var bankIn = bankDeposit+safeBankTransfer+bank_buy_cash_in+bankCashs_in+revenues_bank ;
        $('#bank').append('<tr><td>إجمالي الداخل إلي البنوك</td><td>'+formatMoney(bankIn)+' <?php echo e($company->currency); ?> </td></tr>');



        $.each( data.withdrawal, function( key, value ) {
          withdrawal +=  parseFloat(value.amount);         
        });
        var bankOut = withdrawal+bank_buy_cash_out+bankSafeTransfer+bank_expenses+bankCashs_out+employeesBanks ;
        var expenses = bank_expenses + safe_expenses;
        var revenues = revenues_bank + revenues_safe;
         $('#bank').append('<tr><td>إجمالي الخارج من البنوك</td><td>'+formatMoney(bankOut)+' <?php echo e($company->currency); ?> </td></tr>');
         $('#bank').append('<tr><td>إجمالي المتبقي في البنوك</td><td>'+formatMoney(bankIn-bankOut+banks_start_balance)+' <?php echo e($company->currency); ?> </td></tr>');


         ////
        $('#bills').append('<tr><td>إجمالي المصروفات</td><td>'+formatMoney(expenses)+' <?php echo e($company->currency); ?> </td></tr>');
        $('#bills').append('<tr><td>إجمالي الإيردات</td><td>'+formatMoney(revenues)+' <?php echo e($company->currency); ?> </td></tr>');

        $.each( data.employees, function( key, value ) {
          employeeBalance +=  parseFloat(value.balance);         
        });

        if(employeeBalance > 0 ){var employeeBalanceType ='لهم' }else{var employeeBalanceType ='عليهم';}
        $('#bills').append('<tr><td>إجمالي ديون العملاء </td><td>' + employeeBalanceType+' '+formatMoney(Math.abs(employeeBalance))+' <?php echo e($company->currency); ?> </td></tr>');
        ////

        $.each( data.outerClients, function( key, value ) {
          outerClientsBalance +=  parseFloat(value.prev_balance);         
        });
        if(outerClientsBalance < 0 ){var outerClientsBalanceType ='لهم' }else{var outerClientsBalanceType ='عليهم';}
        $('#bills').append('<tr><td>إجمالي ديون العملاء </td><td>' + outerClientsBalanceType+' '+formatMoney(Math.abs(outerClientsBalance))+' <?php echo e($company->currency); ?> </td></tr>');
        
        $.each( data.suppliers, function( key, value ) {
          suppliersBalance +=  parseFloat(value.prev_balance);         
        });
        if(suppliersBalance > 0 ){var suppliersBalanceType ='لهم'; }else{var suppliersBalanceType ='عليهم';}
        $('#bills').append('<tr><td>إجمالي ديون الموردين </td><td>' + suppliersBalanceType+' '+formatMoney(Math.abs(suppliersBalance))+' <?php echo e($company->currency); ?> </td></tr>');



        $.each( data.products, function( key, value ) {
          productsBuy +=  parseFloat(value.purchasing_price*value.first_balance);  
          productsSell +=  parseFloat(value.sector_price*value.first_balance);  

          product_profit +=parseFloat((value.sector_price - value.purchasing_price)*value.first_balance ); 
       
        });

        $('#products').append('<tr><td>إجمالي تكلفة المنتجات  </td><td>'+formatMoney(productsBuy)+' <?php echo e($company->currency); ?> </td></tr>');
        $('#products').append('<tr><td>إجمالي بيع المنتجات  </td><td>'+formatMoney(productsSell)+' <?php echo e($company->currency); ?> </td></tr>');


        $.each( data.stores, function( key, value ) {
          var productsOfStoreBuy = 0 ;
          var productsOfStoreSell = 0 ;


        $.each( value.products, function( key, value ) {
          productsOfStoreBuy +=  parseFloat(value.purchasing_price*value.first_balance); 
          productsOfStoreSell +=  parseFloat(value.sector_price*value.first_balance); 

                  });

        $('#products').append('<tr><td>إجمالي تكلفة مخزن :  '+value.store_name+'</td><td>'+formatMoney(productsOfStoreBuy)+' <?php echo e($company->currency); ?> </td></tr>');
        $('#products').append('<tr><td>إجمالي بيع مخزن :  '+value.store_name+'</td><td>'+formatMoney(productsOfStoreSell)+' <?php echo e($company->currency); ?> </td></tr>');
          

        });

        $('#products').append('<tr><td>إجمالي الربح المتوقع  </td><td>'+formatMoney(product_profit)+' <?php echo e($company->currency); ?> </td></tr>');

          },
   error: function (data) {

    }
});
};


var selectForm = $('#search');

if (selectForm) {
    selectForm.validate({

        rules: {
      'safe_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/reports/report16.blade.php ENDPATH**/ ?>