CRM1003 Create Sales Orders

General Information

Module Crm.Presales
Code CRM1003
Parent Document Deals
Sub-document Sales Orders
Full Name Create Sales Orders
Deterministic YES
Status NEW
Supports Transitional Documents NO
Supports Single Execution YES
Replaces -
Orphan Rows Ignore
Split Function -
Version Introduced: 2022
Date of Suspension -

Business Logic

This generation is used to create Sales Orders from Deals.

To create a sales order, the customer has to be specified. The customer is extracted from the party, selected in the Deal (Deal.Party) and the up-to-date, and active customer definition of this party in the enterprise company of the sales order (SalesOrder.EnterpriseCompany) or which is without enterprise company. (so Customer.Party = Deal.Party && (Customer.EnterpriseCompany == SalesOrder.EnterpriseCompany || Customer.EnterpriseCompany == null) && Customer.Active == true && (Customer.FromDate <= SalesOrder.DocumentDate || Customer.FromDate == null) && (Customer.ThruDate >= SalesOrder.DocumentDate || Customer.ThruDate == null).

If no such customer is found, the generation procedure is stopped and an error is thrown. The error text is:

 No valid client is found for '{Deal.Party.PartyName}' party. 
 In order to create a sales order, there must be an active customer for '{Deal.Party.PartyName}' party, applicable to the current enterprise company.

The fields in the Sales Order’s header are filled as follows:

SalesOrder.Customer = the determined Customer for the Deal.Party

SalesOrder.DocumentDate = Today

SalesOrder.ShipToPartyContactMechanism = 
if (Count(PartyContactMechanisms, where Party == SalesOrder.Customer.Party && IsDefault == true) == 1)
, then ShipToPartyContactMechanism = First(PartyContactMechanisms, where Party == SalesOrder.Customer.Party && IsDefault == true)
, else SalesOrder.ShipToPartyContactMechanism = null
                                         
SalesOrder.DocumentCurrency = SalesOrder.EnterpriseCompany.BaseCurrency

SalesOrder.PaymentDueDate = DocumentDate + Customer.DefaultPaymentTermDays

SalesOrder.PaymentDueStartDate = DocumentDate + Customer.DefaultPaymentStartDays

SalesOrder.RequiredDeliveryDate = DocumentDate + Customer.DefaultDeliveryTermDays

SalesOrder.DistributionChannel = Customer.DefaultDistributionChannel

SalesOrder.PaymentAccount = Customer.DefaultPaymentAccount

SalesOrder.PaymentType = Customer.DefaultPaymentType

SalesOrder.PriceList = Customer.DefaultPriceList

SalesOrder.CreditLimitOverride = false

SalesOrder.Deal = Deal

SalesOrder.SalesPerson = Deal.LeadingSalesPerson

SalesOrder.Dealer = Deal.Dealer

SalesOrder.Store = null

SalesOrder.ShipToCustomer = null

SalesOrder.DealType = null

SalesOrder.CustomerPurchaseOrderDate = null

SalesOrder.CustomerPurchaseOrderNo = null

SalesOrder.PosLocation = null

SalesOrder.PosOperator = null

SalesOrder.PosTerminal = null

SalesOrder.FiscalSalesNumber = null

SalesOrder.FiscalPrinterPosDevice = null

SalesOrder.EndCustomerParty = null

SalesOrder.DeliveryTermsCode = null

SalesOrder.IntrastatTransactionNatureCode = null

SalesOrder.IntrastatTransportModeCode = null

SalesOrder.IntrastatTransportCountry = null

SalesOrder.ReturnForInvoice = null

SalesOrder.ReturnForSalesOrder = null

SalesOrder.FromDate = null

SalesOrder.ToDate = null

SalesOrder.Notes = null
Note

The attributes which are not specified here are filled in as described in Standard Document Attributes

Fulfillments

No fulfilments and metrics are used for the current generation procedure. Each time the procedure is started, it creates new sub-document no matter if there are documents already created from previous procedure executions.


The new Sales Order Line is created as follows:

SalesOrderLine.LineNo = DealLine.LineNo 

SalesOrderLine.Product = DealLine.Product

SalesOrderLine.ProductDescription = SalesOrderLine.Product.Name

SalesOrderLine.GuaranteePeriodDays = SalesOrderLine.Product.GuaranteePeriodDays

SalesOrderLine.ProductCode = null

SalesOrderLine.ProductPrice = loaded by the 'Determine product price'* method

SalesOrderLine.UnitPrice = loaded by the 'Calculate Unit Price' method
                      
SalesOrderLine.StandardUnitPrice = loaded by the 'Get Standard Unit Price' method

SalesOrderLine.RequestedQuantity = null

SalesOrderLine.Quantity = DealLine.Quantity

SalesOrderLine.QuantityUnit = DealLine.QuantityUnit

SalesOrderLine.QuantityBase = CONVERT(SalesOrderLine.Quantity, SalesOrderLine.Product.BaseMeasurementCategory.BaseUnit)

SalesOrderLine.StandardQuantityBase = CONVERT(SalesOrderLine.Quantity, SalesOrderLine.Product.BaseMeasurementCategory.BaseUnit)

SalesOrderLine.Level1Discount = loaded by the 'Determine line discount'* method

SalesOrderLine.Level1DiscountPercent =
    if (SalesOrderLine.Level1Discount != null)
    , then SalesOrderLine.Level1DiscountPercent = SalesOrderLine.Level1Discount.DiscountPercent
    , else SalesOrderLine.Level1DiscountPercent = null

SalesOrderLine.Level2Discount = loaded by the 'Determine line discount'* method

SalesOrderLine.Level2DiscountPercent =
    if (SalesOrderLine.Level2Discount != null)
    , then SalesOrderLine.Level2DiscountPercent = SalesOrderLine.Level2Discount.DiscountPercent
    , else SalesOrderLine.Level2DiscountPercent = null

SalesOrderLine.Level3Discount = loaded by the 'Determine line discount'* method

SalesOrderLine.Level3DiscountPercent =
    if (SalesOrderLine.Level3Discount != null)
    , then SalesOrderLine.Level3DiscountPercent = SalesOrderLine.Level3Discount.DiscountPercent
    , else SalesOrderLine.Level3DiscountPercent = null

SalesOrderLine.LineStandardDiscountPercent = loaded by the 'Determine Line Standard Discount Percent' method
                                             
SalesOrderLine.LineCustomDiscountPercent = 0.00%

SalesOrderLine.LineAmount = loaded by the 'Determine line amount in sales orders'* method

SalesOrderLine.LineEndCustomerParty = null

SalesOrderLine.RequiredDeliveryDate = SalesOrder.RequiredDeliveryDate

PersistLot = false

SalesOrderLine.Notes = DealLine.Notes

SalesOrderLine.ParentDocument = Deal

SalesOrderLine.ParentLineNo = DealLine.LineNo

SalesOrderLine.Lot = null

SalesOrderLine.SerialNumber = null

SalesOrderLine.ProductVariant = null

SalesOrderLine.LineStore = null

SalesOrderLine.StoreBin = null

SalesOrderLine.LineDealType = null

SalesOrderLine.BonusProgram = null

SalesOrderLine.PromotionalPackage = null

SalesOrderLine.IntrastatApplyDate = null

SalesOrderLine.DeliveryTermsCode = null

SalesOrderLine.IntrastatTransactionNatureCode = null

SalesOrderLine.IntrastatTransportModeCode = null

SalesOrderLine.IntrastatTransportCountry = null

SalesOrderLine.ReturnForInvoiceLine = null

SalesOrderLine.ReturnForSalesOrderLine = null

SalesOrderLine.HistoricalDataJson = null

SalesOrderLine.HistoricalUnitCost = null

SalesOrderLine.LineFromDate = null

SalesOrderLine.LineToDate = null

Links to the methods used in the algorithm above:

*Determine product price

*Determine line discount

*Determine line amount in sales orders