Skip to main content
Solved

Manipulate Invoice-PDF before sending

  • 5 September 2024
  • 7 replies
  • 86 views

priekenberg40
Varsity I
Forum|alt.badge.img

Where is the the best place to put own code to manipulate the attached invoice PDF of an E-Mail before it gets send?

What about PX.Objects.CR.Extensions.ActivityDetailsExt.CreateNotificationProvider()?
How can i PXOverride it?

Pascal

Best answer by priekenberg40

Yes, i did. Not quite perfect, as i had to copy the code from the base method:

 

View original
Did this topic help you find an answer to your question?

7 replies

priekenberg40
Varsity I
Forum|alt.badge.img
  • Author
  • Varsity I
  • 39 replies
  • September 5, 2024

Or is there way to customize PX.Objects.EP.NotificationGenerator?
Which is the graph which is used to perist CRSMEmail in NotificationGenerator.PersistMessages()


Forum|alt.badge.img+1
  • Jr Varsity I
  • 21 replies
  • September 6, 2024

Hi @priekenberg40 

 

Not sure if it possible to override generic CreateNotificationProvider, but at least we can override SendNotification which calls CreateNotificationProvider.

public class ARInvoiceEntry_NotificationExt : PXGraphExtension<ARInvoiceEntry_ActivityDetailsExt, ARInvoiceEntry>
{
    [PXOverride]
    public virtual void SendNotification(string sourceType, string notifications, int? branchID, IDictionary<string, string> parameters, bool massProcess = false, IList<Guid?> attachments = null,
        Action<string, string, int?, IDictionary<string, string>, bool, IList<Guid?>> baseMethod = null)
    {
        baseMethod(sourceType, notifications, branchID, parameters, massProcess, attachments);
    }
}

Invoice PDF is created based on a report. So if you need to change some details inside PDF you would better change the report.


priekenberg40
Varsity I
Forum|alt.badge.img
  • Author
  • Varsity I
  • 39 replies
  • September 6, 2024

Thanks @taras, there is realy no good place to hook in custom code for manipulation the created invoice pdf (E-Invoice/ZUGFeRD).
I’ll do it this way for the time beeing:
 

    public class ARInvoiceEntry_NotificationExt : PXGraphExtension<ARInvoiceEntry_ActivityDetailsExt, ARInvoiceEntry>
    {
        [PXOverride]
        public virtual void SendNotification(string sourceType, string notifications, int? branchID, IDictionary<string, string> parameters, bool massProcess = false, IList<Guid?> attachments = null,
            Action<string, string, int?, IDictionary<string, string>, bool, IList<Guid?>> baseMethod = null)
        {
            var activityExt = Base.GetExtension<ARInvoiceEntry_ActivityDetailsExt>();
            var sender = activityExt.CreateNotificationProvider<ARInvoice>(sourceType, notifications, branchID, parameters, attachments);

            var inv = Base.Caches[typeof(ARInvoice)]?.Current;
            if (inv != null)
            {
                List<FileInfo> _attachments = (List<FileInfo>) sender.GetType().BaseType 
                    .GetField("_newAttachments", BindingFlags.NonPublic | BindingFlags.Instance)
                    .GetValue(sender);
                foreach (FileInfo attm in _attachments)
                {
                   // manipulate pdf here
                }
            }
            if (!sender.Send().Any())
                throw new PXException(PX.Objects.CR.Messages.EmailNotificationError);
        }
    }

The problem is, that i have to bypass the overridden method completely and copy the code it contains to my method. Would be great if the non generic CreateNotificationProvider would have been called in SendNotification<TTemplateEntityType>. Then we could override it, but today it is not used at all.


Forum|alt.badge.img+1
  • Jr Varsity I
  • 21 replies
  • September 6, 2024

@priekenberg40 I can see this line inside CreateNotificationProvider() 

var mainDocRecipient = GetPrimaryRecipientFromContext(NotificationUtility, sourceType, bAccount, source);

I hope override this method will help to omit copying


priekenberg40
Varsity I
Forum|alt.badge.img
  • Author
  • Varsity I
  • 39 replies
  • September 11, 2024

@taras, yes, but i do not get access to the generated report/attachment there.


Chris Hackett
Community Manager
Forum|alt.badge.img
  • Acumatica Community Manager
  • 2679 replies
  • October 16, 2024

Hi @priekenberg40 were you able to find a solution? Thank you!


priekenberg40
Varsity I
Forum|alt.badge.img
  • Author
  • Varsity I
  • 39 replies
  • Answer
  • October 17, 2024

Yes, i did. Not quite perfect, as i had to copy the code from the base method:

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings