Blog navigation

Latest posts

VAT Simulation Before Invoice Generation in Sage X3

 

VAT Simulation Before Invoice Generation in Sage X3

In Sage X3, VAT (Value-Added Tax) is calculated and activated only at the moment the invoice is generated, which can pose a challenge for financial forecasting. One of my clients faced this issue, needing to know the exact VAT value to incorporate it into financial calculations before finalizing the invoice generation. The complexity of VAT calculation and its integration with commissions required a custom solution.

This article presents a solution that allows VAT simulation while still respecting the Sage X3 standard, even before the invoice is created. The technique used here mimics the behavior of a standard invoice, copying VAT information at a specific moment and then canceling the invoice creation by setting specific standard variables.

The advantage of this technique is that it guarantees full compliance with Sage X3 standards while considering any specific verticals or modules installed in the client's system. In fact, the import process simulates a standard data entry, ensuring that the calculation is performed according to the usual rules.

Typical Scenario

Let’s take a typical example: a client needs to make financial forecasts before creating an invoice. However, in Sage X3, VAT is only calculated at the time of final invoice generation. The following code provides a solution that allows VAT to be simulated beforehand while maintaining system integrity.

Code Example for VAT Simulation in Sage X3


$ACTION

  Case ACTION
    When "IMP_OUVRE"            : Gosub IMP_OUVRE
    When "IMP_VERIF_CRE"        : Gosub IMP_VERIF_CRE
    When "IMP_FERME"            : Gosub IMP_FERME
    When "IMP_SETBOUT"          : Gosub IMP_SETBOUT
  Endcase
Return

$IMP_SETBOUT
  [L]YBILIMP=val(timestamp$)
  [L]YINVNB+=1
Return

$IMP_FERME
  [L]YBILIMP=val(timestamp$)-[L]YBILIMP
  Call ECR_TRACE(mess(406,107,1)-num$(([L]YBILIMP/1000)/[L]YINVNB)-mess(25,154,1)-"/"-mess(87,121,1),0) From GESECRAN
Return

$IMP_OUVRE

  If !clalev([F:ZTXSV])      : Local File ZTRANSACTMP   [F:ZTXSV]       : Endif
  Local Integer YI
  Local Integer YINVNB
  Local Decimal YBILIMP
Return

$IMP_VERIF_CRE 
  # At this stage, the class [F:SID] is filled, and commissions are created
  # We are also sure that all standards have been activated previously
  # This action is the last chance to block the creation by setting OK=0
  
  Trbegin [F:ZTXSV]
  For YI=0 To nolign-1
    Read [F:ZTXSV]ZTRX0=[M:SIH4]ZTRXCHR(YI)
    If !fstat
      [F:ZTXSV]VAT(0)=[M:SIH4]VAT1(YI)
      [F:ZTXSV]VAT(1)=[M:SIH4]VAT2(YI)
      [F:ZTXSV]VAT(2)=[M:SIH4]VAT3(YI)
      [F:ZTXSV]AMTTAXLIN(0)=[M:SIH4]AMTTAXLIN1(YI)
      [F:ZTXSV]AMTTAXLIN(1)=[M:SIH4]AMTTAXLIN2(YI)
      [F:ZTXSV]AMTTAXLIN(2)=[M:SIH4]AMTTAXLIN3(YI)
      [F:ZTXSV]YSIHVAT=3
      Rewrite [F:ZTXSV]
    Endif

  Next YI
  If !fstat
    Commit
  Else
    Rollback
  Endif
  OK=0
Return

Solution Explanation

The code above shows how to simulate VAT using a custom process tied to an import model in Sage X3. This model allows VAT information to be determined before the final invoice is generated, and then cancels the invoice creation once the simulation is completed. Each commission is also calculated and associated with the simulated invoice.

Conclusion

This VAT simulation method provides users with accurate information on billing amounts, including applicable commissions and taxes, before the official invoice is created. In addition to complying with Sage X3 standards, this approach integrates seamlessly into customized environments and meets specific client needs for financial forecasts.

 
Posted in: Sage X3, 4GL