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)); $data['driverlist'] = $this->inwardgateregister_model->getdriverlist(); $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_dynamical_format('d-m-Y','',$DeliveryChellan); $Mat_Rcvd_Dt = (string)$this->request->getPost('MaterialRcvdDate'); $MaterialRcvdDt = get_date_time_dynamical_format('d-m-Y','',$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'); $MasterRemarks = $this->request->getPost('MasterRemarks'); $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, 'Remark'=>$MasterRemarks); $igr['MasterFile'] = $requestMasterFileName; #Step 4 Calling DB to Save IGR Master $IGRNO = $this->inwardgateregister_model->addigrM($igr); 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){ $hist = array('key' => 'VehicleNo', 'value' => $VehicleNo, 'igr_no' => $IGRNO, 'igr_item_no' => NULL); $this->saveIGRHistory($hist); } if($DriverName){ $hist = array('key' => 'DriverName', 'value' => $DriverName, 'igr_no' => $IGRNO, 'igr_item_no' => NULL); $this->saveIGRHistory($hist); } if($DriverMobileNumber){ $hist = array('key' => 'DriverMobileNumber', 'value' => $DriverMobileNumber, 'igr_no' => $IGRNO, 'igr_item_no' => NULL); $this->saveIGRHistory($hist); } #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){ $hist = array('key' => 'GrossWeight', 'value' => $GrossWeight, 'igr_no' => $IGRNO, 'igr_item_no' => $igrlineno); $this->saveIGRHistory($hist); } if($TareWeight){ $hist = array('key' => 'TareWeight', 'value' => $TareWeight, 'igr_no' => $IGRNO, 'igr_item_no' => $igrlineno); $this->saveIGRHistory($hist); } if($NetWeight){ $hist = array('key' => 'NetWeight', 'value' => $NetWeight, 'igr_no' => $IGRNO, 'igr_item_no' => $igrlineno); $this->saveIGRHistory($hist); } if($GrossWeightDate){ $hist = array('key' => 'GrossWeightDate', 'value' => $GrossWeightDate, 'igr_no' => $IGRNO, 'igr_item_no' => $igrlineno); $this->saveIGRHistory($hist); } if($TareWeightDate){ $hist = array('key' => 'TareWeightDate', 'value' => $TareWeightDate, 'igr_no' => $IGRNO, 'igr_item_no' => $igrlineno); $this->saveIGRHistory($hist); } if($QuantityAsPerInvoice){ $hist = array('key' => 'QuantityAsPerInvoice', 'value' => $QuantityAsPerInvoice, 'igr_no' => $IGRNO, 'igr_item_no' => $igrlineno); $this->saveIGRHistory($hist); } if($Remarks){ $hist = array('key' => 'Remarks', 'value' => $Remarks, 'igr_no' => $IGRNO, 'igr_item_no' => $igrlineno); $this->saveIGRHistory($hist); } $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 ""; } 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); $TaxInPercentage = 0; for ($i = 0; $i < count($data['details']); $i++) { $details = $data['details'][$i]; if ($details->POType == 'IMPORT') { $TaxInPercentage = isset($details->import_igst) ? $details->import_igst : 0; } if ($details->POType == 'CAPITAL' && $details->CapitalRange == 0) { $TaxInPercentage = isset($details->import_igst) ? $details->import_igst : 0; } if ($details->POType == 'CAPITAL' && $details->CapitalRange == 1) { $TaxInPercentage = (isset($details->service_cgst) ? $details->service_cgst : 0) + (isset($details->service_sgst) ? $details->service_sgst : 0) + (isset($details->service_igst) ? $details->service_igst : 0); } if ($details->POType == 'REVENUE') { $TaxInPercentage = (isset($details->revenue_cgst) ? $details->revenue_cgst : 0) + (isset($details->revenue_sgst) ? $details->revenue_sgst : 0) + (isset($details->revenue_igst) ? $details->revenue_igst : 0); } if ($details->POType == 'SERVICE') { $TaxInPercentage = (isset($details->service_cgst) ? $details->service_cgst : 0) + (isset($details->service_sgst) ? $details->service_sgst : 0) + (isset($details->service_igst) ? $details->service_igst : 0); } $data['details'][$i]->TaxInPercentage = $TaxInPercentage; } $data['files'] = $this->inwardgateregister_model->viewIGRFile($IGRNO); 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); } $MasterRemarks = $this->request->getPost('MasterRemarks'); $igrarr = array('DeliveryChellanDate' => $DeliveryChellanDate, 'MaterialRcvdDate' => $MaterialRcvdDt,'VehicleNo'=>$VehicleNo,'TransporterId'=>$TransporterId,'DriverMobileNumber'=>$DriverMobileNumber,'DriverName'=>$DriverName, 'IGRStatus' => $IGRStatus,'UpdateBY' => $updateby,'DeliveryChellanOrInvoiceNo'=>$DeliveryChellanOrInvoiceNo,'Remark'=>$MasterRemarks); $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)); $getigrstatus = $this->inwardgateregister_model->getigrstatus($IGRNo); $getigrstatus = $getigrstatus->IGRStatus; $updateigrmaster = $this->inwardgateregister_model->updateigr($igrarr, $IGRNo); log_message('error', "Master updated successfully: " . $updateigrmaster); if(!empty($tableData )){ if($VehicleNo){ $hist = array('key' => 'VehicleNo', 'value' => $VehicleNo, 'igr_no' => $IGRNo, 'igr_item_no' => NULL); $this->saveIGRHistory($hist); } if($DriverName){ $hist = array('key' => 'DriverName', 'value' => $DriverName, 'igr_no' => $IGRNo, 'igr_item_no' => NULL); $this->saveIGRHistory($hist); } if($DriverMobileNumber){ $hist = array('key' => 'DriverMobileNumber', 'value' => $DriverMobileNumber, 'igr_no' => $IGRNo, 'igr_item_no' => NULL); $this->saveIGRHistory($hist); } 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) { $hist = array('key' => 'QuantityAsPerInvoice', 'value' => $quantityAsPerInvoice, 'igr_no' => $IGRNo, 'igr_item_no' => $igrItemNo); $this->saveIGRHistory($hist); } if($remarks){ $hist = array('key' => 'Remarks', 'value' => $remarks, 'igr_no' => $IGRNo, 'igr_item_no' => $igrItemNo); $this->saveIGRHistory($hist); } if($grossWeight){ $hist = array('key' => 'GrossWeight', 'value' => $grossWeight, 'igr_no' => $IGRNo, 'igr_item_no' => $igrItemNo); $this->saveIGRHistory($hist); } if($tareWeight){ $hist = array('key' => 'TareWeight', 'value' => $tareWeight, 'igr_no' => $IGRNo, 'igr_item_no' => $igrItemNo); $this->saveIGRHistory($hist); } if($netWeight){ $hist = array('key' => 'NetWeight', 'value' => $netWeight, 'igr_no' => $IGRNo, 'igr_item_no' => $igrItemNo); $this->saveIGRHistory($hist); } if($GrossWtDt){ $hist = array('key' => 'GrossWeightDate', 'value' => $GrossWtDt, 'igr_no' => $IGRNo, 'igr_item_no' => $igrItemNo); $this->saveIGRHistory($hist); } if($TareWtDt){ $hist = array('key' => 'TareWeightDate', 'value' => $TareWtDt, 'igr_no' => $IGRNo, 'igr_item_no' => $igrItemNo); $this->saveIGRHistory($hist); } } } if ($getigrstatus == 'ST027' && ($updateigrmaster > 0 || $updateigrlineitem > 0)) { $result_for_email = $this->inwardgateregister_model->getDetailsforEmail($this->session->get('userId')); $result_for_history = $this->inwardgateregister_model->getHistoryDetailsforEmail($IGRNo); // print_r($result_for_email); $notification = new Notification(); $history_content = NULL; $history = $result_for_history; $field_labels = [ "Remarks" => "Remarks", "QuantityAsPerInvoice" => "Received Qty", "GrossWeight" => "Gross Weight", "TareWeight" => "Tare Weight", "NetWeight" => "Net Weight", "GrossWeightDate" => "Gross Weight Date", "TareWeightDate" => "Tare Weight Date", "VehicleNo" => "Vehicle Number", "DriverName" => "Driver Name", "DriverMobileNumber" => "Driver Mobile Number" ]; $history_content = "
The following values have been edited:"; for ($j = 0; $j < count($history); $j++) { $field_name = $history[$j]->field; $readable_field = isset($field_labels[$field_name]) ? $field_labels[$field_name] : $field_name; $history_content .= "
" . $readable_field . ": `" . $history[$j]->old_data . "` was updated to `" . $history[$j]->new_data . "` ."; } for ($i = 0; $i < count($result_for_email['emails']); $i++) { $email_response = $notification->sendEmail([ 'recipient_email' => $result_for_email['emails'][$i]->email, 'subject' => $result_for_email['company'].' - IGR Notification', 'description' => 'IGR Number : '.$IGRNo.' is Edited By '.($result_for_email['full_name'] ?? $this->session->get('name'))." On ".date('d-m-Y H:i A', strtotime(get_current_date_time() . ' +30 seconds')). $history_content, '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); } } // echo "***".$history_content;die; } 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){ $hist = array('key' => 'GrossWeight', 'value' => $GrossWeight, 'igr_no' => $IGRNo, 'igr_item_no' => NULL); $this->saveIGRHistory($hist); } if($TareWeight){ $hist = array('key' => 'TareWeight', 'value' => $TareWeight, 'igr_no' => $IGRNo, 'igr_item_no' => NULL); $this->saveIGRHistory($hist); } if($NetWeight){ $hist = array('key' => 'NetWeight', 'value' => $NetWeight, 'igr_no' => $IGRNo, 'igr_item_no' => NULL); $this->saveIGRHistory($hist); } if($GrossWtDt){ $hist = array('key' => 'GrossWeightDate', 'value' => $GrossWtDt, 'igr_no' => $IGRNo, 'igr_item_no' => NULL); $this->saveIGRHistory($hist); } if($TareWtDt){ $hist = array('key' => 'TareWeightDate', 'value' => $TareWtDt, 'igr_no' => $IGRNo, 'igr_item_no' => NULL); $this->saveIGRHistory($hist); } // 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){ $hist = array('key' => 'VehicleNo', 'value' => $VehicleNo, 'igr_no' => $IGRNo, 'igr_item_no' => NULL); $this->saveIGRHistory($hist); } if($DriverName){ $hist = array('key' => 'DriverName', 'value' => $DriverName, 'igr_no' => $IGRNo, 'igr_item_no' => NULL); $this->saveIGRHistory($hist); } if($DriverMobileNumber){ $hist = array('key' => 'DriverMobileNumber', 'value' => $DriverMobileNumber, 'igr_no' => $IGRNo, 'igr_item_no' => NULL); $this->saveIGRHistory($hist); } $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){ $hist = array('key' => 'QuantityAsPerInvoice', 'value' => $QuantityAsPerInvoice, 'igr_no' => $IGRNo, 'igr_item_no' => $IGRItemNo); $this->saveIGRHistory($hist); } if($Remarks){ $hist = array('key' => 'Remarks', 'value' => $Remarks, 'igr_no' => $IGRNo, 'igr_item_no' => $IGRItemNo); $this->saveIGRHistory($hist); } $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){ $hist = array('key' => 'GrossWeight', 'value' => $GrossWeight, 'igr_no' => $IGRNO, 'igr_item_no' => $IGRItemNo); $this->saveIGRHistory($hist); } if($GrossWeight){ $hist = array('key' => 'TareWeight', 'value' => $TareWeight, 'igr_no' => $IGRNO, 'igr_item_no' => $IGRItemNo); $this->saveIGRHistory($hist); } if($NetWeight){ $hist = array('key' => 'NetWeight', 'value' => $NetWeight, 'igr_no' => $IGRNO, 'igr_item_no' => $IGRItemNo); $this->saveIGRHistory($hist); } if($GrossWtDt){ $hist = array('key' => 'GrossWeightDate', 'value' => $GrossWtDt, 'igr_no' => $IGRNO, 'igr_item_no' => $IGRItemNo); $this->saveIGRHistory($hist); } if($TareWtDt){ $hist = array('key' => 'TareWeightDate', 'value' => $TareWtDt, 'igr_no' => $IGRNO, 'igr_item_no' => $IGRItemNo); $this->saveIGRHistory($hist); } $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 ''; return; } } // Ensure the directory is writable if (!is_writable($rootPath)) { echo ''; 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 ''; 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 ''; $zip->close(); return redirect()->to('/ViewIGR'); } $filesAdded = true; } else { echo ''; 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 ''; 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(); $this->sendRemarkMail($this->request->getPost('igr_no'),$this->request->getPost('remark'),session()->get('EmpID')); echo json_encode($data); } public function sendRemarkMail($IGRNo,$remark,$empCode) { if(session()->get('roleText') == 'System Administrator') // id is 1 { $roleId = 2; } else if(session()->get('roleText') == 'Auditor') // id is 2 { $roleId = 1; } $result_for_email = $this->inwardgateregister_model->getDetailsforEmail($this->session->get('userId'),$roleId); $email = ""; for ($i = 0; $i < count($result_for_email['emails']); $i++) { $email .= $result_for_email['emails'][$i]->email . " , "; } $email = rtrim($email, " ,"); $content = 'A new remark was created by '.$result_for_email['full_name'].' against IGR no '.$IGRNo.',

"'.$remark.'"'; $notification = new Notification(); $notification->sendEmail([ 'recipient_email' => $email, 'subject' => $result_for_email['company'].' - IGR Remark Raised', 'description' => $content, 'company' => $result_for_email['company'], 'from_mail'=> $result_for_email['from_mail'] ]); } public function saveIGRHistory($hist){ $field = $hist['key']; $igr_no = $hist['igr_no']; $igr_item_no = $hist['igr_item_no']; $new_data = $hist['value']; $old_data = NULL; $same = false; // Flag to check if the same data exists log_message('error', "$igr_no Save History function entered."); // Get existing history $existingHist = $this->inwardgateregister_model->get_igr_history($field, $igr_no, $igr_item_no); if (!empty($existingHist)) { foreach ($existingHist as $row) { if ($row->new_data == $new_data) { $same = true; // The same data already exists break; } else { $old_data = $row->new_data; // Keep track of the latest `new_data` } } } if (!$same) { // Insert or update history since data is different $igr_history = array( 'field' => $field, 'new_data' => $new_data, 'old_data' => $old_data, 'history_dated' => get_current_date_time(), 'by' => $this->session->get('userId'), 'IGR_No' => $igr_no, 'IGRItem_No' => $igr_item_no ); if ($old_data !== NULL) { $igr_history['is_edit'] = 1; // Update existing record } else { $igr_history['is_add'] = 1; // Insert new record } $history_id = $this->inwardgateregister_model->igr_history($igr_history); log_message('error', "History updated successfully. History ID: $history_id" ); } else { // echo "No update needed: ".$param['key']." ($value) already exists."; log_message('error', "No update needed: $field ($new_data) already exists."); } } }