Welcome Guest, Not a member yet? Register   Sign In
Custom Rental Diary
#5

[eluser]gRoberts[/eluser]
The best way, or at least the way I would do this, is to return an array of vehicles, which will be your basis for your matrix.

i.e. if there were no vehicles rented out, this would simply show available for all vehicles.

Then, I would query the database for all vehicles that are rented out between the two dates.

i.e
Code:
<?
function get_vehicle_usage($From, $To)
{
  $_From = strtotime($From);
  $_To = strtotime($To);
  $this->db->where('StartDate >=', $_From);
  $this->db->where('EndDate <=', $_To);
  $q = $this->db->get('vehicleusage');
  $ret = array();
  if($q->num_rows() > 0)
  {
   foreach($q->result() as $row)
   {
    $start = $row->StartDate;
    while($start < $row->EndDate)
    {
     $ret[$row->VehicleID][] = date('d-m-Y', $tmp);
     $start = strtotime('+1 day', $start);
    }
   }
  }
  $q->free_result();
  return $ret;
}
?&gt;

The above would return an multi-dimensional array, which the index would contain the VehicleID and the value would be an array of dates that vehicle is not available.

Then, I would do the following in your view:

Code:
<table id="diary">
<thead>
  <tr>
   <td><strong>VEHICLE REG</strong></td>
   &lt;?php foreach($dates as $date) {?&gt;
    <td>&lt;?=$date?&gt;</td>
   &lt;?php }?&gt;
  </tr>
</thead>
<tbody>
  &lt;?php foreach($vehicles as $vehicle) { ?&gt;
  <tr>
   <td>&lt;?=$vehicle->registration;?&gt;</td>
   &lt;?php foreach($dates as $date) {?&gt;
    <td>&lt;?= (isset($VehicleUsage[$vehicle->VehicleID]) ? (in_array($date, $VehicleUsage[$vehicle->VehicleID]) ? 'Unavailable' : 'Available') : 'Available'); ?&gt;</td>
   &lt;?php }?&gt;
  </tr>
  &lt;?php }?&gt;
</tbody>
</table>


Messages In This Thread
Custom Rental Diary - by El Forum - 05-13-2012, 01:11 AM
Custom Rental Diary - by El Forum - 05-13-2012, 03:09 AM
Custom Rental Diary - by El Forum - 05-14-2012, 03:05 AM
Custom Rental Diary - by El Forum - 05-14-2012, 04:52 AM
Custom Rental Diary - by El Forum - 05-14-2012, 05:21 AM
Custom Rental Diary - by El Forum - 05-14-2012, 06:59 AM



Theme © iAndrew 2016 - Forum software by © MyBB