ria/app/Controllers/Inwardgateregister.php

1470 lines
72 KiB
PHP
Executable File

<?php
namespace App\Controllers;
use App\Controllers\BaseController;
use CodeIgniter\Validation\Exceptions\ValidationException;
use App\Models\Inwardgateregister_model;
/**
* Module : IGR (security)
* Inwardgateregister Class to control all igr related operations.
* @author : Saravana kumar
* @version : 1.1
* @since : 8 Jun 2017
* @example : Revised at 15th april 2024
*/
class Inwardgateregister extends BaseController
{
protected $inwardgateregister_model;
protected $session;
/**
* This is default constructor of the class
*/
public function __construct()
{
parent::__construct();
$this->inwardgateregister_model = new Inwardgateregister_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'] = 'Inward Gate Register';
$this->loadViews("viewinwardgateregister", $this->global, NULL, NULL);
}
function viewIGR()
{
$this->global['pageTitle'] = 'View Inward Gate Register';
$data['IGR'] = $this->inwardgateregister_model->ViewigrListing();
$data['DEPCode'] = $this->session->get('DEPCode');
$this->loadViews("viewinwardgateregister", $this->global, $data, NULL);
// $this->global['pageTitle'] = 'Inward Gate Register Details';
// $data['IGR'] = $this->inwardgateregister_model->igrListing();
// $this->loadViews("viewIGRDetails", $this->global, $data, NULL);
}
function addIGR()
{
$this->inwardgateregister_model = new inwardgateregister_model();
$this->global['pageTitle'] = 'Add Inward Gate Register';
$result = $this->inwardgateregister_model->getpurchaseorder();
// $data['PO_NO'] = array_filter($result, function($item) {
// return !($item->status === 'ST027' && $item->IsOpenOrder === null);
// });
$data['PO_NO'] = array_filter($result, function($item) {
return !($item->status === 'ST027');
});
$this->loadViews("inwardgateregister", $this->global, $data, NULL);
}
function addoutwardgateregister()
{
$this->inwardgateregister_model = new inwardgateregister_model();
$this->global['pageTitle'] = 'Add Outward Gate Register';
$data['Customer'] = $this->inwardgateregister_model->getCustomer();
$data['Supplier'] = $this->inwardgateregister_model->getSupplier();
//$data['Invoice'] = $this->inwardgateregister_model->getInvoice();
$data['storedmaterialcode'] = $this->inwardgateregister_model->getstoredmaterialcode();
//print_r($data['PO_NO']);
$this->loadViews("ogr", $this->global, $data, NULL);
}
function ViewOgr()
{
$this->inwardgateregister_model = new inwardgateregister_model();
$this->global['pageTitle'] = 'View Outward Gate Register';
$data['OGR_Data'] = $this->inwardgateregister_model->getOGRData();
//print_r($data['OGR_Data']);
$this->loadViews("ogrlist", $this->global, $data, NULL);
}
function EditOGR()
{
$OGRNO = $_GET['OGRNO'];
$MRIRNO = $_GET['MRIRNO'];
$this->global['pageTitle'] = 'View Outward Gate Register';
$data['OGR_Data'] = $this->inwardgateregister_model->getOGRDataforedit($OGRNO);
$data['OGR_line'] = $this->inwardgateregister_model->getOGRlineDataforedit($OGRNO, $MRIRNO);
$this->loadViews("editogr", $this->global, $data, NULL);
}
function GetInvoices()
{
$CustomerId = $this->request->getPost('customerId');
$data = $this->inwardgateregister_model->getInvoice($CustomerId);
echo json_encode($data);
}
function GetPO()
{
$supplierId = $this->request->getPost('supplierId');
$data = $this->inwardgateregister_model->getPO($supplierId);
echo json_encode($data);
}
function getPODetails()
{
$PONO = $this->request->getPost('PONO');
$data = $this->inwardgateregister_model->getPODetails($PONO);
//$data['poout'] = $this->inwardgateregister_model->getPODetails($PONO);
echo json_encode($data);
}
function getMRIRDetails()
{
$MRIRno = $this->request->getPost('mrirno');
$PONO = $this->request->getPost('PONO');
$materialcode = $this->request->getPost('materialcode');
$data = $this->inwardgateregister_model->getPOMRIRDetails($MRIRno, $PONO, $materialcode);
//$data['outqty'] = $this->inwardgateregister_model->gettotalout($PONO,$materialcode);
//$data['poout'] = $this->inwardgateregister_model->getPODetails($PONO);
echo json_encode($data);
}
function getMRIR()
{
$MRIRno = $this->request->getPost('MRIRNO');
$PONO = $this->request->getPost('PONO');
$data = $this->inwardgateregister_model->getPOMRIRMaterial($MRIRno, $PONO);
//$data['poout'] = $this->inwardgateregister_model->getPODetails($PONO);
echo json_encode($data);
}
function getPOmrir()
{
$PONO = $this->request->getPost('PONO');
$data = $this->inwardgateregister_model->getPOmrir($PONO);
//$data['poout'] = $this->inwardgateregister_model->getPODetails($PONO);
echo json_encode($data);
}
function getPOmaterialDetails()
{
$PONO = $this->request->getPost('PONO');
$materialcode = $this->request->getPost('materialcode');
$data = $this->inwardgateregister_model->getPOmaterialDetails($PONO, $materialcode);
echo json_encode($data);
}
function getPOmaterial()
{
$PONO = $this->request->getPost('PONO');
$data = $this->inwardgateregister_model->getPOmaterial($PONO);
//$data['poout'] = $this->inwardgateregister_model->getPODetails($PONO);
echo json_encode($data);
}
function getIGRLineItemDetails()
{
$PO = $this->request->getPost('id');
$CreatedBy = $this->session->get('userId');
$this->inwardgateregister_model->UpdatePOMaster($PO, $CreatedBy);
$data = $this->inwardgateregister_model->viewpurchaseorder($PO);
echo json_encode($data);
}
function addloadfile()
{
$lastinsertbillid = 0;
$pono = $this->request->getPost('PONO');
$igr = $this->request->getPost('igr');
$file = $this->request->getFile('file');
$requestfilename = $file->getName();
$files = $this->inwardgateregister_model->getfies($igr);
$fcount = 0;
foreach ($files as $value) {
$lastfile = $value->FilePath;// not a file path just file name only
if ($lastfile == $requestfilename) {
$fcount++;
}
}
if ($fcount == 0) {
if (!empty($requestfilename)) {
if ($file->isValid() && !$file->hasMoved()) {
$path = ROOTPATH.'public/uploads/Igrfiles/';
if(!is_dir($path)) { mkdir($path, 0777, true); }
$Picture = $file->getName();
$file->move($path, $Picture);
}else{
$Picture = "";
}
$myfiles = array('PONO' => $pono, 'IGRNO' => $igr, 'FilePath' => $Picture);
$lastinsertbillid = $this->inwardgateregister_model->fileupload($myfiles);
}
}
if ($lastinsertbillid > 0) {
echo "File updated Successfully!-".$lastinsertbillid;
} else {
echo "File name already Exist";
}
}
function deleteBillFile(){
$deleteBillFile = '';
$Billno = $this->request->getPost('Billno');
$deleteBillFile = $this->inwardgateregister_model->deleteBillFile($Billno);
if ($deleteBillFile) {
echo "file deleted successfully!";
} else {
echo "file details not exist to delete";
}
}
function edituploadfile()
{
$bill = $this->request->getPost('param1');
$oldfile = $this->request->getPost('param2');
$newfile = $this->request->getFile('file');
if ($newfile->isValid() && !$newfile->hasMoved()) {
$path = ROOTPATH . 'public/uploads/Igrfiles/';
$newfilename = $newfile->getName();
if(!is_dir($path)) { mkdir($path, 0777, true); }
$Picture = str_replace(" ", "", $newfilename);
$newfile->move($path,$Picture);
} else {
$Picture = $oldfile;
}
$uploadfile = $this->inwardgateregister_model->updatefile($bill, $Picture, $oldfile);
// if($uploadfile > 0){
echo "updated successfully!";
// }
// else{
// echo "updated successfully!";
// }
}
function SaveIGR()
{
#Step 1 IGR Details
$PONO = $this->request->getPost('PONO');
$DeliveryChellanOrInvoiceNo = $this->request->getPost('InvoiceNo');
$DeliveryChellan = (string)$this->request->getPost('InvoiceDate');
$DeliveryChellanDate = get_date_time_format($DeliveryChellan);
$Mat_Rcvd_Dt = (string)$this->request->getPost('MaterialRcvdDate');
$MaterialRcvdDt = get_date_time_format($Mat_Rcvd_Dt);
$VehicleNo = $this->request->getPost('VehicleNo');
$DriverName = $this->request->getPost('DriverName');
$DriverMobileNumber = $this->request->getPost('DriverMobileNumber');
$CreatedBy = $this->session->get('userId');
$RowCount = $this->request->getPost('txtRowCount');
$createddt = get_current_date_time();
//$IGRStatus = IGR_CREATED;//old
$IGRStatus = (int)$this->request->getPost('hideIGRStatus') == 1 ? IGR_CREATED : IGR_DRAFT;
$document = null;
$igr = array(); // For IGR Master
$paymentstatus = NO_PAIDIGR;
$constant = $this->request->getPost('hideconstants');
$arr = []; // For File to Save
$prefile = array();
$fileupdated_count = 0;
$fileupdated_name = [];
$igr = array('PONO' => $PONO, 'VehicleNo' => $VehicleNo, 'DeliveryChellanOrInvoiceNo' => $DeliveryChellanOrInvoiceNo, 'DeliveryChellanDate' => $DeliveryChellanDate, 'MaterialRcvdDate' => $MaterialRcvdDt, 'DriverName' => $DriverName, 'DriverMobileNumber' => $DriverMobileNumber,'IGRStatus' => $IGRStatus, 'CreatedBy' => $CreatedBy, 'CreatedDate' => $createddt, 'PaymentStatus' => $paymentstatus);
//Saving IGR details Here
$IGRNO = $this->inwardgateregister_model->addigrM($igr);
if($IGRNO){
#Step 1.1 Fetch On History
if($VehicleNo){
$igr_history = array('field' => 'VehicleNo','is_add' => 1,'new_data' => $VehicleNo,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNO);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}
if($DriverName){
$igr_history = array('field' => 'DriverName','is_add' => 1,'new_data' => $DriverName,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNO);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}
if($DriverMobileNumber){
$igr_history = array('field' => 'DriverMobileNumber','is_add' => 1,'new_data' => $DriverMobileNumber,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNO);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}
#Step 2 File Details Gathering
if($constant){
for ($i = 1; $i <= $constant; $i++) {
$pathname = 'browseFiles' . $i;
$file = $this->request->getFile($pathname);
if ($file && $file->isValid()) {
$requestfilename = $file->getName();
if (!empty($requestfilename)) {
$files = str_replace(" ", "", $_FILES[$pathname]['name']);
$fcount = 0;
foreach ($prefile as $value) {
if ($value == $files) { $fcount++; }
}
if ($fcount == 0) {
if ($file->isValid() && !$file->hasMoved()) {
$path = ROOTPATH.'public/uploads/Igrfiles/';
if(!is_dir($path)) { mkdir($path, 0777, true); }
$Picture = $file->getName();
$file->move($path,$Picture);
log_message('error', "File new" . $i . " uploaded successfully. File name: " . $requestfilename);
}
$arr[] = array($Picture);
}
$prefile[] = $files;
}
} else {
log_message('error', "No file uploaded for new" . $i . " or there was an error uploading the file.");
}
}
#Step 2.1 Saving File Details
if (!empty($arr)) {
foreach ($arr as $ma) {
$index = 0;
foreach ($ma as $key => $value) {
$index++;
if ($index == 1) {
$filename = $value;
}
}
if (!empty($filename)) {
$myfile = array('FilePath' => $filename, 'PONO' => $PONO, 'IGRNO' => $IGRNO);
$fileupdated = $this->inwardgateregister_model->fileupload($myfile);
if ($fileupdated) {
$fileupdated_count++;
$fileupdated_name[] = $filename;
}
}
}
}
}
#Step 3 Updating OGR Details
$OGRStatus = $IGRStatus;
$check_OGRPO = $this->inwardgateregister_model->update_OGR($PONO, $OGRStatus);
// echo "step3";
// echo "uuu".(int)$check_OGRPO;
$IGRItemStatus = REQITEM_NEW;
$TotalPendingQty = '';
$TotalPendingQty = (int)$TotalPendingQty;
// echo "step4";
#Step 4 To Update the Date PO MASTER , Material Master , Historydetails and IGR line Item Details Updating OGR Details
for ($i = 1; $i <= (int)$RowCount; $i++) {
$MaterialCode = $this->request->getPost('MaterialCode' . $i);
$MaterialCode = $MaterialCode !== null && is_string($MaterialCode) ? trim($MaterialCode) : null;
$QuantityAsPerInvoice = $this->request->getPost('txtQuantityAsPerInvoice' . $i);
$QuantityAsPerInvoice = $QuantityAsPerInvoice !== null && is_string($QuantityAsPerInvoice) ? trim($QuantityAsPerInvoice) : null;
$OrderedQuantity = $this->request->getPost('OrderedQuantity' . $i);
$OrderedQuantity = $OrderedQuantity !== null && is_string($OrderedQuantity) ? trim($OrderedQuantity) : null;
$ReceivedQty = $this->request->getPost('txtReceivedQuantity' . $i);
$ReceivedQty = $ReceivedQty !== null && is_string($ReceivedQty) ? trim($ReceivedQty) : null;
$PendingQty = $this->request->getPost('txtPendingQty' . $i);
$TotalPendingQty = $TotalPendingQty + $PendingQty;
$GrossWeight = $this->request->getPost('txtGrossWeight' . $i);
$grossWeightDate= $this->request->getPost('txtGrossWeightDate' . $i);
$TareWeight= $this->request->getPost('txtTareWeight' . $i);
$tareWeightDate= $this->request->getPost('txtTareWeightDate' . $i);
$NetWeight= $this->request->getPost('txtNetWeight' . $i);
// var_dump($grossWeightDate);
// var_dump($tareWeightDate);
$GrossWeightDate = !empty($grossWeightDate) && is_string($grossWeightDate) ? date('Y-m-d H:i:s', strtotime($grossWeightDate)) : null;
$TareWeightDate = !empty($tareWeightDate) && is_string($tareWeightDate) ? date('Y-m-d H:i:s', strtotime($tareWeightDate)) : null;
log_message('error', "TareWeightDate" . $TareWeightDate);
if (strlen($QuantityAsPerInvoice) > 0 && $QuantityAsPerInvoice != '0') {
$Remarks = $this->request->getPost('txtRemarks' . $i);
$ItemStatus = '';
if ($PendingQty == 0.00) {
$ItemStatus = $IGRStatus;
} else {
$ItemStatus = POLINEITEM_IGRPARTIAL_CREATED;
}
$CreatedBy = $this->session->get('userId');
$igrDetails = array('IGRNO' => $IGRNO, 'MaterialCode' => $MaterialCode, 'QuantityAsPerInvoice' => $QuantityAsPerInvoice, 'Remarks' => $Remarks, 'IGRItemStatus' => $IGRItemStatus,'GrossWeight' => (float)$GrossWeight ,'GrossWeightDate'=> $GrossWeightDate,'TareWeight' => (float)$TareWeight ,'TareWeightDate' => $TareWeightDate ,'NetWeight' => (float)$NetWeight, 'CreatedBy' => $CreatedBy, 'CreatedDate' => $createddt);
log_message('error', 'SaveIGR igrDetails result : ' . json_encode($igrDetails));
$igrD = $this->inwardgateregister_model->addigrD($igrDetails);
$igrlineno = !empty($igrD) ? $igrD : '';
$itemvalue = '';
$SupplierId = '';
$polineitemvalue = $this->inwardgateregister_model->getitemvalue($PONO, $MaterialCode);
foreach ($polineitemvalue as $it) {
$itemvalue = $it->Rate;
$SupplierId = $it->SupplierID;
}
$historydetails = array('MaterialCode' => $MaterialCode, 'Transaction_type' => "Add", 'Ref_Type' => "IGR", 'Ref_No' => $igrlineno, 'Quantity' => $QuantityAsPerInvoice, 'CreatedBy' => $CreatedBy, 'CreatedOn' => $createddt, 'SupplierID' => $SupplierId, 'ItemValue' => $itemvalue);
$this->inwardgateregister_model->addmaterialhistory($historydetails);
if($GrossWeight){
$igr_history = array('field' => 'GrossWeight','is_add' => 1,'new_data' => $GrossWeight,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNO,'IGRItem_No'=>$igrlineno);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}
if($TareWeight){
$igr_history = array('field' => 'TareWeight','is_add' => 1,'new_data' => $TareWeight,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNO,'IGRItem_No'=>$igrlineno);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}
if($NetWeight){
$igr_history = array('field' => 'NetWeight','is_add' => 1,'new_data' => $NetWeight,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNO,'IGRItem_No'=>$igrlineno);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}
if($GrossWeightDate){
$igr_history = array('field' => 'GrossWeightDate','is_add' => 1,'new_data' => $GrossWeightDate,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNO,'IGRItem_No'=>$igrlineno);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}
if($TareWeightDate){
$igr_history = array('field' => 'TareWeightDate','is_add' => 1,'new_data' => $TareWeightDate,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNO,'IGRItem_No'=>$igrlineno);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}
if($QuantityAsPerInvoice){
$igr_history = array('field' => 'QuantityAsPerInvoice','is_add' => 1,'new_data' => $QuantityAsPerInvoice,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNO,'IGRItem_No'=>$igrlineno);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}
if($Remarks){
$igr_history = array('field' => 'Remarks','is_add' => 1,'new_data' => $Remarks,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNO,'IGRItem_No'=>$igrlineno);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}
$get_pre_qty = $this->inwardgateregister_model->get_CurrentQty($MaterialCode);
$av_qty = 0;
if (!empty($get_pre_qty)) {
foreach ($get_pre_qty as $gt) {
$av_qty = $gt->Current_stock;
}
}
$currentav_qty = $QuantityAsPerInvoice + $av_qty;
$current_qty = array('Current_stock' => $currentav_qty);
$this->inwardgateregister_model->addmaterialmaster($current_qty, $MaterialCode);
$Recqty = $this->inwardgateregister_model->getPOLineItemReceivedQty($PONO, $MaterialCode);
$ReceivedQuantity = 0.00;
if (count($Recqty) > 0) {
foreach ($Recqty as $key) {
$ReceivedQuantity = $key->ReceivedQuantity;
}
}
$totalReceivedqty = $ReceivedQuantity + $QuantityAsPerInvoice;
$POLineItem = array('ReceivedQuantity' => $totalReceivedqty, 'Status' => $ItemStatus, 'UpdateBY' => $CreatedBy, 'UpdatedOn' => $createddt);
$this->inwardgateregister_model->UpdatePOLineItem($POLineItem, $PONO, $MaterialCode);
}
}
$this->inwardgateregister_model->UpdatePOMaster($PONO, $CreatedBy);
#Step 6 Updating Pending Quantity IN PO Master amd Line Item Details.
if ($TotalPendingQty == 0.00) {
$Newstatus = array('Status' => $IGRStatus);
$this->inwardgateregister_model->POLineItemsupdatestatus($PONO, $Newstatus);
$this->inwardgateregister_model->pomasterupdatestatus($PONO, $Newstatus);
} else {
/*echo 'error' ;*/
}
#finally
$finalstatement = "Successfully Created IGR Number: $IGRNO \n";
if ($fileupdated_count > 0) {
$finalstatement .= "Number of files updated: $fileupdated_count \n";
$finalstatement .= "Files: \n " . implode('\n ', $fileupdated_name);
} else {
$finalstatement .= "No files to update";
}
} else {
$finalstatement = 'No data available to process IGR.';
}
// Escape newlines and quotes for the JavaScript alert
$finalstatement = json_encode($finalstatement);
echo "<script>
alert('$finalstatement');
window.location.href = 'ViewIGR';
</script>";
}
function viewIGRDetails()
{
$IGRNO = $this->request->getPost('id');
$data = $this->inwardgateregister_model->viewigr($IGRNO);
// echo $IGRNO;
// print_r($data);die;
echo json_encode($data);
}
function ViewIGRfile()
{
$IGRNO = $this->request->getPost('id');
$igrfile = $this->inwardgateregister_model->viewIGRFile($IGRNO);
$billfile = $this->inwardgateregister_model->ViewIGRfile1($IGRNO);
$data = array_merge($igrfile, $billfile);
echo json_encode($data);
}
function ViewIGRHistory()
{
$IGRNO = $this->request->getPost('igr');
$result = $this->inwardgateregister_model->ViewIGRHistory($IGRNO);
return $this->response->setJSON($result);
}
function UpdateIGR()
{
$IGRNo = $this->request->getPost('igr');
$DeliveryChellan = $this->request->getPost('invdate');
$DeliveryChellanDate = get_date_time_format($DeliveryChellan);
$Mat_Rcvd_Dt = $this->request->getPost('mrc');
$MaterialRcvdDt = get_date_time_format($Mat_Rcvd_Dt);
$VehicleNo = $this->request->getPost('vehicle_no');
$DriverName = $this->request->getPost('driver');
$DriverMobileNumber = $this->request->getPost('driver_mobile');
$IGRStatus = (int)$this->request->getPost('status') == 1 ? IGR_CREATED : IGR_DRAFT;
$tableData = $this->request->getPost('tableData');
$updateby = $this->session->get('userId');
$igrarr = array('DeliveryChellanDate' => $DeliveryChellanDate, 'MaterialRcvdDate' => $MaterialRcvdDt,'VehicleNo'=>$VehicleNo,'DriverMobileNumber'=>$DriverMobileNumber,'DriverName'=>$DriverName, 'IGRStatus' => $IGRStatus,'UpdateBY' => $updateby);
log_message('error', 'UpdateIGR igrarr: ' . json_encode($igrarr));
$updateigrmaster = $this->inwardgateregister_model->updateigr($igrarr, $IGRNo);
if(!empty($tableData )){
if($VehicleNo){
$vecno = $this->inwardgateregister_model->get_igr_history('VehicleNo',$IGRNo);
if(!empty($vecno)){
$old_data = NULL;
foreach ($vecno as $row) {
if ($row->field == 'VehicleNo') {
$old_data = $row->new_data;
}
}
$igr_history = array('field' => 'VehicleNo','new_data' => $VehicleNo,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
} else{$igr_history = array('field' => 'VehicleNo','is_edit' => 1,'new_data' => $VehicleNo,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}}
if($DriverName){
$drname = $this->inwardgateregister_model->get_igr_history('DriverName',$IGRNo);
if(!empty($drname)){
$old_data = NULL;
foreach ($drname as $row) {
if ($row->field == 'DriverName') {
$old_data = $row->new_data;
}
}
$igr_history = array('field' => 'DriverName','new_data' => $DriverName,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
} else{
$igr_history = array('field' => 'DriverName','is_edit' => 1,'new_data' => $DriverName,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}}
if($DriverMobileNumber){
$drmob = $this->inwardgateregister_model->get_igr_history('DriverMobileNumber',$IGRNo);
if(!empty($drmob)){
$old_data = NULL;
foreach ($drmob as $row) {
if ($row->field == 'GrossWeight') {
$old_data = $row->new_data;
}
}
$igr_history = array('field' => 'DriverMobileNumber','new_data' => $DriverMobileNumber,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
} else{
$igr_history = array('field' => 'DriverMobileNumber','is_edit' => 1,'new_data' => $DriverMobileNumber,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}}
foreach ($tableData as $row) {
$quantityAsPerInvoice = $row['QuantityAsPerInvoice'];
$remarks = $row['Remarks'];
$grossWeight = $row['GrossWeight'];
$grossWeightDate = $row['GrossWeightDate'];
$tareWeight = $row['TareWeight'];
$tareWeightDate = $row['TareWeightDate'];
$netWeight = $row['NetWeight'];
$igrItemNo = $row['IGRItemNo'];
$GrossWtDt = get_date_time_format($grossWeightDate);
$TareWtDt = get_date_time_format($tareWeightDate);
$igrline = array(
'QuantityAsPerInvoice' => $quantityAsPerInvoice,
'Remarks' => $remarks,
'GrossWeight' => $grossWeight,
'GrossWeightDate' => $GrossWtDt,
'TareWeight' => $tareWeight,
'TareWeightDate' => $TareWtDt,
'NetWeight' => $netWeight,
'IGRItemNo' => $igrItemNo,
'UpdateBY' => $updateby
);
$updateigrlineitem = $this->inwardgateregister_model->updateIGRLineItem($igrline, $igrItemNo);
log_message('error', "lineitem updated successfully: " . $updateigrlineitem);
log_message('error', 'UpdateIGR updateigrlineitem: ' . json_encode($igrline));
if($quantityAsPerInvoice){
$qu = $this->inwardgateregister_model->get_igr_history('QuantityAsPerInvoice',$IGRNo,$igrItemNo);
if(!empty($qu)){
$old_data = NULL;
foreach ($qu as $row) {
if ($row->field == 'QuantityAsPerInvoice') {
$old_data = $row->new_data;
}
}
$igr_history = array('field' => 'QuantityAsPerInvoice','new_data' => $quantityAsPerInvoice,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo,'IGRItem_No' => $igrItemNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
} else{
$igr_history = array('field' => 'QuantityAsPerInvoice','is_add' => 1,'new_data' => $quantityAsPerInvoice,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo,'IGRItem_No' => $igrItemNo);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}}
if($remarks){
$remak = $this->inwardgateregister_model->get_igr_history('Remarks',$IGRNo,$igrItemNo);
if(!empty($remak)){
$old_data = NULL;
foreach ($remak as $row) {
if ($row->field == 'Remarks') {
$old_data = $row->new_data;
}
}
$igr_history = array('field' => 'Remarks','new_data' => $remarks,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo,'IGRItem_No' => $igrItemNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
} else{$igr_history = array('field' => 'Remarks','is_add' => 1,'new_data' => $remarks,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo,'IGRItem_No' => $igrItemNo);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}}
if($grossWeight){
$gross = $this->inwardgateregister_model->get_igr_history('GrossWeight',$IGRNo,$igrItemNo);
if(!empty($gross)){
$old_data = NULL;
foreach ($gross as $row) {
if ($row->field == 'GrossWeight') {
$old_data = $row->new_data;
}
}
$igr_history = array('field' => 'GrossWeight','new_data' => $grossWeight,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo,'IGRItem_No'=>$igrItemNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}else{
$igr_history = array('field' => 'GrossWeight','is_add' => 1,'new_data' => $grossWeight,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo,'IGRItem_No'=>$igrItemNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}
}
if($tareWeight){
$tare = $this->inwardgateregister_model->get_igr_history('TareWeight',$IGRNo,$igrItemNo);
if(!empty($tare)){
$old_data = NULL;
foreach ($gross as $row) {
if ($row->field == 'TareWeight') {
$old_data = $row->new_data;
}
}
$igr_history = array('field' => 'TareWeight','new_data' => $tareWeight,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo,'IGRItem_No'=>$igrItemNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}else{
$igr_history = array('field' => 'TareWeight','is_edit' => 1,'new_data' => $tareWeight,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo,'IGRItem_No'=>$igrItemNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}
}
if($netWeight){
$net = $this->inwardgateregister_model->get_igr_history('NetWeight',$IGRNo,$igrItemNo);
if(!empty($net)){
$old_data = NULL;
foreach ($gross as $row) {
if ($row->field == 'NetWeight') {
$old_data = $row->new_data;
}
}
$igr_history = array('field' => 'NetWeight','new_data' => $netWeight,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo,'IGRItem_No'=>$igrItemNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
} else{
$igr_history = array('field' => 'NetWeight','is_edit' => 1,'new_data' => $netWeight,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo,'IGRItem_No'=>$igrItemNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}
}
if($GrossWtDt){
$grossdate = $this->inwardgateregister_model->get_igr_history('GrossWeightDate',$IGRNo,$igrItemNo);
if(!empty($grossdate)){
$old_data = NULL;
foreach ($gross as $row) {
if ($row->field == 'GrossWeightDate') {
$old_data = $row->new_data;
}
}
$igr_history = array('field' => 'GrossWeightDate','new_data' => $GrossWtDt,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo,'IGRItem_No'=>$igrItemNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
} else{
$igr_history = array('field' => 'GrossWeightDate','is_edit' => 1,'new_data' => $GrossWtDt,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo,'IGRItem_No'=>$igrItemNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}
}
if($TareWtDt){
$taredate = $this->inwardgateregister_model->get_igr_history('TareWeightDate',$IGRNo,$igrItemNo);
if(!empty($taredate)){
$old_data = NULL;
foreach ($taredate as $row) {
if ($row->field == 'TareWeightDate') {
$old_data = $row->new_data;
}
}
$igr_history = array('field' => 'TareWeightDate','new_data' => $TareWtDt,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo,'IGRItem_No'=>$igrItemNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
} else{
$igr_history = array('field' => 'TareWeightDate','is_edit' => 1,'new_data' => $TareWtDt,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo,'IGRItem_No'=>$igrItemNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}
}
}
}
if ($updateigrmaster > 0) {
echo "Updated Succefully!";
} else if($updateigrlineitem >0){
echo "Updated Succefully!";
}else{
echo "Not Updated!";
}
}
function updateIGRLineItem() {
$IGRNo = $this->request->getPost('IGRNO');
$Status = $this->request->getPost('IGRStatus');
$DriverName = $this->request->getPost('DriverName');
$DriverMobileNumber = $this->request->getPost('DriverMobileNumber');
$GrossWeight = $this->request->getPost('GrossWeight');
$TareWeight = $this->request->getPost('TareWeight');
$NetWeight = $this->request->getPost('NetWeight');
$VehicleNo = $this->request->getPost('VehicleNo');
$requestdata = $this->request->getPost('data');
$updateby = $this->session->get('userId');
$GrossWeightDate = (string)$this->request->getPost('GrossWeightDate');
$GrossWtDt = get_date_time_format($GrossWeightDate);
$TareWeightDate = (string)$this->request->getPost('TareWeightDate');
$TareWtDt = get_date_time_format($TareWeightDate);
// Check if request data is not null and is a string
if (is_string($requestdata)) {
$lineitemdata = json_decode($requestdata, true); // Decode JSON data
if (is_array($lineitemdata)) {
if($GrossWeight){
$gross = $this->inwardgateregister_model->get_igr_history('GrossWeight',$IGRNo);
if(!empty($gross)){
$old_data = NULL;
foreach ($gross as $row) {
if ($row->field == 'GrossWeight') {
$old_data = $row->new_data;
}
}
$igr_history = array('field' => 'GrossWeight','new_data' => $GrossWeight,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}else{
$igr_history = array('field' => 'GrossWeight','is_add' => 1,'new_data' => $GrossWeight,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}
}
if($TareWeight){
$tare = $this->inwardgateregister_model->get_igr_history('TareWeight',$IGRNo);
if(!empty($tare)){
$old_data = NULL;
foreach ($gross as $row) {
if ($row->field == 'TareWeight') {
$old_data = $row->new_data;
}
}
$igr_history = array('field' => 'TareWeight','new_data' => $TareWeight,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}else{
$igr_history = array('field' => 'TareWeight','is_edit' => 1,'new_data' => $TareWeight,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}
}
if($NetWeight){
$net = $this->inwardgateregister_model->get_igr_history('NetWeight',$IGRNo);
if(!empty($net)){
$old_data = NULL;
foreach ($gross as $row) {
if ($row->field == 'NetWeight') {
$old_data = $row->new_data;
}
}
$igr_history = array('field' => 'NetWeight','new_data' => $NetWeight,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
} else{
$igr_history = array('field' => 'NetWeight','is_edit' => 1,'new_data' => $NetWeight,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}
}
if($GrossWtDt){
$grossdate = $this->inwardgateregister_model->get_igr_history('GrossWeightDate',$IGRNo);
if(!empty($grossdate)){
$old_data = NULL;
foreach ($gross as $row) {
if ($row->field == 'GrossWeightDate') {
$old_data = $row->new_data;
}
}
$igr_history = array('field' => 'GrossWeightDate','new_data' => $GrossWtDt,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
} else{
$igr_history = array('field' => 'GrossWeightDate','is_edit' => 1,'new_data' => $GrossWtDt,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}
}
if($TareWtDt){
$taredate = $this->inwardgateregister_model->get_igr_history('TareWeightDate',$IGRNo);
if(!empty($taredate)){
$old_data = NULL;
foreach ($taredate as $row) {
if ($row->field == 'TareWeightDate') {
$old_data = $row->new_data;
}
}
$igr_history = array('field' => 'TareWeightDate','new_data' => $TareWtDt,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
} else{
$igr_history = array('field' => 'TareWeightDate','is_edit' => 1,'new_data' => $TareWtDt,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}
}
// if($DeliveryChellanOrInvoiceNo){
// $igr_history = array('field' => 'DeliveryChellanOrInvoiceNo','is_edit' => 1,'new_data' => $DeliveryChellanOrInvoiceNo,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNO);
// $history_id = $this->inwardgateregister_model->igr_history($igr_history);
// log_message('error', "History updated successfully. History id: " . $history_id);
// }
// if($DeliveryChellanDate){
// $igr_history = array('field' => 'DeliveryChellanDate','is_edit' => 1,'new_data' => $DeliveryChellanDate,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNO);
// $history_id = $this->inwardgateregister_model->igr_history($igr_history);
// log_message('error', "History updated successfully. History id: " . $history_id);
// }
// if($MaterialRcvdDt){
// $igr_history = array('field' => 'MaterialRcvdDate','is_edit' => 1,'new_data' => $MaterialRcvdDt,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNO);
// $history_id = $this->inwardgateregister_model->igr_history($igr_history);
// log_message('error', "History updated successfully. History id: " . $history_id);
// }
if($VehicleNo){
$vecno = $this->inwardgateregister_model->get_igr_history('VehicleNo',$IGRNo);
if(!empty($vecno)){
$old_data = NULL;
foreach ($vecno as $row) {
if ($row->field == 'VehicleNo') {
$old_data = $row->new_data;
}
}
$igr_history = array('field' => 'VehicleNo','new_data' => $VehicleNo,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
} else{$igr_history = array('field' => 'VehicleNo','is_edit' => 1,'new_data' => $VehicleNo,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}}
if($DriverName){
$drname = $this->inwardgateregister_model->get_igr_history('DriverName',$IGRNo);
if(!empty($drname)){
$old_data = NULL;
foreach ($drname as $row) {
if ($row->field == 'DriverName') {
$old_data = $row->new_data;
}
}
$igr_history = array('field' => 'DriverName','new_data' => $DriverName,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
} else{
$igr_history = array('field' => 'DriverName','is_edit' => 1,'new_data' => $DriverName,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}}
if($DriverMobileNumber){
$drmob = $this->inwardgateregister_model->get_igr_history('DriverMobileNumber',$IGRNo);
if(!empty($drmob)){
$old_data = NULL;
foreach ($drmob as $row) {
if ($row->field == 'GrossWeight') {
$old_data = $row->new_data;
}
}
$igr_history = array('field' => 'DriverMobileNumber','new_data' => $DriverMobileNumber,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
} else{
$igr_history = array('field' => 'DriverMobileNumber','is_edit' => 1,'new_data' => $DriverMobileNumber,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}}
$igrarr = array('VehicleNo' => $VehicleNo, 'DriverName' => $DriverName, 'DriverMobileNumber' => $DriverMobileNumber,'IGRStatus' => $Status, 'UpdateBY' => $updateby,'GrossWeight'=>$GrossWeight,'TareWeight'=>$TareWeight,'NetWeight'=>$NetWeight,'GrossWeightDate'=>$GrossWtDt,'TareWeightDate'=>$TareWtDt);
$masterdata = $this->inwardgateregister_model->updateigr($igrarr, $IGRNo);
$dummy = 0;
$i=1;
foreach ($lineitemdata as $item) {
$IGRNO = $item['IGRNO'.$i];
$IGRItemNo = $item['IGRItemNo'.$i];
$MaterialCode = $item['MaterialCode'.$i];
$QuantityAsPerInvoice = $item['txtQuantityAsPerInvoice'.$i];
$Remarks = $item['txtRemarks'.$i];
$igrline = array(
'IGRNO' => $IGRNO,
'MaterialCode' => $MaterialCode,
'IGRItemNo' => $IGRItemNo,
'QuantityAsPerInvoice' => $QuantityAsPerInvoice,
'Remarks' => $Remarks,
'UpdateBY' => $updateby
);
// print_r($igrline);
$lineitemdata = $this->inwardgateregister_model->updateIGRLineItem($igrline, $IGRItemNo);
if($QuantityAsPerInvoice){
$qu = $this->inwardgateregister_model->get_igr_history('QuantityAsPerInvoice',$IGRNo,$IGRItemNo);
if(!empty($qu)){
$old_data = NULL;
foreach ($qu as $row) {
if ($row->field == 'QuantityAsPerInvoice') {
$old_data = $row->new_data;
}
}
$igr_history = array('field' => 'QuantityAsPerInvoice','new_data' => $QuantityAsPerInvoice,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo,'IGRItem_No' => $IGRItemNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
} else{
$igr_history = array('field' => 'QuantityAsPerInvoice','is_add' => 1,'new_data' => $QuantityAsPerInvoice,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo,'IGRItem_No' => $IGRItemNo);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}}
if($Remarks){
$remak = $this->inwardgateregister_model->get_igr_history('Remarks',$IGRNo,$IGRItemNo);
if(!empty($remak)){
$old_data = NULL;
foreach ($remak as $row) {
if ($row->field == 'Remarks') {
$old_data = $row->new_data;
}
}
$igr_history = array('field' => 'Remarks','new_data' => $Remarks,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo,'IGRItem_No' => $IGRItemNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
} else{$igr_history = array('field' => 'Remarks','is_add' => 1,'new_data' => $Remarks,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNo,'IGRItem_No' => $IGRItemNo);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}}
$i++;
if ($lineitemdata > 0) {
$dummy++;
}
}
if ($dummy > 0) {
echo json_encode(array('message' => 'Updated Successfully!'));
} else {
echo json_encode(array('message' => 'Not Updated!'));
}
} else {
echo json_encode(array('message' => 'Invalid data format!'));
}
} else {
echo json_encode(array('message' => 'Invalid request data!'));
}
}
function updateIGRWeight(){
$GrossWeight = $this->request->getPost('GrossWeight');
$GrossWeightDate = $this->request->getPost('GrossWeightDate');
$TareWeight = $this->request->getPost('TareWeight');
$TareWeightDate = $this->request->getPost('TareWeightDate');
$NetWeight = $this->request->getPost('NetWeight');
$IGRNO = $this->request->getPost('IGR');
$IGRItemNo = $this->request->getPost('IGRlineitem');
$updateby = $this->session->get('userId');
if($GrossWeight){
$gross = $this->inwardgateregister_model->get_igr_history('GrossWeight',$IGRNO, $IGRItemNo);
if(!empty($gross)){
$old_data = NULL;
foreach ($gross as $row) {
if ($row->field == 'GrossWeight') {
$old_data = $row->new_data;
}
}
$igr_history = array('field' => 'GrossWeight','new_data' => $GrossWeight,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNO,'IGRItem_No'=>$IGRItemNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}else{
$igr_history = array('field' => 'GrossWeight','is_add' => 1,'new_data' => $GrossWeight,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNO,'IGRItem_No'=>$IGRItemNo);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}
}
if($TareWeight){
$tare = $this->inwardgateregister_model->get_igr_history('TareWeight',$IGRNO, $IGRItemNo);
if(!empty($tare)){
$old_data = NULL;
foreach ($gross as $row) {
if ($row->field == 'TareWeight') {
$old_data = $row->new_data;
}
}
$igr_history = array('field' => 'TareWeight','new_data' => $TareWeight,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNO,'IGRItem_No'=>$IGRItemNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}else{
$igr_history = array('field' => 'TareWeight','is_edit' => 1,'new_data' => $TareWeight,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNO,'IGRItem_No'=>$IGRItemNo);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}
}
if($NetWeight){
$net = $this->inwardgateregister_model->get_igr_history('NetWeight',$IGRNO, $IGRItemNo);
if(!empty($net)){
$old_data = NULL;
foreach ($gross as $row) {
if ($row->field == 'NetWeight') {
$old_data = $row->new_data;
}
}
$igr_history = array('field' => 'NetWeight','new_data' => $NetWeight,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNO,'IGRItem_No'=>$IGRItemNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
} else{
$igr_history = array('field' => 'NetWeight','is_edit' => 1,'new_data' => $NetWeight,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNO,'IGRItem_No'=>$IGRItemNo);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}
}
if($GrossWeightDate){
$grossdate = $this->inwardgateregister_model->get_igr_history('GrossWeightDate',$IGRNO, $IGRItemNo);
if(!empty($grossdate)){
$old_data = NULL;
foreach ($gross as $row) {
if ($row->field == 'GrossWeightDate') {
$old_data = $row->new_data;
}
}
$igr_history = array('field' => 'GrossWeightDate','new_data' => $GrossWeightDate,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNO,'IGRItem_No'=>$IGRItemNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
} else{
$igr_history = array('field' => 'GrossWeightDate','is_edit' => 1,'new_data' => $GrossWeightDate,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNO,'IGRItem_No'=>$IGRItemNo);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}
}
if($TareWeightDate){
$taredate = $this->inwardgateregister_model->get_igr_history('TareWeightDate',$IGRNO, $IGRItemNo);
if(!empty($taredate)){
$old_data = NULL;
foreach ($taredate as $row) {
if ($row->field == 'TareWeightDate') {
$old_data = $row->new_data;
}
}
$igr_history = array('field' => 'TareWeightDate','new_data' => $TareWeightDate,'old_data' => $old_data,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNO,'IGRItem_No'=>$IGRItemNo);
($old_data != NULL) ? $igr_history['is_edit'] = 1 : $igr_history['is_add'] = 1 ;
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
} else{
$igr_history = array('field' => 'TareWeightDate','is_edit' => 1,'new_data' => $TareWeightDate,'old_data' => NULL,'history_dated' => get_current_date_time(),'by' => $this->session->get('userId'),'IGR_No' => $IGRNO,'IGRItem_No'=>$IGRItemNo);
$history_id = $this->inwardgateregister_model->igr_history($igr_history);
log_message('error', "History updated successfully. History id: " . $history_id);
}
}
$IGRItemNo = $this->request->getPost('IGRlineitem');
$igr_lineitem = array('GrossWeight' => $GrossWeight,'GrossWeightDate' => $GrossWeightDate,'TareWeightDate' => $TareWeightDate,'TareWeight' => $TareWeight,'NetWeight' => $NetWeight,'UpdateBY' => $updateby);
$update = $this->inwardgateregister_model->updateIGRLineItem($igr_lineitem, $IGRItemNo);
if ($update) {
echo "Details update successfully!";
}
}
function AddOgr()
{
//echo "string";
$type = $this->request->getPost('type');
$Supplier = $this->request->getPost('sup');
$Date = $this->request->getPost('Date');
$vehicle = $this->request->getPost('Vehicle');
$driver = $this->request->getPost('drive');
if ($type == 1) {
$invoice = $this->request->getPost('invno');
$Otype = 'Invoice';
$Status = 'ST063';
$ogrmaster = array(
'OgrType' => $Otype, 'CreatedDate' => $Date, 'Driver' => $driver, 'PONO_INV' => $invoice, 'VehicleNo' => $vehicle, 'Status' => $Status
);
$addogrmaster = $this->inwardgateregister_model->AddOGR($ogrmaster);
$OGRNO = '';
if (count($addogrmaster) > 0) {
foreach ($addogrmaster as $add) {
$OGRNO = $add->OGRNO;
}
}
$itemcode = $this->request->getPost('itemcode');
$Description = $this->request->getPost('Description');
$invoutwardqty = $this->request->getPost('invoutwardqty');
$Ogrline = array('OGRNO' => $OGRNO, 'MaterialCode' => $itemcode, 'OutwardQty' => $invoutwardqty, 'Status' => $Status);
$addOgrline = $this->inwardgateregister_model->AddOgrLine($Ogrline);
if ((count($addogrmaster) > 0) && ($addOgrline > 0)) {
echo "Saved Successfully OGR No is OGR" . $OGRNO;
}
} else if ($type == 2) {
$pono = $this->request->getPost('pono');
$MRIRNO = $this->request->getPost('mrirno');
$Otype = 'PO';
$row = $this->request->getPost('rowcount');
$ogrmaster = array(
'OgrType' => $Otype, 'CreatedDate' => $Date, 'Driver' => $driver, 'PONO_INV' => $pono, 'VehicleNo' => $vehicle, 'MRIRNO' => $MRIRNO
);
$addogrmaster = $this->inwardgateregister_model->AddOGR($ogrmaster);
$OGRNO = '';
if (count($addogrmaster) > 0) {
foreach ($addogrmaster as $add) {
$OGRNO = $add->OGRNO;
}
}
for ($i = 1; $i <= $row; $i++) {
$MaterialCode = $this->request->getPost('materialcode' . $i);
$OutwardQty = $this->request->getPost('outward' . $i);
$rejqty = $this->request->getPost('RejectedQty' . $i);
$pendingoutward = $this->request->getPost('pendingoutward' . $i);
$balance_Qty = $rejqty - $OutwardQty;
//$balance_Qty = $this->request->getPost('pendingoutward'.$i);
$Outwardtotal = $OutwardQty;
$allowed = $this->request->getPost('allowed' . $i);
if ($MaterialCode != '' && $OutwardQty != '') {
$polqty = $this->inwardgateregister_model->getPOLineItemReceivedQty($pono, $MaterialCode);
$ReceivedQuantity = 0.00;
if (count($polqty) > 0) {
foreach ($polqty as $key) {
$ReceivedQuantity = $key->ReceivedQuantity;
}
}
$totalReceivedqty = $ReceivedQuantity - $Outwardtotal;
$POMStatus = OGR_CREATED;
$POLineItem = array('ReceivedQuantity' => $totalReceivedqty, 'OGR_Status' => $POMStatus);
$this->inwardgateregister_model->UpdatePOLineItem($POLineItem, $pono, $MaterialCode);
if ($pendingoutward == 0) {
$Status = OGR_COMPLETE;
} else {
$Status = OGR_PARTIAL_COMPLETE;
}
$Ogrline = array('OGRNO' => $OGRNO, 'MaterialCode' => $MaterialCode, 'OutwardQty' => $Outwardtotal, 'Status' => $Status, 'balance_Qty' => $balance_Qty);
$addOgrline = $this->inwardgateregister_model->AddOgrLine($Ogrline);
//print_r($addOgrline);
$ogrlineno = '';
$itemvalue = '';
$SupplierId = '';
$CreatedBy = $this->session->get('userId');
$createddt = get_current_date_time();
if (count($addogrmaster) > 0) {
$ogrlinearray = $this->inwardgateregister_model->getlastogrline();
foreach ($ogrlinearray as $og) {
$ogrlineno = $og->OGRItemNO;
}
$polineitemvalue = $this->inwardgateregister_model->getitemvalue($pono, $MaterialCode);
foreach ($polineitemvalue as $it) {
$itemvalue = $it->Rate;
$SupplierId = $it->SupplierID;
}
}
$historydetails = array('MaterialCode' => $MaterialCode, 'Transaction_type' => "Reduce", 'Ref_Type' => "OGR", 'Ref_No' => $ogrlineno, 'Quantity' => $Outwardtotal, 'CreatedBy' => $CreatedBy, 'CreatedOn' => $createddt, 'ItemValue' => $itemvalue, 'SupplierID' => $SupplierId);
$this->inwardgateregister_model->addmaterialhistory($historydetails);
$get_pre_qty = $this->inwardgateregister_model->get_CurrentQty($MaterialCode);
$av_qty = 0;
if (!empty($get_pre_qty)) {
foreach ($get_pre_qty as $gt) {
$av_qty = $gt->Current_stock;
}
}
$currentav_qty = $av_qty - $Outwardtotal;
$current_qty = array('Current_stock' => $currentav_qty);
$this->inwardgateregister_model->addmaterialmaster($current_qty, $MaterialCode);
$this->inwardgateregister_model->UpdateOGRMasterOGRStatus($OGRNO);
$this->inwardgateregister_model->UpdateMRIRMasterOGRStatus($MRIRNO, $OGRNO);
$mrirout = $this->inwardgateregister_model->GetMRIROutQty($MRIRNO, $MaterialCode);
$premrirout = 0;
if (!empty($mrirout)) {
foreach ($mrirout as $mr) {
$premrirout = $mr->Ogr_Out_Qty;
}
}
$totmrirout = $premrirout + $Outwardtotal;
$mrirarray = array('Ogr_Out_Qty' => $totmrirout);
$this->inwardgateregister_model->UpdateMRIROUTQty($mrirarray, $MRIRNO, $MaterialCode);
$POMasterStatus = array('Status' => PO_RELEASED);
$this->inwardgateregister_model->UpdatePOMasterOGRStatus($pono, $POMasterStatus);
}
}
if ((count($addogrmaster) > 0) && (count($addOgrline) > 0)) {
echo "Saved Successfully OGR No is OGR" . $OGRNO;
}
} else if ($type == 3) {
$Otype = 'SERVICE';
$Status = 'ST063';
$ogrmaster = array('OgrType' => $Otype, 'CreatedDate' => $Date, 'Driver' => $driver, 'VehicleNo' => $vehicle, 'Status' => $Status);
$addogrmaster = $this->inwardgateregister_model->AddOGR($ogrmaster);
//print_r($addogrmaster);
$OGRNO = '';
//echo count($addogrmaster);
if (count($addogrmaster) > 0) {
foreach ($addogrmaster as $add) {
$OGRNO = $add->OGRNO;
}
}
$material = $this->request->getPost('material');
$name = $this->request->getPost('name');
$pooutward = $this->request->getPost('pooutward');
$destination = $this->request->getPost('destination');
$Remarks = $this->request->getPost('Remark');
$Ogrline = array('OGRNO' => $OGRNO, 'MaterialCode' => $material, 'OutwardQty' => $pooutward, 'Destination' => $destination, 'Status' => $Status, 'SupplierID' => $name, 'Remark' => $Remarks);
//print_r($Ogrline);
//die();
$addOgrline = $this->inwardgateregister_model->AddOgrLine($Ogrline);
if ((count($addogrmaster) > 0) && ($addOgrline > 0)) {
echo "Saved Successfully OGR No is OGR" . $OGRNO;
}
}
}
}