2022-11-22 09:12:49 +00:00
|
|
|
import { ListViewSettings } from 'fyo/model/types';
|
2022-05-03 13:13:47 +00:00
|
|
|
import { LedgerPosting } from 'models/Transactional/LedgerPosting';
|
2022-11-22 09:12:49 +00:00
|
|
|
import { 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-09-30 11:42:15 +00:00
|
|
|
const exchangeRate = this.exchangeRate ?? 1;
|
2022-05-03 13:13:47 +00:00
|
|
|
const posting: LedgerPosting = new LedgerPosting(this, this.fyo);
|
|
|
|
await posting.credit(this.account!, this.baseGrandTotal!);
|
2022-04-14 09:22:45 +00:00
|
|
|
|
|
|
|
for (const item of this.items!) {
|
2022-09-30 11:42:15 +00:00
|
|
|
await posting.debit(item.account!, item.amount!.mul(exchangeRate));
|
2022-04-14 09:22:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.taxes) {
|
|
|
|
for (const tax of this.taxes) {
|
2022-09-30 11:42:15 +00:00
|
|
|
await posting.debit(tax.account!, tax.amount!.mul(exchangeRate));
|
2022-04-14 09:22:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-15 07:35:07 +00:00
|
|
|
const discountAmount = await this.getTotalDiscount();
|
|
|
|
const discountAccount = this.fyo.singles.AccountingSettings
|
|
|
|
?.discountAccount as string | undefined;
|
|
|
|
if (discountAccount && discountAmount.isPositive()) {
|
2022-09-30 11:42:15 +00:00
|
|
|
await posting.credit(discountAccount, discountAmount.mul(exchangeRate));
|
2022-07-15 07:35:07 +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-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',
|
2022-10-03 08:18:02 +00:00
|
|
|
'baseGrandTotal',
|
2022-04-18 11:29:20 +00:00
|
|
|
'outstandingAmount',
|
|
|
|
],
|
|
|
|
};
|
|
|
|
}
|
2022-04-14 09:22:45 +00:00
|
|
|
}
|