Compare commits

1 Commits
main ... cline

Author SHA1 Message Date
5de91371da aggiornamento da cline 2026-02-20 21:33:44 +01:00
4 changed files with 6264 additions and 0 deletions

2763
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

8
server/.env Normal file
View File

@@ -0,0 +1,8 @@
DB_CLIENT=mysql
DB_HOST=fcarra.mywire.org
DB_PORT=33067
DB_USER=root
DB_PASS=somewordpress
DB_NAME=condopay
JWT_SECRET=condopay_dev_secret_2024
PORT=3001

3449
server/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -793,6 +793,50 @@ app.post('/api/expenses', authenticateToken, requireAdmin, async (req, res) => {
res.json({ success: true, id });
} catch(e) { await connection.rollback(); res.status(500).json({ error: e.message }); } finally { connection.release(); }
});
app.put('/api/expenses/:id', authenticateToken, requireAdmin, async (req, res) => {
const { title, description, startDate, endDate, contractorName, items, shares, attachments } = req.body;
const expenseId = req.params.id;
const connection = await pool.getConnection();
try {
await connection.beginTransaction();
// Update main expense
const totalAmount = items.reduce((acc, i) => acc + i.amount, 0);
await connection.query(
'UPDATE extraordinary_expenses SET title = ?, description = ?, start_date = ?, end_date = ?, contractor_name = ?, total_amount = ? WHERE id = ?',
[title, description, startDate, endDate, contractorName, totalAmount, expenseId]
);
// Delete old items and insert new ones
await connection.query('DELETE FROM expense_items WHERE expense_id = ?', [expenseId]);
for (const item of items) {
await connection.query('INSERT INTO expense_items (id, expense_id, description, amount) VALUES (?, ?, ?, ?)', [uuidv4(), expenseId, item.description, item.amount]);
}
// Delete old shares and insert new ones
await connection.query('DELETE FROM expense_shares WHERE expense_id = ?', [expenseId]);
for (const share of shares) {
// Preserve existing paid amount if updating, otherwise start from 0
let amountPaid = 0;
let status = 'UNPAID';
if (share.id) {
const [oldShares] = await connection.query('SELECT amount_paid, status FROM expense_shares WHERE id = ?', [share.id]);
if (oldShares.length > 0) {
amountPaid = parseFloat(oldShares[0].amount_paid);
const due = parseFloat(share.amountDue);
if (amountPaid >= due - 0.01) status = 'PAID';
else if (amountPaid > 0) status = 'PARTIAL';
}
}
await connection.query('INSERT INTO expense_shares (id, expense_id, family_id, percentage, amount_due, amount_paid, status) VALUES (?, ?, ?, ?, ?, ?, ?)',
[uuidv4(), expenseId, share.familyId, share.percentage, share.amountDue, amountPaid, status]);
}
await connection.commit();
res.json({ success: true });
} catch(e) { await connection.rollback(); res.status(500).json({ error: e.message }); } finally { connection.release(); }
});
app.delete('/api/expenses/:id', authenticateToken, requireAdmin, async (req, res) => {
try {
await pool.query('DELETE FROM extraordinary_expenses WHERE id = ?', [req.params.id]);