fix: Corregir cálculo de excedente para casas con consumo_only
- Agregar método getExpectedAmountWithDiscount() que retorna el monto sin descuento de 00 - El excedente ahora se calcula contra el monto original configurado, no contra el monto con descuento - Casas que pagan exactamente el monto por casa aparecen al corriente (/bin/bash.00) - Casas que pagan más del monto por casa muestran excedente
This commit is contained in:
@@ -51,6 +51,23 @@ class Payment {
|
|||||||
return round($monto_base, 2);
|
return round($monto_base, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getExpectedAmountWithDiscount($house, $year, $month) {
|
||||||
|
$db = Database::getInstance();
|
||||||
|
|
||||||
|
$bill = $db->fetchOne(
|
||||||
|
"SELECT * FROM monthly_bills WHERE year = ? AND month = ?",
|
||||||
|
[$year, $month]
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!$bill) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$monto_base = $bill['amount_per_house'];
|
||||||
|
|
||||||
|
return round($monto_base, 2);
|
||||||
|
}
|
||||||
|
|
||||||
public static function update($houseId, $year, $month, $amount, $userId, $notes = null, $paymentMethod = null) {
|
public static function update($houseId, $year, $month, $amount, $userId, $notes = null, $paymentMethod = null) {
|
||||||
$db = Database::getInstance();
|
$db = Database::getInstance();
|
||||||
|
|
||||||
|
|||||||
@@ -68,6 +68,7 @@
|
|||||||
foreach ($houses as $house):
|
foreach ($houses as $house):
|
||||||
$total = 0;
|
$total = 0;
|
||||||
$totalExpected = 0;
|
$totalExpected = 0;
|
||||||
|
$totalExpectedOriginal = 0;
|
||||||
?>
|
?>
|
||||||
<tr data-house-id="<?= $house['id'] ?>" data-house-number="<?= $house['number'] ?>" data-status="<?= $house['status'] ?>">
|
<tr data-house-id="<?= $house['id'] ?>" data-house-number="<?= $house['number'] ?>" data-status="<?= $house['status'] ?>">
|
||||||
<td><strong><?= $house['number'] ?></strong></td>
|
<td><strong><?= $house['number'] ?></strong></td>
|
||||||
@@ -85,8 +86,10 @@
|
|||||||
$monthTotals[$month] += $amount; // Accumulate monthly total
|
$monthTotals[$month] += $amount; // Accumulate monthly total
|
||||||
|
|
||||||
$expected = Payment::getExpectedAmount($house, $year, $month);
|
$expected = Payment::getExpectedAmount($house, $year, $month);
|
||||||
|
$expectedOriginal = Payment::getExpectedAmountWithDiscount($house, $year, $month);
|
||||||
$total += $amount;
|
$total += $amount;
|
||||||
$totalExpected += $expected;
|
$totalExpected += $expected;
|
||||||
|
$totalExpectedOriginal += $expectedOriginal;
|
||||||
|
|
||||||
$cellClass = 'pending';
|
$cellClass = 'pending';
|
||||||
$cellText = '-';
|
$cellText = '-';
|
||||||
@@ -124,7 +127,7 @@
|
|||||||
</td>
|
</td>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
<?php
|
<?php
|
||||||
$difference = $total - $totalExpected;
|
$difference = $total - $totalExpectedOriginal;
|
||||||
$diffClass = $difference < 0 ? 'text-danger' : 'text-success';
|
$diffClass = $difference < 0 ? 'text-danger' : 'text-success';
|
||||||
$diffText = $difference == 0 ? '$0.00' : '$' . number_format($difference, 2);
|
$diffText = $difference == 0 ? '$0.00' : '$' . number_format($difference, 2);
|
||||||
$grandTotal += $total;
|
$grandTotal += $total;
|
||||||
@@ -200,6 +203,7 @@
|
|||||||
<?php foreach ($houses as $house):
|
<?php foreach ($houses as $house):
|
||||||
$total = 0;
|
$total = 0;
|
||||||
$totalExpected = 0;
|
$totalExpected = 0;
|
||||||
|
$totalExpectedOriginal = 0;
|
||||||
?>
|
?>
|
||||||
<tr>
|
<tr>
|
||||||
<td><strong><?= $house['number'] ?></strong></td>
|
<td><strong><?= $house['number'] ?></strong></td>
|
||||||
@@ -208,8 +212,10 @@
|
|||||||
$payment = $payments[$month][$house['id']] ?? null;
|
$payment = $payments[$month][$house['id']] ?? null;
|
||||||
$amount = $payment['amount'] ?? 0;
|
$amount = $payment['amount'] ?? 0;
|
||||||
$expected = Payment::getExpectedAmount($house, $year, $month);
|
$expected = Payment::getExpectedAmount($house, $year, $month);
|
||||||
|
$expectedOriginal = Payment::getExpectedAmountWithDiscount($house, $year, $month);
|
||||||
$total += $amount;
|
$total += $amount;
|
||||||
$totalExpected += $expected;
|
$totalExpected += $expected;
|
||||||
|
$totalExpectedOriginal += $expectedOriginal;
|
||||||
|
|
||||||
$bg = '#f8d7da';
|
$bg = '#f8d7da';
|
||||||
if ($amount > 0) {
|
if ($amount > 0) {
|
||||||
@@ -223,7 +229,7 @@
|
|||||||
</td>
|
</td>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
<?php
|
<?php
|
||||||
$difference = $total - $totalExpected;
|
$difference = $total - $totalExpectedOriginal;
|
||||||
$diffColor = $difference < 0 ? 'red' : 'green';
|
$diffColor = $difference < 0 ? 'red' : 'green';
|
||||||
$diffText = $difference == 0 ? '$0.00' : '$' . number_format($difference, 2);
|
$diffText = $difference == 0 ? '$0.00' : '$' . number_format($difference, 2);
|
||||||
?>
|
?>
|
||||||
|
|||||||
@@ -58,6 +58,7 @@
|
|||||||
foreach ($houses as $house):
|
foreach ($houses as $house):
|
||||||
$total = 0;
|
$total = 0;
|
||||||
$totalExpected = 0;
|
$totalExpected = 0;
|
||||||
|
$totalExpectedOriginal = 0;
|
||||||
?>
|
?>
|
||||||
<tr>
|
<tr>
|
||||||
<td><strong><?= $house['number'] ?></strong></td>
|
<td><strong><?= $house['number'] ?></strong></td>
|
||||||
@@ -68,8 +69,10 @@
|
|||||||
$monthTotals[$month] += $amount;
|
$monthTotals[$month] += $amount;
|
||||||
|
|
||||||
$expected = Payment::getExpectedAmount($house, $year, $month);
|
$expected = Payment::getExpectedAmount($house, $year, $month);
|
||||||
|
$expectedOriginal = Payment::getExpectedAmountWithDiscount($house, $year, $month);
|
||||||
$total += $amount;
|
$total += $amount;
|
||||||
$totalExpected += $expected;
|
$totalExpected += $expected;
|
||||||
|
$totalExpectedOriginal += $expectedOriginal;
|
||||||
|
|
||||||
$bg_color = '#FFFFFF'; // Default white
|
$bg_color = '#FFFFFF'; // Default white
|
||||||
if ($house['status'] == 'deshabitada') {
|
if ($house['status'] == 'deshabitada') {
|
||||||
@@ -89,7 +92,7 @@
|
|||||||
</td>
|
</td>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
<?php
|
<?php
|
||||||
$difference = $total - $totalExpected;
|
$difference = $total - $totalExpectedOriginal;
|
||||||
$diffColor = $difference < 0 ? 'red' : 'green';
|
$diffColor = $difference < 0 ? 'red' : 'green';
|
||||||
$diffText = $difference == 0 ? '$0.00' : '$' . number_format($difference, 2);
|
$diffText = $difference == 0 ? '$0.00' : '$' . number_format($difference, 2);
|
||||||
$grandTotal += $total;
|
$grandTotal += $total;
|
||||||
|
|||||||
Reference in New Issue
Block a user