mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 23:00:34 +00:00
feat: discount vendor credit
This commit is contained in:
@@ -0,0 +1,23 @@
|
|||||||
|
/**
|
||||||
|
* @param { import("knex").Knex } knex
|
||||||
|
* @returns { Promise<void> }
|
||||||
|
*/
|
||||||
|
exports.up = function(knex) {
|
||||||
|
return knex.schema.alterTable('vendor_credits', (table) => {
|
||||||
|
table.decimal('discount', 10, 2).nullable().after('amount');
|
||||||
|
table.string('discount_type').nullable().after('discount');
|
||||||
|
table.decimal('adjustment', 10, 2).nullable().after('discount_type');
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param { import("knex").Knex } knex
|
||||||
|
* @returns { Promise<void> }
|
||||||
|
*/
|
||||||
|
exports.down = function(knex) {
|
||||||
|
return knex.schema.alterTable('vendor_credits', (table) => {
|
||||||
|
table.dropColumn('discount');
|
||||||
|
table.dropColumn('discount_type');
|
||||||
|
table.dropColumn('adjustment');
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -104,20 +104,37 @@ export default class Bill extends mixin(TenantModel, [
|
|||||||
return this.taxAmountWithheld * this.exchangeRate;
|
return this.taxAmountWithheld * this.exchangeRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Discount amount.
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
|
get discountAmount() {
|
||||||
|
return this.discountType === DiscountType.Amount
|
||||||
|
? this.discount
|
||||||
|
: this.subtotal * (this.discount / 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Discount percentage.
|
||||||
|
* @returns {number | null}
|
||||||
|
*/
|
||||||
|
get discountPercentage(): number | null {
|
||||||
|
return this.discountType === DiscountType.Percentage ? this.discount : null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoice total. (Tax included)
|
* Invoice total. (Tax included)
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
get total() {
|
get total() {
|
||||||
const discountAmount = this.discountType === DiscountType.Amount
|
|
||||||
? this.discount
|
|
||||||
: this.subtotal * (this.discount / 100);
|
|
||||||
|
|
||||||
const adjustmentAmount = defaultTo(this.adjustment, 0);
|
const adjustmentAmount = defaultTo(this.adjustment, 0);
|
||||||
|
|
||||||
return this.isInclusiveTax
|
return this.isInclusiveTax
|
||||||
? this.subtotal - discountAmount - adjustmentAmount
|
? this.subtotal - this.discountAmount - adjustmentAmount
|
||||||
: this.subtotal + this.taxAmountWithheld - discountAmount - adjustmentAmount;
|
: this.subtotal +
|
||||||
|
this.taxAmountWithheld -
|
||||||
|
this.discountAmount -
|
||||||
|
adjustmentAmount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -58,6 +58,24 @@ export default class VendorCredit extends mixin(TenantModel, [
|
|||||||
return this.subtotal * this.exchangeRate;
|
return this.subtotal * this.exchangeRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Discount amount.
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
|
get discountAmount() {
|
||||||
|
return this.discountType === DiscountType.Amount
|
||||||
|
? this.discount
|
||||||
|
: this.subtotal * (this.discount / 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Discount percentage.
|
||||||
|
* @returns {number | null}
|
||||||
|
*/
|
||||||
|
get discountPercentage(): number | null {
|
||||||
|
return this.discountType === DiscountType.Percentage ? this.discount : null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vendor credit total.
|
* Vendor credit total.
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ export class PurchaseInvoiceTransformer extends Transformer {
|
|||||||
'subtotalLocalFormatted',
|
'subtotalLocalFormatted',
|
||||||
'subtotalExcludingTaxFormatted',
|
'subtotalExcludingTaxFormatted',
|
||||||
'taxAmountWithheldLocalFormatted',
|
'taxAmountWithheldLocalFormatted',
|
||||||
|
'discountAmountFormatted',
|
||||||
|
'discountPercentageFormatted',
|
||||||
|
'adjustmentFormatted',
|
||||||
'totalFormatted',
|
'totalFormatted',
|
||||||
'totalLocalFormatted',
|
'totalLocalFormatted',
|
||||||
'taxes',
|
'taxes',
|
||||||
@@ -160,6 +163,39 @@ export class PurchaseInvoiceTransformer extends Transformer {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the formatted discount amount.
|
||||||
|
* @param {IBill} bill
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
protected discountAmountFormatted = (bill): string => {
|
||||||
|
return formatNumber(bill.discountAmount, {
|
||||||
|
currencyCode: bill.currencyCode,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the formatted discount percentage.
|
||||||
|
* @param {IBill} bill
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
protected discountPercentageFormatted = (bill): string => {
|
||||||
|
return bill.discountPercentage
|
||||||
|
? `${bill.discountPercentage}%`
|
||||||
|
: '';
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the formatted adjustment amount.
|
||||||
|
* @param {IBill} bill
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
protected adjustmentFormatted = (bill): string => {
|
||||||
|
return formatNumber(bill.adjustment, {
|
||||||
|
currencyCode: bill.currencyCode,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the total formatted.
|
* Retrieves the total formatted.
|
||||||
* @param {IBill} bill
|
* @param {IBill} bill
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ export class VendorCreditTransformer extends Transformer {
|
|||||||
'formattedCreatedAt',
|
'formattedCreatedAt',
|
||||||
'formattedCreditsRemaining',
|
'formattedCreditsRemaining',
|
||||||
'formattedInvoicedAmount',
|
'formattedInvoicedAmount',
|
||||||
|
'discountAmountFormatted',
|
||||||
|
'discountPercentageFormatted',
|
||||||
|
'adjustmentFormatted',
|
||||||
'entries',
|
'entries',
|
||||||
'attachments',
|
'attachments',
|
||||||
];
|
];
|
||||||
@@ -33,7 +36,7 @@ export class VendorCreditTransformer extends Transformer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retireve formatted created at date.
|
* Retireve formatted created at date.
|
||||||
* @param vendorCredit
|
* @param vendorCredit
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
protected formattedCreatedAt = (vendorCredit): string => {
|
protected formattedCreatedAt = (vendorCredit): string => {
|
||||||
@@ -71,6 +74,37 @@ export class VendorCreditTransformer extends Transformer {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the formatted discount amount.
|
||||||
|
* @param {IVendorCredit} credit
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
protected discountAmountFormatted = (credit): string => {
|
||||||
|
return formatNumber(credit.discountAmount, {
|
||||||
|
currencyCode: credit.currencyCode,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the formatted discount percentage.
|
||||||
|
* @param {IVendorCredit} credit
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
protected discountPercentageFormatted = (credit): string => {
|
||||||
|
return credit.discountPercentage ? `${credit.discountPercentage}%` : '';
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the formatted adjustment amount.
|
||||||
|
* @param {IVendorCredit} credit
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
protected adjustmentFormatted = (credit): string => {
|
||||||
|
return formatNumber(credit.adjustment, {
|
||||||
|
currencyCode: credit.currencyCode,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the formatted invoiced amount.
|
* Retrieves the formatted invoiced amount.
|
||||||
* @param credit
|
* @param credit
|
||||||
|
|||||||
Reference in New Issue
Block a user