File: /home/cafsindia/allyindian_com/sbltt/application/controllers/Acc_report.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once("Secure_Controller.php");
class Acc_report extends Secure_Controller
{
public function __construct()
{
parent::__construct('acc_report');
$this->load->model('Acc_report_model');
}
public function index()
{
if(!$this->Appconfig->isAppvalid()){
redirect('config');
}
$data['table_headers'] = $this->xss_clean(get_Acc_report_table_headers());
$this->load->view('acc_report/manage', $data);
}
/*
Returns Supplier table data rows. This will be called with AJAX.
*/
public function search()
{
$search = $this->input->get('search');
//echo "sat $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'));
$all_leads = $this->Acc_report_model->search($search, $filters, $limit, $offset, $sort, $order);
$total_rows = $this->Acc_report_model->get_found_rows($search, $filters);
$data_rows = array();
foreach($all_leads->result() as $leads){
$data_rows[] = get_Acc_report_data_row($leads, $this);
}
echo json_encode(array('total' => $total_rows, 'rows' => $data_rows));
}
public function excel($start_date, $end_date){
$this->load->library('excel');
$obj = new Excel();
// Add new sheet
$objWorkSheet = $obj->createSheet(0); //Setting index when creating
$obj->setActiveSheetIndex(0); //First sheet open in excel sheet
//Write cells head column name
$objWorkSheet->setCellValue('A1', 'Si.No')
->setCellValue('B1', 'Tour No')
->setCellValue('C1', 'Customer Name')
->setCellValue('D1', 'Billing Name')
->setCellValue('E1', 'Customer Mobile')
->setCellValue('F1', 'Trip Type')
->setCellValue('G1', 'Origin')
->setCellValue('H1', 'Destination')
->setCellValue('I1', 'Avg KM')
->setCellValue('J1', 'From Date')
->setCellValue('K1', 'To Date')
->setCellValue('L1', 'Trip Days')
->setCellValue('M1', 'Vehicle Type')
->setCellValue('N1', 'Vehicle Count')
->setCellValue('O1', 'Customer Type')
->setCellValue('P1', 'Driver Name')
->setCellValue('Q1', 'Ops Type')
->setCellValue('R1', 'Tp info')
->setCellValue('S1', 'Vehicle No')
->setCellValue('T1', 'Ref By')
->setCellValue('U1', 'Travels Name')
->setCellValue('V1', 'Start KM')
->setCellValue('W1', 'End KM')
->setCellValue('X1', 'Total KM')
->setCellValue('Y1', 'Extra KM')
->setCellValue('Z1', 'GST Rate')
->setCellValue('AA1', 'Hire Charge')//Booking amount
->setCellValue('AB1', 'Catering Amount')
->setCellValue('AC1', 'Stay Amount')
->setCellValue('AD1', 'Extra KM Amount')
->setCellValue('AE1', 'Total Hire Charge')
->setCellValue('AF1', 'GST')
->setCellValue('AG1', 'Total Inc Tax') //+gst
->setCellValue('AH1', 'Discount Amount')
->setCellValue('AI1', 'Receipt') //Advance amount
->setCellValue('AJ1', 'Balance Amount')
->setCellValue('AK1', 'Status');
//->setCellValue('1', '');
// set database value
$data = $this->Acc_report_model->excel_account_type_report($start_date, $end_date);
//print_r($data); die;
$i=2;
$k=1;
foreach ($data as $key => $value) {
$serial = $k;
$from_date = date('d-m-Y', strtotime($value['from_date']));
$to_date = date('d-m-Y', strtotime($value['to_date']));
$booking_id = $value['booking_id'];
$name = $value['customer_name'];
$mob = $value['phone_number'];
$origin = $value['frm_city_name'];
$destination = $value['to_city_name'];
$trip_days = $value['trip_days'];
$bus_count = $value['bus_count'];
$tour_no = $value['tour_no'];
$report_address = $value['report_address'];
$billing_name = $value['billing_name'];
$avg_km = $value['avg_km'];
$trip_type_name = $value['trip_type_name'];
$veh_type = $value['veh_type'];
$type = $value['booking_type_name'];
$trip_details = $value['trip_details'];
$operation_type = $value['operation_type'];
$booking_amount = $value['booking_amount'];
$advance_amount = $value['advance_amount'];
$balance_amount = $this->Acc_report_model->get_total_trip_amount($booking_id);
//$balance_amount = $value['balance_amount'];
$discount_amount = $value['discount_amount'];
$payment_type = $value['payment_type'];
$op_suspence_amt = $value['op_suspence_amt'];
$hire_charges = $value['hire_charges'];
$op_driver_name = $value['op_driver_name'];
$vehicle_no = $value['vehicle_no'];
$operation_sts = $value['operation_sts'];
$first_name = $value['first_name'];
$tp_info = $value['tp_info'];
$stay_tot_amt = $value['stay_tot_amt'];
$trip_start_km = $value['trip_start_km'];
$trip_end_km = $value['trip_end_km'];
$extra_km = $value['extra_km'];
$extra_amt = $value['extra_amt'];
$tax_precentage = $value['tax_precentage'];
$catering_amount = $value['catering_amount'];
$vendor_name = $value['vendor_name'];
if($operation_sts === "1"){
$operation_sts = "Follow Up";
}else
if($operation_sts === "2"){
$operation_sts = "Confirm";
}else
if($operation_sts === "3"){
$operation_sts = "Cancelled";
}else
if($operation_sts === "4"){
$operation_sts = "Completed";
}else
if($operation_sts === "5"){
$operation_sts = "On progress";
}
if($operation_type === "1"){
$operation_type = "Vehicle with Driver";
}else
if($operation_type === "2"){
$operation_type = "Driver Only";
}
//Total KM Calculation
$total_km = $trip_end_km - $trip_start_km;
//hire charge include all charge stay,catering,booking and extra km amount
$total_hire_charge = $booking_amount + $catering_amount + $stay_tot_amt + $extra_amt;
//gst calculation
$gst_amount=($total_hire_charge*$tax_precentage)/100;
//gst+total charge
$total_inc_gst_amount = $total_hire_charge + $gst_amount;
//receipt amount
$bal = $this->Acc_report_model->get_bal_log_amount($booking_id);
$advance_amt = $bal->bal_log_amt;
$receipt = $advance_amount+$advance_amt;
$objWorkSheet->setCellValue('A'.$i, $serial)
->setCellValue('B'.$i, $tour_no)
->setCellValue('C'.$i, $name)
->setCellValue('D'.$i, $billing_name)
->setCellValue('E'.$i, $mob)
->setCellValue('F'.$i, $trip_type_name)
->setCellValue('G'.$i, $origin)
->setCellValue('H'.$i, $destination)
->setCellValue('I'.$i, $avg_km)
->setCellValue('J'.$i, $from_date)
->setCellValue('K'.$i, $to_date)
->setCellValue('L'.$i, $trip_days)
->setCellValue('M'.$i, $veh_type)
->setCellValue('N'.$i, $bus_count)
->setCellValue('O'.$i, $type)
->setCellValue('P'.$i, $op_driver_name)
->setCellValue('Q'.$i, $operation_type)
->setCellValue('R'.$i, $tp_info)
->setCellValue('S'.$i, $vehicle_no)
->setCellValue('T'.$i, $first_name)
->setCellValue('U'.$i, $vendor_name)
->setCellValue('V'.$i, $trip_start_km)
->setCellValue('W'.$i, $trip_end_km)
->setCellValue('X'.$i, $total_km)
->setCellValue('Y'.$i, $extra_km)
->setCellValue('Z'.$i, $tax_precentage)
->setCellValue('AA'.$i, $booking_amount)
->setCellValue('AB'.$i, $catering_amount)
->setCellValue('AC'.$i, $stay_tot_amt)
->setCellValue('AD'.$i, $extra_amt)
->setCellValue('AE'.$i, $total_hire_charge)
->setCellValue('AF'.$i, $gst_amount)
->setCellValue('AG'.$i, $total_inc_gst_amount)
->setCellValue('AH'.$i, $discount_amount)
->setCellValue('AI'.$i, $receipt)
->setCellValue('AJ'.$i, $balance_amount)
->setCellValue('AK'.$i, $operation_sts);
//->setCellValue('AJ'.$i, $extra_amt);
//->setCellValue('AB'.$i, $stay_tot_amt)
//->setCellValue('AF'.$i, $amount);
$k++;
$i++;
}
// Rename worksheet name
$objWorkSheet->setTitle("Detailed");
$filename="Accounts Report_".date('d-m-Y').".xls"; //save our workbook as this file name
header('Content-Type: application/vnd.ms-excel'); //mime type
header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
header('Cache-Control: max-age=0'); //no cache
//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
//if you want to save it as .XLSX Excel 2007 format
$objWriter = PHPExcel_IOFactory::createWriter($obj, 'Excel5');
//force user to download the Excel file without writing it to server's HD
$objWriter->save('php://output');
}
}
?>