ria/app/Controllers/Storerequisitionlist.php
2024-05-06 03:47:37 +00:00

537 lines
15 KiB
PHP

<?php
namespace App\Controllers;
use App\Controllers\BaseController;
use CodeIgniter\Validation\Exceptions\ValidationException;
use App\Models\Assetdetails_model;
use App\Models\Batchcard_model;
use App\Models\Cashbook_model;
use App\Models\Companydetails_model;
use App\Models\Config_model;
use App\Models\Costcenter_model;
use App\Models\Dashboard_Model;
use App\Models\Department_model;
use App\Models\Employeedetails_model;
use App\Models\Emppaydate_model;
use App\Models\Inwardgateregister_model;
use App\Models\Login_model;
use App\Models\Monthlypay_model;
use App\Models\Mrir_model;
use App\Models\Payroll_model;
use App\Models\Purchaseorder_model;
use App\Models\Quality_model;
use App\Models\Rawmaterialdetails_model;
use App\Models\Requistion_model;
use App\Models\Store_model;
use App\Models\Storerequistion_model;
use App\Models\Supplier_model;
use App\Models\User_model;
use App\Models\Zohobook_api_model;
/**
* Module - Store
* Storerequisitionlist Class to control all Storerequisitionlist related operations.
* @author : Venba
* @version : 1.1
* @since : 15 Feb 2016
* @example : Revised at 15th april 2024
*/
class Storerequisitionlist extends BaseController
{
protected $storerequistion_model;
protected $session;
/**
* This is default constructor of the class
*/
public function __construct()
{
parent::__construct();
$this->storerequistion_model = new Storerequistion_model();
$this->session = session();
helper('form'); //$this->load->library('form_validation');
$this->isLoggedIn();
}
/*ADD Store requisition line item
*/
function addstores()
{
$this->global['pageTitle'] = 'StoreRequisition Listing';
$userId = $this->session->get('userId');
$data['DEPCode'] = $this->session->get('DEPCode');
$data['DepName'] = $this->session->get('DepartmentName');
$data['cost'] = $this->storerequistion_model->getCostUser($userId);
$data['MaterialList'] = $this->storerequistion_model->getRawMaterialList();
$this->loadViews("addstorerequisitionslip", $this->global, $data, null);
}
function addstore()
{
$this->global['pageTitle'] = 'StoreRequisition Listing';
$userId = $this->session->get('userId');
$data['Store'] = $this->storerequistion_model->Storeall($userId);
$this->loadViews("storerequisition", $this->global, $data, null);
}
/**
* This function used to load the Delete the StoreRequistion Items
*/
function DeleteReqNo()
{
$StoreReqNo = $this->request->getPost('id');
$updateddt = get_current_date_time();
$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()
{
$StoreReqNo = $_GET['StoreReqNo'];
//$StoreReqNo= $this->request->getPost('id');
$this->global['pageTitle'] = 'StoreRequisition Listing';
$data['cost'] = $this->storerequistion_model->editRequistDetails($StoreReqNo);
$data['Status'] = $this->storerequistion_model->getStoreRequistionStatus($StoreReqNo);
$data['MaterialList'] = $this->storerequistion_model->getRawMaterialList();
$data['DepName'] = $this->session->get('DepartmentName');
$data['LineItem'] = $this->storerequistion_model->editstorerequistions($StoreReqNo);
$this->loadViews("editstorerequisition", $this->global, $data, null);
}
/**This function is used to add new StoreRequestion to the system */
function addNewRequistion()
{
$CostCenter = $this->request->getPost('CostCenter');
$DEPCode = $this->request->getPost('txtDepCode');
$CreateBy = $this->session->get('userId');
$createddt = get_current_date_time();
$DeletedRow = $this->request->getPost('txtDeletedRow');
$RowCount = $this->request->getPost('txtRowCount');
// echo $RowCount;
// die();
$Status = $this->request->getPost('txtStatus');
$Requestedby = $this->session->get('EmpID');
$comma_separated = explode(':', $DeletedRow);
//echo 'done';
$StoreReqNo = '';
$StoreItemStatus = STORE_OPEN;
$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);
if (count($Req) > 0) {
$StoreReqNo = $Req[0]['StoreReqNo'];
//printf_r($ReqNumber);
}
//echo $StoreReqNo;
$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];
if ($deletedRow == $i) {
$SkipInsert = "True";
break;
}
}
}
if ($SkipInsert == "False") {
$MaterialCode = $this->request->getPost('MaterialCode' . $i);
$QuantityRequired = $this->request->getPost('Quantity' . $i);
$Remarks = $this->request->getPost('Remarks' . $i);
$Request = array('MaterialCode' => $MaterialCode, 'Status' => $StoreItemStatus, 'QuantityRequired' => $QuantityRequired, 'Remarks' => $Remarks, 'StoreReqNo' => $StoreReqNo);
$addReq = $this->storerequistion_model->addstoreRequistion($Request);
}
}
if ($Status == STORE_DRAFT) {
echo 'Successfully Saved the Store Requistion details';
} else {
echo 'Successfully Created the Store Requistion details';
}
}
function addstorerequisitionlist()
{
$this->global['pageTitle'] = 'StoreRequisition Listing';
$data['Status'] = $this->storerequistion_model->getStatus();
$data['TotNoOfLine'] = $this->storerequistion_model->getRequistionList();
//print_r($data['TotNoOfLine']);
$this->loadViews("storerequisitionlisting", $this->global, $data, null);
}
//To issue Store Requistion
function issuestorerequisition()
{
$this->global['pageTitle'] = 'Issue StoreRequisition';
$StoreReqNo = $_GET['ReqNo'];
$data['ReqItem'] = $this->storerequistion_model->getRequistItemList($StoreReqNo);
$data['ReqListDetails'] = $this->storerequistion_model->getRequistDetails($StoreReqNo);
//print_r($data['ReqItem']);
$this->loadViews("issueStoreRequistion", $this->global, $data, null);
}
function UpdateIssueRequistion()
{
//echo 'ffd';
// die();
$ReqNO = $this->request->getPost('txtReqNo');
$RowCount = $this->request->getPost('txtRowCount');
//echo $RowCount;
//die();
$createddt = get_current_date_time();
$UPdateby = $this->session->get('userId');
$UPdateon = get_current_date_time();
//$ItemStatus = STORE_ISSUSED;
for ($i = 1; $i <= $RowCount; $i++) {
$MaterialCode = $this->request->getPost('MaterialCode' . $i);
// echo $MaterialCode;
$IssuedQuantity = $this->request->getPost('txtIssuedQuantity' . $i);
$Reqqty = $this->request->getPost('txtqty' . $i);
// echo $Reqqty;
// die();
$savedqty = $this->storerequistion_model->getSavedQty($ReqNO, $MaterialCode);
// if($reqstatus==)
// print_r($savedqty);
// die();
$Qtyissued = 0;
foreach ($savedqty as $Qty) {
$Qtyissued = $Qty->QuantityIssued;
}
$ActQty = $Qtyissued + $IssuedQuantity;
// echo $ActQty;
// die();
if ($Reqqty > $ActQty) {
$ItemStatus = STORE_PARTIALLYISSUSED;
} else {
$ItemStatus = STORE_ISSUSED;
}
//echo $ItemStatus;
//die();
// echo'Material issed';
if (strlen($IssuedQuantity) > 0) {
$Remarks = $this->request->getPost('txtRemarks' . $i);
//echo $IssuedQuantity;
//die ();
$CreatedBy = $this->session->get('userId');
$storerequisition = array('StoreReqNo' => $ReqNO, 'MaterialCode' => $MaterialCode, 'QuantityIssued' => $ActQty, 'Status' => $ItemStatus, 'StoreComments' => $Remarks, 'UpdatedOn' => $createddt, 'UpdatedBy' => $CreatedBy);
//print_r($storerequisition);
//die();
$this->storerequistion_model->UpdateStoreRequistionItem($storerequisition, $ReqNO, $MaterialCode);
$getAvailableqty = $this->storerequistion_model->getItemQuantityFromStock(trim($MaterialCode));
if (count($getAvailableqty) > 0) {
$avlQty = $getAvailableqty[0]['Quantity'];
}
$BalanceQty = $avlQty - $IssuedQuantity;
// echo $BalanceQty;
// die();
$updatStock = array(
'Quantity' => $BalanceQty, 'Status' => '0',
'Remarks' => 'Stock Deducted For' . $ReqNO, 'UpdatedOn' => $UPdateon, 'UpdatedBy' => $UPdateby
);
$this->storerequistion_model->UpdateStock($updatStock, trim($MaterialCode));
$StoreReqNo = $ReqNO;
$reqstatus = $this->storerequistion_model->getstatuscount('ST037', $ReqNO);
$reqstatuscount = 0;
//print_r($reqstatus);
foreach ($reqstatus as $Req) {
$reqstatuscount = $Req->SCount;
}
if ($reqstatuscount == $RowCount) {
$reqStatus = STORE_ISSUSED;
} else {
$reqStatus = STORE_PARTIALLYISSUSED;
}
// echo $reqstatuscount;
$updatestatus = array('Status' => $reqStatus);
$this->storerequistion_model->updatestoremaster($updatestatus, $StoreReqNo);
}
}
//die();
echo "<script>alert('Updated Successfully!');</script>";
redirect('storerequisitionlisting', 'refresh');
}
/* this function use to search StoreRequistlist*/
function SearchRequistLists()
{
$userID = $this->session->get('userId');
$data['AppList'] = $this->storerequistion_model->getApproverRequistList($userID);
//print_r($data['AppList']);
$this->global['pageTitle'] = ' ApprovalStoreRequisitionSlip';
$data['Status'] = $this->storerequistion_model->getStatus();
if ($this->Designation != SECURITY && $this->DEPCode != HR) {
$this->loadViews("approvalstorerequisitionslip", $this->global, $data, NULL);
} else {
$this->loadViews("access", $this->global, $data, NULL);
}
}
/*Approve Completed*/
function ApproveRequest()
{
$Status = Trim($_GET['Status']);
//$StoreReqNo=$this->request->getPost('StoreReqNo');
$StoreReqNo = trim($this->request->getPost('id'));
$Remarks = trim($this->request->getPost('newcomments'));
$ApprovedBy = $this->session->get('userId');
$ApprovedDate = get_current_date_time();
$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'] = 'Approvalstorerequisitionlist';
//$data['Status']= $this->storerequistion_model->getStatus();
$userID = $this->session->get('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->request->getPost('id');
$result = $this->storerequistion_model->getRequistItemListApproval($StoreReqNo);
$ReqList = $this->storerequistion_model->getRequistDetails($StoreReqNo);
// $DepNo = $ReqList[0]['DepartmentName'];
$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'];
$IssuedQty = $result[$i]['QuantityIssued'];
$Status = $result[$i]['StatusName'];
$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'>" . $IssuedQty . "</td>
<td align='left'>" . $Status . "</td>
<td align='left'>" . $Remarks . "</td>
</tr>";
//$index = $index + 1;
}
//print_r($ReqList);
die(json_encode(array('Items' => $HTML, 'Requist' => $ReqList)));
}
//not completed
function UpdateStoreRequistion()
{
$CostCenter = $this->request->getPost('CostCenter');
$DeletedRow = $this->request->getPost('txtDeletedRow');
$RowCount = $this->request->getPost('txtRowCount');
$Status = $this->request->getPost('txtStatus');
$Requestedby = $this->session->get('EmpID');
$comma_separated = explode(':', $DeletedRow);
$StoreReqNo = $this->request->getPost('txtReqNo');
$Requestedby = $this->request->getPost('RequestedBy');
//echo $CostCenter;
$UpdatedBy = $this->session->get('userId');
$updatedDate = get_current_date_time();
if (strlen($Status) > 1) {
$Request = array('CostCenterCode' => $CostCenter, 'Status' => $Status, 'updatedOn' => $updatedDate);
$UpdateReq = $this->storerequistion_model->UpdateRequistion($StoreReqNo, $Request);
}
$SkipInsert = False;
$StoreItemStatus = STORE_OPEN;
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];
if ($deletedRow == $i) {
$SkipInsert = "True";
break;
}
}
}
if ($SkipInsert == "False") {
//echo "string"; die();
$MaterialCode = $this->request->getPost('MaterialCode' . $i);
$QuantityRequired = $this->request->getPost('Quantity' . $i);
$Remarks = $this->request->getPost('Remarks' . $i);
$IsExists = $this->storerequistion_model->LineItemIsExists($StoreReqNo, $MaterialCode);
if (count($IsExists) == 0) {
$ReqDetails = array('StoreReqNo' => $StoreReqNo, 'MaterialCode' => $MaterialCode, 'QuantityRequired' => $QuantityRequired, 'Remarks' => $Remarks, 'Status' => $StoreItemStatus, 'UpdatedBy' => $UpdatedBy, 'UpdatedOn' => $updatedDate);
//print_r($ReqDetails);
//die();
$this->storerequistion_model->addstoreRequistion($ReqDetails);
} else {
$ReqDetails = array('QuantityRequired' => $QuantityRequired, 'Remarks' => $Remarks, 'Status' => $StoreItemStatus, '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->request->getPost('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;
}
}