 <?php $__env->startSection('content'); ?>
 <?php Fun::lang() ?>
 <div class="title-page">
   <div class="page-bar">
     <ul class="page-breadcrumb">
       <li><a href="#"><i class="fa fa-dashboard"></i> Dashboard</a></li>
       <li><a href="#">Reports</a></li>
       <li><a href="#">Report Construction</a></li>
       <li><a href="#">Summary Payment</a></li> 
     </ul>
   </div>
 </div>
 <div class="page">
   <div class="top-content">
     <div class="row">
       <div class="col-sm-12 col-xs-12">
         <div class="title-add">
           <div class="pull-left">
             <h3>Report Summary Payment Contractor</h3>
           </div>
         </div>

       </div>
     </div>
   </div>
   <form action="<?php echo e(route('construction-report.ConstructorPayment')); ?>" method="POST">
     <?php echo csrf_field(); ?>
     <div class="form-search">
       <div class="row">
        <div class="col-xs-12 col-sm-4 col-md-4 ">
            <div class="form-group">
              <strong>Form Date</strong>
              <?php echo Form::text('start_date', null, array('placeholder' => 'Start Date','class' => 'form-control date_picker start_date','autocomplete' => 'off')); ?>

            </div>
          </div>
          <div class="col-xs-12 col-sm-4 col-md-4 ">
            <div class="form-group">
              <strong>To Date</strong>
              <?php echo Form::text('end_date', null, array('placeholder' => 'End Date','class' => 'form-control date_picker end_date','autocomplete' => 'off')); ?>

            </div>
          </div>
         <div class="col-xs-12 col-sm-4 col-md-4 ">
           <div class="form-group">
             <strong>Project</strong>
             <?php echo Form::select('projects', $projects, null, ['class' => 'form-control select2 projects']); ?>

           </div>
         </div>
         <div class="col-xs-12 col-sm-4 col-md-4 ">
           <div class="form-group">
             <strong>Contractor</strong>
             <?php echo Form::select('constructors',  $constructors, null, ['class' => 'form-control select2 constructors']); ?>

           </div>
         </div>
         <div class="col-xs-12 col-sm-4 col-md-4 ">
          <div class="form-group">
            <strong>Zone Name</strong>
            <?php echo Form::select('zone_names',$zones ,null, ['class' => 'form-control zone_names select2']); ?>

          </div>
        </div>
        <div class="col-xs-12 col-sm-4 col-md-4 ">
          <div class="form-group">
            <strong>Work Group</strong>
            <?php echo Form::select('work_group',$work_groups ,null, ['class' => 'form-control work_group select2','placeholder'=>'Please Select']); ?>

          </div>
        </div>
         <div class="col-xs-12 col-sm-12 col-md-12 text-right">
           <button type="button" class="button_primary btn-sm search" onclick="searching()"><span class="fa fa-search"> Search</span></button>&nbsp
           <button type="submit" class="button_primary btn-sm search"><span class="fa fa-print"> Print</span></button>
         </div>
       </div>
     </div>
     <?php echo Form::close(); ?>

     <div class="box-body table-responsive">
       <table id="origin-stock-datatable" class="table table-striped table-bordered table-hover nowrap" width="100%">
         <thead>
           <tr>
            <th>No</th>
              <th>Date</th>
              <th>Contractor</th>
              <th>Project</th>
              <th>Zone Name</th>
              <th>Type of house</th>
              <th>Date Start Work</th>
              <th>Duration</th>
              <th>Work Group</th>
              <th>Total Amount</th>
              <th>Paid Amount</th>
              <th>Paid Cash Advance</th>
              <th>Balance Amount</th>
              <th>Bunous</th>
              <th>Penalty</th>
           </tr>
         </thead>
         <tbody class="tbody"></tbody>
         <tfoot class="tfoot">
            <tr>
              <td colspan="9" class="text-right">Total :</td>
              <td></td>
              <td></td>
              <td></td>
              <td></td>
              <td></td>
              <td></td>
            </tr>
          </tfoot>
       </table>
     </div>
 </div>
 <?php $__env->stopSection(); ?> <?php $__env->startSection('js'); ?>
 <script type="text/javascript">
    function get_warehouse(obj){
        $("#main-spinner").show();
        var route = "<?php echo e(route('get_warehouse_by_project',':id')); ?>";
        route = route.replace(":id",$(obj).val());
        $.ajax({
            url:route,
            type:"GET",
            dataType:"JSON",
            success:function(data)
            {
                var opt = `<option value="">Please Select Option</option>`;
                $.each(data,function(index,value)
                {
                    opt += `<option value = "${value.id}">${value.name}</option>`;
                });
                $(".warehouses").html(opt);
            },
            complete:function()
            {
                $("#main-spinner").hide();
            }
        });
    }
     $(document).ready(function() {
         $('#main-spinner').show();
           $('#origin-stock-datatable').DataTable({
             ordering: false,
             "searching":false,
             "scrollY":"600px",
            "scrollCollapse": true,
             "serverSide":true,
             "scrollX": true,
             lengthMenu: [[20, 30, 50, 100,200,500,1000], [20, 30, 50, 100,200,500,1000]],
             ajax: {
               url:"<?php echo e(route('construction-report.ConstructorPayment')); ?>",
               type:"GET",
               data:function(d){
                d.projects = $(".projects").val();
                d.start_date = $(".start_date").val();
                d.end_date = $(".end_date").val();
                d.constructors = $(".constructors").val();
                d.zone_names = $(".zone_names").val();
                d.type_houses = $(".type_houses").val();
                d.work_group = $(".work_group").val();
               }
             },
             columns: [
                  {
                     data: 'DT_RowIndex'
                 },
                 {
                     data:'date'
                 },
                 {
                     data:'constructor_name'
                 },
                 {
                     data: 'project_name'
                 },
                 {
                     data: 'block_name'
                 },
                 {
                     data: 'type_of_house'
                 },
                 {
                    data: 'start_work_date'
                 },
                 {
                    data:'duration'
                 },
                 {
                    data: 'work_group'
                 },
                 
                 {
                    data: 'total_amount'
                 },
                 
                 {
                    data: 'total_paid_amount'
                 },
                 {
                    data: 'total_cash_advance'
                 },
                 
                 {
                    data: 'total_balance_amount'
                 },
                 
                 {
                    data: 'total_bonus'
                 },
                 
                 {
                    data: 'total_penalty'
                 },
             ],

             "initComplete": function(settings, json) {
                 $('#main-spinner').hide();
             },
             "footerCallback": function(row, data, start, end, display) {
                var api = this.api(),
                data;
                var intVal = function(i) {
                return typeof i === 'string' ?
                    i.replace(/[\$,]/g, '') * 1 :
                    typeof i === 'number' ?
                    i : 0;
                };

                var total_amount = api
                .column(9)
                .data()
                .reduce(function(a, b) {
                    return intVal(a) + intVal(b);
                }, 0);

                var total_paid = api
                .column(10)
                .data()
                .reduce(function(a, b) {
                    return intVal(a) + intVal(b);
                }, 0);

                var total_cash_advance = api
                .column(11)
                .data()
                .reduce(function(a, b) {
                    return intVal(a) + intVal(b);
                }, 0);

                var total_balance= api
                .column(12)
                .data()
                .reduce(function(a, b) {
                    return intVal(a) + intVal(b);
                }, 0);

                var total_bunous = api
                .column(13)
                .data()
                .reduce(function(a, b) {
                    return intVal(a) + intVal(b);
                }, 0);

                var total_penalty = api
                .column(14)
                .data()
                .reduce(function(a, b) {
                    return intVal(a) + intVal(b);
                }, 0);

                var numFormat = $.fn.dataTable.render.number('\,', '.', 2, '$').display;
                $(api.column(9).footer()).html(numFormat(total_amount));
                $(api.column(10).footer()).html(numFormat(total_paid));
                $(api.column(11).footer()).html(numFormat(total_cash_advance));
                $(api.column(12).footer()).html(numFormat(total_balance));
                $(api.column(13).footer()).html(numFormat(total_bunous));
                $(api.column(14).footer()).html(numFormat(total_penalty));
            },
         });
     });
     function searching(){
      $('#origin-stock-datatable').DataTable().draw(true);
     }
 </script>
 <?php $__env->stopSection(); ?>
<?php echo $__env->make('adminlte::page', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>