/**
   * Check for AVS verified required settlements when clicking the Next button on Capture & Review -
   * Offer page
   */
  public void offerNextButtonClick() {

    solveSelected();
    try {
      getAvCaches().clear();
      findSettlementAvData(dto);
      // forced to do the logic here since AvCache is a BayServ entity so we cannot use TaskRules
      boolean avsDone = true;
      String errorMsg = "Account verification status for AV required settlement account : ";
      for (ProtoAvCache item : avCaches) {
        if (!ValidationUtils.isIn(item.getAppStatus(), SystemConstants.AV_COMPLETED)) {
          String accountRef = "";
          for (ProtoSettlement settlement : quote.getSettlements()) {
            String compare = StringUtils.right(settlement.getAccount().getAccountNumber(), 10);
            if (compare.equals(item.getNumber().toString())) {
              accountRef = settlement.getFormattedAccountNumber();
              avsDone = false;
              break;
            }
          }
          errorMessage("AVS", errorMsg + accountRef + " : " + item.getAppStatus(), ERR_GLOBAL);
        }
      }
      if (!avsDone) return;

      taskRules.postOfferRules(quote, task);

      taskRules.loanCOCheckoutRules(quote);

      filterSelectedCellularOffers(quote);
      fixCurrentOffer(quote);
      dto.initialiseConfirmOfferCall();
      getRc().execute(UI_NEXT);

    } catch (ServiceException e) {
      popupErrorMessage(e.getError());
      getRc().update(UI_MAIN);
    }
  }
  @Override
  @PostConstruct
  protected void onTaskReceive() throws ServiceException {
    try {
      super.onTaskReceive();
      if (task.getPid() == -1L) return;

      // must bypass descendants, let them initialize inside their own post constructs
      if (!this.getClass().getSimpleName().equals(TASK)) return;

      // only works with a valid PID
      dto = dao.read(task.getPid());
      super.setDto(dto);
      super.setQuote(dto);

      LookupItem jobTitle = lookupItemDAO.find(LookupItem.onCode, dto.getJobTitleCode());
      dto.setJobTitle(jobTitle);

      if (task.isSupport()) {
        // task inspector default
        xdsOnlyRequired = false;
        // look for a special support target
        if (task.getTaskTarget().equals("task.confirm.offer.xds")) {
          xdsOnlyRequired = true;
          // set it back to the real target otherwise documents won't load
          task.setTaskTarget("task.confirm.offer.call");
        }
      } else {
        xdsOnlyRequired = isSalesFlowV2_1(task) && !isCallCenterChannel(task.getPid());
      }

      // set some state
      dto.setCurrentTask(task);
      dto.setUserLink(bayfin.getUser());
      resolveLogTag(dto);
      filterSelectedSettlements(dto);
      buildOfferResponse(dto); // used for recalc
      loadBCMBundle();

      // also read in the cart data
      if (boot.findFeature("INSURANCE_CART").equals("On")) {
        cart = cartDAO.read(task.getPid());
        cart.setCurrentTask(task);
        cart.setUserLink(bayfin.getUser());
        resolveLogTag(cart);
        loadCart();
        showBanking =
            taskRules.insuredBankAccountRequired(cart.getInsuredBankAccount())
                || taskRules.insuredBankAccountRequired(cart.getOffers());
      }
      if (task.getOrigin().equals("task.confirm.offer.call.insurance")) {
        dto.setInsStandalone(true);
      }

      // now also fetch the XdsAuthenticationHIstoryLog
      fetchXdsLog(dto);
      checkXDSExistingStatus();

      // Initialize with the task associated branch details
      signingBranchCode = new Long(task.getBranchCode());

      // Search for branch name
      BranchBasedSearchRequest request = new BranchBasedSearchRequest();
      BranchSearch search = new BranchSearch();
      request.setData(search);
      GeneralSearchResponse response;
      // set
      request.setType(ESearchResultType.LIST);
      search.setSearchType(ESearchParameter.CODE);
      search.setIncludeAgentData(false);
      search.setIncludeUserData(false);
      search.setBranchCode(signingBranchCode);

      // execute
      response = bayserv.branchSearch(request);
      List<ViewBranch> branches = response.getBranchItems();
      if (branches != null && branches.size() > 0) {
        signingBranch = branches.get(0).getBranchName();
      } // end if

      dto.initialiseConfirmOfferCall();
      bindPresenceCall();

      if (pilotFlag.equals("BNW_V0")) {
        disVoiceContract = true;
        disBranchContract = false;
        dto.setContractingMethod(EContractingMethod.BRANCH);
        branchpre = true;
      } else if (info.isAppFeatureActive("CONTBRN", dto.getBranchCode().intValue())
          && dto.getRequestedProduct() != EProductType.MEDICAL
          && dto.getSubgroupType() != EEmployerType.PAYROLL
          && !isWebChannel(task.getPid())
          && !isCallCenterChannel(task.getPid())) {
        disVoiceContract = true;
        disBranchContract = false;
        dto.setContractingMethod(EContractingMethod.BRANCH);
        branchpre = true;
      } else if ((info.isAppFeatureActive("CONTVOICE", dto.getBranchCode().intValue())
              && dto.getRequestedProduct() != EProductType.MEDICAL
              && dto.getSubgroupType() != EEmployerType.PAYROLL)
          || isWebChannel(task.getPid())
          || isCallCenterChannel(task.getPid())) {
        disVoiceContract = false;
        disBranchContract = true;
        dto.setContractingMethod(EContractingMethod.VOICE);
        branchpre = false;
      } else if (info.isAppFeatureActive("CONTBOTH", dto.getBranchCode().intValue())
          && dto.getRequestedProduct() != EProductType.MEDICAL
          && dto.getSubgroupType() != EEmployerType.PAYROLL) {
        disVoiceContract = false;
        disBranchContract = false;
      } else if ((dto.getRequestedProduct() != EProductType.MEDICAL)
          && (dto.getSubgroupType() != EEmployerType.PAYROLL)) {
        if (quote.getStartRole().equals("Branch") || quote.getStartRole().equals("Agent")) {
          disVoiceContract = true;
          disBranchContract = false;
          dto.setContractingMethod(EContractingMethod.BRANCH);
          branchpre = true;
        } else {
          disVoiceContract = false;
          disBranchContract = false;
        }
      } else if ((dto.getRequestedProduct() == EProductType.MEDICAL)
          && (dto.getSubgroupType() != EEmployerType.PAYROLL)) {
        disVoiceContract = false;
        disBranchContract = true;
        dto.setContractingMethod(EContractingMethod.VOICE);
        branchpre = false;
      } else if (dto.getSubgroupType() == EEmployerType.PAYROLL) {
        disVoiceContract = true;
        disBranchContract = false;
        dto.setContractingMethod(EContractingMethod.BRANCH);
        branchpre = true;
      }

      if ((disVoiceContract == true) && (disBranchContract == true)) {
        throw new ServiceException("BAD#Error, both voice and branch contracting disabled");
      }

      if (dto.getRequestedProduct() == EProductType.MEDICAL) {
        if (dto.getSubgroupType() == EEmployerType.PAYROLL) {
          throw new Exception("Invalid product subgroup received");
        }
        dto.setContractingMethod(EContractingMethod.VOICE);
        disVoiceContract = false;
      }
      if (dto.getSubgroupType() == EEmployerType.PAYROLL) {
        disBranchContract = false;
      }
      employerName = dto.getEmployerName();

      // do not display settlements on web apps
      if (isWebChannel(task.getPid())) {
        dto.setWebChannel(true);
      }

    } catch (ServiceException e) {
      e.printStackTrace();
      popupErrorMessage(e.getError());
    } catch (Exception e) {
      e.printStackTrace();
      popupErrorMessage("Unhandled exception", e.getMessage());
    }
  }