mirror of
https://github.com/actualbudget/actual.git
synced 2026-10-12 02:10:19 +00:00
✨ Added support to pluggy date correction based on installments (#8380)
* Added support to pluggy date correction based on installments * md * Update packages/sync-server/src/app-pluggyai/app-pluggyai.js Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * date now considers instalments, originalDate is the date without it * creating new instance instead of same obj * code review * aligning to code review * simpler --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
coderabbitai[bot]
parent
74c925aaf6
commit
ae0594d294
@@ -45,6 +45,7 @@ const mappableFields: MappableField[] = [
|
||||
'booking_date',
|
||||
'value_date',
|
||||
'transaction_date',
|
||||
'originalDate',
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
@@ -137,6 +137,9 @@ app.post(
|
||||
newTrans.transactionId = trans.id;
|
||||
newTrans.sortOrder = transactionDate.getTime();
|
||||
|
||||
newTrans.originalDate = getDate(transactionDate);
|
||||
newTrans.date = getDate(getTransactionDateCorrected(trans));
|
||||
|
||||
delete trans.amount;
|
||||
|
||||
const finalTrans = { ...flattenObject(trans), ...newTrans };
|
||||
@@ -221,3 +224,27 @@ function getPayeeName(trans) {
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
//useful to avoid add month to day 31, which would result in day 01 skipping to the next month
|
||||
function addMonthsClamped(date, months) {
|
||||
const result = new Date(date);
|
||||
const day = result.getUTCDate();
|
||||
result.setUTCDate(1);
|
||||
result.setUTCMonth(result.getUTCMonth() + months);
|
||||
const lastDay = new Date(
|
||||
Date.UTC(result.getUTCFullYear(), result.getUTCMonth() + 1, 0),
|
||||
).getUTCDate();
|
||||
result.setUTCDate(Math.min(day, lastDay));
|
||||
return result;
|
||||
}
|
||||
|
||||
function getTransactionDateCorrected(trans) {
|
||||
if (trans.creditCardMetadata?.installmentNumber != null) {
|
||||
return addMonthsClamped(
|
||||
trans.creditCardMetadata.purchaseDate || trans.date,
|
||||
trans.creditCardMetadata.installmentNumber - 1,
|
||||
);
|
||||
}
|
||||
|
||||
return trans.date;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
---
|
||||
category: Enhancements
|
||||
authors: [lelemm]
|
||||
---
|
||||
|
||||
Add corrected installment dates for Pluggy credit card transactions, available as a mappable date field in bank sync settings.
|
||||
Reference in New Issue
Block a user