diff --git a/controllers/order.controller.js b/controllers/order.controller.js index 8da2be42d80863155677d7ab7a6e3a6f839b3168..e33eedae995bbf2d00a0ad72733d04df6019557c 100644 --- a/controllers/order.controller.js +++ b/controllers/order.controller.js @@ -1638,17 +1638,17 @@ module.exports.assignOrdersToDriver = async (req, res) => { }); } - // Create assignments only for new orders - const assignmentPromises = newOrderIds.map((orderId) => - createDriverOrderAssignmentService({ - orderId, - driverId, - assignmentStatus: "pending", - isActive: true, - }) - ); + // // Create assignments only for new orders + // const assignmentPromises = newOrderIds.map((orderId) => + // createDriverOrderAssignmentService({ + // orderId, + // driverId, + // assignmentStatus: "pending", + // isActive: true, + // }) + // ); - const createdAssignments = await Promise.all(assignmentPromises); + // const createdAssignments = await Promise.all(assignmentPromises); return res.status(200).json({ status: true, @@ -2197,10 +2197,10 @@ module.exports.partialFulfillOrder = async (req, res) => { total_before_tax: totalFulfilledAmount, tax_amount: totalFulfilledTax, final_total: - totalFulfilledAmount + - totalFulfilledTax + - shippingCharge - - discountAmount, + parseFloat(totalFulfilledAmount) + + parseFloat(totalFulfilledTax) + + parseFloat(shippingCharge) - + parseFloat(discountAmount), }, { transaction } ); @@ -2211,10 +2211,10 @@ module.exports.partialFulfillOrder = async (req, res) => { subtotal_amount: totalFulfilledAmount, tax_amount: totalFulfilledTax, total_amount: - totalFulfilledAmount + - totalFulfilledTax + - shippingCharge - - discountAmount, + parseFloat(totalFulfilledAmount) + + parseFloat(totalFulfilledTax) + + parseFloat(shippingCharge) - + parseFloat(discountAmount), }, { transaction } ); @@ -2453,6 +2453,8 @@ module.exports.generateShippingLabel = async (req, res) => { }); } + // console.log("order barcode is", order.barcode); + // Check if order belongs to the store (for store admin) const user = req.user; if (user.role === "store_admin" && order.store_id !== user.storeId) { @@ -4919,6 +4921,11 @@ module.exports.createOrderForSuperAdmin = async (req, res) => { } } + // console.log("barcodeeee", barcode); + + const barCode = generateOrderBarcode(barcode); + + // console.log("barCOde after geneartion", barCode); // Create order const order = await createOrderService( { @@ -4927,7 +4934,7 @@ module.exports.createOrderForSuperAdmin = async (req, res) => { cart_id: null, // No cart for super admin orders store_id: storeId, payment_method: paymentMethod, - barcode: barcode, + barcode: barCode?.data, payment_status: paymentMethod === "cod" ? "pending" : "paid", transaction_id: null, subtotal_amount: subtotalAmount, diff --git a/controllers/productStockController.js b/controllers/productStockController.js index 998fd6f21ec9e2bb3122775f4154fa672495208d..fce8ab09589aa185f6ac631f99e0f7089a9970f7 100644 --- a/controllers/productStockController.js +++ b/controllers/productStockController.js @@ -164,9 +164,16 @@ module.exports.addProductStock = async (req, res) => { attributes: ["ID", "productId"], }); + // console.log("existingVariantttttt",existingVariant) let productId, variationId; - if (existingProduct && !existingProduct.isMultiVariant) { + // Priority: Check variant first, then product + if (existingVariant) { + // Variant - id is variantId + productId = existingVariant.productId; + variationId = id; + console.log("Found as variant - productId:", productId, "variationId:", variationId); + } else if (existingProduct && !existingProduct.isMultiVariant) { // Single product - id is productId, but we need to find its variant ID productId = id; // Find the variant ID for this single product @@ -174,11 +181,17 @@ module.exports.addProductStock = async (req, res) => { where: { productId: id, isDeleted: false }, attributes: ["ID"], }); + console.log("Found as single product - productId:", productId); variationId = singleProductVariant ? singleProductVariant.ID : null; - } else if (existingVariant) { - // Variant - id is variantId - productId = existingVariant.productId; - variationId = id; + console.log("Found variant for single product - variationId:", variationId); + } else if (existingProduct && existingProduct.isMultiVariant) { + // Multi-variant product - this is an error case + // User passed a product ID but we need a variant ID for multi-variant products + errors.push({ + id: id, + error: "ID is a multi-variant product ID. Please provide a specific variant ID instead.", + }); + continue; } else { errors.push({ id: id, @@ -718,7 +731,7 @@ module.exports.getProductVariantDetailsByIds = async (req, res) => { }, attributes: ["ID", "isMultiVariant"], }); - console.log("existingProductssssss", existingProducts); + // console.log("existingProductssssss", existingProducts); const existingVariants = await VARIANT_MODEL.findAll({ where: { ID: { [Op.in]: ids }, @@ -785,6 +798,7 @@ module.exports.getProductVariantDetailsByIds = async (req, res) => { "productImage", "sku", "isMultiVariant", + "description", ], }); @@ -846,7 +860,7 @@ module.exports.getProductVariantDetailsByIds = async (req, res) => { type: "product", productId: product.ID, variantId: null, // Single products don't have variantId - productName: product.productName, + productName: product.productName || "Unknown Product", description: product.description, productImage: product.productImage, sku: product.sku, @@ -878,7 +892,7 @@ module.exports.getProductVariantDetailsByIds = async (req, res) => { variantIds.push(...multiVariantVariantIds); } - console.log("resulttttt", results); + // console.log("resulttttt", results); // Process variants (both single product variants and multi-variant product variants) if (variantIds.length > 0) { const variants = await getAllVariantServices({ @@ -948,24 +962,9 @@ module.exports.getProductVariantDetailsByIds = async (req, res) => { const stock = variantStockMap.get(variant.ID); const price = variantPriceMap.get(variant.ID); - // If product is not multi-variant, treat it as a single product - if (!variant.product?.isMultiVariant) { - results.push({ - type: "product", - productId: variant.productId, - variantId: null, // null for single products - productName: variant.product?.productName || "N/A", - productImage: variant.product?.productImage || null, - sku: variant.skuName, // Use skuName as sku for single products - brand: variant.product?.brand?.brandName || "N/A", - isMultiVariant: false, - currentStock: stock?.stockAvailable || 0, - inStock: stock?.iStockQuantity || false, - costPrice: price?.costPrice || null, - lastCostPrice: price?.lastCostPrice || null, - sellingPrice: price?.sellingPrice || null, - }); - } else { + // Only process variants that belong to multi-variant products + // Single products are already handled in the single products section above + if (variant.product?.isMultiVariant) { // Multi-variant product - show as variant results.push({ type: "variant", @@ -985,6 +984,7 @@ module.exports.getProductVariantDetailsByIds = async (req, res) => { sellingPrice: price?.sellingPrice || null, }); } + // Skip single products here - they are already processed in the single products section }); } diff --git a/controllers/user.controller.js b/controllers/user.controller.js index 16c7132d203741eabab0f2a380806c6e314f52fb..4f9c48163bb9b2f287f34cf6cb4835acc15bfb88 100644 --- a/controllers/user.controller.js +++ b/controllers/user.controller.js @@ -286,7 +286,9 @@ module.exports.superAdminLogin = async (req, res) => { loginMessage = "Finance user logged in successfully"; break; default: - loginMessage = "User logged in successfully"; + loginMessage = `${user?.role.charAt(0).toUpperCase()}${user?.role.slice( + 1 + )} logged in successfully`; } res.status(200).json({ @@ -578,12 +580,14 @@ module.exports.createUser = async (req, res) => { // Determine storeId for the new employee based on creator's role and storeId let storeId = null; - + // Check if creator is a store admin or store admin employee (not super admin employee) - if (req.user && - req.user.role == 'store-admin' && - !isSuperAdminEmployee(req.user) && - req.user.storeId) { + if ( + req.user && + req.user.role == "store-admin" && + !isSuperAdminEmployee(req.user) && + req.user.storeId + ) { storeId = req.user.storeId; // Inherit storeId from creator } // For super admin or super admin employees, storeId remains null (global employees)