|
|
|
@ -973,10 +973,47 @@ exports.getpumpswitchqc = async (req, reply) => {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const generateBatchNo = (type, hardwareIdCompany) => {
|
|
|
|
|
const date = new Date();
|
|
|
|
|
const ddmmyy = `${date.getDate().toString().padStart(2, '0')}${(date.getMonth() + 1).toString().padStart(2, '0')}${date.getFullYear().toString().slice(-2)}`;
|
|
|
|
|
const companyPrefix = hardwareIdCompany.slice(0, 2).toUpperCase();
|
|
|
|
|
const randomNumbers = Math.floor(100 + Math.random() * 900).toString(); // 3 random digits
|
|
|
|
|
|
|
|
|
|
if (type === 'slave') {
|
|
|
|
|
return `SL${ddmmyy}${companyPrefix}${randomNumbers}`;
|
|
|
|
|
}
|
|
|
|
|
if (type === 'master') {
|
|
|
|
|
return `MA${ddmmyy}${companyPrefix}${randomNumbers}`;
|
|
|
|
|
}
|
|
|
|
|
if (type === 'motor_switch') {
|
|
|
|
|
return `MS${ddmmyy}${companyPrefix}${randomNumbers}`;
|
|
|
|
|
}
|
|
|
|
|
// Add other type conditions if needed
|
|
|
|
|
return null;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
exports.createSensor = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const storeId = req.params.storeId;
|
|
|
|
|
const { indate, batchno, hardwareId_company, quantity } = req.body;
|
|
|
|
|
const { indate, batchno, hardwareId_company, quantity, model, type } = req.body;
|
|
|
|
|
|
|
|
|
|
let finalBatchNo = batchno;
|
|
|
|
|
|
|
|
|
|
if (batchno === 'new') {
|
|
|
|
|
let isUnique = false;
|
|
|
|
|
|
|
|
|
|
while (!isUnique) {
|
|
|
|
|
finalBatchNo = generateBatchNo(type, hardwareId_company);
|
|
|
|
|
|
|
|
|
|
// Check for uniqueness
|
|
|
|
|
const existingBatchNo = await Insensors.findOne({ batchno: finalBatchNo });
|
|
|
|
|
if (!existingBatchNo) {
|
|
|
|
|
isUnique = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const date = moment().format('MM-DD');
|
|
|
|
|
let entries = [];
|
|
|
|
@ -984,7 +1021,8 @@ exports.createSensor = async (req, reply) => {
|
|
|
|
|
for (let i = 0; i < quantity; i++) {
|
|
|
|
|
const newSensor = {
|
|
|
|
|
storeId,
|
|
|
|
|
batchno,
|
|
|
|
|
model,
|
|
|
|
|
batchno: finalBatchNo,
|
|
|
|
|
type,
|
|
|
|
|
indate,
|
|
|
|
|
hardwareId_company
|
|
|
|
@ -999,3 +1037,20 @@ exports.createSensor = async (req, reply) => {
|
|
|
|
|
reply.code(500).send(err);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getbatchnumbers = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
await Insensors.distinct('batchno', { storeId: req.params.storeId })
|
|
|
|
|
.then((batchNumbers) => {
|
|
|
|
|
reply.send({ status_code: 200, data: batchNumbers, count: batchNumbers.length });
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
console.log(err);
|
|
|
|
|
reply.send({ error: err });
|
|
|
|
|
});
|
|
|
|
|
} catch (err) {
|
|
|
|
|
reply.send({ error: err });
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|