diff --git a/pages/ExtraordinaryAdmin.tsx b/pages/ExtraordinaryAdmin.tsx index 13aff04..1f3c9cf 100644 --- a/pages/ExtraordinaryAdmin.tsx +++ b/pages/ExtraordinaryAdmin.tsx @@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react'; import { CondoService } from '../services/mockDb'; import { ExtraordinaryExpense, Family, ExpenseItem, ExpenseShare } from '../types'; -import { Plus, Calendar, FileText, CheckCircle2, Clock, Users, X, Save, Paperclip, Euro, Trash2, Eye, Briefcase, Pencil } from 'lucide-react'; +import { Plus, Calendar, FileText, CheckCircle2, Clock, Users, X, Save, Paperclip, Euro, Trash2, Eye, Briefcase, Pencil, Banknote } from 'lucide-react'; export const ExtraordinaryAdmin: React.FC = () => { const [expenses, setExpenses] = useState([]); @@ -26,6 +26,13 @@ export const ExtraordinaryAdmin: React.FC = () => { const [formAttachments, setFormAttachments] = useState<{fileName: string, fileType: string, data: string}[]>([]); const [selectedFamilyIds, setSelectedFamilyIds] = useState([]); // Helper to track checkboxes + // Manual Payment Modal State + const [showPayModal, setShowPayModal] = useState(false); + const [payShare, setPayShare] = useState(null); + const [payAmount, setPayAmount] = useState(0); + const [payNotes, setPayNotes] = useState(''); + const [isPaying, setIsPaying] = useState(false); + useEffect(() => { loadData(); }, []); @@ -229,6 +236,36 @@ export const ExtraordinaryAdmin: React.FC = () => { } catch(e) { alert("Errore file"); } }; + // MANUAL PAYMENT HANDLERS + const openPayModal = (share: ExpenseShare) => { + const remaining = Math.max(0, share.amountDue - share.amountPaid); + setPayShare(share); + setPayAmount(remaining); + setPayNotes('Saldo manuale'); + setShowPayModal(true); + }; + + const handleManualPayment = async (e: React.FormEvent) => { + e.preventDefault(); + if (!selectedExpense || !payShare) return; + + setIsPaying(true); + try { + // Updated API allows Admins to pass familyId to pay on their behalf + await CondoService.payExpense(selectedExpense.id, payAmount, payShare.familyId); + + // Refresh Details + const updated = await CondoService.getExpenseDetails(selectedExpense.id); + setSelectedExpense(updated); + setShowPayModal(false); + } catch (e: any) { + console.error(e); + alert("Errore registrazione pagamento: " + (e.message || "Errore sconosciuto")); + } finally { + setIsPaying(false); + } + }; + return (
@@ -440,6 +477,7 @@ export const ExtraordinaryAdmin: React.FC = () => { Da Pagare Versato Stato + Azioni @@ -458,6 +496,17 @@ export const ExtraordinaryAdmin: React.FC = () => { {share.status === 'PAID' ? 'Saldato' : share.status === 'PARTIAL' ? 'Parziale' : 'Insoluto'} + + {share.status !== 'PAID' && ( + + )} + ))} @@ -468,7 +517,7 @@ export const ExtraordinaryAdmin: React.FC = () => { € {selectedExpense.shares?.reduce((a,b) => a + b.amountPaid, 0).toLocaleString()} - + @@ -478,6 +527,57 @@ export const ExtraordinaryAdmin: React.FC = () => {
)} + + {/* MANUAL PAYMENT MODAL */} + {showPayModal && payShare && ( +
+
+
+

Registra Pagamento

+ +
+ +
+
+

Famiglia: {payShare.familyName}

+

Restante da pagare: € {(payShare.amountDue - payShare.amountPaid).toFixed(2)}

+
+ +
+ +
+ + setPayAmount(parseFloat(e.target.value))} + required + /> +
+
+ +
+ + setPayNotes(e.target.value)} + /> +
+ +
+ + +
+
+
+
+ )} ); };