Solved

Attaching the Current File to Files section as a PDF and concurrently updating the relevant processing screen as well.

  • 2 October 2023
  • 6 replies
  • 117 views

Userlevel 3
Badge

Hi All,


Does anyone Have an idea on how to perform the below activity?


“Need to attach the Current File to ‘Files section’ as a PDF and concurrently update the relevant processing screen as well.”

E.g. I need to attach current invoice in Invoices and memos (AR301000) to the files section and concurrently update the Print Invoices and Memos (AR508000) processing screen. 

Many thanks.

 

icon

Best answer by rashmikamudalinayake10 5 October 2023, 14:25

View original

6 replies

Userlevel 7
Badge +4

Hello @rashmikamudalinayake10 

I dont think your requirements can be fulfilled via Low/No code customization. You probably need to create a code customization to override PRINT button and add the file to Files.

Userlevel 6
Badge +3

hi @rashmikamudalinayake10,

As @RohitRattan88  mentioned you need to  create a code customization to achieve your requirement.

Userlevel 7
Badge +17

@rashmikamudalinayake10  Here is the customization required. Can you please review the below link and hope this helpful.

 

 In this case, you can add this button in the processing screen using the workflows and schedule it according to your requirement.

Userlevel 3
Badge

Dear All,

I was able to attach the file to the Invoices and Memos (AR301000) Files section and display it in the Print Invoices and Memos (AR508000) processing screen. 

But there are some conflicts on it.

1. In the File section it displays all the versions. How to display only the latest/updated PDF Version.

2. When the Print button is clicked it redirects to the report launcher ASPX page as below. Can I stop redirecting it (image 2)

3. The attached file is shown as image 3. How can I attach the pdf like in image 2?

Any idea on how to resolve the above's

Relevant NuGet packages, images and codes are attached below:

 

Many Thanks.

 

Image 0.Installed NuGet packages
Image 1.Need to view only the latest version in Files Section
Image 2.Need like this
Image 3.But getting like this
using iTextSharp.text;
using iTextSharp.text.pdf;
using PX.Data;
using PX.SM;
using System;
using System.Collections;
using System.IO;

namespace PX.Objects.AR
{
public class ARInvoiceEntry_Extension : PXGraphExtension<PX.Objects.AR.ARInvoiceEntry>
{
public class PdfGenerator
{
public static byte[] GenerateCustomPDF(ARInvoice invoice)
{
var document = new iTextSharp.text.Document();
var stream = new MemoryStream();
var writer = iTextSharp.text.pdf.PdfWriter.GetInstance(document, stream);
document.Open();

var titleFont = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 16);
var headingFont = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 12);
var normalFont = FontFactory.GetFont(FontFactory.HELVETICA, 10);

var title = new Paragraph("INVOICE", titleFont);
title.Alignment = Element.ALIGN_CENTER;
document.Add(title);

var referenceNbr = new Paragraph($"Reference Nbr.: {invoice.RefNbr}", headingFont);
referenceNbr.SpacingBefore = 10f;
document.Add(referenceNbr);

var date = new Paragraph($"Date: {invoice.DocDate:dd-MMM-yyyy}", headingFont);
document.Add(date);

var dueDate = new Paragraph($"Due Date: {invoice.DueDate:dd-MMM-yyyy}", headingFont);
document.Add(dueDate);

var customerId = new Paragraph($"Customer ID: {invoice.CustomerID}", headingFont);
customerId.SpacingBefore = 10f;
document.Add(customerId);

var currency = new Paragraph($"Currency: {invoice.CuryID}", headingFont);
document.Add(currency);

var billTo = new Paragraph("BILL TO:", headingFont);
billTo.SpacingBefore = 20f;
document.Add(billTo);

var shipTo = new Paragraph("SHIP TO:", headingFont);
document.Add(shipTo);

var lightGray = new BaseColor(192, 192, 192);

var headers = new string[] { "NO.", "ITEM", "QTY.", "UOM", "UNIT PRICE", "DISC.", "EXTENDED PRICE" };
var itemTable = new PdfPTable(7);
itemTable.TotalWidth = 500f;
itemTable.LockedWidth = true;

foreach (var header in headers)
{
var cell = new PdfPCell(new Phrase(header, headingFont));
cell.HorizontalAlignment = Element.ALIGN_CENTER;
cell.BackgroundColor = lightGray;
itemTable.AddCell(cell);
}

document.Add(itemTable);

var note = new Paragraph("NOTE:", normalFont);
note.SpacingBefore = 10f;
document.Add(note);

var salesTotal = new Paragraph("Sales Total: 0.00", normalFont);
document.Add(salesTotal);

var lessDiscount = new Paragraph("Less Discount: 0.00", normalFont);
document.Add(lessDiscount);

var taxTotal = new Paragraph("Tax Total: 0.00", normalFont);
document.Add(taxTotal);

var total = new Paragraph("Total (USD): 0.00", headingFont);
total.Alignment = Element.ALIGN_RIGHT;
document.Add(total);

var pageNumber = writer.PageNumber;
var page = new Paragraph($"Page: {pageNumber}", normalFont);
page.Alignment = Element.ALIGN_RIGHT;
document.Add(page);

document.Close();
byte[] pdfData = stream.ToArray();
return pdfData;
}
}

