Created
January 29, 2026 16:50
-
-
Save aok-solutions/c3c161cf65102f19820d867af6848fc9 to your computer and use it in GitHub Desktop.
BigBeagle Sales Calc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export enum ProductOptionCode { | |
| Base = 'BASE', | |
| NoContentCoverage = 'NO_CONTENT_COVERAGE', | |
| LiabilityOnly = 'LIABILITY_ONLY', | |
| ContentCoverage5K = 'CONTENT_COVERAGE_5K', | |
| ContentCoverage10K = 'CONTENT_COVERAGE_10K', | |
| ContentCoverage20K = 'CONTENT_COVERAGE_20K', | |
| Liability200K = 'LIABILITY_200K', | |
| ContentCoverage5K200K = 'CONTENT_COVERAGE_5K_200K', | |
| ContentCoverage10K200K = 'CONTENT_COVERAGE_10K_200K', | |
| ContentCoverage20K200K = 'CONTENT_COVERAGE_20K_200K', | |
| Liability300K = 'LIABILITY_300K', | |
| ContentCoverage5K300K = 'CONTENT_COVERAGE_5K_300K', | |
| ContentCoverage10K300K = 'CONTENT_COVERAGE_10K_300K', | |
| ContentCoverage20K300K = 'CONTENT_COVERAGE_20K_300K', | |
| Discount500 = 'DISCOUNT_500', | |
| Discount1000 = 'DISCOUNT_1000', | |
| FullReplacement = 'FULL_REPLACEMENT', | |
| } | |
| const programs: Program[] = [ | |
| { | |
| code: ProgramCode.YourRentersKit, | |
| name: "Your Renters Kit", | |
| requiresMarkup: true, | |
| products: [ | |
| { | |
| code: ProductCode.TenantLegalLiability, | |
| name: "Tenant Liability Waiver", | |
| adminFeePerDoor: 8, | |
| options: [ | |
| { | |
| code: ProductOptionCode.NoContentCoverage, | |
| name: "Liability Only", | |
| price: 10, | |
| }, | |
| { | |
| code: ProductOptionCode.ContentCoverage5K, | |
| name: "$5k", | |
| price: 14, | |
| }, | |
| { | |
| code: ProductOptionCode.ContentCoverage10K, | |
| name: "$10k", | |
| price: 16, | |
| }, | |
| { | |
| code: ProductOptionCode.ContentCoverage20K, | |
| name: "$20k", | |
| price: 20, | |
| }, | |
| { | |
| code: ProductOptionCode.Liability200K, | |
| name: "Liability Only", | |
| price: 13, | |
| }, | |
| { | |
| code: ProductOptionCode.ContentCoverage5K200K, | |
| name: "$5k", | |
| price: 17, | |
| }, | |
| { | |
| code: ProductOptionCode.ContentCoverage10K200K, | |
| name: "$10k", | |
| price: 19, | |
| }, | |
| { | |
| code: ProductOptionCode.ContentCoverage20K200K, | |
| name: "$20k", | |
| price: 23, | |
| }, | |
| { | |
| code: ProductOptionCode.Liability300K, | |
| name: "Liability Only", | |
| price: 16, | |
| }, | |
| { | |
| code: ProductOptionCode.ContentCoverage5K300K, | |
| name: "$5k", | |
| price: 20, | |
| }, | |
| { | |
| code: ProductOptionCode.ContentCoverage10K300K, | |
| name: "$10k", | |
| price: 22, | |
| }, | |
| { | |
| code: ProductOptionCode.ContentCoverage20K300K, | |
| name: "$20k", | |
| price: 26, | |
| }, | |
| ], | |
| }, | |
| { | |
| code: ProductCode.SecurityDepositDiscount, | |
| name: "Security Deposit Alternative", | |
| adminFeePerDoor: 5, | |
| options: [ | |
| { | |
| code: ProductOptionCode.Discount500, | |
| name: "$500 Off", | |
| price: 15, | |
| }, | |
| { | |
| code: ProductOptionCode.Discount1000, | |
| name: "$1,000 Off", | |
| price: 23, | |
| }, | |
| { | |
| code: ProductOptionCode.FullReplacement, | |
| name: "Full Replacement", | |
| price: 0, | |
| }, | |
| ], | |
| }, | |
| { | |
| code: ProductCode.PetDamageInsurance, | |
| name: "Pet Damage Waiver", | |
| adminFeePerDoor: 10, | |
| options: [ | |
| { | |
| code: ProductOptionCode.Base, | |
| name: "Base", | |
| price: 40, | |
| }, | |
| ], | |
| }, | |
| { | |
| code: ProductCode.BaseBenefitsPack, | |
| name: "Renters Kits", | |
| adminFeePerDoor: 0, | |
| options: [ | |
| { | |
| code: ProductOptionCode.Base, | |
| name: "Base", | |
| price: 5, | |
| }, | |
| ], | |
| }, | |
| ], | |
| addons: [], | |
| aiProducts: [], | |
| }, | |
| ]; | |
| const BigBeagleTLLProfitTable: Partial<Record<ProductOptionCode, number>> = { | |
| [ProductOptionCode.NoContentCoverage]: 4, | |
| [ProductOptionCode.ContentCoverage5K]: 5, | |
| [ProductOptionCode.ContentCoverage10K]: 6, | |
| [ProductOptionCode.ContentCoverage20K]: 8, | |
| [ProductOptionCode.Liability200K]: 5, | |
| [ProductOptionCode.ContentCoverage5K200K]: 7, | |
| [ProductOptionCode.ContentCoverage10K200K]: 8, | |
| [ProductOptionCode.ContentCoverage20K200K]: 9, | |
| [ProductOptionCode.Liability300K]: 6, | |
| [ProductOptionCode.ContentCoverage5K300K]: 8, | |
| [ProductOptionCode.ContentCoverage10K300K]: 9, | |
| [ProductOptionCode.ContentCoverage20K300K]: 11, | |
| } | |
| const securityDepositPricingTable: Record<string, { singleFamily: number; multiFamily: number }> = | |
| { | |
| "1500": { singleFamily: 40, multiFamily: 34 }, | |
| "2000": { singleFamily: 52, multiFamily: 44 }, | |
| "2500": { singleFamily: 65, multiFamily: 55 }, | |
| "3000": { singleFamily: 78, multiFamily: 66 }, | |
| "3500": { singleFamily: 91, multiFamily: 77 }, | |
| "4000": { singleFamily: 104, multiFamily: 88 }, | |
| "4500": { singleFamily: 119, multiFamily: 97 }, | |
| "5000": { singleFamily: 132, multiFamily: 108 }, | |
| "5500": { singleFamily: 145, multiFamily: 119 }, | |
| "6000": { singleFamily: 158, multiFamily: 130 }, | |
| } | |
| const avgRentAmountOptions = [ | |
| { | |
| label: "$1,500", | |
| value: "1500", | |
| }, | |
| { | |
| label: "$2,000", | |
| value: "2000", | |
| }, | |
| { | |
| label: "$2,500", | |
| value: "2500", | |
| }, | |
| { | |
| label: "$3,000", | |
| value: "3000", | |
| }, | |
| { | |
| label: "$3,500", | |
| value: "3500", | |
| }, | |
| { | |
| label: "$4,000", | |
| value: "4000", | |
| }, | |
| { | |
| label: "$4,500", | |
| value: "4500", | |
| }, | |
| { | |
| label: "$5,000", | |
| value: "5000", | |
| }, | |
| { | |
| label: "$5,500", | |
| value: "5500", | |
| }, | |
| { | |
| label: "$6,000", | |
| value: "6000", | |
| }, | |
| ] | |
| const propertyTypeOptions = [ | |
| { | |
| label: "Single Family", | |
| value: "SINGLE_FAMILY", | |
| }, | |
| { | |
| label: "Multi Family", | |
| value: "MULTI_FAMILY", | |
| }, | |
| ] | |
| const getSecurityDepositReplacementCost = (rentAmount: number, propertyType: string): number => { | |
| // Define the rent tiers in order | |
| const rentTiers = [1500, 2000, 2500, 3000, 3500, 4000, 4500, 5000, 5500, 6000] | |
| // Find the appropriate tier (ceiling to nearest tier) | |
| let targetTier = rentTiers.find(tier => rentAmount <= tier) | |
| // If rent amount is higher than our highest tier, use the highest tier | |
| if (!targetTier) { | |
| targetTier = rentTiers[rentTiers.length - 1] | |
| } | |
| const rentKey = targetTier.toString() | |
| const pricingData = securityDepositPricingTable[rentKey] | |
| if (pricingData) { | |
| return propertyType === "SINGLE_FAMILY" ? pricingData.singleFamily : pricingData.multiFamily | |
| } | |
| return 0 | |
| } | |
| const getSecurityDepositReplacementProfit = (costToTenant: number): number => { | |
| // Profit mapping based on cost to tenant | |
| const profitMapping: Record<number, number> = { | |
| // Single Family pricing | |
| 40: 9, // $1500 Replacement (Single Family) | |
| 52: 12, // $2000 Replacement (Single Family) | |
| 65: 15, // $2500 Replacement (Single Family) | |
| 78: 18, // $3000 Replacement (Single Family) | |
| 91: 21, // $3500 Replacement (Single Family) | |
| 104: 24, // $4000 Replacement (Single Family) | |
| 119: 28, // $4500 Replacement (Single Family) / $5500 Replacement (Multi Family) | |
| 132: 31, // $5000 Replacement (Single Family) | |
| 145: 34, // $5500 Replacement (Single Family) | |
| 158: 37, // $6000 Replacement (Single Family) | |
| // Multi Family specific pricing | |
| 34: 8, // $1500 Replacement (Multi Family) | |
| 44: 10, // $2000 Replacement (Multi Family) | |
| 55: 13, // $2500 Replacement (Multi Family) | |
| 66: 15, // $3000 Replacement (Multi Family) | |
| 77: 18, // $3500 Replacement (Multi Family) | |
| 88: 20, // $4000 Replacement (Multi Family) | |
| 97: 23, // $4500 Replacement (Multi Family) | |
| 108: 25, // $5000 Replacement (Multi Family) | |
| 130: 30, // $6000 Replacement (Multi Family) | |
| } | |
| return profitMapping[costToTenant] || 0 | |
| } | |
| const calculateProductProfit = ( | |
| productCode: ProductCode, | |
| productOptionCode: ProductOptionCode, | |
| selectedPrice?: number | |
| ) => { | |
| if (productCode === ProductCode.BaseBenefitsPack) { | |
| return markup | |
| } | |
| if (productCode === ProductCode.TenantLegalLiability) { | |
| return BigBeagleTLLProfitTable[productOptionCode] ?? 0 | |
| } else if (productCode === ProductCode.SecurityDepositDiscount) { | |
| switch (productOptionCode) { | |
| case ProductOptionCode.Discount500: // $500 off coverage | |
| return 3 | |
| case ProductOptionCode.Discount1000: // $1000 off coverage | |
| return 5 | |
| case ProductOptionCode.FullReplacement: // Full replacement | |
| // Calculate profit based on the replacement tier | |
| if (selectedPrice) { | |
| return getSecurityDepositReplacementProfit(selectedPrice) | |
| } | |
| return 0 | |
| default: | |
| return 0 | |
| } | |
| } else if (productCode === ProductCode.PetDamageInsurance) { | |
| return 5 | |
| } else { | |
| return 0 | |
| } | |
| } | |
| const calculateTotalProductProfit = (product: SelectedProduct) => { | |
| const underwritingProfit = calculateProductProfit( | |
| product.code, | |
| product.optionCode, | |
| product.selectedPrice | |
| ) | |
| // Use customAdminFee if it exists, otherwise use the standard adminFeePerDoor | |
| const adminFee = | |
| product.customAdminFee !== undefined ? product.customAdminFee : product.adminFeePerDoor | |
| return underwritingProfit + adminFee | |
| } | |
| const calculateTotalProfit = () => { | |
| const totalProfit = selectedProducts.reduce( | |
| (acc, product) => acc + calculateTotalProductProfit(product), | |
| 0 | |
| ) | |
| return totalProfit | |
| } | |
| const calculateTotalProductCost = (product: SelectedProduct) => { | |
| // Use customAdminFee if it exists, otherwise use adminFeePerDoor (but only if it's not 0) | |
| const adminFee = | |
| product.customAdminFee !== undefined ? product.customAdminFee : product.adminFeePerDoor | |
| return product.selectedPrice + adminFee | |
| } | |
| const selectedProducts: SelectedProduct[] = planConfiguration.productConfigurations | |
| .map((config) => { | |
| if (config.product.code === ProductCode.AirFilterDelivery) { | |
| return { | |
| code: ProductCode.AirFilterDelivery, | |
| optionCode: ProductOptionCode.Base, | |
| name: "Air Filter Delivery", | |
| selectedPrice: 5, | |
| adminFeePerDoor: 0, | |
| } | |
| } | |
| if (config.product.code === ProductCode.PestControl) { | |
| return { | |
| code: ProductCode.PestControl, | |
| optionCode: ProductOptionCode.Base, | |
| name: "Pest Control", | |
| selectedPrice: 6, | |
| adminFeePerDoor: 0, | |
| } | |
| } | |
| const product = selectedProgram.products.find((p) => p.code === config.product.code) | |
| const selectedOption = product?.options.find((o) => o.code === config.option.code) | |
| if (!product || !selectedOption) return null | |
| let finalPrice = selectedOption.price | |
| if ( | |
| config.product.code === ProductCode.SecurityDepositDiscount && | |
| config.option.code === ProductOptionCode.FullReplacement | |
| ) { | |
| finalPrice = getSecurityDepositReplacementCost(avgRentAmount, propertyType) | |
| } | |
| // Use customAdminFee for all products that support admin fees | |
| if ( | |
| (config.product.code === ProductCode.TenantLegalLiability || | |
| config.product.code === ProductCode.SecurityDepositDiscount || | |
| config.product.code === ProductCode.PetDamageInsurance) && | |
| config.adminFeeValue !== undefined | |
| ) { | |
| return { | |
| code: product.code, | |
| optionCode: selectedOption.code, | |
| name: config.product.name, | |
| selectedPrice: finalPrice, | |
| adminFeePerDoor: product.adminFeePerDoor, | |
| customAdminFee: config.adminFeeValue, | |
| } | |
| } else { | |
| // For products without admin fees or legacy logic | |
| const adminFeeAmount = config.includeAdminFee ? product.adminFeePerDoor : 0 | |
| return { | |
| code: product.code, | |
| optionCode: selectedOption.code, | |
| name: config.product.name, | |
| selectedPrice: finalPrice, | |
| adminFeePerDoor: adminFeeAmount, | |
| } | |
| } | |
| }) | |
| .filter((product): product is SelectedProduct => product !== null) | |
| const selectedAddons = planConfiguration.addons.map((addon) => { | |
| const fullAddon = selectedProgram.addons.find((a) => a.code === addon.code) | |
| return fullAddon || addon | |
| }) | |
| const shouldIncludeMarkup = | |
| selectedProgram.requiresMarkup && | |
| shouldShowMarkup && | |
| planConfiguration.productConfigurations.length > 0 | |
| const baseMonthlyTotal = selectedProducts.reduce((acc, product) => acc + product.selectedPrice, 0) | |
| // Helper function to calculate total admin fees | |
| const getTotalAdminFees = (): number => { | |
| return selectedProducts.reduce((total, product) => { | |
| const config = planConfiguration.productConfigurations.find( | |
| (config) => config.product.code === product.code | |
| ) | |
| return total + (config?.adminFeeValue || 0) | |
| }, 0) | |
| } | |
| const effectiveMarkup = shouldIncludeMarkup ? markup : 0 | |
| const adminFees = getTotalAdminFees() | |
| const monthlyRetail = baseMonthlyTotal + effectiveMarkup + adminFees | |
| const monthlyProfitAmount = Math.ceil(numberOfDoors * (formValues.portfolioCoverage / 100)) * calculateTotalProfit() | |
| const annualProfit = 12 * monthlyProfitAmount | |
| const securityDepositReplacementSelected = selectedProducts.some( | |
| (product) => | |
| product.code === ProductCode.SecurityDepositDiscount && | |
| product.optionCode === ProductOptionCode.FullReplacement | |
| ) | |
| console.log("avgRentAmount", avgRentAmount) | |
| console.log("propertyType", propertyType) | |
| const airFilterProduct = selectedProducts.find((p) => p.code === ProductCode.AirFilterDelivery) | |
| const pestControlProduct = selectedProducts.find((p) => p.code === ProductCode.PestControl) | |
| const airFilterCost = airFilterProduct ? calculateTotalProductCost(airFilterProduct) : 0 | |
| const pestControlCost = pestControlProduct ? calculateTotalProductCost(pestControlProduct) : 0 | |
| // Helper function to get product profit labels | |
| const getProductProfitLabel = (productCode: ProductCode): string => { | |
| switch (productCode) { | |
| case ProductCode.TenantLegalLiability: | |
| return "Tenant Liability Waiver" | |
| case ProductCode.SecurityDepositDiscount: | |
| return "Security Deposit Replacement" | |
| case ProductCode.PetDamageInsurance: | |
| return "Pet Damage Waiver" | |
| default: | |
| return "Product" | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment