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