CRM0206 Create VAT Entry

Basic Information

Module Crm.Invoices
Code CRM0206
Parent Document Invoice
Sub-document VAT.Entries
Full Name Create VAT sales ledger entries
Status ACTIVE
Deterministic YES
Supports Transitional Documents NO
Replaces GenerateEntry; GenerateEntrySkipNote
Orphan Rows Forbid
Split Function InvoiceLine.LineDealType
Introduced In Version 2022
Date of Suspension -

Business Logic

The generation is used for creating sales VAT entries from Invoices. These records contain VAT Amount and VAT Base Amount from current Invoice and are used for collecting data for the creating of the VAT Declaration for the reporting period.

Different lines in the Invoice may have different Line Deal Types. For each of these Line Deal Type have to be created a separate VAT Entry. Therefore, at the beginning of the generation procedure, the lines of the invoice have to be divided into sets by their Deal Type.

For each set of lines is calculated the sum of the distributed VAT amounts. The algorithm of this calculation is described below:
Тo make the algorithm more understandable, we will introduce several auxiliary variables. The values of these variables will be used in the descriptions of the Metrics and the creation of the new document.

VATDealType = the LineDealType of the current set of invoice lines

VATDocumentAmountType = Invoice.EnterpriseCompany.VATDocumentAmountType
 
VATDocumentAmountCurrency = IIF(Invoice.DocumentAmounts.InputAmountCurrency is not Null, Invoice.DocumentAmounts.InputAmountCurrency Where Invoice.DocumentAmounts.DocumentAmountType = VATDocumentAmountType, Invoice.DocumentCurrency)

DealTypeAmount = SUM (Invoice.DocumentDistributedAmount/Amount) WHERE DocumentLineId = InvoiceLine DocumentAmountType=VATDocumentAmountType Group By LineDealType

DealTypeBaseAmount = SUM (Invoice.DocumentDistributedAmount/BaseAmount) WHERE DocumentLineId = InvoiceLine DocumentAmountType=VATDocumentAmountType Group By LineDealType

VATDealType = InvoiceLine.LineDealType Group By LineDealType - it is same which is used for grouping in DealTypeAmount and DealTypeBaseAmount.

The Document table attributes are filled in as described in Standard Document Attributes.

Fulfillments

Name InvoiceLineToVATEnrty
Parent Entity InvoiceLine
Child Entity VAT.Entry
Parent / Child Relations Entry.ParentDocument = Invoice; Entry.DealType = DealType; Entry.RegistrationVATNumber = Invoice.Customer.RegistrationVATNumber, Entry.RegistrationNumber = Invoice.Customer.RegistrationNumber, VATEntry.ApplyDate = Invoice.ApplyDate

Metrics

Fulfillment Name Metric Name Measurement Unit Parent Value Child Value New Record
InvoiceLineToVATEnrty AmountBase VATDocumentAmountCurrency DealTypeAmount Entry.AmountBase YES
InvoiceLineToVATEnrty VATAmountBase VATDocumentAmountCurrency DealTypeBaseAmount Entry.VATAmountBase YES

The new VAT Entries are created as follows:

 
Entry.EntryType = Sales

Entry.DealType = VATDealType

Entry.Party = Invoice.Customer.Party

Entry.RegistrationNumber = 
       if Invoice.Customer.Party.PartyType = Company, then Entry.RegistrationVATNumber = Invoice.Customer.RegistrationVATNumber
           
       if (Invoice.Customer.RegistrationNumber.HasValue and Invoice.Customer.Party.PartyType = Company), then Entry.RegistrationNumber = Invoice.Customer.RegistrationNumber
        
       if Invoice.Customer.Party.PartyType = Person, then Entry.RegistrationNumber = Invoice.Customer.Party.Person.NationalNumber

Entry.ReferencedDocumentType = Invoice.DocumentType

Entry.ReferencedDocumentNo = Invoice.DocumentNo

Entry.AmountBase = CONVERT( Remaining(AmountBase), BaseCurrency)

Entry.VATAmountBase = CONVERT( Remaining(VATAmountBase), BaseCurrency)

Entry.ApplyDate = Invoice.ApplyDate

Entry.CashReportingMode = Invoice.VATCashReportingMode

VATEntry.Notes =
       if Invoice.VATNotes.HasValue, then VATEntry.Notes = Invoice.VATNotes
       else if  Entry.EnterpriseCompany is Bulgaria, then VATEntry.Notes = "Продажба на стоки/услуги."

Note

RegistrationVATNumber, RegistrationNumber And VATNotes can be null if there is no value for them.