486 lines
20 KiB
PHP
486 lines
20 KiB
PHP
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
|
require APPPATH . '/libraries/BaseController.php';
|
|
|
|
/**
|
|
* Class : CostCenter (Cost Center Details - Controller)
|
|
* CostCenter Class to control all Cost Center related operations.
|
|
* @author : Venba Info Tech -
|
|
* @version : 1.1
|
|
* @since : 18 November 2017
|
|
*/
|
|
class CostCenter extends BaseController
|
|
{
|
|
/**
|
|
* default constructor of the class
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('costcenter_model');
|
|
$this->load->library('form_validation');
|
|
$this->load->library('pagination');
|
|
$this->isLoggedIn();
|
|
$this->CompanyName = $this->global['CompanyName'];
|
|
}
|
|
|
|
/**
|
|
* Index Page for this controller(default function of the class)
|
|
*/
|
|
public function index()
|
|
{
|
|
//$this->global['pageTitle'] = 'Resico : Cost Details';
|
|
$this->global['pageTitle'] = $this->CompanyName.' : Cost Details';
|
|
$this->loadViews("costListing", $this->global, NULL , NULL);
|
|
}
|
|
|
|
/**
|
|
* To load the Cost list
|
|
*/
|
|
function CostListing()
|
|
{
|
|
|
|
|
|
$data['userRecords'] = $this->costcenter_model->CostListing();
|
|
//$this->global['pageTitle'] = 'Resico : Cost List';
|
|
$this->global['pageTitle'] = $this->CompanyName.' : Cost Details';
|
|
$this->loadViews("costListing", $this->global, $data, NULL);
|
|
|
|
}
|
|
|
|
/**
|
|
* To load the add new cost Center
|
|
*/
|
|
function addCostCenter()
|
|
{
|
|
|
|
$data['Department'] = $this->costcenter_model->getDepartment();
|
|
|
|
$data['BudgetType'] = $this->costcenter_model->getConfigValue('C004');
|
|
|
|
$data['Approver'] = $this->costcenter_model->getApproverName();
|
|
|
|
$data['FiscalYear'] = $this->costcenter_model->getFiscalYear();
|
|
|
|
//$this->global['pageTitle'] = 'Resico : Add Cost Center';
|
|
$this->global['pageTitle'] = $this->CompanyName.' : Add Cost Center';
|
|
|
|
$this->loadViews("addCostCenter", $this->global,$data, NULL);
|
|
|
|
}
|
|
|
|
/**
|
|
* Validation for Selected Department
|
|
*/
|
|
function Dep_SelectedDepartment($selectValue)
|
|
{
|
|
if(strlen($SelectedDepartment) <= 0 )
|
|
{
|
|
$this->form_validation->set_message('Dep_SelectedDepartment', 'Please Select Department.');
|
|
return false;
|
|
}
|
|
else // user picked something
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* To Store the add new Cost center details into DB
|
|
*/
|
|
function addNewcost()
|
|
{
|
|
|
|
$this->form_validation->set_rules('CostCode','CostCode','trim|required');
|
|
$this->form_validation->set_rules('CostName','CostName','trim|required');
|
|
|
|
if($this->form_validation->run() == FALSE)
|
|
{
|
|
$this->addCostCenter();
|
|
}
|
|
else
|
|
{
|
|
$CostCode = strtoupper(trim($this->input->post('CostCode')));
|
|
$CostName = strtoupper(trim($this->input->post('CostName')));
|
|
$CreateBy = $this->session->userdata ( 'userId' );
|
|
$SelectedDepartment = $this->input->post('txtSelectedDepartment');
|
|
//echo $SelectedDepartment;
|
|
$ApproverName = $this->input->post('ApprovedBy');
|
|
$comma_separated = explode(':', $SelectedDepartment);
|
|
$dt = new DateTime('now', new DateTimeZone('Asia/Kolkata'));
|
|
|
|
$createddt = $dt->format('Y-m-d H:i:s');
|
|
|
|
$CodeExists = $this->costcenter_model->checkCostDetailsExists( $CostCode);
|
|
|
|
if(count($CodeExists) == 0)
|
|
{
|
|
$Cost = array('CostCenterCode'=>$CostCode, 'CostCenterName'=>$CostName,'ApprovedBy'=>$ApproverName,'CreatedBy'=>$CreateBy,'createdDate'=>$createddt);
|
|
$this->costcenter_model->addNewcost($Cost);
|
|
}
|
|
|
|
for ($j = 0; $j < count($comma_separated); $j++)
|
|
{
|
|
$DeptCode = $comma_separated[$j];
|
|
|
|
$this->costcenter_model->DeleteDepartment( $DeptCode,$CostCode);
|
|
|
|
$Dept = array('CostCenterCode'=>$CostCode, 'DEPCode'=>$DeptCode,'CreatedBy'=>$CreateBy,'createdDate'=>$createddt);
|
|
$this->costcenter_model->addCostCenterDepartment($Dept);
|
|
|
|
}
|
|
$RowCount = $this->input->post('txtRowCount');
|
|
|
|
for ($i = 1; $i <= $RowCount; $i++)
|
|
{
|
|
$BudgetType = $this->input->post('BudgetType'.$i);
|
|
$BudgetYear = $this->input->post('BudgetYear'.$i);
|
|
$BudgetAmount = $this->input->post('BudgetAmount'.$i);
|
|
$Remarks = $this->input->post('Remarks'.$i);
|
|
$this->costcenter_model->DeleteBudget( $BudgetType,$BudgetYear,$CostCode);
|
|
|
|
$Budget = array('CostCenterCode'=>$CostCode, 'BudgetType'=>$BudgetType,'BudgetYear'=>$BudgetYear,'BudgetAmount'=>$BudgetAmount,'Remarks'=>$Remarks,'CreatedBy'=>$CreateBy,'createdDate'=>$createddt);
|
|
$this->costcenter_model->addBudget($Budget);
|
|
|
|
}
|
|
|
|
Print_r('Successfully Created Cost details');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* To load Exists information and load edit costcenter screen
|
|
*/
|
|
function editOldcost($CostCode = NULL)
|
|
{
|
|
|
|
if($CostCode == '')
|
|
{
|
|
$CostCenterID = $_GET['CostCode'];
|
|
}
|
|
else
|
|
{
|
|
$CostCenterID = $CostCode;
|
|
}
|
|
|
|
$data['CostMaster'] = $this->costcenter_model->GetCostCenterMaster($CostCenterID);
|
|
$data['CostDepts'] = $this->costcenter_model->GetCostCenterDepartment($CostCenterID);
|
|
$data['CostBudget'] = $this->costcenter_model->GetCostCenterBudget($CostCenterID);
|
|
$data['DeptList'] = $this->costcenter_model->GetDepartmentNotinCostCenter($CostCenterID);
|
|
$data['BudType'] = $this->costcenter_model->GetBudgetTypeNotinCostCenter($CostCenterID,'C004');
|
|
$data['BudYear'] = $this->costcenter_model->GetBudgetYear($CostCenterID);
|
|
$data['FiscalYear'] = $this->costcenter_model->getFiscalYear();
|
|
|
|
//$this->global['pageTitle'] = 'Resico : Edit Cost';
|
|
$this->global['pageTitle'] = $this->CompanyName.' : Edit Cost Center';
|
|
|
|
$this->loadViews("editCostCenter", $this->global, $data,NULL);
|
|
}
|
|
|
|
/**
|
|
* For display budget related information by using year-wise
|
|
*/
|
|
function GetBudgetForYear()
|
|
{
|
|
|
|
$BudYear = $_GET['BudYear'];
|
|
$CostCenterID = $_GET['CostCode'];
|
|
$result = $this->costcenter_model->GetCostCenterBudgetByYear($CostCenterID, $BudYear);
|
|
$BudList = $this->costcenter_model->GetCostBudgetTypeByYear($CostCenterID,'C004', $BudYear);
|
|
|
|
$HTML="";
|
|
$HTML2="";
|
|
$index = 0;
|
|
|
|
for ($j = 0; $j < count($BudList); $j++)
|
|
{
|
|
$ConfigValue = $BudList[$j]['ConfigValue'];
|
|
$HTML2.="<option value='".$ConfigValue."'>".$ConfigValue."</option>";
|
|
}
|
|
|
|
for ($i = 0; $i < count($result); $i++)
|
|
{
|
|
$index = $index + 1;
|
|
$BudgetType = $result[$i]['BudgetType'];
|
|
$BudgetYear = $result[$i]['BudgetYear'];
|
|
$BudgetAmount = $result[$i]['BudgetAmount'];
|
|
$Remarks = $result[$i]['Remarks'];
|
|
$HTML.="<tr id='".$index."'>
|
|
<td align='left'>". $BudgetType."</td>
|
|
<input type='hidden' name='BudgetType".$index."' id='BudgetType".$index."' value='". $BudgetType."'/>
|
|
<input type='hidden' name='BudgetYear".$index."' id='BudgetYear".$index."' value='". $BudgetYear."'/>
|
|
<input type='hidden' name='BudgetAmount".$index."' id='BudgetAmount".$index."' value='". $BudgetAmount."'/>
|
|
<input type='hidden' name='Remarks".$index."' id='Remarks".$index."' value='". $Remarks."'/>
|
|
|
|
<td align='left'>".$BudgetYear."</td>
|
|
|
|
<td align='left'>".$BudgetAmount."</td>
|
|
|
|
<td align='left'>".$Remarks."</td>
|
|
|
|
<td>
|
|
<a data-target='#Edit' data-id=".$index." data-userid=".$index." data-toggle='modal' href='#Edit'><i class='fa fa-pencil' data-toggle='tooltip' title='Click here to view/Edit the ".$BudgetType." Budget details'></i> </a> </td></tr>
|
|
";
|
|
}
|
|
$HTML.="<input type='hidden' name='txtRowCount' id='txtRowCount' value='".$index ."'/>";
|
|
die(json_encode(array('Html' => $HTML,'BudYear' => $HTML2)));
|
|
|
|
}
|
|
|
|
/**
|
|
* To edit the costcenter information
|
|
*/
|
|
function editcost()
|
|
{
|
|
|
|
$this->form_validation->set_rules('CostCode','CostCode','trim|required');
|
|
$this->form_validation->set_rules('CostName','CostName','trim|required');
|
|
|
|
if($this->form_validation->run() == FALSE)
|
|
{
|
|
$this->addCostCenter();
|
|
}
|
|
else
|
|
{
|
|
$CostCode = strtoupper(trim($this->input->post('CostCode')));
|
|
$CostName = strtoupper(trim($this->input->post('CostName')));
|
|
$updatedBy = $this->session->userdata ( 'userId' );
|
|
$SelectedDepartment = $this->input->post('txtSelectedDepartment');
|
|
$ApproverName = $this->input->post('ApprovedBy');
|
|
$comma_separated = "";
|
|
|
|
if(strlen($SelectedDepartment)>0)
|
|
{
|
|
|
|
$comma_separated = explode(':', $SelectedDepartment);
|
|
}
|
|
|
|
$dt = new DateTime('now', new DateTimeZone('Asia/Kolkata'));
|
|
$updateddt = $dt->format('Y-m-d H:i:s');
|
|
$CodeExists = $this->costcenter_model->checkCostDetailsExists($CostCode);
|
|
|
|
if(count($CodeExists) > 0)
|
|
{
|
|
$Cost = array( 'CostCenterName'=>$CostName,'ApprovedBy'=>$ApproverName,'UpdatedBy'=>$updatedBy,'UpdatedDate'=>$updateddt);
|
|
$this->costcenter_model->EditCost($Cost,$CostCode);
|
|
}
|
|
|
|
$RowCount = $this->input->post('txtRowCount');
|
|
|
|
for ($i = 1; $i <= $RowCount; $i++)
|
|
{
|
|
$BudgetType = $this->input->post('BudgetType'.$i);
|
|
$BudgetYear = $this->input->post('BudgetYear'.$i);
|
|
$BudgetAmount = $this->input->post('BudgetAmount'.$i);
|
|
$Remarks = $this->input->post('Remarks'.$i);
|
|
|
|
$Budget = array('CostCenterCode'=>$CostCode, 'BudgetType'=>$BudgetType,'BudgetYear'=>$BudgetYear,'BudgetAmount'=>$BudgetAmount,'Remarks'=>$Remarks,'CreatedBy'=>$updatedBy,'createdDate'=>$updateddt,'UpdatedBy'=>$updatedBy,'UpdatedDate'=>$updateddt);
|
|
$ExistYearBudget = $this->costcenter_model->CheckExistBudget($BudgetType,$BudgetYear,$CostCode);
|
|
|
|
if($ExistYearBudget){
|
|
$this->costcenter_model->updateBudget($Budget,$BudgetType,$BudgetYear,$CostCode);
|
|
}
|
|
else{
|
|
$this->costcenter_model->addBudget($Budget);
|
|
}
|
|
}
|
|
|
|
echo('Successfully Updated Cost details');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* To Remove/delete costcenter's department details into database
|
|
*/
|
|
function DeleteCostDepartment()
|
|
{
|
|
|
|
$CostCode = strtoupper(trim($this->input->post('CostCode')));
|
|
$CostName = strtoupper(trim($this->input->post('CostName')));
|
|
$updatedBy = $this->session->userdata ( 'userId' );
|
|
$SelectedDepartment = $this->input->post('txtSelectedDepartment');
|
|
$this->costcenter_model->DeleteDepartment($SelectedDepartment,$CostCode);
|
|
echo ("Department Removed Successfully");
|
|
}
|
|
|
|
/**
|
|
* To store/add the costcenter's department details into DB
|
|
*/
|
|
function AddCostDepartment()
|
|
{
|
|
$CostCode = strtoupper(trim($this->input->post('CostCode')));
|
|
$CostName = strtoupper(trim($this->input->post('CostName')));
|
|
$updatedBy = $this->session->userdata ( 'userId' );
|
|
$SelectedDepartment = $this->input->post('txtSelectedDepartment');
|
|
$dt = new DateTime('now', new DateTimeZone('Asia/Kolkata'));
|
|
$updateddt = $dt->format('Y-m-d H:i:s');
|
|
|
|
$Dept = array('CostCenterCode'=>$CostCode, 'DEPCode'=>$SelectedDepartment,'CreatedBy'=>$updatedBy,'createdDate'=>$updateddt,'UpdatedBy'=>$updatedBy,'UpdatedDate'=>$updateddt);
|
|
$this->costcenter_model->addCostCenterDepartment($Dept);
|
|
echo ("Department Added Successfully");
|
|
}
|
|
|
|
|
|
/**
|
|
* To view costcenter exsits information and load into edit cost coster screen
|
|
* */
|
|
function viewcost($CostCenterID = NULL)
|
|
{
|
|
|
|
if($CostCenterID == null)
|
|
{
|
|
redirect('costListing');
|
|
}
|
|
|
|
$data['Cost'] = $this->costcenter_model->getuserinfo($CostCenterID);
|
|
|
|
//$this->global['pageTitle'] = 'Resico : View Cost Details';
|
|
$this->global['pageTitle'] = $this->CompanyName.' : View Cost Details';
|
|
|
|
$this->loadViews("viewcost", $this->global, $data,NULL);
|
|
|
|
}
|
|
|
|
/**
|
|
* To delete costcenter details.
|
|
* Note: this function tsemporary not in use.
|
|
*/
|
|
function deletecost()
|
|
{
|
|
if($this->isAdmin() == TRUE)
|
|
{
|
|
echo(json_encode(array('status'=>'access')));
|
|
}
|
|
else
|
|
{
|
|
$CostCenterID = $this->input->Costst('CostCentreID');
|
|
$cost = array('CreateDate'=>date('Y-m-d H:i:sa'));
|
|
|
|
$result = $this->costcenter_model->deletecost($Cost, $CostCenterID);
|
|
|
|
if ($result > 0) { echo(json_encode(array('status'=>TRUE))); }
|
|
else { echo(json_encode(array('status'=>FALSE))); }
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* To export report of costcenter details in excel
|
|
*/
|
|
function export_cost(){
|
|
|
|
|
|
$this->load->library('excel');
|
|
$this->excel->setActiveSheetIndex(0)->mergeCells('G3:M3');
|
|
$this->excel->setActiveSheetIndex(0)->getStyle('G3')->getAlignment()->applyFromArray(
|
|
array('horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,)
|
|
);
|
|
|
|
$this->excel->getActiveSheet()->setTitle('Cost Master');
|
|
|
|
|
|
$this->excel->getActiveSheet()->setCellValue('G3', strtoupper($this->CompanyName).' Cost Master');
|
|
$this->excel->getActiveSheet()->setCellValue('C5', 'S.No');
|
|
$this->excel->getActiveSheet()->setCellValue('D5', 'CostCenterCode');
|
|
$this->excel->getActiveSheet()->setCellValue('E5', 'CostCenterName');
|
|
$this->excel->getActiveSheet()->setCellValue('F5', 'CAPITAL');
|
|
$this->excel->getActiveSheet()->setCellValue('G5', 'REVENUE');
|
|
$this->excel->getActiveSheet()->setCellValue('H5', 'IMPORT');
|
|
$this->excel->getActiveSheet()->setCellValue('I5', 'SERVICE');
|
|
$this->excel->getActiveSheet()->setCellValue('J5', 'BudgetYear');
|
|
$this->excel->getActiveSheet()->setCellValue('K5', 'DepartmentName');
|
|
$this->excel->getActiveSheet()->setCellValue('L5', 'IsActive');
|
|
$this->excel->getActiveSheet()->setCellValue('M5', 'CreatedBy');
|
|
$this->excel->getActiveSheet()->setCellValue('N5', 'UpdatedBy');
|
|
$this->excel->getActiveSheet()->setCellValue('O5', 'IsApproved');
|
|
$this->excel->getActiveSheet()->setCellValue('P5', 'ApprovedBy');
|
|
|
|
|
|
$this->excel->getActiveSheet()->getStyle('G3')->getFont()->setSize(14);
|
|
$this->excel->getActiveSheet()->getStyle('G3')->getFont()->setBold(true);
|
|
$this->excel->getActiveSheet()->getStyle('C5')->getFont()->setSize(12);
|
|
$this->excel->getActiveSheet()->getStyle('C5')->getFont()->setBold(true);
|
|
$this->excel->getActiveSheet()->getStyle('D5')->getFont()->setSize(12);
|
|
$this->excel->getActiveSheet()->getStyle('D5')->getFont()->setBold(true);
|
|
$this->excel->getActiveSheet()->getStyle('E5')->getFont()->setSize(12);
|
|
$this->excel->getActiveSheet()->getStyle('E5')->getFont()->setBold(true);
|
|
$this->excel->getActiveSheet()->getStyle('F5')->getFont()->setSize(12);
|
|
$this->excel->getActiveSheet()->getStyle('F5')->getFont()->setBold(true);
|
|
$this->excel->getActiveSheet()->getStyle('G5')->getFont()->setSize(12);
|
|
$this->excel->getActiveSheet()->getStyle('G5')->getFont()->setBold(true);
|
|
$this->excel->getActiveSheet()->getStyle('H5')->getFont()->setSize(12);
|
|
$this->excel->getActiveSheet()->getStyle('H5')->getFont()->setBold(true);
|
|
$this->excel->getActiveSheet()->getStyle('I5')->getFont()->setSize(12);
|
|
$this->excel->getActiveSheet()->getStyle('I5')->getFont()->setBold(true);
|
|
$this->excel->getActiveSheet()->getStyle('J5')->getFont()->setSize(12);
|
|
$this->excel->getActiveSheet()->getStyle('J5')->getFont()->setBold(true);
|
|
$this->excel->getActiveSheet()->getStyle('K5')->getFont()->setSize(12);
|
|
$this->excel->getActiveSheet()->getStyle('K5')->getFont()->setBold(true);
|
|
$this->excel->getActiveSheet()->getStyle('L5')->getFont()->setSize(12);
|
|
$this->excel->getActiveSheet()->getStyle('L5')->getFont()->setBold(true);
|
|
$this->excel->getActiveSheet()->getStyle('M5')->getFont()->setSize(12);
|
|
$this->excel->getActiveSheet()->getStyle('M5')->getFont()->setBold(true);
|
|
$this->excel->getActiveSheet()->getStyle('N5')->getFont()->setSize(12);
|
|
$this->excel->getActiveSheet()->getStyle('N5')->getFont()->setBold(true);
|
|
$this->excel->getActiveSheet()->getStyle('O5')->getFont()->setSize(12);
|
|
$this->excel->getActiveSheet()->getStyle('O5')->getFont()->setBold(true);
|
|
$this->excel->getActiveSheet()->getStyle('P5')->getFont()->setSize(12);
|
|
$this->excel->getActiveSheet()->getStyle('P5')->getFont()->setBold(true);
|
|
|
|
|
|
$exportData = $this->costcenter_model->export_excel();
|
|
if ($exportData) {
|
|
$i = 6;
|
|
$s = 1;
|
|
foreach ($exportData as $data) {
|
|
|
|
$this->excel->getActiveSheet()->setCellValue('C'. $i,$s);
|
|
|
|
$this->excel->getActiveSheet()->setCellValue('D'. $i,$data['CostCenterCode']);
|
|
$this->excel->getActiveSheet()->setCellValue('E'. $i,$data['CostCenterName']);
|
|
$this->excel->getActiveSheet()->setCellValue('F'. $i,$data['capital']);
|
|
$this->excel->getActiveSheet()->setCellValue('G'. $i,$data['revenue']);
|
|
$this->excel->getActiveSheet()->setCellValue('H'. $i,$data['import']);
|
|
$this->excel->getActiveSheet()->setCellValue('I'. $i,$data['service']);
|
|
$this->excel->getActiveSheet()->setCellValue('J'. $i,$data['BudgetYear']);
|
|
$this->excel->getActiveSheet()->setCellValue('K'. $i,$data['DepartmentName']);
|
|
$this->excel->getActiveSheet()->setCellValue('L'. $i,$data['IsActive']);
|
|
$this->excel->getActiveSheet()->setCellValue('M'. $i,$data['firstname']);
|
|
$this->excel->getActiveSheet()->setCellValue('N'. $i,$data['Updated_By']);
|
|
$this->excel->getActiveSheet()->setCellValue('O'. $i,$data['IsApproved']);
|
|
$this->excel->getActiveSheet()->setCellValue('P'. $i,$data['firstname']);
|
|
|
|
$i++;
|
|
$s++;
|
|
}
|
|
}
|
|
|
|
$filename = 'Cost_Master' .' '. '.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
|
|
$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');
|
|
if (ob_get_contents()) ob_end_clean();
|
|
ob_start();
|
|
$objWriter->save('php://output');
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
* To load pagenotfound view
|
|
*/
|
|
function pageNotFound()
|
|
{
|
|
//$this->global['pageTitle'] = 'Resico : 404 - Page Not Found';
|
|
$this->global['pageTitle'] = $this->CompanyName.' : 404 - Page Not Found';
|
|
|
|
$this->loadViews("404", $this->global, NULL, NULL);
|
|
}
|
|
}
|
|
|
|
?>
|