 @extends('layouts.app')
 @section('title')Income Page @endsection
 @section('content')
<!--<script src="https://code.jquery.com/jquery-3.5.1.js"> </script>
<script src="https://cdn.datatables.net/1.11.5/js/jquery.dataTables.min.js"> </script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.11.5/css/jquery.dataTables.min.css">--->
 <?php 
 
    //echo"<pre>"; print_r($leadclientsall); exit;
    $totalincome         = $data['totalincome'];
    $outsatnginamt       = $data['outsatnginamt'];
    $leadclients         = $data['leadclients'];
    $usersagent          = $data['useraragents'];
    $search_start_date   = $data['search_start_date'];
    $search_end_date     = $data['search_end_date'];
    $client_name         = @$data['client_name'];
    $client_id           = @$data['client_id'];
    $role                = Auth::user()->user_role;
    use \App\Http\Controllers\AgentincomeController;
    use App\User;
 
 ?>
 <style>
     .datepicker{
         z-index:99999!important;
     }
    
    div.dataTables_wrapper div.dataTables_processing {
        height: 59px !important;
        top: 10% !important;
    }
   .dataTables_wrapper .dataTables_paginate .paginate_button:hover {
        color: white !important;
        border: 1px solid #fff!important;
        background-color: #fff!important;
        background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #fff), color-stop(100%, #fff))!important;
        background: -webkit-linear-gradient(top, #fff 0%, #fff 100%)!important;
        background: -moz-linear-gradient(top, #fff 0%, #fff 100%)!important;
        background: -ms-linear-gradient(top, #fff 0%, #fff 100%)!important;
        background: -o-linear-gradient(top, #fff 0%, #fff 100%)!important;
        background: linear-gradient(to bottom, #fff 0%, #fff 100%)!important;
        
        
    }
    .dataTables_wrapper .dataTables_paginate .paginate_button{
        padding: 0.5em 1mm !important;
    }
  
    .table-hover>tbody>tr:hover {
        background-color: #f5f5f5 !important;
    }
    
    .table-bordered {
        border: 1px solid #ddd !important;
    }
    
    thead {
        display: table-header-group !important;
        vertical-align: middle !important;
        border-color: inherit !important;
    }
    
    tr {
        display: table-row;
        vertical-align: inherit;
        border-color: inherit;
    }


    table {
        border-collapse: collapse !important;
        border-spacing: 0 !important;
    }
    
    .table-bordered>thead>tr>td, .table-bordered>thead>tr>th {
        border-bottom-width: 2px !important;
    }
    .table-bordered>tbody>tr>td, .table-bordered>tbody>tr>th, .table-bordered>tfoot>tr>td, .table-bordered>tfoot>tr>th, .table-bordered>thead>tr>td, .table-bordered>thead>tr>th {
        border: 1px solid #ddd !important;
    }
    .table>thead>tr>th {
        vertical-align: bottom !important;
        border-bottom: 2px solid #ddd !important;
    }
    
    .table>tbody>tr>td, .table>tbody>tr>th, .table>tfoot>tr>td, .table>tfoot>tr>th, .table>thead>tr>td, .table>thead>tr>th {
        padding: 8px;
        line-height: 1.42857143 !important;
        vertical-align: top !important;
        border-top: 1px solid #ddd !important;
    }


    * {
        -webkit-box-sizing: border-box !important;
        -moz-box-sizing: border-box !important;
        box-sizing: border-box !important;
    }
    .table * {
        font-size: 14px !important;
    }
    
    .table-bordered>tbody>tr>td, .table-bordered>tbody>tr>th, .table-bordered>tfoot>tr>td, .table-bordered>tfoot>tr>th, .table-bordered>thead>tr>td, .table-bordered>thead>tr>th {
        border: 1px solid #ddd !important;
    }
    .table>tbody>tr>td, .table>tbody>tr>th, .table>tfoot>tr>td, .table>tfoot>tr>th, .table>thead>tr>td, .table>thead>tr>th {
        padding: 8px;
        line-height: 1.42857143 !important;
        vertical-align: top !important;
        border-top: 1px solid #ddd !important;
    }
    table.dataTable thead .sorting:after, table.dataTable thead .sorting_asc:after, table.dataTable thead .sorting_desc:after, table.dataTable thead .sorting_asc_disabled:after, table.dataTable thead .sorting_desc_disabled:after
    {
        display: none !important;
    }
    .sweet-alert button.cancel {
        background-color: #ff0000 !important;
    }

</style>
 <section class="content-header mb-10 pb-10">
  <div class="row">
  @if($role!=AGENT && $data['show_agent_list']!=0)
  <div class="col-md-6 pt-10 sm-text-left clearfix">
    <div class="input_container" style="float: right;min-width: 235px;"> 
      <span style="padding-right: 10px;">Select Agent</span>
      <input id="agentsetsession" type="hidden" class="form-control search_new" name="agentsetsession" value="{{ url('agentsetsession') }}">
      <select id="agent_id" settype="setsig" name="agent_id" class="form-control select2 selectagent" style="width: 235px">
        <option value="">Select Agent</option>
        @foreach($usersagent as $useragent)
        <option <?php echo (session('aragentsearch') == $useragent->id) ? 'selected=true' : '' ?> value="{{ $useragent->id }}">{{ $useragent->name }} {{ $useragent->last_name }}</option>
        @endforeach
      </select>
    </div>
  </div>
  @endif
</div>
</section>

<?php 

    $total_incoe = array();
    $total_invoice = array();
    $gross_pay = array();
    $ids = array();
    
  
?>

<section class="content">
  <div class="row">
    <div class="col-xs-12">
     @include('layouts.flesh-message')
     <div class="box">
      <div class="box-header">
        <h3 style="float:left;" class="box-title">
          <?php 
          if(Request::segment(1) == 'adminincome'){
            echo $usserpage = 'Admin';
          }elseif(Request::segment(1) == 'arincome'){
            echo $usserpage = "AR";
          }else{
            echo $usserpage = "Agent";
          }
          
          //print_r($data['income_detail']->outsatnginamt); exit;
          $url = Request::path();
          //echo "url ".$url;
          ?> Income</h3>
        <div class="show_amount_detail text-right">
            
            <?php if(empty($_GET['income']) || $_GET['income']=='outstand'){ ?>
          <div class="sho_amount pr-10"> 
            <strong>Outstanding Invoice Amt. = </strong>
            
            
            <?php if($url == 'agentincome' || $url == 'arincome' || $url=='adminincome' || $url=='adminincome_new'){ ?>
               <strong id="outsatnginamt">$ <?php //echo (!empty($data['income_detail']->outsatnginamt)?$data['income_detail']->outsatnginamt:'0.0') ?> Loading...</strong>
           <?php }else{ ?>
           
                <strong id="outsatnginamt">$ Loading... </strong>
            
            <?php } ?>
           
          </div>
           <?php } ?>
           
            <?php if(empty($_GET['income']) || $_GET['income']=='gross'){ ?>
                <div class="sho_amount pl-10" >
                
                    <strong>Gross Revenue = </strong>
                    <?php if($url == 'agentincome' || $url == 'arincome' || $url=='adminincome' || $url=='adminincome_new'){ ?>
                
                        <strong id="gross_pay">$ <?php //echo (!empty($data['income_detail']->gross_pay)?$data['income_detail']->gross_pay:'0.0') ?> Loading...</strong>
                        
                         <?php }else{ ?>
           
                        <strong id="gross_pay">$ Loading...</strong>
            
                    <?php } ?>
                    
                    
                <?php //} ?> 
                </div>
            <?php } ?>
            
          <?php if(empty($_GET['income']) || $_GET['income']=='company' ||  $_GET['income']=='all'){ ?>
            <?php  if(collect(request()->segments())->last()=='adminincome') { ?>
          
            <div class="sho_amount pr-10"> 
                <strong>Outstanding Invoice Amt. = </strong>
            
            
                <?php if($url == 'agentincome' || $url == 'arincome' || $url=='adminincome' || $url=='adminincome_new'){ ?>
                   <strong id="outsatnginamt">$ <?php //echo (!empty($data['income_detail']->outsatnginamt)?$data['income_detail']->outsatnginamt:'0.0') ?> Loading...</strong>
               <?php }else{ ?>
           
                <strong id="outsatnginamt">$ Loading... </strong>
            
                <?php } ?>
           
          </div>
          
           <div class="sho_amount pl-10" >
                
                    <strong>Gross Revenue = </strong>
                    <?php if($url == 'agentincome' || $url == 'arincome' || $url=='adminincome' || $url=='adminincome_new'){ ?>
                
                        <strong id="gross_pay">$ <?php //echo (!empty($data['income_detail']->gross_pay)?$data['income_detail']->gross_pay:'0.0') ?> Loading...</strong>
                        
                         <?php }else{ ?>
           
                        <strong id="gross_pay">$ Loading...</strong>
            
                    <?php } ?>
                    
                    
                <?php //} ?> 
                </div>
          
            <?php  } ?>
          
            <div class="sho_amount pl-10" >
                
                <strong>Company Income = </strong>
                
                
                <?php if($url == 'agentincome' || $url == 'arincome' || $url=='adminincome' || $url=='adminincome_new'){ ?>
            
                    <strong id="total_incoe"> <?php //echo (!empty($data['income_detail']->total_income)?$data['income_detail']->total_income:0.0) ?>Loading...</strong>
                    
                     <?php }else{ ?>
       
                    <strong id="total_incoe">$ Loading... </strong>
        
                <?php } ?>
                
            </div>
            <?php } ?>
            
            <?php if(empty($_GET['income']) || $_GET['income']=='agent'){ ?>
            <div class="sho_amount pl-10" >
                
                <strong>Agent Income = </strong>
                
                
                <?php if($url == 'agentincome' || $url == 'arincome' || $url=='adminincome' || $url=='adminincome_new'){ ?>
            
                    <strong id="total_agincoe">$ Loading...</strong>
                    
                     <?php }else{ ?>
       
                    <strong id="total_agincoe">$ Loading... </strong>
        
                <?php } ?>
                
            </div>
            <?php } ?>
            <?php if($url == 'agentincome' || $url == 'arincome' || $url=='adminincome' || $url=='adminincome_new'){ 
            
            
            }else{ ?>
            <!--<div id="loader" style="margin-right: 30%;">-->
            <!--    please wait while calculating... -->
            <!--    <img src="https://i.gifer.com/ZZ5H.gif" style="width: 21px;">-->
            <!--</div>-->
            <?php } ?>
          
        </div>
      </div> 
      <div class="box-header">
        <form method="get" action="javascript:void(0);">
          @csrf
          <div class="row">
              
              <input type="hidden" name="reseturl" id="reseturl" value="<?php echo $data['reseturl']; ?>">            
              <div class="input_wraper col-md-4">
              <span class="dt-ser--lab">Client ID</span>
              <input type="text" id="client_id"  name="client_id" class="form-control dt-ser" placeholder="Enter Client ID" value="<?php if(isset($client_id)){echo $client_id;} ?>" autocomplete="off">
            </div>
            <div class="input_wraper col-md-4">
              <span class="dt-ser--lab">Client Name</span>
              <input type="hidden" value="{{ url('/search_client_name') }}" id="clientsearch">
              <input type="text" id="client_name"  name="client_name" class="form-control dt-ser" placeholder="Enter Client Name" value="<?php if(isset($client_name)){echo $client_name;} ?>" autocomplete="off">
              <div class="result search_new" style="width:340px; top:20px;"></div>
            </div>
          </div>
         <div class=" row">
            <div class="input_wraper col-md-4">
              <span class="dt-ser-lab">From</span>
              <input type="text" id="search_start_date"  name="search_start_date" class="form-control dt-ser" value="{{ showdateformate($search_start_date) }}" placeholder="Select start date" autocomplete="off">
            </div>
            <div class="input_wraper col-md-4">
              <span class="dt-ser-lab">To</span>
              <input type="text" id="search_end_date" name="search_end_date" class="form-control dt-ser" value="{{ showdateformate($search_end_date) }}" placeholder="Select end date" autocomplete="off">
              
            </div>
            <input type="hidden" id="page_no" name="page_no" value="<?php echo (!empty($_GET['page'])?$_GET['page']:1);?>" >
            
            
             
            <div class="col-md-4 text-right">
              <span class="pt-10 mt-10" style="display: inline-block;">
                <button type="button" name="search_agent" value="submit" class="top-btn btn btn-primary ser-btn" id="search_lead"><i class="fa fa-search"></i>Search</button>
                 
               
            <a href=""><button style="margin-left: 7px;" type="button" class="top-btn btn btn-primary ser-btn" id="search_reset"><i class="fa fa-search"></i>Reset</button></a>
               
                <!--<button style="margin-left: 7px;" type="button" class="top-btn btn btn-primary ser-btn" id="search_reset"><i class="fa fa-search"></i>Reset</button>-->
                 
              </span>
            </div>
         </div>
       </form>
        <?php if($url == 'agentincome' || $url == 'arincome' || $url=='adminincome'){ ?>
            <input type="hidden" id="ids" name="ids" value="<?php echo (!empty($data['income_detail']->lead_id)?($data['income_detail']->lead_id):'');?>" >
        <?php }else{ ?>
            <input type="hidden" id="ids" name="ids" value="">
        <?php } ?>
                
      </div>
      <?php
      
       //echo "<pre>";print_r(lead_calculate(22005)['agent_paid']); exit
      ?>
     
      
      <!--<a class="top-btn btn btn-primary ser-btn mb-10 ml-10" id="print_preview" onclick="getPDF('<?php //echo (!empty($outsatnginamt)?$outsatnginamt:''); ?>','<?php //echo (!empty($gross_pay)?array_sum($gross_pay):''); ?>','<?php //echo (!empty($total_incoe)?array_sum($total_incoe):''); ?>');"><i class="fa fa-print"></i> Preview/Print</a>-->
      
        <a class="top-btn btn btn-primary ser-btn mb-10 ml-10" id="print_preview_pdf" target="_blank">  <i class="fa fa-print"></i> Preview/Print </a>
      
       <a class="top-btn btn btn-primary ser-btn mb-10 ml-10" id="print_preview" onclick="get_PDF();"><i class="fa fa-download"></i>  Export CSV </a>
       
      <?php if(Auth::user()->user_role != AGENT){?>
        <a class="top-btn btn btn-primary ser-btn mb-10 ml-10" id="payroll" href="#" onclick="getpayroll()"><i class="fa fa-print"></i> Add PayRoll</a>
     <?php } ?>
      
      <div class="box-body">
        <div class="table_con">
        <table id="example2" class="table table-bordered table-hover" >
          <thead>
            <tr>
            <!--<th>Sr no.</th>-->
               
                <th><a href="javascript:void(0);">Client</a></th>
                <th><a href="javascript:void(0);">Client Name</a></th>
                <th>Res. commission($)</th>
                <th><a href="javascript:void(0);">Paid Amt. ($)</a></th>
                <th>payment Date</th>
                <th>Status</th>
                <th>Deduction($)</th>
                <th>Agent Income($)</th>
                <th>Company Income($)</th>
                <th><a href="javascript:void(0);">Paid Out</a></th>
              </tr>
        </thead>
         
        <tfoot>
            <tr>
                 <th></th>
           
                <th>Total</th>
                
                <th id="res_commission"></th>
                <th id="paid_amount"></th>
                <th></th>
                <th></th>
                <th id="total_deduction"></th>
                <th id="total_agent"></th>
                <th id="total_copany"></th>
                      
                 <th></th>
            </tr>
        </tfoot>
      </table>
    </div> 
       
  </div>
  
   
   <!-- /.box-body -->
  </div>
  <!-- /.box -->
</div>
</div>
</section>  
<div class="modal fade" id="modal-default">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span></button>
          <h4 class="modal-title">Get Payroll Detail</h4>
      </div>
      <input type="hidden" value="{{ url('/getPayRollDetail') }}" id="addurl" name="">
      <form name="savepayrollform" id="submitpayrolldata" method="POST" action="javascript:void(0);">

        <div class="modal-body" id="open_editform">
            <div class="row">
              <div class="col-md-6 col-sm-12 input_wraper">
                <span class="dt-ser-lab">From</span>
                <input type="text" id="payroll_start_date"  name="payroll_start_date" class="form-control dt-ser" value="" placeholder="Payroll start date" autocomplete="off">
              </div>
              <div class="col-md-6 col-sm-12 input_wraper">
                <span class="dt-ser-lab">To</span>
                <input type="text" id="payroll_end_date" name="payroll_end_date" class="form-control dt-ser" value="" placeholder="Payroll end date" autocomplete="off">
              </div>
            </div>
            <!-- row -->
        </div>
        <div class="modal-footer">
            
            <button type="button" id="submitpayrollformdownload" class="btn btn-primary">
            Download
          </button>
          <!--<button type="submit" id="submitpayrollform" class="btn btn-primary">
            {{ __('Print Preview') }}
          </button>-->
          <button type="button" class="btn btn-default pull-left" data-dismiss="modal">Close</button>
        </div>
      </form> 
    </div>
    <!-- /.modal-content -->
  </div>
  <!-- /.modal-dialog -->
</div>
<style>
    
    #table_datass >.table-bordered>tbody>tr>td:nth-child(2) {
       text-align: right;
    }
</style>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<div class="modal fade" id="showdeduct" role="dialog">
   <div class="modal-dialog showdocmodel" style="margin-left: 31%;">
      <div class="modal-content modal-sm" style="width: 60%;">
         <div class="modal-header" style="background: #3c8dbc;color: #fff;text-align: center;"><b>Deductions</b>
            <button type="button" class="close" data-dismiss="modal">&times;</button>            
         </div>
         <div class="modal-body" id="table_datass">
             
         </div>
         <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
         </div>
      </div>
   </div>
</div>

<!-- /.modal -->  
<div id="output" ></div>
<script type="text/javascript">
    function view_deduct(id){
        str = $('.ded_'+id).attr('str');
       
       $('#table_datass').html('<table class="table table-bordered" >'+str+'</table>');
    }
    
    function view_deduct1(id){
       
        str = $('.ded1_'+id).attr('str');
        
       $('#table_datass').html('<table class="table table-bordered" >'+str+'</table>');
    }
    
    
    
  $(function() {
        get_record();
    $("#search_start_date").datepicker({
      autoclose: true,
      changeMonth: true,
      dateFormat: 'mm-dd-yy'
    });

    $("#search_end_date").datepicker({
      autoclose: true,
      changeMonth: true,
      dateFormat: 'mm-dd-yy'
    });

    $("#payroll_start_date").datepicker({
      autoclose: true,
      changeMonth: true,
      dateFormat: 'mm-dd-yy'
    });

    $("#payroll_end_date").datepicker({
      autoclose: true,
      changeMonth: true,
      dateFormat: 'mm-dd-yy'
    });
    
        $('#search_lead').click(function(){
            get_record()
        })
         $('#search_reset').click(function(){
           // $("#client_id").val('');
            //$("#client_name").val('');
            //$("#search_start_date").val('');
            //$("#search_end_date").val('');
            //location.reload();
            //get_record()
        })
        
        
  });

  
function get_record(){
     
    var token = $("input[name=_token]").val();
    var Auth = <?php echo !empty(Auth::user()->id)?Auth::user()->id:''; ?>
    
    var client_id = $("#client_id").val();
    var client_name = $("#client_name").val();
    var search_start_date = $("#search_start_date").val();
    var search_end_date = $("#search_end_date").val();
    
    var income ='<?php echo(!empty($_GET['income'])?$_GET['income']:''); ?>';
    var income_url ='<?php echo(!empty(collect(request()->segments())->last())?collect(request()->segments())->last():''); ?>';    
    $('#example2').DataTable({
        order: [[0, 'desc']],
        "responsive": true,
        "destroy": true,
        "bProcessing": true,
        "bSorting":false,
        "bFilter": false,
        //"language": {
            //processing: '<i class="fa fa-spinner fa-spin fa-3x fa-fw" style="margin-top: -8%;"></i><span class="sr-only">Loading...</span> //'},
        "lengthMenu": [[25, 50, 100], [25, 50, 100]],
        "serverSide": true,
        "ajax":{
            url :"income_list",
            type: "post",
            data: {"_token": token,"reseturl":$('#reseturl').val(),client_id:client_id,client_name:client_name,search_start_date:search_start_date,search_end_date:search_end_date,income:income,income_url:income_url},
        },
        'columnDefs': [ {
            'targets': [2,4,6,7,8], 
            'orderable': false,
        }]
        ,
        drawCallback: function (settings) {
        
            var response = settings.json;
            
            total_data =response.total_data
            
            console.log(response);
            $('#ids').val('');
            $('#res_commission').html(response.total_data.rescommission)
            $('#paid_amount').html(response.total_data.gross_revenue)
            $('#total_deduction').html(response.total_data.deduction)
            
            
            $('#outsatnginamt').html(response.total_data.outstanding);
            $('#gross_pay').html(response.total_data.gross_revenue);
            
            $('#total_incoe').html(response.total_data.company_income);
            $('#total_agincoe').html(response.total_data.agent_income);
            $('#ids').val(response.total_data.id);
            
           
            $('#total_agent').html(response.total_data.agent_income)
            $('#total_copany').html(response.total_data.company_income)
                
            //$('#print_preview_pdf').attr('href',response.total_data.link)
                
        }
        ,
        "footerCallback": function ( row, data, start, end, display) {
            //console.log(total_data)
            var api = this.api(), data;
 
            // converting to interger to find total
            var intVal = function ( i ) {
                return typeof i === 'string' ?
                    i.replace(/[\$,]/g, '')*1 :
                    typeof i === 'number' ?
                        i : 0;
            };
 
            // computing column Total of the complete result 
            var monTotal = api
                .column( 1 )
                .data()
                .reduce( function (a, b) {
                    return intVal(a) + intVal(b);
                }, 0 );
				
	        var tueTotal = api
                .column( 2 )
                .data()
                .reduce( function (a, b) {
                    return intVal(a) + intVal(b);
                }, 0 );
				
            var wedTotal = api
                .column( 3 )
                .data()
                .reduce( function (a, b) {
                    return intVal(a) + intVal(b);
                }, 0 );
				
	     
				
	        var friTotal = api
                .column( 6 )
                .data()
                .reduce( function (a, b) {
                    return intVal(a) + intVal(b);
                }, 0 );
			
				
            // Update footer by showing the total with the reference of the column index 
	       // $( api.column( 0 ).footer() ).html('Total');
        //     $( api.column( 1 ).footer() ).html(monTotal);
        //     $( api.column( 2 ).footer() ).html(tueTotal);
        //     $( api.column( 3 ).footer() ).html(wedTotal);
        //     $( api.column( 6 ).footer() ).html(friTotal);
        }
    });
    
    $('#example2').on('draw.dt', function () {
        $('.popoverData').popover({ trigger: "hover" });
        $('[data-toggle="tooltip"]').tooltip();
    });
    
    $('#example2').on('page.dt', function() {
        $('html, body').animate({
            scrollTop: $(".dataTables_wrapper").offset().top
        }, 'slow');
    });
}
  
  
  
 
  function method(){
    var loc       = window.location.href;
    var pathName  = loc.split("/");
    var len       = pathName.length-1;
    var actual    = pathName[len].split('?');
    return actual[0];
  }
  

function get_PDF(){
    var client_id = $('#client_id').val();
    var start_date = $('#search_start_date').val();
    var end_date = $('#search_end_date').val();
    var client_name = $('#client_name').val();
    var income = '<?php echo (!empty($_GET['income'])?$_GET['income']:'');?>';
    var income_url ='<?php echo(!empty(collect(request()->segments())->last())?collect(request()->segments())->last():''); ?>';
    
    baeurl = '<?php echo url('/');?>/download_income';
    
    var url = baeurl+'?start_date='+start_date+'&end_date='+end_date+'&client_id='+client_id+"&client_name="+client_name+'&income='+income+'&income_url='+income_url;
    
    window.open(url, "_blank");
}
  
    
$("#print_preview_pdf").click(function(e){
    var client_id = $('#client_id').val();
    var start_date = $('#search_start_date').val();
    var end_date = $('#search_end_date').val();
    var client_name = $('#client_name').val();
    var income = '<?php echo (!empty($_GET['income'])?$_GET['income']:'');?>';
    var income_url ='<?php echo(!empty(collect(request()->segments())->last())?collect(request()->segments())->last():''); ?>';
    
    baeurl = '<?php echo url('/');?>/download_income_pdf';
    
    var url = baeurl+'?start_date='+start_date+'&end_date='+end_date+'&client_id='+client_id+"&client_name="+client_name+'&income='+income+'&income_url='+income_url;
    
    window.open(url, "_blank");
});
   
$("#submitpayrollform").click(function(e){
    
    if($('#payroll_start_date').val() && $('#payroll_end_date').val() ){
        $('#output').html('<img src="{{ url('public/images/LoaderIcon.gif') }}" />').css({"display": "block", "z-index": "99999","margin-top":"12%"});
        
        getpayrolldataraj();
        
    }else{
       swal("Please select Start/End Date"); return false; 
    }
    //
    
    // alert($('#addurl').val());
    // $("form[name='savepayrollform']").validate({
    //   rules: {
    //     payroll_start_date: "required",
    //     payroll_end_date: "required"
    //   },
     
    //   messages: {
    //     payroll_start_date: "Please select Start Date",
    //     payroll_end_date:"Please select End Date"
    //   },
      
    //   submitHandler: function(form) {
    //     getpayrolldataraj();
    //     $('#output').html('<img src="{{ url('public/images/LoaderIcon.gif') }}" />');
    //   }
    // });
});
   
   
 $("#submitpayrollformdownload").click(function(e){
  
    var start_date=document.getElementById('payroll_start_date').value;
    var  end_date=document.getElementById('payroll_end_date').value;
    
    if(start_date && end_date){
        var url = '<?php echo url('/'); ?>/downloadpayroll?start_date='+start_date+'&end_date='+end_date;
        window.open(url, "_blank");
    }
});

  function getpayrolldataraj(){
  
    $.ajaxSetup({
      headers: {
       'X-XSRF-Token': $('meta[name="_token"]').attr('content')
      }
    });
        
   // $('#output').css('display','');
    var start_date=document.getElementById('payroll_start_date').value;
    var  end_date=document.getElementById('payroll_end_date').value;
    var url = $('#addurl').val(); 
    
    $.ajax({
      type:'POST',
      url:url,
      data: {payroll_start_date:start_date,payroll_end_date:end_date},
      success:function(data){
        $('#output').css('display','none');
        data=JSON.parse(data);
        console.log(data.link);
        window.open(data.link);
      }
    });
  }  
        
  $(function() {

      $("#search_start_date").datepicker({
        autoclose: true,
        changeMonth: true,
        dateFormat: 'mm-dd-yy'
      });

      $("#search_end_date").datepicker({
        autoclose: true,
        changeMonth: true,
        dateFormat: 'mm-dd-yy'
      });

      $("#payroll_start_date").datepicker({
        autoclose: true,
        changeMonth: true,
        dateFormat: 'mm-dd-yy'
      });

      $("#payroll_end_date").datepicker({
        autoclose: true,
        changeMonth: true,
        dateFormat: 'mm-dd-yy'
      });
  });

  //get client name list ajax function date 12_2_20 by Vinod M
  $('#client_name').keyup(function(e){
    /* Get input value on change */
    var key       = e.keyCode;
    var inputVal  = $(this).val();
    if(inputVal){

      var resultDropdown = $(this).siblings(".result");
      if(inputVal.length){
        resultDropdown.html('');
        var url = $('#clientsearch').val();  
        $.ajax({
          type:'GET',
          url:url,
          data:{inputVal:inputVal},
          success:function(data){
            resultDropdown.html(data);
          }
        });
      } else{
        resultDropdown.empty();
      }
    }
  });

  // Set search input value on click of result item
  $(document).on("click", ".result p", function(){
    var $valsel = $(this).text();
    $('#client_name').val($(this).text());
    $(".result").empty();
  });
  
  function get_total_income(){
     $.ajaxSetup({
      headers: {
       'X-XSRF-Token': $('meta[name="_token"]').attr('content')
      }
    });
        //$("#print_preview").attr("disabled", true)
        //$("#payroll").attr("disabled", true)
        
    var url = '<?php echo url('/'); ?>/adminincomejson';
    $('#output').css('display','');
    $('.overlay').css('display','');
    $('#output').html('<img src="{{ url('public/images/LoaderIcon.gif') }}" />');
    
    var client_id = $('#client_id').val();
    var search_start_date = $('#search_start_date').val();
    var search_end_date = $('#search_end_date').val();
    var client_name = $('#client_name').val();
    var page_no = $('#page_no').val();
    var pagin = $('#pagin').val();
    var ids = $('#ids').val();
      
    $('#output').hide()
    
    $.ajax({
      type:'POST',
      url:url,
      data:{'method':method(),client_id:client_id,search_start_date:search_start_date,search_end_date:search_end_date,client_name:client_name,page_no:page_no,pagin:pagin,ids:ids},
      dataType:'json' ,
      success:function(data){
           $('#loader').hide()
            //$("#print_preview").attr("disabled", false)
            //$("#payroll").attr("disabled", false)
      //var data = JSON.parse(data);
        console.log(data.gross_pay); 
        $('#gross_pay').text('$ '+data.gross_pay)
        
            $('#total_incoe').text('$ '+data.total_incoe)
            $('.total_incoe').text('$ '+data.total_incoe)
        
        //if(data.outsatnginamt>0){
              $('#outsatnginamt').text('$ '+data.outsatnginamt)
               $('#outsatnginamt').text('$ '+data.outsatnginamt)
        // }else{
        //     $('#outsatnginamt').text('$ 0.00')
        // }
        
        if(method()=='outstand'){
            alert('Here')
        }
      
        $('#ids').val(data.ids)
        
      }
    });
 }
  
</script>
<style>
  .search_fild{
    width: 85%;
    float: left;
  }
  .dt-ser{
    float: left;
    width: 25%;
  }
  .dt-ser-lab{
    float: left;
    width: 10%; 
    text-align: center;
  }
  .dt-ser-btn{
    float: left;
    width: 30%; 
    text-align: center;
  }
  .ser-btn{
    float: left;
    margin-left: 34px;
  }

  .show_amount_detail{
    width: 85%;
    float: right;
  }
  .sho_amount{
    width: 45%;
    float: right;
    font-size: 18px;
  }
  #output{
    min-height:300px;
    border:#fffff 1px solid;
    padding:15px;
    position:absolute;
    top:0;
    margin-top:18%;
    margin-left:30%;
    text-align:center;
  }
</style>
@endsection

