<?php 
include 'head.php';
include('xcrud/xcrud.php');
$xcrud = Xcrud::get_instance();
echo Xcrud::load_css(); 
include 'nav.php';
?>
<div class="content-wrapper">
	<section class="content-header">
		<h1>Truck Records</h1>
    </section>
    <section class="content">      
		<div class="row">
			<div class="col-lg-12 col-xs-12">
				<form method="post" class="mb-3">
    <div class="form-row">
      <div class="col-md-4 mb-3">
        <label for="TruckNo">Truck No</label>
        <input type="text" class="form-control" id="TruckNo" name="TruckNo" required>
      </div>
      <div class="col-md-4 mb-3">
        <label for="Date">Date</label>
        <input type="date" class="form-control" id="Date" name="Date" required>
      </div>
      <div class="col-md-4 mb-3">
        <label>&nbsp</label>
        <button name="Search" type="submit" class="form-control btn btn-primary">Search</button>
      </div>
    </div>
  </form>
			</div>
			<div class="col-lg-12 col-xs-12">
				
			  <?php
$xcrud->table('TruckNo');
$xcrud->subselect('Qty','SELECT COUNT(*) FROM truckdetails WHERE TruckNo = {TruckId}');
$xcrud->columns('TruckNo,Date,Status,completed_date,show_status',false);
$xcrud->columns('TruckNo,Date,Status,completed_date,show_status',false);
$xcrud->label('show_status','Approved');
$xcrud->label('TruckNo','Truck No');
$xcrud->change_type('Date','date');
$xcrud->change_type('completed_date','date');
$xcrud->change_type("Status","select","approved","approved,completed,selected");
$xcrud->unset_add();
$xcrud->unset_title();

if (!in_array('View', $permissionsArray['Truck-Details'])) {
	$xcrud->unset_view();
}
if (!in_array('Edit', $permissionsArray['Truck-Details'])) {
	$xcrud->unset_edit();
}
if (!in_array('Delete', $permissionsArray['Truck-Details'])) {
	$xcrud->unset_remove();
}

if (in_array('Add-Data', $permissionsArray['Truck-Details'])) {
	$xcrud->button('TruckData.php?truckID={truckID}&type=all','Add Data','glyphicon glyphicon-plus','',array('target'=>'_self'));
}

if(isset($_GET['type']) && $_GET['type']=="all"){
	
}else{
	$xcrud->where('Status','approved');
	$xcrud->unset_edit();
}
if (isset($_POST['Search'])) {
  $truckNo = $_POST['TruckNo'];
  $date = $_POST['Date'];
  //$truckID = $truckNo . $date;
  //$truckID = str_replace('-', '', $truckID);
  $date1=str_replace('-','',date('d-m-Y',strtotime($date)));
  $truckID = $truckNo ."-". $date1;
  
  $xcrud->where('TruckId=',$truckID);
}
				echo $xcrud->render();
			  ?>
			</div>
		</div>
    </section>
</div>
<?php
include 'footer.php';
echo Xcrud::load_js();
?>