Skip to main content
Solved

retrieve Discount percent based on price class id and customer

  • November 27, 2024
  • 2 replies
  • 49 views

We are seeking suggestions to modify an existing generic inquiry designed to retrieve the discount percentage based on the InventoryPriceClassId and CustomerId. While it functions correctly in most cases, we are encountering an issue where, for a specific InventoryPriceClassId, we receive four results instead of the expected single result. We require assistance to ensure that only the relevant '15PCTUP' discount code record is returned, corresponding to our specific Item Price class.

 

 

Best answer by arthia98

Hi ​@erpdev11 , Add “DiscountInventoryPriceClass.inventoryPriceClassID” in Grouping
In Conditions tab, you can add  '15PCTUP' for Discountcode

 

View original
Did this topic help you find an answer to your question?

2 replies

Forum|alt.badge.img+1
  • Jr Varsity III
  • 81 replies
  • Answer
  • November 28, 2024

Hi ​@erpdev11 , Add “DiscountInventoryPriceClass.inventoryPriceClassID” in Grouping
In Conditions tab, you can add  '15PCTUP' for Discountcode

 


saifalisabri
Jr Varsity II
Forum|alt.badge.img
  • Jr Varsity II
  • 47 replies
  • November 28, 2024

My response was crafted with AI assistance, tailored to provide detailed and actionable guidance for your query.

Response 1

To address the issue of retrieving the correct discount percentage (DiscountPercent) based on InventoryPriceClassId and CustomerId in your Generic Inquiry (GI), the problem likely lies in either the joins or the conditions not being specific enough to filter out the unwanted results. 

1. Inspect the Discount Table Relationships

  • Verify how the discount codes and percentages are stored in your database.
  • The relevant tables might include:
    • Discount Codes (e.g., ARDiscount or similar)
    • Discount Details (e.g., ARDiscountDetail)
    • Links between discounts, price classes, and customers.

2. Review Current Joins in GI

  • Go to the Relations tab in your GI and confirm the relationships between:
    • InventoryPriceClassId
    • CustomerId
    • Discount tables (like ARDiscount and ARDiscountDetail).
  • Ensure the joins are precise:
    • Use Inner Join for mandatory relationships.
    • Define join conditions explicitly based on InventoryPriceClassId and CustomerId.

3. Apply Specific Conditions

  • On the Conditions tab:
    • Add a filter to ensure only records matching the 15PCTUP discount code are retrieved.
    • Example condition:
      sql  Copy code

      [DiscountCode] = '15PCTUP'

    • Additionally, filter by InventoryPriceClassId and CustomerId to narrow the results further:
      sql  Copy code

      [InventoryPriceClassId] = <Your Specific ID> AND [CustomerId] = <Your Specific Customer>

4. Prioritize Discount Codes

  • If multiple discount codes exist for the same InventoryPriceClassId and CustomerId, you need to prioritize them:
    • Add a Sort Order in the GI, prioritizing DiscountCode or DiscountPercent as required.
    • Example: Sort by DiscountCode in ascending or descending order to ensure 15PCTUP is the first record.

5. Eliminate Redundant Records

  • Use the Group By feature in the GI:
    • In the Schema tab, group by InventoryPriceClassId and CustomerId.
    • Use an aggregate function (e.g., Max or Min) on DiscountPercent to retrieve a single value per group.

6. SQL-Like Condition for Specific Cases

If possible, refine the data source with an SQL-like condition directly:

sql   Copy code

SELECT TOP 1 DiscountPercent FROM DiscountTable WHERE InventoryPriceClassId = '<Your Inventory Price Class>' AND CustomerId = '<Your Customer>' AND DiscountCode = '15PCTUP' ORDER BY DiscountCode ASC

7. Debugging Multiple Results

  • Check for duplicates or overlapping entries in the discount setup:
    • Multiple entries in the discount table for the same InventoryPriceClassId and CustomerId.
  • Ensure the 15PCTUP discount code is correctly linked to the intended inventory price class and customer.

Example GI Setup

Here’s how your GI settings might look:

  • Tables:

    • ARDiscount
    • ARDiscountDetail
    • Customer
    • InventoryPriceClass
  • Conditions:

    1. [InventoryPriceClassId] = <Specific Value>
    2. [CustomerId] = <Specific Customer>
    3. [DiscountCode] = '15PCTUP'
  • Sorting:

    • Add DiscountCode or DiscountPercent for prioritization.

Next Steps

  • Test the refined GI by previewing the results.
  • Confirm the exact InventoryPriceClassId and CustomerId you’re working with, and ensure these are included in the conditions.
  • If this doesn't resolve the issue, the discount setup itself might require adjustments.

My response was crafted with AI assistance, tailored to provide detailed and actionable guidance for your query.

Response 2

To modify your Generic Inquiry (GI) and ensure that only the relevant discount code record (15PCTUP) is returned for a specific InventoryPriceClassId, follow these suggestions:

1. Filter Discount Records by Discount Code

  • Add a Condition to your GI to filter the discount records explicitly for the 15PCTUP discount code.
  • Go to the Conditions tab in the GI and specify:
    • Field: DiscountCode
    • Condition: Equals
    • Value: 15PCTUP

This ensures that only rows with the 15PCTUP discount code are retrieved.

2. Ensure Proper Joins

If the multiple results are caused by incorrect table joins, refine your joins in the Relations tab:

  • Ensure the ARPriceClass table (or its alias) is correctly linked to the relevant tables using:
    • CustomerID (to identify discounts linked to specific customers).
    • InventoryPriceClassID (to filter by item price class).
  • Specify the correct join type (e.g., Inner Join) to limit results to only those with matching entries.

Example:

  • Main Table: DiscountDetail (or equivalent discount table in your schema).
  • Join Conditions:
    • DiscountDetail.InventoryPriceClassID = ARPriceClass.InventoryPriceClassID
    • DiscountDetail.CustomerID = Customer.CustomerID

3. Prioritize Discounts by Specific Criteria

If the 15PCTUP discount isn't the only record in the dataset but should take precedence:

  • Use a calculated field or SQL expression to assign a priority ranking to rows.
  • For example, add a column with logic like:
    vbnet  Copy code

    CASE WHEN DiscountCode = '15PCTUP' THEN 1 ELSE 2 END AS Priority

  • Add a condition or sorting logic to select the highest priority row.

4. Remove Duplicates Using Grouping

If duplicates are still present after applying conditions:

  • Use the Grouping feature in the GI to collapse multiple rows into one.
  • Navigate to the Results Grid tab:
    • Identify the fields needed for grouping (e.g., InventoryPriceClassID, CustomerID).
    • Add these fields as grouping keys.
  • For the DiscountPercent column, set the aggregation method (e.g., MAX, MIN, or FIRST).

5. Advanced Filtering via Custom Expressions

If the issue persists, create a custom calculated field in the GI schema:

  • Use SQL or Acumatica's query syntax to filter results programmatically.
  • Example expression for DiscountPercent:
    sql   Copy code

    (SELECT TOP 1 DiscountPercent FROM DiscountDetail WHERE DiscountCode = '15PCTUP' AND InventoryPriceClassID = Main.InventoryPriceClassID AND CustomerID = Main.CustomerID ORDER BY EffectiveDate DESC)

This ensures only the most relevant record is selected.

Summary of Steps

  1. Add a condition to filter by DiscountCode = '15PCTUP'.
  2. Refine joins to ensure correct linking between tables.
  3. Prioritize results by DiscountCode or other fields (e.g., EffectiveDate).
  4. Use grouping or aggregation to collapse duplicates.
  5. Leverage custom expressions for advanced filtering if required.

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings