private void PrepareCertificationData(CarrierPlugin cp) { ICarrierService plugin = CreateCarrierService(this, cp); if (plugin != null) { UploadFileMaintenance upload = PXGraph.CreateInstance <UploadFileMaintenance>(); CarrierResult <IList <CarrierCertificationData> > result = plugin.GetCertificationData(); if (result != null) { StringBuilder sb = new StringBuilder(); foreach (Message message in result.Messages) { sb.AppendFormat("{0}:{1} ", message.Code, message.Description); } if (result.IsSuccess) { CarrierPlugin copy = (CarrierPlugin)Plugin.Cache.CreateCopy(cp); using (System.IO.MemoryStream ms = new System.IO.MemoryStream()) { ZipArchive zip = new ZipArchive(ms, false); foreach (CarrierCertificationData d in result.Result) { using (System.IO.Stream zipStream = zip.OpenWrite(string.Format("{0}.{1}", d.Description, d.Format))) { zipStream.Write(d.File, 0, d.File.Length); } } FileInfo file = new FileInfo("CertificationData.zip", null, ms.ToArray()); upload.SaveFile(file, FileExistsAction.CreateVersion); PXNoteAttribute.SetFileNotes(Plugin.Cache, copy, file.UID.Value); } Plugin.Update(copy); this.Save.Press(); } else { throw new PXException(SO.Messages.CarrierServiceError, sb.ToString()); } } } }
private FileInfo SaveReportFile(StreamManager streamManager, ComplianceDocument complianceDocument, string format) { var projectCd = printEmailLienWaiversProcess.Select <Contract>() .SingleOrDefault(ct => ct.ContractID == complianceDocument.ProjectID)?.ContractCD; var vendorCd = GetVendorCd(complianceDocument); DeleteFileIfNeeded(complianceDocument.NoteID, projectCd, vendorCd); var fileName = GetNameForLienWaiverReport(complianceDocument, format, projectCd, vendorCd); var reportFileInfo = new FileInfo(fileName, null, streamManager.MainStream.GetBytes()); uploadFileMaintenance.SaveFile(reportFileInfo, FileExistsAction.CreateVersion); LinkToLienWaiverIfNeeded(reportFileInfo.UID, complianceDocument.NoteID); return(reportFileInfo); }
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 PrintFedexLabel(PXAdapter adapter) { var shiporder = Base.Document.Current; var carrier = Carrier.PK.Find(Base, shiporder.ShipVia); if (!UseCarrierService(shiporder, carrier)) { return(adapter.Get()); } if (shiporder.ShippedViaCarrier != true) { // Build Fedex Request object ICarrierService cs = CarrierMaint.CreateCarrierService(Base, shiporder.ShipVia); CarrierRequest cr = Base.CarrierRatesExt.BuildRequest(shiporder); var warehouseInfo = SelectFrom <INSite> .Where <INSite.siteID.IsEqual <P.AsInt> > .View .Select(Base, shiporder.SiteID).RowCast <INSite>().FirstOrDefault(); // Replace ShipTo Info to DCL warehouse Address warehouseAddress = PXSelect <Address, Where <Address.addressID, Equal <Required <Address.addressID> > > > .Select(Base, warehouseInfo?.AddressID); Contact warehouseContact = PXSelect <Contact, Where <Contact.contactID, Equal <Required <Contact.contactID> > > > .Select(Base, warehouseInfo?.ContactID); cr.Destination = warehouseAddress; cr.DestinationContact = warehouseContact; if (cr.Packages.Count > 0) { // Get Fedex web service data CarrierResult <ShipResult> result = cs.Ship(cr); if (result != null) { StringBuilder sb = new StringBuilder(); foreach (Message message in result.Messages) { sb.AppendFormat("{0}:{1} ", message.Code, message.Description); } if (result.IsSuccess) { using (PXTransactionScope ts = new PXTransactionScope()) { UploadFileMaintenance upload = PXGraph.CreateInstance <UploadFileMaintenance>(); foreach (PackageData pd in result.Result.Data) { if (pd.Image != null) { string fileName = string.Format("Label #{0}.{1}", pd.TrackingNumber, pd.Format); FileInfo file = new FileInfo(fileName, null, pd.Image); try { upload.SaveFile(file); } catch (PXNotSupportedFileTypeException exc) { throw new PXException(exc, Messages.NotSupportedFileTypeFromCarrier, pd.Format); } PXNoteAttribute.SetFileNotes(Base.Document.Cache, Base.Document.Current, file.UID.Value); } Base.Document.UpdateCurrent(); } Base.Save.Press(); ts.Complete(); } //show warnings: if (result.Messages.Count > 0) { Base.Document.Cache.RaiseExceptionHandling <SOShipment.curyFreightCost>(shiporder, shiporder.CuryFreightCost, new PXSetPropertyException(sb.ToString(), PXErrorLevel.Warning)); } } else { if (!string.IsNullOrEmpty(result.RequestData)) { PXTrace.WriteError(result.RequestData); } Base.Document.Cache.RaiseExceptionHandling <SOShipment.curyFreightCost>(shiporder, shiporder.CuryFreightCost, new PXSetPropertyException(Messages.CarrierServiceError, PXErrorLevel.Error, sb.ToString())); throw new PXException(Messages.CarrierServiceError, sb.ToString()); } } } } return(adapter.Get()); }
public override void Persist() { // Current Data var _currData = (LumItemsCOC)_viewLine.Cache.Current; // Create Upload Image Graph UploadFileMaintenance upload = PXGraph.CreateInstance <UploadFileMaintenance>(); // Html to Image and Upload to Server Action <string, string> htmlToImage = (_html, _fileName) => { HtmlDocument _doc = new HtmlDocument(); _doc.LoadHtml(_html); if (string.IsNullOrEmpty(_doc.DocumentNode.InnerText)) { return; } var htmlNode = _doc.DocumentNode.SelectSingleNode("//html"); HtmlNode newNode = HtmlNode.CreateNode(@"<meta http-equiv=""content-type"" content=""text/html; charset=utf-8"" />"); htmlNode.InsertBefore(newNode, htmlNode.ChildNodes[0]); var htmlToImageConv = new NReco.ImageGenerator.HtmlToImageConverter(); var jpegBytes = htmlToImageConv.GenerateImage(_doc.DocumentNode.OuterHtml, NReco.ImageGenerator.ImageFormat.Jpeg); FileInfo file = new FileInfo($"{_fileName}.jpeg", null, jpegBytes); upload.SaveFile(file, FileExistsAction.CreateVersion); //To Attach file to Entity PXNoteAttribute.SetFileNotes(_viewLine.Cache, _viewLine.Cache.Current, file.UID.Value); }; // Process All Tab #region MaterialProductDesc if (!CheckInnerTextIsEmpty(_currData.MaterialProductDesc)) { htmlToImage(_currData.MaterialProductDesc, $"COC_{_currData.InventoryID}_MaterialProductDesc"); } else { _viewLine.Cache.SetValue <LumItemsCOC.materialProductDesc>(_viewLine.Cache.Current, null); } #endregion #region MaterialProductDesc2 if (!CheckInnerTextIsEmpty(_currData.MaterialProductDesc2)) { htmlToImage(_currData.MaterialProductDesc2, $"COC_{_currData.InventoryID}_MaterialProductDesc2"); } else { _viewLine.Cache.SetValue <LumItemsCOC.materialProductDesc2>(_viewLine.Cache.Current, null); } #endregion ; #region COCProductDesc if (!CheckInnerTextIsEmpty(_currData.COCProductDesc)) { htmlToImage(_currData.COCProductDesc, $"COC_{_currData.InventoryID}_COCProductDesc"); } else { _viewLine.Cache.SetValue <LumItemsCOC.cOCProductDesc>(_viewLine.Cache.Current, null); } #endregion #region TESTProductDesc if (!CheckInnerTextIsEmpty(_currData.TESTProductDesc)) { htmlToImage(_currData.TESTProductDesc, $"COC_{_currData.InventoryID}_TESTProductDesc"); } else { _viewLine.Cache.SetValue <LumItemsCOC.tESTProductDesc>(_viewLine.Cache.Current, null); } #endregion #region REROHSProductDesc if (!CheckInnerTextIsEmpty(_currData.REROHSProductDesc)) { htmlToImage(_currData.REROHSProductDesc, $"COC_{_currData.InventoryID}_REROHSProductDesc"); } else { _viewLine.Cache.SetValue <LumItemsCOC.rEROHSProductDesc>(_viewLine.Cache.Current, null); } #endregion #region REACHProductDesc if (!CheckInnerTextIsEmpty(_currData.REACHProductDesc)) { htmlToImage(_currData.REACHProductDesc, $"COC_{_currData.InventoryID}_REACHProductDesc"); } else { _viewLine.Cache.SetValue <LumItemsCOC.rEACHProductDesc>(_viewLine.Cache.Current, null); } #endregion #region REACHProductDesc2 if (!CheckInnerTextIsEmpty(_currData.REACHProductDesc2)) { htmlToImage(_currData.REACHProductDesc2, $"COC_{_currData.InventoryID}_REACHProductDesc2"); } else { _viewLine.Cache.SetValue <LumItemsCOC.rEACHProductDesc2>(_viewLine.Cache.Current, null); } #endregion #region Compliantproductdesc if (!CheckInnerTextIsEmpty(_currData.Compliantproductdesc)) { htmlToImage(_currData.Compliantproductdesc, $"COC_{_currData.InventoryID}_Compliantproductdesc"); } else { _viewLine.Cache.SetValue <LumItemsCOC.compliantproductdesc>(_viewLine.Cache.Current, null); } #endregion #region QCProductDesc if (!CheckInnerTextIsEmpty(_currData.QCProductDesc)) { htmlToImage(_currData.QCProductDesc, $"COC_{_currData.InventoryID}_QCProductDesc"); } else { _viewLine.Cache.SetValue <LumItemsCOC.qCProductDesc>(_viewLine.Cache.Current, null); } #endregion base.Persist(); }
public void RefreshRecordFileList(string screenID, string folderName, string folderID, Guid?refNoteID, bool isForcingSync) { var tokenHandler = PXGraph.CreateInstance <UserTokenHandler>(); //Get list of files contained in the record folder. RecurseDepth=0 will retrieve all subfolders List <BoxUtils.FileFolderInfo> boxFileList = BoxUtils.GetFileList(tokenHandler, folderID, (int)BoxUtils.RecursiveDepth.Unlimited).Result; // Remove files from cache if they don't exist on Box server foreach (PXResult <BoxFileCache, UploadFileRevisionNoData, UploadFile, NoteDoc> result in FilesByNoteID.Select(refNoteID)) { BoxUtils.FileFolderInfo boxFile = boxFileList.FirstOrDefault(f => f.ID == ((BoxFileCache)result).FileID); if (boxFile == null) { //File was deleted FilesByNoteID.Delete(result); UploadFiles.Delete(result); UploadFileRevisions.Delete(result); NoteDocs.Delete(result); } else { // File still exists, remove it from in-memory list // so we don't process it as a new file in the next loop boxFileList.Remove(boxFile); } } // Remove any files/folders coming from activities stored beneath the current record, they've been processed above var filesFoundOnlyOnServer = boxFileList.Where(x => !x.Name.StartsWith(Messages.ActivitiesFolderName)).ToList(); //Check for underlying activities records BoxFolderCache currentFolder = FoldersByFolderID.Select(folderID); if (currentFolder != null && boxFileList.Any(x => x.Name.StartsWith(Messages.ActivitiesFolderName))) { // If nullOrEmpty, Folder may have been created manually if (string.IsNullOrEmpty(currentFolder.ActivityFolderID)) { //Find actual folder ID and save in BoxFolderCache's ActivityFolderID field BoxUtils.FileFolderInfo activityFolderinfo = BoxUtils.FindFolder(tokenHandler, folderID, Messages.ActivitiesFolderName).Result; if (activityFolderinfo != null) { currentFolder.ActivityFolderID = activityFolderinfo?.ID; FoldersByFolderID.Update(currentFolder); } } if (currentFolder.ActivityFolderID != null) { SynchronizeFolderContentsWithScreen(ActivityMaintScreenId, currentFolder.ActivityFolderID, isForcingSync); } } //Remaining files aren't found in cache but are in Box server. if (filesFoundOnlyOnServer.Any()) { if (refNoteID == null) { // User may have created some folder manually with a name not matching to any record, or record // may have been deleted in Acumatica. We can safely ignore it, but let's write to trace. PXTrace.WriteWarning(string.Format("No record found for folder {0} (screen {1}, ID {2})", folderName, screenID, folderID)); return; } UploadFileMaintenance ufm = PXGraph.CreateInstance <UploadFileMaintenance>(); ufm.IgnoreFileRestrictions = true; ufm.RowInserting.AddHandler <UploadFileRevision>(delegate(PXCache sender, PXRowInsertingEventArgs e) { ((UploadFileRevision)e.Row).BlobHandler = Guid.NewGuid(); }); //Add files to the caches foreach (BoxUtils.FileFolderInfo boxFile in filesFoundOnlyOnServer) { ufm.Clear(); string fileName = string.Format("{0}\\{1}", folderName, boxFile.Name.Replace(Path.GetInvalidPathChars(), ' ')); FileInfo fileInfo = ufm.GetFileWithNoData(fileName); Guid? blobHandlerGuid; if (fileInfo == null) { fileInfo = new FileInfo(fileName, null, new byte[0]); //The SaveFile call will trigger a Load() on the BoxBlobStorageProvider which can be skipped PXContext.SetSlot <bool>("BoxDisableLoad", true); try { if (!ufm.SaveFile(fileInfo)) { throw new PXException(Messages.ErrorAddingFileSaveFileFailed, fileName); } } finally { PXContext.SetSlot <bool>("BoxDisableLoad", false); } if (!fileInfo.UID.HasValue) { throw new PXException(Messages.ErrorAddingFileUIDNull, fileName); } UploadFileMaintenance.SetAccessSource(fileInfo.UID.Value, null, screenID); NoteDoc noteDoc = (NoteDoc)NoteDocs.Cache.CreateInstance(); noteDoc.NoteID = refNoteID; noteDoc.FileID = fileInfo.UID; NoteDocs.Insert(noteDoc); blobHandlerGuid = ufm.Revisions.Current.BlobHandler; } else { //File already exists in the database, retrieve BlobHandler if (!fileInfo.UID.HasValue) { throw new PXException(Messages.GetFileWithNoDataReturnedUIDNull, fileName); } blobHandlerGuid = GetBlobHandlerForFileID(fileInfo.UID.Value); //Clear old references of this blob handler from cache; it will be reinserted with up-to-date info var bfcOrphan = (BoxFileCache)FilesByBlobHandler.Select(blobHandlerGuid); if (bfcOrphan != null) { FilesByBlobHandler.Delete(bfcOrphan); } //Update NoteDoc entry if existing file was moved to new NoteID or create it if not there NoteDoc nd = (NoteDoc)NoteDocsByFileID.Select(fileInfo.UID); if (nd == null) { nd = (NoteDoc)NoteDocs.Cache.CreateInstance(); nd.NoteID = refNoteID; nd.FileID = fileInfo.UID; NoteDocs.Insert(nd); } else if (nd.NoteID != refNoteID) { nd.NoteID = refNoteID; NoteDocs.Update(nd); } } var bfc = (BoxFileCache)FilesByBlobHandler.Cache.CreateInstance(); bfc.BlobHandler = blobHandlerGuid; bfc.FileID = boxFile.ID; bfc.ParentFolderID = boxFile.ParentFolderID; bfc = FilesByBlobHandler.Insert(bfc); } } }
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()); }