2022-04-24 06:48:44 +00:00
|
|
|
import { Doc } from 'fyo/model/doc';
|
2022-04-19 05:59:36 +00:00
|
|
|
import { FiltersMap, FormulaMap } from 'fyo/model/types';
|
2022-04-11 09:41:49 +00:00
|
|
|
import Money from 'pesa/dist/types/src/money';
|
|
|
|
|
|
|
|
export class PaymentFor extends Doc {
|
|
|
|
formulas: FormulaMap = {
|
2022-04-29 13:00:24 +00:00
|
|
|
amount: {
|
|
|
|
formula: async () => {
|
|
|
|
if (!this.referenceName) {
|
|
|
|
return this.fyo.pesa(0);
|
|
|
|
}
|
2022-04-11 09:41:49 +00:00
|
|
|
|
2022-05-02 10:15:16 +00:00
|
|
|
const outstandingAmount = (await this.fyo.getValue(
|
2022-04-29 13:00:24 +00:00
|
|
|
this.referenceType as string,
|
|
|
|
this.referenceName as string,
|
|
|
|
'outstandingAmount'
|
2022-05-02 10:15:16 +00:00
|
|
|
)) as Money;
|
2022-04-11 09:41:49 +00:00
|
|
|
|
2022-04-29 13:00:24 +00:00
|
|
|
if (outstandingAmount) {
|
|
|
|
return outstandingAmount;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.fyo.pesa(0);
|
|
|
|
},
|
|
|
|
dependsOn: ['referenceName'],
|
2022-04-11 09:41:49 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static filters: FiltersMap = {
|
|
|
|
referenceName: () => ({
|
|
|
|
outstandingAmount: ['>', 0],
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
}
|