Invoice add payment

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Zahradnik
    Junior Member
    • Oct 2021
    • 6

    Invoice add payment

    Hi, I am trying to add an invoice payment record in invoices.
    Some customers pay the invoice multiple times. This means I'm trying to add more records.
    For example, the invoice amount is 100.
    First payment: 20/11/2024 - 50
    21.11.2024 - 25
    25/11/2024 - 25
    Once the sum of the payments = the invoice amount, the invoice will be changed to "paid"
    Can someone help me please?
    Thank you​
  • victor
    Active Community Member
    • Aug 2022
    • 727

    #2
    How to make such a functionality is described in detail in this article: https://www.espocrm.com/blog/tutoria...-transactions/.

    However, if it's easier to do, then you just need:
    1. Create Payment entity and relate it with Invoice entity as Many-to-One.
    2. In the Invoice entity, create a Payment Sum field with the Currency type.
    3. In the Payment entity, create a Payment Amount field with the Currency type.
    4. Add all the required fields to the Layouts you need in both entities.
    5. In Administration > Entity Manager > Invoice > Formula > Before Save Custom Script add the following formula (note that your field names may differ):​
    Code:
    cPaymentSum = entity\sumRelated('cPayments', 'paymentAmount');
    
    ifThen(
        amount == cPaymentSum,
        status = 'Paid';
    );​
    Thus, when the Payment Sum field becomes equal to the Amount field, the Status will automatically change to Paid.

    Comment

    • shalmaxb
      Senior Member
      • Mar 2015
      • 1602

      #3
      This is definetely possible. I solved a similar problem for one of my clients.
      He has different payment conditions:
      1. Due by Sales Order
      2. Due by Invoice
      3. 30% by Sales Order, 70% by Invoice
      4. 50% by Sales Order, 50% by Invoice

      You may have other conditions. What is important is, that you determine due dates and amounts of the total invoice as fixed and not by customer`s decision.

      For the conditions I created a enum field with the mentioned options. This is necessary to trigger the correct formula behind of each of these conditions.
      That means, that for each condition you will need the calculation against your totals.

      How does that look for the invoice.

      First I introduced the conditions in all parts of the sales process, what means, it appears already in Quote, in SalesOrder and in Invoice. From one stage to the next these values will be copied through and the calculation is for any part quite the same. (My client wanted in the Invoice the aditional possibility to add positions or deduct positions, what had been quite complicated to achive. But this is a special case).

      Depending on the conditions you will have to split the totals and for those partly payable amounts you will need custom fields to represent these partly amounts. So you will be able to calculate with those.
      In the end you need to sum up the single payments and balance them with the total. As soon as the sum of the rates is equal the total you may display paid. I did that again with an enum field (displayed as coloured labels) with the options: open, paid, overdue. Displaying these labels in the list view will give a good presentation of your paid and open invoices.

      It would be also reasonable to introduce date fields for the rates to be paid, for example to be able to calculate the overdue date.

      Don`t forget to pay attention to taxes, discounts and other values that might interfere with your calculations. This normally is depending on each country`s laws differently.

      Comment

      Working...