backend-01
commit bf1e9693e4eed1904db54baf3ad17804d25da44c
Author: Pedro Lucas Porcellis <porcellis@eletrotupi.com>
bill: move isPaid label logic to bill model
app/models/Bill.php | 5 +++++
app/views/bill_edit.php | 3 +--
app/views/bills.php | 4 ++--
app/views/dashboard.php | 2 +-
diff --git a/app/models/Bill.php b/app/models/Bill.php
index 46e76cc65df3e9572cc097db5924b57c72de86c7..129c9f49bf4239b8f4f5fac1dc08cb424f169b1b 100644
--- a/app/models/Bill.php
+++ b/app/models/Bill.php
@@ -21,6 +21,11 @@ $this->tags = $tags;
$this->pdfPath = $pdfPath;
}
+ // TODO: Move this to use some sort of translation service instead
+ public function isPaidLabel() {
+ return $this->paid ? 'Sim' : 'Não';
+ }
+
public function getTitle() {
return $this->title;
}
diff --git a/app/views/bill_edit.php b/app/views/bill_edit.php
index c7e55c753221950af0378b0516ea2d81b7efe0bf..2ac41b31e07f32d0b43b4e2e83959072f5aab918 100644
--- a/app/views/bill_edit.php
+++ b/app/views/bill_edit.php
@@ -39,11 +39,10 @@
<div class="mb-4">
<label class="flex items-center text-sm font-medium text-gray-700">
- <input type="checkbox" name="paid" class="mr-2" checked="<?= $bill->isPaid() ?>" />
+ <input type="checkbox" name="paid" class="mr-2" <?= ($bill->isPaid()) ? 'checked' : '' ?> />
Pago?
</label>
</div>
-
<div class="flex items-center space-x-4">
<button type="submit" class="bg-blue-600 text-white py-2 px-4 rounded hover:bg-blue-700">
diff --git a/app/views/bills.php b/app/views/bills.php
index 4dab882dbddd4ffd619bead59e5f13680d081c47..a3e72cda9f2f5a538eaffaba4c9f04560449de1b 100644
--- a/app/views/bills.php
+++ b/app/views/bills.php
@@ -55,8 +55,8 @@
<td class="py-3 px-6"><?= htmlspecialchars($bill->getTitle()) ?></td>
<td class="py-3 px-6">R$ <?= number_format($bill->getAmount(), 2, ',', '.') ?></td>
<td class="py-3 px-6"><?= date('d/m/Y', strtotime($bill->getDueDate())) ?></td>
- <td class="py-3 px-6"><?= htmlspecialchars($bill->getTags()) ?></td>
- <td class="py-3 px-6"><?= $bill->isPaid() ? 'Sim' : 'Não' ?></td>
+ <td class="py-3 px-6"><?= htmlspecialchars($bill->getTags() ?? '-') ?></td>
+ <td class="py-3 px-6"><?= $bill->isPaidLabel() ?></td>
<td class="py-3 px-6 flex space-x-2">
<a href="/bills/edit/<?= $bill->getId() ?>" class="text-yellow-600 hover:text-yellow-700">Editar</a>
<a href="/bills/delete/<?= $bill->getId() ?>" class="text-red-600 hover:text-red-700">Apagar</a>
diff --git a/app/views/dashboard.php b/app/views/dashboard.php
index 88981aa22462557f16f3a223c985a40b03f3de2c..509986d8bbb442162d69504cfe961389488eb29c 100644
--- a/app/views/dashboard.php
+++ b/app/views/dashboard.php
@@ -39,7 +39,7 @@ = htmlspecialchars($bill->getTitle()) ?> |
<td class="py-3 px-6">$<?= number_format($bill->getAmount(), 2, '.', ',') ?></td>
<td class="py-3 px-6"><?= date('d/m/Y', strtotime($bill->getDueDate())) ?></td>
<td class="py-3 px-6"><?= htmlspecialchars($bill->getTags() ?? '-') ?></td>
- <td class="py-3 px-6"><?= $bill->isPaid() ? 'Sim' : 'Não' ?></td>
+ <td class="py-3 px-6"><?= $bill->isPaidLabel() ?></td>
<td class="py-3 px-6 flex items-center space-x-2">
<a href="/bills/edit/<?= $bill->getId() ?>" class="text-yellow-600 hover:text-yellow-700">Editar</a>
<a href="/bills/delete/<?= $bill->getId() ?>" class="text-red-600 hover:text-red-700">Apagar</a>