Realestateunitsalertsrents Documentation

Real Estate Units Alerts Rents Controller

File: /controllers/realestateunitsalertsrents.php

Purpose: Monitors and alerts on real estate rental payments due within specified date ranges

Last Updated: December 20, 2024

Total Functions: 2

Lines of Code: ~70

---

๐Ÿ“‹ Overview

The Real Estate Units Alerts Rents Controller serves as a rental payment alert system that tracks and monitors rental payments that are due within specified time periods. It provides:

This controller is essential for property managers to stay on top of rental payment schedules and ensure timely collection from clients and payments to suppliers.

Primary Functions

Related Controllers

---

๐Ÿ—„๏ธ Database Tables

Primary Tables (Direct Operations)

Table NamePurposeKey Columns
**realestateunitspaids**Real estate payment recordsid, realestateid, realestateunitid, supplierid, clientid, addtoday, del
**realestateunitpaidinstallments**Payment installment detailsrealestateunitpaidid, 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 - Rental Alerts Interface

Location: Lines 6-9

Purpose: Display the main rental payment alerts monitoring interface

Process Flow:

1. Display header template

2. Load rental alerts view (realestateunitsalertsrentsview/show.html)

3. Display footer template

---

2. getdata - Generate Rental Payment Alerts Report

Location: Lines 10-68

Purpose: Generate comprehensive report of rental payments due within specified date range

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 {
    // Default to current date for urgent alerts
    $searchQuery .=' and realestateunitspaids.addtoday >= "' . $date . ' 00-00-00" 
                    and realestateunitspaids.addtoday <= "' . $date . ' 23-59-55" ';
}

2. Property and Unit Filtering:

if($realestateid != ''){
    $searchQuery .=' and realestateunitspaids.realestateid = ' . $realestateid . ' ';
}

if($realestateunitid != ''){
    $searchQuery .=' and realestateunitspaids.realestateunitid = ' . $realestateunitid . ' ';
}

3. Party-Specific Filtering:

if($supplierid != ''){
    $ssearchQuery .=' and realestateunitspaids.supplierid = ' . $supplierid . ' ';
}

if($clientid != ''){
    $csearchQuery .=' and realestateunitspaids.clientid = ' . $clientid . ' ';
}

4. Supplier Payment Alerts Query:

// Supplier payments due within date range
$srealestateunitspaids = R::findAll('realestateunitspaids', 
    "where realestateunitspaids.del < 2 and realestateunitspaids.clientid = 0 
     $searchQuery $ssearchQuery");

foreach($srealestateunitspaids as $srealestateunitspaid){
    $realestate = R::load('realestates', $srealestateunitspaid->realestateid);
    $supplier = R::getRow('select * from supplier WHERE supplierid = ?', 
                         [$srealestateunitspaid->supplierid]);
    
    // Load related installments
    $realestateunitpaidinstallments = R::findAll('realestateunitpaidinstallments',
        'realestateunitpaidid = ? and del < 2', [$srealestateunitspaid->id]);
    
    $srealestateunitspaid->realestate = $realestate;
    $srealestateunitspaid->supplier = $supplier;
    $srealestateunitspaid->realestateunitpaidinstallments = $realestateunitpaidinstallments;
}

5. Client Payment Alerts Query:

// Client payments due within date range
$crealestateunitspaids = R::findAll('realestateunitspaids', 
    "where realestateunitspaids.del < 2 and realestateunitspaids.supplierid = 0 
     $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]);
    
    // Load related installments  
    $realestateunitpaidinstallments = R::findAll('realestateunitpaidinstallments',
        'realestateunitpaidid = ? and del < 2', [$crealestateunitspaid->id]);
    
    $crealestateunitspaid->realestate = $realestate;
    $crealestateunitspaid->realestatesunit = $realestatesunit;
    $crealestateunitspaid->client = $client;
    $crealestateunitspaid->realestateunitpaidinstallments = $realestateunitpaidinstallments;
}

6. Template Assignment and Display:

