FIN0202 Create VAT Purchases Entries

Basic Information

Module Logistics.Procurement
Code FIN0202
Parent Document PurchaseInvoice
Sub-document VAT.Entries
Full Name Create VAT purchases ledger entries
Status ACTIVE
Deterministic YES
Supports Transitional Documents NO
Replaces GenerateEntry; GenerateEntrySkipNote
Orphan Rows Forbid
Split Function PurchaseInvoiceLine.LineDealType
Introduced In Version 2022
Date of Suspension -

Business Logic

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

Different lines in the Purchase Invoice may have different Line Deal Types. For each of these Line Deal Types have to be created a separate VAT Entry. Therefore, at the beginning of the generation procedure, the lines of the purchase invoice have to be divided into sets by their Line 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 purchase invoice lines

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

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

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

VATDealType = PurchaseInvoiceLine.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 = PurchaseInvoice; Entry.DealType = DealType; Entry.RegistrationVATNumber = PurchaseInvoice.Supplier.RegistrationVATNumber, Entry.RegistrationNumber = PurchaseInvoice.Supplier.RegistrationNumber, Entry.ApplyDate = PurchaseInvoice.ApplyDate

Metrics

Fulfillment Name Metric Name Measurement Unit Parent Value Child Value New Record
PurchaseInvoiceLineToVATEnrty AmountBase VATDocumentAmountCurrency DealTypeBaseAmount Entry.AmountBase YES
PurchaseInvoiceLineToVATEnrty VATAmountBase VATDocumentAmountCurrency DealTypeAmount Entry.VATAmountBase YES
Entry.DocumentDate = PurchaseInvoice.DocumentDate

Entry.EntryType = Purchase

Entry.DealType = VATDealType

Entry.Party = PurchaseInvoice.Supplier.Party

If Invoice.Supplier.Party.PartyType = Company then Entry.RegistrationVATNumber = PurchaseInvoice.Supplier.RegistrationVATNumber

if (PurchaseInvoice.Supplier.RegistrationNumber.HasValue and PurchaseInvoice.Supplier.Party.PartyType = Company) then
    Entry.RegistrationNumber = PurchaseInvoice.Supplier.RegistrationNumber

if PurchaseInvoice.Supplier.Party.PartyType = Person   then Entry.RegistrationNumber   = PurchaseInvoice.Supplier.Party.Person.NationalNumber

Entry.ReferencedDocumentNo = 
    if PurchaseInvoice.ReferenceDocumentNo.HasValue then
        PurchaseInvoice.ReferenceDocumentNo
    else PurchaseInvoice.DocumentNo

Entry.ReferenceDate = 
    If PurchaseInvoice.ReferenceDate.HasValue then
        PurchaseInvoice.ReferenceDate 
    else PurchaseInvoice.DocumentDate

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

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

Entry.ApplyDate = PurchaseInvoice.ApplyDate

Entry.CashReportingMode = PurchaseInvoice.VATCashReportingMode

if Invoice.VATNotes.HasValue then
    VATEntry.Notes = PurchaseInvoice.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.