Exemplo n.º 1
0
/* --------------------------------------------------------------- FUNCTION */
int AH_Job_SepaStandingOrdersGet__ReadSto(AH_JOB *j,
					  AB_IMEXPORTER_CONTEXT *ctx,
					  const uint8_t *ptr,
					  uint32_t len,
					  const char *fiId){
  int rv;
  AB_IMEXPORTER_CONTEXT *tmpCtx;
  GWEN_BUFFER *tbuf;
  AB_IMEXPORTER_ACCOUNTINFO *ai;

  tmpCtx=AB_ImExporterContext_new();
  tbuf=GWEN_Buffer_new(0, 256, 0, 1);
  GWEN_Buffer_AppendBytes(tbuf, (const char*) ptr, len);

  rv=AB_Banking_ImportBuffer(AH_Job_GetBankingApi(j),
			     tmpCtx,
			     "sepa",
			     "default",
			     tbuf);
  if (rv<0) {
    DBG_INFO(AQHBCI_LOGDOMAIN, "here (%d)", rv);
    GWEN_Buffer_free(tbuf);
    AB_ImExporterContext_free(tmpCtx);
    return rv;
  }
  GWEN_Buffer_free(tbuf);

  ai=AB_ImExporterContext_GetFirstAccountInfo(tmpCtx);
  if (ai) {
    AB_TRANSACTION *t;

    while( (t=AB_ImExporterAccountInfo_GetFirstTransaction(ai)) ) {
      AB_Transaction_List_Del(t);
      AB_Transaction_SetFiId(t, fiId);
      /* add to real im/exporter context */
      AB_ImExporterContext_AddTransaction(ctx, t);
    }
  }
  AB_ImExporterContext_free(tmpCtx);

  return 0;
}
Exemplo n.º 2
0
/* --------------------------------------------------------------- FUNCTION */
int AH_Job_GetTransactions__ReadTransactions(AH_JOB *j,
                                             AB_IMEXPORTER_ACCOUNTINFO *ai,
                                             const char *docType,
                                             int ty,
                                             const uint8_t *ptr,
                                             uint32_t len)
{
  AB_PROVIDER *pro;
  AB_IMEXPORTER_CONTEXT *tempContext;
  AB_IMEXPORTER_ACCOUNTINFO *tempAccountInfo;
  int rv;

  assert(j);
  pro=AH_Job_GetProvider(j);
  assert(pro);

  /* import data into a temporary context */
  tempContext=AB_ImExporterContext_new();

#if 0
  DBG_ERROR(0, "About to read this SWIFT data (%s)", docType);
  GWEN_Text_DumpString((const char *) ptr, len, 2);
#endif

  rv=AB_Banking_ImportFromBufferLoadProfile(AB_Provider_GetBanking(pro),
                                            "swift",
                                            tempContext,
                                            docType,
                                            NULL,
                                            ptr,
                                            len);
  if (rv<0) {
    DBG_INFO(AQHBCI_LOGDOMAIN, "here (%d)", rv);
    AB_ImExporterContext_free(tempContext);
    return rv;
  }

  /* copy data from temporary context to real context */
  tempAccountInfo=AB_ImExporterContext_GetFirstAccountInfo(tempContext);
  while (tempAccountInfo) {
    AB_TRANSACTION_LIST *tl;
    AB_BALANCE_LIST *bl;

    /* move transactions, set transaction type */
    tl=AB_ImExporterAccountInfo_GetTransactionList(tempAccountInfo);
    if (tl) {
      AB_TRANSACTION *t;

      while ((t=AB_Transaction_List_First(tl))) {
        AB_Transaction_List_Del(t);
        AB_Transaction_SetType(t, ty);
        AB_ImExporterAccountInfo_AddTransaction(ai, t);
      }
    }

    /* move balances */
    bl=AB_ImExporterAccountInfo_GetBalanceList(tempAccountInfo);
    if (bl) {
      AB_BALANCE *bal;

      while ((bal=AB_Balance_List_First(bl))) {
        AB_Balance_List_Del(bal);
        AB_ImExporterAccountInfo_AddBalance(ai, bal);
      }
    }

    tempAccountInfo=AB_ImExporterAccountInfo_List_Next(tempAccountInfo);
  }
  AB_ImExporterContext_free(tempContext);

  return 0;
}