/// <summary> Upload csv to UK/CA FTP </summary> public virtual bool UploadFileByFTP(FTP_Config config, string fileName, byte[] data) { FTPHelper helper = new FTPHelper(config); var ftpResult = helper.UploadFileToFTP(data, fileName); return(ftpResult); }
/// <summary> Get Config </summary> public FTP_Config GetConfig() { var configP3PL = P3PLSetup.Select().RowCast <LUM3PLUKSetup>().FirstOrDefault(); FTP_Config config = new FTP_Config() { FtpHost = configP3PL.FtpHost, FtpUser = configP3PL.FtpUser, FtpPass = configP3PL.FtpPass, FtpPort = configP3PL.FtpPort, FtpPath = configP3PL.FtpOutPath }; return(config); }
protected virtual IEnumerable LumGenerate3PLUKFile(PXAdapter adapter) { try { SOShipment soShipment = adapter.Get <SOShipment>()?.FirstOrDefault(); // Get Csv String Builder var result = CombineCSV(soShipment, "P3PL"); // Upload Graph UploadFileMaintenance upload = PXGraph.CreateInstance <UploadFileMaintenance>(); // Create SM.FileInfo var fileName = $"{result.OrderNbr}.csv"; var data = new UTF8Encoding(true).GetBytes(result.csvText.ToString()); FileInfo fi = new FileInfo(fileName, null, data); // Upload file to FTP #region 3PL UK FTP var configYusen = SelectFrom <LUM3PLUKSetup> .View.Select(Base).RowCast <LUM3PLUKSetup>().FirstOrDefault(); FTP_Config config = new FTP_Config() { FtpHost = configYusen.FtpHost, FtpUser = configYusen.FtpUser, FtpPass = configYusen.FtpPass, FtpPort = configYusen.FtpPort, FtpPath = configYusen.FtpPath }; var ftpResult = UploadFileByFTP(config, fileName, data); //var ftpResult = true; if (!ftpResult) { throw new Exception("Ftp Upload Fail!!"); } #endregion // Upload file to Attachment upload.SaveFile(fi); PXNoteAttribute.SetFileNotes(Base.Document.Cache, Base.Document.Current, fi.UID.Value); Base.Document.Current.GetExtension <SOShipmentExt>().UsrSendToWareHouse = true; Base.Document.UpdateCurrent(); Base.Save.Press(); } catch (Exception ex) { PXProcessing.SetError(ex.Message); } return(adapter.Get()); }
protected virtual IEnumerable PrepareImport(PXAdapter adapter) { PXLongOperation.StartOperation(this, () => { try { // Clear Data PXDatabase.Delete <LUMP3PLImportProcess>( new PXDataFieldRestrict <LUMP3PLImportProcess.createdByID>(Accessinfo.UserID)); this.ImportDataList.Cache.Clear(); // Load FTP File FTP_Config config = GetConfig(); FTPHelper helper = new FTPHelper(config); var ftpFileContents = helper.LoadFileStringFromFTP(); foreach (var item in ftpFileContents) { var line = item.Value.Split(';'); var model = this.ImportDataList.Insert((LUMP3PLImportProcess)this.ImportDataList.Cache.CreateInstance()); model.WarehouseOrder = line[0]; model.CustomerOrderRef = line[1]; model.OrderStatus = line[2]; model.UnitsSent = int.Parse(string.IsNullOrEmpty(line[3]) ? "0" : line[3]); model.Carrier = line[4]; model.TrackingNumber = line[5]; model.FreightCost = decimal.Parse(string.IsNullOrEmpty(line[6]) ? "0" : line[6]); model.FreightCurrency = line[7]; model.FtpFileName = item.Key; } this.Actions.PressSave(); } catch (Exception e) { throw new PXOperationCompletedWithErrorException(e.Message, e); } }); return(adapter.Get()); }
protected virtual IEnumerable LumGenerate3PLUKFile(PXAdapter adapter, [PXDate] DateTime?shipDate, [PXInt] int?siteID, [SOOperation.List] string operation) { try { // Create SOShipment Graph var graph = PXGraph.CreateInstance <SOShipmentEntry>(); var soOrder = adapter.Get <SOOrder>().FirstOrDefault(); using (PXTransactionScope sc = new PXTransactionScope()) { // FBM wont create Shipment, only upload file to FTP if (soOrder.OrderType == "FM") { // Combine csv data var result = graph.GetExtension <SOShipmentEntryExt>().CombineCSVForFBM(soOrder, "P3PL"); // Upload Graph UploadFileMaintenance upload = PXGraph.CreateInstance <UploadFileMaintenance>(); // Create SM.FileInfo var fileName = $"{soOrder.OrderNbr}.csv"; var data = new UTF8Encoding(true).GetBytes(result.csvText.ToString()); FileInfo fi = new FileInfo(fileName, null, data); // upload file to FTP #region 3PL UK FTP var configYusen = SelectFrom <LUM3PLUKSetup> .View.Select(Base).RowCast <LUM3PLUKSetup>().FirstOrDefault(); FTP_Config config = new FTP_Config() { FtpHost = configYusen.FtpHost, FtpUser = configYusen.FtpUser, FtpPass = configYusen.FtpPass, FtpPort = configYusen.FtpPort, FtpPath = configYusen.FtpPath }; var ftpResult = graph.GetExtension <SOShipmentEntryExt>().UploadFileByFTP(config, fileName, data); //var ftpResult = true; if (!ftpResult) { throw new Exception("Ftp Upload Fail!!"); } #endregion // upload file to Attachment upload.SaveFile(fi); PXNoteAttribute.SetFileNotes(Base.Document.Cache, Base.Document.Current, fi.UID.Value); Base.Save.Press(); PXProcessing.SetProcessed(); } else { // Create Shipment Base.CreateShipmentIssue(adapter, shipDate, siteID); if (PXProcessing <SOOrder> .GetItemMessage().ErrorLevel != PXErrorLevel.RowInfo) { return(null); } // Find SOShipment var _soOrderShipment = FbqlSelect <SelectFromBase <SOOrderShipment, TypeArrayOf <IFbqlJoin> .Empty> .Where <BqlChainableConditionBase <TypeArrayOf <IBqlBinary> .FilledWith <And <Compare <SOOrderShipment.orderType, Equal <P.AsString> > > > > .And <BqlOperand <SOOrderShipment.orderNbr, IBqlString> .IsEqual <P.AsString> > >, SOOrderShipment> .View.Select(Base, soOrder.OrderType, soOrder.OrderNbr) .RowCast <SOOrderShipment>().FirstOrDefault(); // Create new Adapter var newAdapter = new PXAdapter(graph.Document) { Searches = new Object[] { _soOrderShipment.ShipmentNbr } }; // Generate UK csv file and upload to FTP graph.GetExtension <SOShipmentEntryExt>().lumGenerate3PLUKFile.PressButton(newAdapter); // Remove Hold graph.releaseFromHold.PressButton(newAdapter); } if (PXProcessing <SOOrder> .GetItemMessage().ErrorLevel == PXErrorLevel.RowInfo) { sc.Complete(); } } } catch (Exception ex) { PXProcessing.SetError <SOOrder>(ex.Message); } return(adapter.Get()); }