Support Rate Fetching Based on Customer Category (`FetchRateAsPerCategory`)
Introduce a new system parameter FetchRateAsPerCategory that changes how the ERP fetches selling prices from the Price Master (PriceMst). When enabled, the system queries the Price Master using the selected customer’s category (by joining with partymst to find any customer under the same category) rather than looking up the selected customer’s ID directly.
This approach avoids making any database schema or UI changes to the Price Master.
User Review Required
Note
Advantages of this approach:
- No changes to Price Master UI/Imports: Users will continue to create and import prices in the Price Master for specific customers just as they do today. No changes are made to the Price Master screens or Excel import.
- Cross-Customer Pricing: If the parameter is ON, the system matches prices defined for any customer who belongs to the same category as the selected customer.
- Automatic support for Re-update Rate: The “Re-update Rate From Price Master” action on the line details page calls the same
GetPriceAPI endpoint under the hood, meaning it will automatically fetch the category-based rate when the parameter is enabled.
Open Questions
None.
Proposed Changes
1. Database Migrations
[NEW] V0_0_0_0_0_78__Insert_Syspara_FetchRateAsPerCategory.sql
- Seed the new system parameter
FetchRateAsPerCategorywith a default value of'N'(OFF) into thesysparameterstable to guarantee backward compatibility.
2. Core Pricing & Sales Order Components
[MODIFY] ISalesOrderRepository.cs
- Add a new helper method signature
string GetPartyCategoryCode(string partyId, string dbname)to get the category code of a customer.
[MODIFY] SalesOrderRepository.cs
GetPartyCategoryCode: Implement the lookup ofcategorycodefrom thepartymsttable.GetPrice:- Check the
FetchRateAsPerCategoryparameter via_IUtilityMethodsRepository.GetSysParameterValue. - If OFF, execute the existing customer-specific query.
- If ON, execute the category-based query joining with
partymst:SELECT TOP 1 P.price AS rate, P.MRP, P.factor AS pricemstfactor FROM pricemst P INNER JOIN partymst PM ON P.partyid = PM.partyid WHERE P.itemid = @itemId AND PM.categorycode = (SELECT categorycode FROM partymst WHERE partyid = @partyId) AND P.Brandid = @brandId AND P.Currency = @currency ORDER BY P.Updatedon DESC, P.id DESC
- Check the
SalesOrder1Import:- Check the
FetchRateAsPerCategoryparameter. - Dynamically adjust the SQL CTE
updateTempDataquery join condition for pricing:- If ON: Match
PriceMst.partyidviapartymstcategory code:OUTER APPLY(SELECT TOP 1 price,mrp,factor FROM pricemst P INNER JOIN partymst PM ON P.partyid = PM.partyid WHERE P.itemid = T.itemid AND P.brandid = T.brandid AND P.currency = T.Currency AND PM.categorycode = (SELECT categorycode FROM partymst WHERE partyid = T.partyid) ORDER BY updatedon DESC ) X - If OFF: Use the existing customer ID match:
OUTER APPLY(SELECT TOP 1 price,mrp,factor FROM pricemst P WHERE P.itemid = T.itemid AND P.brandid = T.brandid AND P.currency = T.Currency AND P.partyid = T.partyid ORDER BY updatedon DESC ) X
- If ON: Match
- Check the
[MODIFY] SalesOrderController.cs
SalesOrder1ValidateCreate:- If
FetchRateAsPerCategoryis ON and the retrieved price is null or 0:- Validate if the customer actually has a category code assigned in
partymst. If not, add a descriptive error:"Customer Category is not assigned for this Customer. Cannot fetch rate." - Otherwise, append the custom message:
"Rate is not available in Price Master for any Customer in the same Customer Category. Are you missing the brand/currency?"
- Validate if the customer actually has a category code assigned in
- If
3. Other Impacted Modules & Reports
[MODIFY] AdvanceLicenseRepository.cs
GetRate: Update to respect theFetchRateAsPerCategorysystem parameter. If enabled, queryPriceMstjoining withpartymstto match the customer category:SELECT TOP 1 {selectQuery} AS rate FROM pricemst P INNER JOIN partymst PM ON P.partyid = PM.partyid WHERE P.itemid = @itemId AND PM.categorycode = (SELECT categorycode FROM partymst WHERE partyid = @partyId) AND P.Brandid = @brandId AND P.Currency = @exportCurrency ORDER BY P.updatedon DESC, P.id DESC
[MODIFY] SalesAnalysisReportRepository.cs
- Update the
pricemstouter apply join in the Sales Return/Rejection report query to join withpartymstand match categories when the parameter is ON:OUTER APPLY (SELECT TOP 1 price FROM pricemst P INNER JOIN partymst PM ON P.partyid = PM.partyid WHERE Currency='INR' AND S1.Itemid = P.itemid AND PM.categorycode = (SELECT categorycode FROM partymst WHERE partyid = S.partyid) AND S1.Brandid = P.brandid ORDER BY Updatedon DESC,id DESC ) X
Verification Plan
Automated Tests
- No automated test project exists in this workspace.
Manual Verification
- Database Script Verification: Run the migration script and ensure the
FetchRateAsPerCategorysystem parameter is inserted. - Settings UI Check: Navigate to
System Parameterspage and verify that the new parameterFetchRateAsPerCategoryshows up with default valueNo. - Standard Pricing Behavior (Parameter OFF):
- Create a Sales Order line. Confirm rates are fetched from
PriceMstmatching the customer’s ID.
- Create a Sales Order line. Confirm rates are fetched from
- Category Pricing Setup:
- Verify Category
'01'exists, and both Customer A and Customer B are assigned to Category'01'. - Setup a price record in Price Master for Customer B.
- Toggle the parameter
FetchRateAsPerCategorytoYeson the system parameter screen.
- Verify Category
- Category Pricing Behavior (Parameter ON):
- Create a Sales Order line for Customer A. Verify that the rate is fetched successfully (it matches the price defined for Customer B because they share Category
'01'). - Verify that trying to create a line for a customer without an assigned category fails with:
"Customer Category is not assigned for this Customer. Cannot fetch rate."
- Create a Sales Order line for Customer A. Verify that the rate is fetched successfully (it matches the price defined for Customer B because they share Category
- Re-update Rate Check:
- On the line details page of a line belonging to Customer A, click “Update Rate/MRP” and verify that it correctly fetches/updates the rate based on Customer B’s price master record.
- Bulk Import Check:
- Import Sales Order lines using Excel import and verify that category-based price matching works during bulk uploads.
- Regression Check:
- Turn the parameter back to
Noand verify standard customer pricing is restored.
- Turn the parameter back to