Ejemplo n.º 1
0
static
void _dumpBal(const AB_BALANCE *bal,
	      const GWEN_TIME *ti,
	      FILE *fd) {
  if (bal) {
    const GWEN_TIME *bti;
    const AB_VALUE *val;
  
    bti=AB_Balance_GetTime(bal);
    if (bti==0)
      bti=ti;
    if (bti) {
      GWEN_BUFFER *tbuf;

      tbuf=GWEN_Buffer_new(0, 24, 0, 1);
      GWEN_Time_toString(bti, "DD.MM.YYYY\thh:mm", tbuf);
      fprintf(fd, "%s\t", GWEN_Buffer_GetStart(tbuf));
      GWEN_Buffer_free(tbuf);
    }
    else {
      fprintf(fd, "\t\t");
    }
  
    val=AB_Balance_GetValue(bal);
    if (val) {
      AB_VALUE *vNew;
      GWEN_BUFFER *vbuf;
      const char *cur;

      vNew=AB_Value_dup(val);
      AB_Value_SetCurrency(vNew, NULL);
      vbuf=GWEN_Buffer_new(0, 32, 0, 1);
      AB_Value_toHumanReadableString(vNew, vbuf, 2);
      fprintf(fd, "%s\t", GWEN_Buffer_GetStart(vbuf));
      GWEN_Buffer_free(vbuf);
      AB_Value_free(vNew);

      cur=AB_Value_GetCurrency(val);
      if (cur)
	fprintf(fd, "%s\t", cur);
      else
	fprintf(fd, "\t");
    }
    else {
      fprintf(fd, "\t\t");
    }
  }
  else {
    fprintf(fd, "\t\t\t\t");
  }
}
Ejemplo n.º 2
0
void AB_Value_Dump(const AB_VALUE *v, FILE *f, unsigned int indent) {
  unsigned int i;

  for (i=0; i<indent; i++)
    fprintf(f, " ");
  fprintf(f, "Value: ");
  if (v) {
    GWEN_BUFFER *nbuf;

    nbuf=GWEN_Buffer_new(0, 128, 0, 1);
    AB_Value_toHumanReadableString(v, nbuf, 2);
    gmp_fprintf(f, "%Qi (%s)\n", v->value, GWEN_Buffer_GetStart(nbuf));
    GWEN_Buffer_free(nbuf);
  }
  else
    fprintf(f, "[none]\n");
}
Ejemplo n.º 3
0
int EBC_Provider_ExecContext__IZV(AB_PROVIDER *pro,
				  AB_IMEXPORTER_CONTEXT *ctx,
				  AB_USER *u,
				  AB_ACCOUNT *a,
				  GWEN_HTTP_SESSION *sess,
				  EBC_CONTEXT *ectx){
  EBC_PROVIDER *dp;
  AB_JOB_LIST2_ITERATOR *jit;
  AB_JOB_STATUS js;
  AB_IMEXPORTER_CONTEXT *exCtx;
  AB_IMEXPORTER_ACCOUNTINFO *ai;
  GWEN_BUFFER *bufDtaus;
  GWEN_TIME *currentTime;
  GWEN_BUFFER *logbuf;
  int rv;
  const char *profileName=NULL;
  const char *s;
  const char *rqType;
  uint32_t groupId=0;

  assert(pro);
  dp=GWEN_INHERIT_GETDATA(AB_PROVIDER, EBC_PROVIDER, pro);
  assert(dp);

  /* prepare CTX log */
  logbuf=GWEN_Buffer_new(0, 256, 0, 1);
  GWEN_Buffer_AppendString(logbuf, "BEGIN");
  currentTime=GWEN_CurrentTime();
  GWEN_Time_toString(currentTime, I18N("YYYY/MM/DD-hh:mm:ss"), logbuf);
  GWEN_Time_free(currentTime);
  GWEN_Buffer_AppendString(logbuf, "\t");
  GWEN_Buffer_AppendString(logbuf, I18N("National Mass Transfer"));
  GWEN_Buffer_AppendString(logbuf, "\n");
  GWEN_Buffer_AppendString(logbuf, "\t");
  GWEN_Buffer_AppendString(logbuf, I18N("Transfer type: "));
  GWEN_Buffer_AppendString(logbuf, "\t");

  switch(EBC_Context_GetJobType(ectx)) {
  case AB_Job_TypeTransfer:
    if (!profileName)
      profileName="transfer";
    GWEN_Buffer_AppendString(logbuf, I18N("Transfer"));
    break;
  case AB_Job_TypeDebitNote:
    if (!profileName)
      profileName="debitnote";
    GWEN_Buffer_AppendString(logbuf, I18N("Debit Note"));
    break;
  default:
    GWEN_Buffer_AppendString(logbuf, I18N("unknown"));
    break;
  }
  GWEN_Buffer_AppendString(logbuf, "\n");

  GWEN_Buffer_AppendString(logbuf, "\t");
  GWEN_Buffer_AppendString(logbuf, I18N("Account: "));
  GWEN_Buffer_AppendString(logbuf, "\t");
  GWEN_Buffer_AppendString(logbuf, AB_Account_GetBankCode(a));
  GWEN_Buffer_AppendString(logbuf, " / ");
  GWEN_Buffer_AppendString(logbuf, AB_Account_GetAccountNumber(a));
  GWEN_Buffer_AppendString(logbuf, "\n");
  /* add a tab-less line to start a new table */
  GWEN_Buffer_AppendString(logbuf, "Transactions\n");

  DBG_INFO(AQEBICS_LOGDOMAIN, "Sampling transactions from jobs");
  exCtx=AB_ImExporterContext_new();
  ai=AB_ImExporterAccountInfo_new();
  AB_ImExporterAccountInfo_FillFromAccount(ai, a);

  jit=AB_Job_List2_First(EBC_Context_GetJobs(ectx));
  if (jit) {
    AB_JOB *uj;

    uj=AB_Job_List2Iterator_Data(jit);
    assert(uj);
    while(uj) {
      AB_TRANSACTION *t;
      const GWEN_STRINGLIST *sl;
      const char *s;
      const AB_VALUE *v;

      switch(EBC_Context_GetJobType(ectx)) {
      case AB_Job_TypeTransfer:
      case AB_Job_TypeDebitNote:
	t=AB_Job_GetTransaction(uj);
        break;
      default:
        t=NULL;
      }
      assert(t);

      if (groupId==0)
	/* take id from first job of the created DTAUS doc */
	groupId=AB_Job_GetJobId(uj);
      AB_Transaction_SetGroupId(t, groupId);

      AB_ImExporterAccountInfo_AddTransaction(ai, AB_Transaction_dup(t));
      sl=AB_Transaction_GetRemoteName(t);
      s=NULL;
      if (sl)
	s=GWEN_StringList_FirstString(sl);
      if (!s)
	s=I18N("unknown");
      GWEN_Buffer_AppendString(logbuf, s);
      GWEN_Buffer_AppendString(logbuf, "\t");
      s=AB_Transaction_GetRemoteBankCode(t);
      if (!s)
	s="????????";
      GWEN_Buffer_AppendString(logbuf, s);
      GWEN_Buffer_AppendString(logbuf, "\t");
      s=AB_Transaction_GetRemoteAccountNumber(t);
      if (!s)
	s="??????????";
      GWEN_Buffer_AppendString(logbuf, s);
      GWEN_Buffer_AppendString(logbuf, "\t");
      sl=AB_Transaction_GetPurpose(t);
      s=NULL;
      if (sl)
	s=GWEN_StringList_FirstString(sl);
      if (!s)
	s="";
      GWEN_Buffer_AppendString(logbuf, s);
      GWEN_Buffer_AppendString(logbuf, "\t");
      v=AB_Transaction_GetValue(t);
      if (v)
	AB_Value_toHumanReadableString(v, logbuf, 2);
      else
	GWEN_Buffer_AppendString(logbuf, "0,00 EUR");
      GWEN_Buffer_AppendString(logbuf, "\n");

      uj=AB_Job_List2Iterator_Next(jit);
    } /* while */
    AB_Job_List2Iterator_free(jit);
  }
  AB_ImExporterContext_AddAccountInfo(exCtx, ai);

  GWEN_Buffer_AppendString(logbuf, I18N("Results:\n"));

  /* export as DTAUS to bufDtaus */
  bufDtaus=GWEN_Buffer_new(0, 1024, 0, 1);

  DBG_INFO(AQEBICS_LOGDOMAIN, "Exporting transactions to DTAUS[default]");
  rv=AB_Banking_ExportToBuffer(AB_Provider_GetBanking(pro),
			       exCtx,
			       "dtaus",
			       profileName,
			       bufDtaus);
  if (rv<0) {
    DBG_INFO(AQEBICS_LOGDOMAIN, "here (%d)", rv);
    GWEN_Buffer_free(bufDtaus);
    EBC_Provider_SetJobListStatus(EBC_Context_GetJobs(ectx),
				  AB_Job_StatusError);
    GWEN_Buffer_AppendString(logbuf, "\t");
    GWEN_Buffer_AppendString(logbuf, I18N("Error while exporting to DTAUS\n"));
    GWEN_Buffer_AppendString(logbuf, "END\n");

    AB_ImExporterContext_AddLog(ctx, GWEN_Buffer_GetStart(logbuf));
    GWEN_Buffer_free(logbuf);
    return rv;
  }

  GWEN_Buffer_AppendString(logbuf, "\t");
  GWEN_Buffer_AppendString(logbuf, I18N("Exporting to DTAUS: ok\n"));

  /* exchange upload request */
  DBG_INFO(AQEBICS_LOGDOMAIN, "Uploading.");
  AB_HttpSession_ClearLog(sess);

  if (EBC_Context_GetJobType(ectx)==AB_Job_TypeDebitNote) {
    if (EBC_User_GetFlags(u) & EBC_USER_FLAGS_USE_IZL)
      rqType="IZL";
    else
      rqType="IZV";
  }
  else
    rqType="IZV";
  rv=EBC_Provider_XchgUploadRequest(pro, sess, u, rqType,
				    (const uint8_t*)GWEN_Buffer_GetStart(bufDtaus),
				    GWEN_Buffer_GetUsedBytes(bufDtaus));
  if (rv<0 || rv>=300)
    js=AB_Job_StatusError;
  else
    js=AB_Job_StatusFinished;

  s=AB_HttpSession_GetLog(sess);
  if (s)
    GWEN_Buffer_AppendString(logbuf, s);
  GWEN_Buffer_AppendString(logbuf, "END\n");

  AB_ImExporterContext_AddLog(ctx, GWEN_Buffer_GetStart(logbuf));
  GWEN_Buffer_free(logbuf);

  EBC_Provider_SetJobListStatus(EBC_Context_GetJobs(ectx), js);

  DBG_INFO(AQEBICS_LOGDOMAIN, "Done");
  return 0;
}
Ejemplo n.º 4
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;
}