<div class="content-w">
<ul class="breadcrumb hidden-xs-down hidden-sm-down">
		<div class="back">
			<a href="<?php echo base_url();?>admin/reports/"><i class="os-icon os-icon-common-07"></i></a>
		</div></ul>
  <div class="content-i">
      
    <?php if($report_type=="User") {?>
    <div class="content-box">
        
        <?php if($jobsheet_data==null) { ?>
        <div class="alert alert-danger col-sm-12" role="alert">
            Sorry, no jobsheets records were found for the date between <?= $start_date ?> and <?= $end_date ?>. Try again!
        </div>
        <?php }else{ ?>
        
       <div class="row" style="margin-top:-5px !important;">
            <div class="col-sm-12">
        <div class="element-wrapper">
          <div class="element-box">
              <div class="element-info">
                <div class="element-info-with-icon">
                  <div class="element-info-text">
                    <h5 class="element-inner-header"> <?= $report_type;?> Reports Jobs - <?= $start_date?> - <?= $end_date?></h5>
                  </div>
                </div>
              </div>
              <div class="table-responsive">
			<table id="dataTable1" width="100%" class="table table-striped table-lightfont">
			<thead>
				<tr>
    				<th><?php // echo get_phrase('client');?></th>
					<th><?php echo get_phrase('date');?></th>
					<th><?php echo get_phrase('job task');?></th>
					<th><?php echo get_phrase('total hours');?></th>
					<th><?php echo get_phrase('contract_type');?></th>
					<th><?php echo get_phrase('job_type');?></th>
					<th><?php echo get_phrase('job_status ');?></th>
					
					<th><?php echo get_phrase('Engineer');?></th>
				
				</tr>
			</thead>
			<tbody>
			<?php foreach($jobsheet_data->result_array() as $row) { ?>
				<tr>
					<td><?php // $row['client_name'] ?></td>
					<td><a class="btn nc btn-rounded btn-sm btn-primary" style="color:white"><?=date("d F Y", strtotime($row['job_date']));?></a></td>
					<td><?=$row['project']?></td>
					<td><?=$row['Chargeable_hours']?></td>
					    
						<td><?=$row['contract_type']?></td>
						<td><?=$row['job_type']?></td>
						<td><a class="btn nc btn-rounded btn-sm btn-success" style="color:white"><?=$row['job_status']?></a></td>
						
						<td><?=$user_data->name ?></td>

					<td>
					
					</td>

				</tr>
			<?php } ?>
			</tbody>
			        <tfoot> 
                <tr>
                   <th>Totals</th>
                   <th></th>
                    <th></th>
                   <th>Totals</th>
                   
                    <th style='text-align:left;'><?php echo $row['total_hours'];?></th>
                     <th style='text-align:left;'><?php echo $row['total_hours'];?></th>
                   <th style='text-align:left;'><?php echo $row['total_hours'];?></th>
               <th style='text-align:left;'><?php echo $row['total_hours'];?></th>
                
                   <th></th>
                   <th></th>
				   <th></th>
                </tr></tfoot>
			</table>
		  </div>
          </div>
        </div>
      </div>
      </div>
      
        <?php } ?>
    </div>
    <?php }?>
    
    <?php if($report_type=="Client") {?>
    <div class="content-box">
        
        <?php if($jobsheet_data==null) { ?>
        <div class="alert alert-danger col-sm-12" role="alert">
            Sorry, no jobsheets records were found for the date between <?= $start_date ?> and <?= $end_date ?>. Try again!
        </div>
        <?php }else{ ?>
        
       <div class="row" style="margin-top:-5px !important;">
            <div class="col-sm-12">
        <div class="element-wrapper">
          <div class="element-box">
              <div class="element-info">
                <div class="element-info-with-icon">
                  <div class="element-info-text">
                    <h5 class="element-inner-header">  <?= $report_type;?> Report Jobs - <?= $start_date?> - <?= $end_date?></h5>
                  </div>
                </div>
              </div>
              <div class="table-responsive">
			<table id="example6" width="100%" >
			<thead>
				<tr>
    			
					<th><?php echo"Activity";?></th>
					<th><?php echo "QTY";?></th>
					<th><?php echo "Rate";?></th>
					
					<th><?php echo "Amount Excl Vat";?></th>
				
					
				
				</tr>
			</thead>
			<tbody>
			<?php 
			$totalhours=0;
			$totalamountall=0;
			foreach($jobsheet_data->result_array() as $row) {
			    $charges=0;
			    $client_id=$row['client_id'];
		 $hourlyrate = $this->db->get_where('client', array('client_id' => $client_id))->row()->NormalRate;
			$client_id=$data['client_id'];
			$rate_type=$this->db->get_where('jobcards' , array('client_id' => $client_id))->row()->rate_type;
                   $rate = $this->db->get_where('rates' , array('client_id' => $client_id,'rate_type'=>$type))->row()->amount;
			$hours=$row['Chargeable_hours'];
			$totalamount=$hours*$hourlyrate;
			$totalhours+=$hours;
			$totalamountall+=$totalamount;
			?>
				<tr>
			<?php $dash="-";
			$desc="Job Sheet No ";
			$attached="( See attached Job sheet for more details)"
			?>
					<td><a class="btn nc btn-rounded btn-sm btn-primary" style="color:white"><?=date("F ", strtotime($row['job_date']));?><?=$dash?><?=$desc?><?=$row['jid']?><?=$attached?></a></td>
					
					<td><?=$row['Chargeable_hours']?></td>
					<td><?php 
					$client_id=$data['client_id'];
					echo $hourlyrate?></td>
					
					
					<td><?php echo ($hours*$hourlyrate)?></td>
					    
					
						


				</tr>
			<?php } ?>
			<tfooter>
				<tr>
    				
				<td><b>Totals</b></td><td><?php echo $totalhours;?></td><td></td><td><?php echo number_format($totalamountall,2);?></td>
				</tr>
			</tfooter>
			</tbody>
			</table>
		  </div>
          </div>
        </div>
      </div>
      </div>
 
      
        <?php } ?>
    </div>
    <?php }?>
  </div>
