Bookmark this: tool.io/cost/total-ownership/source-code
Total Cost of Ownership Calculator Source Code
Browse the implementation files for Total Cost of Ownership Calculator.tool.ts typescript
import {
CURRENCY_OPTIONS,
formatCostSummary,
formatMoney,
parseCurrency,
parseNonnegative,
parsePositive
} from '../calculation';
import { calculateTotalOwnershipCost } from '@tool.io/tools/cost/total-ownership';
export const totalOwnershipCost = (
currencyInput: unknown,
purchaseInput: unknown,
yearsInput: unknown,
operatingInput: unknown,
maintenanceInput: unknown,
insuranceInput: unknown,
resaleInput: unknown
): string => {
const currency = parseCurrency(currencyInput);
const purchase = parseNonnegative(purchaseInput);
const years = parsePositive(yearsInput);
const operating = parseNonnegative(operatingInput);
const maintenance = parseNonnegative(maintenanceInput);
const insurance = parseNonnegative(insuranceInput);
const resale = parseNonnegative(resaleInput);
if (
!currency ||
purchase === null ||
years === null ||
operating === null ||
maintenance === null ||
insurance === null ||
resale === null
)
return '';
const result = calculateTotalOwnershipCost(
purchase,
years,
operating,
maintenance,
insurance,
resale,
currency
);
if (!result) return '';
return formatCostSummary([
['Purchase price', formatMoney(result.purchasePrice, currency)],
['Recurring costs', formatMoney(result.recurringCosts, currency)],
['Resale value', formatMoney(result.resaleValue, currency)],
['Total cost of ownership', formatMoney(result.totalCost, currency)],
[
'Average annual cost',
formatMoney(result.averageAnnualCost, currency)
]
]);
};
export const Tool: TypeTool = {
name: 'Total Cost of Ownership Calculator',
slug: 'cost/total-ownership',
intro:
'Estimate lifetime ownership cost after recurring expenses and expected resale value.',
tool: totalOwnershipCost,
i: [
{
example: 'USD',
label: 'Currency',
options: CURRENCY_OPTIONS,
placeholder: 'Select currency',
type: 'select'
},
{
example: '30000',
label: 'Purchase Price',
placeholder: 'Initial purchase price',
type: 'number'
},
{
example: '5',
label: 'Years Owned',
placeholder: 'Ownership duration',
type: 'number'
},
{
example: '2000',
label: 'Annual Operating Cost',
placeholder: 'Fuel, energy, or operation',
type: 'number'
},
{
example: '1000',
label: 'Annual Maintenance',
placeholder: 'Maintenance cost',
type: 'number'
},
{
example: '1200',
label: 'Annual Insurance',
placeholder: 'Insurance cost',
type: 'number'
},
{
example: '15000',
label: 'Expected Resale Value',
placeholder: 'Value when sold',
type: 'number'
}
],
o: [
{
example:
'Purchase price: $30,000.00\nRecurring costs: $21,000.00\nResale value: $15,000.00\nTotal cost of ownership: $36,000.00\nAverage annual cost: $7,200.00',
label: 'Total Cost of Ownership',
placeholder: 'Ownership costs will appear here...',
render: 'textarea',
type: 'text'
}
],
cite: [
{
title: 'Total cost of ownership - Wikipedia',
url: 'https://en.wikipedia.org/wiki/Total_cost_of_ownership'
}
]
};
export default Tool;
Description
Browse the implementation files for Total Cost of Ownership Calculator.