Skip to content

Commit

Permalink
use partner commissionAmount
Browse files Browse the repository at this point in the history
  • Loading branch information
devkiran committed Dec 24, 2024
1 parent 7d48eec commit 99cf016
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 78 deletions.
15 changes: 11 additions & 4 deletions apps/web/lib/api/sales/commission.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
import { Program } from "@dub/prisma/client";
import { Program, ProgramEnrollment } from "@dub/prisma/client";

/*
Calculate the commission earned for a sale
*/
export const calculateEarnings = ({
program,
partner,
sales,
saleAmount,
}: {
program: Pick<Program, "commissionAmount" | "commissionType">;
partner?: Pick<ProgramEnrollment, "commissionAmount">;
sales: number;
saleAmount: number;
}) => {
if (program.commissionAmount === 0) {
const commissionAmount =
partner?.commissionAmount !== null
? partner?.commissionAmount
: program.commissionAmount;

if (!commissionAmount) {
return 0;
}

if (program.commissionType === "percentage") {
return saleAmount * (program.commissionAmount / 100);
return saleAmount * (commissionAmount / 100);
}

if (program.commissionType === "flat") {
return sales * program.commissionAmount;
return sales * commissionAmount;
}

throw new Error("Invalid commissionType");
Expand Down
74 changes: 0 additions & 74 deletions apps/web/lib/api/sales/recalculate-sales-earnings.ts

This file was deleted.

1 change: 1 addition & 0 deletions apps/web/lib/api/sales/sale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const createSaleData = ({
program,
sales: 1,
saleAmount: sale.amount,
partner,
});

const commissionAmount =
Expand Down

0 comments on commit 99cf016

Please sign in to comment.