Example #1
0
  public static String getResponse(String url) {
    try {
      HttpClient httpClient = HttpClients.createDefault();
      HttpGet get = new HttpGet(new URI(url));

      String authorization = AccountUtil.getLoginPassword();
      Charset charset = Charset.forName("UTF-8");
      String encodedAuthorization =
          "Basic " + new String(Base64.encodeBase64(authorization.getBytes(charset)), charset);
      get.setHeader("Authorization", encodedAuthorization);
      HttpResponse response = httpClient.execute(get);
      String userJsons = EntityUtils.toString(response.getEntity());
      return userJsons;
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(0);
      ;
    }
    return null;
  }
Example #2
0
  @Override
  public int tiersExport(String path, Vector<OrderLine> orderLines)
      throws IOException, SQLException {
    //
    OrderLine e = null;
    int errors = 0;
    boolean m1 = false;
    boolean m2 = false;
    String message = "";
    StringBuilder logMessage = new StringBuilder();
    String m1prefix = MessageUtil.getMessage("account.error");
    String m2prefix = MessageUtil.getMessage("matching.account.error");
    String logpath = path + ".log";
    PrintWriter out = new PrintWriter(new FileWriter(path));

    for (int i = 0, n = orderLines.size(); i < n; i++) {
      e = orderLines.elementAt(i);
      if (!AccountUtil.isPersonalAccount(e.getAccount())) {
        errors++;
        logMessage
            .append(m1prefix)
            .append(" -> ")
            .append(e)
            .append(" [")
            .append(e.getAccount())
            .append("]")
            .append(TextUtil.LINE_SEPARATOR);
        m1 = true;
        continue;
      }

      int p = getPersonalAccountId(e.getAccount().getId());
      if (p == 0) {
        errors++;
        logMessage
            .append(m2prefix)
            .append(" -> ")
            .append(e.getAccount())
            .append(TextUtil.LINE_SEPARATOR);
        m2 = true;
        continue;
      }

      Account c = getAccount(p);
      String m = nf.format(Math.abs(e.getAmount()) / 100.0); // le montant doit être positif
      String codeJournal = getCodeJournal(e.getAccount().getId());
      String f = (e.getInvoice() == null) ? "" : e.getInvoice();
      out.print(
          TextUtil.padWithTrailingZeros(c.getNumber(), 10)
              + "#"
              + dateFormat.format(e.getDate().getDate())
              + "#"
              + codeJournal
              + "#"
              + TextUtil.padWithTrailingSpaces(e.getDocument(), 10)
              + "#"
              + TextUtil.padWithTrailingSpaces(TextUtil.truncate(e.getLabel(), 24), 24)
              + "#"
              + TextUtil.padWithLeadingZeros(m, 13)
              + "#"
              + (e.getAmount() < 0 ? cd : dc) // cd Crédit
              + "#"
              + TextUtil.padWithTrailingSpaces(e.getCostAccount().getNumber(), 10)
              + "#"
              + (char) 13);

      out.print(
          TextUtil.padWithTrailingZeros(getAccount(e), 10) // compte client
              + "#"
              + dateFormat.format(e.getDate().getDate())
              + "#"
              + codeJournal
              + "#"
              + TextUtil.padWithTrailingSpaces(f, 10)
              + "#"
              + TextUtil.padWithTrailingSpaces(TextUtil.truncate(e.getLabel(), 24), 24)
              + "#"
              + TextUtil.padWithLeadingZeros(m, 13)
              + "#"
              + (e.getAmount() < 0 ? dc : cd) // dc Débit
              + "#"
              + TextUtil.padWithTrailingSpaces("", 10)
              + "#"
              + (char) 13); // CR (Carriage return, retour à la ligne)
    }
    out.close();

    if (logMessage.length() > 0) {
      PrintWriter log = new PrintWriter(new FileWriter(logpath));
      log.println(logMessage.toString());
      log.close();
    }

    if (errors > 0) {
      if (m1) {
        message += MessageUtil.getMessage("personal.account.export.warning");
      }
      if (m2) {
        message += MessageUtil.getMessage("no.revenue.matching.warning");
      }
      String err = MessageUtil.getMessage("error.count.warning", errors);
      String l = MessageUtil.getMessage("see.log.file", path);
      MessagePopup.warning(null, err + message + l);
    }

    return errors;
  }