Loading...
Area: Episerver B2B Commerce

Budget pipelines

Recommended reading 

GetBudgetActualAmountPipes

Order Pipe Description
100 GetSettings Gets BudgetsFromOnlineOnly setting. If Currency parameter is not null, then sets ConversionRate into result (if CurrencyRate for currency is null or ConversionRate is equal 0, then use 1, otherwise value from CurrencyRate.ConversionRate).
200 CreateOrderHistoryQuery Sets OrderHistoryQuery by whole OrderHistory table
300 FilterOrderHistoryQuery

Filter OrderHistoryQuery with BillTo.CustomerNumber, PeriodStartDate and PeriodEndDate parameters.

If ShipTo parameter is set, UserProfile parameter is null and BudgetsFromOnlineOnly setting is false, then filter also by ShipTo.CustomerSequence parameter.

400 FilterForOnlineOnlyIfNeeded

If BudgetsFromOnlineOnly is false, then exit pipe.

If OrderHistoryQuery is null, then throw ArgumentNullException

Join CustomerOrder table by orderHistory.WebOrderNumber and cart.OrderNumber. If UserProfile parameter exists, filter cart.InitiatedByUserProfile.UserName also by UserProfile.UserName parameter. And update OrderHistoryQuery result by all filtering with selecting order history.

500 CalculateBudgetActualAmount

If OrderHistoryQuery is null, then throw ArgumentNullException

Calculate BudgetActualAmount by summarizing all OrderHistoryQuery  results.

Code Example:

orderHistory.OrderTotal / (orderHistory.ConversionRate == 0 || orderHistory.ConversionRate == null ? 1 : orderHistory.ConversionRate) * result.ConversionRate

GetCustomerBudgetReview

Order Pipe Description
100 GetCurrency Get BillTo currency or default website currency (if customer currency is not set).
200 GetBudgetCalendar Get first BudgetCalendar filtered by BillTo.Id and FiscalYear parameters.
300 GetCustomerBudgets

If UserProfile parameter is not null, filter CustomerBudget by BillTo.Id and UserProfile.Id parameters

If ShipTo parameter is not null, filter CustomerBudget by BillTo.Id and ShipTo.Id parameters

Else filter CustomerBudget by BillTo.Id parameter and ShipToCustomerId, UserProfileId equal null.

CurrentCustomerBudget and PreviousCustomerBudget are being set by filtering collection.

400 CalculateVariance

If BudgetCalendar is null, exit pipe.

Fill CustomerBudgetReviewDtos with 13 periods by using data from previous pipes (BudgetCalendar, CurrentCustomerBudget, PreviousCustomerBudget).

500 GetBudgetActualAmounts

If GetBudgetActualAmounts is false, exit pipe.

Iterate over CustomerBudgetReviewDtos and calculate CurrentFiscalYearActual and LastFiscalYearActual using GetBudgetActualAmount budget pipeline. Based on previous iteration, calculate CurrentFiscalYearVariance and LastFiscalYearVariance per each CustomerBudgetReviewDto.

GetAvailableBudgetBalance

Order

Handler

Description

100

ValidateBudgetEnforcementLevel

Retrieves BillTo by BillToId parameter, can return not found error. If BudgetsFromOnlineOnly setting is false and customer BudgetEnforcementLevel is BudgetEnforcementLevel.User, then set BudgetEnforcementLevel to BudgetEnforcementLevel.None. If customer BudgetEnforcementLevel is BudgetEnforcementLevel.None, then exit the handler chain.

200

GetFilterForBudgetEnforcementLevel

If customer BudgetEnforcementLevel is BudgetEnforcementLevel.ShipTo, then retrieve ShipTo by ShipToId parameter, can return not found error.

If customer BudgetEnforcementLevel is BudgetEnforcementLevel.User, then retrieve UserProfile by UserProfileId parameter, can return not found error.

300

CalculateAvailableBudgetBalance

Call GetCustomerBudgetReview budget pipeline for current year, with retrieved BillTo, ShipTo or UserProfile. Calculate FiscalYearBudget based on retrieved data.

If customer budget review records exists. then set result Currency from BillTo or website default currency (if BillTo Currency property is not set). Call GetBudgetActualAmount budget pipeline and set FiscalYearActual with pipeline result.

AvailableBudgetBalance value will be.calculated as FiscalYearBudget minus FiscalYearActual.

Do you find this information helpful? Please log in to provide feedback.

Last updated: Dec 11, 2020

Recommended reading