diff --git a/application/controllers/CostCenter.php b/application/controllers/CostCenter.php index 78a1bf3f..a275be53 100644 --- a/application/controllers/CostCenter.php +++ b/application/controllers/CostCenter.php @@ -20,6 +20,7 @@ class CostCenter extends BaseController $this->load->model('costcenter_model'); //$this->load->library('session'); $this->load->library('form_validation'); + $this->load->library('pagination'); $this->isLoggedIn(); } @@ -39,12 +40,11 @@ class CostCenter extends BaseController function CostListing() { - $this->load->model('costcenter_model'); + //$this->load->model('costcenter_model'); $searchText = $this->input->post('searchText'); - $data['searchText'] = $searchText; + $data['searchText'] = $searchText; - $this->load->library('pagination'); $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"]); - $this->global['pageTitle'] = 'Siddharth : Cost List'; + $this->global['pageTitle'] = 'Siddharth : Test List'; $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 */ function addCostCenter() { - $this->load->model('costcenter_model'); - //$data['costName'] = $this->purchaseorder_model->getcostName(); - //$data['users'] = $this->purchaseorder_model->getusers(); + $data['Department'] = $this->costcenter_model->getDepartment(); + + $data['BudgetType'] = $this->costcenter_model->getConfigValue('C004'); + + $data['Approver'] = $this->costcenter_model->getApproverName(); $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 */ function addNewcost() { - - $this->load->library('form_validation'); - + - $this->form_validation->set_rules('CostName','Address','trim|required|'); - $this->form_validation->set_rules('Description','Contact Number','trim'); - - + $this->form_validation->set_rules('CostCode','CostCode','trim|required'); + $this->form_validation->set_rules('CostName','CostName','trim|required'); + + $SelectedDepartment = $this->input->post('txtSelectedDepartment'); + $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) { - $this->addcost(); + $this->addCostCenter(); } else { - $CostName = ($this->input->post('CostName')); - $Description = $this->input->post('Description'); - - - - - $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'); - } - else - { - $this->session->set_flashdata('error', 'Cost creation failed'); - } - echo $result; + $CostCode = strtoupper(trim($this->input->post('CostCode'))); + $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'); - redirect('addcost'); + $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'); + } }