// gl and gl2 excel file Export Program
public function glExcelFileExport()
{
$from_date1 = $this->input->post('from_date1');
$to_date1 = $this->input->post('to_date1');
$account_number = $this->input->post('account_number');
$glnames = $this->input->post('glnames');
$sql = "SELECT * FROM ut_sbi_reco_rungl WHERE value_date between '".$from_date1."' AND '".$to_date1."' ";
$result = $this->db->query($sql)->result_array();
if(count($result)>0)
{
require FCPATH . 'vendor/autoload.php';
$object = new PHPExcel();
$prestasi = $object->setActiveSheetIndex(0);
//manage row hight
$object->getActiveSheet()->getRowDimension(1)->setRowHeight(25);
// Excel Heading Description
if($glnames == 'gl1') {
//style alignment
$styleArray = array(
'alignment' => array('horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
),
);
$object->getActiveSheet()->getStyle('A1:U1')->getFont()->setBold(true);
$object->getActiveSheet()->getStyle('A1:U1')->applyFromArray($styleArray);
//border
$styleArray1 = array(
'borders' => array(
'allborders' => array(
'style' => PHPExcel_Style_Border::BORDER_THIN
)
)
);
//background
$styleArray12 = array(
'fill' => array(
'type' => PHPExcel_Style_Fill::FILL_SOLID,
'startcolor' => array(
'rgb' => 'FFFF00',
),
),
);
//freeepane
$object->getActiveSheet()->freezePane('A2');
//column width
$object->getActiveSheet()->getColumnDimension('A')->setWidth(15);
$object->getActiveSheet()->getColumnDimension('B')->setWidth(15);
$object->getActiveSheet()->getColumnDimension('C')->setWidth(15);
$object->getActiveSheet()->getColumnDimension('D')->setWidth(20);
$object->getActiveSheet()->getColumnDimension('E')->setWidth(20);
$object->getActiveSheet()->getColumnDimension('F')->setWidth(12);
$object->getActiveSheet()->getColumnDimension('G')->setWidth(15);
$object->getActiveSheet()->getColumnDimension('H')->setWidth(20);
$object->getActiveSheet()->getColumnDimension('I')->setWidth(20);
$object->getActiveSheet()->getColumnDimension('J')->setWidth(20);
$object->getActiveSheet()->getColumnDimension('K')->setWidth(20);
$object->getActiveSheet()->getColumnDimension('L')->setWidth(10);
$object->getActiveSheet()->getColumnDimension('M')->setWidth(12);
$object->getActiveSheet()->getColumnDimension('N')->setWidth(25);
$object->getActiveSheet()->getColumnDimension('O')->setWidth(15);
$object->getActiveSheet()->getColumnDimension('P')->setWidth(15);
$object->getActiveSheet()->getColumnDimension('Q')->setWidth(15);
$object->getActiveSheet()->getColumnDimension('R')->setWidth(15);
$object->getActiveSheet()->getColumnDimension('S')->setWidth(15);
$object->getActiveSheet()->getColumnDimension('T')->setWidth(25);
$object->getActiveSheet()->getColumnDimension('U')->setWidth(15);
$object->getActiveSheet()->getStyle('A1:U1')->applyFromArray($styleArray1);
$object->getActiveSheet()->getStyle('A1:U1')->applyFromArray($styleArray12);
$object->getActiveSheet()->getStyle('I')->getNumberFormat()->setFormatCode("0.00");
$table_columns = array("SRL", "Scheme", "Tran Type", "App Refer", "OTH Refer",
"Account", "Name", "Value Date", "Amount", "Pay Category", "Rev Flg",
"Security", "Cheque Number", "SCH", "Book Date", "Cheque Date",
"Reg Id", "Inputter", "Narration", "FL", "Batch Number");
$column = 0;
foreach($table_columns as $field)
{
$object->getActiveSheet()->setCellValueByColumnAndRow($column, 1, $field);
$column++;
}
}
if($glnames == 'gl2') {
//style alignment
$styleArray = array(
'alignment' => array('horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
),
);
$object->getActiveSheet()->getStyle('A1:C1')->getFont()->setBold(true);
$object->getActiveSheet()->getStyle('A1:C1')->applyFromArray($styleArray);
//border
$styleArray1 = array(
'borders' => array(
'allborders' => array(
'style' => PHPExcel_Style_Border::BORDER_THIN
)
)
);
//background
$styleArray12 = array(
'fill' => array(
'type' => PHPExcel_Style_Fill::FILL_SOLID,
'startcolor' => array(
'rgb' => 'FFFF00',
),
),
);
//freeepane
$object->getActiveSheet()->freezePane('A2');
//column width
$object->getActiveSheet()->getColumnDimension('A')->setWidth(15);
$object->getActiveSheet()->getColumnDimension('B')->setWidth(15);
$object->getActiveSheet()->getColumnDimension('C')->setWidth(15);
$object->getActiveSheet()->getStyle('A1:C1')->applyFromArray($styleArray1);
$object->getActiveSheet()->getStyle('A1:C1')->applyFromArray($styleArray12);
$object->getActiveSheet()->getStyle('C')->getNumberFormat()->setFormatCode("0.00");
$table_columns1 = array("Account", "Name", "Amount");
$column1 = 0;
foreach($table_columns1 as $field1)
{
$object->getActiveSheet()->setCellValueByColumnAndRow($column1, 1, $field1);
$column1++;
}
}
// List of column names
$style = array(
'alignment' => array(
'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
)
);
$prestasi->getDefaultStyle()->applyFromArray($style);
if($glnames == 'gl1') {
// Gl1 Query
$excel_row = 2;
for ($kk=0;$kk<count($account_number);$kk++)
{
$account_number2 = $account_number[$kk];
$gl1Arr = $this->ut_gl_model->getDisplayGl1Query($account_number2,$from_date1,$to_date1);
foreach($gl1Arr as $row)
{
$object->getActiveSheet()->setCellValueByColumnAndRow(0, $excel_row, $row['srl']);
$object->getActiveSheet()->setCellValueByColumnAndRow(1, $excel_row, $row['scheme']);
$object->getActiveSheet()->setCellValueByColumnAndRow(2, $excel_row, $row['tran_type']);
$object->getActiveSheet()->setCellValueByColumnAndRow(3, $excel_row, $row['app_refer']);
$object->getActiveSheet()->setCellValueByColumnAndRow(4, $excel_row, $row['oth_refer']);
$object->getActiveSheet()->setCellValueByColumnAndRow(5, $excel_row, $row['account']);
$object->getActiveSheet()->setCellValueByColumnAndRow(6, $excel_row, $row['name']);
$object->getActiveSheet()->setCellValueByColumnAndRow(7, $excel_row, (isset($row['value_date']) && $row['value_date']!='0000-00-00')?date('d/m/Y',strtotime($row['value_date'])):'');
$object->getActiveSheet()->setCellValueByColumnAndRow(8, $excel_row, $row['amt']);
$object->getActiveSheet()->setCellValueByColumnAndRow(9, $excel_row, $row['pay_catego']);
$object->getActiveSheet()->setCellValueByColumnAndRow(10, $excel_row, $row['rev_flg']);
$object->getActiveSheet()->setCellValueByColumnAndRow(11, $excel_row, $row['security']);
$object->getActiveSheet()->setCellValueByColumnAndRow(12, $excel_row, $row['chq_number']);
$object->getActiveSheet()->setCellValueByColumnAndRow(13, $excel_row, 'y');
$object->getActiveSheet()->setCellValueByColumnAndRow(14, $excel_row, (isset($row['book_date']) && $row['book_date']!='0000-00-00')?date('d/m/Y',strtotime($row['book_date'])):'');
$object->getActiveSheet()->setCellValueByColumnAndRow(15, $excel_row, (isset($row['chq_date']) && $row['chq_date']!='0000-00-00')?date('d/m/Y',strtotime($row['chq_date'])):'');
$object->getActiveSheet()->setCellValueByColumnAndRow(16, $excel_row, $row['reg_id']);
$object->getActiveSheet()->setCellValueByColumnAndRow(17, $excel_row, $row['inputter']);
$object->getActiveSheet()->setCellValueByColumnAndRow(18, $excel_row, $row['narration']);
$object->getActiveSheet()->setCellValueByColumnAndRow(19, $excel_row, '');
$object->getActiveSheet()->setCellValueByColumnAndRow(20, $excel_row, '');
$excel_row++;
}
}
// Excel Download Logic
$downloadFile = 'gl1_'.date('Ymd').'.xlsx';
$prestasi->setTitle("Gl1 Dump");
$object_writer = PHPExcel_IOFactory::createWriter($object, 'Excel2007');
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'.$downloadFile.'" ');
$object_writer->save('php://output');
}
$excel_row1 = 2;
if($glnames == 'gl2') {
// Gl2 Query
for ($jj=0;$jj<count($account_number);$jj++)
{
$account_number3 = $account_number[$jj];
$gl2Arr = $this->ut_gl_model->getDisplayGl2Query($account_number3,$from_date1,$to_date1);
foreach($gl2Arr as $row1)
{
$object->getActiveSheet()->setCellValueByColumnAndRow(0, $excel_row1, $row1['account']);
$object->getActiveSheet()->setCellValueByColumnAndRow(1, $excel_row1, $row1['name']);
$object->getActiveSheet()->setCellValueByColumnAndRow(2, $excel_row1, $row1['amount']);
// $object->getActiveSheet()->setCellValueByColumnAndRow(3, $excel_row1, $row1['value_date']);
$excel_row1++;
}
}
// Excel Download Logic
$prestasi->setTitle("Gl2 Dump");
$downloadFile2 = 'gl2_'.date('Ymd').'.xlsx';
$object_writer = PHPExcel_IOFactory::createWriter($object, 'Excel2007');
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'.$downloadFile2.'" ');
$object_writer->save('php://output');
}
}
else
{
$this->session->set_flashdata('error', 'Data not found.');
redirect(site_url('sbi-reco/run-gl'));
}
}