2025-05-14 08:55:54 +00:00
|
|
|
import React, { useEffect, useState } from 'react'
|
|
|
|
import { useInputValues, useProductionCapacityData, useROISummaryData } from '../../../../store/builder/store';
|
2025-05-14 12:51:49 +00:00
|
|
|
import { useSelectedProduct } from '../../../../store/simulation/useSimulationStore';
|
2025-05-14 04:27:31 +00:00
|
|
|
|
|
|
|
export default function ROIData() {
|
|
|
|
const { inputValues } = useInputValues();
|
|
|
|
const { productionCapacityData } = useProductionCapacityData()
|
2025-05-14 12:51:49 +00:00
|
|
|
const { selectedProduct } = useSelectedProduct();
|
2025-05-14 04:27:31 +00:00
|
|
|
|
2025-05-14 08:55:54 +00:00
|
|
|
|
|
|
|
const { setRoiSummaryData } = useROISummaryData();
|
2025-05-14 04:27:31 +00:00
|
|
|
useEffect(() => {
|
|
|
|
if (inputValues === undefined) return;
|
|
|
|
|
|
|
|
const electricityCost = parseFloat(inputValues["Electricity cost"]);
|
|
|
|
const fixedCost = parseFloat(inputValues["Fixed costs"]);
|
|
|
|
const laborCost = parseFloat(inputValues["Labor Cost"]);
|
|
|
|
const maintenanceCost = parseFloat(inputValues["Maintenance cost"]); // Remove space typ
|
|
|
|
const materialCost = parseFloat(inputValues["Material cost"]);
|
|
|
|
const productionPeriod = parseFloat(inputValues["Production period"]);
|
|
|
|
const salvageValue = parseFloat(inputValues["Salvage value"]);
|
|
|
|
const sellingPrice = parseFloat(inputValues["Selling price"]);
|
|
|
|
const initialInvestment = parseFloat(inputValues["Initial Investment"]);
|
|
|
|
const shiftLength = parseFloat(inputValues["Shift length"]);
|
|
|
|
const shiftsPerDay = parseFloat(inputValues["Shifts / day"]);
|
|
|
|
const workingDaysPerYear = parseFloat(inputValues["Working days / year"]);
|
|
|
|
|
|
|
|
if (!isNaN(electricityCost) && !isNaN(fixedCost) && !isNaN(laborCost) && !isNaN(maintenanceCost) &&
|
|
|
|
!isNaN(materialCost) && !isNaN(productionPeriod) && !isNaN(salvageValue) && !isNaN(sellingPrice) &&
|
|
|
|
!isNaN(shiftLength) && !isNaN(shiftsPerDay) && !isNaN(workingDaysPerYear) && productionCapacityData > 0) {
|
|
|
|
|
|
|
|
console.log('sellingPrice: ', sellingPrice);
|
|
|
|
console.log('salvageValue: ', salvageValue);
|
|
|
|
console.log('productionPeriod: ', productionPeriod);
|
|
|
|
console.log('materialCost: ', materialCost);
|
|
|
|
console.log('maintenanceCost: ', maintenanceCost);
|
|
|
|
console.log('laborCost: ', laborCost);
|
|
|
|
console.log('fixedCost: ', fixedCost);
|
|
|
|
console.log('electricityCost: ', electricityCost);
|
|
|
|
|
|
|
|
|
|
|
|
// Revenue
|
|
|
|
const RevenueForYear = productionCapacityData * sellingPrice;
|
|
|
|
console.log('RevenueForYear: ', RevenueForYear);
|
|
|
|
|
|
|
|
//Costs
|
2025-05-14 12:51:49 +00:00
|
|
|
|
|
|
|
let materialCount = 1200;
|
|
|
|
|
|
|
|
//Material Cost
|
|
|
|
|
2025-05-14 04:27:31 +00:00
|
|
|
let MaterialCost = productionCapacityData * materialCost
|
|
|
|
console.log('MaterialCost: ', MaterialCost);
|
|
|
|
let LaborCost = laborCost * shiftLength * shiftsPerDay * workingDaysPerYear;
|
|
|
|
console.log('LaborCost: ', LaborCost);
|
|
|
|
let EnergyCost = electricityCost * shiftLength * shiftsPerDay * workingDaysPerYear;
|
|
|
|
console.log('EnergyCost: ', EnergyCost);
|
|
|
|
let MaintenceCost = maintenanceCost + fixedCost;
|
|
|
|
console.log('MaintenceCost: ', MaintenceCost);
|
|
|
|
|
|
|
|
//Total Anuual Cost
|
2025-05-14 12:51:49 +00:00
|
|
|
let TotalAnnualCost = (MaterialCost * materialCount) + LaborCost + EnergyCost + MaintenceCost;
|
2025-05-14 04:27:31 +00:00
|
|
|
console.log('TotalAnnualCost: ', TotalAnnualCost);
|
|
|
|
|
2025-05-14 08:55:54 +00:00
|
|
|
|
2025-05-14 04:27:31 +00:00
|
|
|
//Profit for Year
|
|
|
|
let ProfitforYear = RevenueForYear - TotalAnnualCost;
|
|
|
|
console.log('ProfitforYear: ', ProfitforYear);
|
|
|
|
|
|
|
|
//Net Profit
|
|
|
|
let NetProfit = ProfitforYear * productionPeriod;
|
|
|
|
console.log('NetProfit: ', NetProfit);
|
|
|
|
|
|
|
|
|
|
|
|
//Final ROI
|
|
|
|
const ROIData = ((NetProfit + salvageValue - initialInvestment) / TotalAnnualCost) * 100;
|
|
|
|
console.log('ROIData: ', ROIData);
|
|
|
|
|
|
|
|
|
|
|
|
// Payback Period
|
|
|
|
const paybackPeriod = initialInvestment / ProfitforYear;
|
|
|
|
console.log('paybackPeriod: ', paybackPeriod);
|
2025-05-14 12:51:49 +00:00
|
|
|
|
2025-05-14 08:55:54 +00:00
|
|
|
|
|
|
|
setRoiSummaryData({
|
2025-05-14 12:51:49 +00:00
|
|
|
productName: selectedProduct.productName,
|
|
|
|
roiPercentage: parseFloat((ROIData / 100).toFixed(2)),
|
|
|
|
paybackPeriod: parseFloat(paybackPeriod.toFixed(2)),
|
2025-05-14 08:55:54 +00:00
|
|
|
totalCost: TotalAnnualCost,
|
|
|
|
revenueGenerated: RevenueForYear,
|
|
|
|
netProfit: NetProfit > 0 ? NetProfit : 0,
|
|
|
|
netLoss: NetProfit < 0 ? -NetProfit : 0
|
|
|
|
});
|
2025-05-14 04:27:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, [inputValues, productionCapacityData]);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<></>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
|