FIN0204 Create VAT sales ledger entries

Basic Information

Module Logistics.Procurement
Code FIN0204
Parent Document PurchaseInvoices
Sub-document VAT.Entries
Full Name Create VAT sales ledger entries
Status ACTIVE
Deterministic YES
Supports Transitional Documents NO
Replaces GenerateSalesEntry; GenerateSalesEntrySkipNote
Orphan Rows Forbid
Split Function PurchaseInvoiceLine.SaleLineDealTypes
Introduced In Version 2022
Date of Suspension -

Business Logic

The generation is used for creating sales 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 Sale Line Deal Types. For each of these Sale 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 Sale 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.

VATSaleDealType = the SaleLineDealType of the current set of purchase invoice lines

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

SaleDealTypeAmount = SUM (PurchaseInvoices.DocumentDistributedAmount/Amount) WHERE DocumentLineId = PurchaseInvoiceLine DocumentAmountType=VATDocumentAmountType Group By SaleLineDealType

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

VATSaleDealType = PurchaseInvoiceLine.LineDealType Group By SaleLineDealType - it is same which is used for grouping in SaleDealTypeAmount and SaleDealTypeBaseAmount.

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

Fulfillments

Name InvoiceLineToVATEnrty
Parent Entity PurchaseInvoiceLine
Child Entity VAT.Entry
Parent / Child Relations Entry.ParentDocument = PurchaseInvoice; Entry.DealType = DealType; Entry.RegistrationVATNumber = PurchaseInvoice.Supplier.RegistrationVATNumber, Entry.RegistrationNumber = PurchaseInvoice.Supplier.RegistrationNumber, VATEntry.ApplyDate = PurchaseInvoice.ApplyDate

Metrics

Fulfillment Name Metric Name Measurement Unit Parent Value Child Value New Record
PurchaseInvoiceLineToVATEnrty AmountBase VATDocumentAmountCurrency SaleDealTypeBaseAmount Entry.AmountBase YES
PurchaseInvoiceLineToVATEnrty VATAmountBase VATDocumentAmountCurrency SaleDealTypeAmount Entry.VATAmountBase YES

Entry.DocumentDate = PurchaseInvoice.DocumentDate

Entry.EntryType = Sales

Entry.DealType = VATSaleDealType

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.