Merge remote-tracking branch 'origin/v3-refactor' into v3
This commit is contained in:
commit
c965961d98
|
@ -1,11 +1,11 @@
|
||||||
import { useProductContext } from '../../../modules/simulation/products/productContext'
|
import { useProductContext } from '../../../modules/simulation/products/productContext'
|
||||||
import RegularDropDown from '../../ui/inputs/RegularDropDown';
|
import RegularDropDown from '../../ui/inputs/RegularDropDown';
|
||||||
import { useProductStore } from '../../../store/simulation/useProductStore';
|
import { useProductStore } from '../../../store/simulation/useProductStore';
|
||||||
import { useSaveVersion } from '../../../store/builder/store';
|
import { useLoadingProgress, useSaveVersion } from '../../../store/builder/store';
|
||||||
import useModuleStore from '../../../store/useModuleStore';
|
import useModuleStore from '../../../store/useModuleStore';
|
||||||
import CompareLayOut from '../../ui/compareVersion/CompareLayOut';
|
import CompareLayOut from '../../ui/compareVersion/CompareLayOut';
|
||||||
import ComparisonResult from '../../ui/compareVersion/ComparisonResult';
|
import ComparisonResult from '../../ui/compareVersion/ComparisonResult';
|
||||||
import { useComparisonProduct } from '../../../store/simulation/useSimulationStore';
|
import { useComparisonProduct, useMainProduct } from '../../../store/simulation/useSimulationStore';
|
||||||
import { usePauseButtonStore, usePlayButtonStore } from '../../../store/usePlayButtonStore';
|
import { usePauseButtonStore, usePlayButtonStore } from '../../../store/usePlayButtonStore';
|
||||||
|
|
||||||
function ComparisonScene() {
|
function ComparisonScene() {
|
||||||
|
@ -16,7 +16,9 @@ function ComparisonScene() {
|
||||||
const { selectedProductStore } = useProductContext();
|
const { selectedProductStore } = useProductContext();
|
||||||
const { selectedProduct } = selectedProductStore();
|
const { selectedProduct } = selectedProductStore();
|
||||||
const { comparisonProduct, setComparisonProduct } = useComparisonProduct();
|
const { comparisonProduct, setComparisonProduct } = useComparisonProduct();
|
||||||
|
const { mainProduct } = useMainProduct();
|
||||||
const { setIsPaused } = usePauseButtonStore();
|
const { setIsPaused } = usePauseButtonStore();
|
||||||
|
const { loadingProgress } = useLoadingProgress();
|
||||||
|
|
||||||
const handleSelectLayout = (option: string) => {
|
const handleSelectLayout = (option: string) => {
|
||||||
const product = products.find((product) => product.productName === option);
|
const product = products.find((product) => product.productName === option);
|
||||||
|
@ -40,7 +42,7 @@ function ComparisonScene() {
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
<CompareLayOut />
|
<CompareLayOut />
|
||||||
{false && <ComparisonResult />}
|
{(comparisonProduct && mainProduct && !loadingProgress) && <ComparisonResult />}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
|
|
|
@ -2,6 +2,7 @@ import React, { useEffect, useState } from 'react'
|
||||||
import { useInputValues, useProductionCapacityData, useROISummaryData } from '../../../../store/builder/store';
|
import { useInputValues, useProductionCapacityData, useROISummaryData } from '../../../../store/builder/store';
|
||||||
import { usePlayButtonStore } from '../../../../store/usePlayButtonStore';
|
import { usePlayButtonStore } from '../../../../store/usePlayButtonStore';
|
||||||
import { useProductContext } from '../../products/productContext';
|
import { useProductContext } from '../../products/productContext';
|
||||||
|
import { useProductStore } from '../../../../store/simulation/useProductStore';
|
||||||
|
|
||||||
export default function ROIData() {
|
export default function ROIData() {
|
||||||
const { selectedProductStore } = useProductContext();
|
const { selectedProductStore } = useProductContext();
|
||||||
|
@ -10,6 +11,9 @@ export default function ROIData() {
|
||||||
const { selectedProduct } = selectedProductStore();
|
const { selectedProduct } = selectedProductStore();
|
||||||
const { isPlaying } = usePlayButtonStore();
|
const { isPlaying } = usePlayButtonStore();
|
||||||
const { setRoiSummaryData } = useROISummaryData();
|
const { setRoiSummaryData } = useROISummaryData();
|
||||||
|
const { products, getProductById } = useProductStore();
|
||||||
|
const [compareProducts, setCompareProducts] = useState<any[]>([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isPlaying) {
|
if (!isPlaying) {
|
||||||
setRoiSummaryData({
|
setRoiSummaryData({
|
||||||
|
@ -43,47 +47,36 @@ export default function ROIData() {
|
||||||
!isNaN(materialCost) && !isNaN(productionPeriod) && !isNaN(salvageValue) && !isNaN(sellingPrice) &&
|
!isNaN(materialCost) && !isNaN(productionPeriod) && !isNaN(salvageValue) && !isNaN(sellingPrice) &&
|
||||||
!isNaN(shiftLength) && !isNaN(shiftsPerDay) && !isNaN(workingDaysPerYear) && productionCapacityData > 0) {
|
!isNaN(shiftLength) && !isNaN(shiftsPerDay) && !isNaN(workingDaysPerYear) && productionCapacityData > 0) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const totalHoursPerYear = shiftLength * shiftsPerDay * workingDaysPerYear;
|
const totalHoursPerYear = shiftLength * shiftsPerDay * workingDaysPerYear;
|
||||||
|
|
||||||
// Total good units produced per year
|
// Total good units produced per year
|
||||||
const annualProductionUnits = productionCapacityData * totalHoursPerYear;
|
const annualProductionUnits = productionCapacityData * totalHoursPerYear;
|
||||||
|
|
||||||
// Revenue for a year
|
// Revenue for a year
|
||||||
const annualRevenue = annualProductionUnits * sellingPrice;
|
const annualRevenue = annualProductionUnits * sellingPrice;
|
||||||
|
|
||||||
// Costs
|
// Costs
|
||||||
const totalMaterialCost = annualProductionUnits * materialCost;
|
const totalMaterialCost = annualProductionUnits * materialCost;
|
||||||
const totalLaborCost = laborCost * totalHoursPerYear;
|
const totalLaborCost = laborCost * totalHoursPerYear;
|
||||||
const totalEnergyCost = electricityCost * totalHoursPerYear;
|
const totalEnergyCost = electricityCost * totalHoursPerYear;
|
||||||
const totalMaintenanceCost = maintenanceCost + fixedCost;
|
const totalMaintenanceCost = maintenanceCost + fixedCost;
|
||||||
|
|
||||||
const totalAnnualCost = totalMaterialCost + totalLaborCost + totalEnergyCost + totalMaintenanceCost;
|
const totalAnnualCost = totalMaterialCost + totalLaborCost + totalEnergyCost + totalMaintenanceCost;
|
||||||
|
|
||||||
// Annual Profit
|
// Annual Profit
|
||||||
const annualProfit = annualRevenue - totalAnnualCost;
|
const annualProfit = annualRevenue - totalAnnualCost;
|
||||||
console.log('annualProfit: ', annualProfit);
|
|
||||||
|
|
||||||
// Net Profit over production period
|
// Net Profit over production period
|
||||||
const netProfit = annualProfit * productionPeriod;
|
const netProfit = annualProfit * productionPeriod;
|
||||||
|
|
||||||
// ROI
|
// ROI
|
||||||
const roiPercentage = ((netProfit + salvageValue - initialInvestment) / initialInvestment) * 100;
|
const roiPercentage = ((netProfit + salvageValue - initialInvestment) / initialInvestment) * 100;
|
||||||
|
|
||||||
// Payback Period
|
// Payback Period
|
||||||
const paybackPeriod = initialInvestment / (annualProfit || 1); // Avoid division by 0
|
const paybackPeriod = initialInvestment / (annualProfit || 1); // Avoid division by 0
|
||||||
console.log('paybackPeriod: ', paybackPeriod);
|
|
||||||
|
|
||||||
// console.log("--- ROI Breakdown ---");
|
//
|
||||||
// console.log("Annual Production Units:", annualProductionUnits.toFixed(2));
|
//
|
||||||
// console.log("Annual Revenue:", annualRevenue.toFixed(2));
|
//
|
||||||
// console.log("Total Annual Cost:", totalAnnualCost.toFixed(2));
|
//
|
||||||
// console.log("Annual Profit:", annualProfit.toFixed(2));
|
//
|
||||||
// console.log("Net Profit:", netProfit.toFixed(2));
|
//
|
||||||
// console.log("ROI %:", roiPercentage.toFixed(2));
|
//
|
||||||
// console.log("Payback Period (years):", paybackPeriod.toFixed(2));
|
//
|
||||||
|
|
||||||
setRoiSummaryData({
|
setRoiSummaryData({
|
||||||
productName: selectedProduct.productName,
|
productName: selectedProduct.productName,
|
||||||
|
@ -107,13 +100,48 @@ export default function ROIData() {
|
||||||
const netProfitForTarget = profitForTargetUnits > 0 ? profitForTargetUnits : 0;
|
const netProfitForTarget = profitForTargetUnits > 0 ? profitForTargetUnits : 0;
|
||||||
const netLossForTarget = profitForTargetUnits < 0 ? -profitForTargetUnits : 0;
|
const netLossForTarget = profitForTargetUnits < 0 ? -profitForTargetUnits : 0;
|
||||||
|
|
||||||
// console.log("--- Fixed Product Count (" + productCount + ") ---");
|
//
|
||||||
// console.log("Cost per Unit:", costPerUnit.toFixed(2));
|
//
|
||||||
// console.log("Total Cost for " + productCount + " Units:", costForTargetUnits.toFixed(2));
|
//
|
||||||
// console.log("Revenue for " + productCount + " Units:", revenueForTargetUnits.toFixed(2));
|
//
|
||||||
// console.log("Profit:", netProfitForTarget.toFixed(2));
|
//
|
||||||
// console.log("Loss:", netLossForTarget.toFixed(2));
|
//
|
||||||
|
|
||||||
|
const productData = getProductById(selectedProduct.productUuid);
|
||||||
|
|
||||||
|
|
||||||
|
setCompareProducts(prev => {
|
||||||
|
const newData = {
|
||||||
|
productUuid: productData?.productUuid,
|
||||||
|
productName: productData?.productName,
|
||||||
|
costPerUnit: parseFloat(costPerUnit.toFixed(2)),
|
||||||
|
workingDaysPerYear: parseFloat(workingDaysPerYear.toFixed(2)),
|
||||||
|
shiftLength: parseFloat(shiftLength.toFixed(2)),
|
||||||
|
shiftsPerDay: parseFloat(shiftsPerDay.toFixed(2)),
|
||||||
|
roiPercentage: parseFloat((roiPercentage / 100).toFixed(2)),
|
||||||
|
paybackPeriod: parseFloat(paybackPeriod.toFixed(2)),
|
||||||
|
totalCost: parseFloat(totalAnnualCost.toFixed(2)),
|
||||||
|
revenueGenerated: parseFloat(annualRevenue.toFixed(2)),
|
||||||
|
netProfit: netProfit > 0 ? parseFloat(netProfit.toFixed(2)) : 0,
|
||||||
|
netLoss: netProfit < 0 ? parseFloat((-netProfit).toFixed(2)) : 0
|
||||||
|
};
|
||||||
|
|
||||||
|
const existingIndex = prev.findIndex(
|
||||||
|
item => item.productUuid === productData?.productUuid
|
||||||
|
);
|
||||||
|
|
||||||
|
if (existingIndex !== -1) {
|
||||||
|
// Replace the existing item
|
||||||
|
const updated = [...prev];
|
||||||
|
updated[existingIndex] = newData;
|
||||||
|
return updated;
|
||||||
|
} else {
|
||||||
|
// Add as new item
|
||||||
|
return [...prev, newData];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// console.log('compareProducts: ', compareProducts);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}, [inputValues, productionCapacityData]);
|
}, [inputValues, productionCapacityData]);
|
||||||
|
|
|
@ -36,7 +36,7 @@ export default function ThroughPutData() {
|
||||||
setMaterialCycleTime(0);
|
setMaterialCycleTime(0);
|
||||||
setProcessBar([]);
|
setProcessBar([]);
|
||||||
setThroughputData(0);
|
setThroughputData(0);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
let process: any = [];
|
let process: any = [];
|
||||||
const fetchProductSequenceData = async () => {
|
const fetchProductSequenceData = async () => {
|
||||||
|
@ -190,9 +190,6 @@ export default function ThroughPutData() {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (machineActiveTime > 0 && materialCycleTime > 0 && machineCount > 0) {
|
if (machineActiveTime > 0 && materialCycleTime > 0 && machineCount > 0) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const utilization = machineActiveTime / 3600; // Active time per hour
|
const utilization = machineActiveTime / 3600; // Active time per hour
|
||||||
const unitsPerMachinePerHour = 3600 / materialCycleTime;
|
const unitsPerMachinePerHour = 3600 / materialCycleTime;
|
||||||
const throughput = unitsPerMachinePerHour * machineCount * utilization;
|
const throughput = unitsPerMachinePerHour * machineCount * utilization;
|
||||||
|
|
Loading…
Reference in New Issue