<?php $__env->startSection('content'); ?>
<link rel="stylesheet" href="<?php echo e($url); ?>/abserve/css/jquery.dataTables.min.css">
<link rel="stylesheet" href="<?php echo e($url); ?>/abserve/css/dataTables.jqueryui.min.css">
<script type="text/javascript" src="<?php echo e(asset('abserve/js/plugins/chartjs/Chart.min.js')); ?>"></script>
<script src="<?php echo e($url); ?>/abserve/js/jquery.dataTables.min.js" type="text/javascript"></script>
<script src="<?php echo e($url); ?>/abserve/js/dataTables.jqueryui.min.js" type="text/javascript"></script>
<style type="text/css">
            input[type="search"]
            {
                -webkit-appearance :searchfield;
            }
            label {
                padding-left : 16px;
                font-weight :normal;
            }
            .lab_names,.site_names{
                width:200px;
            }
            .theme-config
            {
                display:none;
            }
</style>
<div class="page-content row">
    <div class="page-header">
            <div class="page-title">
            <h3> Weekly Report <small> Weekly Report </small></h3>
            </div>
            <ul class="breadcrumb">
            <!--  <li>
            <a href="<?php echo e(URL::to('dashboard')); ?>"> Dashboard </a></li> -->
            <li class="active">Weekly Report</li>
            </ul> 
          
    </div>
    <div class="page-content-wrapper">  
            <div class="sbox-title"> <h5> <i class="fa fa-table"></i>Weekly Report </h5>
                    <div>

                    <a href="<?php echo e(url()); ?>/weekly_report" class="btn btn-xs btn-white tips" title="Clear Search" style="float:  right;" ><i class="fa fa-trash-o"></i> </a>

                    </div>
            </div>
    
    <?php if(Auth::check() && Auth::user()->group_id == 1): ?>

        <form action="<?php echo url();?>/weekly_report/index" class="Book_avail">
                <input type="hidden" class="hidden_url" value="<?php echo url();?>/weekly_report/index">
                <input type="hidden" class="show_from_date" value="<?php echo e($show_from_date); ?>">
                <input type="hidden" class="show_to_date" value="<?php echo e($show_to_date); ?>">

                <div class="sbox-content">     
                <div class="toolbar-line "> 
                <label><input type="text" id="dt1" placeholder="From" required="required" class="form-control"></label>
                <label><input type="text" id="dt2" placeholder="To" class="form-control"></label>
                <label><input type="submit" value="Submit" class="submit_search tips btn btn-sm btn-success"/></label>


                <?php if($show_from_date): ?>
                <label><a href="javascript:void(0);" class="downloadfile" title="<?php echo e(Lang::get('core.btn_download')); ?>"><i class="fa fa-download"></i>&nbsp;<?php echo e(Lang::get('core.btn_download')); ?> </a></label>
                <label><a href="javascript:void(0);" class="printfile" title="Print">Print </a></label>
                <?php if($show_clear == '1'): ?>
                <label><a href="<?php echo url();?>/weekly_report"/>Search this week</a></label>
                <?php 
                $url_param='';
                $url_param.='from='.$show_from_date;
                $url_param.='&to='.$show_to_date;
                ?>
<!-- <a href="<?php //echo url().'/salary_week_report?'.$url_param;?>" target="_blank" class="print_hide" style="clear:both;display:block;margin:0px 0 0 555px;display:none;">Same Search with Salary</a> -->
                <?php endif; ?> 
                <?php endif; ?> 
                </div>
        </form>

