fix: discount transactions GL entries

This commit is contained in:
Ahmed Bouhuolia
2024-12-08 14:20:11 +02:00
parent 14ae978bde
commit 46719ef361
17 changed files with 375 additions and 58 deletions

View File

@@ -1,6 +1,7 @@
import { Model, raw, mixin } from 'objection';
import { castArray, defaultTo, difference } from 'lodash';
import moment from 'moment';
import * as R from 'ramda';
import TenantModel from 'models/TenantModel';
import BillSettings from './Bill.Settings';
import ModelSetting from './ModelSetting';
@@ -133,12 +134,11 @@ export default class Bill extends mixin(TenantModel, [
get total() {
const adjustmentAmount = defaultTo(this.adjustment, 0);
return this.isInclusiveTax
? this.subtotal - this.discountAmount - adjustmentAmount
: this.subtotal +
this.taxAmountWithheld -
this.discountAmount -
adjustmentAmount;
return R.compose(
R.add(adjustmentAmount),
R.subtract(this.discountAmount),
R.when(R.always(this.isInclusiveTax), R.add(this.taxAmountWithheld))
)(this.subtotal);
}
/**

View File

@@ -107,7 +107,7 @@ export default class CreditNote extends mixin(TenantModel, [
* @returns {number}
*/
get total() {
return this.subtotal - this.discountAmount - this.adjustment;
return this.subtotal - this.discountAmount + this.adjustment;
}
/**

View File

@@ -116,7 +116,7 @@ export default class SaleEstimate extends mixin(TenantModel, [
get total() {
const adjustmentAmount = defaultTo(this.adjustment, 0);
return this.subtotal - this.discountAmount - adjustmentAmount;
return this.subtotal - this.discountAmount + adjustmentAmount;
}
/**

View File

@@ -1,4 +1,5 @@
import { mixin, Model, raw } from 'objection';
import * as R from 'ramda';
import { castArray, defaultTo, takeWhile } from 'lodash';
import moment from 'moment';
import TenantModel from 'models/TenantModel';
@@ -147,9 +148,7 @@ export default class SaleInvoice extends mixin(TenantModel, [
* @returns {number | null}
*/
get discountPercentage(): number | null {
return this.discountType === DiscountType.Percentage
? this.discount
: null;
return this.discountType === DiscountType.Percentage ? this.discount : null;
}
/**
@@ -158,11 +157,12 @@ export default class SaleInvoice extends mixin(TenantModel, [
*/
get total() {
const adjustmentAmount = defaultTo(this.adjustment, 0);
const differencies = this.discountAmount + adjustmentAmount;
return this.isInclusiveTax
? this.subtotal - differencies
: this.subtotal + this.taxAmountWithheld - differencies;
return R.compose(
R.add(adjustmentAmount),
R.subtract(R.__, this.discountAmount),
R.when(R.always(this.isInclusiveTax), R.add(this.taxAmountWithheld))
)(this.subtotal);
}
/**

View File

@@ -108,7 +108,7 @@ export default class SaleReceipt extends mixin(TenantModel, [
get total() {
const adjustmentAmount = defaultTo(this.adjustment, 0);
return this.subtotal - this.discountAmount - adjustmentAmount;
return this.subtotal - this.discountAmount + adjustmentAmount;
}
/**

View File

@@ -73,7 +73,7 @@ export default class VendorCredit extends mixin(TenantModel, [
* @returns {number}
*/
get total() {
return this.subtotal - this.discountAmount - this.adjustment;
return this.subtotal - this.discountAmount + this.adjustment;
}
/**