Rentproducts Documentation
Rent Products Controller Documentation
File: /controllers/rentproducts.php
Purpose: Manages rental products inventory including purchase, rental pricing, and lifecycle management
Last Updated: December 20, 2024
Total Functions: 8
Lines of Code: ~460
---
๐ Overview
The Rent Products Controller manages a specialized rental inventory system for products that are purchased and then rented out to customers. It handles the complete lifecycle from product acquisition to rental management, including financial transactions for both cash and credit purchases.
Primary Functions
- โ Add new rental products with purchase details
- โ Manage rental pricing and availability
- โ Track product quantities and rental status
- โ Handle cash and supplier credit purchases
- โ Update rental product information
- โ Soft delete rental products
- โ Integration with accounting system (daily entries)
- โ Supplier debt management
Related Controllers
- โข supplierController.php - Supplier management
- โข saveController.php - Cash management
- โข dailyentry.php - Accounting entries
---
๐๏ธ Database Tables
Primary Tables (Direct Operations)
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **rentproduct** | Rental products master | id, name, buyprice, rentprice, quantity, paytype, supplierid, totalprice, createdate, isdel, dailyentryid | |
| **rentstore** | Rental inventory tracking | id, rentproductid, amount, rented |
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **save** | Cash registers/safes | saveid, savename, savecurrentvalue, treeId | |
| **savedaily** | Cash transaction log | savedailyid, saveid, savedailychangeamount, savedailychangetype, processname, savedailymodelid | |
| **supplier** | Suppliers master data | supplierid, suppliername, suppliercurrentDebt, treeId | |
| **supplierdebtchange** | Supplier debt transactions | supplierdebtchangeid, supplierid, supplierdebtchangeamount, supplierdebtchangetype, tablename |
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **dailyentry** | Journal entries | dailyentryid, entryComment, reverseofid | |
| **dailyentrycreditor** | Credit entries | dailyentrycreditorid, dailyentryid, accountstreeid, value | |
| **dailyentrydebtor** | Debit entries | dailyentrydebtorId, dailyentryid, accountstreeid, value | |
| **accountstree** | Chart of accounts | accountstreeid, accountname |
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **youtubelink** | Tutorial videos | youtubelinkid, title, url | |
| **programsettings** | System configuration | programsettingsid, settingkey, settingvalue |
๐ Key Functions
1. Default Action - Add Form Display
Location: Lines 113-121
Purpose: Display form for adding new rental products
Process Flow:
1. Load all suppliers for dropdown
2. Display add form template
3. Include authentication check
Template: rent/products/add.html
---
2. add() - Add New Rental Product
Location: Lines 122-315
Purpose: Create new rental product with financial transactions
Function Signature:
// POST Parameters
$name = filter_input(INPUT_POST, 'name');
$info = filter_input(INPUT_POST, 'info');
$amount = filter_input(INPUT_POST, 'amount');
$buyprice = filter_input(INPUT_POST, 'buyprice');
$totalprice = filter_input(INPUT_POST, 'totalprice');
$rentprice = filter_input(INPUT_POST, 'rentprice');
$paytype = filter_input(INPUT_POST, 'paytype'); // 0=cash, 1=credit
$supplierid = filter_input(INPUT_POST, 'supplierid');
Process Flow:
1. Duplicate Check: Verify product name doesn't exist
2. Product Creation: Insert into rentproduct table
3. Inventory Setup: Create rentstore record with quantity
4. Payment Processing:
- Cash Payment (paytype=0):
- Decrease save balance
- Update save daily report
- Create accounting entry (Debit: Purchases, Credit: Cash)
- Credit Payment (paytype=1):
- Increase supplier debt
- Log supplier debt change
- Create accounting entry (Debit: Purchases, Credit: Supplier)
5. Update Product: Link daily entry ID to product
Accounting Entries:
// Cash Purchase
Debit: Purchases (Account ID: 12) = $totalprice
Credit: Cash Save (Account: save->treeId) = $totalprice
// Credit Purchase
Debit: Purchases (Account ID: 12) = $totalprice
Credit: Supplier (Account: supplier->treeId) = $totalprice
Validation:
- โข Duplicate name prevention
- โข Required field validation
- โข Numeric validation for prices and quantities
---
3. show() - Display Rental Products List
Location: Lines 316-326
Purpose: Show all non-deleted rental products with management options
Process Flow:
1. Query all active rental products (isdel = 0)
2. Load YouTube tutorial links
3. Display with delete/edit controls
Template: rent/products/show.html
---
4. edit() - Edit Form Display
Location: Lines 327-337
Purpose: Display edit form for existing rental product
Process Flow:
1. Load product data by ID
2. Load suppliers for dropdown
3. Display edit form
Template: rent/products/edit.html
---
5. update() - Update Rental Product
Location: Lines 349-423
Purpose: Update rental product information with accounting adjustments
Function Signature:
$name = filter_input(INPUT_POST, 'name');
$info = filter_input(INPUT_POST, 'info');
$buyprice = filter_input(INPUT_POST, 'buyprice');
$totalprice = filter_input(INPUT_POST, 'totalprice');
$rentprice = filter_input(INPUT_POST, 'rentprice');
$id = filter_input(INPUT_POST, 'id');
Process Flow:
1. Load Original Product: Get existing product data
2. Reverse Original Entry: Reverse existing daily entry
3. Create New Entry: Generate new accounting entry based on payment type
4. Update Product: Save new product information
5. Transaction Management: Commit or rollback on error
Key Features:
- โข Accounting entry reversal and recreation
- โข Price update capability
- โข Transaction safety with rollback
---
6. tempdelete() - Soft Delete Product
Location: Lines 424-445
Purpose: Soft delete rental product and reverse accounting entries
Process Flow:
1. Mark product as deleted (isdel = 1)
2. Reverse associated daily entry
3. Transaction safety with commit/rollback
Note: This is a soft delete - product remains in database but marked as deleted
---
๐ Workflows
Workflow 1: Cash Purchase Rental Product
---
Workflow 2: Supplier Credit Purchase
---
๐ URL Routes & Actions
| URL Parameter | Function Called | Description | |
|---|---|---|---|
| (empty) | Default action | Display add form | |
| `do=add` | `add()` | Process new product creation | |
| `do=show` | `show()` | Display products list | |
| `do=edit` | `edit()` | Display edit form | |
| `do=editprint` | Print edit | Display print-friendly edit | |
| `do=update` | `update()` | Process product updates | |
| `do=tempdelete` | `tempdelete()` | Soft delete product | |
| `do=sucess` | Success | Show success page | |
| `do=error` | Error | Show error page |
Add Product (do=add):
- โข
name- Product name (required, unique) - โข
info- Product description - โข
amount- Initial quantity - โข
buyprice- Purchase price per unit - โข
totalprice- Total purchase cost - โข
rentprice- Rental price per period - โข
paytype- Payment type (0=cash, 1=credit) - โข
supplierid- Supplier ID
Edit Product (do=edit):
- โข
id- Product ID
Update Product (do=update):
- โข
id- Product ID - โข
name- Updated product name - โข
buyprice- Updated purchase price - โข
rentprice- Updated rental price - โข
totalprice- Updated total price
Delete Product (do=tempdelete):
- โข
id- Product ID - โข
dailyentryid- Daily entry ID to reverse
---
๐งฎ Calculation Methods
Purchase Cost Calculation
// Total cost validation
$totalprice = $buyprice * $amount; // Should match user input
Cash Flow Management
// Cash purchase impact
$balanceBefore = $saveinfo->savecurrentvalue;
$balanceAfter = $balanceBefore - $totalprice;
// Validation check
if ($balanceAfter < 0) {
// Insufficient funds error
}
Supplier Debt Calculation
// Credit purchase impact
$debtBefore = $supplierinfo->suppliercurrentDebt;
$debtAfter = $debtBefore + $totalprice;
Rental Profitability
// Break-even calculation (implied)
$breakEvenRentals = $buyprice / $rentprice;
---
๐ Security & Permissions
Authentication
include_once("../public/authentication.php");
- โข All actions require valid user session
- โข Session-based user ID tracking
Input Validation
$name = filter_input(INPUT_POST, 'name');
$amount = filter_input(INPUT_POST, 'amount');
$buyprice = filter_input(INPUT_POST, 'buyprice');
- โข PHP filter_input() for basic sanitization
- โข Duplicate name prevention
- โข Numeric validation for prices
Data Integrity
- โข Transaction management with commit/rollback
- โข Accounting entry reversal on updates/deletes
- โข Soft delete preservation of historical data
---
๐ Performance Considerations
Database Optimization
1. Indexes Recommended:
- rentproduct(name) for duplicate checking
- rentproduct(isdel) for active product queries
- rentstore(rentproductid) for inventory lookups
- supplierdebtchange(supplierid, tablename) for debt tracking
2. Query Efficiency:
- Single product insert per transaction
- Batch operations for related tables
- Proper use of transactions
Memory Management
- โข Minimal data loading in forms
- โข Efficient supplier dropdown loading
- โข Clean object instantiation
Known Performance Issues
// Potential issue: Loading all suppliers for dropdown
$suppliers = $mysupplier->queryAll();
// Consider pagination for large supplier lists
---
๐ Common Issues & Troubleshooting
1. Duplicate Product Names
Issue: Error when adding products with existing names
Cause: Duplicate check in add() function
Solution:
$checkduplicate = $myrentProducts->queryByName($name);
if (count($checkduplicate) > 0) {
// Handle duplicate error
}
2. Insufficient Cash Balance
Issue: Cash purchases failing with negative balance
Cause: No balance validation before save update
Debug:
SELECT savecurrentvalue FROM save WHERE saveid = [SESSION_SAVE_ID];
3. Accounting Entry Imbalance
Issue: Debit/Credit entries don't balance
Cause: Incorrect account tree ID assignment
Fix:
// Verify account tree IDs exist
$saveTreeId = $dataSave->treeId; // Cash account
$supplierTreeId = $oldSupplier->treeId; // Supplier account
4. Transaction Rollback Issues
Issue: Partial data saved when errors occur
Cause: Missing transaction management
Fix:
$mytransactions = new Transaction();
try {
// Operations here
$mytransactions->commit();
} catch (Exception $exc) {
$mytransactions->rollback();
}
---
๐งช Testing Scenarios
Test Case 1: Cash Purchase
1. Select supplier and enter product details
2. Choose cash payment (paytype=0)
3. Verify sufficient save balance
4. Submit form
5. Check: Product created, inventory updated, cash decreased, accounting entry created
Test Case 2: Credit Purchase
1. Enter product details
2. Choose credit payment (paytype=1)
3. Submit form
4. Check: Product created, supplier debt increased, accounting entry created
Test Case 3: Product Update
1. Edit existing product
2. Change prices
3. Verify old accounting entry reversed
4. Check new accounting entry created
Test Case 4: Product Deletion
1. Delete active product
2. Verify product marked isdel=1
3. Check accounting entry reversed
4. Verify product no longer appears in lists
Debug Mode Enable
// Add at top of file for debugging
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Debug accounting entries
echo "Daily Entry ID: " . $dailyId . "<br>";
echo "Total Price: " . $totalprice . "<br>";
---
๐ Related Documentation
- โข CLAUDE.md - PHP 8.2 migration guide
- โข supplierController.php - Supplier management
- โข saveController.php - Cash management
- โข dailyentry.php - Accounting system
- โข Database Schema Documentation - Table relationships
---
Documented By: AI Assistant
Review Status: โ Complete
Next Review: When major changes occur