$smarty->assign('srealestateunitspaids', $srealestateunitspaids);
$smarty->assign('crealestateunitspaids', $crealestateunitspaids);
$smarty->display("realestateunitsalertsrentsview/getdata.html");

---

๐Ÿ”„ Workflows

Workflow 1: Rental Payment Alerts Generation

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
START: Generate Rental Payment Alerts
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
1Process Alert Parameters
- Date range (start_date, end_date)
- Property filters (realestateid, unitid)
- Party filters (supplierid, clientid)
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
2Build Date-Based Query Filters
IF date range provided:
โ”‚ โ””โ”€ Filter by start_date to end_date โ”‚
ELSE:
โ”‚ โ””โ”€ Default to current date (urgent alerts) โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
3Add Property and Party Filters
- Apply property filter (if specified)
- Apply unit filter (if specified)
- Build separate supplier and client filters
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
4Query Supplier Payment Alerts
- Find payments where clientid = 0
- Within specified date range
- Load related property and supplier details
- Include installment payment schedules
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
5Query Client Payment Alerts
- Find payments where supplierid = 0
- Within specified date range
- Load related property, unit, and client details
- Include installment payment schedules
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
6Generate Comprehensive Alerts Report
- Assign supplier payment alerts
- Assign client payment alerts
- Display via realestateunitsalertsrentsview template
- Include installment breakdowns
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

---

๐ŸŒ URL Routes & Actions

URL ParameterFunction CalledDescription
`do=` (empty)Default actionDisplay rental alerts monitoring interface
`do=getdata`getdata processingGenerate rental payment alerts report
### Required Parameters for do=getdata

POST Parameters (all optional):

---

๐Ÿงฎ Calculation Methods

Date Range Alert Logic

// User-specified date range
if($start_date != '' && $end_date != ''){
    $searchQuery .=' and realestateunitspaids.addtoday >= "' . $start_date . ' 00-00-00" 
                    and realestateunitspaids.addtoday <= "' . $end_date . ' 23-59-55" ';
}
// Default to current date (urgent alerts)
else {
    $searchQuery .=' and realestateunitspaids.addtoday >= "' . $date . ' 00-00-00" 
                    and realestateunitspaids.addtoday <= "' . $date . ' 23-59-55" ';
}

Payment Type Categorization

Supplier Payments: clientid = 0
- Property lease payments to landlords
- Construction/maintenance payments
- Property purchase installments

Client Payments: supplierid = 0  
- Rental payments from tenants
- Lease payments from clients
- Security deposit payments

Alert Priority Logic

Default Behavior (no date range):
- Shows payments due TODAY
- High priority urgent alerts
- Immediate attention required

Date Range Specified:
- Shows payments due within range
- Planning and scheduling alerts  
- Medium priority monitoring

Installment Integration

