Bill Property Controller Documentation
File: /controllers/billpropertyController.php
Purpose: Manages bill properties/types and their settings across different bill templates
Last Updated: December 20, 2024
Total Functions: 8
Lines of Code: ~390
---
๐ Overview
The Bill Property Controller manages bill properties (types) that define characteristics of different bill formats. When a new bill property is created, it automatically generates default settings for all existing bill templates in the system. This ensures consistent property availability across all billing forms and provides a centralized way to manage bill behaviors.
Primary Functions
- โ Create bill properties with automatic settings generation
- โ Display paginated list of properties
- โ Edit property details and descriptions
- โ Soft delete properties with dependency checking
- โ Restore deleted properties
- โ Batch operations on multiple properties
- โ Dependency validation before deletion
- โ Integration with bill settings system
Related Controllers
- โข billTemplateController.php - Bill templates using these properties
- โข sellbillController.php - Sales bills with properties
- โข buyBillController.php - Purchase bills with properties
---
๐๏ธ Database Tables
Primary Tables (Direct Operations)
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **billproperty** | Bill property definitions | billpropertyid, billpropertyname, conditions | |
| **billsettings** | Property settings per bill type | billnameid, billpropertyid, billsettingsvalue | |
| **billname** | Bill template names | billnameid, billname |
| Table Name | Purpose | Key Columns |
|---|---|---|
| **smartypaginate** | Pagination support | Various pagination fields |
๐ Key Functions
1. Default Action - Add Form Display
Location: Line 70-72
Purpose: Display form for creating new bill properties
Process Flow:
1. Display billpropertyview/add.html template
2. Load property creation form interface
---
2. add() - Create Bill Property
Location: Line 164-194
Purpose: Create new bill property and generate default settings for all bill types
Function Signature:
function add()
Process Flow:
$billpropertyname = $_POST['billpropertyname'];
$description = $_POST['description'];
$Billproperty->billpropertyname = $billpropertyname;
$Billproperty->conditions = 0; // Active status
$billpropertyId = $BillpropertyDAO->insert($Billproperty, $description);
Automatic Settings Generation:
$billnameData = $myBillnameRecord->queryAll();
foreach ($billnameData as $billname) {
$billnameId = $billname->billnameid;
$Billsetting->billnameid = $billnameId;
$Billsetting->billpropertyid = $billpropertyId;
$Billsetting->billsettingsvalue = 0; // Default disabled
$BillsettingDAO->insert($Billsetting);
}
Key Features:
- โข Creates property record with description
- โข Automatically creates settings for ALL existing bill types
- โข Sets default value (0 = disabled) for all new settings
- โข Ensures consistent property availability
---
3. show() - Display Properties with Pagination
Location: Line 197-228
Purpose: Display paginated list of bill properties
Function Signature:
function show()
Pagination Setup:
$paginate = new SmartyPaginate;
$paginate->connect();
$paginate->setLimit(50); // 50 items per page
// Get total count
$allColums = $BillpropertyDAO->queryAll();
$paginate->setTotal(count($allColums));
// Get limited results
$qname = $BillpropertyEX->queryAlllimted(
$paginate->getCurrentIndex(),
$paginate->getLimit()
);
Navigation Configuration:
$paginate->setNextText('ุงูุชุงูู'); // Next
$paginate->setPrevText('ุงูุณุงุจู'); // Previous
$paginate->setUrl('billpropertyController.php?do=show&');
---
4. edit() - Load Property for Editing
Location: Line 231-241
Purpose: Load bill property data for modification
Function Signature:
function edit()
// Returns: property data object
Process Flow:
$billpropertyid = $_GET['id'];
$data = $BillpropertyDAO->load($billpropertyid);
return $data;
---
5. update() - Update Bill Property
Location: Line 244-263
Purpose: Update existing bill property details
Function Signature:
function update()
Process Flow:
$billpropertyid = $_POST['billpropertyid'];
$billpropertyname = $_POST['billpropertyname'];
$description = $_POST['description'];
$conditions = $_POST['conditions'];
$Billproperty->billpropertyid = $billpropertyid;
$Billproperty->billpropertyname = $billpropertyname;
$Billproperty->conditions = $conditions;
$BillpropertyDAO->update($Billproperty, $description);
---
6. delete() - Soft Delete with Dependency Check
Location: Line 267-297
Purpose: Safely delete bill property after checking dependencies
Function Signature:
function delete($id)
// Returns: "sucess" or error message
Dependency Checking:
$billpropertyid = $id;
$alldata = $BillsettingDAO->queryByBillpropertyid($billpropertyid);
if (count($alldata) > 0) {
$note = "ูุง ูู
ูู ุญุฐู ูุฐุง ุงูููุน ูุงูู ู
ุฑุชุจุท ุจูุงุชูุฑู ุงุฎุฑู";
// Cannot delete - property is linked to bills
} else {
$Billproperty->billpropertyid = $billpropertyid;
$Billproperty->conditions = 1; // Soft delete
$BillpropertyEX->updatedel($Billproperty);
$note = "sucess";
}
Safety Features:
- โข Checks for existing bill settings using this property
- โข Prevents deletion if property is in use
- โข Uses soft delete (conditions = 1) instead of hard delete
- โข Returns descriptive error messages
---
7. ruturndelete() - Restore Deleted Property
Location: Line 300-325
Purpose: Restore a previously soft-deleted property
Function Signature:
function ruturndelete($id)
// Returns: "sucess" or error message
Restoration Process:
$billpropertyid = $id;
$Billproperty->conditions = 0; // Restore to active
$Billproperty->billpropertyid = $billpropertyid;
if ($BillpropertyEX->updatedel($Billproperty)) {
$note = "sucess";
} else {
$note = "ูู
ุชุชู
ุงูุนู
ููู ุจูุฌุงุญ ูุงู ูุฐุง ุงูุนูุตุฑ ูู
ูุชู
ุญุฐู ู
ู ูุจู";
// Operation failed - element was not previously deleted
}
---
8. executeOperation() - Batch Operations
Location: Line 327-388
Purpose: Perform batch delete or restore operations on multiple properties
Function Signature:
function executeOperation()
Operation Types:
- โข Operation 1: Batch delete multiple properties
- โข Operation 2: Batch restore multiple properties
Process Flow:
$operationType = $_POST['operation'];
$choosedItemArr = $_POST['choosedItem']; // Array of property IDs
foreach ($choosedItemArr as $billpropertyid) {
$Billpropertytdata = $BillpropertyDAO->load($billpropertyid);
$billpropertyname = $Billpropertytdata->billpropertyname;
if ($operationType == '1') { // Delete
$note = delete($billpropertyid);
} elseif ($operationType == "2") { // Restore
$note = ruturndelete($billpropertyid);
}
// Build result message
if ($note != "sucess") {
$outputString .= $billpropertyname . ": " . $note . "<br/>";
} else {
$outputString .= $billpropertyname . ": " . " ุชู
ุช ุงูุนู
ููุฉ ุจูุฌุงุญ <br/>";
}
}
Result Display:
$smarty->assign("outputString", $outputString);
$smarty->assign("operationType", $operationType);
---
๐ Workflows
Workflow 1: Create Bill Property
Workflow 2: Safe Property Deletion
---
๐ URL Routes & Actions
| URL Parameter | Function Called | Description | |
|---|---|---|---|
| `do=` (empty) | Default | Display add form | |
| `do=add` | `add()` | Create new property | |
| `do=show` | `show()` | Display paginated list | |
| `do=edit` | `edit()` | Load property for editing | |
| `do=update` | `update()` | Update existing property | |
| `do=delete` | `delete($id)` | Delete property (with dependency check) | |
| `do=ruturndelete` | `ruturndelete($id)` | Restore deleted property | |
| `do=executeOperation` | `executeOperation()` | Batch operations | |
| `do=sucess` | Template | Success page | |
| `do=error` | Template | Error page |
Create Property (do=add):
- โข
billpropertyname- Property name - โข
description- Property description
Edit Property (do=edit):
- โข
id- Property ID (URL parameter)
Update Property (do=update):
- โข
billpropertyid- Property ID - โข
billpropertyname- Updated name - โข
description- Updated description - โข
conditions- Status (0=active, 1=deleted)
Delete Property (do=delete):
- โข
id- Property ID (URL parameter)
Restore Property (do=ruturndelete):
- โข
id- Property ID (URL parameter)
Batch Operations (do=executeOperation):
- โข
operation- Operation type (1=delete, 2=restore) - โข
choosedItem[]- Array of property IDs
---
๐งฎ Business Logic
Property Status Management
// Active property
$Billproperty->conditions = 0;
// Deleted property (soft delete)
$Billproperty->conditions = 1;
Automatic Settings Generation
When a new property is created, the system automatically:
1. Queries all existing bill types (billname table)
2. Creates a billsettings record for each bill type
3. Sets default value to 0 (disabled)
4. Ensures property is available for configuration on all bills
Dependency Checking Logic
// Check if property is used in any bill settings
$alldata = $BillsettingDAO->queryByBillpropertyid($billpropertyid);
if (count($alldata) > 0) {
// Property has dependencies - prevent deletion
return "Cannot delete - property is linked to bills";
} else {
// Safe to delete - perform soft delete
$Billproperty->conditions = 1;
return "success";
}
Batch Operation Results
// Track results for each item in batch
foreach ($choosedItemArr as $billpropertyid) {
$result = performOperation($billpropertyid);
if ($result == "success") {
$outputString .= $propertyName . ": Operation completed successfully<br/>";
} else {
$outputString .= $propertyName . ": " . $result . "<br/>";
}
}
---
๐ Security & Permissions
Authentication
- โข โ No explicit authentication in this controller
- โข โ ๏ธ Relies on session data:
$_SESSION['userid'] - โข โ No permission level checking
Input Validation
- โข โ Basic POST data access
- โข โ No input sanitization
- โข โ No CSRF protection
- โข โ No validation of property names
Security Concerns
- โข SQL Injection Risk: Direct parameter usage
- โข No Access Control: Anyone with session can manage properties
- โข No Audit Trail: No logging of property changes
- โข Batch Operation Risk: No limit on bulk operations
---
๐ Performance Considerations
Pagination Implementation
$paginate = new SmartyPaginate;
$paginate->setLimit(50); // Reasonable page size
Database Optimization
1. Settings Generation: Creates N records per property (N = number of bill types)
2. Dependency Checking: Single query to check relationships
3. Pagination: Efficient limiting of results
Performance Issues
- โข N+1 Query Problem: Batch operations load each property individually
- โข No Indexing: Dependency queries may be slow without proper indexes
- โข No Caching: Repeated property loads in batch operations
Optimization Opportunities
// Batch load properties for batch operations
$propertyData = $BillpropertyDAO->loadMultiple($choosedItemArr);
// Index recommendations
CREATE INDEX idx_billsettings_property ON billsettings(billpropertyid);
CREATE INDEX idx_billproperty_conditions ON billproperty(conditions);
---
๐ Common Issues & Troubleshooting
1. Property Cannot Be Deleted
Issue: "ูุง ูู ูู ุญุฐู ูุฐุง ุงูููุน ูุงูู ู ุฑุชุจุท ุจูุงุชูุฑู ุงุฎุฑู"
Cause: Property has associated bill settings
Debug:
SELECT * FROM billsettings WHERE billpropertyid = ?;
2. Settings Not Generated for New Bills
Issue: New bill types don't have settings for existing properties
Solution: Run setup script to generate missing settings
3. Restore Operation Fails
Issue: "ูู ุชุชู ุงูุนู ููู ุจูุฌุงุญ ูุงู ูุฐุง ุงูุนูุตุฑ ูู ูุชู ุญุฐู ู ู ูุจู"
Cause: Property was not previously deleted (conditions โ 1)
Check: Property conditions value
4. Pagination Performance
Issue: Slow loading with many properties
Solution: Add database indexes and optimize queries
---
๐ Related Documentation
- โข CLAUDE.md - PHP 8.2 migration guide
- โข billTemplateController.md - Bill templates using properties
- โข sellbillController.md - Sales operations
- โข SmartyPaginate Documentation - Pagination system
---
Documented By: AI Assistant
Review Status: โ Complete
Next Review: When access control is implemented