2022-04-19 05:59:36 +00:00
|
|
|
import { Fyo } from 'fyo';
|
|
|
|
import { Action, ListViewSettings } from 'fyo/model/types';
|
2022-05-03 13:13:47 +00:00
|
|
|
import { LedgerPosting } from 'models/Transactional/LedgerPosting';
|
2022-05-02 15:17:14 +00:00
|
|
|
import { ModelNameEnum } from 'models/types';
|
|
|
|
import { getInvoiceActions, getTransactionStatusColumn } from '../../helpers';
|
2022-04-14 09:22:45 +00:00
|
|
|
import { Invoice } from '../Invoice/Invoice';
|
|
|
|
import { PurchaseInvoiceItem } from '../PurchaseInvoiceItem/PurchaseInvoiceItem';
|
|
|
|
|
|
|
|
export class PurchaseInvoice extends Invoice {
|
|
|
|
items?: PurchaseInvoiceItem[];
|
|
|
|
|
|
|
|
async getPosting() {
|
2022-05-03 13:13:47 +00:00
|
|
|
const posting: LedgerPosting = new LedgerPosting(this, this.fyo);
|
2022-04-14 09:22:45 +00:00
|
|
|
|
2022-05-03 13:13:47 +00:00
|
|
|
await posting.credit(this.account!, this.baseGrandTotal!);
|
2022-04-14 09:22:45 +00:00
|
|
|
|
|
|
|
for (const item of this.items!) {
|
2022-05-03 13:13:47 +00:00
|
|
|
await posting.debit(item.account!, item.baseAmount!);
|
2022-04-14 09:22:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.taxes) {
|
|
|
|
for (const tax of this.taxes) {
|
2022-05-03 13:13:47 +00:00
|
|
|
await posting.debit(tax.account!, tax.baseAmount!);
|
2022-04-14 09:22:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-03 13:13:47 +00:00
|
|
|
await posting.makeRoundOffEntry();
|
|
|
|
return posting;
|
2022-04-14 09:22:45 +00:00
|
|
|
}
|
|
|
|
|
2022-04-19 05:59:36 +00:00
|
|
|
static getActions(fyo: Fyo): Action[] {
|
2022-05-02 15:17:14 +00:00
|
|
|
return getInvoiceActions(ModelNameEnum.PurchaseInvoice, fyo);
|
2022-04-18 11:29:20 +00:00
|
|
|
}
|
|
|
|
|
2022-04-28 12:37:07 +00:00
|
|
|
static getListViewSettings(): ListViewSettings {
|
2022-04-18 11:29:20 +00:00
|
|
|
return {
|
|
|
|
formRoute: (name) => `/edit/PurchaseInvoice/${name}`,
|
|
|
|
columns: [
|
|
|
|
'name',
|
2022-04-28 12:37:07 +00:00
|
|
|
getTransactionStatusColumn(),
|
2022-05-12 05:52:25 +00:00
|
|
|
'party',
|
2022-04-18 11:29:20 +00:00
|
|
|
'date',
|
|
|
|
'grandTotal',
|
|
|
|
'outstandingAmount',
|
|
|
|
],
|
|
|
|
};
|
|
|
|
}
|
2022-04-14 09:22:45 +00:00
|
|
|
}
|