<?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> Attendance Report <small> Attendance Report </small></h3>
	  </div>
	   <ul class="breadcrumb">
       <!--  <li>
        <a href="<?php echo e(URL::to('dashboard')); ?>"> Dashboard </a></li> -->
        <li class="active">Attendance Report</li>
      </ul>	
		  
	</div>
	<div class="page-content-wrapper">  
	<div class="sbox-title"> <h5> <i class="fa fa-table"></i> Attendance Report </h5>
<div>

		<a href="<?php echo e(url()); ?>/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();?>/report/index" class="Book_avail">
	 <input type="hidden" class="hidden_url" value="<?php echo url();?>/report/index">
	  <input type="hidden" class="show_labour_name" value="<?php echo e($show_labour_name); ?>">
	 <input type="hidden" class="show_site_name" value="<?php echo e($show_site_name); ?>">
	 <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" class="form-control"></label>
     <label>
<input type="text" id="dt2" placeholder="To" class="form-control"></label>
 <label>
<select class="site_names">
<option value="select">Select Site</option>
 <?php foreach($site_names as $site): ?>
 
<option name="site_option" value="<?php echo e($site->site_name); ?>"><?php echo e($site->site_name); ?></option>  
	<?php endforeach; ?> 
	</select></label>
	 <label>
<select class="lab_names">
<option value="select">Select Labour Name</option>
 <?php foreach($labour_names as $lab): ?>
<option name="lab_names_option" value="<?php echo e($lab->username); ?>"><?php echo e($lab->username); ?></option>  
	<?php endforeach; ?> 
	</select></label>
