feat(BillingManager): add functionality to calculate next payment date by adding one month to the last payment date
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 4m46s
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 4m46s
This commit is contained in:
@@ -295,6 +295,14 @@ function BillingManager() {
|
|||||||
return Math.ceil((nextPayment - now) / (1000 * 60 * 60 * 24));
|
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) {
|
function formatDate(dateString) {
|
||||||
if (!dateString) return '—';
|
if (!dateString) return '—';
|
||||||
@@ -459,12 +467,14 @@ function BillingManager() {
|
|||||||
const payments = [...(s.payments || [])];
|
const payments = [...(s.payments || [])];
|
||||||
payments.splice(index, 1);
|
payments.splice(index, 1);
|
||||||
const last = payments.slice().sort((a,b) => new Date(b.date) - new Date(a.date))[0];
|
const last = payments.slice().sort((a,b) => new Date(b.date) - new Date(a.date))[0];
|
||||||
|
const nextPaymentDate = addMonthToDate(last?.date);
|
||||||
return {
|
return {
|
||||||
...s,
|
...s,
|
||||||
payments,
|
payments,
|
||||||
lastPaymentDate: last?.date || '',
|
lastPaymentDate: last?.date || '',
|
||||||
lastPaymentAmount: last?.amount || 0,
|
lastPaymentAmount: last?.amount || 0,
|
||||||
lastPaymentCurrency: last?.currency || 'USD'
|
lastPaymentCurrency: last?.currency || 'USD',
|
||||||
|
nextPaymentDate: nextPaymentDate || s.nextPaymentDate
|
||||||
};
|
};
|
||||||
}));
|
}));
|
||||||
setShowDeletePaymentModal(false);
|
setShowDeletePaymentModal(false);
|
||||||
@@ -1081,7 +1091,8 @@ function BillingManager() {
|
|||||||
note: paymentDraft.note || ''
|
note: paymentDraft.note || ''
|
||||||
};
|
};
|
||||||
const last = payments.slice().sort((a,b) => new Date(b.date) - new Date(a.date))[0];
|
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);
|
setEditingPayment(null);
|
||||||
} else {
|
} else {
|
||||||
@@ -1094,7 +1105,8 @@ function BillingManager() {
|
|||||||
note: paymentDraft.note || ''
|
note: paymentDraft.note || ''
|
||||||
}];
|
}];
|
||||||
const last = payments.slice().sort((a,b) => new Date(b.date) - new Date(a.date))[0];
|
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);
|
setShowPaymentModal(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user