Skip to content

Commit

Permalink
fix(calculateKpi): code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
lucianak committed Oct 17, 2024
1 parent 61b8f4e commit 751bd96
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions packages/backend-modules/republik/script/finance/calculateKpis.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ const currency = new Intl.NumberFormat('de-CH', {
useGrouping: false,
})

const isCancelledOrRefunded = (item) => {
return ['CANCELLED', 'REFUNDED', 'FAILED'].includes(item.status.toUpperCase())
}

const evaluateCompanyMonth = async (
company,
begin,
Expand Down Expand Up @@ -166,7 +170,7 @@ const evaluateCompanyMonth = async (
.filter((i) => i.companyName === company)
.filter((i) => i.method === method)
.filter((i) => i.type === 'MembershipType')
.filter((i) => ['CANCELLED', 'REFUNDED', 'failed', 'refunded'].includes(i.status))
.filter((i) => isCancelledOrRefunded(i))

results.StornierteMitgliedschaften = {
Anzahl: StornierteMitgliedschaften.map(
Expand Down Expand Up @@ -284,7 +288,7 @@ const evaluateCompanyMonth = async (
(i) =>
i.donation > 0 || ['DONATE', 'DONATE_POT'].includes(i.packageName),
)
.filter((i) => ['CANCELLED', 'REFUNDED', 'failed', 'refunded'].includes(i.status))
.filter((i) => isCancelledOrRefunded(i))

results.StornierteSpenden = {
Betrag:
Expand Down Expand Up @@ -330,7 +334,7 @@ const evaluateCompanyMonth = async (
.filter((i) => i.method === method)
.filter((i) => ['MONTHLY_ABO', 'MONTHLY_SUBSCRIPTION'].includes(i.packageName))
.filter((i) => i.type === 'MembershipType')
.filter((i) => ['CANCELLED', 'REFUNDED', 'failed', 'refunded'].includes(i.status))
.filter((i) => isCancelledOrRefunded(i))

results.StornierteAbonnements = {
Anzahl: StornierteAbonnements.map(
Expand Down Expand Up @@ -404,7 +408,7 @@ const evaluateCompanyMonth = async (
.filter((i) => i.method === method)
.filter((i) => i.packageName === 'ABO_GIVE_MONTHS')
.filter((i) => i.type === 'MembershipType')
.filter((i) => ['CANCELLED', 'REFUNDED', 'failed', 'refunded'].includes(i.status))
.filter((i) => isCancelledOrRefunded(i))

results.StornierteMonatsgeschenkabos = {
Anzahl: StornierteMonatsgeschenkabos.map(
Expand Down Expand Up @@ -452,7 +456,7 @@ const evaluateCompanyMonth = async (
.filter((i) => i.method === method)
.filter((i) => ['YEARLY_ABO'].includes(i.packageName))
.filter((i) => i.type === 'MembershipType')
.filter((i) => ['CANCELLED', 'REFUNDED', 'failed', 'refunded'].includes(i.status))
.filter((i) => isCancelledOrRefunded(i))

const StornierteJahresabonnementsWithPrecomputed = precomputeTransitoryLiabilities(StornierteJahresabonnements, endFiscalYear)

Expand Down Expand Up @@ -493,7 +497,7 @@ const evaluateCompanyMonth = async (
.filter((i) => i.companyName === company)
.filter((i) => i.method === method)
.filter((i) => i.type === 'Goodie')
.filter((i) => ['CANCELLED', 'REFUNDED', 'failed', 'refunded'].includes(i.status))
.filter((i) => isCancelledOrRefunded(i))

results.StornierteHandelsware = {
Betrag:
Expand Down Expand Up @@ -546,3 +550,5 @@ PgDb.connect()
.catch((e) => {
console.error(e)
})


0 comments on commit 751bd96

Please sign in to comment.