|
|
|
|
@ -2065,6 +2065,7 @@ exports.getOrdersByCustomer = async (req, reply) => {
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.acceptQuotation = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { quotationId } = req.params;
|
|
|
|
|
@ -2109,19 +2110,36 @@ exports.acceptQuotation = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
for (const sensor of sensorTypes) {
|
|
|
|
|
if (sensor.count > 0) {
|
|
|
|
|
await Insensors.updateMany(
|
|
|
|
|
{ storeId, type: sensor.type, status: "available" },
|
|
|
|
|
{ $set: { status: "blocked", customerId } },
|
|
|
|
|
{ limit: sensor.count }
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Update SensorStock
|
|
|
|
|
await SensorStock.updateOne(
|
|
|
|
|
{ storeId, type: sensor.type },
|
|
|
|
|
{
|
|
|
|
|
$inc: { total_available: -sensor.count, total_blocked: sensor.count },
|
|
|
|
|
const stock = await SensorStock.findOne({ storeId, type: sensor.type });
|
|
|
|
|
|
|
|
|
|
if (stock) {
|
|
|
|
|
let available = stock.total_available || 0;
|
|
|
|
|
let needed = sensor.count;
|
|
|
|
|
|
|
|
|
|
let toBlock = Math.min(available, needed);
|
|
|
|
|
let excessNeeded = needed - toBlock;
|
|
|
|
|
|
|
|
|
|
// Update Insensors for available sensors
|
|
|
|
|
if (toBlock > 0) {
|
|
|
|
|
await Insensors.updateMany(
|
|
|
|
|
{ storeId, type: sensor.type, status: "available" },
|
|
|
|
|
{ $set: { status: "blocked", customerId } },
|
|
|
|
|
{ limit: toBlock }
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Update SensorStock
|
|
|
|
|
await SensorStock.updateOne(
|
|
|
|
|
{ storeId, type: sensor.type },
|
|
|
|
|
{
|
|
|
|
|
$inc: {
|
|
|
|
|
total_available: -toBlock,
|
|
|
|
|
total_blocked: toBlock,
|
|
|
|
|
excess_needed: excessNeeded > 0 ? excessNeeded : 0,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|