Bookmark this: tool.io/cost/project/source-code
Project Cost Calculator Source Code
Browse the implementation files for Project Cost Calculator.tool.ts typescript
import {
CURRENCY_OPTIONS,
formatCostSummary,
formatMoney,
parseCurrency,
parseNonnegative
} from '../calculation';
import { calculateProjectCost } from '@tool.io/tools/cost/project';
export const projectCost = (
currencyInput: unknown,
laborHoursInput: unknown,
laborRateInput: unknown,
materialsInput: unknown,
equipmentInput: unknown,
contingencyInput: unknown
): string => {
const currency = parseCurrency(currencyInput);
const hours = parseNonnegative(laborHoursInput);
const rate = parseNonnegative(laborRateInput);
const materials = parseNonnegative(materialsInput);
const equipment = parseNonnegative(equipmentInput);
const contingency = parseNonnegative(contingencyInput);
if (
!currency ||
hours === null ||
rate === null ||
materials === null ||
equipment === null ||
contingency === null
)
return '';
const result = calculateProjectCost(
hours,
rate,
materials,
equipment,
contingency,
currency
);
if (!result) return '';
return formatCostSummary([
['Labor', formatMoney(result.laborCost, currency)],
[
'Materials and equipment',
formatMoney(result.materialsAndEquipment, currency)
],
['Contingency', formatMoney(result.contingencyCost, currency)],
['Project total', formatMoney(result.totalCost, currency)]
]);
};
export const Tool: TypeTool = {
name: 'Project Cost Calculator',
slug: 'cost/project',
intro:
'Estimate labor, materials, equipment, contingency, and total project cost.',
tool: projectCost,
i: [
{
example: 'USD',
label: 'Currency',
options: CURRENCY_OPTIONS,
placeholder: 'Select currency',
type: 'select'
},
{
example: '100',
label: 'Labor Hours',
placeholder: 'Estimated labor hours',
type: 'number'
},
{
example: '50',
label: 'Hourly Labor Rate',
placeholder: 'Cost per labor hour',
type: 'number'
},
{
example: '3000',
label: 'Materials',
placeholder: 'Material costs',
type: 'number'
},
{
example: '1000',
label: 'Equipment',
placeholder: 'Equipment costs',
type: 'number'
},
{
example: '10',
label: 'Contingency (%)',
placeholder: 'Contingency percentage',
type: 'number'
}
],
o: [
{
example:
'Labor: $5,000.00\nMaterials and equipment: $4,000.00\nContingency: $900.00\nProject total: $9,900.00',
label: 'Project Cost',
placeholder: 'Project costs will appear here...',
render: 'textarea',
type: 'text'
}
],
cite: [
{
title: 'Cost estimate - Wikipedia',
url: 'https://en.wikipedia.org/wiki/Cost_estimate'
}
]
};
export default Tool;
Description
Browse the implementation files for Project Cost Calculator.