Ejemplo n.º 1
0
  private ServicioRep mapEntity(List<Account> list) {
    ServicioRep rep = new ServicioRep();
    SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy hh:mm");
    List<TipoPago> tpl = new ArrayList<TipoPago>();
    List<TipoServicio> tsl = new ArrayList<TipoServicio>();
    Map<String, TipoPago> tpMap = new HashMap<String, TipoPago>();
    Map<String, List<Servicio>> tsMap = new HashMap<String, List<Servicio>>();
    for (Account at : list) {
      for (FolioTransaction ft : at.getFolioTransactionCollection()) {
        TipoPago tpago = tpMap.get(ft.getPayId().getPayCode());
        if (tpago == null) {
          tpMap.put(
              ft.getPayId().getPayCode(),
              new TipoPago(ft.getPayId().getPayDesc(), ft.getFtrAmount()));
        } else {
          tpago.setTotal(tpago.getTotal().add(ft.getFtrAmount()));
        }
      }
      for (AccountTransactions act : at.getAccountTransactionsCollection()) {
        if (act.getSrvId() != null) {
          BigDecimal ammt =
              act.getSrvId().getSrvPrice().multiply(new BigDecimal(act.getAtrQuantity()));
          if (MMKeys.AccountsTransactions.STA_PAGADO_KEY.equalsIgnoreCase(
              act.getAtrStatus().getMvaKey())) {
            List<Servicio> sl = tsMap.get(act.getSrvId().getSvtId().getSvtDesc());
            if (sl == null) {
              sl = new ArrayList<Servicio>();
              sl.add(
                  new Servicio(act.getSrvId().getSrvDesc(), act.getAtrQuantity(), ammt.toString()));
              tsMap.put(act.getSrvId().getSvtId().getSvtDesc(), sl);
            } else {
              sl.add(
                  new Servicio(act.getSrvId().getSrvDesc(), act.getAtrQuantity(), ammt.toString()));
            }
          }
        }
      }
    }

    for (TipoPago entry : tpMap.values()) {
      tpl.add(entry);
    }
    for (String key : tsMap.keySet()) {
      tsl.add(new TipoServicio(key, tsMap.get(key)));
    }
    rep.setPymentType(tpl);
    rep.setServiceType(tsl);

    return rep;
  }