|
|
|
@ -125,6 +125,7 @@ const customerautopercentages = ({
|
|
|
|
|
const motordataSchema = new mongoose.Schema({
|
|
|
|
|
customerId: { type: String, default: null },
|
|
|
|
|
motor_id: { type: String, default: null },
|
|
|
|
|
started_by:{ type: String, default: "user" },
|
|
|
|
|
start_instance_id:{type:String,default:null},
|
|
|
|
|
supplierTank: { type: String, default: null },
|
|
|
|
|
receiverTank: { type: String, default: null },
|
|
|
|
@ -142,6 +143,36 @@ const motordataSchema = new mongoose.Schema({
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const updateMotorData = async () => {
|
|
|
|
|
try {
|
|
|
|
|
// Fetch all motor data where quantity_delivered is null or needs updating
|
|
|
|
|
const motorDataRecords = await MotorData.find({});
|
|
|
|
|
|
|
|
|
|
for (let record of motorDataRecords) {
|
|
|
|
|
// Convert string values to numbers by removing commas
|
|
|
|
|
const initialLevel = parseInt(record.receiverInitialwaterlevel.replace(/,/g, ""), 10) || 0;
|
|
|
|
|
const finalLevel = parseInt(record.receiverfinalwaterlevel.replace(/,/g, ""), 10) || 0;
|
|
|
|
|
|
|
|
|
|
// Calculate quantity delivered
|
|
|
|
|
const quantityDelivered = finalLevel - initialLevel;
|
|
|
|
|
|
|
|
|
|
// Update the record
|
|
|
|
|
await MotorData.updateOne(
|
|
|
|
|
{ _id: record._id },
|
|
|
|
|
{
|
|
|
|
|
$set: {
|
|
|
|
|
started_by: "user",
|
|
|
|
|
quantity_delivered: quantityDelivered.toString(), // Convert back to string for consistency
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log("Motor data updated successfully!");
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error("Error updating motor data:", err);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const tankSchema = new mongoose.Schema({
|
|
|
|
|
tankhardwareId: { type: String },
|
|
|
|
|