diff --git a/application/controllers/requisitionform.php b/application/controllers/requisitionform.php
index 436a3d7e..528730e1 100644
--- a/application/controllers/requisitionform.php
+++ b/application/controllers/requisitionform.php
@@ -17,34 +17,208 @@ class requisitionform extends BaseController
public function __construct()
{
parent::__construct();
- $this->load->model('purchaseorder_model');
+ $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 user
+ /**
+ * This function used to load the first screen of the Requistion
*/
-
+ function requisitionlisting()
+ {
+ $this->global['pageTitle'] = 'Siddharth : Requisition Listing';
+
+ $this->loadViews("requisitionlisting", $this->global, NULL);
+ }
+ /**
+ * This function used to load the first screen of the requisition Form
+ */
function requisition()
{
$this->global['pageTitle'] = 'Siddharth : Raise Requisition';
- $data['RequestType'] = $this->purchaseorder_model->getConfigValue('C004');
+ $data['RequestType'] = $this->requistion_model->getConfigValue('C004');
- $data['EmpList'] = $this->purchaseorder_model->getAllEmployees();
- $data['MaterialList'] = $this->purchaseorder_model->getRawMaterialList();
-
- $data['CostCenter'] = $this->purchaseorder_model->getCostCenter();
-
+ $data['EmpList'] = $this->requistion_model->getAllEmployees();
+
+ // $data['MaterialList'] = $this->requistion_model->getRawMaterialList();
+
$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 = "";
+ $BudAmount = "";
+ if(count($CostList) > 0)
+ {
+ for ($j = 0; $j < count($CostList); $j++)
+ {
+ $Code = $CostList[$j]['CostCenterCode'];
+ $Name = $CostList[$j]['CostCenterName'];
+ $HTML .="";
+ }
+ }
+ 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 = "";
+
+ if(count($MaterialCode) > 0)
+ {
+ for ($j = 0; $j < count($MaterialCode); $j++)
+ {
+ $Code = $MaterialCode[$j]['MaterialCode'];
+ $Name = $MaterialCode[$j]['MaterialName'];
+ $HTML .="";
+
+ }
+ $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;
+ $Request = array('ReqType'=>$RequestType, 'Requestedby'=>$Requestedby,'ReqDate'=>$createddt,'Status'=>$Status,'CreatedDate'=>$createddt,'CreatedBy'=>$CreateBy);
+
+ $Req = $this->requistion_model->addRequistion($Request);
+ $ReqNumber = '';
+ if(count($Req)>0)
+ {
+ $ReqNumber = $Req[0]['ReqNo'];
+ }
+ //print_r($comma_separated);
+ // $ReqNumber = 'REQ0001';
+ $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 pageNotFound()
{
$this->global['pageTitle'] = 'CodeInsect : 404 - Page Not Found';