export function sortEntityRecordsAndAddBalance(openingBalance, records) {
    const sortedRecords = records.sort((a, b) => {
        const diff = a.invoiceDate.getTime() - b.invoiceDate.getTime();
        if (diff === 0) {
            return a.id.localeCompare(b.id);
        }
        return diff;
    });
    let balance = openingBalance;
    const recordsWithBalance = sortedRecords.map(record => {
        balance += record.amount.raw;
        return {
            ...record,
            balance,
        };
    });
    return recordsWithBalance;
}
//# sourceMappingURL=yearly-ledger-report.helper.js.map