Skip to content

Instantly share code, notes, and snippets.

@hc3
Created July 10, 2020 00:18
Show Gist options
  • Save hc3/492273538a301021deb19bf350493e1f to your computer and use it in GitHub Desktop.
Save hc3/492273538a301021deb19bf350493e1f to your computer and use it in GitHub Desktop.
const isValidProductToIndicator = require('../validations/is-valid-product-to-indicator')
module.exports = (merged, volume_indicators) => {
const { REAL_CERVEJA_RETORNAVEL, PREMIUM, VOLUME_TOTAL, CORINGA_01, CORINGA_02 } = volume_indicators
let real_umb_cerv_ret = 0
let meta_umb_cerv_ret = 0
let real_hl_cerv_ret = 0
let meta_hl_cerv_ret = 0
let real_umb_premium = 0
let meta_umb_premium = 0
let real_hl_premium = 0
let meta_hl_premium = 0
let real_umb_volume_total = 0
let meta_umb_volume_total = 0
let real_hl_volume_total = 0
let meta_hl_volume_total = 0
let real_umb_coringa_01 = 0
let meta_umb_coringa_01 = 0
let real_hl_coringa_01 = 0
let meta_hl_coringa_01 = 0
let real_umb_coringa_02 = 0
let meta_umb_coringa_02 = 0
let real_hl_coringa_02 = 0
let meta_hl_coringa_02 = 0
const panel = merged.reduce((prev, curr) => {
const { product_family, product_id, goal, real, factor } = curr
const meta_hl = goal * (factor/100)
const real_hl = real * (factor/100)
return {
cervejas_300_600_1lt: {
name: 'cervejas_300_600_1lt',
real_umb: real_umb_cerv_ret += isValidProductToIndicator(product_family, product_id, real, REAL_CERVEJA_RETORNAVEL),
meta_umb: meta_umb_cerv_ret += isValidProductToIndicator(product_family, product_id, goal, REAL_CERVEJA_RETORNAVEL),
real_hl: real_hl_cerv_ret += isValidProductToIndicator(product_family, product_id, real_hl , REAL_CERVEJA_RETORNAVEL),
meta_hl: meta_hl_cerv_ret += isValidProductToIndicator(product_family, product_id, meta_hl , REAL_CERVEJA_RETORNAVEL)
},
premium: {
name: 'premium',
real_umb: real_umb_premium += isValidProductToIndicator(product_family, product_id, real, PREMIUM),
meta_umb: meta_umb_premium += isValidProductToIndicator(product_family, product_id, goal, PREMIUM),
real_hl: real_hl_premium += isValidProductToIndicator(product_family, product_id, real_hl , PREMIUM),
meta_hl: meta_hl_premium += isValidProductToIndicator(product_family, product_id, meta_hl , PREMIUM)
},
volume_total: {
name: 'volume_total',
real_umb: real_umb_volume_total += isValidProductToIndicator(product_family, product_id, real, VOLUME_TOTAL, true),
meta_umb: meta_umb_volume_total += isValidProductToIndicator(product_family, product_id, goal, VOLUME_TOTAL, true),
real_hl: real_hl_volume_total += isValidProductToIndicator(product_family, product_id, real_hl , true),
meta_hl: meta_hl_volume_total += isValidProductToIndicator(product_family, product_id, meta_hl , true)
},
coringa_01: {
name: 'coringa_01',
real_umb: real_umb_coringa_01 += isValidProductToIndicator(product_family, product_id, real, CORINGA_01),
meta_umb: meta_umb_coringa_01 += isValidProductToIndicator(product_family, product_id, goal, CORINGA_01),
real_hl: real_hl_coringa_01 += isValidProductToIndicator(product_family, product_id, real_hl , CORINGA_01),
meta_hl: meta_hl_coringa_01 += isValidProductToIndicator(product_family, product_id, meta_hl , CORINGA_01)
},
coringa_02: {
name: 'coringa_02',
real_umb: real_umb_coringa_02 += isValidProductToIndicator(product_family, product_id, real, CORINGA_02),
meta_umb: meta_umb_coringa_02 += isValidProductToIndicator(product_family, product_id, goal, CORINGA_02),
real_hl: real_hl_coringa_02 += isValidProductToIndicator(product_family, product_id, real_hl , CORINGA_02),
meta_hl: meta_hl_coringa_02 += isValidProductToIndicator(product_family, product_id, meta_hl , CORINGA_02)
}
}
},{})
let response = []
Object.keys(panel).map(el => response.push(panel[el]))
return response
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment