Exemplo n.º 1
0
AB_IMEXPORTER_ACCOUNTINFO*
AB_ImExporterContext_FindAccountInfoByIban(AB_IMEXPORTER_CONTEXT *iec, const char *iban){
  AB_IMEXPORTER_ACCOUNTINFO *iea;

  if (!iban)
    iban="";

  assert(iec);
  iea=AB_ImExporterAccountInfo_List_First(iec->accountInfoList);
  while(iea) {
    const char *sIban;

    sIban=AB_ImExporterAccountInfo_GetIban(iea);
    if (sIban==0)
      sIban="";
    if (strcasecmp(sIban, iban)==0) {
      return iea;
    }
    iea=AB_ImExporterAccountInfo_List_Next(iea);
  }
  return 0;
}
Exemplo n.º 2
0
int listBal(AB_BANKING *ab, GWEN_DB_NODE *dbArgs, int argc, char **argv)
{
  GWEN_DB_NODE *db;
  int rv;
  const char *ctxFile;
  AB_IMEXPORTER_CONTEXT *ctx=0;
  AB_IMEXPORTER_ACCOUNTINFO *iea=0;
  uint32_t aid;
  const char *bankId;
  const char *accountId;
  const char *subAccountId;
  const char *iban;
  const char *tmplString;
  const char *s;
  AB_BALANCE_TYPE bt=AB_Balance_TypeBooked;

  /* parse command line arguments */
  db=_readCommandLine(dbArgs, argc, argv);
  if (db==NULL) {
    /* error in command line */
    return 1;
  }

  /* read command line arguments */
  aid=(uint32_t)GWEN_DB_GetIntValue(db, "uniqueAccountId", 0, 0);
  bankId=GWEN_DB_GetCharValue(db, "bankId", 0, 0);
  accountId=GWEN_DB_GetCharValue(db, "accountId", 0, 0);
  subAccountId=GWEN_DB_GetCharValue(db, "subAccountId", 0, 0);
  iban=GWEN_DB_GetCharValue(db, "iban", 0, 0);
  tmplString=GWEN_DB_GetCharValue(db, "template", 0,
                                  "$(dateAsString)\t"
                                  "$(valueAsString)\t"
                                  "$(iban)");

  /* determine balance type */
  s=GWEN_DB_GetCharValue(db, "balanceType", 0, "noted");
  if (s && *s) {
    AB_BALANCE_TYPE tempBalanceType;

    tempBalanceType=AB_Balance_Type_fromString(s);
    if (tempBalanceType==AB_Balance_TypeUnknown) {
      DBG_ERROR(0, "Invalid balance type given (%s)", s);
      return 1;
    }
    bt=tempBalanceType;
  }

  /* init AqBanking */
  rv=AB_Banking_Init(ab);
  if (rv) {
    DBG_ERROR(0, "Error on init (%d)", rv);
    return 2;
  }

  /* load ctx file */
  ctxFile=GWEN_DB_GetCharValue(db, "ctxfile", 0, 0);
  rv=readContext(ctxFile, &ctx, 1);
  if (rv<0) {
    DBG_ERROR(0, "Error reading context (%d)", rv);
    AB_ImExporterContext_free(ctx);
    return 4;
  }

  /* copy context, but only keep wanted accounts and transactions */
  iea=AB_ImExporterContext_GetFirstAccountInfo(ctx);
  while (iea) {
    if (AB_ImExporterAccountInfo_Matches(iea,
                                         aid,  /* unique account id */
                                         "*",
                                         bankId,
                                         accountId,
                                         subAccountId,
                                         iban,
                                         "*", /* currency */
                                         AB_AccountType_Unknown)) {
      AB_BALANCE *bal;
      GWEN_DB_NODE *dbAccount;
      const char *s;

      dbAccount=GWEN_DB_Group_new("dbAccount");

      s=AB_ImExporterAccountInfo_GetBankCode(iea);
      if (s && *s)
        GWEN_DB_SetCharValue(dbAccount, GWEN_DB_FLAGS_OVERWRITE_VARS, "bankCode", s);

      s=AB_ImExporterAccountInfo_GetAccountNumber(iea);
      if (s && *s)
        GWEN_DB_SetCharValue(dbAccount, GWEN_DB_FLAGS_OVERWRITE_VARS, "accountNumber", s);

      s=AB_ImExporterAccountInfo_GetBic(iea);
      if (s && *s)
        GWEN_DB_SetCharValue(dbAccount, GWEN_DB_FLAGS_OVERWRITE_VARS, "bic", s);

      s=AB_ImExporterAccountInfo_GetIban(iea);
      if (s && *s)
        GWEN_DB_SetCharValue(dbAccount, GWEN_DB_FLAGS_OVERWRITE_VARS, "iban", s);

      bal=AB_Balance_List_GetLatestByType(AB_ImExporterAccountInfo_GetBalanceList(iea), bt);
      if (bal) {
        GWEN_DB_NODE *dbElement;
        const AB_VALUE *v;
        const GWEN_DATE *dt;
        GWEN_BUFFER *dbuf;

        dbElement=GWEN_DB_Group_dup(dbAccount);
        AB_Balance_toDb(bal, dbElement);

        /* translate value */
        dbuf=GWEN_Buffer_new(0, 256, 0, 1);
        v=AB_Balance_GetValue(bal);
        if (v) {
          AB_Value_toHumanReadableString(v, dbuf, 2, 0);
          GWEN_DB_SetCharValue(dbElement, GWEN_DB_FLAGS_OVERWRITE_VARS, "valueAsString", GWEN_Buffer_GetStart(dbuf));
          GWEN_Buffer_Reset(dbuf);
        }

        /* translate date */
        dt=AB_Balance_GetDate(bal);
        if (dt) {
          rv=GWEN_Date_toStringWithTemplate(dt, I18N("DD.MM.YYYY"), dbuf);
          if (rv>=0) {
            GWEN_DB_SetCharValue(dbElement, GWEN_DB_FLAGS_OVERWRITE_VARS, "dateAsString", GWEN_Buffer_GetStart(dbuf));
          }
          GWEN_Buffer_Reset(dbuf);
        }

        GWEN_DB_ReplaceVars(dbElement, tmplString, dbuf);
        fprintf(stdout, "%s\n", GWEN_Buffer_GetStart(dbuf));
        GWEN_Buffer_free(dbuf);
        GWEN_DB_Group_free(dbElement);
      } /* if bal */

      GWEN_DB_Group_free(dbAccount);
    } /* if account matches */

    iea=AB_ImExporterAccountInfo_List_Next(iea);
  } /* while */
  AB_ImExporterContext_free(ctx);

  /* deinit */
  rv=AB_Banking_Fini(ab);
  if (rv) {
    fprintf(stderr, "ERROR: Error on deinit (%d)\n", rv);
    return 5;
  }

  return 0;
}