private void updatePromoUses() throws WrongParamException {
    try {
      this.promoId =
          (request.getParameter("promoId") == null
                  || request.getParameter("promoId").equals("")
                  || request.getParameter("promoId").equals("undefined")
                  || request.getParameter("promoId").equals("null"))
              ? null
              : Integer.parseInt(request.getParameter("promoId"));
      this.tipusPromo =
          (request.getParameter("tipusPromo") == null
                  || request.getParameter("tipusPromo").equals("")
                  || request.getParameter("tipusPromo").equals("undefined"))
              ? null
              : request.getParameter("tipusPromo");
    } catch (NumberFormatException e) {
      throw new WrongParamException("wrong promo id");
    }
    if (this.promoId != null && this.tipusPromo != null) {

      if (this.tipusPromo.equals("gen"))
        this.promocionsBo.updateNumUsed(this.promoId, Utils.formatDate2(new Date()));

      if (this.tipusPromo.equals("esp"))
        this.promocionsBo.updateNumUsedAssociada(this.promoId, Utils.formatDate2(new Date()));
    }
  }
  private void inizilizeComandaDiaHoraADomicili() throws WrongParamException {

    try {

      this.hora =
          (request.getParameter("hora") == null || request.getParameter("hora").equals(""))
              ? null
              : request.getParameter("hora");
      this.dia =
          (request.getParameter("dia") == null || request.getParameter("dia").equals(""))
              ? null
              : Utils.getDate2(request.getParameter("dia"));
      this.aDomicili =
          (request.getParameter("aDomicili") == null
                  || request.getParameter("aDomicili").equals(""))
              ? null
              : request.getParameter("aDomicili");
      this.targeta =
          (request.getParameter("targeta") == null || request.getParameter("targeta").equals(""))
              ? null
              : request.getParameter("targeta");

    } catch (Exception e) {
      throw new WrongParamException("wrong id of comanda");
    }
  }
  public VotacioTMPBeguda getBeguda(Long idBeguda, Long idUser) {

    List<VotacioTMPBeguda> list =
        (List<VotacioTMPBeguda>)
            getHibernateTemplate()
                .find(
                    "from VotacioTMPBeguda vtmp where vtmp.begudaId="
                        + idBeguda
                        + " and vtmp.userId="
                        + idUser
                        + " and vtmp.dia='"
                        + Utils.formatDate2(new Date())
                        + "'");
    if (!list.isEmpty()) {
      return list.get(0);
    }
    return null;
  }
  public VotacioTMP get(Long idplat, Long idUser) {

    List<VotacioTMP> list =
        (List<VotacioTMP>)
            getHibernateTemplate()
                .find(
                    "from VotacioTMP vtmp where vtmp.platId="
                        + idplat
                        + " and vtmp.userId="
                        + idUser
                        + " and vtmp.dia='"
                        + Utils.formatDate2(new Date())
                        + "'");
    if (!list.isEmpty()) {
      return list.get(0);
    }
    return null;
  }
  public String checkComanda() {

    ServletOutputStream out = null;
    String json = "";
    ResourceBundle resource = getTexts("MessageResources");

    try {
      out = this.response.getOutputStream();
      setAuthenticationUser();

      if (this.nameAuth.equals("anonymousUser")) {
        json = Utils.createNotLogedJSON("User not loged. Login before...");
      } else {
        inizilizeComandaId();
        inizilizeComandaDiaHoraADomicili();
        inizializeAddress();
        inizilizeIndicacions();

        Users user = this.usersBo.findByUsername(this.nameAuth);

        this.comanda = this.comandaBo.load(this.idComanda);

        this.comanda.setHora(Utils.getHora(this.hora));
        this.comanda.setDia(this.dia);
        this.comanda.setaDomicili(Boolean.valueOf(aDomicili));
        this.comanda.setTargeta(Boolean.valueOf(targeta));
        this.comanda.setPagada(false);
        if (this.address != null) {
          this.comanda.setAddress(Utils.decodeUTFONlyWords(this.address));
        } else {
          this.comanda.setAddress(this.address);
        }

        this.comanda.setObservacions(Utils.decodeUTFONlyWords(this.indicacions));
        if (this.comanda.getUser() == null) {
          this.comanda.setUser(user);
        }
        this.comanda.setPreu(this.comandaService.getPreuOfComanda(comanda));
        updatePromoUses();
        if (this.promoId != null) {
          Promocio promo = this.promocionsBo.load(this.promoId);
          if (promo != null) {
            this.comanda.setImportDescomte(promo.getDescompteImport());
            this.comanda.setTipuDescomte(promo.getTipuDescompte());
          }
        }
        this.comandaBo.update(this.comanda);
        json = this.comandaService.checkComandaProblems(this.comanda, resource);

        if (json.contains("comandaOK") && user != null) {

          if (this.promoId != null) user.setCodePromo("");
          this.usersBo.update(user);
        }
      }

    } catch (ComandaException ce) {
      json = Utils.createErrorJSON("error in comanda service action");
    } catch (Exception e) {
      json = Utils.createErrorJSON("error in ajax action");
    }

    try {
      out.print(json);
    } catch (IOException e) {
      throw new GeneralException(e, "possibly ServletOutputStream null");
    }
    return null;
  }