Untitled

 avatar
unknown
plain_text
a year ago
1.4 kB
4
Indexable
else if (product.product_code >= 1000) {
      const productsInPack = allPacks.filter(
        (item) => item.pack_id === product.product_code
      );
      const findPack = allProducts.find(
        (item) => item.code === product.product_code
      );
      if (!findPack) {
        resultPack.push({
          status: "error",
          error: `O pacote ${product.product_code} não foi encontrado!`,
        });
        continue;
      }
      let totalNewPrice = 0;
      productsInPack.forEach((packItem) => {
        const productInPackage = allProducts.find(
          (item) => item.code === packItem.product_id
        );
        if (productInPackage) {
          const priceToUse =
            productInPackage.code === product.product_code
              ? product.new_price
              : productInPackage.sales_price;
          totalNewPrice += priceToUse * packItem.qty;
        }
      });
      resultPack.push({
        status: "success",
        pack: {
          code: findPack.code,
          name: findPack.name,
          cost_price: findPack.cost_price,
          quantity: productsInPack.length,
          sales_price: findPack.sales_price,
          new_price: totalNewPrice,
        },
      });
    } else {
      result.push({
        status: "error",
        error: `Código de produto inválido: ${product.product_code}`,
      });
      continue;
    }
Editor is loading...
Leave a Comment