Cost center

This commit is contained in:
gandhimathi Bharathirajan 2017-05-08 13:22:45 +05:30
parent d751d4df0d
commit ad96335580

View File

@ -169,13 +169,16 @@ class CostCenter extends BaseController
else else
{ {
$CostCenterID = $CostCode; } $CostCenterID = $CostCode;
}
$data['CostMaster'] = $this->costcenter_model->GetCostCenterMaster($CostCenterID); $data['CostMaster'] = $this->costcenter_model->GetCostCenterMaster($CostCenterID);
$data['CostDepts'] = $this->costcenter_model->GetCostCenterDepartment($CostCenterID); $data['CostDepts'] = $this->costcenter_model->GetCostCenterDepartment($CostCenterID);
$data['CostBudget'] = $this->costcenter_model->GetCostCenterBudget($CostCenterID); $data['CostBudget'] = $this->costcenter_model->GetCostCenterBudget($CostCenterID);
// $data['DeptList'] = $this->costcenter_model->GetDepartmentNotinCostCenter($CostCenterID); $data['DeptList'] = $this->costcenter_model->GetDepartmentNotinCostCenter($CostCenterID);
$data['BudType'] = $this->costcenter_model->GetBudgetTypeNotinCostCenter($CostCenterID,'C004');
$data['BudYear'] = $this->costcenter_model->GetBudgetYear($CostCenterID);
//print_r(count($data['BudType']));
$this->global['pageTitle'] = 'Siddharth : Edit Cost'; $this->global['pageTitle'] = 'Siddharth : Edit Cost';
@ -183,13 +186,52 @@ class CostCenter extends BaseController
} }
function ech() function GetBudgetForYear()
{ {
//$id = $this->input->post('id');
echo $this->input->post('CostCentreID'); $BudYear = $_GET['BudYear'];
echo $this->input->post('CostName'); $CostCenterID = $_GET['CostCode'];
echo $this->input->post('Description'); $result = $this->costcenter_model->GetCostCenterBudgetByYear($CostCenterID, $BudYear);
$BudList = $this->costcenter_model->GetCostBudgetTypeByYear($CostCenterID,'C004', $BudYear);
$HTML="";
$HTML2="";
$index = 1;
// $HTML2 = $BudList[0]['ConfigValue'];
//if($BudList->num_rows() > 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++)
{
$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>&nbsp;&nbsp;&nbsp;</a> </td></tr>
";
$index = $index + 1;
}
$HTML.="<input type='hidden' name='txtRowCount' id='txtRowCount' value='".$index ."'/>";
die(json_encode(array('Html' => $HTML,'BudYear' => $HTML2)));
// echo $HTML2;
} }
/** /**
@ -198,49 +240,71 @@ class CostCenter extends BaseController
function editcost() function editcost()
{ {
$this->load->library('form_validation'); $this->form_validation->set_rules('CostCode','CostCode','trim|required');
$this->form_validation->set_rules('CostName','CostName','trim|required');
$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) if($this->form_validation->run() == FALSE)
{ {
$this->editcost($CostCenterID); $this->addCostCenter();
} }
else else
{ {
$CostCenterID = $this->input->post('CostCentreID'); $CostCode = strtoupper(trim($this->input->post('CostCode')));
$CostName = ucwords(strtolower($this->input->post('CostName'))); $CostName = strtoupper(trim($this->input->post('CostName')));
$Description = $this->input->post('Description'); $updatedBy = $this->session->userdata ( 'userId' );
$SelectedDepartment = $this->input->post('txtSelectedDepartment');
$ApproverName = $this->input->post('ApprovedBy');
$comma_separated = "";
//print_r(strlen($SelectedDepartment));
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');
//$this->costcenter_model->editcost($Cost);
$cost = array();
$CodeExists = $this->costcenter_model->checkCostDetailsExists($CostCode);
//print_r(count($CodeExists));
if(count($CodeExists) > 0)
{
$Cost = array( 'CostCenterName'=>$CostName,'ApprovedBy'=>$ApproverName,'UpdatedBy'=>$updatedBy,'UpdatedDate'=>$updateddt);
$this->costcenter_model->EditCost($Cost,$CostCode);
}
//echo count($comma_separated);
$Cost = array('CostCentreID'=>$CostCenterID,'CostName'=>$CostName, 'Description'=>$Description,'createdDate'=>date('Y-m-d H:i:sa')); if(count($comma_separated)> 1)
{
for ($j = 0; $j < count($comma_separated); $j++)
{
$DeptCode = $comma_separated[$j];
$result = $this->costcenter_model->editcost($Cost, $CostCenterID);
$this->costcenter_model->DeleteDepartment( $DeptCode,$CostCode);
if($result == true)
{ $Dept = array('CostCenterCode'=>$CostCode, 'DEPCode'=>$DeptCode,'CreatedBy'=>$updatedBy,'createdDate'=>$updateddt,'UpdatedBy'=>$updatedBy,'UpdatedDate'=>$updateddt);
$this->session->set_flashdata('success', 'Cost updated successfully'); $this->costcenter_model->addCostCenterDepartment($Dept);
}
else }
{ }
$this->session->set_flashdata('error', 'Cost updation failed');
} $RowCount = $this->input->post('txtRowCount');
//$BudgetType = $this->input->post('BudgetType2');
redirect('costListing'); //echo $BudgetType;
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'=>$updatedBy,'createdDate'=>$updateddt,'UpdatedBy'=>$updatedBy,'UpdatedDate'=>$updateddt);
$this->costcenter_model->addBudget($Budget);
print_r( $BudgetType );
}
echo('Successfully Updated Cost details');
} }
} }