1877 lines
89 KiB
PHP
Executable File
1877 lines
89 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Controllers;
|
|
|
|
use App\Controllers\BaseController;
|
|
|
|
use CodeIgniter\Validation\Exceptions\ValidationException;
|
|
|
|
use App\Models\Inwardgateregister_model;
|
|
use App\Models\IGRRemarks_model;
|
|
use App\Helpers\Notification;
|
|
use DateTime;
|
|
|
|
use ZipArchive;
|
|
|
|
/**
|
|
* 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 $IGRRemarks_model;
|
|
protected $session;
|
|
protected $logger;
|
|
|
|
/**
|
|
* This is default constructor of the class
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->inwardgateregister_model = new Inwardgateregister_model();
|
|
$this->IGRRemarks_model = new IGRRemarks_model();
|
|
|
|
$this->session = session();
|
|
helper('form'); //$this->load->library('form_validation');
|
|
$this->logger = service('logger'); // Load the logger service
|
|
|
|
$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()
|
|
{
|
|
|
|
if ($this->request->getMethod() === 'GET')
|
|
{
|
|
$toDate = date('Y-m-d');
|
|
$fromDate = date('Y-m-d', strtotime('-90 days', strtotime($toDate)));
|
|
} elseif ($this->request->getMethod() === 'POST') {
|
|
$fromDate = $this->request->getPost('fromDate');
|
|
$toDate = $this->request->getPost('toDate');
|
|
$fromDate = date('Y-m-d', strtotime($fromDate));
|
|
$toDate = date('Y-m-d', strtotime($toDate));
|
|
}
|
|
|
|
|
|
$this->global['pageTitle'] = 'View Inward Gate Register';
|
|
$result = $this->inwardgateregister_model->ViewigrListing($fromDate, $toDate);
|
|
$igrList = $result[0];
|
|
|
|
foreach ($igrList as &$igr) {
|
|
$igrNo = $igr->IGRNO;
|
|
$fileDetails = $this->inwardgateregister_model->getAllIgrFileDetails($igrNo);
|
|
$igr->isIgrFilePresent = false; // Initialize the key
|
|
|
|
foreach ($fileDetails as $file) {
|
|
if (!empty($file->file)) {
|
|
$igr->isIgrFilePresent = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Unset reference to avoid side effects
|
|
unset($igr);
|
|
|
|
$data['IGR'] = $igrList;
|
|
$data['IGRDownload'] = $result[1];
|
|
$data['userRole'] = $this->session->get('role');
|
|
$data['transporter'] = $this->inwardgateregister_model->transporter();
|
|
$data['fromDate'] = date('d-m-Y', strtotime($fromDate));
|
|
$data['toDate'] = date('d-m-Y', strtotime($toDate));
|
|
|
|
$this->loadViews("viewinwardgateregister", $this->global, $data, NULL);
|
|
}
|
|
|
|
|
|
function accountsDashboard(){
|
|
|
|
$toDate = date('Y-m-d');
|
|
$fromDate = date('Y-m-d');
|
|
|
|
|
|
$this->global['pageTitle'] = 'Accounts Dashboard';
|
|
$result = $this->inwardgateregister_model->customViewigrListing($fromDate, $toDate);
|
|
$igrList = $result[0];
|
|
|
|
|
|
foreach ($igrList as &$igr) {
|
|
$igrNo = $igr->IGRNO;
|
|
$fileDetails = $this->inwardgateregister_model->getAllIgrFileDetails($igrNo);
|
|
$igr->isIgrFilePresent = false;
|
|
|
|
foreach ($fileDetails as $file) {
|
|
if (!empty($file->file)) {
|
|
$igr->isIgrFilePresent = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Unset reference to avoid side effects
|
|
unset($igr);
|
|
|
|
$data['IGR'] = $igrList;
|
|
$data['IGRDownload'] = $result[1];
|
|
$data['userRole'] = $this->session->get('role');
|
|
$data['transporter'] = $this->inwardgateregister_model->transporter();
|
|
$data['fromDate'] = date('d-m-Y', strtotime($fromDate));
|
|
$data['toDate'] = date('d-m-Y', strtotime($toDate));
|
|
|
|
$this->loadViews("accountsDashboard" , $this->global, $data, NULL);
|
|
|
|
}
|
|
|
|
function addIGR()
|
|
{
|
|
|
|
$this->inwardgateregister_model = new inwardgateregister_model();
|
|
$this->global['pageTitle'] = 'Add Inward Gate Register';
|
|
|
|
$result = $this->inwardgateregister_model->getpurchaseorder();
|
|
$result1 = $this->inwardgateregister_model->transporter();
|
|
$data['driverlist'] = $this->inwardgateregister_model->getdriverlist();
|
|
$data['transporter'] = array_filter($result1 , function($item) {
|
|
return ($item->isactive == 1);
|
|
});
|
|
|
|
// $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');
|
|
});
|
|
$data['emp_data'] = [];
|
|
// $data['emp_data'] = $this->inwardgateregister_model->getAdditionalIGRFile();
|
|
// dd($data['driverlist']);die;
|
|
|
|
$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,IGR_CREATED);
|
|
$data = $this->inwardgateregister_model->viewpurchaseorder($PO);
|
|
|
|
echo json_encode($data);
|
|
}
|
|
|
|
|
|
|
|
function getAdditionalIGRFile()
|
|
{
|
|
|
|
$lastinsertbillid = 0;
|
|
|
|
|
|
$pono = $this->request->getPost('PONO');
|
|
$igr = $this->request->getPost('igr');
|
|
|
|
$file = $this->request->getFile('file');
|
|
$requestfilename = $file->getName();
|
|
|
|
$files = $this->inwardgateregister_model->getAdditionalIGRFile($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->uploadAdditionalFile($myfiles);
|
|
}
|
|
}
|
|
|
|
if ($lastinsertbillid > 0) {
|
|
echo "File updated Successfully!-".$lastinsertbillid;
|
|
} else {
|
|
echo "File name already Exist";
|
|
}
|
|
}
|
|
|
|
function deleteAdditionalIGRFile(){
|
|
|
|
$deleteAdditionalFile = false;
|
|
$fileid = $this->request->getPost('id');
|
|
$deleteAdditionalFile = $this->inwardgateregister_model->deleteAdditionalFile($fileid);
|
|
return $this->response->setJSON([
|
|
'status' => 'success',
|
|
'message' => 'Operation successful',
|
|
'data' => $deleteAdditionalFile
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
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');
|
|
$IsThisOpenOrderPO = $this->request->getPost('hiddenIsOpenOrder');
|
|
$DeliveryChellanOrInvoiceNo = $this->request->getPost('InvoiceNo');
|
|
$DeliveryChellan = (string)$this->request->getPost('InvoiceDate');
|
|
$DeliveryChellanDate = get_date_time_format_new($DeliveryChellan);
|
|
$Mat_Rcvd_Dt = (string)$this->request->getPost('MaterialRcvdDate');
|
|
$MaterialRcvdDt = get_date_time_format_new($Mat_Rcvd_Dt);
|
|
$VehicleNo = $this->request->getPost('VehicleNo');
|
|
$TransporterId = $this->request->getPost('TransporterId');
|
|
$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
|
|
$PreIGRStatus = (int)$this->request->getPost('hideIGRStatus') == 1 ? IGR_CREATED : IGR_DRAFT;
|
|
$IGRStatus = ((int)$IsThisOpenOrderPO == 1) ? IGR_DRAFT : $PreIGRStatus;
|
|
|
|
$igr = array(); // For IGR Master
|
|
$paymentstatus = NO_PAIDIGR;
|
|
|
|
$fileupdated_count = 0;
|
|
$fileupdated_name = [];
|
|
|
|
#Step 1 File Path Creation
|
|
$path = ROOTPATH.'public/uploads/Igrfiles/';
|
|
if(!is_dir($path)) { mkdir($path, 0777, true); }
|
|
|
|
#Step 2 Master File and Its Details Gathering
|
|
$MasterFile = $this->request->getFile('MasterFile');
|
|
$requestMasterFileName = NULL;
|
|
if (!empty($MasterFile)) {
|
|
$requestMasterFileName = $MasterFile->getName();
|
|
if ($MasterFile && $MasterFile->isValid() && !$MasterFile->hasMoved()) {
|
|
if (!empty($this->inwardgateregister_model->isFileExistsInIGRmaster(filename: $requestMasterFileName))) {
|
|
log_message('error', 'File already exists in the database'.$requestMasterFileName);
|
|
}
|
|
else{
|
|
$MasterFile->move($path, $requestMasterFileName);
|
|
$fileupdated_count++;
|
|
$fileupdated_name[] = $requestMasterFileName;
|
|
}
|
|
}
|
|
}
|
|
#Step 3 Master Details Gathering to Save In DB
|
|
$igr = array('PONO' => $PONO, 'VehicleNo' => $VehicleNo, 'TransporterId'=>$TransporterId,'DeliveryChellanOrInvoiceNo' => $DeliveryChellanOrInvoiceNo, 'DeliveryChellanDate' => $DeliveryChellanDate, 'MaterialRcvdDate' => $MaterialRcvdDt, 'DriverName' => $DriverName, 'DriverMobileNumber' => $DriverMobileNumber,'IGRStatus' => $IGRStatus, 'CreatedBy' => $CreatedBy, 'CreatedDate' => $createddt, 'PaymentStatus' => $paymentstatus);
|
|
$igr['MasterFile'] = $requestMasterFileName;
|
|
#Step 4 Calling DB to Save IGR Master
|
|
$IGRNO = $this->inwardgateregister_model->addigrM($igr);
|
|
// echo "master - no problem";
|
|
// $IGRNO = "IGRNO02767";
|
|
// print_r($this->request->getPost());die;
|
|
if($IGRNO){
|
|
$files = $this->request->getFiles();
|
|
$fileNames = $this->request->getPost('file_name'); // Get user-entered file names
|
|
if(isset($files['emp_file']))
|
|
{
|
|
foreach ($files['emp_file'] as $index => $file) {
|
|
if ($file->isValid() && !$file->hasMoved()) {
|
|
// Move the file to the desired directory
|
|
$finallyfilename = (!empty($fileNames[$index])) ? $fileNames[$index] : $file->getName();
|
|
$newName = $file->getRandomName();
|
|
$file->move($path, $newName);
|
|
// Store the file information in the database
|
|
$additionalFiles = array(
|
|
'Remarks' => $finallyfilename,
|
|
'FilePath' => $newName,
|
|
'IGRNO' => $IGRNO,
|
|
'PONO' => $PONO
|
|
);
|
|
$lastInsertFileId = $this->inwardgateregister_model->uploadAdditionalFile($additionalFiles);
|
|
if ($lastInsertFileId) {
|
|
$fileupdated_count++;
|
|
$fileupdated_name[] = $finallyfilename;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#Step 5 Save Master Detail On History Table
|
|
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 6 Updating OGR Details
|
|
$OGRStatus = $IGRStatus;
|
|
$check_OGRPO = $this->inwardgateregister_model->update_OGR($PONO, $OGRStatus);
|
|
// echo "uuu".(int)$check_OGRPO;
|
|
$IGRItemStatus = REQITEM_NEW;
|
|
$TotalPendingQty = '';
|
|
$TotalPendingQty = (int)$TotalPendingQty;
|
|
#Step 7 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);
|
|
#Step 8 Saving Weight File and Its Details Gathering
|
|
$WeightFile = $this->request->getFile('txtWeightFile' . $i);
|
|
$requestWeightFileName = $WeightFile->getName();
|
|
// echo $i.$requestWeightFileName;die;
|
|
|
|
if (!empty($requestWeightFileName)) {
|
|
if ($WeightFile && $WeightFile->isValid() && !$WeightFile->hasMoved()) {
|
|
// $WeightFile->move($path, $requestWeightFileName);
|
|
if (!empty($this->inwardgateregister_model->isFileExistsInIGRdetails($requestWeightFileName))) {
|
|
log_message('error', 'File already exists in the database'.$requestWeightFileName);
|
|
$requestWeightFileName = NULL;
|
|
}
|
|
else{
|
|
$WeightFile->move($path, $requestWeightFileName);
|
|
$fileupdated_count++;
|
|
$fileupdated_name[] = $requestWeightFileName;
|
|
}
|
|
}else{
|
|
$requestWeightFileName = NULL;
|
|
}
|
|
}else{
|
|
$requestWeightFileName = NULL;
|
|
}
|
|
|
|
$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);
|
|
$Remarks = $this->request->getPost('txtRemarks' . $i);
|
|
$ItemStatus = '';
|
|
if (strlen($QuantityAsPerInvoice) > 0 && $QuantityAsPerInvoice != '0') {
|
|
if ($PendingQty == 0.00) {
|
|
$ItemStatus = $IGRStatus;
|
|
} else {
|
|
$ItemStatus = POLINEITEM_IGRPARTIAL_CREATED;
|
|
}
|
|
}
|
|
else if ((int)$IsThisOpenOrderPO == 1) {
|
|
$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);
|
|
$igrDetails['WeightFile'] = $requestWeightFileName;
|
|
|
|
log_message('error', 'SaveIGR igrDetails result : ' . json_encode($igrDetails));
|
|
$igrlineno = "";
|
|
if (strlen($QuantityAsPerInvoice) > 0 && $QuantityAsPerInvoice != '0' && ((int)$IsThisOpenOrderPO != 1)){
|
|
$igrD = $this->inwardgateregister_model->addigrD($igrDetails);
|
|
$igrlineno = !empty($igrD) ? $igrD : '';
|
|
}else if((int)$IsThisOpenOrderPO == 1){
|
|
$igrD = $this->inwardgateregister_model->addigrD($igrDetails);
|
|
$igrlineno = !empty($igrD) ? $igrD : '';
|
|
}
|
|
if($igrlineno){
|
|
$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; //$av_qty means Avaliable Quantity
|
|
if (!empty($get_pre_qty)) {
|
|
foreach ($get_pre_qty as $gt) {
|
|
$av_qty = $gt->Current_stock;
|
|
}
|
|
}
|
|
$currentav_qty = (int)$QuantityAsPerInvoice + (int)$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 = (int)$IsThisOpenOrderPO == 1 ? 0 : (int)$ReceivedQuantity + (int)$QuantityAsPerInvoice ;
|
|
// $totalReceivedqty = $ReceivedQuantity + $QuantityAsPerInvoice;
|
|
if(((int)$totalReceivedqty > 0) && ((int)$IsThisOpenOrderPO != 1)){
|
|
$POLineItem = array('ReceivedQuantity' => $totalReceivedqty, 'Status' => $ItemStatus, 'UpdateBY' => $CreatedBy, 'UpdatedOn' => $createddt);
|
|
$this->inwardgateregister_model->UpdatePOLineItem($POLineItem, $PONO, $MaterialCode);
|
|
}else if((int)$IsThisOpenOrderPO == 1){
|
|
$POLineItem = array('ReceivedQuantity' => $totalReceivedqty, 'Status' => $ItemStatus, 'UpdateBY' => $CreatedBy, 'UpdatedOn' => $createddt);
|
|
$this->inwardgateregister_model->UpdatePOLineItem($POLineItem, $PONO, $MaterialCode);
|
|
}
|
|
}
|
|
}
|
|
$this->inwardgateregister_model->UpdatePOMaster($PONO, $CreatedBy,$IGRStatus);
|
|
|
|
#Step 9 Updating Pending Quantity IN PO Master amd Line Item Details.
|
|
if ((int)$IsThisOpenOrderPO != 1) {
|
|
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(PHP_EOL, $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 drivernameautocomplete(){
|
|
$dr = $this->request->getGet('query');
|
|
$query = $this->inwardgateregister_model->checkdrivername($dr);
|
|
echo json_encode($query);
|
|
}
|
|
public function drivermobileautocomplete() {
|
|
$dr = $this->request->getGet('query');
|
|
$drName = $this->request->getGet('driverName');
|
|
$query = $this->inwardgateregister_model->checkdriverMobile($dr, $drName);
|
|
echo json_encode($query);
|
|
}
|
|
|
|
|
|
public function drivermobileautocomplete2() {
|
|
$driverName = $this->request->getGet('drivername');
|
|
$term = $this->request->getGet('term');
|
|
|
|
// Debugging
|
|
if (!$driverName || !$term) {
|
|
return $this->response->setJSON(['error' => 'Missing parameters']);
|
|
}
|
|
|
|
$query = $this->inwardgateregister_model->checkdriverMobile($driverName, $term);
|
|
|
|
// Check the output
|
|
if (is_array($query)) {
|
|
return $this->response->setJSON($query);
|
|
} else {
|
|
return $this->response->setJSON(['error' => 'Invalid response from model']);
|
|
}
|
|
}
|
|
|
|
function viewIGRDetails()
|
|
{
|
|
|
|
$IGRNO = $this->request->getPost('id');
|
|
|
|
$data['details'] = $this->inwardgateregister_model->viewigr($IGRNO);
|
|
$data['files'] = $this->inwardgateregister_model->viewIGRFile($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 getCostCenterData()
|
|
{
|
|
$pono = $this->request->getPost('pono');
|
|
$result = $this->inwardgateregister_model->getCostCenterData($pono);
|
|
|
|
return $this->response->setJSON($result);
|
|
}
|
|
|
|
|
|
function UpdateIGR()
|
|
{
|
|
|
|
$IGRNo = $this->request->getPost('igr');
|
|
$PONo = $this->request->getPost('po');
|
|
|
|
$DeliveryChellanOrInvoiceNo = $this->request->getPost('invno');
|
|
$DeliveryChellan = $this->request->getPost('invdate');
|
|
$DeliveryChellanDate = !$DeliveryChellan || $DeliveryChellan === null ? NULL : get_date_time_format($DeliveryChellan);
|
|
|
|
$Mat_Rcvd_Dt = $this->request->getPost('mrc');
|
|
$MaterialRcvdDt = !$Mat_Rcvd_Dt || $Mat_Rcvd_Dt === null ? NULL : get_date_time_format($Mat_Rcvd_Dt);
|
|
|
|
|
|
$VehicleNo = $this->request->getPost('vehicle_no');
|
|
$TransporterId = $this->request->getPost('Transporter_Id');
|
|
$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');
|
|
if (is_string($tableData)) {
|
|
$tableData = json_decode($tableData, true);
|
|
}
|
|
$updateby = $this->session->get('userId');
|
|
|
|
$path = ROOTPATH.'public/uploads/Igrfiles/';
|
|
if(!is_dir($path)) { mkdir($path, 0777, true); }
|
|
|
|
$igrarr = array('DeliveryChellanDate' => $DeliveryChellanDate, 'MaterialRcvdDate' => $MaterialRcvdDt,'VehicleNo'=>$VehicleNo,'TransporterId'=>$TransporterId,'DriverMobileNumber'=>$DriverMobileNumber,'DriverName'=>$DriverName, 'IGRStatus' => $IGRStatus,'UpdateBY' => $updateby,'DeliveryChellanOrInvoiceNo'=>$DeliveryChellanOrInvoiceNo);
|
|
|
|
$MasterFile = $this->request->getfile('MasterFile');
|
|
|
|
if ($MasterFile) {
|
|
$requestMasterFileName = $MasterFile->getName();
|
|
if ($MasterFile && $MasterFile->isValid() && !$MasterFile->hasMoved()) {
|
|
if (!empty($this->inwardgateregister_model->isFileExistsInIGRmaster($requestMasterFileName))) {
|
|
log_message('error', 'File already exists in the database'.$requestMasterFileName);
|
|
}
|
|
else{
|
|
$MasterFile->move($path, $requestMasterFileName);
|
|
$igrarr['MasterFile'] = $requestMasterFileName;
|
|
}
|
|
}
|
|
}
|
|
$fileupdated_count = 0;
|
|
$fileupdated_name = [];
|
|
|
|
$fileNames = $this->request->getPost('file_name');
|
|
$files = $this->request->getFileMultiple('emp_file');
|
|
|
|
|
|
if(isset($files))
|
|
{
|
|
foreach ($files as $index => $file) {
|
|
|
|
if ($file->isValid() && !$file->hasMoved()) {
|
|
|
|
// Move the file to the desired directory
|
|
$finallyfilename = (!empty($fileNames[$index])) ? $fileNames[$index] : $file->getName();
|
|
$newName = $file->getRandomName();
|
|
$file->move($path, $newName);
|
|
// Store the file information in the database
|
|
$additionalFiles = array(
|
|
'Remarks' => $finallyfilename,
|
|
'FilePath' => $newName,
|
|
'IGRNO' => $IGRNo,
|
|
'PONO' => $PONo
|
|
);
|
|
$lastInsertFileId = $this->inwardgateregister_model->uploadAdditionalFile($additionalFiles);
|
|
if ($lastInsertFileId) {
|
|
$fileupdated_count++;
|
|
$fileupdated_name[] = $finallyfilename;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
log_message('error', 'UpdateIGR igrarr: ' . json_encode($igrarr));
|
|
$updateigrmaster = $this->inwardgateregister_model->updateigr($igrarr, $IGRNo);
|
|
log_message('error', "Master updated successfully: " . $updateigrmaster);
|
|
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 = !empty($grossWeightDate) && strtolower($grossWeightDate) !== 'null' ? get_date_time_format($grossWeightDate) : NULL;
|
|
$TareWtDt = !empty($tareWeightDate) && strtolower($tareWeightDate) !== 'null' ? get_date_time_format($tareWeightDate) : NULL;
|
|
|
|
$igrline = array(
|
|
'QuantityAsPerInvoice' => $quantityAsPerInvoice,
|
|
'Remarks' => $remarks,
|
|
'GrossWeight' => $grossWeight,
|
|
'GrossWeightDate' => $GrossWtDt,
|
|
'TareWeight' => $tareWeight,
|
|
'TareWeightDate' => $TareWtDt,
|
|
'NetWeight' => $netWeight,
|
|
'IGRItemNo' => $igrItemNo,
|
|
'UpdateBY' => $updateby
|
|
);
|
|
// $WeightFile = $this->request->getfile('WeightFile');
|
|
// $requestWeightFileName = $WeightFile->getName();
|
|
|
|
// if (!empty($requestWeightFileName)) {
|
|
// if ($WeightFile && $WeightFile->isValid() && !$WeightFile->hasMoved()) {
|
|
// if (!empty($this->inwardgateregister_model->isFileExistsInIGRdetails($requestWeightFileName))) {
|
|
// log_message('error', 'File already exists in the database'.$requestWeightFileName);
|
|
// }
|
|
// else{
|
|
// $WeightFile->move($path, $requestWeightFileName);
|
|
// $igrline['WeightFile'] = $requestWeightFileName;
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
$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);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
$result_for_email = $this->inwardgateregister_model->getDetailsforEmail($this->session->get('userId'));
|
|
|
|
|
|
|
|
if ($updateigrmaster > 0 || $updateigrlineitem > 0) {
|
|
if ($IGRStatus == IGR_CREATED || $IGRStatus == MRIR_CREATED || $IGRStatus == MRIR_APPROVED ) {
|
|
|
|
$result_for_email = $this->inwardgateregister_model->getDetailsforEmail($this->session->get('userId'));
|
|
$notification = new Notification();
|
|
|
|
for ($i = 0; $i < count($result_for_email['emails']); $i++) {
|
|
$email_response = $notification->sendEmail([
|
|
'recipient_email' => $result_for_email['emails'][$i]->email,
|
|
'subject' => 'Resico Industries - IGR Notification',
|
|
'description' => 'IGR Number : '.$IGRNo.' is Edited By '.($result_for_email['full_name'] ?? $this->session->get('name')),
|
|
'company' => $result_for_email['company'],
|
|
'from_mail'=> $result_for_email['from_mail']
|
|
]);
|
|
|
|
log_message('error', 'email reponse : ' . json_encode($email_response));
|
|
// Determine the email response
|
|
$mail_log = isset($email_response['success']) ? 'Email sent successfully' : 'Failed to send email';
|
|
$receiving_status = isset($email_response['success']) ? 1 : 0;
|
|
|
|
// Log the result
|
|
if ($receiving_status) {
|
|
$this->logger->info("Email ID = " . $result_for_email['emails'][$i]->email . " " . $mail_log);
|
|
} else {
|
|
$this->logger->error("Email ID = " . $result_for_email['emails'][$i]->email . " " . $mail_log);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
if ($updateigrmaster > 0) {
|
|
$finalstatement = "Successfully Updated IGR Number: $IGRNo \n";
|
|
} else if($updateigrlineitem >0){
|
|
$finalstatement = "Successfully Updated IGR Number: $IGRNo \n";
|
|
}else{
|
|
$finalstatement = "IGR Number: $IGRNo \n";
|
|
}
|
|
|
|
if ($fileupdated_count > 0) {
|
|
$finalstatement .= "Number of files updated: $fileupdated_count \n";
|
|
$finalstatement .= "Files: \n" . implode(PHP_EOL, $fileupdated_name);
|
|
} else {
|
|
$finalstatement .= "No files to update";
|
|
}
|
|
|
|
echo $finalstatement;
|
|
}
|
|
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 = !empty($GrossWeightDate) ? get_date_time_format($GrossWeightDate) : NULL;
|
|
|
|
$TareWeightDate = (string)$this->request->getPost('TareWeightDate');
|
|
$TareWtDt = !empty($TareWeightDate) ? get_date_time_format($TareWeightDate) : NULL;
|
|
|
|
|
|
|
|
// 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');
|
|
$WeightFile = $this->request->getfile('WeightFile');
|
|
$GrossWtDt = (!empty($GrossWeightDate) && (string)$GrossWeightDate != 'null' ) ? get_date_time_format($GrossWeightDate) : null;
|
|
$TareWtDt =(!empty($TareWeightDate) && (string)$TareWeightDate != 'null') ? get_date_time_format($TareWeightDate) : null;
|
|
|
|
|
|
$path = ROOTPATH.'public/uploads/Igrfiles/';
|
|
if(!is_dir($path)) { mkdir($path, 0777, true); }
|
|
|
|
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($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 ;
|
|
$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);
|
|
$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 ;
|
|
$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);
|
|
$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' => $GrossWtDt,'TareWeightDate' => $TareWtDt,'TareWeight' => $TareWeight,'NetWeight' => $NetWeight,'UpdateBY' => $updateby);
|
|
$requestWeightFileName =null ;
|
|
if($WeightFile){
|
|
if (!empty($requestWeightFileName)) {
|
|
if ($WeightFile && $WeightFile->isValid() && !$WeightFile->hasMoved()) {
|
|
if (!empty($this->inwardgateregister_model->isFileExistsInIGRdetails($requestWeightFileName))) {
|
|
log_message('error', 'File already exists in the database'.$requestWeightFileName);
|
|
}
|
|
else{
|
|
$WeightFile->move($path, $requestWeightFileName);
|
|
$igr_lineitem['WeightFile'] = $requestWeightFileName;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$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;
|
|
}
|
|
}
|
|
}
|
|
|
|
public function downloadFilesAsZip($igrno)
|
|
{
|
|
// Get all file details for the given IGR number
|
|
$fileDetails = $this->inwardgateregister_model->getAllIgrFileDetails($igrno);
|
|
|
|
// Define the root path for files
|
|
$rootPath = ROOTPATH . 'public/uploads/Igrfiles/';
|
|
|
|
// Check if the directory exists, create if it doesn't
|
|
if (!is_dir($rootPath)) {
|
|
if (!mkdir($rootPath, 0755, true)) {
|
|
echo '<script>alert("Failed to create the directory.");</script>';
|
|
return;
|
|
}
|
|
}
|
|
|
|
// Ensure the directory is writable
|
|
if (!is_writable($rootPath)) {
|
|
echo '<script>alert("Directory is not writable.");</script>';
|
|
return;
|
|
}
|
|
|
|
// Create a new ZIP archive
|
|
$zip = new ZipArchive();
|
|
$zipFileName = $igrno . '.zip';
|
|
$zipFilePath = $rootPath . $zipFileName;
|
|
|
|
// Attempt to open the ZIP file
|
|
if ($zip->open($zipFilePath, ZipArchive::CREATE | ZipArchive::OVERWRITE) !== TRUE) {
|
|
echo '<script>alert("Failed to create ZIP file.");</script>';
|
|
return redirect()->to('/ViewIGR');
|
|
}
|
|
|
|
$filesAdded = false;
|
|
|
|
// Add each file to the ZIP archive
|
|
foreach ($fileDetails as $file) {
|
|
$filePath = $rootPath . $file->file;
|
|
|
|
// Ensure file exists and is not a directory
|
|
if (file_exists($filePath) && is_file($filePath)) {
|
|
// Sanitize filename for ZIP
|
|
$sanitizedFilename = preg_replace('/[^a-zA-Z0-9_\-\.]/', '_', $file->file);
|
|
if (!$zip->addFile($filePath, $sanitizedFilename)) {
|
|
echo '<script>alert("Failed to add file: ' . $file->filename . '");</script>';
|
|
$zip->close();
|
|
return redirect()->to('/ViewIGR');
|
|
}
|
|
$filesAdded = true;
|
|
} else {
|
|
echo '<script> alert("File not found or is a directory: ' . $filePath . '");</script>';
|
|
continue;
|
|
}
|
|
}
|
|
|
|
// Close ZIP archive if files were added
|
|
if ($filesAdded) {
|
|
$zip->close(); // Close ZIP only if files were added
|
|
return $this->response->download($zipFilePath, null)->setFileName($zipFileName);
|
|
} else {
|
|
// Close and remove any empty ZIP file created
|
|
$zip->close();
|
|
if (file_exists($zipFilePath)) {
|
|
unlink($zipFilePath);
|
|
}
|
|
echo '<script>alert("No files were added to the ZIP.");</script>';
|
|
return redirect()->to('/ViewIGR');
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function getIGRRemarks()
|
|
{
|
|
$igrNo = $this->request->getPost('igr_no');
|
|
$data = $this->IGRRemarks_model->select('t_igr_remarkes.remark ,t_igr_remarkes.remark_on , t_employee_details.FirstName as remark_by')
|
|
->join('t_employee_details', 't_igr_remarkes.remark_by = t_employee_details.EmpID', 'left')
|
|
->where('t_igr_remarkes.igr_no', $igrNo)
|
|
->findAll();
|
|
|
|
echo json_encode($data);
|
|
}
|
|
|
|
public function saveIGRRemarks()
|
|
{
|
|
$data['igr_no'] = $this->request->getPost('igr_no');
|
|
$data['remark'] = $this->request->getPost('remark');
|
|
$data['remark_by'] = session()->get('EmpID');
|
|
$data['remark_on'] = date('Y-m-d H:i:s');
|
|
|
|
$insert = $this->IGRRemarks_model->save($data);
|
|
|
|
$data = $this->IGRRemarks_model->select('t_igr_remarkes.remark ,t_igr_remarkes.remark_on , t_employee_details.FirstName as remark_by')
|
|
->join('t_employee_details', 't_igr_remarkes.remark_by = t_employee_details.EmpID', 'left')
|
|
->where('t_igr_remarkes.igr_no', $data['igr_no'])
|
|
->findAll();
|
|
|
|
echo json_encode($data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} |