siddharth_application/application/controllers/storerequisitionlist.php
venbatechnologies@gmail.com 229da1d6e9 capital po check in
2017-07-05 18:08:07 +05:30

489 lines
15 KiB
PHP
Executable File

<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
require APPPATH . '/libraries/BaseController.php';
/**
* Class : Cost Center (Cost Center Controller)
* User Class to control all user related operations.
* @author : VenbaMail Mali
* @version : 1.1
* @since : 15 Feb 2016
*/
class storerequisitionlist extends BaseController
{
/**
* This is default constructor of the class
*/
public function __construct()
{
parent::__construct();
$this->load->model('storerequistion_model');
$this->load->library('session');
$this->load->library('form_validation');
$this->isLoggedIn();
}
/*ADD Store requisition line item
*/
function addstores($userId='',$MaterialCode='')
{
$this->global['pageTitle'] = 'Siddharth : StoreRequisition Listing';
$this->load->model('storerequistion_model');
$userId= $this->session->userdata ('userId');
$data['DEPCode'] = $this->session->userdata('DEPCode');
$data['DepName'] = $this->session->userdata('DepartmentName');
//print_r($data['cost']);
$data['cost'] = $this->storerequistion_model->getCostUser($userId);
$data['MaterialList'] = $this->storerequistion_model->getRawMaterialList($MaterialCode);
//$data['Store'] = $this->storerequistion_model->Storeall($userId);
$this->loadViews("addstorerequisitionslip", $this->global,$data,null);
}
function addstore()
{
$this->global['pageTitle'] = 'Siddharth : StoreRequisition Listing';
//$this->load->model('storerequistion_model');
$userId= $this->session->userdata ('userId');
$data['Store'] = $this->storerequistion_model->Storeall($userId);
//print_r($data['Store']);
//echo "Check point form con";
$this->loadViews("storerequisition", $this->global,$data,null);
}
/**
* This function used to load the Delete the StoreRequistion Items
*/
function DeleteReqNo()
{
$StoreReqNo= $this->input->post('id');
$dt = new DateTime('now', new DateTimeZone('Asia/Kolkata'));
$updateddt = $dt->format('Y-m-d H:i:s');
$Request = array('Status'=>REQ_DELETED,'updatedOn'=>$updateddt);
$this->storerequistion_model->UpdateRequistion($StoreReqNo,$Request);
echo "Successfully Deleted the ".$StoreReqNo;
}
/* The Function Edit Store Requistion list */
function EditStoreRequistion($MaterialCode='')
{
$StoreReqNo = $_GET['StoreReqNo'];
//$StoreReqNo= $this->input->post('id');
$this->global['pageTitle'] = 'Siddharth : StoreRequisition Listing';
$this->load->model('storerequistion_model');
$data['cost'] = $this->storerequistion_model->editRequistDetails($StoreReqNo);
// print_r( $data);
$data['MaterialList'] = $this->storerequistion_model->getRawMaterialList($MaterialCode);
$data['DepName'] = $this->session->userdata('DepartmentName');
$data['LineItem']=$this ->storerequistion_model->editstorerequistions($StoreReqNo);
// $data['StoreReqNO'] = $StoreReqNo ;
//print_r($data['LineItem']);
$this->loadViews("editstorerequisition", $this->global,$data,null);
}
/**get the date formatted**/
function getDateformat($Val)
{
$date = new DateTime($Val);
$retDate = $date->format('Y-m-d H:i:s');
return $retDate;
}
/**This function is used to add new StoreRequestion to the system */
function addNewRequistion()
{
$Status= $_GET['ID'];
$Requestedby = $_GET['RequestedBy'];
$CostCenter = $_GET['CostCenter'];
$DEPCode = $_GET['DEPCode'];
$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 = $_GET['txtRowCount'];
//echo $RowCount; die();
$comma_separated = explode(':', $DeletedRow);
$IsExists = $this->storerequistion_model->RequistionIsExists($Requestedby);
if(count( $IsExists) == 0)
{
$Request = array( 'Requestedby'=>$Requestedby,'DepartmentCode'=>$DEPCode,'ReqDate'=>$createddt,'CostCenterCode'=>$CostCenter,'Status'=>$Status,'CreatedDate'=>$createddt,'CreatedBy'=>$CreateBy);
//print_r($Request);
$Req = $this->storerequistion_model->addRequistion($Request);
foreach ($Req[0] as $value)
{
$StoreReqNo = $value;
}
//echo $StoreReqNo;
}
else
{
$Request = array('Requestedby'=>$Requestedby,'DepartmentCode'=>$DEPCode,'ReqDate'=>$createddt,'Status'=>$Status,'CreatedDate'=>$createddt,'CreatedBy'=>$CreateBy,'CostCenterCode'=>$CostCenter);
$UpdateReq = $this->storerequistion_model->UpdateRequistion($Request,$IsExists[0]['StoreReqNo']);
}
$ReqNumber = '';
//print_r($RowCount);die();
if(count($Req)>0)
{
$ReqNumber = $Req[0]['StoreReqNo'];
//printf_r($ReqNumber);
}
else
{
$ReqNumber = $IsExists[0]['StoreReqNo'];
}
$SkipInsert = False;
for ($i = 1; $i <= $RowCount; $i++)
{
$MaterialCode = $this->input->post('MaterialCode'.$i);
$QuantityRequired=$this->input->post('Quantity'.$i);
$Remarks=$this->input->post('Remarks'.$i);
$Request = array('MaterialCode'=>$MaterialCode,'Status'=>$Status,'QuantityRequired'=>$QuantityRequired,'Remarks'=>$Remarks,'StoreReqNo'=>$value);
$addReq=$this->storerequistion_model->addstoreRequistion($Request);
$SkipInsert = "False";
if( count($comma_separated) > 0)
{
for($j = 1; $j < count($comma_separated); $j++)
{
$deletedRow = $comma_separated[$j] ;
if($deletedRow == $i )
{
$SkipInsert = "True";
break;
}
}
}
}
if($Status == STORE_DRAFT)
{
echo 'Successfully Saved the Store Requistion details';
}
else
{
echo 'Successfully Created the Store Requistion details';
}
}
function addstorerequisitionlist()
{
$this->global['pageTitle'] = 'Siddharth : StoreRequisition Listing';
$this->load->model('storerequistion_model');
$data['Status']= $this->storerequistion_model->getStatus();
$data['TotNoOfLine']=$this->storerequistion_model->getRequistionList();
//print_r($data['TotNoOfLine']);
$this->loadViews("storerequisitionlisting", $this->global,$data,null);
}
/* this function use to search StoreRequistlist*/
function SearchRequistLists()
{
$userID = $this->session->userdata ( 'userId' );
$ReqValue = $this->input->post('SearchDate');
$Dt = explode("-",$ReqValue);
$FromDate ='';
$ToDate = '';
$Status= '';
if(count( $Dt)>1)
{
$FDate = $Dt[0]."-".$Dt[1]."-".$Dt[2];
$TDate = $Dt[3]."-".$Dt[4]."-".$Dt[5];
$FromDate = $this->getDateformat($FDate);
$ToDate = $this->getDateformat($TDate);
}
$St = $this->input->post('STORE REQUISTION STATUS');
if($St == "-1")
{
$Status = '';
}
else
{
$Status = $St;
}
$data['AppList'] = $this->storerequistion_model->getApproverRequistList($userID,$Status,$FromDate, $ToDate);
$this->global['pageTitle'] = 'Siddharth : ApprovalStoreRequisitionSlip';
$data['Status']= $this->storerequistion_model->getStatus();
$this->loadViews("approvalstorerequisitionslip", $this->global, $data, NULL);
}
/*Approve Completed*/
function ApproveRequest()
{
$Status= Trim($_GET['Status']);
//$StoreReqNo=$this->input->post('StoreReqNo');
$StoreReqNo = trim($this->input->post('id'));
$Remarks=trim($this->input->post('newcomments'));
$ApprovedBy = $this->session->userdata ( 'userId' );
$dt = new DateTime('now', new DateTimeZone('Asia/Kolkata'));
$ApprovedDate = $dt->format('Y-m-d H:i:s');
$Request = array('Status'=>$Status,'Comments'=>$Remarks,'ApprovedOn'=>$ApprovedDate,'Approvedby'=>$ApprovedBy);
$this->storerequistion_model->UpdateRequistion($StoreReqNo,$Request);
echo "Successfully Updated the Requistion No: ".$StoreReqNo;
}
/**
* This function used to load the first screen of the Requistion List Approval Screen
*/
function requisitionlistApproval()
{
$this->global['pageTitle'] = 'Siddharth :Approvalstorerequisitionlist';
//$data['Status']= $this->storerequistion_model->getStatus();
$userID = $this->session->userdata ( 'userId' );
$data['AppList'] = $this->storerequistion_model->getApproverRequistList($userID);
$this->loadViews("requisitionlistapproval", $this->global, $data, NULL);
}
/* To Edit the view store request*/
function ViewRequest()
{
$StoreReqNo= $this->input->post('id');
$result = $this->storerequistion_model->getRequistItemList($StoreReqNo);
$ReqList = $this->storerequistion_model->getRequistDetails($StoreReqNo);
$DepNo = $ReqList[0]['DepartmentName'];
//$CostList = $this->requistion_model->GetCostCenterByDept($DepNo);
$HTML="";
for ($i = 0; $i < count($result); $i++)
{
$SNo = $i + 1;
$MaterialCode = $result[$i]['MaterialCode'];
$MaterialName = $result[$i]['MaterialName'];
$UOM = $result[$i]['UOM'];
$Quantity = $result[$i]['QuantityRequired'];
$Remarks= $result[$i]['Remarks'];
$HTML.="<tr id='".$i."'>
<td align='left'>".$SNo."</td>
<td align='left'>".$MaterialCode."</td>
<td align='left'>".$MaterialName."</td>
<td align='left'>".$UOM."</td>
<td align='left'>".$Quantity."</td>
<td align='left'>".$Remarks."</td>
</tr>";
//$index = $index + 1;
}
$CostCode = '';
$ReqType = '';
$dt = new DateTime('now', new DateTimeZone('Asia/Kolkata'));
$Year = $dt->format('Y');
if(count($ReqList)>0)
{
$ReqType = $ReqList[0]['Requestedby'];
$CostCode = $ReqList[0]['CostCenterName'];
//$AvlBudget=$ReqList[0]['CostCenterName'];
}
$AvlBudget = $this->storerequistion_model->GetAvailableBudgetAmount($CostCode,$Year,$ReqType);
//print_r($result);
$AvilBudAmt = '0';
if(count($AvlBudget)>0)
{
$AvilBudAmt = $AvlBudget[0]['BudgetAmount'] - $AvlBudget[0]['Totalvalue'];
}
//echo $AvilBudAmt;
die(json_encode(array('Items' =>$HTML,'Requist'=>$ReqList,'AvilBudAmount'=>number_format($AvilBudAmt,2))));
}
//not completed
function EditStoreRequisitions()
{
$StoreReqNo =$this->input->post('txtReqNo');
// echo $StoreReqNo;
$Status = $this->input->post('txtStatus');
$Requestedby = $this->input->post('RequestedBy');
$CostCenter = $this->input->post('CostCenter');
//echo $CostCenter;
$UpdatedBy = $this->session->userdata ('userId' );
//$ReqDate=$this->input->post('Date')
$dt = new DateTime('now', new DateTimeZone('Asia/Kolkata'));
$updatedDate = $dt->format('Y-m-d H:i:s');
$DEPCode = $_GET['DEPCode'];
$DeletedRow = $this->input->post('txtDeletedRow');
$RowCount = $this->input->post('txtRowCount');
//print_r($RowCount); die();
$comma_separated = explode(':', $DeletedRow);
if(strlen($Status) >1)
{
$Request = array('Requestedby'=>$Requestedby,'DepartmentCode'=>$DEPCode,'ReqDate'=>$updatedDate,'CostCenterCode'=>$CostCenter,'Status'=>$Status,'updatedOn'=>$updatedDate );
//print_r($Request); die();
$UpdateReq = $this->storerequistion_model->UpdateRequistion($StoreReqNo,$Request);
//echo"string"; die();
// foreach ($UpdateReq as $value)
// {
// $StoreReqNo = $value;
// }
}
$SkipInsert = False;
for ($i = 1; $i <= $RowCount; $i++)
{
//echo"hi";
$MaterialCode = $this->input->post('EditMaterialCode');
$QuantityRequired=$this->input->post('EditQuantity');
//echo"$QuantityRequired"; die();
$Remarks=$this->input->post('EditRemarks');
$Request = array('MaterialCode'=>$MaterialCode,'Status'=>$Status,'QuantityRequired'=>$QuantityRequired,'Remarks'=>$Remarks);
//print_r($Request);die();
$addReq = $this->storerequistion_model->addstoreRequistion($Request);
$SkipInsert = "False";
if(count($comma_separated) > 0)
{
for($j = 1; $j < count($comma_separated); $j++)
{
$deletedRow = $comma_separated[$j] ;
if($deletedRow == $i )
{
$SkipInsert = "True";
break;
}
}
}
if($SkipInsert == "False")
{
//echo "string"; die();
$MaterialCode = $this->input->post('EditMaterialCode'.$i);
echo"MaterialCode"; die();
$QuantityRequired=$this->input->post('Quantity'.$i);
$Remarks=$this->input->post('Remarks'.$i);
$Request = array('MaterialCode'=>$MaterialCode,'Status'=>$Status,'QuantityRequired'=>$QuantityRequired,'Remarks'=>$Remarks,'StoreReqNo'=>$StoreReqNo);
//print_r($Request);die();
$IsExists = $this->storerequistion_model->LineItemIsExists($StoreReqNo,$MaterialCode);
if(count( $IsExists) == 0)
{
$ReqDetails = array('StoreReqNo'=>$StoreReqNo, 'MaterialCode'=>$MaterialCode,'QuantityRequired'=>$QuantityRequired,'UpdatedBy'=>$UpdatedBy,'UpdatedOn'=>$updatedDate);
$this->storerequistion_model->addRequistionDetails($ReqDetails);
}
else
{
$ReqDetails = array('StoreReqNo'=>$StoreReqNo, 'MaterialCode'=>$MaterialCode,'Quantity'=>$Quantity,'UpdatedBy'=>$UpdatedBy,'UpdatedOn'=>$updatedDate);
$this->storerequistion_model->UpdateRequistionLineItem($ReqDetails,$StoreReqNo,$MaterialCode);
}
}
}
echo 'Successfully updated the Requistion details';
}
/**
* This function used to load the Delete the Requistion Items
*/
function DeleteRequistionForm()
{
$ReqList= $this->input->post('id');
$StoreReqNo ='';
$MaterialCode = '';
if(count($ReqList) > 0)
{
$StoreReqNo = $ReqList[0];
$MaterialCode = $ReqList[1];
}
$this->storerequistion_model->DeleteRequistionLineItem( $StoreReqNo,$MaterialCode);
echo "Successfully Deleted the Line item".$StoreReqNo;
}
}