av6-core 1.0.21 → 1.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +11 -7
- package/dist/index.mjs +11 -7
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1131,6 +1131,9 @@ var maybeStep = (v, stepwise, fmt, p) => stepwise ? applyRound(v, fmt, p) : v;
|
|
|
1131
1131
|
function clamp(n, min, max) {
|
|
1132
1132
|
return Math.max(min, Math.min(max, n));
|
|
1133
1133
|
}
|
|
1134
|
+
var percentage = (amount, percentage2) => {
|
|
1135
|
+
return amount * percentage2 / 100;
|
|
1136
|
+
};
|
|
1134
1137
|
function calculateBillingFromChildren(inputs, masterExtra, options = {}) {
|
|
1135
1138
|
const stepwise = options.calculationMethod === "STEP_WISE";
|
|
1136
1139
|
const lineFmt = options.lineRound ?? RoundFormat.TO_FIXED;
|
|
@@ -1139,7 +1142,7 @@ function calculateBillingFromChildren(inputs, masterExtra, options = {}) {
|
|
|
1139
1142
|
const children = inputs.map((it) => {
|
|
1140
1143
|
let baseRate = it.rate;
|
|
1141
1144
|
if (it.addonPercentage) {
|
|
1142
|
-
baseRate = baseRate + baseRate
|
|
1145
|
+
baseRate = baseRate + percentage(baseRate, it.addonPercentage);
|
|
1143
1146
|
baseRate = maybeStep(baseRate, stepwise, lineFmt, precision);
|
|
1144
1147
|
}
|
|
1145
1148
|
const subtotal = applyRound(it.qty * baseRate, lineFmt, precision);
|
|
@@ -1149,28 +1152,29 @@ function calculateBillingFromChildren(inputs, masterExtra, options = {}) {
|
|
|
1149
1152
|
if (masterExtra.coPayMode === "PERCENTAGE-AMOUNT") {
|
|
1150
1153
|
const copayType = it.coPaymentType ?? "AMOUNT";
|
|
1151
1154
|
const copayValue = it.coPayValue ?? 0;
|
|
1152
|
-
copayAmount2 = copayType === "PERCENTAGE" ?
|
|
1155
|
+
copayAmount2 = copayType === "PERCENTAGE" ? percentage(subtotal, copayValue) : Math.min(copayValue, subtotal);
|
|
1153
1156
|
}
|
|
1154
1157
|
const dMode = it.discountMode ?? "AMOUNT";
|
|
1155
1158
|
const dVal = it.discountValue ?? 0;
|
|
1156
1159
|
const tMethod = it.taxMethod ?? "NONE";
|
|
1157
1160
|
const tVal = Math.max(0, it.taxValue ?? 0);
|
|
1158
|
-
let baseAfterTaxDisc =
|
|
1161
|
+
let baseAfterTaxDisc = basePreTax;
|
|
1159
1162
|
let discountValue = 0;
|
|
1160
1163
|
if (tMethod === "INCLUSIVE") {
|
|
1161
1164
|
const inclusiveTaxMultiplier = (100 + tVal) / 100;
|
|
1162
1165
|
baseAfterTaxDisc = basePreTax / inclusiveTaxMultiplier;
|
|
1163
1166
|
}
|
|
1164
1167
|
baseAfterTaxDisc = maybeStep(baseAfterTaxDisc, stepwise, lineFmt, precision);
|
|
1168
|
+
const inxInclusiveDiff = applyRound(basePreTax - baseAfterTaxDisc, lineFmt, precision);
|
|
1165
1169
|
if (dMode === "AMOUNT") {
|
|
1166
1170
|
discountValue = dVal;
|
|
1167
1171
|
} else if (dMode === "PERCENTAGE") {
|
|
1168
|
-
discountValue = baseAfterTaxDisc
|
|
1172
|
+
discountValue = percentage(baseAfterTaxDisc, dVal);
|
|
1169
1173
|
}
|
|
1170
1174
|
discountValue = maybeStep(discountValue, stepwise, lineFmt, precision);
|
|
1171
1175
|
let afterDisc = Math.max(0, baseAfterTaxDisc - discountValue);
|
|
1172
1176
|
afterDisc = maybeStep(afterDisc, stepwise, lineFmt, precision);
|
|
1173
|
-
let calculatedTax =
|
|
1177
|
+
let calculatedTax = percentage(afterDisc, tVal);
|
|
1174
1178
|
calculatedTax = maybeStep(calculatedTax, stepwise, lineFmt, precision);
|
|
1175
1179
|
let grossAmount2 = afterDisc + calculatedTax;
|
|
1176
1180
|
grossAmount2 = maybeStep(grossAmount2, stepwise, lineFmt, precision);
|
|
@@ -1184,7 +1188,7 @@ function calculateBillingFromChildren(inputs, masterExtra, options = {}) {
|
|
|
1184
1188
|
const lineRoundOff = patientRounded - patientRaw;
|
|
1185
1189
|
return {
|
|
1186
1190
|
baseRate: applyRound(baseRate, lineFmt, precision),
|
|
1187
|
-
subtotalAmount: subtotal,
|
|
1191
|
+
subtotalAmount: applyRound(subtotal + other - inxInclusiveDiff, lineFmt, precision),
|
|
1188
1192
|
otherChargeAmount: other,
|
|
1189
1193
|
discountMode: dMode,
|
|
1190
1194
|
discountValue: dVal,
|
|
@@ -1211,7 +1215,7 @@ function calculateBillingFromChildren(inputs, masterExtra, options = {}) {
|
|
|
1211
1215
|
const patientRawTotal = grossAmount - copayAmount;
|
|
1212
1216
|
let masterExtraApplied = 0;
|
|
1213
1217
|
if (masterExtra.mode === "PERCENTAGE") {
|
|
1214
|
-
masterExtraApplied = patientRawTotal
|
|
1218
|
+
masterExtraApplied = percentage(patientRawTotal, masterExtra.value);
|
|
1215
1219
|
} else if (masterExtra.mode === "AMOUNT") {
|
|
1216
1220
|
masterExtraApplied = Math.min(masterExtra.value, patientRawTotal);
|
|
1217
1221
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1083,6 +1083,9 @@ var maybeStep = (v, stepwise, fmt, p) => stepwise ? applyRound(v, fmt, p) : v;
|
|
|
1083
1083
|
function clamp(n, min, max) {
|
|
1084
1084
|
return Math.max(min, Math.min(max, n));
|
|
1085
1085
|
}
|
|
1086
|
+
var percentage = (amount, percentage2) => {
|
|
1087
|
+
return amount * percentage2 / 100;
|
|
1088
|
+
};
|
|
1086
1089
|
function calculateBillingFromChildren(inputs, masterExtra, options = {}) {
|
|
1087
1090
|
const stepwise = options.calculationMethod === "STEP_WISE";
|
|
1088
1091
|
const lineFmt = options.lineRound ?? RoundFormat.TO_FIXED;
|
|
@@ -1091,7 +1094,7 @@ function calculateBillingFromChildren(inputs, masterExtra, options = {}) {
|
|
|
1091
1094
|
const children = inputs.map((it) => {
|
|
1092
1095
|
let baseRate = it.rate;
|
|
1093
1096
|
if (it.addonPercentage) {
|
|
1094
|
-
baseRate = baseRate + baseRate
|
|
1097
|
+
baseRate = baseRate + percentage(baseRate, it.addonPercentage);
|
|
1095
1098
|
baseRate = maybeStep(baseRate, stepwise, lineFmt, precision);
|
|
1096
1099
|
}
|
|
1097
1100
|
const subtotal = applyRound(it.qty * baseRate, lineFmt, precision);
|
|
@@ -1101,28 +1104,29 @@ function calculateBillingFromChildren(inputs, masterExtra, options = {}) {
|
|
|
1101
1104
|
if (masterExtra.coPayMode === "PERCENTAGE-AMOUNT") {
|
|
1102
1105
|
const copayType = it.coPaymentType ?? "AMOUNT";
|
|
1103
1106
|
const copayValue = it.coPayValue ?? 0;
|
|
1104
|
-
copayAmount2 = copayType === "PERCENTAGE" ?
|
|
1107
|
+
copayAmount2 = copayType === "PERCENTAGE" ? percentage(subtotal, copayValue) : Math.min(copayValue, subtotal);
|
|
1105
1108
|
}
|
|
1106
1109
|
const dMode = it.discountMode ?? "AMOUNT";
|
|
1107
1110
|
const dVal = it.discountValue ?? 0;
|
|
1108
1111
|
const tMethod = it.taxMethod ?? "NONE";
|
|
1109
1112
|
const tVal = Math.max(0, it.taxValue ?? 0);
|
|
1110
|
-
let baseAfterTaxDisc =
|
|
1113
|
+
let baseAfterTaxDisc = basePreTax;
|
|
1111
1114
|
let discountValue = 0;
|
|
1112
1115
|
if (tMethod === "INCLUSIVE") {
|
|
1113
1116
|
const inclusiveTaxMultiplier = (100 + tVal) / 100;
|
|
1114
1117
|
baseAfterTaxDisc = basePreTax / inclusiveTaxMultiplier;
|
|
1115
1118
|
}
|
|
1116
1119
|
baseAfterTaxDisc = maybeStep(baseAfterTaxDisc, stepwise, lineFmt, precision);
|
|
1120
|
+
const inxInclusiveDiff = applyRound(basePreTax - baseAfterTaxDisc, lineFmt, precision);
|
|
1117
1121
|
if (dMode === "AMOUNT") {
|
|
1118
1122
|
discountValue = dVal;
|
|
1119
1123
|
} else if (dMode === "PERCENTAGE") {
|
|
1120
|
-
discountValue = baseAfterTaxDisc
|
|
1124
|
+
discountValue = percentage(baseAfterTaxDisc, dVal);
|
|
1121
1125
|
}
|
|
1122
1126
|
discountValue = maybeStep(discountValue, stepwise, lineFmt, precision);
|
|
1123
1127
|
let afterDisc = Math.max(0, baseAfterTaxDisc - discountValue);
|
|
1124
1128
|
afterDisc = maybeStep(afterDisc, stepwise, lineFmt, precision);
|
|
1125
|
-
let calculatedTax =
|
|
1129
|
+
let calculatedTax = percentage(afterDisc, tVal);
|
|
1126
1130
|
calculatedTax = maybeStep(calculatedTax, stepwise, lineFmt, precision);
|
|
1127
1131
|
let grossAmount2 = afterDisc + calculatedTax;
|
|
1128
1132
|
grossAmount2 = maybeStep(grossAmount2, stepwise, lineFmt, precision);
|
|
@@ -1136,7 +1140,7 @@ function calculateBillingFromChildren(inputs, masterExtra, options = {}) {
|
|
|
1136
1140
|
const lineRoundOff = patientRounded - patientRaw;
|
|
1137
1141
|
return {
|
|
1138
1142
|
baseRate: applyRound(baseRate, lineFmt, precision),
|
|
1139
|
-
subtotalAmount: subtotal,
|
|
1143
|
+
subtotalAmount: applyRound(subtotal + other - inxInclusiveDiff, lineFmt, precision),
|
|
1140
1144
|
otherChargeAmount: other,
|
|
1141
1145
|
discountMode: dMode,
|
|
1142
1146
|
discountValue: dVal,
|
|
@@ -1163,7 +1167,7 @@ function calculateBillingFromChildren(inputs, masterExtra, options = {}) {
|
|
|
1163
1167
|
const patientRawTotal = grossAmount - copayAmount;
|
|
1164
1168
|
let masterExtraApplied = 0;
|
|
1165
1169
|
if (masterExtra.mode === "PERCENTAGE") {
|
|
1166
|
-
masterExtraApplied = patientRawTotal
|
|
1170
|
+
masterExtraApplied = percentage(patientRawTotal, masterExtra.value);
|
|
1167
1171
|
} else if (masterExtra.mode === "AMOUNT") {
|
|
1168
1172
|
masterExtraApplied = Math.min(masterExtra.value, patientRawTotal);
|
|
1169
1173
|
}
|