siddharth_application/application/controllers/requisitionform.php
2017-05-10 14:39:53 +05:30

259 lines
7.9 KiB
PHP

<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
require APPPATH . '/libraries/BaseController.php';
/**
* Class : purchaseorder (PurchaseorderController)
* User Class to control all user related operations.
* @author : VenbaMail Mali
* @version : 1.1
* @since : 15 Feb 2016
*/
class requisitionform extends BaseController
{
/**
* This is default constructor of the class
*/
public function __construct()
{
parent::__construct();
$this->load->model('requistion_model');
$this->load->library('session');
$this->load->library('form_validation');
$this->isLoggedIn();
}
/**
* This function used to load the first screen of the Requistion
*/
function requisitionlisting()
{
$this->global['pageTitle'] = 'Siddharth : Requisition Listing';
$userID = $this->session->userdata ( 'userId' );
$data['ReqList'] = $this->requistion_model->getRequistListUserID($userID);
$data['Status'] = $this->requistion_model->CheckDraftStatus($userID);
$this->loadViews("requisitionlisting", $this->global, $data, NULL);
}
/**
* This function used to load the first screen of the requisition Form
*/
function requisition()
{
$this->global['pageTitle'] = 'Siddharth : Raise Requisition';
$data['RequestType'] = $this->requistion_model->getConfigValue('C004');
$data['EmpList'] = $this->requistion_model->getAllEmployees();
$userID = $this->session->userdata ( 'userId' );
$data['Emp'] = $this->requistion_model->getEmpIdByUserID($userID);
$data['CostCenter'] = $this->requistion_model->getCostCenterUserID($userID);
$this->loadViews("requisitionform", $this->global, $data,null);
}
/**
* This function used to load the Employee details based on the EmpID selection
*/
function GetSelectedEmpDetails()
{
$ReqType = $_GET['ReqType'];
$EmpID = $this->input->post('id');
$empDetails = $this->requistion_model->GetEmployeeDetails( $EmpID );
$DeptCode = $empDetails[0]['DEPCode'];
$CostList = $this->requistion_model->GetCostCenterByDept( $DeptCode);
$HTML = "<option value='-1'>Select Cost center</option>";
$BudAmount = "";
if(count($CostList) > 0)
{
for ($j = 0; $j < count($CostList); $j++)
{
$Code = $CostList[$j]['CostCenterCode'];
$Name = $CostList[$j]['CostCenterName'];
$HTML .="<option value='".$Code."'>".$Code."-".$Name."</option>";
}
}
if(count($CostList) == 1)
{
$dt = new DateTime('now', new DateTimeZone('Asia/Kolkata'));
$Year = $dt->format('Y');
$CostCode = $CostList[0]['CostCenterCode'];
$Cost = $this->requistion_model->GetAvailableBudgetAmount( $CostCode,$Year,$ReqType);
if(count($Cost) >0)
{
$BudAmount = $Cost[0]['BudgetAmount'];
}
}
die(json_encode(array('emp' => $empDetails,'Cost' => $HTML,'AvlAmount' => $BudAmount)));
}
function getAvailableBudAmount()
{
$ReqType = $_GET['ReqType'];
$CostCode= $this->input->post('id');
$dt = new DateTime('now', new DateTimeZone('Asia/Kolkata'));
$Year = $dt->format('Y');
$Cost = $this->requistion_model->GetAvailableBudgetAmount( $CostCode,$Year,$ReqType);
die(json_encode(array('Cost' =>$Cost)));
}
// To get the Material code based on the Request type
function getMaterialCode()
{
$ReqType= $this->input->post('id');
$MaterialCode = $this->requistion_model->GetMaterialCode( $ReqType);
$MaterialName = "";
$UOM = "";
$HTML = "<option value='-1'>Select Material Type</option>";
if(count($MaterialCode) > 0)
{
for ($j = 0; $j < count($MaterialCode); $j++)
{
$Code = $MaterialCode[$j]['MaterialCode'];
$Name = $MaterialCode[$j]['MaterialName'];
$HTML .="<option value='".$Code."'>".$Code."-".$Name."</option>";
}
$MaterialName = $MaterialCode[0]['MaterialName'];
$UOM = $MaterialCode[0]['UOM'];
}
die(json_encode(array('Material' =>$HTML,'MaterialName'=>$MaterialName,'UOM'=>$UOM)));
}
// To get the Material value based on the MaterialCode
function getMaterialDetails()
{
$Material= $this->input->post('id');
$MaterialDetails = $this->requistion_model->getRawMaterialList($Material);
die(json_encode(array('MatDetail' =>$MaterialDetails)));
}
/*
To Insert the Requistion Details to Database
*/
/**
* This function is used to add new Cost to the system
*/
function addNewRequistion()
{
$this->form_validation->set_rules('RequestType','RequestType','trim|required');
$this->form_validation->set_rules('EmpID','EmpID','trim|required');
if($this->form_validation->run() == FALSE)
{
$this->requisition();
}
else
{
$Status= $_GET['ID'];
$RequestType = strtoupper(trim($this->input->post('RequestType')));
$Requestedby = strtoupper(trim($this->input->post('EmpID')));
$CreateBy = $this->session->userdata ( 'userId' );
$dt = new DateTime('now', new DateTimeZone('Asia/Kolkata'));
$createddt = $dt->format('Y-m-d H:i:s');
$DeletedRow = $this->input->post('txtDeletedRow');
$RowCount = $this->input->post('txtRowCount');
$comma_separated = explode(':', $DeletedRow);
//echo $DeletedRow;
//echo count($comma_separated);
//echo $RowCount. " Status:". $Status;
$IsExists = $this->requistion_model->RequistionIsExists($Requestedby);
if(count( $IsExists) == 0)
{
$Request = array('ReqType'=>$RequestType, 'Requestedby'=>$Requestedby,'ReqDate'=>$createddt,'Status'=>$Status,'CreatedDate'=>$createddt,'CreatedBy'=>$CreateBy);
$Req = $this->requistion_model->addRequistion($Request);
}
else
{
$Request = array('ReqType'=>$RequestType, 'Requestedby'=>$Requestedby,'ReqDate'=>$createddt,'Status'=>$Status,'CreatedDate'=>$createddt,'CreatedBy'=>$CreateBy);
$UpdateReq = $this->requistion_model->UpdateRequistion($Request,$IsExists[0]['ReqNo']);
}
$ReqNumber = '';
if(count($Req)>0)
{
$ReqNumber = $Req[0]['ReqNo'];
}
else
{
$ReqNumber = $IsExists[0]['ReqNo'];
}
$SkipInsert = False;
for ($i = 1; $i <= $RowCount; $i++)
{
$SkipInsert = "False";
if( count($comma_separated) > 0)
{
for($j = 1; $j < count($comma_separated); $j++)
{
$deletedRow = $comma_separated[$j] ;
//$SkipInsert = ($deletedRow != $i ? FALSE:True);
if($deletedRow == $i )
{
$SkipInsert = "True";
break;
}
}
}
if($SkipInsert == "False")
{
$MaterialCode = $this->input->post('MaterialCode'.$i);
$Quantity = $this->input->post('Quantity'.$i);
$ReqDetails = array('ReqNo'=>$ReqNumber, 'MaterialCode'=>$MaterialCode,'Quantity'=>$Quantity);
$this->requistion_model->addRequistionDetails($ReqDetails);
}
}
echo 'Successfully Created Requistion details';
}
}
function editrequisitionlisting()
{
$this->global['pageTitle'] = 'Siddharth : Edit Requisition Listing';
$this->loadViews("editrequisitionform", $this->global, NULL);
}
function pageNotFound()
{
$this->global['pageTitle'] = 'CodeInsect : 404 - Page Not Found';
$this->loadViews("404", $this->global, NULL, NULL);
}
}
?>