feat(SPG-656): allow input number on formula
parent
9802d983bb
commit
0658b503bd
|
@ -9,7 +9,9 @@ export function calculateSalesFormula(
|
|||
throwError = false,
|
||||
) {
|
||||
try {
|
||||
let { value, variable, tax_datas } = mappingTaxes(taxes, formula, total);
|
||||
const mapTaxes = mappingTaxes(taxes, formula, total);
|
||||
let { value } = mapTaxes;
|
||||
const { variable, tax_datas } = mapTaxes;
|
||||
|
||||
const x1 = math.simplify(formula, variable).toString();
|
||||
console.log('Formula ', x1);
|
||||
|
@ -41,13 +43,10 @@ export function calculateProfitFormula(
|
|||
throwError = false,
|
||||
) {
|
||||
try {
|
||||
let { value, variable, tax_datas } = mappingTaxes(
|
||||
taxes,
|
||||
formula,
|
||||
total,
|
||||
profit_share,
|
||||
);
|
||||
|
||||
const mapTaxes = mappingTaxes(taxes, formula, total, profit_share);
|
||||
let { value } = mapTaxes;
|
||||
const { variable, tax_datas } = mapTaxes;
|
||||
console.log(formula, variable);
|
||||
const result = math.simplify(formula, variable).toString();
|
||||
console.log(result, 'formula');
|
||||
|
||||
|
@ -64,9 +63,9 @@ export function calculateProfitFormula(
|
|||
}
|
||||
|
||||
function mappingTaxes(taxes, formula, total, profit_share = 0) {
|
||||
let value = 0;
|
||||
const value = 0;
|
||||
const variable = {};
|
||||
let tax_datas = [];
|
||||
const tax_datas = [];
|
||||
const const_variable = ['profit_share', 'item_share', 'dpp'];
|
||||
|
||||
const regex = /([a-zA-Z0-9_]+)/g;
|
||||
|
@ -78,14 +77,17 @@ function mappingTaxes(taxes, formula, total, profit_share = 0) {
|
|||
for (const key of keys) {
|
||||
if (!const_variable.includes(key)) {
|
||||
const keyData = taxes.find((tax) => tax.name == key);
|
||||
variable[key] = keyData.value / 100;
|
||||
|
||||
tax_datas.push({
|
||||
tax_id: keyData.id,
|
||||
tax_name: keyData.name,
|
||||
tax_value: keyData.value,
|
||||
tax_total_value: (keyData.value / 100) * Number(total),
|
||||
});
|
||||
if (!keyData) {
|
||||
variable[key] = key;
|
||||
} else {
|
||||
variable[key] = keyData.value / 100;
|
||||
tax_datas.push({
|
||||
tax_id: keyData.id,
|
||||
tax_name: keyData.name,
|
||||
tax_value: keyData.value,
|
||||
tax_total_value: (keyData.value / 100) * Number(total),
|
||||
});
|
||||
}
|
||||
} else {
|
||||
switch (key) {
|
||||
case 'profit_share':
|
||||
|
|
Loading…
Reference in New Issue