gps tracking stuff
This commit is contained in:
@@ -245,30 +245,52 @@ const ApplicationExecutionModal = ({ application, propertyDetails, onClose, onCo
|
||||
// Validate required fields
|
||||
if (!validSectionId) {
|
||||
toast.error('No valid section found for this application');
|
||||
console.error('Invalid section ID:', validSectionId, 'Available sections:', sections);
|
||||
return;
|
||||
}
|
||||
if (!validEquipmentId) {
|
||||
toast.error('No equipment information found for this application');
|
||||
console.error('Invalid equipment ID:', validEquipmentId, 'Plan details:', planDetails);
|
||||
return;
|
||||
}
|
||||
if (validProducts.length === 0) {
|
||||
toast.error('No products found for this application');
|
||||
console.error('No valid products. Original products:', planDetails?.products, 'Filtered products:', validProducts);
|
||||
return;
|
||||
}
|
||||
|
||||
// Validate GPS tracking data exists
|
||||
if (gpsTrack.length === 0) {
|
||||
console.warn('No GPS tracking data collected');
|
||||
toast.error('No GPS tracking data was collected. Please ensure location services are enabled.');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('All validations passed. GPS points:', gpsTrack.length, 'Total distance:', totalDistance, 'Duration:', duration);
|
||||
|
||||
// Prepare GPS track data - ensure all required fields are present and valid
|
||||
const gpsTrackData = {
|
||||
points: gpsTrack.map(point => ({
|
||||
lat: point.lat,
|
||||
lng: point.lng,
|
||||
timestamp: point.timestamp,
|
||||
accuracy: point.accuracy || 0,
|
||||
speed: point.speed || 0
|
||||
})),
|
||||
totalDistance: Math.round(totalDistance * 100) / 100, // Round to 2 decimal places
|
||||
duration: Math.round(duration), // Duration in seconds
|
||||
averageSpeed: Math.round(averageSpeed * 100) / 100 // Round to 2 decimal places
|
||||
};
|
||||
|
||||
// Try minimal log data first
|
||||
const logData = {
|
||||
planId: application.id,
|
||||
lawnSectionId: validSectionId,
|
||||
equipmentId: validEquipmentId,
|
||||
gpsTrack: {
|
||||
points: gpsTrack,
|
||||
totalDistance: totalDistance,
|
||||
duration: duration
|
||||
}, // Backend expects object format
|
||||
gpsTrack: gpsTrackData, // Backend expects object format with points array
|
||||
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`,
|
||||
areaCovered: Math.max(application.totalSectionArea || application.sectionArea || 0, 0.1), // Ensure positive
|
||||
notes: `Application completed via mobile tracking. Duration: ${Math.round(duration/60)} minutes, Distance: ${(totalDistance * 3.28084).toFixed(0)} ft, Points: ${gpsTrack.length}`,
|
||||
products: validProducts
|
||||
};
|
||||
|
||||
@@ -277,12 +299,16 @@ const ApplicationExecutionModal = ({ application, propertyDetails, onClose, onCo
|
||||
|
||||
try {
|
||||
// Save the application log to the backend
|
||||
await applicationsAPI.createLog(logData);
|
||||
console.log('About to call createLog with data:', JSON.stringify(logData, null, 2));
|
||||
const response = await applicationsAPI.createLog(logData);
|
||||
console.log('CreateLog response:', response);
|
||||
toast.success('Application completed successfully');
|
||||
onComplete();
|
||||
} catch (error) {
|
||||
console.error('Failed to save application log:', error);
|
||||
toast.error('Failed to save application log');
|
||||
console.error('Error details:', error.response?.data);
|
||||
console.error('Full error object:', JSON.stringify(error.response || error, null, 2));
|
||||
toast.error(`Failed to save application log: ${error.response?.data?.message || error.message}`);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user