Billproperty Documentation

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

Related Controllers

---

๐Ÿ—„๏ธ Database Tables

Primary Tables (Direct Operations)

Table NamePurposeKey Columns
**billproperty**Bill property definitionsbillpropertyid, billpropertyname, conditions
**billsettings**Property settings per bill typebillnameid, billpropertyid, billsettingsvalue
**billname**Bill template namesbillnameid, billname
### System Tables

Table NamePurposeKey Columns
**smartypaginate**Pagination supportVarious 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:

---

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:

---

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:

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

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
START: Create Property
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
1Display Add Form
- Show property name input
- Show description field
- Load form template
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
2Process Form Submission (do=add)
- Get property name and description
- Create property record (conditions = 0)
- Get new property ID
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
3Auto-Generate Settings for All Bill Types
FOR EACH existing bill type:
โ”‚
โ†’ Get bill type ID
โ†’ Create billsetting record
โ”‚ โ”œโ”€ billnameid = bill type ID
โ”‚ โ”œโ”€ billpropertyid = new property ID
โ”‚ โ”‚ โ””โ”€ billsettingsvalue = 0 (default off) โ”‚
โ”‚
โ”‚ โ””โ”€โ†’ Insert setting record โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
4Success Response
- Property created and available for all bills
- Default settings generated
- Redirect to success page
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Workflow 2: Safe Property Deletion

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
START: Delete Property
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
1Check Property Dependencies
- Query billsettings for this property
- Check if property is used in any bills
- Count dependent records
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
2Decision Point
- If dependencies exist:
โ”‚ โ””โ”€โ†’ Return error message โ”‚
- If no dependencies:
โ”‚ โ””โ”€โ†’ Proceed with soft delete โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
3Perform Soft Delete
- Set conditions = 1 (deleted status)
- Keep record in database
- Property hidden from normal operations
- Can be restored later if needed
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
4Success Response
- Property safely deactivated
- Data integrity maintained
- Restoration possible if needed
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

---

๐ŸŒ URL Routes & Actions

URL ParameterFunction CalledDescription
`do=` (empty)DefaultDisplay 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`TemplateSuccess page
`do=error`TemplateError page
### Required Parameters by Action

Create Property (do=add):

Edit Property (do=edit):

Update Property (do=update):

Delete Property (do=delete):

Restore Property (do=ruturndelete):

Batch Operations (do=executeOperation):

---

๐Ÿงฎ 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

Input Validation

Security Concerns

---

๐Ÿ“Š 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

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

---

Documented By: AI Assistant

Review Status: โœ… Complete

Next Review: When access control is implemented