public delegate IEnumerable PrintInvoiceDelegate(PXAdapter adapter, String reportID);

[PXOverride]
public IEnumerable PrintInvoice(PXAdapter adapter, String reportID, PrintInvoiceDelegate baseMethod)
{
foreach (ARInvoice invoice in adapter.Get<ARInvoice>())
{
byte[] pdfData = PdfGenerator.GenerateCustomPDF(invoice);
string fileName = $"{invoice.RefNbr.Trim()}.pdf";
PX.SM.FileInfo file = new PX.SM.FileInfo(fileName, null, pdfData);
UploadFileMaintenance graph = new UploadFileMaintenance();
graph.SaveFile(file);

if (file != null && file.UID != null && file.UID.Value != null)
{
PXNoteAttribute.SetFileNotes(Base.Document.Cache, invoice, file.UID.Value);
}

var fileId = file.UID.GetValueOrDefault();
PXNoteAttribute.AttachFile(Base.Document.Cache, invoice, file);
}
return baseMethod(adapter, reportID);
}
}
}

 

Userlevel 3
Badge

Dear All

Could able to Find an alternative.

Many thanks.

public class ARInvoiceEntry_Extension : PXGraphExtension<PX.Objects.AR.ARInvoiceEntry>
{
[InjectDependency]
protected IReportLoaderService ReportLoader { get; private set; }

[InjectDependency]
protected internal PX.Reports.IReportDataBinder ReportDataBinder { get; private set; }

public delegate IEnumerable PrintInvoiceDelegate(PXAdapter adapter, String reportID);
[PXOverride]
public IEnumerable PrintInvoice(PXAdapter adapter, String reportID, PrintInvoiceDelegate baseMethod)
{
foreach(ARInvoice invoice in adapter.Get<ARInvoice>())
{
ARRegisterExt aRRegisterExt = PXCache<ARRegister>.GetExtension<ARRegisterExt>(invoice);

//Report Paramenters
Dictionary<String, String> parameters = new Dictionary<String, String>();
parameters["ARInvoice.DocType"] = invoice.DocType;
parameters["ARInvoice.RefNbr"] = invoice.RefNbr;
PXReportSettings settings = new PXReportSettings("AR641000");

//Report Processing
PX.Reports.Controls.Report report =
ReportLoader.CheckIfNull(nameof(ReportLoader)).LoadReport("AR641000", null);
ReportLoader.InitReportParameters(report, parameters, settings, false);
PX.Reports.Data.ReportNode reportNode =
ReportDataBinder.CheckIfNull(nameof(ReportDataBinder)).ProcessReportDataBinding(report);

//Generation PDF
byte[] data = PX.Reports.Mail.Message.GenerateReport(reportNode,
RenderType.FilterPdf).First();
PX.SM.FileInfo file = new PX.SM.FileInfo(reportNode.ExportFileName + "- " + invoice.RefNbr + ".pdf", null, data);

var uploadFileMaintenance = PXGraph.CreateInstance<UploadFileMaintenance>();
uploadFileMaintenance.SaveFile(file);
PXNoteAttribute.AttachFile(Base.Caches[typeof(ARInvoice)], invoice, file);

Base.Document.Cache.Update(invoice);
Base.Save.Press();
}
return baseMethod(adapter, reportID);
}

 

Userlevel 7
Badge

Thank you for sharing your solution with the community @rashmikamudalinayake10!

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved