load->model('costcenter_model'); //$this->load->library('session'); $this->load->library('form_validation'); $this->load->library('pagination'); $this->isLoggedIn(); } /** * This function used to load the first screen of the user */ public function index() { $this->global['pageTitle'] = 'Siddharth : Cost'; $this->loadViews("costListing", $this->global, NULL , NULL); } /** * This function is used to load the Cost list */ function CostListing() { //$this->load->model('costcenter_model'); $searchText = $this->input->post('searchText'); $data['searchText'] = $searchText; $count = $this->costcenter_model->CostListingCount($searchText); $returns = $this->paginationCompress ( "costListing/", $count, 5 ); $data['userRecords'] = $this->costcenter_model->CostListing($searchText, $returns["page"], $returns["segment"]); //print_r( $data) ; $this->global['pageTitle'] = 'Siddharth : Test List'; $this->loadViews("costListing", $this->global, $data, NULL); } /** * This function is used 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(); $this->global['pageTitle'] = 'siddharth : Add Cost Center'; $this->loadViews("addCostCenter", $this->global,$data, NULL); } function Dep_SelectedDepartment($selectValue) { //echo 'select_validate method called'; // 'none' is the first option and the text says something like "-Choose one-" if(strlen($SelectedDepartment) <= 0 ) { $this->form_validation->set_message('Dep_SelectedDepartment', 'Please Select Department.'); return false; } else // user picked something { return true; } } /** * This function is used to add new Cost to the system */ 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'); $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'); } } /** * This function is used load user edit information * @param number $userId : Optional : This is user id */ 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); $this->global['pageTitle'] = 'Siddharth : Edit Cost'; $this->loadViews("editOldcost", $this->global, $data,NULL); } function ech() { echo $this->input->post('CostCentreID'); echo $this->input->post('CostName'); echo $this->input->post('Description'); } /** * This function is used to edit the user information */ function editcost() { $this->load->library('form_validation'); $CostCenterID = $this->input->post('CostCentreID'); $this->form_validation->set_rules('CostName','Cost Name','trim|required|'); $this->form_validation->set_rules('Description','Description','trim|required|'); if($this->form_validation->run() == FALSE) { $this->editcost($CostCenterID); } else { $CostCenterID = $this->input->post('CostCentreID'); $CostName = ucwords(strtolower($this->input->post('CostName'))); $Description = $this->input->post('Description'); //$this->costcenter_model->editcost($Cost); $cost = array(); $Cost = array('CostCentreID'=>$CostCenterID,'CostName'=>$CostName, 'Description'=>$Description,'createdDate'=>date('Y-m-d H:i:sa')); $result = $this->costcenter_model->editcost($Cost, $CostCenterID); if($result == true) { $this->session->set_flashdata('success', 'Cost updated successfully'); } else { $this->session->set_flashdata('error', 'Cost updation failed'); } redirect('costListing'); } } function viewcost($CostCenterID = NULL) { if($CostCenterID == null) { redirect('costListing'); } $data['Cost'] = $this->costcenter_model->getuserinfo($CostCenterID); //$data['users'] = $this->purchaseorder_model->getusers(); $this->global['pageTitle'] = 'Siddharth : View Cost'; $this->loadViews("viewcost", $this->global, $data,NULL); } /** * This function is used to delete the user using userId * @return boolean $result : TRUE / FALSE */ 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))); } } } function pageNotFound() { $this->global['pageTitle'] = 'CodeInsect : 404 - Page Not Found'; $this->loadViews("404", $this->global, NULL, NULL); } } ?>