@accounter/server
Version:
Accounter GraphQL server
40 lines • 1.86 kB
JavaScript
import { format } from 'date-fns';
import { dateToTimelessDateString } from '../../../../shared/helpers/index.js';
import { calculateMonthlyVatTotalAmount, isWithinMonthlyVatAmountTolerance, } from '../../../reports/helpers/vat-report.helper.js';
import { getVatRecords } from '../../../reports/resolvers/get-vat-records.resolver.js';
import { getChargeTransactionsMeta } from '../../helpers/common.helper.js';
export const missingMonthlyVatInfoSuggestions = async (DbCharge, _, { injector }) => {
try {
const { transactionsAmount, transactionsMinDebitDate, transactionsMinEventDate } = await getChargeTransactionsMeta(DbCharge, injector);
if (transactionsAmount == null) {
return null;
}
const transactionDate = (transactionsMinEventDate ??
transactionsMinDebitDate ??
null);
if (!transactionDate) {
return null;
}
const reportMonthDate = new Date(transactionDate.getUTCFullYear(), transactionDate.getUTCMonth() - 1, 15);
const monthDate = dateToTimelessDateString(reportMonthDate);
const { income, expenses } = await getVatRecords({
filters: {
financialEntityId: DbCharge.owner_id,
monthDate,
},
}, injector, { includeChargeBuckets: false });
const monthlyVatTotalAmount = calculateMonthlyVatTotalAmount(income, expenses);
if (!isWithinMonthlyVatAmountTolerance(monthlyVatTotalAmount, transactionsAmount)) {
return null;
}
return {
description: `VAT for ${format(reportMonthDate, 'MM/yyyy')}`,
tags: [],
};
}
catch (error) {
console.error('Error in missingMonthlyVatInfoSuggestions:', error);
return null;
}
};
//# sourceMappingURL=monthly-vat-suggestions.resolver.js.map