Stages of Calculations in the Order Calculation Batch
Preparation for Batch Start
Stage | Description |
|---|---|
Launch | The batch is launched using the script --diagram '1,2' – calculate all diagrams related to 1 and 2. --diagram_from 'TABLE_NAME, COLUMN' – take the list of diagrams from a table/column. Ignored if --diagram is present. --days 7 – overrides the ordersDays option. --date_shift 1 – shifts the current date forward. --stores '21,34' – list of stores for which the calculation should be performed. --warehouse '1,2,3' – list of warehouses to calculate, including related orders from stores. --direct_orders – calculate only direct store-to-supplier orders, excluding warehouses. --no_store_orders – do not calculate store orders, warehouses only. --calc_calendars_only – calculate only new calendars. --do_not_confirm – do not auto-confirm orders at the end of the calculation. --send_email – when calculating all diagrams, send a statistics email to addresses in options-mail-to. --force_send_email – always send a statistics email to addresses in options-mail-to, regardless of parameters. --send_email_suppliers – send generated orders to suppliers (only if confirmed). --use_budget – enable calculation according to budgets. --concurrent_stores 2 – number of stores calculated simultaneously in a single thread (max 3). --max_workers 3 – number of parallel threads for store calculation (minimum 2, but no more than available processors). For debugging: --localdb – use database connection settings from loader - local_connection. --no_batches – do not launch additional scripts before or after calculations. --do_not_touch_db – do not write anything to the database. --skip_calculations – skip calculations. --dblog – output all database queries being generated, with parameter substitutions applied. Sometimes it is necessary to allocate more memory than default for calculations via |
List of diagrams | If --diagram, --diagram_from, parameters are present, a list of diagrams for calculation is generated (method Note: lists larger than 2,500 diagrams may cause the database parser to fail, and the query will not execute. |
Calendars | The list of active diagrams and the latest calendar dates for them are retrieved ( WARNING: existing calendars are not deleted or recalculated, unlike orders. To recalculate calendars, they must be deleted first. |
Cache table | A temporary table |
Pre-processing | The SQL batch |
List of stores and warehouses | The list of stores is retrieved ( |
Warehouse balances | An object with warehouse stock balances is prepared ( Queries used:
Each new order line subtracts from the warehouse balances here. |
Forecast ID | The ID of the last forecast is cached ( |
Calculation of store orders
Stage | Description |
|---|---|
Calculating Stores in Sequence | The calculation is performed store by store, in descending order of average sales. If parallel calculation is enabled, some stores may be processed simultaneously, but groups are still processed in sorted order. Procedure: |
Populating the Table for Calculations | The table RPM_SKU_BY_DIAGRAMS is populated with data for the store with three fields: |
Retrieving Data for Order Skeletons Formation | For each store, the main data is retrieved using the following queries:
Assortment matrices are also generated using the procedure |
Checking and Filtering Duplicates | Duplicates are checked for pairs |
Checking for Missing Links | Calendars are checked: records from |
Combining Data | Data from the above queries is combined to form order skeletons using the procedure |
Supplementing Data | Order skeletons are supplemented with data on presentations, stock, and SKU parameters using the procedure |
Completing Matrices | Assortment matrices are supplemented for substitute SKUs where the main product is missing using the procedure |
Checking Order Duplicates | The procedure |
Reorganizing Pick-to-Zero Orders | Since pick-to-zero orders are retrieved by store order calendars, but actually the orders correspond to warehouse delivery dates with the nearest date according to the store schedule, order and delivery dates are reorganized. Extra orders between warehouse delivery dates are removed, and the order date is changed in the necessary orders ( |
Additional Presentation | Additional presentation is added to orders via the procedure |
Transforming Increases for Holidays | Holiday uplifts retrieved from the database via |
Analyzing Minimum and Maximum Dates | Minimum and maximum dates are analyzed for |
Generating Matrix Map by Dates | The procedure |
Loading Forecast Data | Forecast data is retrieved via Additionally, procedure |
Checking Presence in Matrices | Order skeletons are checked for presence in the matrix by |
Supplementing Promotion Data | Promotion data is supplemented in order skeletons using |
Distributing Forecast by Days | Weekly sales forecasts are distributed by days according to recalculated daily shares. |
Adding Shipment Forecast | Shipment forecasts are added to daily sales forecasts if it is a warehouse (already retrieved by days using |
Removing Non-Working Days | Non-working days are removed from daily forecasts according to the parameter |
Supplementing Warehouse Promotion Data | Warehouse orders are supplemented with promotion data using |
Preparing Goods in Transit | Goods-in-transit object is prepared using the procedure |
Forecasting by Similar Items | For similar SKUs that are not in the matrix but have a contract and have order skeletons, sales forecasts are added from similar SKUs that are in the matrix but have no contract ( |
Generating Forecasts for Periods O1D1 and D1D2 | The procedure |
Calculating Ingredient Consumption Forecast | If the parameter
|
Calculating Shelf-Life Limits | The maximum quantity that can be ordered to sell the product within a certain percentage of shelf life ( |
Calculating Write-Off Forecasts | If the parameter |
Order Calculation | Orders are sorted by dates, separated by SKU, and calculated using |
Summarizing Data by Ingredients | Forecasts, presentations, and stock data for master products using the same ingredient are summed in ingredient orders (initially in ingredient orders they were separate per master product) to save memory. |
Adding “Tender” Flag | Orders eligible for contract change (tender) are flagged accordingly. |
Deleting Orders | Existing unconfirmed orders from the current date, as well as additional pick-to-zero calendars and orders, are deleted from the database. |
Creating Pick-to-Zero Calendars | Pick-to-zero calendars are created and inserted using |
Splitting Orders by Type | Orders are split by type using |
Order Headers | Order IDs are assigned and orders are grouped into headers using |
Calculating Final Values | Final order totals are calculated using |
Optimizing Orders by Quantity or Total | The procedure |
Recalculating Order Totals After Optimization | Final order totals are recalculated using |
Inserting into Database | Orders are inserted into the database. |
Post-Processing | SQL batch |
Calculation stages after store orders have been calculated
Stage | Description |
|---|---|
Calculating warehouse orders | Выполняется в отсортированном порядке по их месту в цепочке поставок исключительно последовательно, без параллелизации. |
Determining a list with delivery (today) | Заполняется таблица RPM_SKU_BY_DIAGRAM для заказов склад-поставщик у которых дата доставки - сегодня |
Clearing delivery boxes | Запросом |
Calculating warehouse orders | Запускается функцией |
Rebalancing store orders by balance | Для тех заказов магазинов, где дата доставки сегодня, запускается выравнивание заказов магазинов по остатку склада функцией |
Recalculating future orders | Функцией |
Linking lots | Если установлена опция |
Recalculating remaining warehouse orders | Выполняется |
Saving picking orders | запрос |
Calculating cross-dock orders | Вызывается процедура |
Finalizing the batch work
Stage | Description |
|---|---|
Post-processing | SQL batch |
Clearing the cache | The temporary table |
Sending orders | If the parameter |
Final script | SQL batch |
Sending statistics | Emails with statistics are sent according to the parameters |
P.S. To be continued