diff --git a/frontend/src/BillingManager.jsx b/frontend/src/BillingManager.jsx index 0e44e10..204986e 100644 --- a/frontend/src/BillingManager.jsx +++ b/frontend/src/BillingManager.jsx @@ -295,6 +295,14 @@ function BillingManager() { return Math.ceil((nextPayment - now) / (1000 * 60 * 60 * 24)); }; + // Добавить 1 месяц к дате (для обновления nextPaymentDate после платежа) + const addMonthToDate = (dateString) => { + if (!dateString) return ''; + const d = new Date(dateString); + d.setMonth(d.getMonth() + 1); + return d.toISOString().slice(0, 10); + }; + // Форматирование function formatDate(dateString) { if (!dateString) return '—'; @@ -459,12 +467,14 @@ function BillingManager() { const payments = [...(s.payments || [])]; payments.splice(index, 1); const last = payments.slice().sort((a,b) => new Date(b.date) - new Date(a.date))[0]; + const nextPaymentDate = addMonthToDate(last?.date); return { ...s, payments, lastPaymentDate: last?.date || '', lastPaymentAmount: last?.amount || 0, - lastPaymentCurrency: last?.currency || 'USD' + lastPaymentCurrency: last?.currency || 'USD', + nextPaymentDate: nextPaymentDate || s.nextPaymentDate }; })); setShowDeletePaymentModal(false); @@ -1081,7 +1091,8 @@ function BillingManager() { note: paymentDraft.note || '' }; const last = payments.slice().sort((a,b) => new Date(b.date) - new Date(a.date))[0]; - return { ...s, payments, lastPaymentDate: last?.date || '', lastPaymentAmount: last?.amount || 0, lastPaymentCurrency: last?.currency || 'USD' }; + const nextPaymentDate = addMonthToDate(last?.date); + return { ...s, payments, lastPaymentDate: last?.date || '', lastPaymentAmount: last?.amount || 0, lastPaymentCurrency: last?.currency || 'USD', nextPaymentDate: nextPaymentDate || s.nextPaymentDate }; })); setEditingPayment(null); } else { @@ -1094,7 +1105,8 @@ function BillingManager() { note: paymentDraft.note || '' }]; const last = payments.slice().sort((a,b) => new Date(b.date) - new Date(a.date))[0]; - return { ...s, payments, lastPaymentDate: last?.date || '', lastPaymentAmount: last?.amount || 0, lastPaymentCurrency: last?.currency || 'USD' }; + const nextPaymentDate = addMonthToDate(last?.date); + return { ...s, payments, lastPaymentDate: last?.date || '', lastPaymentAmount: last?.amount || 0, lastPaymentCurrency: last?.currency || 'USD', nextPaymentDate: nextPaymentDate || s.nextPaymentDate }; })); } setShowPaymentModal(false);