File: /home/cafsindia/allyindian_com/sbltt/application/controllers/Booking.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Secure_Controller.php");
class Booking extends Secure_Controller{
public function __construct(){
parent::__construct('booking');
$this->load->model('Booking_model');
$this->load->model('Sms_model');
$this->load->model('Email_model');
$this->load->model('Customer');
}
public function index(){
if(!$this->Appconfig->isAppvalid()){
redirect('config');
}
$data['table_headers']=$this->xss_clean(get_booking_headers());
$this->load->view('booking/manage',$data);
}
public function date_difference(){
$from_date = strtotime($this->input->post('from_date'));
$to_date = strtotime($this->input->post('to_date'));
if($from_date > $to_date){
echo json_encode(array('success' => false, 'message' =>"Please enter valid form and to date"));
}else{
$from_date = date("Y-m-d", $from_date);
$to_date = date("Y-m-d", $to_date);
$diff = abs(strtotime($to_date) - strtotime($from_date));
$years = floor($diff / (365*60*60*24));
$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
$days = $days +1;
echo json_encode(array('success' => true, 'days'=>$days));
}
}
public function suggest_customer(){
$suggestions = $this->xss_clean($this->Booking_model->get_customer_suggestions($this->input->post('term')));
echo json_encode(array('success' => TRUE, 'search' => $suggestions));
}
public function get_customer(){
$suggestions = $this->xss_clean($this->Booking_model->get_customer_info($this->input->post('term')));
echo json_encode(array('success' => TRUE, 'search' => $suggestions));
}
public function get_average_km(){
$orgin = $this->input->post('orgin');
$destination = $this->input->post('destination');
$average_km = $this->Booking_model->get_average_km($orgin,$destination);
echo json_encode(array('success' => TRUE, 'average_km' => $average_km));
}
public function get_tariff(){
$trip_type = $this->input->post('trip_type');
$vehicle_type = $this->input->post('vehicle_type');
$tariff = $this->Booking_model->get_tariff($trip_type,$vehicle_type);
echo json_encode(array('success' => TRUE, 'tariff' => $tariff));
}
public function get_amount(){
$trip_type = $this->input->post('trip_type');
$vehicle_type = $this->input->post('vehicle_type');
$avg_km = $this->input->post('avg_km');
$bus_count = $this->input->post('bus_count');
$tariff_amt = $this->Booking_model->get_tariff_amt($trip_type,$vehicle_type,$avg_km);
$upto_km = $tariff_amt->upto_km;
$upto_amt = $tariff_amt->upto_amt;
$extra_km_amt = $tariff_amt->extra_km_amt;
$trip_ex_km = (int)$avg_km - (int)$upto_km;
$trip_ex_amt = 0;
if((int)$trip_ex_km > 0){
$trip_ex_amt = (int)$trip_ex_km * (int)$extra_km_amt;
}
$trip_amt = (int)$upto_amt + (int)$trip_ex_amt;
if((int)$bus_count > 0){
$trip_amt = (int)$trip_amt*(int)$bus_count;
}
echo json_encode(array('success' => TRUE, 'trip_amt' => $trip_amt));
}
public function get_vehicle_list(){
$vehicle_type = $this->input->post('vehicle_type');
$vehicle_list = $this->Booking_model->get_vehicle($vehicle_type);
echo json_encode(array('success' => TRUE, 'vehicle_list' => $vehicle_list));
}
public function get_menu(){
$menu_id = $this->input->post('menu_id');
$menu = $this->Booking_model->get_menu($menu_id);
echo json_encode(array('success' => TRUE, 'menu_list' => $menu));
}
public function check_avilability(){
$trip_type = $this->input->post('trip_type');
$vehicle_type = $this->input->post('vehicle_type');
$from_date = date("Y-m-d", strtotime($this->input->post('from_date')));
$to_date = date("Y-m-d", strtotime($this->input->post('to_date')));
$get_cout = $this->input->post('get_cout');
$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");
$vehicle_list = $this->Booking_model->get_vehicle_live($vehicle_type);
foreach ($vehicle_list as $vehicle){
$vehicle_id = $vehicle->vehicle_id;
$vehicle_no = $vehicle->vehicle_no;
$type = $vehicle->vehicle_type;
$txt_month = date("F Y", strtotime("$year_month-01"));
$booked_list = $this->Booking_model->get_booking_chart($year_month,$vehicle_id,$type);
$demand_month = $this->Booking_model->get_demand_date($year_month);
$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);
$th_line = "<th style='padding:4px;text-align:center;vertical-align:middle;border:1px solid #CCCCCC;'>Vehicle Number</th>";
$th_line .= "<th style='padding:4px;text-align:center;vertical-align:middle;border:1px solid #CCCCCC;'>Mode</th>";
for($i = 1; $i <= $tot_days; $i++){
$getday = strtotime("$year_month-$i");
$day = date('D', $getday);
$col = "day_".$i;
$demand_days = $demand_month->$col;
$crl = "";
if(($day === "Sat") || ($day === "Sun")){
$crl = "background-color:#FFCF00;";
}
if($demand_days === "1"){
$crl = "background-color:#4dd9f9;";
}
$th_line .= "<th style='padding:4px;text-align:center;border:1px solid #CCCCCC;$crl'>$day <br/>$i</th>";
}
$th_line = "<tr>$th_line</tr>";
$td_line .= "<td rowspan='2' style='padding:8px 0px;text-align:center;vertical-align:middle;border:1px solid #CCCCCC;'>$vehicle_no</td>";
foreach ($booked_list as $booked_list){
$mode = $booked_list->mode;
$mode_name = ucfirst(strtolower($mode));
$td_line .= "<td style='padding:8px 0px;text-align:center;border:1px solid #CCCCCC;'>$mode_name</td>";
for($i = 1; $i <= $tot_days; $i++){
$col = "day_".$i;
$to_booked = $booked_list->$col;
$crl = "";
if($to_booked === "1"){
if($mode === "SALES"){
$crl = "background-color:#E4E051;";
}else{
$crl = "background-color:#43D854;";
}
}
$td_line .= "<td style='padding:4px;text-align:center;border:1px solid #CCCCCC;$crl'></td>";
}
$td_line = "<tr>$td_line</tr>";
}
}
$table .="<div style='font-weight: bold; color: #d84f57; margin-top: 4px;text-align: center; font-size: 10px;'>$txt_month</div>
<table class='table table-hover table-striped table-bordered' style='font-size:9px !important;margin-top:4px;margin-bottom: 4px;'>
$th_line
$td_line
</table>";
$td_line = "";
if($get_cout === "1"){
$avilability_count = $this->avilability_count($from_date,$to_date,$type);
}
}
$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
";
if($get_cout === "1"){
echo "<div style='font-weight: bold; color: #d84f57; margin-top: 4px;text-align: center; font-size: 11px;padding-right:15px;text-align:right;'>$avilability_count</div>$avilability_chart";
}else{
echo "$avilability_chart";
}
}
public function avilability_count($from_date,$to_date,$vehicle_type){
$from = strtotime($from_date);
$to = strtotime($to_date);
$chkdate = explode('-', $from_date);
$premonth = $chkdate[1];
$chk_qry = "";
$chk_qry1 = "";
for($i=$from; $i<=$to; $i+=86400) {
$bet_date = date("Y-m-d", $i);
$between = explode('-', $bet_date);
$between_year = $between[0];
$between_month = $between[1];
$between_date = $between[2];
$between_date = ltrim($between_date, '0');
$col = "day_".$between_date;
if($premonth === $between_month){
$month_one = $between_year."-".$between_month;
$chk_qry .= " $col = '0' and";
}else{
$month_two = $between_year."-".$between_month;
$chk_qry1 .= " $col = '0' and";
}
}
$avilability = "";
if($chk_qry !== ""){
$chk_qry = rtrim($chk_qry, 'and');
$month_one_qry = $this->db->query("select * from sblt_booking_chart where chart_month = '$month_one' and mode = 'OPERATION' and chart_vehicle_type = '$vehicle_type' and $chk_qry");
$month_one_count = $month_one_qry->num_rows();
$txt_month = date("F Y", strtotime("$month_one-01"));
$avilability .= "$month_one_count Vehicle available for selected date<br/>";
}
if($chk_qry1 !== ""){
$chk_qry1 = rtrim($chk_qry1, 'and');
$month_two_qry = $this->db->query("select * from sblt_booking_chart where chart_month = '$month_two' and mode = 'OPERATION' and chart_vehicle_type = '$vehicle_type' and $chk_qry");
$month_two_count = $month_two_qry->num_rows();
$txt_month = date("F Y", strtotime("$month_two-01"));
$avilability .= "$month_two_count Vehicle available for selected date<br/>";
}
return $avilability;
}
public function search(){
$search=$this->input->get('search');
$limit=$this->input->get('limit');
$offset=$this->input->get('offset');
$sort=$this->input->get('sort');
$order=$this->input->get('order');
$filters = array('start_date' => $this->input->get('start_date'),'end_date' => $this->input->get('end_date'),'Follow_Up' => FALSE,'Confirm' => FALSE,'Cancelled' => FALSE,'Completed' => FALSE,'On_progress' => FALSE);
$filledup = array_fill_keys($this->input->get('filters'), TRUE);
$filters = array_merge($filters, $filledup);
$booking=$this->Booking_model->search($search,$filters,$limit,$offset,$sort,$order);
$TotalRows=$this->Booking_model->get_found_rows($search,$filters);
$DataRows=array();
foreach ($booking->result() as $person){
$DataRows[]=get_booking_datarows($person,$this);
}
$DataRows=$this->xss_clean($DataRows);
echo json_encode(array('total'=>$TotalRows,'rows'=>$DataRows));
}
public function view($booking_id=-1){
$info=$this->Booking_model->get_info($booking_id);
foreach (get_object_vars($info) as $property => $value){
$info->$property = $this->xss_clean($value);
}
$data['booking']=$info;
$getcust = $data['booking'];
$cust_id = $getcust->cust_id;
$type = $getcust->vehicle_type;
$trip = $getcust->trip_type;
$data['tariff_table'] = $this->Booking_model->get_tariff($trip,$type);
$cust_info=$this->Booking_model->get_customer($cust_id);
foreach (get_object_vars($info) as $property => $value){
$info->$property = $this->xss_clean($value);
}
$data['cust_info']=$cust_info;
$vehicle_list["all"] = "--Select Preferred Vehicle--";
$vehicle = $this->Booking_model->get_vehicle($type);
foreach($vehicle as $row){
$vehicle_list[$this->xss_clean($row->vehicle_id)] = $this->xss_clean($row->vehicle_no);
}
$data['vehicle_list'] = $vehicle_list;
$state_info[""] = "--Select State--";
foreach($this->Booking_model->get_state()->result_array() as $row){
$state_info[$this->xss_clean($row['state_code'])] = $this->xss_clean($row['state_name']);
}
$data['state_info'] = $state_info;
$city_info[""] = "--Select City--";
foreach($this->Booking_model->get_city()->result_array() as $row){
$city_info[$this->xss_clean($row['city_id'])] = $this->xss_clean($row['city_name']);
}
$data['city_info'] = $city_info;
$booking_type[""] = "--Select Customer Type--";
foreach($this->Booking_model->get_booking_type()->result_array() as $row){
$booking_type[$this->xss_clean($row['booking_type_id'])] = $this->xss_clean($row['booking_type_name']);
}
$data['booking_type'] = $booking_type;
$vehicle_type[""] = "--Select Vehicle Type--";
foreach($this->Booking_model->get_vehicle_type()->result_array() as $row){
$vehicle_type[$this->xss_clean($row['veh_type_id'])] = $this->xss_clean($row['veh_type']." - ".$row['veh_category']);
}
$data['vehicle_type'] = $vehicle_type;
$trip_type[""] = "--Select Trip Type--";
foreach($this->Booking_model->get_trip_type()->result_array() as $row){
$trip_type[$this->xss_clean($row['trip_type_id'])] = $this->xss_clean($row['trip_type_name']);
}
$data['trip_type'] = $trip_type;
$referral_info[""] = "---- Select Refered By ----";
foreach($this->Booking_model->get_referral()->result_array() as $row){
$referral_info[$this->xss_clean($row['person_id'])] = $this->xss_clean($row['first_name']."-".$row['role_name']);
}
$referral_info['0'] = "Others";
$data['referral_info'] = $referral_info;
$this->load->view("booking/form",$data);
}
public function save($booking_id = -1){
$mobile = $this->input->post('phone_number');
$cust_email = $this->input->post('email');
$mobile_sms = $this->input->post('phone_number').','.$this->input->post('alt_number');
$customer_data = array(
'customer_name' => $this->input->post('customer_name'),
'phone_number' => $this->input->post('phone_number'),
'alt_number' => $this->input->post('alt_number'),
'land_line' => $this->input->post('land_line'),
'cust_email' => $this->input->post('email'),
'cust_address' => $this->input->post('cust_address'),
'city' => $this->input->post('city'),
'state' => $this->input->post('state'),
'dob' => date('Y-m-d',strtotime($this->input->post('dob'))),
//'cust_type' => $this->input->post('cust_type'),
'referral_type' => $this->input->post('referral_type'),
'allow_contract' => $this->input->post('allow_contract'),
'cust_sts' => $this->input->post('cust_sts'),
'cust_zone' => $this->input->post('cust_zone'),
'csut_gst' => $this->input->post('csut_gst'),
'csut_pan' => $this->input->post('csut_pan'),
'includ_gst' => $this->input->post('includ_gst')
);
$cust_id = $this->Customer->lead_save_customer($customer_data, $mobile);
$tour_no="";
if(($this->input->post('booking_sts') === "2") || ($this->input->post('booking_sts') === "3")){
$trip_type = $this->input->post('trip_type');
$tour_no = $this->Booking_model->get_fy_count($trip_type,$booking_id);
$orgin = $this->input->post('orgin');
$destination = $this->input->post('destination');
$avg_km = $this->input->post('avg_km');
$this->Booking_model->update_average_km($orgin,$destination,$avg_km);
}
else
{
//$tour_no = time();
}
$preferred_vehicle = implode(",",$this->input->post('preferred_vehicle'));
$insert_data = array(
'booking_id' => $this->input->post('booking_id'),
'enquiry_id' => $this->input->post('enquiry_id'),
'cust_id' => $cust_id,
'tour_no' => $tour_no,
'billing_name' => $this->input->post('billing_name'),
'report_address' => $this->input->post('report_address'),
'landmark' => $this->input->post('landmark'),
'orgin' => $this->input->post('orgin'),
'destination' => $this->input->post('destination'),
'bus_count' => $this->input->post('bus_count'),
'from_date' => date('Y-m-d',strtotime($this->input->post('from_date'))),
'to_date' => date('Y-m-d',strtotime($this->input->post('to_date'))),
'trip_days' => $this->input->post('trip_days'),
'trip_type' => $this->input->post('trip_type'),
'cust_type' => $this->input->post('cust_type'),
'vehicle_type' => $this->input->post('vehicle_type'),
'avg_km' => $this->input->post('avg_km'),
'preferred_vehicle' => $preferred_vehicle,
'reporting_time' => $this->input->post('reporting_time'),
'shed_out_time' => $this->input->post('shed_out_time'),
'booking_amount' => $this->input->post('booking_amount'),
'advance_amount' => $this->input->post('advance_amount'),
'tax_precentage' => $this->input->post('tax_precentage'),
'discount_amount' => $this->input->post('discount_amount'),
'payment_type' => $this->input->post('payment_type'),
'toll' => $this->input->post('toll'),
'parking' => $this->input->post('parking'),
'driver_batta' => $this->input->post('driver_batta'),
'state_tax' => $this->input->post('state_tax'),
'catering' => $this->input->post('catering'),
'trip_details' => $this->input->post('trip_details'),
'remark' => $this->input->post('remark'),
'referral' => $this->input->post('referral'),
'tp_info' => $this->input->post('tp_info'),
'operation_type' => $this->input->post('operation_type'),
'pax' => $this->input->post('pax'),
);
$booking_data = $insert_data;
$booking_data['booking_sts'] = $this->input->post('booking_sts');
$booking_data['ncd'] = $this->input->post('ncd');
$booking_data['cancel_reson'] = $this->input->post('cancel_reson');
$operation_data = "";
$accounts_data = "";
if(($this->input->post('booking_sts') === "2") || ($this->input->post('booking_sts') === "3")){
$operation_data = $insert_data;
$operation_data['operation_sts'] = $this->input->post('booking_sts');
$accounts_data = $insert_data;
$accounts_data['operation_sts'] = $this->input->post('booking_sts');
$accounts_data['accounts_sts'] = $this->input->post('booking_sts');
}
if($this->Booking_model->save_booking($booking_data,$operation_data,$accounts_data, $booking_id)){
$booking_data = $this->xss_clean($booking_data);
if($booking_id == -1){
$booking_id = $booking_data['booking_id'];
echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('booking_successful_adding').' '.
$booking_data['booking_name'], 'id' => $booking_data['booking_id']));
}else{
echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('booking_successful_updating').' '.
$booking_data['booking_name'], 'id' => $booking_id));
}
// SEND SMS
if($this->input->post('booking_sts') === "2"){
if($mobile){
$this->Sms_model->send_sms($booking_id,$mobile_sms,"booking_confirm");
$this->send_email($booking_id,$mode="");
}
}
if($this->input->post('booking_sts') === "3"){
if($mobile){
$this->Sms_model->send_sms($booking_id,$mobile_sms,"booking_cancelled");
}
//if($cust_email){ UDY :: REMOVE GS ASKED TO SEND WITH OUT TO EMAIL
$content = $this->Sms_model->get_replaced_content($booking_id,"booking_cancelled");
$email_data = array(
'to_email' => $cust_email,
'subject' => "SBLT Booking Cancelled for $tour_no",
'email_content' => $content,
'email_type' => "BOOKING_CANCELLED",
);
//$this->Email_model->send_email($email_data);
$this->Email_model->send_phpmailer($email_data);
//}
}
}else{
$booking_data = $this->xss_clean($booking_data);
echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('booking_error_adding_updating').' '.
$booking_data['booking_name'], 'id' => -1));
}
}
public function resend_sms($booking_id){
$info=$this->Booking_model->get_info($booking_id);
foreach (get_object_vars($info) as $property => $value){
$info->$property = $this->xss_clean($value);
}
$data['booking']=$info;
$getcust = $data['booking'];
$cust_id = $getcust->cust_id;
$cust_info=$this->Booking_model->get_customer($cust_id);
foreach (get_object_vars($info) as $property => $value){
$info->$property = $this->xss_clean($value);
}
$data['cust_info']=$cust_info;
$cust_info = $data['cust_info'];
$mobile = $cust_info->phone_number;
$mobile_sms = $cust_info->phone_number.','.$cust_info->alt_number;
if($mobile){
$sms_content = $this->Sms_model->resend_sms($booking_id,$mobile_sms,"booking_confirm");
$data['mobile'] = $mobile;
$data['sms_content'] = $sms_content;
$data['sts'] = "SMS Sent Successfully!!!";
}else{
$data['mobile'] = "Invalid Mobile";
$data['sms_content'] = "";
$data['sts'] = "SMS Not Sent";
}
$this->load->view("booking/resend_sms",$data);
}
public function booking_log($booking_id){
$data['booking_log'] = $this->Booking_model->get_booking_log($booking_id);
$this->load->view('booking/booking_log',$data);
}
public function get_order(){
$order_id = $this->input->post('order_id');
$order_info = $this->Booking_model->get_order($order_id);
echo json_encode(array('success' => TRUE, 'order_info' => $order_info));
}
public function catering_add(){
$date = date('Y-m-d',strtotime($this->input->post('date')));
$booking_id = $this->input->post('booking_id');
$catering_date = array(
'booking_id' => $this->input->post('booking_id'),
'cust_id' => $this->input->post('cust_id'),
'order_date' => date('Y-m-d',strtotime($this->input->post('date'))),
'break_fast' => $this->input->post('break_fast'),
'break_fast_menu' => $this->input->post('bf_menu'),
'bf_count' => $this->input->post('bf_count'),
'bf_amount' => $this->input->post('bf_amount'),
'lunch' => $this->input->post('lunch'),
'lunch_menu' => $this->input->post('lunch_menu'),
'lunch_count' => $this->input->post('lunch_count'),
'lunch_amount' => $this->input->post('lunch_amount'),
'dinner' => $this->input->post('dinner'),
'dinner_menu' => $this->input->post('dinner_menu'),
'dinner_count' => $this->input->post('dinner_count'),
'dinner_amount' => $this->input->post('dinner_amount'),
'amount' => $this->input->post('amount'),
'mode' => "BOOKING",
'created_by' => $this->session->userdata('emp_id'),
'created_date' => date("Y-m-d H:i:s"),
);
if($this->Booking_model->catering_save($catering_date,$booking_id, $date)){
$catering_order = $this->Booking_model->get_catering_order($booking_id);
echo json_encode(array('success' => TRUE, 'catering_order' =>$catering_order));
}else{
echo "Unable process your request";
}
}
public function get_stay(){
$stay_id = $this->input->post('stay_id');
$stay_info = $this->Booking_model->get_stay($stay_id);
echo json_encode(array('success' => TRUE, 'stay_info' => $stay_info));
}
public function stay_add(){
$stay_date = date('Y-m-d',strtotime($this->input->post('stay_date')));
$booking_id = $this->input->post('stay_booking_id');
$sharing = $this->input->post('sharing');
$stay_data = array(
'booking_id' => $this->input->post('stay_booking_id'),
'stay_date' => date('Y-m-d',strtotime($this->input->post('stay_date'))),
'hotel_name' => $this->input->post('hotel_name'),
'sharing' => $this->input->post('sharing'),
'stay_count' => $this->input->post('stay_count'),
'stay_tot_amt' => $this->input->post('stay_tot_amt'),
'created_by' => $this->session->userdata('emp_id'),
'created_date' => date("Y-m-d H:i:s"),
);
if($this->Booking_model->stay_save($stay_data,$booking_id, $stay_date, $sharing)){
$stay_info = $this->Booking_model->get_stay_list($booking_id);
echo json_encode(array('success' => TRUE, 'stay_info' =>$stay_info));
}else{
echo "Unable process your request";
}
}
public function get_pack(){
$pack_id = $this->input->post('pack_id');
$pack_info = $this->Booking_model->get_pack($pack_id);
echo json_encode(array('success' => TRUE, 'pack_info' => $pack_info));
}
public function package_add(){
$pack_date = date('Y-m-d',strtotime($this->input->post('pack_date')));
$booking_id = $this->input->post('pack_booking_id');
$stay_data = array(
'booking_id' => $this->input->post('pack_booking_id'),
'pack_date' => date('Y-m-d',strtotime($this->input->post('pack_date'))),
'program' => $this->input->post('program'),
'night_stay' => $this->input->post('night_stay'),
'remarks' => $this->input->post('remarks'),
'created_by' => $this->session->userdata('emp_id'),
'created_date' => date("Y-m-d H:i:s"),
);
if($this->Booking_model->pack_save($stay_data,$booking_id, $pack_date)){
$pack_info = $this->Booking_model->get_pack_list($booking_id);
echo json_encode(array('success' => TRUE, 'pack_info' =>$pack_info));
}else{
echo "Unable process your request";
}
}
public function update_catering($booking_id){
$info=$this->Booking_model->get_info($booking_id);
foreach (get_object_vars($info) as $property => $value){
$info->$property = $this->xss_clean($value);
}
$data['booking']=$info;
$catering_menu[""] = "--Select Menu--";
foreach($this->Booking_model->get_catering_menu()->result_array() as $row){
$catering_menu[$this->xss_clean($row['catering_menu_id'])] = $this->xss_clean($row['name']);
}
$data['catering_menu'] = $catering_menu;
$data['catering_order'] = $this->Booking_model->get_catering_order($booking_id);
$data['stay_info'] = $this->Booking_model->get_stay_list($booking_id);
$data['pack_info'] = $this->Booking_model->get_pack_list($booking_id);
$this->load->view("booking/catering_form",$data);
}
public function balance_log($booking_id){
$info=$this->Booking_model->get_info($booking_id);
foreach (get_object_vars($info) as $property => $value){
$info->$property = $this->xss_clean($value);
}
$data['booking']=$info;
$catering_menu[""] = "--Select Menu--";
foreach($this->Booking_model->get_catering_menu()->result_array() as $row){
$catering_menu[$this->xss_clean($row['catering_menu_id'])] = $this->xss_clean($row['name']);
}
$data['balance_info'] = $this->Booking_model->balance_log_list($booking_id);
$this->load->view("booking/balance_form",$data);
}
public function save_balance_log($booking_id){
$bal_log_id = $this->input->post('bal_log_id');
$balance_data = array(
'booking_id' => $this->input->post('bal_booking_id'),
'balance_date' => date('Y-m-d',strtotime($this->input->post('balance_date'))),
'amount' => $this->input->post('amount'),
'remarks' => $this->input->post('remarks'),
'created_by' => $this->session->userdata('emp_id'),
'created_date' => date("Y-m-d H:i:s"),
);
$balance_amount = $this->Booking_model->balance_amount($booking_id);
$pay_amount = $this->input->post('amount');
if((int)$balance_amount >= (int)$pay_amount){
if($this->Booking_model->save_balance_log($balance_data,$bal_log_id)){
$balance_info = $this->Booking_model->balance_log_list($booking_id);
echo json_encode(array('success' => TRUE, 'balance_info' =>$balance_info,'sts' =>"SUCCESS"));
}
}else{
echo json_encode(array('success' => TRUE, 'sts' =>"FAIL"));
}
}
public function get_balance_log(){
$balance_log_id = $this->input->post('balance_log_id');
$balance_info = $this->Booking_model->get_balance_log($balance_log_id);
echo json_encode(array('success' => TRUE, 'balance_info' => $balance_info));
}
public function get_row($booking_ids){
$booking_infos = $this->Booking_model->get_multiple_info($booking_ids);
$result = array();
foreach($booking_infos as $item_info)
{
$result[$item_info->booking_id] = $this->xss_clean(get_item_data_row($item_info, $this));
}
echo json_encode($result);
}
public function print_booking($booking_id){
$data = $this->_load_booking_data($booking_id);
$this->load->view('booking/print_booking',$data);
}
private function _load_booking_data($booking_id){
$data['booking_info'] = $this->Booking_model->get_load_data($booking_id);
$getcust = $data['booking_info'];
$booking_id = $getcust[0]->booking_id;
$vehicle = $getcust[0]->vehicle_type;
$trip = $getcust[0]->trip_type;
$km = $getcust[0]->avg_km;
if($km === ""){
$km = 0;
}
$data['tariff'] = $this->Booking_model->get_tariff_amt($trip,$vehicle,$km);
$data['hsn'] = $this->Booking_model->get_hsn();
$data['catering_order'] = $this->Booking_model->get_catering_order($booking_id);
$data['stay_info'] = $this->Booking_model->get_stay_list($booking_id);
$data['pack_info'] = $this->Booking_model->get_pack_list($booking_id);
$data['balance_log'] = $this->Booking_model->get_bal_log_amount($booking_id);
return $data;
}
public function send_email($booking_id,$mode=""){
$data = $this->_load_booking_data($booking_id);
$booking_info = $data['booking_info'];
$tariff = $data['tariff'];
$hsn = $data['hsn'];
$catering_order = $data['catering_order'];
$stay_info = $data['stay_info'];
$pack_info = $data['pack_info'];
$balance_log = $data['balance_log'];
$company = $this->config->item('company');
$address = $this->config->item('address');
$landline = $this->config->item('landline');
$phone = $this->config->item('phone');
$email = $this->config->item('email');
$website = $this->config->item('website');
$company_info = "<b>$company</b><br/>$address<br/>$landline - $phone<br/>$email<br/>$website<br/>";
foreach($booking_info as $booking){
$tour_no = $booking->tour_no;
$customer_name = $booking->customer_name;
$billing_name = $booking->billing_name;
$report_address = $booking->report_address;
$phone_number = $booking->phone_number;
$alt_number = $booking->alt_number;
$land_line = $booking->land_line;
$cust_email = $booking->cust_email;
$cust_address = $booking->cust_address;
$city = $booking->city;
$state = $booking->state;
$state_name = $booking->state_name;
$includ_gst = $booking->includ_gst;
$from_date = date('d-m-Y',strtotime($booking->from_date));
$to_date = date('d-m-Y',strtotime($booking->to_date));
$frm_city_name = $booking->frm_city_name;
$to_city_name = $booking->to_city_name;
$bus_count = $booking->bus_count;
$trip_days = $booking->trip_days;
$veh_type = $booking->veh_type;
$avg_km = $booking->avg_km;
$booking_amount = $booking->booking_amount;
$advance_amount = $booking->advance_amount;
$landmark = $booking->landmark;
$trip_details = $booking->trip_details;
$tax_precentage = $booking->tax_precentage;
$payment_type = $booking->payment_type;
$discount_amount = $booking->discount_amount;
$reporting_time = $booking->reporting_time;
$toll = $booking->toll;
$parking = $booking->parking;
$driver_batta = $booking->driver_batta;
$state_tax = $booking->state_tax;
$remark = $booking->remark;
$created_date = date('d-m-Y H:i:s',strtotime($booking->booking_date));
$reporting_time = date("G:i", strtotime($reporting_time));
//@gs 19june2018
$rep_day=date('l', strtotime($from_date));
$extra_km_amt = $tariff->extra_km_amt;
$extra = "";
if($toll === "1"){
$extra = "Toll,";
}
if($parking === "1"){
$extra .= "Parking,";
}
if($driver_batta === "1"){
$extra .= "Driver Batta,";
}
if($state_tax === "1"){
$extra .= "Other State tax";
}
$extra = rtrim($extra, ',');
if($extra === ""){
$extra = "Toll,Parking,Driver Batta,Other State tax all inclusive*";
}else{
$extra = $extra." extra*";
}
}
$igst = 0;
$sgst = 0;
$cgst = 0;
if($tax_precentage > 0){
$igst = $tax_precentage;
$sgst = $tax_precentage /2;
$cgst = $tax_precentage /2;
}
$tr_line = "";
$count = 1;
$sub_total = 0;
$canshow_note = false;
foreach($catering_order as $order){
$canshow_note = true;
$count++;
$order_date = date('d-m-Y',strtotime($order->order_date));
$break_fast_menu = $order->break_fast_menu;
$bf_count = $order->bf_count;
$bf_amount = $order->bf_amount;
$lunch_menu = $order->lunch_menu;
$lunch_count = $order->lunch_count;
$lunch_amount = $order->lunch_amount;
$dinner_menu = $order->dinner_menu;
$dinner_count = $order->dinner_count;
$dinner_amount = $order->dinner_amount;
$amount = $order->amount;
$sub_total += $amount;
$tr_line.= "<tr>
<td style='padding: 8px;border: 1px solid #333333;'>$count</td>
<td style='padding: 8px;border: 1px solid #333333;'>
<table style='width: 100%;border-collapse: collapse; border-spacing: 0;font-size: 12px;font-family: sans-serif;'>
<tr>
<td style='font-weight:bold !important;'>$order_date</td>
<td style='font-weight:bold !important;width: 38%;'>Menu</td>
<td style='font-weight:bold !important;'>Pax#</td>
<td style='font-weight:bold !important;'>Per pax</td>
</tr>
<tr>
<td>Breaf Fast</td>
<td>$break_fast_menu</td>
<td>$bf_count</td>
<td>$bf_amount</td>
</tr>
<tr>
<td>Lunch</td>
<td>$lunch_menu</td>
<td>$lunch_count</td>
<td>$lunch_amount</td>
</tr>
<tr>
<td>Dinner</td>
<td>$dinner_menu</td>
<td>$dinner_count</td>
<td>$dinner_amount</td>
</tr>
</table>
</td>
<td style='padding: 8px;border: 1px solid #333333;'>$amount</td>
<td style='padding: 8px;border: 1px solid #333333;'>0</td>
<td style='padding: 8px;border: 1px solid #333333;font-weight:bold;text-align:right;'>$amount</td>
<tr>";
}
foreach($stay_info as $stay){
$canshow_note = true;
$count++;
$stay_date = date('d-m-Y',strtotime($stay->stay_date));
$hotel_name = $stay->hotel_name;
$sharing = $stay->sharing;
$stay_count = $stay->stay_count;
$stay_tot_amt = $stay->stay_tot_amt;
$sub_total += $stay_tot_amt;
$tr_line.= "<tr>
<td style='padding: 8px;border: 1px solid #333333;'>$count</td>
<td style='padding: 8px;border: 1px solid #333333;'>
<table style='width: 100%;border-collapse: collapse; border-spacing: 0;font-size: 12px;font-family: sans-serif;'>
<tr>
<td style='font-weight:bold !important;white-space: nowrap !important;width: 20%;'>$stay_date</td>
<td style='font-weight:bold !important;white-space: nowrap !important;width: 38%;'>Hotel Name</td>
<td style='font-weight:bold !important;'>sharing</td>
<td style='font-weight:bold !important;'>No of pax</td>
</tr>
<tr>
<td></td>
<td>$hotel_name</td>
<td>$sharing</td>
<td>$stay_count</td>
</tr>
</table>
</td>
<td style='padding: 8px;border: 1px solid #333333;'>$stay_tot_amt</td>
<td style='padding: 8px;border: 1px solid #333333;'>0</td>
<td style='padding: 8px;border: 1px solid #333333;font-weight:bold;text-align:right;'>$stay_tot_amt</td>
<tr>";
}
$discount_total = $booking_amount - $discount_amount;
$sub_total = $discount_total + $sub_total;
$igst_amt = $sub_total * $igst/100;
$sgst_amt = $sub_total * $sgst/100;
$cgst_amt = $sub_total * $cgst/100;
$total_amt = $sub_total;
if($includ_gst === "1"){
if($state === "33"){
$total_amt = $sub_total + $cgst_amt + $sgst_amt;
$cgst_amt = number_format($cgst_amt,2);
$sgst_amt = number_format($sgst_amt,2);
}else{
$total_amt = $sub_total + $igst_amt;
$igst_amt = number_format($igst_amt,2);
}
}
$advance = (int)$advance_amount + (int)$balance_log->bal_log_amt;
$balance_amount = (int)$total_amt - (int)$advance;
$base_url = "http://".$_SERVER['SERVER_NAME'].dirname($_SERVER["REQUEST_URI"].'?').'/';
$url = str_replace("index.php/booking/send_email","","$base_url");
$url = str_replace("index.php/booking/resend_email",'',"$base_url");
/*Added by GS Image Issue */
$url = "http://www.sblt.co.in/sbltt/";
if($tr_line === ""){
for($i=0;$i<=5;$i++){
$add_line .= "<tr>
<td style='padding: 8px;border-right: 1px solid #333333;border-left: 1px solid #333333;'></td>
<td style='padding: 8px;border-right: 1px solid #333333;border-left: 1px solid #333333;'></td>
<td style='padding: 8px;border-right: 1px solid #333333;border-left: 1px solid #333333;'></td>
<td style='padding: 8px;border-right: 1px solid #333333;border-left: 1px solid #333333;'></td>
<td style='padding: 8px;border-right: 1px solid #333333;border-left: 1px solid #333333;'></td>
</tr>";
}
}
$tax_info = "";
if($includ_gst === "1"){
if($state === "33"){
$tax_info = "<tr>
<td style='padding: 8px;border: 1px solid #333333;font-weight:bold;'>CGST - $cgst%</td>
<td style='padding: 8px;border: 1px solid #333333;font-weight:bold;text-align:right;'>Rs. $cgst_amt/-</td>
</tr>
<tr>
<td style='padding: 8px;border: 1px solid #333333;font-weight:bold;'>SGST - $sgst%</td>
<td style='padding: 8px;border: 1px solid #333333;font-weight:bold;text-align:right;'>Rs. $sgst_amt/-</td>
</tr>";
}else{
$tax_info = "<tr>
<td style='padding: 8px;border: 1px solid #333333;font-weight:bold;'>IGST - $igst%</td>
<td style='padding: 8px;border: 1px solid #333333;font-weight:bold;text-align:right;'>Rs. $igst_amt/-</td>
</tr>";
}
}
if((int)$balance_amount === 0){
$txt_bal = "Zero";
}else{
$txt_bal = $this->numberTowords($balance_amount);
}
if($canshow_note){
$canshow_txt = "<tr>
<td colspan='5' style='padding: 8px;border: 1px solid #333333;border-bottom: 0px;'> Hotel / Food menu may vary depend on availability* </td>
</tr>";
}
if(count($pack_info) > 0){
foreach($pack_info as $pack){
$pack_date = date('d-m-Y',strtotime($pack->pack_date));
$program = $pack->program;
$night_stay = $pack->night_stay;
$remarks = $pack->remarks;
$line_txt .= "<tr>
<td style='padding: 8px;border: 1px solid #333333;'>$pack_date </td>
<td style='padding: 8px;border: 1px solid #333333;'>$program </td>
<td style='padding: 8px;border: 1px solid #333333;'>$night_stay </td>
<td style='padding: 8px;border: 1px solid #333333;'>$remarks </td>
</tr>";
}
$pack_txt = "<tr>
<td colspan='5'>
<table style='width: 100%;border-collapse: collapse; border-spacing: 0;font-size: 12px;font-family: sans-serif;'>
<tr>
<td style='padding: 8px;border: 1px solid #333333;font-weight:bold;'>Date</td>
<td style='padding: 8px;border: 1px solid #333333;font-weight:bold;'>Program</td>
<td style='padding: 8px;border: 1px solid #333333;font-weight:bold;'>Night Stay</td>
<td style='padding: 8px;border: 1px solid #333333;font-weight:bold;'>Remarks</td>
</tr>
$line_txt
</table>
</td>
</tr>";
}
$email_content = "<div>
Dear Sir,<br/>
<b>Greeting From SBLT!!!</b><br/><br/>
Booking Details $billing_name,<br/>
Your Booking Has Registered Successfully. Your Booking Details are below.<br/><br/>
<table style='width: 100%;border-collapse: collapse; border-spacing: 0;font-size: 12px;font-family: sans-serif;'>
<tr>
<td style='padding: 8px;border: 1px solid #333333;'><img src='$url/images/sbltlogo.png' alt='SBLTT Logo' height='45'/></td>
<td style='padding: 8px;border: 1px solid #333333;border-bottom:0px;text-align:center;font-weight: 800;'>Tour Advance Booking Sheet</td>
</tr>
<tr>
<td style='padding: 8px;border: 1px solid #333333;border-right:0px;'>$company_info</td>
<td>
<table style='width: 100%;border-collapse: collapse; border-spacing: 0;font-size: 12px;font-family: sans-serif;'>
<tr>
<td style='padding: 8px;border: 1px solid #333333;'><b>Booked Date & Time</b></td>
<td style='padding: 8px;border: 1px solid #333333;'>$created_date Hrs</td>
</tr>
<tr>
<td style='padding: 8px;border: 1px solid #333333;'><b>Booked By</b></td>
<td style='padding: 8px;border: 1px solid #333333;'>$customer_name / $phone_number</td>
</tr>
<tr>
<td colspan='2' style='padding: 8px;border: 1px solid #333333;border-bottom:0px;'>
<b>Reporting Details</b><br/>
$billing_name<br/>$report_address<br/>$city<br/>$state_name<br/>$phone_number $alt_number $land_line<br/>$cust_email<br/><b>Land Mark</b> : $landmark
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td style='padding: 8px;border: 1px solid #333333;'><b>Journey On:</b> $from_date $rep_day</td>
<td style='padding: 8px;border: 1px solid #333333;'><b>Reporting Time:</b> $reporting_time Hrs</td>
</tr>
<tr>
<td style='padding: 8px;border: 1px solid #333333;'><b>Tour No:</b> $tour_no</td>
<td style='padding: 8px;border: 1px solid #333333;'><b>No Of Days:</b> $trip_days</td>
</tr>
<tr>
<td style='padding: 8px;border: 1px solid #333333;border-bottom:0px;'><b>No Of Vehicle:</b> $bus_count</td>
<td style='padding: 8px;border: 1px solid #333333;border-bottom:0px;'><b>Coach:</b> $veh_type</td>
</tr>
</tabel>
</div>
<div>
<table style='width: 100%;border-collapse: collapse; border-spacing: 0;font-size: 12px;font-family: sans-serif;'>
<tr>
<td style='padding: 8px;border: 1px solid #333333;font-weight:bold;'>Sl.no</td>
<td style='padding: 8px;border: 1px solid #333333;font-weight:bold;'>Particular</td>
<td style='padding: 8px;border: 1px solid #333333;font-weight:bold;'>Amount</td>
<td style='padding: 8px;border: 1px solid #333333;font-weight:bold;'>Discount</td>
<td style='padding: 8px;border: 1px solid #333333;font-weight:bold;'>Total</td>
</tr>
<tr>
<td style='padding: 8px;border-right: 1px solid #333333;border-left: 1px solid #333333;'> 1 </td>
<td style='padding: 8px;border-right: 1px solid #333333;border-left: 1px solid #333333;'> Booking for $frm_city_name - $to_city_name , $from_date - $to_date</td>
<td style='padding: 8px;border-right: 1px solid #333333;border-left: 1px solid #333333;'>$booking_amount</td>
<td style='padding: 8px;border-right: 1px solid #333333;border-left: 1px solid #333333;'>$discount_amount</td>
<td style='padding: 8px;border-right: 1px solid #333333;border-left: 1px solid #333333;font-weight:bold;text-align:right;'>$discount_total</td>
</tr>
$tr_line
$add_line
<tr>
<td colspan='2' style='padding: 8px;border: 1px solid #333333;border-right:0px;'>
<b>Trip Information</b><br/>$trip_details<br/>
<b>Special Instructions</b><br/>$remark
</td>
<td colspan='3'>
<table style='width: 100%;border-collapse: collapse; border-spacing: 0;font-size: 12px;font-family: sans-serif;'>
<tr>
<td style='padding: 8px;border: 1px solid #333333;font-weight:bold;'>Sub Total</td>
<td style='padding: 8px;border: 1px solid #333333;font-weight:bold;text-align:right;'>Rs.$sub_total/-</td>
</tr>
$tax_info
<tr>
<td style='padding: 8px;border: 1px solid #333333;font-weight:bold;'>Total Trip Amount</td>
<td style='padding: 8px;border: 1px solid #333333;font-weight:bold;text-align:right;'>Rs.$total_amt/-</td>
</tr>
<tr>
<td style='padding: 8px;border: 1px solid #333333;font-weight:bold;'>Paid Amount</td>
<td style='padding: 8px;border: 1px solid #333333;font-weight:bold;text-align:right;'>Rs.$advance/-</td>
</tr>
<tr>
<td style='padding: 8px;border: 1px solid #333333;border-bottom: 0px;font-weight:bold;'>Balance Amount</td>
<td style='padding: 8px;border: 1px solid #333333;border-bottom: 0px;font-weight:bold;text-align:right;'>Rs.$balance_amount/-</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan='5' style='padding: 8px;border: 1px solid #333333;'>
Total Amount in Words : <b>Rupees $txt_bal</b>
</td>
</tr>
<tr>
<td colspan='5' style='padding: 8px;border: 1px solid #333333;'> $extra </td>
</tr>
<tr>
<td colspan='5' style='padding: 8px;border: 1px solid #333333;'> More than coverage KM extra charges will be applicable* Coverage KM for this trip = $avg_km Extra per km cost for this trip = $extra_km_amt </td>
</tr>
$canshow_txt
$pack_txt
<tr>
<td colspan='2' style='padding: 8px;border: 1px solid #333333;border-top: 0px;'>
<b>For further details of vehicle & driver to check with us</b>
<table style='width: 100%;border-collapse: collapse; border-spacing: 0;font-size: 12px;font-family: sans-serif;'>
<tr>
<td>Mr. Vasu</td>
<td>9841698503</td>
</tr>
</table>
</td>
<td colspan='3' style='padding: 8px;border: 1px solid #333333;border-top: 0px;text-align:right;'>
<b>for Sri Bhagiyalakshmi Tours & Travels</b><br/><br/><br/><br/><br/><br/>
Authorised Signatory<br/>
</td>
</tr>
<table></div>";
//if($cust_email){ UDY :: REMOVE GS ASKED TO SEND WITH OUT TO EMAIL
$email_data = array(
'to_email' => $cust_email,
'subject' => "SBLT Booking Sheet for $tour_no",
'email_content' => $email_content,
'email_type' => "BOOKING",
);
//$this->Email_model->send_email($email_data);
$this->Email_model->send_phpmailer($email_data);
//}
if($mode === "RESEND"){
echo "<body style='background-color:#EEEEEE;'> <div style='padding:30px;background-color:#FFFFFF;'> $email_content </div> </body>";
}
}
public function resend_email($booking_id){
$this->send_email($booking_id,"RESEND");
}
public function numberTowords($number){
$no = round($number);
$point = round($number - $no, 2) * 100;
$hundred = null;
$digits_1 = strlen($no);
$i = 0;
$str = array();
$words = array('0' => '', '1' => 'One', '2' => 'Two',
'3' => 'Three', '4' => 'Four', '5' => 'Five', '6' => 'Six',
'7' => 'Seven', '8' => 'Eight', '9' => 'Nine',
'10' => 'Ten', '11' => 'Eleven', '12' => 'Twelve',
'13' => 'Thirteen', '14' => 'Fourteen',
'15' => 'Fifteen', '16' => 'Sixteen', '17' => 'Seventeen',
'18' => 'Eighteen', '19' =>'Nineteen', '20' => 'Twenty',
'30' => 'Thirty', '40' => 'Forty', '50' => 'Fifty',
'60' => 'Sixty', '70' => 'Seventy',
'80' => 'Eighty', '90' => 'Ninety');
$digits = array('', 'Hundred', 'Thousand', 'Lakh', 'Crore');
while ($i < $digits_1) {
$divider = ($i == 2) ? 10 : 100;
$number = floor($no % $divider);
$no = floor($no / $divider);
$i += ($divider == 10) ? 1 : 2;
if ($number) {
$plural = (($counter = count($str)) && $number > 9) ? 's' : null;
$hundred = ($counter == 1 && $str[0]) ? ' and ' : null;
$str [] = ($number < 21) ? $words[$number] .
" " . $digits[$counter] . $plural . " " . $hundred
:
$words[floor($number / 10) * 10]
. " " . $words[$number % 10] . " "
. $digits[$counter] . $plural . " " . $hundred;
} else $str[] = null;
}
$str = array_reverse($str);
$result = implode('', $str);
$points = ($point) ?
"." . $words[$point / 10] . " " .
$words[$point = $point % 10] : '';
//echo $result . "Rupees " . $points . " Paise";
return $result . "INR Only ";
}
public function delete(){
$booking_to_delete = $this->xss_clean($this->input->post('ids'));
if($this->Booking_model->delete_list($booking_to_delete)){
echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('booking_successful_deleted').' '. count($booking_to_delete).' '.$this->lang->line('booking_one_or_multiple')));
}else{
echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('booking_cannot_be_deleted')));
}
}
}
?>