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 { SalesInvoiceItem } from '../SalesInvoiceItem/SalesInvoiceItem';
|
|
|
|
|
|
|
|
export class SalesInvoice extends Invoice {
|
|
|
|
items?: SalesInvoiceItem[];
|
|
|
|
|
|
|
|
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.debit(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.credit(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.credit(tax.account!, tax.amount!.mul(exchangeRate));
|
2022-04-14 09:22:45 +00:00
|
|
|
}
|
|
|
|
}
|
2022-05-03 13:13:47 +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.debit(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-19 05:59:36 +00:00
|
|
|
static getActions(fyo: Fyo): Action[] {
|
2022-05-02 15:17:14 +00:00
|
|
|
return getInvoiceActions(ModelNameEnum.SalesInvoice, fyo);
|
2022-04-18 11:29:20 +00:00
|
|
|
}
|
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/SalesInvoice/${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
|
|
|
}
|