mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 13:20:31 +00:00
feat(server): wip sale invoice tax rate GL entries
This commit is contained in:
@@ -42,6 +42,7 @@ exports.up = (knex) => {
|
||||
.unsigned()
|
||||
.references('id')
|
||||
.inTable('tax_rates');
|
||||
table.decimal('tax_rate').unsigned();
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -77,6 +77,9 @@ export interface IAccountTransaction {
|
||||
projectId?: number;
|
||||
|
||||
account?: IAccount;
|
||||
|
||||
taxRateId?: number;
|
||||
taxRate?: number;
|
||||
}
|
||||
export interface IAccountResponse extends IAccount {}
|
||||
|
||||
|
||||
@@ -47,7 +47,9 @@ export interface ILedgerEntry {
|
||||
itemId?: number;
|
||||
branchId?: number;
|
||||
projectId?: number;
|
||||
|
||||
taxRateId?: number;
|
||||
taxRate?: number;
|
||||
|
||||
entryId?: number;
|
||||
createdAt?: Date;
|
||||
|
||||
@@ -6,6 +6,10 @@ import { getTransactionTypeLabel } from '@/utils/transactions-types';
|
||||
|
||||
export default class AccountTransaction extends TenantModel {
|
||||
referenceType: string;
|
||||
credit: number;
|
||||
debit: number;
|
||||
exchangeRate: number;
|
||||
taxRate: number;
|
||||
|
||||
/**
|
||||
* Table name
|
||||
@@ -28,6 +32,54 @@ export default class AccountTransaction extends TenantModel {
|
||||
return ['referenceTypeFormatted'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the credit amount in foreign currency.
|
||||
* @return {number}
|
||||
*/
|
||||
get creditFcy() {
|
||||
return this.credit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the debit amount in foreign currency.
|
||||
* @return {number}
|
||||
*/
|
||||
get debitFcy() {
|
||||
return this.debit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the credit amount in base currency.
|
||||
* @return {number}
|
||||
*/
|
||||
get creditBcy() {
|
||||
return this.credit * this.exchangeRate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the debit amount in base currency.
|
||||
* @return {number}
|
||||
*/
|
||||
get debitBcy() {
|
||||
return this.debit * this.exchangeRate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the tax amount in foreign currency.
|
||||
* @return {number}
|
||||
*/
|
||||
get taxAmountFcy() {
|
||||
return (this.creditFcy - this.debitFcy) * this.taxRate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the tax amount in base currency.
|
||||
* @return {number}
|
||||
*/
|
||||
get taxAmountBcy() {
|
||||
return (this.creditBcy - this.debitBcy) * this.taxRate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve formatted reference type.
|
||||
* @return {string}
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
import moment from 'moment';
|
||||
import { castArray, sumBy, toArray } from 'lodash';
|
||||
import { IBill, ISystemUser, IAccount } from '@/interfaces';
|
||||
import { castArray } from 'lodash';
|
||||
import JournalPoster from './JournalPoster';
|
||||
import JournalEntry from './JournalEntry';
|
||||
import { IExpense, IExpenseCategory } from '@/interfaces';
|
||||
import { increment } from 'utils';
|
||||
|
||||
export default class JournalCommands {
|
||||
journal: JournalPoster;
|
||||
models: any;
|
||||
@@ -16,7 +12,6 @@ export default class JournalCommands {
|
||||
*/
|
||||
constructor(journal: JournalPoster) {
|
||||
this.journal = journal;
|
||||
|
||||
this.repositories = this.journal.repositories;
|
||||
this.models = this.journal.models;
|
||||
}
|
||||
|
||||
@@ -234,6 +234,9 @@ export default class Ledger implements ILedger {
|
||||
entryId: entry.id,
|
||||
branchId: entry.branchId,
|
||||
projectId: entry.projectId,
|
||||
|
||||
taxRateId: entry.taxRateId,
|
||||
taxRate: entry.taxRate,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -32,5 +32,8 @@ export const transformLedgerEntryToTransaction = (
|
||||
projectId: entry.projectId,
|
||||
|
||||
costable: entry.costable,
|
||||
|
||||
taxRateId: entry.taxRateId,
|
||||
taxRate: entry.taxRate,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -53,7 +53,7 @@ export class SaleInvoiceGLEntries {
|
||||
saleInvoice,
|
||||
ARAccount.id,
|
||||
taxPayableAccount.id
|
||||
);
|
||||
);
|
||||
// Commits the ledger entries to the storage as UOW.
|
||||
await this.ledegrRepository.commit(tenantId, ledger, trx);
|
||||
};
|
||||
@@ -190,6 +190,8 @@ export class SaleInvoiceGLEntries {
|
||||
itemQuantity: entry.quantity,
|
||||
accountNormal: AccountNormal.CREDIT,
|
||||
projectId: entry.projectId || saleInvoice.projectId,
|
||||
taxRateId: entry.taxRateId,
|
||||
taxRate: entry.taxRate,
|
||||
};
|
||||
}
|
||||
);
|
||||
@@ -201,15 +203,22 @@ export class SaleInvoiceGLEntries {
|
||||
* @returns {ILedgerEntry}
|
||||
*/
|
||||
private getInvoiceTaxEntry = R.curry(
|
||||
(saleInvoice: ISaleInvoice, taxPayableAccountId: number): ILedgerEntry => {
|
||||
(
|
||||
saleInvoice: ISaleInvoice,
|
||||
taxPayableAccountId: number,
|
||||
entry: IItemEntry,
|
||||
index: number
|
||||
): ILedgerEntry => {
|
||||
const commonEntry = this.getInvoiceGLCommonEntry(saleInvoice);
|
||||
|
||||
return {
|
||||
...commonEntry,
|
||||
credit: saleInvoice.taxAmountWithheld,
|
||||
credit: entry.taxAmount,
|
||||
accountId: taxPayableAccountId,
|
||||
index: saleInvoice.entries.length + 3,
|
||||
index: index + 3,
|
||||
accountNormal: AccountNormal.CREDIT,
|
||||
taxRateId: entry.taxRateId,
|
||||
taxRate : entry.taxRate,
|
||||
};
|
||||
}
|
||||
);
|
||||
@@ -230,10 +239,13 @@ export class SaleInvoiceGLEntries {
|
||||
ARAccountId
|
||||
);
|
||||
const transformItemEntry = this.getInvoiceItemEntry(saleInvoice);
|
||||
|
||||
const transformTaxEntry = this.getInvoiceTaxEntry(
|
||||
saleInvoice,
|
||||
taxPayableAccountId
|
||||
);
|
||||
const creditEntries = saleInvoice.entries.map(transformItemEntry);
|
||||
const taxEntry = this.getInvoiceTaxEntry(saleInvoice, taxPayableAccountId);
|
||||
const taxEntries = saleInvoice.entries.map(transformTaxEntry);
|
||||
|
||||
return [receivableEntry, ...creditEntries, taxEntry];
|
||||
return [receivableEntry, ...creditEntries, ...taxEntries];
|
||||
};
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ export class PaymentReceivesApplication {
|
||||
}
|
||||
|
||||
/**
|
||||
* deletes the given payment receive.
|
||||
* Deletes the given payment receive.
|
||||
* @param {number} tenantId
|
||||
* @param {number} paymentReceiveId
|
||||
* @param {ISystemUser} authorizedUser
|
||||
@@ -126,7 +126,7 @@ export class PaymentReceivesApplication {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Retrieves the given payment receive.
|
||||
* @param {number} tenantId
|
||||
* @param {number} paymentReceiveId
|
||||
* @returns {Promise<IPaymentReceive>}
|
||||
|
||||
Reference in New Issue
Block a user