 <?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="#">Manage Using</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 Manage Using</h3>
           </div>
         </div>

       </div>
     </div>
   </div>
   <form action="<?php echo e(route('construction-report.ManageUsingReport')); ?>" 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','onchange'=>'get_warehouse(this)']); ?>

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

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

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

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

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

           </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>Project Name</th>
              <th>Warehouse</th>
              <th>Zone</th>
              <th>House</th>
              <th>Product Name</th>
              <th>Category</th>
              <th>Sub Category</th>
              <th>Quantities</th>
              <th>Unit Name</th>
           </tr>
         </thead>
         <tbody class="tbody"></tbody>
         <tfoot class="tfoot">
          <tr>
            <td colspan="9" class="text-right">Total :</td>
            <td style="text-align: left;"></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,
             "serverSide":true,
             "scrollY":"600px",
            "scrollCollapse": true,
             lengthMenu: [[20, 30, 50, 100,200,500,1000], [20, 30, 50, 100,200,500,1000]],
             ajax: {
               url:"<?php echo e(route('construction-report.ManageUsingReport')); ?>",
               type:"GET",
               data:function(d){
                d.warehouses = $(".warehouses").val();
                d.projects = $(".projects").val();
                d.categories = $(".categories").val();
                d.products = $(".products").val();
                d.start_date = $(".start_date").val();
                d.end_date = $(".end_date").val();
                d.zones = $(".zones").val();
                d.house_numbers = $(".house_numbers").val();
               }
             },
             columns: [
                  {
                     data: 'DT_RowIndex'
                 },
                 {
                     data:'date'
                 },
                 {
                     data: 'project_name'
                 },
                 {
                     data: 'warehouse_name'
                 },
                 {
                     data: 'zone_name'
                 },
                 {
                    data: 'house_name'
                 },
                 {
                    data:'product_name'
                 },
                 {
                    data: 'product_category_name'
                 },
                 {
                     data: 'sub_category'
                 },
                 {
                     data: 'product_use_qty'
                 },
                 {
                     data: 'unit_name'
                 },
             ],

             "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 = api
                .column(9)
                .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));
            },
         });
     });
     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(); ?>