From 1429141e7c1bdea8f16a4a64bff834bc800a8306 Mon Sep 17 00:00:00 2001 From: Jake Kasper Date: Thu, 28 Aug 2025 08:14:08 -0500 Subject: [PATCH] efasdf --- .../Applications/ApplicationPlanModal.js | 60 ++++++++++++------- 1 file changed, 39 insertions(+), 21 deletions(-) diff --git a/frontend/src/components/Applications/ApplicationPlanModal.js b/frontend/src/components/Applications/ApplicationPlanModal.js index 8b712d1..a2d07bd 100644 --- a/frontend/src/components/Applications/ApplicationPlanModal.js +++ b/frontend/src/components/Applications/ApplicationPlanModal.js @@ -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 = ({

{calc.productName}:

Product needed: {calc.totalProductNeeded} {calc.unit}

- {calc.waterNeeded > 0 &&

Water needed: {calc.waterNeeded} gallons

}
))} + {applicationType === 'liquid' && calculations.waterNeeded > 0 && ( +
+

Water needed: {calculations.waterNeeded} gallons

+
+ )} ) : null;