asdf
This commit is contained in:
@@ -206,24 +206,48 @@ const ApplicationExecutionModal = ({ application, propertyDetails, onClose, onCo
|
|||||||
const endTime = new Date();
|
const endTime = new Date();
|
||||||
const duration = startTime ? (endTime - startTime) / 1000 : 0; // seconds
|
const duration = startTime ? (endTime - startTime) / 1000 : 0; // seconds
|
||||||
|
|
||||||
const logData = {
|
// Ensure we have valid section data from fetched plan details
|
||||||
planId: application.id,
|
const validSectionId = sections.length > 0 ? sections[0].id : null;
|
||||||
lawnSectionId: application.sections?.[0]?.id || application.section?.id, // Use first section for multi-area plans
|
const validEquipmentId = application.equipment?.id;
|
||||||
equipmentId: application.equipment?.id,
|
const validProducts = application.products && application.products.length > 0 ?
|
||||||
applicationDate: endTime.toISOString(),
|
application.products.map(product => ({
|
||||||
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 => ({
|
|
||||||
productId: product.productId,
|
productId: product.productId,
|
||||||
userProductId: product.userProductId,
|
userProductId: product.userProductId,
|
||||||
rateAmount: product.rateAmount,
|
rateAmount: product.rateAmount,
|
||||||
rateUnit: product.rateUnit,
|
rateUnit: product.rateUnit,
|
||||||
actualProductAmount: product.actualProductAmount || product.productAmount,
|
actualProductAmount: product.actualProductAmount || product.productAmount,
|
||||||
actualWaterAmount: product.actualWaterAmount || product.waterAmount,
|
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 {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user