34 lines
795 B
JavaScript
34 lines
795 B
JavaScript
const db = require("../db");
|
|
|
|
exports.openInvoices = async (req, res) => {
|
|
try {
|
|
const [rows] = await db.promise().query(`
|
|
SELECT
|
|
i.id,
|
|
i.invoice_date,
|
|
i.total_amount,
|
|
i.status,
|
|
p.firstname,
|
|
p.lastname
|
|
FROM invoices i
|
|
JOIN patients p ON p.id = i.patient_id
|
|
WHERE i.status = 'open'
|
|
ORDER BY i.invoice_date DESC
|
|
`);
|
|
console.log("ROWS:", rows);
|
|
const invoices = rows.map((inv) => ({
|
|
...inv,
|
|
total_amount_formatted: Number(inv.total_amount).toFixed(2),
|
|
}));
|
|
|
|
res.render("invoices/open-invoices", {
|
|
user: req.session.user,
|
|
invoices,
|
|
active: "open_invoices",
|
|
});
|
|
} catch (err) {
|
|
console.error("❌ openInvoices Fehler:", err);
|
|
res.status(500).send("Fehler beim Laden der offenen Rechnungen");
|
|
}
|
|
};
|