2022-10-03 08:18:02 +00:00
|
|
|
import { Fyo } from 'fyo';
|
|
|
|
import { DocValueMap } from 'fyo/core/types';
|
2022-04-24 06:48:44 +00:00
|
|
|
import { Doc } from 'fyo/model/doc';
|
2022-10-03 08:18:02 +00:00
|
|
|
import { CurrenciesMap } from 'fyo/model/types';
|
|
|
|
import { DEFAULT_CURRENCY } from 'fyo/utils/consts';
|
2022-05-23 05:30:54 +00:00
|
|
|
import { Money } from 'pesa';
|
2022-10-03 08:18:02 +00:00
|
|
|
import { FieldTypeEnum, Schema } from 'schemas/types';
|
|
|
|
import { Invoice } from '../Invoice/Invoice';
|
2022-04-11 09:41:49 +00:00
|
|
|
|
|
|
|
export class TaxSummary extends Doc {
|
2022-04-14 09:22:45 +00:00
|
|
|
account?: string;
|
2023-12-02 21:57:11 +00:00
|
|
|
from_account?: string;
|
2022-04-14 09:22:45 +00:00
|
|
|
rate?: number;
|
|
|
|
amount?: Money;
|
2022-10-03 08:18:02 +00:00
|
|
|
parentdoc?: Invoice;
|
|
|
|
|
|
|
|
get exchangeRate() {
|
|
|
|
return this.parentdoc?.exchangeRate ?? 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
get currency() {
|
|
|
|
return this.parentdoc?.currency ?? DEFAULT_CURRENCY;
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(schema: Schema, data: DocValueMap, fyo: Fyo) {
|
|
|
|
super(schema, data, fyo);
|
|
|
|
this._setGetCurrencies();
|
|
|
|
}
|
|
|
|
|
|
|
|
getCurrencies: CurrenciesMap = {};
|
|
|
|
_getCurrency() {
|
|
|
|
if (this.exchangeRate === 1) {
|
|
|
|
return this.fyo.singles.SystemSettings?.currency ?? DEFAULT_CURRENCY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.currency;
|
|
|
|
}
|
|
|
|
_setGetCurrencies() {
|
|
|
|
const currencyFields = this.schema.fields.filter(
|
|
|
|
({ fieldtype }) => fieldtype === FieldTypeEnum.Currency
|
|
|
|
);
|
|
|
|
|
|
|
|
const getCurrency = this._getCurrency.bind(this);
|
|
|
|
|
|
|
|
for (const { fieldname } of currencyFields) {
|
|
|
|
this.getCurrencies[fieldname] ??= getCurrency;
|
|
|
|
}
|
|
|
|
}
|
2022-04-11 09:41:49 +00:00
|
|
|
}
|