addProductToOrderList method

bool addProductToOrderList({
  1. required CollectStockCardModel product,
  2. required bool isSingle,
  3. required bool isRange,
  4. required bool isBox,
})

Implementation

bool addProductToOrderList({
  required CollectStockCardModel product,
  required bool isSingle,
  required bool isRange,
  required bool isBox,
}) {
  if (isSingle) {
    CollectStockCardModel? orderProduct;
    for (final data in searchedList) {
      if (data.materialCode == product.materialCode) {
        orderProduct = data;
        break;
      }
    }
    if (orderProduct != null) {
      orderProduct.singleList!.addAll(product.singleList!);
      orderProduct.scannedQty =
          product.singleList!.length + orderProduct.scannedQty;
      selectedProduct.value = CollectStockCardModel();
      selectedProduct.value = orderProduct;
      return true;
    } else {
      Helper.assetSuccessDialog(
          Get.context!,
          "Failed to add asset.",
          "Scanned product is not availale in the order",
          const AssetImage(
            "assets/images/failed.png",
          ));

      return false;
    }
  } else if (isRange) {
    CollectStockCardModel? orderProduct;
    for (final data in searchedList) {
      if (data.materialCode == product.materialCode) {
        orderProduct = data;
        break;
      }
    }
    if (orderProduct != null) {
      orderProduct.rangeList!.addAll(product.rangeList!);
      int qty = 0;
      for (final data in product.rangeList!) {
        qty = qty + data.iccidList!.length;
      }
      orderProduct.scannedQty = qty + orderProduct.scannedQty;
      selectedProduct.value = CollectStockCardModel();
      selectedProduct.value = orderProduct;
      return true;
    } else {
      Helper.assetSuccessDialog(
          Get.context!,
          "Failed to add asset.",
          "Scanned product is not availale in the order",
          const AssetImage(
            "assets/images/failed.png",
          ));

      return false;
    }
  } else {
    return false;
  }
}