Resetdiscount Documentation
Reset Discount Controller Documentation
File: /controllers/resetdiscount.php
Purpose: Utility controller for fixing restaurant discount calculations on specific dates
Last Updated: December 20, 2024
Total Functions: 2
Lines of Code: ~60
---
๐ Overview
The Reset Discount Controller is a specialized utility for correcting restaurant discount calculations. It handles:
- โข Restaurant-specific discount correction operations
- โข Date-based discount fixes
- โข YouTube tutorial link display
- โข Administrative discount maintenance
- โข Batch discount recalculation
- โข Error correction for discount misapplications
Primary Functions
- โ Fix restaurant discounts for specific dates
- โ Display helpful tutorial videos
- โ Administrative interface for discount maintenance
- โ Batch correction of discount calculations
- โ User permission validation
- โ Results reporting and feedback
Related Controllers
- โข sellbillController.php - Sales bill operations
- โข restaurantController.php - Restaurant operations
- โข discountController.php - General discount management
- โข billController.php - Bill management
---
๐๏ธ Database Tables
Primary Tables (Indirect Operations)
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **sellbill** | Sales bills with discount data | sellbillid, sellbilldiscount, sellbilldiscounttype, sellbilldate, sellbilltotalbill | |
| **youtubelink** | Tutorial video links | youtubelinkid, title, url, category |
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **sellbilldetail** | Bill line items | sellbilldetailid, sellbillid, sellbilldetailprice, sellbilldetaildiscount | |
| **programsettings** | System configuration | programsettingsid, settingkey, settingvalue | |
| **user** | System users | userid, username, usergroupid | |
| **usergroup** | User permissions | usergroupid, groupname, permissions |
๐ Key Functions
1. Default Action (empty $do) - Discount Fix Interface
Location: Line 39
Purpose: Display interface for fixing restaurant discounts with date selection
Process Flow:
1. Check user authentication and permissions
2. Process discount fix if date provided
3. Load YouTube tutorial links for assistance
4. Display fix interface template
5. Show results if operation performed
Function Logic:
$billdate = filter_input(INPUT_POST, "billdate");
if (isset($billdate) && !empty($billdate)) {
$rowsAffected = $sellbillEX->fixDiscountRestaurantFatma($billdate);
$smarty->assign("rowsAffected", $rowsAffected);
}
Features:
- โข Date input validation
- โข Results feedback display
- โข Tutorial integration
- โข Permission checking
---
2. fixDiscountRestaurantFatma() - Core Fix Logic
Location: Called from SellbillMySqlExtDAO
Purpose: Execute restaurant-specific discount corrections
Process Flow:
1. Query sales bills for specified date
2. Identify discount calculation errors
3. Apply corrected discount formulas
4. Update affected records
5. Return count of rows modified
Expected Corrections:
- โข Percentage vs fixed amount discount corrections
- โข Tax calculation adjustments
- โข Total bill amount recalculations
- โข Discount type standardization
---
๐ Workflows
Workflow 1: Discount Correction Process
---
๐ URL Routes & Actions
| URL Parameter | Function Called | Description |
|---|---|---|
| `do=` (empty) | Default action | Show discount fix interface |
POST Data:
- โข
billdate- Target date for discount corrections (YYYY-MM-DD)
---
๐ Security & Permissions
Access Control
include_once("../public/authentication.php");
Security Features:
- โข User authentication required
- โข Session validation
- โข Input filtering with
filter_input(INPUT_POST) - โข Protected administrative function
Permission Requirements
- โข Must be logged in user
- โข Administrative access level typically required
- โข Date modification permissions needed
---
๐งฎ Discount Fix Logic
Restaurant-Specific Corrections
The fixDiscountRestaurantFatma() function likely corrects:
1. Discount Type Mismatches:
-- Fix percentage discounts calculated as fixed amounts
UPDATE sellbill SET
sellbillaftertotalbill = sellbilltotalbill - (sellbilltotalbill * sellbilldiscount / 100)
WHERE sellbilldiscounttype = 0 AND sellbilldate = ?
```
2. **Fixed Amount Corrections**:
```sql
-- Fix fixed discounts
UPDATE sellbill SET
sellbillaftertotalbill = sellbilltotalbill - sellbilldiscount
WHERE sellbilldiscounttype = 1 AND sellbilldate = ?
```
3. **Tax Recalculations**:
```sql
-- Recalculate tax on corrected amounts
UPDATE sellbill SET
tax_amount = (sellbillaftertotalbill * tax_rate / 100)
WHERE sellbilldate = ?
```
---
## ๐ Performance Considerations
### Batch Operation Impact
- Processes all bills for specified date
- May affect hundreds or thousands of records
- Database locks during updates
- Potential timeout for large date ranges
### Optimization Strategies
1. **Index Usage**:
- Ensure index on `sellbill(sellbilldate)`
- Consider composite index for discount operations
2. **Batch Size Management**:
- Process in smaller batches if needed
- Add progress feedback for large operations
---
## ๐ Common Issues & Troubleshooting
### 1. **No Rows Affected**
**Issue**: Fix operation returns 0 rows affected
**Possible Causes**:
- No bills exist for selected date
- Bills already have correct discount calculations
- Date format incorrect
**Debug Steps**:
sql
-- Check if bills exist for date
SELECT COUNT(*) FROM sellbill WHERE DATE(sellbilldate) = 'YYYY-MM-DD';
-- Check discount types and values
SELECT sellbillid, sellbilldiscount, sellbilldiscounttype,
sellbilltotalbill, sellbillaftertotalbill
FROM sellbill WHERE DATE(sellbilldate) = 'YYYY-MM-DD';
### 2. **Timeout Errors**
**Issue**: Operation times out on large datasets
**Solution**: Process smaller date ranges or implement batch processing
### 3. **Permission Denied**
**Issue**: User cannot access fix function
**Solution**: Verify user has administrative permissions
---
## ๐งช Testing Scenarios
### Test Case 1: Basic Discount Fix
1. Create test bills with incorrect discounts
2. Run fix for specific date
3. Verify discount calculations corrected
4. Check row count matches expected
### Test Case 2: Edge Cases
1. Test with date having no bills
2. Test with already correct discounts
3. Test with invalid date formats
4. Verify appropriate responses
### Test Case 3: Performance Testing
1. Create large number of bills for test date
2. Monitor execution time
3. Verify all records processed
4. Check database performance impact
---
## ๐ก Tutorial Integration
### YouTube Links Feature
php
$youtubes = $youtubeLinkDAO->queryAll();
$smarty->assign("youtubes", $youtubes);
```
Purpose:
- โข Provide instructional videos
- โข Guide users through discount fix process
- โข Document common scenarios and solutions
Display Options:
- โข Video thumbnails
- โข Tutorial titles
- โข Category-based organization
- โข Direct video links
---
๐ Business Context
When to Use This Tool
1. After System Updates: When discount calculation logic changes
2. Data Migration: After importing bills with incorrect discounts
3. Error Correction: When bugs in discount calculation are discovered
4. Audit Compliance: To ensure consistent discount application
5. Restaurant Specific Issues: Address unique restaurant discount scenarios
Typical Scenarios
- โข Percentage vs Fixed Mix-ups: Bills with wrong discount type
- โข Tax Base Errors: Tax calculated on wrong amount
- โข Rounding Issues: Discount calculations with precision problems
- โข Multiple Discount Conflicts: Bills with conflicting discount rules
---
๐ Related Documentation
- โข CLAUDE.md - PHP 8.2 migration guide
- โข sellbillController.md - Sales operations
- โข SellbillMySqlExtDAO.class.php - Extended discount functions
- โข Restaurant Operations Guide - Restaurant-specific features
---
Documented By: AI Assistant
Review Status: โ Complete
Next Review: When major changes occur