CRM0202 Create Invoices

Basic Information

Module Crm.Invoicing
Code CRM0202
Parent Document InvoiceOrder
Sub-document Invoice
Full Name Create Invoices
Status ACTIVE
Deterministic/Non-deterministic Yes
Supports Transitional Documents NO
Supports Single Execution YES
Replace Generation Procedures GenerateInvoices
Processing Orphan Rows Ignore
Introduced In Version 2019.1
Date of Suspension -

Business Logic

The current generation creates Invoice directly from an already existing Invoice Order. The invoice is almost identical to the invoice order and the generation is used in cases when the invoicing is automatic and is nor not executed by the users through a specialized navigator.

The Invoice header is created based on the Invoice Order header as follows:

Invoice.DocumentDate = today

Invoice.Customer = InvoiceOrder.Customer

Invoice.Notes = InvoiceOrder.Notes

Invoice.DocumentCurrency = InvoiceOrder.DocumentCurrency

Invoice.PaymentType = InvoiceOrder.PaymentType

Invoice.PaymentTypeDescription = InvoiceOrder.PaymentTypeDescription

Invoice.PaymentAccount = InvoiceOrder.PaymentAccount

Invoice.PaymentDueDate = if InvoiceOrder.PaymentDueDate.HasValue

then MAX(InvoiceOrder.PaymentDueDate, InvoiceOrder.DocumentDate) + (today - InvoiceOrder.DocumentDate)

else empty

Invoice.CreditNoteOriginalInvoice = InvoiceOrder.CreditNoteOriginalInvoice

Invoice.CreditNoteDescription = InvoiceOrder.CreditNoteDescription

Invoice.DeliveryDate = if InvoiceOrder.DeliveryDate.HasValue,

​    then InvoiceOrder.DeliveryDate

​    else Invoice.DocumentDate

Invoice.DealType = InvoiceOrder.DealType

Invoice.ApplyDate = InvoiceOrder.ApplyDate

Invoice.PaymentDueStartDate = InvoiceOrder.PaymentDueStartDate

Invoice.IntrastatTransactionNatureCode = InvoiceOrder.SalesOrder.IntrastatTransactionNatureCode

Invoice.DeliveryTermsCode = InvoiceOrder.SalesOrder.DeliveryTermsCode

Invoice.IntrastatTransportModeCode = InvoiceOrder.SalesOrder.IntrastatTransportModeCode

Invoice.IntrastatTransportCountry = InvoiceOrder.SalesOrder.IntrastatTransportCountry

The rest of the Document table attributes which are not listed here are filled in as described in Standard Document Attributes.

Note

The new invoice is saved then and only when there is at least one line in it.

Fulfillments

Name InvoiceOrderLineToInvoiceLine
Parent Entity InvoiceOrderLine
Child Entity InvoiceLine
Parent / Child Relationship InvoiceLine.ParentDocument = InvoiceOrder;InvoiceLine.ParentLineNo = InvoiceOrderLine.LineNo

Metrics

Fulfillment Name Metric Name Measurement Unit Parent Value Child Value New Record
InvoiceOrderLineToInvoiceLine MStandardQuantityBase InvoiceOrderLine.Product.BaseMeasurementUnit InvoiceOrderLine.StandardQuantityBase iInvoiceLine.StandardQuantityBase YES
InvoiceOrderLineToInvoiceLine MQuantity InvoiceOrderLine.QuantityUnit InvoiceOrderLine.Quantity InvoiceLine.Quantity NO
InvoiceOrderLineToInvoiceLine MQuantityBase InvoiceOrderLine.Product.BaseMeasurementUnit InvoiceOrderLine.QuantityBase InvoiceLine.QuantityBase NO
InvoiceOrderLineToInvoiceLine MLineAmount InvoiceOrder.DocumentCurrency InvoiceOrderLine.LineAmount InvoiceLine.LineAmount YES

The lines of the new document are created based on the data for the Fulfilled Part of quantities and amounts by Invoices that are already created (for more information, see topic Discrepancy System). The new InvoiceLine is created as follows:

InvoiceLine.LineNo = InvoiceOrderLine.LineNo
InvoiceLine.Product = InvoiceOrderLine.Product
InvoiceLine.ProductDescription = InvoiceOrderLine.ProductDescription
InvoiceLine.Quantity = InvoiceOrderLine.REMAINING(MQuantity)
InvoiceLine.QuantityUnit = InvoiceOrderLine.QuantityUnit
InvoiceLine.LineDiscount = InvoiceOrderLine.LineDiscount
InvoiceLine.LineStandardDiscountPercent = InvoiceOrderLine.LineStandardDiscountPercent
InvoiceLine.LineCustomDiscountPercent = InvoiceOrderLine.LineCustomDiscountPercent
InvoiceLine.LineAmount = InvoiceOrderLine.REMAINING(MLineAmount)
InvoiceLine.ParentSalesOrderLine = InvoiceOrderLine.SalesOrderLine
InvoiceLine.LineDealType = InvoiceOrderLine.LineDealType
InvoiceLine.InvoiceOrderLine = InvoiceOrderLine
InvoiceLine.BusinessReason = InvoiceOrderLine.BusinessReason
InvoiceLine.SalesOrder = InvoiceOrderLine.SalesOrder
InvoiceLine.PaymentTransaction = InvoiceOrderLine.PaymentTransaction
InvoiceLine.TransactionLine = InvoiceOrderLine.TransactionLine
InvoiceLine.QuantityBase = InvoiceOrderLine.REMAINING(MQuantityBase)
InvoiceLine.StandardQuantityBase = InvoiceOrderLine.REMAINING(MStandardQuantityBase)
if InvoiceOrderLine.SalesOrderLine.HasValue then
    InvoiceLine.SalesOrderAmount = InvoiceOrderLine.REMAINING(MLineAmount)
InvoiceLine.SerialNumber = InvoiceOrderLine.SerialNumber
InvoiceLine.ParentLineNo = InvoiceOrderLine.LineNo
InvoiceLine.IntrastatTransactionNatureCode = InvoiceOrderLine.SalesOrderLine.IntrastatTransactionNatureCode
InvoiceLine.DeliveryTermsCode = InvoiceOrderLine.SalesOrderLine.DeliveryTermsCode
InvoiceLine.IntrastatTransportModeCode = InvoiceOrderLine.SalesOrderLine.IntrastatTransportModeCode
InvoiceLine.IntrastatTransportCountry = InvoiceOrderLine.SalesOrderLine.IntrastatTransportCountry
InvoiceLine.IntrastatApplyDate = InvoiceOrderLine.SalesOrderLine.IntrastatApplyDate