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:

Primary Functions

Related Controllers

---

๐Ÿ—„๏ธ Database Tables

Primary Tables (Direct Operations)

Table NamePurposeKey Columns
**realestateunitspaids**Real estate unit paymentsid, realestateid, realestateunitid, supplierid, clientid, payed, addtoday, del
**realestateunitpaidinstallments**Payment installmentsrealestateunitpaidid, payed, del
### Reference Tables

Table NamePurposeKey Columns
**realestates**Property master dataid, realestatename
**realestatesunits**Property unitsid, realestateid, unitname, unitarea
**supplier**Supplier informationsupplierid, suppliername, supplierphone
**client**Client informationclientid, 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

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
START: Track Pending Payments
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
1Process Filter Parameters
- Date range (optional for pending payments)
- Property filters (realestateid, unitid)
- Party filters (supplierid, clientid)
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
2Build Conditional Query Filters
- Apply date range only if specified
- Add property-specific conditions
- Add party-specific conditions
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
3Query Pending Supplier Payments
- Filter: clientid = 0 AND payed < 2
- Load related property and supplier details
- Include pending installment details
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
4Query Pending Client Payments
- Filter: supplierid = 0 AND payed < 2
- Load related property, unit, and client details
- Include pending installment details
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
5Generate Pending Payments Report
- Assign supplier and client payment data
- Display via realestatepaymentsview template
- Show installment breakdown for each payment
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

---

๐ŸŒ URL Routes & Actions

URL ParameterFunction CalledDescription
`do=` (empty)Default actionDisplay pending payments interface
`do=getdata`getdata processingGenerate pending payments report
### Required Parameters for do=getdata

POST Parameters (all optional):

---

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

Data Access Control

---

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

---

๐Ÿ› 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

---

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