Skip to content

Main content

Employee Cost Calculator Source Code

Browse the implementation files for Employee Cost Calculator.
@tool.io/tools/cost/employee source ↗
tool.ts typescript
import {
	CURRENCY_OPTIONS,
	formatCostSummary,
	formatMoney,
	parseCurrency,
	parseNonnegative,
	parsePositive
} from '../calculation';
import { calculateEmployeeCost } from '@tool.io/tools/cost/employee';

export const employeeCost = (
	currencyInput: unknown,
	salaryInput: unknown,
	payrollTaxInput: unknown,
	benefitsInput: unknown,
	overheadInput: unknown,
	annualHoursInput: unknown
): string => {
	const currency = parseCurrency(currencyInput);
	const salary = parseNonnegative(salaryInput);
	const payrollTax = parseNonnegative(payrollTaxInput);
	const benefits = parseNonnegative(benefitsInput);
	const overhead = parseNonnegative(overheadInput);
	const annualHours = parsePositive(annualHoursInput);
	if (
		!currency ||
		salary === null ||
		payrollTax === null ||
		benefits === null ||
		overhead === null ||
		annualHours === null
	)
		return '';
	const result = calculateEmployeeCost(
		salary,
		payrollTax,
		benefits,
		overhead,
		annualHours,
		currency
	);
	if (!result) return '';
	return formatCostSummary([
		['Salary', formatMoney(result.salary, currency)],
		[
			'Employer payroll taxes',
			formatMoney(result.payrollTaxCost, currency)
		],
		[
			'Benefits and overhead',
			formatMoney(result.benefitsAndOverhead, currency)
		],
		['Annual employer cost', formatMoney(result.annualCost, currency)],
		[
			'Monthly employer cost',
			formatMoney(result.monthlyCost, currency)
		],
		[
			'Cost per work hour',
			formatMoney(result.costPerHour, currency)
		]
	]);
};

export const Tool: TypeTool = {
	name: 'Employee Cost Calculator',
	slug: 'cost/employee',
	intro:
		'Estimate an employer’s annual, monthly, and hourly employee cost beyond base salary.',
	tool: employeeCost,
	i: [
		{
			example: 'USD',
			label: 'Currency',
			options: CURRENCY_OPTIONS,
			placeholder: 'Select currency',
			type: 'select'
		},
		{
			example: '70000',
			label: 'Annual Salary',
			placeholder: 'Gross annual salary',
			type: 'number'
		},
		{
			example: '7.65',
			label: 'Employer Payroll Tax (%)',
			placeholder: 'Employer tax percentage',
			type: 'number'
		},
		{
			example: '12000',
			label: 'Annual Benefits',
			placeholder: 'Benefits cost',
			type: 'number'
		},
		{
			example: '8000',
			label: 'Annual Overhead',
			placeholder: 'Workspace and equipment',
			type: 'number'
		},
		{
			example: '2080',
			label: 'Annual Work Hours',
			placeholder: 'Paid work hours',
			type: 'number'
		}
	],
	o: [
		{
			example:
				'Salary: $70,000.00\nEmployer payroll taxes: $5,355.00\nBenefits and overhead: $20,000.00\nAnnual employer cost: $95,355.00\nMonthly employer cost: $7,946.25\nCost per work hour: $45.84',
			label: 'Employee Cost',
			placeholder: 'Employer costs will appear here...',
			render: 'textarea',
			type: 'text'
		}
	],
	cite: [
		{
			title: 'Cost to company - Wikipedia',
			url: 'https://en.wikipedia.org/wiki/Cost_to_company'
		}
	]
};
export default Tool;

Description

Browse the implementation files for Employee Cost Calculator.

References

  1. Tool.io on GitHub
  2. Tool.io TypeScript tools library

Similar or alternative tools