</div>
<!-- /.content -->
  <script >
     
     $(document).ready(function() {
    var printCounter = 0;
 
    // Append a caption to the table before the DataTables initialisation
    $('#example6').append('<caption style="caption-side: bottom">Jobsheets Report</caption>');
 
    $('#example6').DataTable( {
        "footerCallback": function ( row, data, start, end, display ) {
            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;
            };
            
                var monTotal = api
                .column(7)
                .data()
                .reduce( function (a, b) {
                    return intVal(a) + intVal(b);
                }, 0 );
                
                   var deveTotal = api
                .column(8)
                .data()
                .reduce( function (a, b) {
                    return intVal(a) + intVal(b);
                }, 0 );
                
                 $( api.column( 0 ).footer() ).html('Total');
            $( api.column( 7 ).footer() ).html(monTotal);
             $( api.column(8).footer() ).html(deveTotal);
				
        },
        dom: 'Bfrtip',
        "dom": '<"bottom"Bflength>rt<"top"lip><"clear">',
        buttons: [
            'copy',
            {
                  
               extend: 'excelHtml5',
                    text: 'Excel',
                 footer: true,
                 title: 'Jobsheets Report <?php  $start = date("Y-m-d"); echo $start; ?>',
                messageTop: '<?php   echo 'Jobsheet Report ';
                
                ?> ',
                 exportOptions: { columns: ':visible'}
            },
            {
                extend: 'pdf',
                messageBottom: null
            },
            {
                extend: 'print',
                messageTop: function () {
                    printCounter++;
 
                    if ( printCounter === 1 ) {
                        return 'This is the first time you have printed this document.';
                    }
                    else {
                        return 'You have printed this document '+printCounter+' times';
                    }
                },
                              
       
              processing: true,
               "select": true,
                messageBottom: null
            }
            
            ,'colvis'
        ], "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]] } );
} );
     
    </script>