<?php if(!empty($show_from_date) || !empty($show_to_date)) { ?>
        <div id="second">
                <table class="print_show">
                <tr><td>From Date:</td><td><?php echo e($show_from_date); ?></td></tr>
                <tr><td>To Date:</td><td><?php echo e($show_to_date); ?></td></tr>
                </table>
                <br>
        </div>


                <div class="table-responsive" style="">
                            <table id="example" class="table table-striped"  style="">
                                    <thead>
                                        <tr>
                                        <th>S.No</th>
                                        <th>Site Name</th>
                                        <th>Labour</th>
                                        <th>Salary</th>
                                        <th>Official Cost</th>
                                        <th>Expenses</th>
                                        <th>Outwards</th>
                                        <th>Returns</th>
                                        <th>Materials</th>
                                        <th>Total</th>
                                        </tr>
                                    </thead>
                                     <tbody>
                        <?php
                        if($result_all){
                            $from_date_ex = explode('-',$show_from_date);
$from_date_day = (int)$from_date_ex[0];
$from_date_month = (int)$from_date_ex[1];
$from_date_year = $from_date_ex[2];
if($from_date_day<10){
    $from_date_day='0'.$from_date_day;
} 
if($from_date_month <10){
    $from_date_month ='0'.$from_date_month ;
}
$search_from_date = $from_date_year.'-'.$from_date_month.'-'.$from_date_day;

$to_date_ex = explode('-',$show_to_date);
$to_date_day = (int)$to_date_ex[0];
$to_date_month = (int)$to_date_ex[1];
$to_date_year = $to_date_ex[2];
if($to_date_day<10){
    $to_date_day='0'.$to_date_day;
} 
if($to_date_month <10){
    $to_date_month ='0'.$to_date_month ;
}
$search_to_date = $to_date_year.'-'.$to_date_month.'-'.$to_date_day;
$rec=0;
$all_tot_amt = $tot_labour_count = $tot_official_cost=$tot_site_expense=$tot_site_salary=$tot_matout_amount=$tot_matret_amount=$tot_mat_amt=0;
foreach ($result_all as $site_id=>$result) {
    $rec++;
    if(empty($result['matout_amount'])){
        $result['matout_amount']=0;
    }
    if(empty($result['matret_amount'])){
        $result['matret_amount']=0;
    }
    
    $tot_labour_count += $result['labour_count'];
    $tot_official_cost += $result['official_cost'];
    $tot_site_expense += $result['site_expense'];
    $tot_site_salary += $result['tot_site_salary'];
    $tot_matout_amount += $result['matout_amount'];
    $tot_matret_amount += $result['matret_amount'];

    $mat_final = (float)$result['matout_amount'] - (float)$result['matret_amount'];

    $tot_row_amt = (float)$result['official_cost']+(float)$result['site_expense']+(float)$result['tot_site_salary']+ $mat_final;

    $tot_mat_amt += $mat_final;
    
    $all_tot_amt +=$tot_row_amt;
    $tot_site = $rec;
    echo '<tr>
                                                <td>'.$rec.'</td><!-- ID-->
                                                <td>'.$result['sitename'].'</td><!-- Site Name-->
                                                <td><a href="'.url().'/salary/index?site_name='.$result['sitename'].'&labour_selcted_name=&from='.$show_from_date.'&to='.$show_to_date.'" target="_blank">'.$result['labour_count'].'</a></td><!-- No of Labour-->
                                                <td><a href="'.url().'/salary/index?site_name='.$result['sitename'].'&labour_selcted_name=&from='.$show_from_date.'&to='.$show_to_date.'" target="_blank">'.$result['tot_site_salary'].'</a></td><!-- Labour Salary-->
                                                <td><a href="'.url().'/salary/index?site_name='.$result['sitename'].'&labour_selcted_name=&from='.$show_from_date.'&to='.$show_to_date.'" target="_blank">'.$result['official_cost'].'</a></td><!-- Site Amount-->
                                                <td><a href="'.url().'/salary/index?site_name='.$result['sitename'].'&labour_selcted_name=&from='.$show_from_date.'&to='.$show_to_date.'" target="_blank">'.$result['site_expense'].'</a></td><!-- Site Expense-->
                                                <td><a href="'.url().'/materialoutwards?search=date:between:'.$search_from_date.':'.$search_to_date.'|site:equal:'.$site_id.'|" target="_blank">'.$result['matout_amount'].'</a></td><!-- Outwards-->
                                                <td><a href="'.url().'/materialreturns?search=date:between:'.$search_from_date.':'.$search_to_date.'|site:equal:'.$site_id.'|" target="_blank">'.$result['matret_amount'].'</a></td><!-- Returns-->
                                                <td>'.$mat_final.'</td><!-- Material-->
                                                <td>'.$tot_row_amt.'</td>
                                            </tr>';
} }?>
                                               </tbody>
                            </table> </div>
                            <br><br>
                            <ul id="report_all" class="table table-striped"  style="list-style: none;">
                            <li style="list-style: none;height: 20px;clear: both;"></li>
                            <li style="list-style: none;clear: both;"><span class="col-md-3"><b>Worked Sites:</b></span><span class="col-md-9"><b><?php echo e($tot_site); ?></b></span></li>
                            <li style="list-style: none;clear: both;"><span class="col-md-3"><b>Total Labour:</b></span><span class="col-md-9"><b><?php echo e($tot_labour_count); ?></b></span></li>
                            <li style="list-style: none;clear: both;"><span class="col-md-3"><b>Total Salary:</b></span><span class="col-md-9"><b>Rs.<?php echo e($tot_site_salary); ?></b></span></li>
                            <li style="list-style: none;clear: both;"><span class="col-md-3"><b>Total Official Cost:</b></span><span class="col-md-9"><b>Rs.<?php echo e($tot_official_cost); ?></b></span></li>
                            <li style="list-style: none;clear: both;"><span class="col-md-3"><b>Total Expenses:</b></span><span class="col-md-9"><b>Rs.<?php echo e($tot_site_expense); ?></b></span></li>
                            <li style="list-style: none;clear: both;"><span class="col-md-3"><b>Total Materials (Outwards-Returns):</b></span><span class="col-md-9"><b>Rs.<?php echo e($tot_mat_amt); ?> ( Rs.<?php echo e($tot_matout_amount); ?> - Rs.<?php echo e($tot_matret_amount); ?> )</b></span></li>
                            <li style="list-style: none;clear: both;"><span class="col-md-3"><b>Overall Amount:</b></span><span class="col-md-9"><b>Rs.<?php echo e($all_tot_amt); ?></b></span></li></ul>
        <?php } ?>

    <?php endif; ?> 

