Source Code: PosDiscount.cpp See also discount() PosCommand
Execution
Source Ref: PosDiscount::Go()
- Verify a sale has been passed in. Abort if not.
- Create FlowDataBase "PosDiscount", and record the command.
- Extract the name of the discount, selecting all characters until a delimiter (space is a delimiter and not permitted in disc_name field)
- If the name is "select" call discountSelect screen. If the result of this is to remove discounts, issue the corresponding "cleardiscount" PosCommand and exit
- Query the database using discounts.disc_name. If the name is not found in database log flow error 1219170628 and exit
- Verify the line syntax is correct and log flow error 1219170608 if something is wrong, but continue processing anyway
- Uniform discounts:
- Verify the requested amount is not 0. Exit if 0.
- If the setting DiscountMaxUniform is present, exit if the requested amount is greater than this.
- If the setting DiscountMinUniform is present, exit if the requested amount is less than this.
- Percentage discounts:
- If the setting DiscountInteger is set (default=yes) then Fetch "long1". If this is 0, then convert the param field to the percentage then divide by "long2" (0 is treated as 1)
- Otherwise fetch "long1" as a double, if 0 converting param field to the percentage and then divide by "long2" (0 is treated as 1) using floating point operations. Set the processing mode to float-mode.
- If the percentage rate is greater than the setting DiscountMaxPercentage (default 100.00), the exit and do not apply
- If the percentage rate is less than the setting DiscountMinPercentage (default 0.01), the exit and do not apply
- Other types of discounts, preload various values. If the discount type is unknown, log flow error 1220170628 and exit.
- Store any "if" conditions present on the discount into the call arguments. They are only stored at this time, not evaluated.
- Transfer control to Sale-Add-Discount to apply the decoded discount
Sale-Add-Discount
Source Ref: Sale::AddDiscount()
- Log flow point 804160728
- If the requested line is "0" (sale wide discount) and the setting SaleDiscAutoAllLine is defined, the line is changed to -2
- If the was 0 the setting SaleDiscNoSale is set, exit without applying