diff --git a/app/services/page.tsx b/app/services/page.tsx index aeff381..5fe0792 100644 --- a/app/services/page.tsx +++ b/app/services/page.tsx @@ -105,12 +105,29 @@ export default function ServicesPage() {

{service?.label || bill.type}

-

{new Date(bill.date).toLocaleDateString('es-AR', { dateStyle: 'long' })}

+
+

{new Date(bill.date).toLocaleDateString('es-AR', { dateStyle: 'long' })}

+ {bill.usage && ( + <> + +

+ Consumo: {bill.usage} {bill.unit} +

+ + )} +

{formatCurrency(bill.amount)}

-

{bill.period}

+
+

{bill.period}

+ {bill.usage && bill.amount && ( +

+ {formatCurrency(bill.amount / bill.usage)} / {bill.unit} +

+ )} +
) diff --git a/components/modals/AddServiceModal.tsx b/components/modals/AddServiceModal.tsx index 0aef630..d3e9b2d 100644 --- a/components/modals/AddServiceModal.tsx +++ b/components/modals/AddServiceModal.tsx @@ -22,11 +22,24 @@ export function AddServiceModal({ isOpen, onClose }: AddServiceModalProps) { const [type, setType] = useState('electricity') const [amount, setAmount] = useState('') + const [usage, setUsage] = useState('') const [period, setPeriod] = useState(new Date().toISOString().slice(0, 7)) // YYYY-MM const [date, setDate] = useState(new Date().toISOString().split('T')[0]) if (!isOpen) return null + const getUnit = (serviceType: string) => { + switch (serviceType) { + case 'electricity': return 'kW' + case 'gas': return 'm³' + case 'water': return 'm³' + default: return '' + } + } + + const unit = getUnit(type) + const showUsage = type !== 'internet' + const handleSubmit = (e: React.FormEvent) => { e.preventDefault() @@ -35,6 +48,8 @@ export function AddServiceModal({ isOpen, onClose }: AddServiceModalProps) { addServiceBill({ type: type as any, amount: parseFloat(amount), + usage: usage ? parseFloat(usage) : undefined, + unit: unit || undefined, date: new Date(date).toISOString(), period: period, notes: '' @@ -42,6 +57,7 @@ export function AddServiceModal({ isOpen, onClose }: AddServiceModalProps) { // Reset setAmount('') + setUsage('') onClose() } @@ -81,22 +97,42 @@ export function AddServiceModal({ isOpen, onClose }: AddServiceModalProps) { })} - {/* Amount */} -
- -
- $ - setAmount(e.target.value)} - className="w-full pl-8 pr-4 py-3 bg-slate-950 border border-slate-800 rounded-lg focus:ring-2 focus:ring-cyan-500/50 focus:border-cyan-500 text-white text-lg font-mono outline-none" - required - autoFocus - /> +
+ {/* Amount */} +
+ +
+ $ + setAmount(e.target.value)} + className="w-full pl-8 pr-4 py-3 bg-slate-950 border border-slate-800 rounded-lg focus:ring-2 focus:ring-cyan-500/50 focus:border-cyan-500 text-white text-lg font-mono outline-none" + required + autoFocus + /> +
+ + {/* Usage */} + {showUsage && ( +
+ +
+ setUsage(e.target.value)} + className="w-full px-4 py-3 bg-slate-950 border border-slate-800 rounded-lg focus:ring-2 focus:ring-cyan-500/50 focus:border-cyan-500 text-white text-lg font-mono outline-none" + /> + {unit} +
+
+ )}
diff --git a/lib/types.ts b/lib/types.ts index b369283..3da0ad8 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -66,6 +66,8 @@ export interface ServiceBill { id: string type: 'electricity' | 'water' | 'gas' | 'internet' amount: number + usage?: number + unit?: string date: string period: string // YYYY-MM isPaid: boolean