NewBase - SendOrderToBackoffice
This function handles the process of sending an order from App4Sales to the NewBase ERP system. It involves generating an order number, preparing order data including customer and item details, and then posting this data to the NewBase API. It also handles the response from NewBase, updating the order number in App4Sales if necessary, and managing error conditions.
Data Source Configuration
The data primarily originates from the internal App4Sales Order object, which contains customer information, order lines, and other relevant details. Additional data is fetched from App4Sales contexts like ContactPersonsContext, CustomersContext, and ItemsContext. The NewBase API is the target system for the order.
Data Mapping Table (Order Header)
App4Sales Field | Source Field (API/Excel/DB) | Logic/Notes |
Order Number | Derived | Generated internally by App4Sales. Uses |
Customer Details |
| Passed directly from the App4Sales |
Main Contact Person |
| Retrieved from App4Sales internal context based on the customer GUID. |
Customer Free Fields |
| Retrieved from App4Sales internal context based on the customer code. |
Settings |
| Various connector settings influence the order sending process. |
Data Mapping Table (Order Lines)
App4Sales Field | Source Field (API/Excel/DB) | Logic/Notes |
Item Code |
| Taken directly from the order line. |
Price |
| If |
Discount | Derived | If |
Special Logic & Filters
Order Number Generation: If the NewBase API does not support automatic order number generation, App4Sales generates a unique order number. This number is based on a configurable prefix (
OrderNumberGenerationPrefix), the most recent order number, and a configurable number of digits (OrderNumberGenerationNumDigits).Base Price for Order Lines: If
SendBasePriceForItemOrderLinesis enabled, the system retrieves theSalesPricefrom theItemsContextfor each item in the order. If thisSalesPriceis higher than the current line price, a discount percentage is calculated and applied to the line. The line's price is then set to the item'sSalesPrice.API Call: The order data, along with contact person details, customer free fields, and connector settings, is composed into a
PostSalesOrderparameter object and sent to the NewBase API via an HTTP POST request.Error Handling:
If the NewBase API returns no response, an error is logged, the generated order number is reset in App4Sales, and an error message is returned.
If the NewBase API response indicates failure (
response.Successis false), an error is logged, the generated order number is reset, and an error message including the NewBase message is returned.If
UseA4SOrderNumberAsOurRefis false and NewBase does not return an order number, an error is logged, the generated order number is reset, and an error message is returned.Any other exception during the process results in logging the error, resetting the order number, and returning an error message.
Order Number Update:
If
UseA4SOrderNumberAsOurRefis false (default behavior), the order number returned by NewBase (response.OrderNr) is used to update the order in App4Sales.If
UseA4SOrderNumberAsOurRefis true, the internally generated order number is returned (it's assumed to have been sent to NewBase as their reference).
Domain Specifics / Extension Section
Order Header Logic
Order Numbering: App4Sales generates a unique order number locally if the ERP does not support automatic generation. This number respects
OrderNumberGenerationPrefixandOrderNumberGenerationNumDigits.Customer Information: Customer details from the App4Sales
Orderobject are used. The main contact person and any custom free fields associated with the customer are also retrieved and included in the order payload.
Line & Pricing Logic
Item Pricing: The connector can be configured to send the base sales price for order lines (
SendBasePriceForItemOrderLines). When this setting is enabled, the system will retrieve theSalesPriceof items from the App4Sales item context and recalculate discounts if the original line price is lower than the sales price.
Charges & Attachments
No explicit logic for handling charges or attachments is present within the SendOrderToBackoffice method. These might be handled at a different layer or not supported by this connector.
Responses & Error Handling
ERP Response: The connector expects a
PostResponseSalesOrderfrom the NewBase API. This response includes aSuccessflag and potentially anOrderNr.Duplicate Detection: Not explicitly handled in this method.
Retry/Backoff: Not explicitly handled in this method.
Order Number Update: The order number in App4Sales is updated with the ERP's order number if
UseA4SOrderNumberAsOurRefis false. IfUseA4SOrderNumberAsOurRefis true, the locally generated order number is retained.Error Messages: Detailed error messages are returned to the user in case of API failure, no response, or missing order number from NewBase. The App4Sales order number is reset in case of any error during the process.
Related Settings & Prerequisites
Order Number Generation Prefix: A prefix used for generating App4Sales order numbers when NewBase does not provide one.
Order Number Generation Num Digits: The number of digits to use for the sequential part of the generated order number. Default is 5 if less than 2.
Send Base Price For Item Order Lines: A boolean flag. If true, the system will use the item's base sales price and calculate discounts accordingly.
Use A4S Order Number As Our Ref: A boolean flag. If true, the App4Sales generated order number is sent as NewBase's reference, and that same number is returned. If false, the order number returned by NewBase is used.
Known Limitations
NewBase API does not support automatic order number generation for orders sent via API, requiring App4Sales to generate it internally.
No explicit handling for charges or attachments is visible within this method.
No explicit retry or duplicate order detection logic is visible within this method.