<label>
<input type="submit" value="Submit" class="submit_search tips btn btn-sm btn-success"/></label>
<?php if(!empty($show_labour_name) || !empty($show_site_name) || !empty($show_from_date) || !empty($show_to_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();?>/report"/>Clear Search</a></label>
<?php endif; ?> 
<?php } ?>
</div>
</form>

<?php if(!empty($show_labour_name) || !empty($show_site_name) || !empty($show_from_date) || !empty($show_to_date)) { ?>
<div id="second">
<table class="print_show">
<tr><td>Site Name:</td><td><?php echo e($show_site_name); ?></td></tr>
<tr><td>Labour:</td><td><?php echo e($show_labour_name); ?></td></tr>
<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 class="rows clearfix" style="margin-bottom:10px;">
<div class="col-md-6">
<div>
<label>Total Official Cost :</label>
<label>Rs . <?php echo e($sum_official_cost); ?></label>
</div>
<div>
<label>Total Man power :</label>
<label><?php echo e($total_man_power); ?></label>
</div>
<div>
<label>Actual Working Days :</label>
<label><?php echo e($working_days); ?></label>
</div>
</div>

<div class="col-md-6">
<?php $url_param='';
$url_param.='site_name='.$show_site_name;
$url_param.='&labour_selcted_name='.$show_labour_name;
$url_param.='&from='.$show_from_date;
$url_param.='&to='.$show_to_date;
?>
<a href="<?php echo url().'/salary?'.$url_param;?>" target="_blank" class="print_hide" style="clear:both;display:block;margin:20px 0 0 10px;display:none;">Same Search with Salary</a>
</div>

</div>

</div>
<br>
<div>
    <?php $tabs = array(
    ''      => 'Detailed View',
    'count' => 'Count Based View',
    );

    ?>

    <ul class="nav nav-tabs" >
        <?php foreach($tabs as $key=>$val): ?>
        <li  <?php if($key == $_GET['type']): ?> class="active" <?php endif; ?>><a href="<?php echo e(URL::to('report?site_name='.$_GET['site_name'].'&labour_selcted_name='.$_GET['labour_selcted_name'].'&from='.$_GET['from'].'&to='.$_GET['to'].'&type='.$key)); ?>"> <?php echo e($val); ?>  </a></li>
        <?php endforeach; ?>

    </ul>

</div>
<div class="tab-content m-t">
  <div class="tab-pane <?php echo ((isset($_GET['type']) && $_GET['type']=='')) ? 'active' : ($_GET['type']!='count') ? 'active' : ''; ?> use-padding" id="info">
<div class="table-responsive" style="min-height:300px;">
<table id="example" class="table table-striped"  style="border:solid 1px #ddd">
 <thead>
            <tr>
             <th>id</th>
                <th>Labour Name</th>
                <th>Site Name</th>
                <th>Attendance Date</th>
                <th>Official Cost</th>
                <th>Personal Cost</th>
                <th>Created Date</th>
            </tr>
        </thead>
         <tbody>
<?php if($attendance): ?>
<?php foreach($attendance as $at): ?>
<?php
$date = $at->attendance_date;
 $str = $date;
$date1 = DateTime::createFromFormat('Y-m-d', $str);

$date2 = $at->created_date;
 $str2 = $date2;
$date2 = DateTime::createFromFormat('Y-m-d', $str2);
//echo $date1->format('d-m-Y')
?>
<tr>
<td><?php echo e($at->id); ?></td>
                <td><?php echo e($at->labours_name); ?></td>
                <td><?php echo e($at->site_name); ?></td>
                <td><?php echo e($date1->format('d-m-Y')); ?></td>
                <td><?php echo e($at->official_cost); ?></td>
                <td><?php echo e($at->personal_cost); ?></td>
                 <td><?php echo e($date2->format('d-m-Y')); ?></td>
            </tr>
<?php endforeach; ?>
<?php else: ?>
<?php endif; ?> 
</tbody></table>	</div>
</div></div>
<div class="tab-content m-t">
  <div class="tab-pane <?php echo (isset($_GET['type']) && $_GET['type']=='count') ? 'active' : ''; ?> use-padding" id="count">
      <div class="table-responsive" style="min-height:300px;">
<table id="example" class="table table-striped"  style="border:solid 1px #ddd">
 <thead>
            <tr>
             <th>id</th>
                <th>Site Name</th>
                <th>Attendance Date</th>
                <th>Labour Count</th>
            </tr>
        </thead>
         <tbody>
<?php if($attendance): ?>
<?php foreach($attendance as $ky=>$at): ?>
<?php
$date = $at->attendance_date;
 $str = $date;
$date1 = DateTime::createFromFormat('Y-m-d', $str);


//echo $date1->format('d-m-Y')
?>
<tr>
<td><?php echo e($ky+1); ?></td>
                <td><?php echo e($at->site_name); ?></td>
                <td><?php echo e($date1->format('d-m-Y')); ?></td>
                 <td><?php echo $at->labour_count; ?></td>
            </tr>
<?php endforeach; ?>
<?php else: ?>
<?php endif; ?> 
</tbody></table>    </div>
  </div></div>
<?php } ?>
</div>

<!-- <?php if($show_clear == '1'): ?> -->


<!-- <?php endif; ?> 
 -->
	<?php endif; ?> 

</div>
<script type="text/javascript">
function printData()
{
   var divToPrint=document.getElementById("example");
   var content2=document.getElementById("second");
   newWin= window.open("");
   newWin.document.write(content2.innerHTML+divToPrint.outerHTML);
   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();?>/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 += '?site_name='+site_selcted_name+'&labour_selcted_name='+labour_selcted_name+'&from='+from_filter+'&to='+to_filter
   
window.location.href = url;
 return false;   
         });
        
    	$('.site_names').select2();
    	$('.lab_names').select2();
       
 $('#example').DataTable( {
       "aaSorting": [[ 0, "desc" ]],
       "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 += '?site_name='+site_selcted_name+'&labour_selcted_name='+labour_selcted_name+'&from='+from_filter+'&to='+to_filter
   
window.location.href = url;
 return false;
});
    });

    
</script>
<style>
.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(); ?>