locked
Calculate total amount invoice to custom field using Plug-In RRS feed

  • Question

  • Hi there,

    I've got a problem with my client, they want to calculate total amount invoice everytime they create invoice record. They want to update custom field in contact that contain total amount invoice contact.

    Can I use plug in for calculate total amount invoice to custom field in entity contact?

    I really appreciate for your answer.

    Best regards,

    Christian Aditya

    Thursday, January 31, 2013 2:32 AM

Answers

  • Just to clarify your requirement; you want to rollup all Invoice total's for a given contact and display this total on the contact record?

    Eg: If you have contact "Frosty Stevens", and Frosty has 2 Invoices, each totaling $100.00, the plugin should add these together and display the total of both on the contact. So in this case our 'Total Invoiced Amount' would be $200.00.

    If this is what you are trying to do, then yes you can use a plugin. The plugin should do something like this:

    On invoice - create/update (filtering: totalamount), you want to get the Customer of the invoice. It the customer is a contact, retrieve all Invoices for the contact, and sum the total amounts (you can use fetch aggregate). Then update the contact with the new total.

    You would also want to consider the possibility of someone deleting an invoice, or changing the Customer of an invoice, so you should handle these scenarios as well (for example, running the plugin on delete as well, and disabling the Customer lookup after the invoice is created).

    Hope that helps

    Paul

    • Proposed as answer by Amreek Singh Thursday, January 31, 2013 1:21 PM
    • Marked as answer by Christian Aditya Monday, February 4, 2013 2:16 AM
    Thursday, January 31, 2013 4:42 AM

All replies

  • Just to clarify your requirement; you want to rollup all Invoice total's for a given contact and display this total on the contact record?

    Eg: If you have contact "Frosty Stevens", and Frosty has 2 Invoices, each totaling $100.00, the plugin should add these together and display the total of both on the contact. So in this case our 'Total Invoiced Amount' would be $200.00.

    If this is what you are trying to do, then yes you can use a plugin. The plugin should do something like this:

    On invoice - create/update (filtering: totalamount), you want to get the Customer of the invoice. It the customer is a contact, retrieve all Invoices for the contact, and sum the total amounts (you can use fetch aggregate). Then update the contact with the new total.

    You would also want to consider the possibility of someone deleting an invoice, or changing the Customer of an invoice, so you should handle these scenarios as well (for example, running the plugin on delete as well, and disabling the Customer lookup after the invoice is created).

    Hope that helps

    Paul

    • Proposed as answer by Amreek Singh Thursday, January 31, 2013 1:21 PM
    • Marked as answer by Christian Aditya Monday, February 4, 2013 2:16 AM
    Thursday, January 31, 2013 4:42 AM
  • Thanks for your answer Paul, that's help me a lot.

    Regards,

    Christian Aditya

    Friday, February 8, 2013 2:35 AM
  • if you like to go for the plug-in

    register ur plug-in on message:create,post-operation

    register ur plug-in on message:update,pre-operation


    ms crm

    Friday, February 8, 2013 9:17 AM