</div></div>
<script type="text/javascript">
function printData()
{
   var divToPrint=document.getElementById("example");
   var content2=document.getElementById("second");
   var report_all=document.getElementById("report_all");
   newWin= window.open("");
   newWin.document.write(content2.innerHTML+divToPrint.outerHTML+report_all.innerHTML);
   newWin.print();
   newWin.close();
}
    $(document).ready(function () {
        jQuery('.printfile').click( function() {
            printData();
        });


         jQuery('.downloadfile').click( function() {
         /*var site_selcted_name= $( '.site_names option:selected').val();
        var labour_selcted_name= $( '.lab_names option:selected').val();*/

        var from_filter = $('#dt1').val();
        var to_filter = $('#dt2').val();
        var url = '<?php echo url();?>/weekly_report/downloadfile'; 
       /* if(site_selcted_name== 'select')
        {
            site_selcted_name ='';
        }
        if(labour_selcted_name == 'select')
        {
            labour_selcted_name ='';
        }*/

        // if((from_filter !== '') && (to_filter == ''))
        // {
        //  alert("Please select from and to dates");
        //  return false;

        // }
        if((to_filter !== '') && (from_filter == ''))
        {
            alert("Please select from date");
            return false;

        }

        if(from_filter == '')
        {
            from_filter ='';
        }
        if(to_filter == '')
        {
            to_filter ='';
        }

   url += '?from='+from_filter+'&to='+to_filter
   
window.location.href = url;
 return false;   
         });
        
        /*$('.site_names').select2();
        $('.lab_names').select2();*/
       
 $('#example').DataTable( {
       "aaSorting": [[ 0, "asc" ]],
       "iDisplayLength": 100
    } );

        //$('#example').dataTable();
       /* $('.site_names').select2('val', $('.show_site_name').val());
        $('.lab_names').select2('val', $('.show_labour_name').val());*/
        $('#dt1').val($('.show_from_date').val());
        $('#dt2').val($('.show_to_date').val());


        $("#dt1").datepicker({
           format: 'dd-mm-yyyy',
            minDate: 0,
            onSelect: function (date) {
                var dt2 = $('#dt2');
                var startDate = $(this).datepicker('getDate');
                var minDate = $(this).datepicker('getDate');
                dt2.datepicker('setDate', minDate);
                startDate.setDate(startDate.getDate() + 30);
                //sets dt2 maxDate to the last day of 30 days window
                dt2.datepicker('option', 'maxDate', startDate);
                dt2.datepicker('option', 'minDate', minDate);
                $(this).datepicker('option', 'minDate', minDate);
            }
        });
        $('#dt2').datepicker({
           format: 'dd-mm-yyyy',
        });

        jQuery('.Book_avail').submit( function() {
       /* var site_selcted_name= $( '.site_names option:selected').val();
        var labour_selcted_name= $( '.lab_names option:selected').val();*/

        var from_filter = $('#dt1').val();
        var to_filter = $('#dt2').val();
        var url = $('.hidden_url').val(); 
        /*if(site_selcted_name== 'select')
        {
            site_selcted_name ='';
        }
        if(labour_selcted_name == 'select')
        {
            labour_selcted_name ='';
        }*/

        // if((from_filter !== '') && (to_filter == ''))
        // {
        //  alert("Please select from and to dates");
        //  return false;

        // }
        if((to_filter !== '') && (from_filter == ''))
        {
            alert("Please select from date");
            return false;

        }

        if(from_filter == '')
        {
            from_filter ='';
        }
        if(to_filter == '')
        {
            to_filter ='';
        }

   url += '?from='+from_filter+'&to='+to_filter
   
window.location.href = url;
 return false;
});
    });

    
</script>
<style>
#report_all li{list-style: none;}
.rows.clearfix label {
    font-weight: bold;
}
.print_hide{display:block !important;}
.print_show{display:none;}
</style>

<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.app', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>