Rentava Documentation
Rent Availability Controller Documentation
File: /controllers/rentava.php
Purpose: Displays rental product availability and rental store status for equipment and product rental operations
Last Updated: December 20, 2024
Total Functions: 1
Lines of Code: ~145
---
๐ Overview
The Rent Availability Controller is a simple display controller that provides visibility into the rental inventory system. It shows available rental products and displays the rental store history, giving users an overview of what equipment/products are available for rental and their rental history. This controller is part of the rental management system separate from real estate operations.
Primary Functions
- โ Display available rental products
- โ Show rental store status and history
- โ Product name resolution for rental items
- โ Basic rental inventory overview
- โ Integration with rental product management
Related Controllers
- โข rentproduct.php - Rental product management
- โข rentstore.php - Rental inventory management
- โข rentbill.php - Rental billing operations
- โข rentdelays.php - Rental delay tracking
---
๐๏ธ Database Tables
Primary Tables (Read-Only Operations)
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **rentproducts** | Rental product master data | rentproductid, name | |
| **rentstore** | Rental inventory status | id, rentproductid, status, dates |
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **supplier** | Equipment suppliers | supplierid, suppliername | |
| **client** | Rental customers | clientid, clientname | |
| **save** | Cash registers/safes | saveid, savename | |
| **rentbill** | Rental bills | rentbillid, clientid | |
| **rentbillprop** | Rental bill properties | id, billid, productid |
| DAO Class | Entity | Purpose | |
|---|---|---|---|
| **RentproductMySqlDAO** | Rentproduct | Product data access | |
| **RentstoreMySqlDAO** | Rentstore | Store data access | |
| **SupplierMySqlDAO** | Supplier | Supplier data access | |
| **ClientMySqlDAO** | Client | Client data access | |
| **SaveMySqlDAO** | Save | Save data access | |
| **RentbillMySqlDAO** | Rentbill | Bill data access | |
| **RentbillpropMySqlDAO** | Rentbillprop | Bill properties access |
๐ Key Functions
1. Default Action - Rental Availability Display
Location: Line 117
Purpose: Displays the main rental availability interface with product list and store history
Function Signature:
// Triggered when: do parameter is empty
if (empty($do))
Process Flow:
1. Initialize DAO Objects - Create all necessary data access objects
2. Load Authentication - Include permission checks
3. Query Rental Products - Get all available rental products
4. Query Store History - Get all rental store records
5. Enhance Store Data - Add product names to store records
6. Assign Template Variables - Pass data to Smarty template
7. Display Template - Show rental availability interface
DAO Initialization:
// Rental-specific DAOs
$rentProducts = new Rentproduct();
$myrentProducts = new RentproductMySqlDAO();
$extrentProducts = new RentproductMySqlExtDAO();
$rentStore = new Rentstore();
$myrentStore = new RentstoreMySqlDAO();
$extrentStore = new RentstoreMySqlExtDAO();
// Supporting DAOs
$supplier = new Supplier();
$client = new Client();
$save = new Save();
$rentbill = new Rentbill();
$rentbillpro = new Rentbillprop();
Data Processing:
// Get all rental products
$products = $myrentProducts->queryAll();
// Get all rental store records
$allpros = $myrentStore->queryAll();
// Enhance store records with product names
foreach ($allpros as $sinpro) {
$productinfo = $myrentProducts->load($sinpro->rentproductid);
$sinpro->productname = $productinfo->name;
}
Template Assignment:
$smarty->assign('products', $products);
$smarty->assign('allpros', $allpros);
$smarty->assign('showsearch', 1);
$smarty->display("rent/reports/rentava.html");
---
๐ Workflows
Workflow 1: Rental Availability Check
---
๐ URL Routes & Actions
| URL Parameter | Function Called | Description |
|---|---|---|
| `do=` (empty) | Default display | Show rental availability interface |
Product Data:
- โข
$products- Array of all rental products - โข
$allpros- Array of rental store records with product names - โข
$showsearch- Flag to enable search functionality (set to 1)
Global Variables:
- โข
$rentjs- JavaScript flag for rental functionality (set to 1) - โข
$Programsettingdata- System configuration settings
---
๐งฎ Calculation Methods
Product Name Resolution
foreach ($allpros as $sinpro) {
$productinfo = $myrentProducts->load($sinpro->rentproductid);
$sinpro->productname = $productinfo->name;
}
Search Functionality Setup
$showsearch = 1;
$smarty->assign('showsearch', $showsearch);
---
๐ Security & Permissions
Authentication Check
include_once("../public/authentication.php");
Global Security Includes
include("../public/impOpreation.php"); // Main operations file
include_once("../public/config.php"); // Configuration
include("../public/include_dao.php"); // DAO includes
Session Management
- โข Relies on session management from
impOpreation.php - โข Uses global authentication system
- โข No controller-specific permission checks
---
๐ Performance Considerations
Database Queries
1. Query Patterns:
- Simple queryAll() operations on rental tables
- Individual load() operations in loop for product names
- No complex joins or aggregations
2. Optimization Opportunities:
- Could optimize product name lookup with single JOIN query
- Consider caching product data for frequently accessed items
Current Implementation:
// Less efficient: N+1 query pattern
$allpros = $myrentStore->queryAll();
foreach ($allpros as $sinpro) {
$productinfo = $myrentProducts->load($sinpro->rentproductid); // Individual query per item
$sinpro->productname = $productinfo->name;
}
Optimized Alternative:
-- Single query approach
SELECT rs.*, rp.name as productname
FROM rentstore rs
LEFT JOIN rentproducts rp ON rs.rentproductid = rp.rentproductid;
Memory Usage
- โข Loads all rental products into memory
- โข Loads all rental store records into memory
- โข For large rental inventories, consider pagination
---
๐ Common Issues & Troubleshooting
1. Missing Product Names
Issue: Store records show without product names
Cause: Broken foreign key relationships or missing product records
Debug:
-- Check for orphaned store records
SELECT rs.id, rs.rentproductid, rp.rentproductid as product_exists
FROM rentstore rs
LEFT JOIN rentproducts rp ON rs.rentproductid = rp.rentproductid
WHERE rp.rentproductid IS NULL;
Fix:
-- Remove orphaned records or add missing products
DELETE FROM rentstore WHERE rentproductid NOT IN (SELECT rentproductid FROM rentproducts);
2. Empty Product List
Issue: No products appear in availability list
Cause: Empty rentproducts table or DAO connection issues
Debug:
-- Check product table
SELECT COUNT(*) as product_count FROM rentproducts;
SELECT * FROM rentproducts LIMIT 5;
3. Template Display Issues
Issue: Page loads but shows no data
Cause: Template path issues or variable assignment problems
Debug:
// Add before template display
echo "Products count: " . count($products) . "<br>";
echo "Store records count: " . count($allpros) . "<br>";
var_dump($products);
4. DAO Initialization Errors
Issue: Fatal errors on DAO object creation
Cause: Missing DAO class files or incorrect include paths
Check:
// Verify DAO files exist
file_exists('../models/mysql/RentproductMySqlDAO.class.php');
file_exists('../models/mysql/RentstoreMySqlDAO.class.php');
---
๐งช Testing Scenarios
Test Case 1: Basic Functionality
1. Navigate to rentava.php (no parameters)
2. Verify page loads without errors
3. Check that product list displays
4. Verify store records show with product names
5. Confirm search functionality is enabled
Test Case 2: Data Integrity
1. Check that all store records have corresponding products
2. Verify product names are correctly resolved
3. Test with empty product table
4. Test with empty store table
5. Verify graceful handling of missing data
Test Case 3: Performance
1. Test with large number of products (100+)
2. Test with large number of store records (1000+)
3. Measure page load time
4. Check memory usage
5. Verify responsiveness with large datasets
Debug Mode Enable
// Add at top of controller for debugging
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Debug data loading
echo "<pre>";
print_r($products);
print_r($allpros);
echo "</pre>";
---
๐ Related Documentation
- โข CLAUDE.md - PHP 8.2 migration guide
- โข rentdelays.md - Rental delay tracking
- โข Database Schema Documentation - Rental table relationships
- โข DAO Pattern Documentation - Data access layer information
File Dependencies
Core Includes:
- โข
../public/impOpreation.php- Main operations - โข
../public/config.php- Configuration - โข
../public/include_dao.php- DAO class includes - โข
../public/authentication.php- Permission checks - โข
dailyentryfun.php- Daily entry functions
Template Files:
- โข
header.html- Page header - โข
rent/reports/rentava.html- Main rental availability template - โข
footer.html- Page footer
---
Documented By: AI Assistant
Review Status: โ Complete
Next Review: When rental system changes occur