update
This commit is contained in:
@@ -251,8 +251,16 @@ export class ExportBuilder {
|
||||
const startDate = new Date();
|
||||
startDate.setDate(startDate.getDate() - days);
|
||||
|
||||
this.options.dateStart = startDate.toISOString().split('T')[0];
|
||||
this.options.dateEnd = endDate.toISOString().split('T')[0];
|
||||
// Format as DD-MM-YYYY for bunq API
|
||||
const formatDate = (date: Date): string => {
|
||||
const day = String(date.getDate()).padStart(2, '0');
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||
const year = date.getFullYear();
|
||||
return `${day}-${month}-${year}`;
|
||||
};
|
||||
|
||||
this.options.dateStart = formatDate(startDate);
|
||||
this.options.dateEnd = formatDate(endDate);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -264,8 +272,16 @@ export class ExportBuilder {
|
||||
const startDate = new Date(now.getFullYear(), now.getMonth() - 1, 1);
|
||||
const endDate = new Date(now.getFullYear(), now.getMonth(), 0);
|
||||
|
||||
this.options.dateStart = startDate.toISOString().split('T')[0];
|
||||
this.options.dateEnd = endDate.toISOString().split('T')[0];
|
||||
// Format as DD-MM-YYYY for bunq API
|
||||
const formatDate = (date: Date): string => {
|
||||
const day = String(date.getDate()).padStart(2, '0');
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||
const year = date.getFullYear();
|
||||
return `${day}-${month}-${year}`;
|
||||
};
|
||||
|
||||
this.options.dateStart = formatDate(startDate);
|
||||
this.options.dateEnd = formatDate(endDate);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@@ -2,6 +2,7 @@ import * as plugins from './bunq.plugins.js';
|
||||
import { BunqAccount } from './bunq.classes.account.js';
|
||||
import { BunqTransaction } from './bunq.classes.transaction.js';
|
||||
import { BunqPayment } from './bunq.classes.payment.js';
|
||||
import { ExportBuilder } from './bunq.classes.export.js';
|
||||
import type { IBunqPaginationOptions, IBunqMonetaryAccountBank } from './bunq.interfaces.js';
|
||||
|
||||
export type TAccountType = 'bank' | 'joint' | 'savings' | 'external' | 'light' | 'card' | 'external_savings' | 'savings_external';
|
||||
@@ -251,4 +252,60 @@ export class BunqMonetaryAccount {
|
||||
reason_description: reason
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get account statement with flexible date options
|
||||
* @param optionsArg - Options for statement generation
|
||||
* @returns ExportBuilder instance for creating the statement
|
||||
*/
|
||||
public getAccountStatement(optionsArg: {
|
||||
from?: Date;
|
||||
to?: Date;
|
||||
monthlyIndexedFrom0?: number;
|
||||
monthlyIndexedFrom1?: number;
|
||||
includeTransactionAttachments: boolean;
|
||||
}): ExportBuilder {
|
||||
const exportBuilder = new ExportBuilder(this.bunqAccountRef, this);
|
||||
|
||||
// Determine date range based on provided options
|
||||
let startDate: Date;
|
||||
let endDate: Date;
|
||||
|
||||
if (optionsArg.from && optionsArg.to) {
|
||||
// Use provided date range
|
||||
startDate = optionsArg.from;
|
||||
endDate = optionsArg.to;
|
||||
} else if (optionsArg.monthlyIndexedFrom0 !== undefined) {
|
||||
// Calculate date range for 0-indexed month
|
||||
const now = new Date();
|
||||
const targetDate = new Date(now.getFullYear(), now.getMonth() - optionsArg.monthlyIndexedFrom0, 1);
|
||||
startDate = new Date(targetDate.getFullYear(), targetDate.getMonth(), 1);
|
||||
endDate = new Date(targetDate.getFullYear(), targetDate.getMonth() + 1, 0);
|
||||
} else if (optionsArg.monthlyIndexedFrom1 !== undefined) {
|
||||
// Calculate date range for 1-indexed month (1 = last month, 2 = two months ago, etc.)
|
||||
const now = new Date();
|
||||
const targetDate = new Date(now.getFullYear(), now.getMonth() - optionsArg.monthlyIndexedFrom1, 1);
|
||||
startDate = new Date(targetDate.getFullYear(), targetDate.getMonth(), 1);
|
||||
endDate = new Date(targetDate.getFullYear(), targetDate.getMonth() + 1, 0);
|
||||
} else {
|
||||
// Default to last month if no date options provided
|
||||
const now = new Date();
|
||||
startDate = new Date(now.getFullYear(), now.getMonth() - 1, 1);
|
||||
endDate = new Date(now.getFullYear(), now.getMonth(), 0);
|
||||
}
|
||||
|
||||
// Format dates as DD-MM-YYYY (bunq API format)
|
||||
const formatDate = (date: Date): string => {
|
||||
const year = date.getFullYear();
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(date.getDate()).padStart(2, '0');
|
||||
return `${day}-${month}-${year}`;
|
||||
};
|
||||
|
||||
// Configure the export builder
|
||||
exportBuilder.dateRange(formatDate(startDate), formatDate(endDate));
|
||||
exportBuilder.includeAttachments(optionsArg.includeTransactionAttachments);
|
||||
|
||||
return exportBuilder;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user