updateSpotSellThruOrder method

Future<void> updateSpotSellThruOrder(
  1. CartModel data
)

Implementation

Future<void> updateSpotSellThruOrder(cart.CartModel data) async {
  var products = data.data!.products ?? [];
  RxList<ProductContentModel> temp = <ProductContentModel>[].obs;
  var tempIccids = <String>[].obs;
  if (products.isNotEmpty) {
    var totalAmount = data.data!.totalRetailPrice ?? 0.0; // subTotal
    var totalNetAmount = data.data!.totalSellingPrice; // strike through
    double ctw = 0.0; // - value
    double? ctwPercentage;
    var totalDiscount = 0.0;
    if (data.data!.taxes != null) {
      // total discount
      data.data!.taxes!.forEach((element) {
        if (element.name! == "COMMISSION" || element.name! == "Commission") {
          totalDiscount = element.totalPrice != null
              ? double.parse(element.totalPrice!)
              : 0.0;
        }
        if (element.name! == "WHT" || element.name! == "CTW") {
          ctwPercentage = element.percentage;
          var sign = 1;
          if (element.whtBearer != null &&
              element.whtBearer!.isNotEmpty &&
              element.whtBearer! == "DEALER") {
            sign = -1;
          }
          ctw = element.totalPrice != null
              ? double.parse(element.totalPrice!) * sign
              : 0.0;
        }
      });
    }
    double totalTax = 0.0; //
    double overallSaleTaxPercentage = 0.0; //

    var salesTax = "Vat";
    var ctwNegativeTax = "CTW"; // red color
    var localCurrency = data.data!.grandTotalInLocalCurrency!.price!.currency;
    var currency = data.data!.currency;
    var localGrandTotal = data.data!.grandTotalInLocalCurrency!.price!.amount;
    totalTax = data.data!.overallSaleTax ?? 0.0;
    overallSaleTaxPercentage = data.data!.overallSaleTaxPercentage ?? 0.0;
    // ctw = data.data!.totalWHT ?? 0.0;
    // data.data!.taxes!.forEach((tax) {
    //   if (tax.name == "SalesTax") {
    //     salesTax = "Vat";
    //     totalTax = double.parse(tax.totalPrice!);
    //   }
    //   if (tax.name!.toLowerCase() == "ctw") {
    //     ctwNegativeTax = tax.name!;
    //     ctw = double.parse(tax.totalPrice!);
    //   }
    // });
    var totalAmountPaid = data.data!.grandTotal ?? "0.0";
    products.forEach((product) {
      ProductContentModel productModel = ProductContentModel();
      productModel.productCode = product.productCode ?? "";
      productModel.productId = product.productId ?? "";
      productModel.productImage = product.productImage ?? "";
      productModel.productName = product.name ?? "";
      productModel.totalOrderedQuantity = 0;
      productModel.itemAmount =
          product.unitPrice != null ? double.parse(product.unitPrice!) : 0;
      productModel.unitSellingPrice = product.sellingUnitPrice != null
          ? double.parse(product.sellingUnitPrice!)
          : 0;
      productModel.sellingPrice = product.sellingPrice != null
          ? double.parse(product.sellingPrice!)
          : 0;
      productModel.itemTax =
          product.unitTax != null ? double.parse(product.unitTax!) : 0;
      productModel.scannedQty = product.quantity ?? 0;

      // tempIccids.addAll(product.assetList!);
      List<SingleScannedModel> iccidList = [];
      product.assetList!.forEach((element) {
        iccidList.add(SingleScannedModel(
            iccid: element.id, purchaseOrderDate: element.purchaseOrderDate));
        tempIccids.add(element.id!);
      });
      productModel.iccidList = iccidList;
      productModel.rangeList = [];
      temp.add(productModel);
    });

    sellThruOrder.value = SellThruProductDataModel(
      currency: currency,
      localCurrency: localCurrency,
      localCurrencyGrandTotal: double.parse(localGrandTotal!),
      ctwNegativeTax: ctwNegativeTax,
      ctw: ctw,
      salesTax: salesTax,
      paymentStatus: "PENDING",
      content: productDataScannedList,
      totalAmount: double.parse(totalAmount.toString()),
      totalNetAmount: totalNetAmount,
      totalTax: totalTax,
      taxPercentage: ctwPercentage?.toString(),
      overallSaleTaxPercentage: overallSaleTaxPercentage,
      totalDiscount: totalDiscount,
      totalAmountPaid: double.parse(totalAmountPaid),
    );
  }
  scannedIccidList = tempIccids; // assigning all the scanned iccids;
  productDataScannedList.value = [...temp]; // assigning product list
}