Exemplo n.º 1
0
  public static List<ReconcilationDTO> analyse(InputStream fstream, List<Order> orders) {
    List<ReconcilationDTO> rs = new ArrayList<ReconcilationDTO>();
    try {

      DataInputStream in = new DataInputStream(fstream);
      BufferedReader br = new BufferedReader(new InputStreamReader(in));
      String strLine;
      String sdate = "";
      while ((strLine = br.readLine()) != null) {
        // System.out.println(strLine);

        if (strLine != null) {
          if (strLine.startsWith("0")) {
            sdate = StringUtil.split(strLine, "|")[2];
            SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
            sdate = new SimpleDateFormat("dd MMM yyyy").format(format.parse(sdate));
          } else if (strLine.startsWith("1")) {
            List<ReconcilationDTO> dtos = getDTO(strLine, orders);
            for (ReconcilationDTO dto : dtos) {
              dto.setDate(sdate);
              rs.add(dto);
            }
          }
        }
      }
      in.close();
    } catch (Exception e) {
      System.err.println("Error: " + e.getMessage());
    }
    return rs;
  }
Exemplo n.º 2
0
  public static boolean createItem(ReconcilationDTO tr, CashBook cb) {

    String ref = tr.getRefNumber();
    String amount = tr.getAmount();
    try {
      if (StringUtil.isNotEmpty(ref) && StringUtil.isNotEmpty(amount)) {
        //			BigDecimal bAmount = new BigDecimal(amount);
        //			CashBookEntry entry = cb.createEntry(System.currentTimeMillis() + "" +
        // StringUtil.nextString(10));
        //			entry.setAccountCode( ref);
        //			entry.setSummary("Installment " + ref + " "+ tr.getDate());
        //			entry.setTitle(entry.getSummary());
        //			entry.setTotal(bAmount);
        //			entry.setDateOfTransaction(new SimpleDateFormat("dd MMM yyyy").parse(tr.getDate()));
        //			entry.save();
        String nm = new Date().getTime() + StringUtil.nextString(10);
        String code = StringUtil.nextString(10);
        String sql =
            "insert into WFS_FILE (clazz, dateCreated, lastModified, name, parent_id, summary, title, code, paymentMethod,total, accountCode, dateOfTransaction, DTYPE, absolutePath, size, status, commentable, dislikeit, likeit,ratable) values "
                + "('org.castafiore.accounting.CashBookEntry',now(),now(),'"
                + nm
                + "', "
                + "'/root/users/elieandsons/Applications/e-Shop/elieandsons/DefaultCashBook', "
                + "'Installment "
                + tr.getName()
                + "  "
                + tr.getDate()
                + "', 'Installment "
                + tr.getName()
                + "  "
                + tr.getDate()
                + "', '"
                + code
                + "', 'Standing Order', '"
                + tr.getAmount()
                + "', '"
                + tr.getName()
                + "',now() ,'CashBookEntry','/root/users/elieandsons/Applications/e-Shop/elieandsons/DefaultCashBook/"
                + nm
                + "',1,1,true,1,1, true);";

        SpringUtil.getBeanOfType(Dao.class).getSession().createSQLQuery(sql).executeUpdate();
        return true;
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    return false;
  }
Exemplo n.º 3
0
  private static List<ReconcilationDTO> getDTO(String line, List<Order> orders) {
    List<ReconcilationDTO> result = new ArrayList<ReconcilationDTO>();

    String[] parts = StringUtil.split(line, "|");
    if (parts != null) {
      if (parts[0].equals("1")) {
        try {
          int count = 0;
          for (String part : parts) {
            if (part.contains("FS")) {
              part =
                  part.replace("FS ", "FS")
                      .replace("AND ", "")
                      .replace("-", " ")
                      .replace("REF:", "")
                      .replace(",", " ");
              String as[] = StringUtil.split(part, " ");
              for (String documentNumber : as) {
                if (documentNumber != null && documentNumber.trim().length() > 0) {
                  ReconcilationDTO dto = new ReconcilationDTO();
                  dto.setRefNumber(documentNumber.trim());
                  result.add(dto);
                }
              }
            }
          }

          if (result.size() == 0) {
            ReconcilationDTO dto = new ReconcilationDTO();
            dto.setRefNumber("");
            dto.setComment("No reference number");
            dto.setName(line);
            result.add(dto);
          }

          for (String part : parts) {
            if (part.toLowerCase().contains("bank")) {
              for (ReconcilationDTO dto : result) dto.setBank(part);
            } else if (part.equalsIgnoreCase("MUR")) {
              for (ReconcilationDTO dto : result) dto.setAmount(parts[count + 1]);
            } else if (count == 3) {
              for (ReconcilationDTO dto : result) dto.setName(part);
            } else if (count == 2) {
              for (ReconcilationDTO dto : result) dto.setAccountNumber(part);
            }

            count = count + 1;
          }
          Order order = null;
          if (result.size() > 0) order = searchFromCode(orders, result.get(0).getRefNumber());

          if (order != null) {
            for (ReconcilationDTO dto : result) {
              dto.setComment(dto.getComment() + " Order found");
              dto.setOk(true);
            }
          } else {
            for (ReconcilationDTO dto : result) {
              dto.setComment(dto.getComment() + " Order not found");
              dto.setOk(false);
            }
          }
        } catch (Exception e) {
          for (ReconcilationDTO dto : result) {
            dto.setComment("Cannot parse line");
            dto.setName(line);
          }
        }
      }
    }
    return result;
  }