Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Matrix rate
Message
From
27/06/1999 21:52:50
 
 
To
27/06/1999 20:53:30
Dovi Gilberd
Dovtware Consulting Inc
Miami, Florida, United States
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Miscellaneous
Thread ID:
00233562
Message ID:
00234604
Views:
28
>hi barbara...pleeeeaaase help me out..im stil with this dilema.......
>ppplllllleeeeeaaaassse,,,Thank you Dovi

Let me give you a model that you might be able to adapt from a real-world scenario in one of my applications; you may be able to adapt this to your situation.

In a relatively simplistic model of discounting for my company's order processing system, the discount for a given order is based on two things, the classification of the customer, and the total number of line items ordered. The customer record contains a classification code for the customer - wholesaler, bookstore, library, university, etc. I ensure that every customer has a valid classification in the customer record.

For any given classification, there's a discount based on the total number of items ordered on the customer's PO. There is no fixed set of breaks, for example, wholesalers receive a 5% discount on orders up to 10 items, a 30% discount on orders for 11-100 items, and a 40% discount for orders that exceed 100 items. Individuals get no discount regardless of the number of items ordered. Bookstores get a 10% discount on orders for 1-4 items, 15% for 5-10 items, 20% for 11-25 items, and 25% for an order for more than 25 items.

I have a table containing the matrix of discounts, with four fields in the table; a classification code 4 characters wide (custclass), a minimum quantity (min_oqty), a maximum quantity (max_oqty) and a discount (StdDisc). The table looks something like this
 Table DISCRATE
CLASS  MIN   MAX   DISC
BKST   1     4     10.00
BKST   5     10    15.00
BKST   15    25    20.00
BKST   26    9999  25.00
INDI   1     9999  0.00
WHOL   1     10    5.00
WHOL   11    100   30.00
WHOL   101   9999  40.00
I have a Discount calculation function GetDisc, which takes two arguments, a classification code and the number of items ordered, and it returns either a discount percentage, or NULL if there's no matching discounting record. The routine that calls the function is expected to check for a NULL return to see if an unsupported combination is submitted:
FUNCTION GetDisc
LPARAMETERS cCustClass, nQtyItems
IF ! VARTYPE(cCustClass) = 'C'
    ASSERT  .F. Message 'Customer class is not type C'
    RETURN NULL
ENDIF
IF ! VARTYPE(nQtyItems) = 'N'
   ASSERT  .F. Message 'Quantity is not a numeric value'
   RETURN NULL
ENDIF
IF ! BETWEEN(nQtyItems,1,9999)
   ASSERT .F. Message 'Quantity out of range supported'
   RETURN NULL
ENDIF
LOCAL lcInAlias
lcInAlias = ALIAS()
IF ! USED('DiscMat')
   USE DiscMat IN 0 AGAIN ALIAS DiscMat SHARED
ENDIF
SELECT DiscMat
LOCATE FOR cCustClass == UPPER(cCustClass) AND BETWEEN(nQtyItems,min_oqty, max_oqty)
LOCAL nDiscount
IF ! FOUND()
   ASSERT .F. MESSAGE 'The tuple >' + cCustClass + STR(nQtyItems) + '< not in Discmat'
   nDiscount = NULL
ELSE
   nDiscount = Discmat.StdDisc
ENDIF
IF ! EMPTY(lcInAlias)
   SELECT lcInAlias
ELSE
   SELECT 0
ENDIF
RETURN nDiscount
The ASSERTs give me valuable debugging information, and can bring up the debugger running under VFP's development version if an error I trap for occurs, helping me with debugging the code. ASSERT doesn't cost anything run outside the development environment

Hopefully, you can adapt this concept to what you're doing by normalizing the table containing your matrix, and using similar strategies for finding the right discount matrix entry.
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Reply
Map
View

Click here to load this message in the networking platform