This commit is contained in:
Jake Kasper
2025-08-28 08:14:08 -05:00
parent bd5f982e76
commit 1429141e7c

View File

@@ -20,7 +20,7 @@ const ApplicationPlanModal = ({
const [selectedNozzleId, setSelectedNozzleId] = useState('');
const [selectedProducts, setSelectedProducts] = useState([]);
const [applicationType, setApplicationType] = useState('');
const [plannedDate, setPlannedDate] = useState('');
const [plannedDate, setPlannedDate] = useState(new Date().toISOString().split('T')[0]);
const [notes, setNotes] = useState('');
const [loading, setLoading] = useState(false);
const [spreaderSettings, setSpreaderSettings] = useState({});
@@ -356,45 +356,59 @@ const ApplicationPlanModal = ({
return total + (area?.area || 0);
}, 0);
const totalAreaSquareMeters = totalArea * 0.092903; // Convert sq ft to sq meters
let waterNeeded = 0;
// For liquid applications, calculate water needed once for all products
if (applicationType === 'liquid' && selectedNozzleId && selectedEquipmentId) {
const selectedNozzle = nozzles.find(n => n.id === parseInt(selectedNozzleId));
const selectedEquipment = equipment.find(eq => eq.id === parseInt(selectedEquipmentId));
if (selectedNozzle && selectedEquipment && selectedNozzle.flowRateGpm && selectedEquipment.sprayWidthFeet) {
// Convert units
const flowRateLPM = selectedNozzle.flowRateGpm * 3.78541; // GPM to L/min
const widthMeters = selectedEquipment.sprayWidthFeet * 0.3048; // feet to meters
const speedMPM = 107.29; // Assumed speed in meters/minute (4 km/h)
// Carrier application rate: Rate (L/m²) = flow (L/min) / (width (m) × speed (m/min))
const carrierRate = flowRateLPM / (widthMeters * speedMPM);
// Total water needed = carrier rate × total area
const waterNeededLiters = carrierRate * totalAreaSquareMeters;
waterNeeded = waterNeededLiters * 0.264172; // Convert liters to gallons
}
}
const calculations = selectedProducts.map(product => {
const rateAmount = parseFloat(product.rateAmount) || 0;
const areaIn1000s = totalArea / 1000;
if (product.productType === 'granular') {
// Granular calculations
const totalProductNeeded = rateAmount * areaIn1000s;
// Granular calculations - total product needed
const totalProductNeeded = (rateAmount * totalArea) / 1000; // Rate is per 1000 sq ft
return {
productName: product.productName,
totalProductNeeded: totalProductNeeded.toFixed(2),
unit: product.rateUnit,
unit: product.rateUnit?.replace('/1000sqft', '').replace('/1000 sq ft', '') || 'lbs',
waterNeeded: 0 // No water for granular
};
} else {
// Liquid calculations
const totalProductNeeded = rateAmount * areaIn1000s;
// Calculate water needed based on nozzle and equipment settings
let waterNeeded = 0;
if (selectedNozzleId) {
const selectedNozzle = nozzles.find(n => n.id === parseInt(selectedNozzleId));
if (selectedNozzle && selectedNozzle.flowRateGpm) {
// Basic calculation - this would need equipment speed settings for accuracy
waterNeeded = (selectedNozzle.flowRateGpm * 60 * areaIn1000s) / 1000; // Rough estimate
}
}
// Liquid calculations - total product needed
const totalProductNeeded = (rateAmount * totalArea) / 1000; // Rate is per 1000 sq ft
return {
productName: product.productName,
totalProductNeeded: totalProductNeeded.toFixed(2),
unit: product.rateUnit,
waterNeeded: waterNeeded.toFixed(1)
unit: product.rateUnit?.replace('/1000sqft', '').replace('/1000 sq ft', '') || 'oz',
waterNeeded: 0 // Water calculated separately for liquid
};
}
});
return {
totalArea: totalArea.toLocaleString(),
calculations
calculations,
waterNeeded: waterNeeded > 0 ? waterNeeded.toFixed(1) : 0
};
};
@@ -805,9 +819,13 @@ const ApplicationPlanModal = ({
<div key={index} className="mb-2">
<p className="font-medium">{calc.productName}:</p>
<p className="ml-2">Product needed: {calc.totalProductNeeded} {calc.unit}</p>
{calc.waterNeeded > 0 && <p className="ml-2">Water needed: {calc.waterNeeded} gallons</p>}
</div>
))}
{applicationType === 'liquid' && calculations.waterNeeded > 0 && (
<div className="mt-2 pt-2 border-t border-blue-200">
<p className="font-medium">Water needed: {calculations.waterNeeded} gallons</p>
</div>
)}
</div>
</div>
) : null;