417 lines
14 KiB
PHP
417 lines
14 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers;
|
|
|
|
use App\Controllers\BaseController;
|
|
|
|
use CodeIgniter\Validation\Exceptions\ValidationException;
|
|
|
|
// require APPPATH . '/third_party/mpdf/mpdf.php';
|
|
|
|
use App\Models\Inwardgateregister_model;
|
|
use App\Models\Mrir_model;
|
|
use App\Models\Purchaseorder_model;
|
|
use App\Models\Requistion_model;
|
|
|
|
|
|
/**
|
|
* Module : MRIR (security)
|
|
* MRIRcontroller Class to control all MRIR related operations.
|
|
* @author : Saravana kumar
|
|
* @version : 1.1
|
|
* @since : 10 Jun 2017
|
|
* @example : Revised at 15th april 2024
|
|
*/
|
|
class MRIRcontroller extends BaseController
|
|
{
|
|
protected $purchaseorder_model;
|
|
protected $inwardgateregister_model;
|
|
protected $mrir_model;
|
|
protected $requistion_model;
|
|
protected $session;
|
|
|
|
|
|
/**
|
|
* This is default constructor of the class
|
|
*/
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->purchaseorder_model = new Purchaseorder_model();
|
|
$this->inwardgateregister_model = new Inwardgateregister_model();
|
|
$this->requistion_model = new Requistion_model();
|
|
$this->mrir_model = new Mrir_model();
|
|
$this->session = session();
|
|
helper('form'); //$this->load->library('form_validation');
|
|
$this->isLoggedIn();
|
|
|
|
}
|
|
/**
|
|
* This function used to load the first screen of the user
|
|
*/
|
|
public function index()
|
|
{
|
|
$this->global['pageTitle'] = 'View material inspection report';
|
|
|
|
$this->loadViews("viewmaterialinspectionreport", $this->global, NULL, NULL);
|
|
}
|
|
/* For Entry MRIR Screen*/
|
|
function materialinspectionreport($mrir = '', $IGRNO = '')
|
|
{
|
|
$this->global['pageTitle'] = 'Material Inspection Report';
|
|
|
|
|
|
|
|
$data['IGRNOonly'] = $this->mrir_model->getIGRNOonly();
|
|
|
|
$this->loadViews("materialinspectionreport", $this->global, $data, NULL);
|
|
}
|
|
// Mrir pdf
|
|
public function MrirDetailsPrintPdf()
|
|
{
|
|
$MrirNo = $_GET['MRIRNO'];
|
|
|
|
|
|
$this->global['pageTitle'] = 'MRIR Pdf ';
|
|
$data['CompanyDetails'] = $this->purchaseorder_model->getCompanyInformation();
|
|
$data['MRIRDetails'] = $this->mrir_model->edit_mrir($MrirNo);
|
|
|
|
//mpdf
|
|
$mpdf = new mPDF('utf-8', 'A4-P', 10, 10, 10, 10, 10, 38, 4, 6);
|
|
$mpdf->SetDisplayMode('fullpage');
|
|
$mpdf->SetHTMLHeader($HtmlHeading);
|
|
$html = view('Mrirprintpdf', $data, true);
|
|
$mpdf->SetDisplayMode('fullpage');
|
|
$mpdf->setFooter($HTMLFooter . "Page {PAGENO} of {nb}");
|
|
$mpdf->list_indent_first_level = 1;
|
|
$mpdf->setAutoTopMargin = 'stretch';
|
|
$mpdf->setAutoBottomMargin = 'stretch';
|
|
$mpdf->WriteHTML($html);
|
|
$mpdf->Output("MrirDetails" . $data . '.pdf', 'I', $php);
|
|
|
|
|
|
|
|
|
|
// Get output html
|
|
// $php = $this->output->get_output();
|
|
|
|
// // Load library
|
|
// $this->load->library('dompdf_gen');
|
|
|
|
// // Convert to PDF
|
|
// $this->dompdf->load_html($php);
|
|
// $this->dompdf->render();
|
|
// $data['Attachment'] = FALSE;
|
|
// $this->dompdf->stream("MrirDetails.pdf",$data,$php);
|
|
|
|
}
|
|
|
|
public function viewmrirforbilling()
|
|
{
|
|
$this->global['pageTitle'] = 'Billing ';
|
|
$data['Billing'] = $this->mrir_model->view_mrir_Billing();
|
|
|
|
|
|
|
|
$this->loadViews("viewmrirforbilling", $this->global, $data, NULL);
|
|
}
|
|
|
|
|
|
public function viewmMaterialDistributionList()
|
|
{
|
|
$this->global['pageTitle'] = 'Distribution list ';
|
|
|
|
$data['Distribution'] = $this->mrir_model->ViewDistributionList();
|
|
$data['status'] = $this->mrir_model->getStatus();
|
|
|
|
|
|
|
|
$this->loadViews("MaterialIssueList", $this->global, $data, NULL);
|
|
}
|
|
|
|
|
|
/*FOR Displaying IGR Values (view folder- IGR view page (button link)) */
|
|
function igrdatavalues()
|
|
{
|
|
|
|
$IgrNo = $_GET['IGRNO'];
|
|
|
|
$data['IGRDetails'] = $this->mrir_model->get_IGR($IgrNo);
|
|
|
|
$this->global['pageTitle'] = 'IGR Details ';
|
|
|
|
$this->loadViews("materialinspectionreport", $this->global, $data, NULL);
|
|
}
|
|
function viewinwardgateregister()
|
|
{
|
|
|
|
$this->global['pageTitle'] = 'View Inward Gate Register';
|
|
|
|
$data['IGR'] = $this->mrir_model->ViewigrListing();
|
|
|
|
|
|
|
|
|
|
|
|
$this->loadViews("viewinwardgateregister", $this->global, $data, NULL);
|
|
}
|
|
|
|
/* For View MRIR Screen (view folder - view page)*/
|
|
function viewmaterialinspectionreport()
|
|
|
|
{
|
|
|
|
$this->mrir_model = new mrir_model();
|
|
|
|
$data['viewmrirdatas'] = $this->mrir_model->view_mrir();
|
|
//old name:mrirdatas2
|
|
$this->global['pageTitle'] = 'View Material Inspection Report';
|
|
//print_r( $data);
|
|
|
|
|
|
|
|
$this->loadViews("viewmaterialinspectionreport", $this->global, $data, NULL);
|
|
}
|
|
|
|
/* FOR Edit MRIR Screen (View folder - edit page)*/
|
|
function editmaterialinspectionreport()
|
|
{
|
|
|
|
$this->mrir_model = new mrir_model();
|
|
|
|
$MrirNo = $_GET['MRIRNO'];
|
|
|
|
$data['MRIRDetails'] = $this->mrir_model->edit_mrir($MrirNo); //get_MRIR_Values($MrirNo);
|
|
//print_r($data['MRIRDetails']);
|
|
|
|
$this->global['pageTitle'] = 'Edit Material Inspection Report';
|
|
|
|
$this->loadViews("Editmaterialinspectionreport", $this->global, $data, NULL);
|
|
}
|
|
|
|
|
|
/* NEW Values TO Stored in DB (for insert operation) */
|
|
function stored_db() //old name : displaying_values()
|
|
{
|
|
$this->mrir_model = new mrir_model();
|
|
|
|
$RowCount = $this->request->getPost('RowCount');
|
|
$igrno = $this->request->getPost('IGRNO');
|
|
$PONO = $this->request->getPost('PONO');
|
|
|
|
$CreatedBy = $this->session->get('userId');
|
|
|
|
$createddt = get_current_date_time();
|
|
$Remark = $this->request->getPost('Remark');
|
|
|
|
|
|
//this array to store the value in master table..
|
|
$mrirmastervalues = array('MRIRStatus' => MRIR_CREATED, 'IGRNO' => $igrno, 'PONO' => $PONO, 'CreatedBy' => $CreatedBy, 'Createdon' => $createddt);
|
|
|
|
$mrirmaster = $this->mrir_model->master_mrir($mrirmastervalues);
|
|
$IGRDetails = array('IGRStatus' => MRIR_CREATED, 'UpdateBY' => $CreatedBy, 'UpdatedOn' => $createddt);
|
|
|
|
$this->mrir_model->UpdateIGRStatus($IGRDetails, $igrno);
|
|
|
|
// $OGRStatus=MRIR_CREATED;
|
|
// $check_OGRPO= $this->inwardgateregister_model->update_OGR($PONO,$OGRStatus);
|
|
|
|
|
|
$MRIRNO = '';
|
|
|
|
|
|
if (count($mrirmaster) > 0) {
|
|
foreach ($mrirmaster as $key) {
|
|
|
|
$MRIRNO = $key->MRIRNo;
|
|
}
|
|
}
|
|
|
|
|
|
for ($i = 1; $i <= $RowCount; $i++) {
|
|
|
|
$MaterialCode = $this->request->getPost('MaterialCode' . $i);
|
|
$MaterialCode = $MaterialCode !== null && is_string($MaterialCode) ? trim($MaterialCode) : null;
|
|
$ActualQuantityReceived = $this->request->getPost('ActualQuantity' . $i);
|
|
$ActualQuantityReceived = $ActualQuantityReceived !== null && is_string($ActualQuantityReceived) ? trim($ActualQuantityReceived) : null;
|
|
$QuantityAsPerInvoice = $this->request->getPost('Remark' . $i);
|
|
$QuantityAsPerInvoice = $QuantityAsPerInvoice !== null && is_string($QuantityAsPerInvoice) ? trim($QuantityAsPerInvoice) : null;
|
|
$Remarked = $this->request->getPost('OrderedQuantity' . $i);
|
|
$Remarked = $Remarked !== null && is_string($Remarked) ? trim($Remarked) : null;
|
|
$StoreIncharge = $this->session->get('userId');
|
|
|
|
|
|
//this array to store the value in child table..
|
|
$mrirdetailvalues = array('MRIRNO' => $MRIRNO, 'MaterialCode' => $MaterialCode, 'ActualQuantityReceived' => $ActualQuantityReceived, 'StoreInchargeID' => $StoreIncharge, 'Remarks' => $Remarked);
|
|
|
|
//print_r($mrirdetailvalues);
|
|
//die();
|
|
|
|
$mrirdetails = $this->mrir_model->detail_mrir($mrirdetailvalues);
|
|
}
|
|
echo "successfully created : " . $MRIRNO;
|
|
}
|
|
|
|
/* Values To Stored in DB (for update operation) */
|
|
function updated_db()
|
|
{
|
|
|
|
$this->mrir_model = new mrir_model();
|
|
|
|
$mrir_no = $this->request->getPost('MRIRNO');
|
|
$RowCount = $this->request->getPost('RowCount');
|
|
$Status = $this->request->getPost('status');
|
|
$UPdateby = $this->session->get('userId');
|
|
|
|
$UPdateon = get_current_date_time();
|
|
$PONO = $this->request->getPost('PONO');
|
|
//this array to store the updated value in master table..
|
|
|
|
$strStatus = '';
|
|
|
|
$strStatus = '';
|
|
|
|
$ISRejected = 0;
|
|
for ($i = 1; $i <= $RowCount; $i++) {
|
|
$ActualQty = $this->request->getPost('ActualQuantityReceived' . $i);
|
|
$ActualQty = $ActualQty !== null && is_string($ActualQty) ? trim($ActualQty) : null;
|
|
$acceptquantity = $this->request->getPost('QuantityAccepted' . $i);
|
|
$acceptquantity = $acceptquantity !== null && is_string($acceptquantity) ? trim($acceptquantity) : null;
|
|
$rejectquantity = $this->request->getPost('QuantityRejected' . $i);
|
|
$rejectquantity = $rejectquantity !== null && is_string($rejectquantity) ? trim($rejectquantity) : null;
|
|
$MaterialCode = $this->request->getPost('MaterialCode' . $i);
|
|
$MaterialCode = $MaterialCode !== null && is_string($MaterialCode) ? trim($MaterialCode) : null;
|
|
$Lineitm = $this->request->getPost('Lineitm' . $i);
|
|
$Lineitm = $Lineitm !== null && is_string($Lineitm) ? trim($Lineitm) : null;
|
|
|
|
|
|
if ($acceptquantity != 0) {
|
|
|
|
$ISRejected = 1;
|
|
$strStatus = MRIR_APPROVED;
|
|
$avlQty = 0;
|
|
$getAvailableqty = $this->mrir_model->getItemQuantityFromStock(trim($MaterialCode));
|
|
|
|
if (count($getAvailableqty) > 0) {
|
|
$avlQty = $getAvailableqty[0]['Quantity'];
|
|
}
|
|
|
|
|
|
$updatStock = array('Quantity' => ($acceptquantity + $avlQty), 'Status' => '0', 'UpdatedOn' => $UPdateon, 'UpdatedBy' => $UPdateby, 'Remarks' => 'Stock added for ' . $this->request->getPost('MRIRNO'));
|
|
|
|
$this->mrir_model->UpdateStock($updatStock, trim($MaterialCode));
|
|
} elseif ($rejectquantity != 0 && $acceptquantity == 0) {
|
|
$strStatus = MRIR_REJECTED;
|
|
}
|
|
|
|
|
|
|
|
$remark = $this->request->getPost('Remark' . $i);
|
|
|
|
$updateby = $this->session->get('userId');
|
|
|
|
$updateon = get_current_date_time();
|
|
|
|
if (strlen($acceptquantity) <= 0 && $acceptquantity == 0) {
|
|
$rejectquantity = $ActualQty;
|
|
}
|
|
//this array to store the update value in child table..
|
|
$updatedetailvalues = array('UpdateBy' => $updateby, 'UpdatedOn' => $updateon, 'QuantityAccepted' => $acceptquantity, 'QuantityRejected' => $rejectquantity, 'Remarks' => $remark, 'MRIRStatus' => $strStatus);
|
|
|
|
|
|
|
|
$updatedetails = $this->mrir_model->update_mrirdetail($updatedetailvalues, $Lineitm);
|
|
|
|
$POLineItem = array('Status' => $strStatus, 'UpdateBY' => $updateby, 'UpdatedOn' => $updateon);
|
|
|
|
$this->mrir_model->UpdatePOLineItem($POLineItem, $PONO, $MaterialCode);
|
|
|
|
//$OGRStatus=MRIR_CREATED;
|
|
//$check_OGRPO= $this->inwardgateregister_model->update_OGR($PONO,$strStatus);
|
|
|
|
}
|
|
|
|
|
|
$OGRStatus = OGR_NOT_CREATED;
|
|
$PoMrirStatus = '';
|
|
|
|
if ($ISRejected == 1) {
|
|
$PoMrirStatus = MRIR_APPROVED;
|
|
} else {
|
|
$PoMrirStatus = MRIR_REJECTED;
|
|
}
|
|
$updatemastervalues = array('MRIRStatus' => $PoMrirStatus, 'UpdateBY' => $UPdateby, 'UpdatedOn' => $UPdateon, 'OGRstatus' => $OGRStatus);
|
|
|
|
$updatemaster = $this->mrir_model->update_mrirmaster($updatemastervalues, $mrir_no);
|
|
|
|
$this->mrir_model->UpdatePOMaster($PONO, $PoMrirStatus, $UPdateby);
|
|
|
|
echo "successfully updated :" . $mrir_no;
|
|
}
|
|
|
|
/*in view screen we display values for modal (viewmaterialinspectionreport.php)*/
|
|
function displaying_MRIRvalues()
|
|
{
|
|
$mrir = $this->request->getPost("mrirno");
|
|
$result = $this->mrir_model->get_MRIRs($mrir);
|
|
$obj = json_encode($result);
|
|
echo $obj;
|
|
}
|
|
|
|
|
|
function displaying_IGRvalues()
|
|
{
|
|
|
|
$igr = $this->request->getPost("igrno");
|
|
$result = $this->mrir_model->get_IGRs($igr);
|
|
$obj = json_encode($result);
|
|
echo $obj;
|
|
}
|
|
|
|
function UpdateReqItemStatus()
|
|
{
|
|
|
|
$Values = $this->request->getPost('id');
|
|
$StatusCode = trim($Values[0]);
|
|
$MaterialCode = trim($Values[1]);
|
|
$ReqNumber = trim($Values[2]);
|
|
$Remarks = trim($Values[3]);
|
|
$ReqQuantity = trim($Values[4]);
|
|
$AceptedQty = trim($Values[5]);
|
|
|
|
$UpdatedBy = $this->session->get('userId');
|
|
|
|
$updatedDt = get_current_date_time();
|
|
|
|
$getAvailableqty = $this->mrir_model->getItemQuantityFromStock($MaterialCode);
|
|
|
|
|
|
$avlQty = 0;
|
|
|
|
if (count($getAvailableqty) > 0) {
|
|
$avlQty = $getAvailableqty[0]['Quantity'];
|
|
}
|
|
|
|
|
|
$BalanceQty = 0;
|
|
if ($avlQty > 0 && $avlQty >= $AceptedQty) {
|
|
$BalanceQty = $avlQty - $AceptedQty;
|
|
}
|
|
|
|
|
|
$ReqDetails = array('Status' => $StatusCode, 'remarks' => $Remarks, 'UpdatedBy' => $UpdatedBy, 'UpdatedOn' => $updatedDt, 'DeliveredQuantity' => $ReqQuantity);
|
|
|
|
$this->requistion_model->UpdateRequistionLineItem($ReqDetails, $ReqNumber, $MaterialCode);
|
|
|
|
$StoreDetails = array('Remarks' => 'Stock Dedeucted for ' . $ReqNumber . ' from ' . $avlQty, 'Quantity' => $BalanceQty);
|
|
|
|
|
|
$this->requistion_model->UpdateAvlQty($StoreDetails, $MaterialCode);
|
|
|
|
|
|
echo "Material Issued Successfully for the Requistion: " . $ReqNumber;
|
|
}
|
|
|
|
}
|