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
{
$CostCenterID = $CostCode; }
$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['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';
@ -183,13 +186,52 @@ class CostCenter extends BaseController
}
function ech()
function GetBudgetForYear()
{
echo $this->input->post('CostCentreID');
echo $this->input->post('CostName');
echo $this->input->post('Description');
//$id = $this->input->post('id');
$BudYear = $_GET['BudYear'];
$CostCenterID = $_GET['CostCode'];
$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()
{
$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|');
$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->editcost($CostCenterID);
$this->addCostCenter();
}
else
{
$CostCenterID = $this->input->post('CostCentreID');
$CostName = ucwords(strtolower($this->input->post('CostName')));
$Description = $this->input->post('Description');
$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 = "";
//print_r(strlen($SelectedDepartment));
if(strlen($SelectedDepartment)>0)
{
$comma_separated = explode(':', $SelectedDepartment);
}
$dt = new DateTime('now', new DateTimeZone('Asia/Kolkata'));
//$this->costcenter_model->editcost($Cost);
$cost = array();
$updateddt = $dt->format('Y-m-d H:i:s');
$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'));
$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');
if(count($comma_separated)> 1)
{
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'=>$updatedBy,'createdDate'=>$updateddt,'UpdatedBy'=>$updatedBy,'UpdatedDate'=>$updateddt);
$this->costcenter_model->addCostCenterDepartment($Dept);
}
}
$RowCount = $this->input->post('txtRowCount');
//$BudgetType = $this->input->post('BudgetType2');
//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');
}
}