prepareCartRequest method

AddToCartRequest prepareCartRequest(
  1. String? serialNum,
  2. String? serialStartRange,
  3. String? serialEndRange,
  4. String? productCode,
)

Implementation

AddToCartRequest prepareCartRequest(String? serialNum,
    String? serialStartRange, String? serialEndRange, String? productCode) {
  String buyerType = storage.read("LEVEL_ID").toString();
  String sellerType = storage.read("DISTRIBUTER_LEVEL_ID").toString();
  String region = storage.read("REGION_NAME") ?? "";
  String? buyerTypeEntityId = storage.read("PARTNER_ID") ?? "";
  String sellerTypeEntityId = SecureStorageService.readSecureData(
        SecureStorageService.partnerIdLogin,
      ) ??
      "";
  String levelNameLogin = SecureStorageService.readSecureData(
        SecureStorageService.levelNameLogin,
      ) ??
      "Regional Distributor(RD)";
  var transactionType = "SCAN_IN";
  List<RelatedParty> relatedPart = [];
  var category = "";

  relatedPart
      .add(RelatedParty(name: levelNameLogin, role: "DistributorType"));
  if (currentScan == ScanType.collectStock) {
    storage.read("DISTRIBUTOR_DRO_USER_ID");
    transactionType = "SCAN_IN";
    buyerType = SecureStorageService.readSecureData(
          SecureStorageService.levelIdLogin,
        ) ??
        "";
    buyerTypeEntityId = null;
    category = "scan-in";
    relatedPart.add(RelatedParty(
        name: storage.read("DISTRIBUTOR_DRO_USER_ID"), role: "CreatedBy"));
    relatedPart.add(RelatedParty(
        name: storage.read("DISTRIBUTOR_DRO_USER_ID"), role: "agentId"));
    relatedPart.add(RelatedParty(
        id: math.Random().nextInt(100) + 50,
        name: storage.read("WAREHOUSE_ID"),
        role: "distributorWarehouseId"));
  } else if (currentScan == ScanType.spotSellThru) {
    relatedPart.add(RelatedParty(name: userId, role: "CreatedBy"));
    transactionType = "SPOT_SELL_THRU";
    buyerType = storage.read("LEVEL_ID").toString();
    buyerTypeEntityId = storage.read("PARTNER_ID") ?? "";
    category = "spot-sell-thru";
    relatedPart.add(RelatedParty(name: userId, role: "agentId"));
  } else if (currentScan == ScanType.sellThru) {
    relatedPart.add(RelatedParty(name: userId, role: "CreatedBy"));
    transactionType = "SELL_THRU";
    buyerType = storage.read("LEVEL_ID").toString();
    buyerTypeEntityId = storage.read("PARTNER_ID") ?? "";
    category = "sell-thru-delivery";
    relatedPart.add(RelatedParty(name: userId, role: "agentId"));
  }

  AddToCartRequest request = AddToCartRequest();
  List<SelectedCartoffers> selectedCartoffers = [];
  selectedCartoffers.add(SelectedCartoffers(
      assetId: serialNum,
      productCode: productCode,
      startRange: serialStartRange,
      endRange: serialEndRange));
  ContextParameters contextParameters = ContextParameters(
      currencyType: "USD",
      buyerType: buyerType,
      buyerTypeEntityId: buyerTypeEntityId,
      sellerTypeEntityId: sellerTypeEntityId,
      sellerType: sellerType,
      region: region,
      transactionType: transactionType);
  request.contextParameters = contextParameters;
  request.relatedParty = relatedPart;
  request.selectedCartoffers = selectedCartoffers;
  // if (currentScan == ScanType.spotSellThru) {
  //   List<AdhocTax> adhocTaxList = [];
  //   AdhocTax adhocTax = AdhocTax(
  //       name: "CTW",
  //       type: "PERCENTAGE",
  //       value: storage.read("ADHOX_TAX_VALUE") ?? "",
  //       code: storage.read("ADHOX_TAX_CODE") ?? "");
  //   adhocTaxList.add(adhocTax);
  //   request.adhocTax = adhocTaxList;
  // }
  request.category = category;
  // request.category = "sell-thru";
  return request;
}