Esempio n. 1
0
  /** @param string */
  private void prepareChildren(String indexes) {
    GenericMapper childrenMapper = null;

    String field = "";
    if (m_type.equalsIgnoreCase("Project Cost")) {
      childrenMapper = MasterMap.obtainMapperFor(PmtProjectCostDetail.class);
      field = "PmtProjectCost";
    } else {
      childrenMapper = MasterMap.obtainMapperFor(PmtOperationalCostDetail.class);
      field = "PmtOperationalCost";
    }

    childrenMapper.setActiveConn(m_conn);
    String clause = "1=1";
    /*if (!indexes.equals(""))
    clause = field + " in (" + indexes + ")";*/

    if (!indexes.equals("")) {
      int idx = indexes.indexOf("ORDER BY");
      indexes = indexes.substring(0, idx);
      clause = field + " in (select autoindex from " + field + " where " + indexes + ")";
    }
    List childrenList = childrenMapper.doSelectWhere(clause);

    childrenMap = new HashMap();
    Iterator iterator = childrenList.iterator();
    while (iterator.hasNext()) {
      if (m_type.equalsIgnoreCase("Project Cost")) {
        PmtProjectCostDetail det = (PmtProjectCostDetail) iterator.next();

        Long key = new Long(det.getPmtProjectCost().getIndex());
        if (childrenMap.containsKey(key)) {
          List dets = (List) childrenMap.get(key);
          dets.add(det);
        } else {
          List dets = new ArrayList();
          dets.add(det);
          childrenMap.put(key, dets);
        }
      } else {
        PmtOperationalCostDetail det = (PmtOperationalCostDetail) iterator.next();

        Long key = new Long(det.getPmtOperationalCost().getIndex());
        if (childrenMap.containsKey(key)) {
          List dets = (List) childrenMap.get(key);
          dets.add(det);
        } else {
          List dets = new ArrayList();
          dets.add(det);
          childrenMap.put(key, dets);
        }
      }
    }
  }
Esempio n. 2
0
    public String getTotal(GeneralVoucherToGetTotal voucher, String type, Connection conn) {
      double total = 0;
      DecimalFormat dm = new DecimalFormat("#,##0.00");

      if (type.equalsIgnoreCase("Project Cost")) {
        /*GenericMapper mapper=MasterMap.obtainMapperFor(PmtProjectCostDetail.class);
        mapper.setActiveConn(vConn);
        String strWhere = IDBConstants.ATTR_PMT_PROJECT_COST+"="+voucher.vgetIndex();
        List rs=mapper.doSelectWhere(strWhere);
        */
        PmtProjectCostDetail detail = null;

        Long key = new Long(voucher.vgetIndex());
        List rs = (List) childrenMap.get(key);

        String attr = "";
        if (voucher.vgetCashAccount() != null) attr = IConstants.ATTR_PMT_CASH;
        else if (voucher.vgetBankAccount() != null) attr = IConstants.ATTR_PMT_BANK;
        else {
          if (voucher.igetPaymentSource().equalsIgnoreCase("CASH")) attr = IConstants.ATTR_PMT_CASH;
          else attr = IConstants.ATTR_PMT_BANK;
        }
        /*JournalStandardAccount[] jsAccounts = getJournalStandardAccount(attr);*/

        JournalStandardAccount[] jsAccounts =
            (JournalStandardAccount[]) journalStandardAccountsMap.get(attr);

        if (rs != null)
          for (int i = 0; i < rs.size(); i++) {
            detail = (PmtProjectCostDetail) rs.get(i);
            for (int j = 0; j < jsAccounts.length; j++)
              if (detail.getAccount().getIndex() == jsAccounts[j].getAccount().getIndex())
                if (!jsAccounts[j].isCalculate() && !jsAccounts[j].isHidden()) {
                  JournalStandardAccount jsAccount = jsAccounts[j];
                  double amount = detail.getaccValue();
                  if (jsAccount.getBalance() == 1) amount = -detail.getaccValue();
                  total += amount;
                }
          }
      } else if (type.equalsIgnoreCase("Operational Cost")) {
        if (voucher != null) {
          /*GenericMapper mapper=MasterMap.obtainMapperFor(PmtOperationalCostDetail.class);
          mapper.setActiveConn(conn);
          List detailList=mapper.doSelectWhere(IDBConstants.ATTR_PMT_OPERASIONAL_COST+"="+voucher.vgetIndex());*/

          Long key = new Long(voucher.vgetIndex());
          List detailList = (List) childrenMap.get(key);

          PmtOperationalCostDetail detail;
          int length = detailList.size();
          if (length > 0) {
            /*JournalStandardAccount[] jsAccounts = getJournalStandardAccount((PmtOperationalCost) voucher);*/

            PmtOperationalCost pmt = (PmtOperationalCost) voucher;

            String attr = "";
            if (pmt.getCashAccount() != null) {
              attr = IConstants.ATTR_PMT_CASH;
            } else if (pmt.getBankAccount() != null) {
              attr = IConstants.ATTR_PMT_BANK;
            } else if (pmt.getPaymentSource().equalsIgnoreCase("BANK")) {
              attr = IConstants.ATTR_PMT_BANK;
            } else if (pmt.getPaymentSource().equalsIgnoreCase("CASH")) {
              attr = IConstants.ATTR_PMT_CASH;
            }

            JournalStandardAccount[] jsAccounts =
                (JournalStandardAccount[]) journalStandardAccountsMap.get(attr);

            if (detailList != null)
              for (int i = 0; i < detailList.size(); i++) {
                detail = (PmtOperationalCostDetail) detailList.get(i);
                for (int j = 0; j < jsAccounts.length; j++)
                  if (detail.getAccount().getIndex() == jsAccounts[j].getAccount().getIndex())
                    if (!jsAccounts[j].isCalculate() && !jsAccounts[j].isHidden()) {
                      JournalStandardAccount jsAccount = jsAccounts[j];
                      double amount = detail.getAccValue();
                      if (jsAccount.getBalance() == 1) amount = -detail.getAccValue();
                      total += amount;
                    }
              }
          } else {
            total = 0;
          }
        }
      }
      return dm.format(total);
    }