File: /home/cafsindia/allyindian_com/sbltt/application/controllers/Live_chart.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Secure_Controller.php");
class live_chart extends Secure_Controller
{
public function __construct(){
parent::__construct('live_chart');
$this->load->model('Live_chart_model');
}
public function index(){
if(!$this->Appconfig->isAppvalid()){
redirect('config');
}
$this->load->view('live_chart/manage');
}
public function check_avilability(){
$from_date = date("Y-m-d", strtotime($this->input->post('start_date')));
$to_date = date("Y-m-d", strtotime($this->input->post('end_date')));
$start = (new DateTime($from_date))->modify('first day of this month');
$end = (new DateTime($to_date))->modify('first day of next month');
$interval = DateInterval::createFromDateString('1 month');
$period = new DatePeriod($start, $interval, $end);
$table = "";
foreach ($period as $dt) {
$year_month = $dt->format("Y-m");
$year_month_rslt = explode('-', $year_month);
$year = $year_month_rslt[0];
$month = $year_month_rslt[1];
$tot_days = cal_days_in_month(CAL_GREGORIAN,$month,$year);
$txt_month = date("F Y", strtotime("$year_month-01"));
$vehicle_list = $this->Live_chart_model->get_vehicle();
$vehicle_id_group = $this->Live_chart_model->vehicle_id_group();
$vehicle_ids = $vehicle_id_group->vehicle_ids;
$th_line = "<th style='padding:4px;text-align:center;vertical-align:middle;border:1px solid #CCCCCC;left: 0px;border-bottom: 0px !important;'>Day</th>";
$th_line2 = "<th style='padding:4px;text-align:center;vertical-align:middle;border:1px solid #CCCCCC;left: 0px;border-top: 0px !important;'></th>";
foreach ($vehicle_list as $vehicle){
$vehicle_id = $vehicle->vehicle_id;
$vehicle_no = $vehicle->vehicle_no;
$vehicle_type = $vehicle->vehicle_type;
$veh_type = $vehicle->veh_type;
$this->Live_chart_model->get_booking_chart($year_month,$vehicle_id,$vehicle_type);
$th_line .= "<th style='padding:4px;text-align:center;vertical-align:middle;border:1px solid #CCCCCC;' colspan='2' scope='colgroup'><div style='font-size: 11px !important; width: 100px !important; white-space: nowrap; text-overflow: ellipsis; overflow: hidden;'>$veh_type</div>$vehicle_no</th>";
$th_line2 .= "<th style='padding:4px;text-align:center;vertical-align:middle;border:1px solid #CCCCCC;background-color: #43D854;' scope='col'>Operation</th><th style='padding:4px;text-align:center;vertical-align:middle;border:1px solid #CCCCCC;background-color: #E4E051;' scope='col'>Sales</th>";
}
$th_line = "<tr style='top: 0px'>$th_line</tr>";
$th_line2 = "<tr style='top: 0px'>$th_line2</tr>";
$demand_month = $this->Live_chart_model->get_demand_date($year_month);
for($i = 1;$i <= $tot_days; $i++){
$getday = strtotime("$year_month-$i");
$day = date('D', $getday);
$col = "day_".$i;
$demand_days = $demand_month->$col;
$day_crl = "";
if(($day === "Sat") || ($day === "Sun")){
$day_crl = "background-color:#FFCF00;";
}
if($demand_days === "1"){
$day_crl = "background-color:#4dd9f9;";
}
$booked_list = $this->Live_chart_model->get_booking_chart_date($year_month,$col,$vehicle_ids);
foreach ($booked_list as $booked_list){
$mode = $booked_list->mode;
$to_booked = $booked_list->days;
$chart_vehicle_id = $booked_list->chart_vehicle_id;
$crl = "";
if($to_booked === "1"){
if($mode === "SALES"){
$crl = "background-color:#E4E051;";
}else{
$crl = "background-color:#43D854;";
}
}
$line .= "<td style='padding:4px;text-align:center;border:1px solid #CCCCCC;$crl'></td>";
}
$td_line .= "<tr>
<td style='padding:4px;text-align:center;border:1px solid #CCCCCC;$day_crl' scope='row'>$i <br/> $day</td>
$line
</tr>";
$line = "";
}
$table .="<div style='font-weight: bold; color: #d84f57; margin-top: 4px;text-align: center; font-size:12px;'>$txt_month</div>
<div class='JStableOuter' > <table class='table table-hover table-striped table-bordered'>
<col>
<colgroup span='2'></colgroup>
<colgroup span='2'></colgroup>
<thead>
$th_line
$th_line2
</thead>
<tbody>
$td_line
</tbody>
</table></div>";
$th_line = "";
$th_line2 = "";
$td_line = "";
}
$avilability_chart = "<span style='padding:0px 8px;background-color:#FFCF00;'></span> Saturday and Sunday
<span style='padding:0px 8px;background-color:#4dd9f9;'></span> Demand Date
<span style='padding:0px 8px;background-color:#E4E051;'></span> Sales Assigned
<span style='padding:0px 8px;background-color:#43D854;'></span> Operation Confirmed
$table";
echo "$avilability_chart";
}
}
?>