Cost center

This commit is contained in:
gandhimathi Bharathirajan 2017-05-04 18:51:32 +05:30
parent 0b73a68f1e
commit dff4fb7bc7

View File

@ -20,6 +20,7 @@ class CostCenter extends BaseController
$this->load->model('costcenter_model'); $this->load->model('costcenter_model');
//$this->load->library('session'); //$this->load->library('session');
$this->load->library('form_validation'); $this->load->library('form_validation');
$this->load->library('pagination');
$this->isLoggedIn(); $this->isLoggedIn();
} }
@ -39,12 +40,11 @@ class CostCenter extends BaseController
function CostListing() function CostListing()
{ {
$this->load->model('costcenter_model'); //$this->load->model('costcenter_model');
$searchText = $this->input->post('searchText'); $searchText = $this->input->post('searchText');
$data['searchText'] = $searchText; $data['searchText'] = $searchText;
$this->load->library('pagination');
$count = $this->costcenter_model->costListingCount($searchText); $count = $this->costcenter_model->costListingCount($searchText);
@ -52,83 +52,115 @@ class CostCenter extends BaseController
$data['userRecords'] = $this->costcenter_model->costListing($searchText, $returns["page"], $returns["segment"]); $data['userRecords'] = $this->costcenter_model->costListing($searchText, $returns["page"], $returns["segment"]);
$this->global['pageTitle'] = 'Siddharth : Cost List'; $this->global['pageTitle'] = 'Siddharth : Test List';
$this->loadViews("costListing", $this->global, $data, NULL); $this->loadViews("costListing", $this->global, $data, NULL);
} }
/**
* This function is used to load the add new cost */
function addcost()
{
$this->load->model('costcenter_model');
//$data['costName'] = $this->purchaseorder_model->getcostName();
//$data['users'] = $this->purchaseorder_model->getusers();
$this->global['pageTitle'] = 'siddharth : Add Cost';
$this->loadViews("addcost", $this->global, NULL);
}
/** /**
* This function is used to load the add new cost Center */ * This function is used to load the add new cost Center */
function addCostCenter() function addCostCenter()
{ {
$this->load->model('costcenter_model'); $data['Department'] = $this->costcenter_model->getDepartment();
//$data['costName'] = $this->purchaseorder_model->getcostName();
//$data['users'] = $this->purchaseorder_model->getusers(); $data['BudgetType'] = $this->costcenter_model->getConfigValue('C004');
$data['Approver'] = $this->costcenter_model->getApproverName();
$this->global['pageTitle'] = 'siddharth : Add Cost Center'; $this->global['pageTitle'] = 'siddharth : Add Cost Center';
$this->loadViews("addCostCenter", $this->global, NULL); $this->loadViews("addCostCenter", $this->global,$data, NULL);
} }
/** /**
* This function is used to add new Cost to the system * This function is used to add new Cost to the system
*/ */
function addNewcost() function addNewcost()
{ {
$this->load->library('form_validation');
$this->form_validation->set_rules('CostCode','CostCode','trim|required');
$this->form_validation->set_rules('CostName','CostName','trim|required');
$this->form_validation->set_rules('CostName','Address','trim|required|'); $SelectedDepartment = $this->input->post('txtSelectedDepartment');
$this->form_validation->set_rules('Description','Contact Number','trim'); $ApproverName = $this->input->post('ApprovedBy');
//print_r($ApproverName);
$Deptlist = explode(':', $SelectedDepartment);
if(strlen($SelectedDepartment) <= 0 )
{
print_r('Please select Department');
return;
}
$RowCount = $this->input->post('txtRowCount');
if($RowCount <= 0 )
{
print_r('Please Add Budget');
return;
}
if($ApproverName == "-1" )
{
print_r('Please Select Approver');
return;
}
if($this->form_validation->run() == FALSE) if($this->form_validation->run() == FALSE)
{ {
$this->addcost(); $this->addCostCenter();
} }
else else
{ {
$CostName = ($this->input->post('CostName')); $CostCode = strtoupper(trim($this->input->post('CostCode')));
$Description = $this->input->post('Description'); $CostName = strtoupper(trim($this->input->post('CostName')));
$CreateBy = $this->session->userdata ( 'userId' );
$SelectedDepartment = $this->input->post('txtSelectedDepartment');
$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('CostName'=>$CostName, 'Description'=>$Description,'createdDate'=>date('Y-m-d H:i:sa'));
$this->load->model('costcenter_model');
$result = $this->costcenter_model->addNewcost($Cost);
if($result > 0)
{ {
$this->session->set_flashdata('success', 'New Cost created successfully'); $Cost = array('CostCenterCode'=>$CostCode, 'CostCenterName'=>$CostName,'ApprovedBy'=>$ApproverName,'CreatedBy'=>$CreateBy,'createdDate'=>$createddt);
$this->costcenter_model->addNewcost($Cost);
} }
else
for ($j = 0; $j < count($comma_separated); $j++)
{ {
$this->session->set_flashdata('error', 'Cost creation failed'); $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);
} }
echo $result; $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');
redirect('addcost');
} }
} }