asdf
This commit is contained in:
@@ -206,24 +206,48 @@ const ApplicationExecutionModal = ({ application, propertyDetails, onClose, onCo
|
||||
const endTime = new Date();
|
||||
const duration = startTime ? (endTime - startTime) / 1000 : 0; // seconds
|
||||
|
||||
const logData = {
|
||||
planId: application.id,
|
||||
lawnSectionId: application.sections?.[0]?.id || application.section?.id, // Use first section for multi-area plans
|
||||
equipmentId: application.equipment?.id,
|
||||
applicationDate: endTime.toISOString(),
|
||||
gpsTrack: gpsTrack,
|
||||
averageSpeed: averageSpeed,
|
||||
areaCovered: application.totalSectionArea || application.sectionArea || 0,
|
||||
notes: `Application completed via mobile tracking. Duration: ${Math.round(duration/60)} minutes`,
|
||||
products: application.products?.map(product => ({
|
||||
// Ensure we have valid section data from fetched plan details
|
||||
const validSectionId = sections.length > 0 ? sections[0].id : null;
|
||||
const validEquipmentId = application.equipment?.id;
|
||||
const validProducts = application.products && application.products.length > 0 ?
|
||||
application.products.map(product => ({
|
||||
productId: product.productId,
|
||||
userProductId: product.userProductId,
|
||||
rateAmount: product.rateAmount,
|
||||
rateUnit: product.rateUnit,
|
||||
actualProductAmount: product.actualProductAmount || product.productAmount,
|
||||
actualWaterAmount: product.actualWaterAmount || product.waterAmount,
|
||||
actualSpeedMph: averageSpeed
|
||||
})) || []
|
||||
actualSpeedMph: Math.max(averageSpeed, 0.1) // Ensure positive speed
|
||||
})) : [];
|
||||
|
||||
// Validate required fields
|
||||
if (!validSectionId) {
|
||||
toast.error('No valid section found for this application');
|
||||
return;
|
||||
}
|
||||
if (!validEquipmentId) {
|
||||
toast.error('No equipment information found for this application');
|
||||
return;
|
||||
}
|
||||
if (validProducts.length === 0) {
|
||||
toast.error('No products found for this application');
|
||||
return;
|
||||
}
|
||||
|
||||
const logData = {
|
||||
planId: application.id,
|
||||
lawnSectionId: validSectionId,
|
||||
equipmentId: validEquipmentId,
|
||||
completedAt: endTime.toISOString(), // Use completedAt instead of applicationDate
|
||||
gpsTrack: {
|
||||
points: gpsTrack,
|
||||
totalDistance: totalDistance,
|
||||
duration: duration
|
||||
}, // Convert gpsTrack to object format
|
||||
averageSpeed: Math.max(averageSpeed, 0.1), // Ensure positive number
|
||||
areaCovered: application.totalSectionArea || application.sectionArea || 0,
|
||||
notes: `Application completed via mobile tracking. Duration: ${Math.round(duration/60)} minutes`,
|
||||
products: validProducts
|
||||
};
|
||||
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user