mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 21:00:31 +00:00
feat(server): wip tax rate on sale invoice service
This commit is contained in:
@@ -2,6 +2,8 @@ import { Model } from 'objection';
|
||||
import TenantModel from 'models/TenantModel';
|
||||
|
||||
export default class ItemEntry extends TenantModel {
|
||||
public taxRate: number;
|
||||
|
||||
/**
|
||||
* Table name.
|
||||
*/
|
||||
@@ -17,7 +19,7 @@ export default class ItemEntry extends TenantModel {
|
||||
}
|
||||
|
||||
static get virtualAttributes() {
|
||||
return ['amount'];
|
||||
return ['amount', 'taxAmount'];
|
||||
}
|
||||
|
||||
get amount() {
|
||||
@@ -31,6 +33,22 @@ export default class ItemEntry extends TenantModel {
|
||||
return discount ? total - total * discount * 0.01 : total;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tag rate fraction.
|
||||
* @returns {number}
|
||||
*/
|
||||
get tagRateFraction() {
|
||||
return this.taxRate / 100;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tax amount withheld.
|
||||
* @returns {number}
|
||||
*/
|
||||
get taxAmount() {
|
||||
return this.amount * this.tagRateFraction;
|
||||
}
|
||||
|
||||
static get relationMappings() {
|
||||
const Item = require('models/Item');
|
||||
const BillLandedCostEntry = require('models/BillLandedCostEntry');
|
||||
|
||||
@@ -13,6 +13,11 @@ export default class SaleInvoice extends mixin(TenantModel, [
|
||||
CustomViewBaseModel,
|
||||
ModelSearchable,
|
||||
]) {
|
||||
taxAmountWithheld: number;
|
||||
balance: number;
|
||||
paymentAmount: number;
|
||||
exchangeRate: number;
|
||||
|
||||
/**
|
||||
* Table name
|
||||
*/
|
||||
@@ -51,12 +56,115 @@ export default class SaleInvoice extends mixin(TenantModel, [
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoice total FCY.
|
||||
* @returns {number}
|
||||
*/
|
||||
get totalFcy() {
|
||||
return this.amountFcy + this.taxAmountWithheldFcy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoice total BCY.
|
||||
* @returns {number}
|
||||
*/
|
||||
get totalBcy() {
|
||||
return this.amountBcy + this.taxAmountWithheldBcy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tax amount withheld FCY.
|
||||
* @returns {number}
|
||||
*/
|
||||
get taxAmountWithheldFcy() {
|
||||
return this.taxAmountWithheld;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tax amount withheld BCY.
|
||||
* @returns {number}
|
||||
*/
|
||||
get taxAmountWithheldBcy() {
|
||||
return this.taxAmountWithheld;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtotal FCY.
|
||||
* @returns {number}
|
||||
*/
|
||||
get subtotalFcy() {
|
||||
return this.amountFcy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtotal BCY.
|
||||
* @returns {number}
|
||||
*/
|
||||
get subtotalBcy() {
|
||||
return this.amountBcy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoice due amount FCY.
|
||||
* @returns {number}
|
||||
*/
|
||||
get dueAmountFcy() {
|
||||
return this.amountFcy - this.paymentAmountFcy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoice due amount BCY.
|
||||
* @returns {number}
|
||||
*/
|
||||
get dueAmountBcy() {
|
||||
return this.amountBcy - this.paymentAmountBcy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoice amount FCY.
|
||||
* @returns {number}
|
||||
*/
|
||||
get amountFcy() {
|
||||
return this.balance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoice amount BCY.
|
||||
* @returns {number}
|
||||
*/
|
||||
get amountBcy() {
|
||||
return this.balance * this.exchangeRate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoice payment amount FCY.
|
||||
* @returns {number}
|
||||
*/
|
||||
get paymentAmountFcy() {
|
||||
return this.paymentAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoice payment amount BCY.
|
||||
* @returns {number}
|
||||
*/
|
||||
get paymentAmountBcy() {
|
||||
return this.paymentAmount * this.exchangeRate;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
get total() {
|
||||
return this.balance + this.taxAmountWithheld;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoice amount in local currency.
|
||||
* @returns {number}
|
||||
*/
|
||||
get localAmount() {
|
||||
return this.balance * this.exchangeRate;
|
||||
return this.total * this.exchangeRate;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -333,6 +441,7 @@ export default class SaleInvoice extends mixin(TenantModel, [
|
||||
const PaymentReceiveEntry = require('models/PaymentReceiveEntry');
|
||||
const Branch = require('models/Branch');
|
||||
const Account = require('models/Account');
|
||||
const TaxRateTransaction = require('models/TaxRateTransaction');
|
||||
|
||||
return {
|
||||
/**
|
||||
@@ -428,6 +537,21 @@ export default class SaleInvoice extends mixin(TenantModel, [
|
||||
to: 'accounts.id',
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
taxes: {
|
||||
relation: Model.HasManyRelation,
|
||||
modelClass: TaxRateTransaction.default,
|
||||
join: {
|
||||
from: 'sales_invoices.id',
|
||||
to: 'tax_rate_transactions.referenceId',
|
||||
},
|
||||
filter(builder) {
|
||||
builder.where('reference_type', 'SaleInvoice');
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
42
packages/server/src/models/TaxRateTransaction.ts
Normal file
42
packages/server/src/models/TaxRateTransaction.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { mixin, Model, raw } from 'objection';
|
||||
import TenantModel from 'models/TenantModel';
|
||||
import ModelSearchable from './ModelSearchable';
|
||||
|
||||
export default class TaxRateTransaction extends mixin(TenantModel, [
|
||||
ModelSearchable,
|
||||
]) {
|
||||
/**
|
||||
* Table name
|
||||
*/
|
||||
static get tableName() {
|
||||
return 'tax_rate_transactions';
|
||||
}
|
||||
|
||||
/**
|
||||
* Timestamps columns.
|
||||
*/
|
||||
get timestamps() {
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Virtual attributes.
|
||||
*/
|
||||
static get virtualAttributes() {
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Model modifiers.
|
||||
*/
|
||||
static get modifiers() {
|
||||
return {};
|
||||
}
|
||||
|
||||
/**
|
||||
* Relationship mapping.
|
||||
*/
|
||||
static get relationMappings() {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user