Realestatepayments Documentation
Real Estate Payments Controller
File: /controllers/realestatepayments.php
Purpose: Tracks and displays pending payments for real estate properties
Last Updated: December 20, 2024
Total Functions: 2
Lines of Code: ~70
---
๐ Overview
The Real Estate Payments Controller manages the tracking and reporting of pending payments for real estate properties. It focuses specifically on:
- โข Pending supplier payments (unpaid bills)
- โข Pending client rental payments (outstanding rents)
- โข Payment installment tracking
- โข Date range filtering for payment analysis
- โข Property and unit-specific payment reports
Primary Functions
- โ Track pending supplier payments
- โ Monitor outstanding client rental payments
- โ Display payment installment details
- โ Support date range filtering
- โ Property-specific payment tracking
- โ Distinguish between supplier and client payments
Related Controllers
- โข realestateaveragerevenue.php - Revenue analysis
- โข realestateunits.php - Unit management
- โข supplier.php - Supplier management
- โข client.php - Client management
---
๐๏ธ Database Tables
Primary Tables (Direct Operations)
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **realestateunitspaids** | Real estate unit payments | id, realestateid, realestateunitid, supplierid, clientid, payed, addtoday, del | |
| **realestateunitpaidinstallments** | Payment installments | realestateunitpaidid, payed, del |
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **realestates** | Property master data | id, realestatename | |
| **realestatesunits** | Property units | id, realestateid, unitname, unitarea | |
| **supplier** | Supplier information | supplierid, suppliername, supplierphone | |
| **client** | Client information | clientid, clientname, clientphone |
๐ Key Functions
1. Default Action - Main Payment Display Interface
Location: Lines 6-9
Purpose: Display the main payment tracking interface
Process Flow:
1. Display header template
2. Load payment tracking view (realestatepaymentsview/show.html)
3. Display footer template
---
2. getdata - Pending Payments Analysis
Location: Lines 10-68
Purpose: Generate report of all pending payments for properties
Function Signature:
// Triggered when: do=getdata (POST)
$start_date = filter_input(INPUT_POST, 'start_date');
$end_date = filter_input(INPUT_POST, 'end_date');
$supplierid = filter_input(INPUT_POST, 'supplierid');
$clientid = filter_input(INPUT_POST, 'clientid');
$realestateid = filter_input(INPUT_POST, 'realestateid');
$realestateunitid = filter_input(INPUT_POST, 'realestateunitid');
Process Flow:
1. Date Range Processing:
if($start_date != '' && $end_date != ''){
$searchQuery .=' and realestateunitspaids.addtoday >= "' . $start_date . ' 00-00-00"
and realestateunitspaids.addtoday <= "' . $end_date . ' 23-59-55" ';
} else {
// No default date filter - shows all pending payments
// Commented out: $searchQuery .=' and realestateunitspaids.addtoday >= ...
}
2. Property and Unit Filtering:
if($realestateid != ''){
$searchQuery .=' and realestateunitspaids.realestateid = ' . $realestateid . ' ';
}
if($realestateunitid != ''){
$searchQuery .=' and realestateunitspaids.realestateunitid = ' . $realestateunitid . ' ';
}
3. Supplier Pending Payments Analysis:
// Key difference: payed < 2 (pending) instead of payed > 0 (paid)
$srealestateunitspaids = R::findAll('realestateunitspaids',
"where realestateunitspaids.del < 2 and realestateunitspaids.clientid = 0
and realestateunitspaids.payed < 2 $searchQuery $ssearchQuery");
foreach($srealestateunitspaids as $srealestateunitspaid){
$realestate = R::load('realestates', $srealestateunitspaid->realestateid);
$supplier = R::getRow('select * from supplier WHERE supplierid = ?',
[$srealestateunitspaid->supplierid]);
// Get pending installments (payed < 2)
$realestateunitpaidinstallments = R::findAll('realestateunitpaidinstallments',
'realestateunitpaidid = ? and del < 2 and payed < 2',
[$srealestateunitspaid->id]);
$srealestateunitspaid->realestate = $realestate;
$srealestateunitspaid->supplier = $supplier;
$srealestateunitspaid->realestateunitpaidinstallments = $realestateunitpaidinstallments;
}
4. Client Pending Rental Payments Analysis:
// Client payments that are still pending
$crealestateunitspaids = R::findAll('realestateunitspaids',
"where realestateunitspaids.del < 2 and realestateunitspaids.supplierid = 0
and realestateunitspaids.payed < 2 $searchQuery $csearchQuery");
foreach($crealestateunitspaids as $crealestateunitspaid){
$realestate = R::load('realestates', $crealestateunitspaid->realestateid);
$realestatesunit = R::load('realestatesunits', $crealestateunitspaid->realestateunitid);
$client = R::getRow('select * from client WHERE clientid = ?',
[$crealestateunitspaid->clientid]);
// Get pending installments
$realestateunitpaidinstallments = R::findAll('realestateunitpaidinstallments',
'realestateunitpaidid = ? and del < 2 and payed < 2',
[$crealestateunitspaid->id]);
$crealestateunitspaid->realestate = $realestate;
$crealestateunitspaid->realestatesunit = $realestatesunit;
$crealestateunitspaid->client = $client;
$crealestateunitspaid->realestateunitpaidinstallments = $realestateunitpaidinstallments;
}
5. Template Assignment:
$smarty->assign('srealestateunitspaids', $srealestateunitspaids);
$smarty->assign('crealestateunitspaids', $crealestateunitspaids);
$smarty->display("realestatepaymentsview/getdata.html");
---
๐ Workflows
Workflow 1: Pending Payments Report Generation
---
๐ URL Routes & Actions
| URL Parameter | Function Called | Description | |
|---|---|---|---|
| `do=` (empty) | Default action | Display pending payments interface | |
| `do=getdata` | getdata processing | Generate pending payments report |
do=getdata
POST Parameters (all optional):
- โข
start_date- Start date filter (YYYY-MM-DD format) - โข
end_date- End date filter (YYYY-MM-DD format) - โข
supplierid- Filter by specific supplier - โข
clientid- Filter by specific client - โข
realestateid- Filter by specific property - โข
realestateunitid- Filter by specific unit
---
๐งฎ Calculation Methods
Payment Status Logic
// Payment status determination:
// payed < 2 = Pending/Unpaid
// payed >= 2 = Paid (handled in realestateaveragerevenue.php)
// Supplier payments that are pending
$srealestateunitspaids = R::findAll('realestateunitspaids',
"where realestateunitspaids.del < 2 and realestateunitspaids.clientid = 0
and realestateunitspaids.payed < 2");
// Client payments that are pending
$crealestateunitspaids = R::findAll('realestateunitspaids',
"where realestateunitspaids.del < 2 and realestateunitspaids.supplierid = 0
and realestateunitspaids.payed < 2");
Payment Categorization
Supplier Payments: clientid = 0, payed < 2
- Property purchase payments
- Construction payments
- Maintenance payments
Client Payments: supplierid = 0, payed < 2
- Rental payments
- Lease payments
- Security deposits
Installment Tracking
// Load pending installments for each payment
$realestateunitpaidinstallments = R::findAll('realestateunitpaidinstallments',
'realestateunitpaidid = ? and del < 2 and payed < 2',
[$payment->id]);
---
๐ Security & Permissions
Input Validation
// Secure input filtering
$start_date = filter_input(INPUT_POST, 'start_date');
$end_date = filter_input(INPUT_POST, 'end_date');
$supplierid = filter_input(INPUT_POST, 'supplierid');
$clientid = filter_input(INPUT_POST, 'clientid');
$realestateid = filter_input(INPUT_POST, 'realestateid');
$realestateunitid = filter_input(INPUT_POST, 'realestateunitid');
SQL Injection Prevention
- โข RedBeanPHP ORM with parameterized queries
- โข Proper type checking for numeric IDs
- โข Safe date format handling
Data Access Control
- โข Soft delete filtering (
del < 2) - โข Payment status validation (
payed < 2) - โข Proper foreign key relationships
---
๐ Performance Considerations
Database Optimization
1. Critical Indexes:
- realestateunitspaids(payed, del, clientid, supplierid)
- realestateunitspaids(addtoday, realestateid)
- realestateunitpaidinstallments(realestateunitpaidid, payed, del)
2. Query Efficiency:
- Conditional date filtering (only when needed)
- Efficient payment status filtering
- Optimized LEFT JOINs for related data
Memory Usage
- โข Iterative processing of payment records
- โข Efficient loading of related entities
- โข Minimal template variable overhead
---
๐ Common Issues & Troubleshooting
1. No Pending Payments Shown
Issue: Report shows empty even with known pending payments
Cause: Payment status confusion (payed >= 2)
Debug:
-- Check payment status distribution
SELECT payed, COUNT(*) FROM realestateunitspaids
WHERE del < 2 GROUP BY payed;
-- Look for pending payments
SELECT * FROM realestateunitspaids
WHERE del < 2 AND payed < 2 LIMIT 10;
2. Missing Installment Details
Issue: Payments show without installment breakdown
Cause: Orphaned installment records or del status
Debug:
-- Check installment linkage
SELECT rp.id, COUNT(ri.id) as installment_count
FROM realestateunitspaids rp
LEFT JOIN realestateunitpaidinstallments ri ON rp.id = ri.realestateunitpaidid
WHERE rp.del < 2 AND rp.payed < 2
GROUP BY rp.id;
3. Date Filter Not Working
Issue: Date range filter doesn't affect results
Cause: Commented out default date logic
Note: This is intentional design - pending payments are shown regardless of creation date unless specifically filtered.
Verify:
// Check if date filtering is working when dates are provided
if($start_date != '' && $end_date != ''){
// Date filtering should be active
echo "Date filtering: " . $searchQuery;
}
---
๐งช Testing Scenarios
Test Case 1: Basic Pending Payments Display
1. Create test property and units
2. Add payment records with payed < 2
3. Run pending payments report
4. Verify all pending payments appear
5. Check installment details are loaded
Test Case 2: Payment Status Filtering
1. Create payments with different payed values
- payed = 0 (pending)
- payed = 1 (partial)
- payed = 2 (paid)
2. Run report and verify only payed < 2 appear
3. Compare with realestateaveragerevenue.php (payed > 0)
Test Case 3: Property and Party Filtering
1. Create payments for multiple properties/parties
2. Filter by specific property ID
3. Verify only related pending payments appear
4. Test supplier and client filters separately
Test Case 4: Date Range Functionality
1. Add pending payments on different dates
2. Apply date range filter
3. Verify filtering works when dates provided
4. Verify all payments shown when no dates provided
---
๐ Related Documentation
- โข CLAUDE.md - PHP 8.2 migration guide
- โข realestateaveragerevenue.md - Revenue analysis (paid amounts)
- โข realestateunits.md - Unit management
- โข Database Schema Documentation - Table relationships
---
Key Differences from realestateaveragerevenue.php:
1. Payment Status: payed < 2 (pending) vs payed > 0 (paid)
2. Date Filtering: Optional vs required/defaulted
3. Purpose: Outstanding amounts vs completed revenue
4. Expense Data: Not included (focus on payments only)
---
Documented By: AI Assistant
Review Status: โ Complete
Next Review: When major changes occur