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