// Load all installment details for each payment
$realestateunitpaidinstallments = R::findAll('realestateunitpaidinstallments',
    'realestateunitpaidid = ? and del < 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

// Soft delete protection
"where realestateunitspaids.del < 2"

// Payment category validation  
"and realestateunitspaids.clientid = 0"    // Supplier payments
"and realestateunitspaids.supplierid = 0"  // Client payments

---

๐Ÿ“Š Performance Considerations

Database Optimization

1. Critical Indexes:

- realestateunitspaids(addtoday, del, clientid, supplierid)

- realestateunitspaids(realestateid, realestateunitid)

- realestateunitpaidinstallments(realestateunitpaidid, del)

2. Query Efficiency:

- Date range filtering with proper timestamp format

- Efficient payment type separation

- Optimized installment loading

Memory Management

---

๐Ÿ› Common Issues & Troubleshooting

1. No Alerts Showing for Current Date

Issue: Report shows no alerts despite having payments due today

Cause: Date comparison or payment creation date issues

Debug:

-- Check payments for current date
SELECT addtoday, COUNT(*) FROM realestateunitspaids 
WHERE DATE(addtoday) = CURDATE() AND del < 2 
GROUP BY DATE(addtoday);

-- Check date format in database
SELECT addtoday FROM realestateunitspaids 
WHERE del < 2 LIMIT 5;

2. Date Range Filtering Issues

Issue: Date range filter doesn't return expected results

Cause: Time component in date comparison

Debug:

// Verify date range construction
echo "Start: " . $start_date . " 00-00-00<br>";
echo "End: " . $end_date . " 23-59-55<br>";

// Check if payments exist in range
$test_query = "SELECT COUNT(*) as count FROM realestateunitspaids 
               WHERE addtoday >= '{$start_date} 00-00-00' 
               AND addtoday <= '{$end_date} 23-59-55' 
               AND del < 2";

3. Missing Installment Details

Issue: Payments show without installment breakdown

Cause: Orphaned installment records

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 AND ri.del < 2
WHERE rp.del < 2
GROUP BY rp.id;

4. Party Filter Not Working

Issue: Supplier or client filters don't affect results

Cause: Filter query construction

Debug:

// Check filter construction
echo "Supplier search query: " . $ssearchQuery . "<br>";
echo "Client search query: " . $csearchQuery . "<br>";

// Verify filter values
var_dump($_POST['supplierid']);
var_dump($_POST['clientid']);

---

๐Ÿงช Testing Scenarios

Test Case 1: Current Date Urgent Alerts

1. Create payment records with addtoday = current date
2. Include both supplier and client payments
3. Run alerts report without date range
4. Verify only today's payments appear
5. Check both payment types are included
6. Verify installment details loaded

Test Case 2: Date Range Planning Alerts

1. Create payment records across multiple dates
2. Set specific date range (e.g., next 7 days)
3. Run alerts report with date range
4. Verify only payments in range appear
5. Check edge cases (start/end date boundaries)
6. Verify time handling (00-00-00 to 23-59-55)

Test Case 3: Property and Unit Filtering

1. Create payments for multiple properties/units
2. Apply property filter (specific ID)
3. Verify only related payments appear
4. Apply unit filter within property
5. Verify filtering narrows results correctly
6. Test with invalid property/unit IDs

Test Case 4: Party-Specific Filtering

1. Create payments for multiple suppliers/clients
2. Apply supplier filter
3. Verify only supplier payments (clientid = 0) appear
4. Apply client filter  
5. Verify only client payments (supplierid = 0) appear
6. Test with non-existent supplier/client IDs

Test Case 5: Installment Integration

1. Create payment records with multiple installments
2. Ensure installments have different del statuses
3. Run alerts report
4. Verify only active installments (del < 2) appear
5. Check installment details properly attached
6. Verify orphaned installments handled correctly

Test Case 6: Combined Filtering

1. Create diverse payment data set
2. Apply multiple filters simultaneously:
   - Date range + property filter
   - Supplier filter + unit filter
   - Date range + client filter + property
3. Verify intersection logic works correctly
4. Test edge cases with no matching results
5. Verify performance with complex filters

---

๐Ÿ“š Related Documentation

---

Key Differences from Other Real Estate Controllers:

1. vs realestatepayments.php:

- Date Focus: Specific date range alerts vs payment status

- Purpose: Proactive alerts vs pending payment tracking

- Default Behavior: Current date vs all pending

2. vs realestateaveragerevenue.php:

- Payment Status: All payments vs only paid amounts

- Purpose: Alert generation vs revenue calculation

- Data Scope: Alerts-focused vs comprehensive analysis

3. vs realestateunitsalertsemptys.php:

- Data Type: Payment alerts vs availability status

- Time Dimension: Date-based vs current state

- Purpose: Payment management vs occupancy tracking

---

Alert System Features:

1. Urgent Mode: Default to current date for immediate attention

2. Planning Mode: Date range specification for advance planning

3. Comprehensive Coverage: Both supplier and client payments

4. Detailed Context: Full property, unit, and party information

5. Installment Awareness: Breakdown of payment schedules

6. Flexible Filtering: Multiple filter criteria support

---

Documented By: AI Assistant

Review Status: โœ… Complete

Next Review: When major changes occur