int AB_ImExporterYN_Import(AB_IMEXPORTER *ie, AB_IMEXPORTER_CONTEXT *ctx, GWEN_SYNCIO *sio, GWEN_DB_NODE *params){ AB_IMEXPORTER_YELLOWNET *ieh; //GWEN_DB_NODE *dbSubParams; GWEN_XMLNODE *doc; GWEN_XMLNODE *node; int rv; GWEN_XML_CONTEXT *ctxml; assert(ie); ieh=GWEN_INHERIT_GETDATA(AB_IMEXPORTER, AB_IMEXPORTER_YELLOWNET, ie); assert(ieh); // dbSubParams=GWEN_DB_GetGroup(params, GWEN_PATH_FLAGS_NAMEMUSTEXIST, // "params"); doc=GWEN_XMLNode_new(GWEN_XMLNodeTypeTag, "root"); ctxml=GWEN_XmlCtxStore_new(doc, GWEN_XML_FLAGS_HANDLE_HEADERS); rv=GWEN_XMLContext_ReadFromIo(ctxml, sio); GWEN_XmlCtx_free(ctxml); if (rv) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Could not parse XML stream (%d)", rv); GWEN_XMLNode_free(doc); return GWEN_ERROR_BAD_DATA; } node=GWEN_XMLNode_FindFirstTag(doc, "IC", 0, 0); if (node==NULL) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Document does not contain element \"IC\""); GWEN_XMLNode_Dump(doc, 2); GWEN_XMLNode_free(doc); return GWEN_ERROR_BAD_DATA; } node=GWEN_XMLNode_FindFirstTag(node, "KONAUS", 0, 0); while(node) { AB_IMEXPORTER_ACCOUNTINFO *ai; ai=AB_ImExporterYN__ReadAccountInfo(ie, ctx, node); assert(ai); rv=AB_ImExporterYN__ReadAccountStatus(ie, ai, node); if (rv==0) rv=AB_ImExporterYN__ReadTransactions(ie, ai, node); if (rv) { AB_ImExporterAccountInfo_free(ai); GWEN_XMLNode_free(doc); return rv; } AB_ImExporterContext_AddAccountInfo(ctx, ai); node=GWEN_XMLNode_FindNextTag(node, "KONAUS", 0, 0); } GWEN_XMLNode_free(doc); return 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; }
int AH_ImExporterOFX_AccountCallback_cb(const struct OfxAccountData data, void *user_data) { AH_IMEXPORTER_OFX *ieh; AB_IMEXPORTER_ACCOUNTINFO *ai; DBG_INFO(AQBANKING_LOGDOMAIN, "Account callback"); ieh=(AH_IMEXPORTER_OFX *)user_data; ai=AB_ImExporterAccountInfo_new(); #ifdef HAVE_OFX_WITH_CONNECT if (data.account_number_valid) { AB_ImExporterAccountInfo_SetAccountNumber(ai, data.account_number); if (*(data.account_name)) AB_ImExporterAccountInfo_SetAccountName(ai, data.account_name); } else if (data.account_id_valid) AB_ImExporterAccountInfo_SetAccountNumber(ai, data.account_id); else AB_ImExporterAccountInfo_SetAccountNumber(ai, "----"); if (data.bank_id_valid) AB_ImExporterAccountInfo_SetBankCode(ai, data.bank_id); #else if (data.account_id_valid) { AB_ImExporterAccountInfo_SetAccountNumber(ai, data.account_id); if (*(data.account_name)) AB_ImExporterAccountInfo_SetAccountName(ai, data.account_name); } else { AB_ImExporterAccountInfo_SetAccountNumber(ai, "----"); } #endif if (data.account_type_valid) { AB_ACCOUNT_TYPE at; switch (data.account_type) { case OFX_CHECKING: at=AB_AccountType_Checking; break; case OFX_SAVINGS: at=AB_AccountType_Savings; break; case OFX_MONEYMRKT: at=AB_AccountType_Investment; break; case OFX_CREDITLINE: at=AB_AccountType_Bank; break; case OFX_CMA: at=AB_AccountType_Cash; break; case OFX_CREDITCARD: at=AB_AccountType_CreditCard; break; case OFX_INVESTMENT: at=AB_AccountType_Investment; break; default: at=AB_AccountType_Bank; break; } AB_ImExporterAccountInfo_SetType(ai, at); } else { AB_ImExporterAccountInfo_SetType(ai, AB_AccountType_Bank); } AB_ImExporterContext_AddAccountInfo(ieh->context, ai); ieh->lastAccountInfo=ai; return 0; }
static int listTrans(AB_BANKING *ab, GWEN_DB_NODE *dbArgs, int argc, char **argv) { GWEN_DB_NODE *db; int rv; const char *ctxFile; const char *outFile; const char *exporterName; const char *profileName; const char *profileFile; AB_IMEXPORTER_CONTEXT *ctx=0; AB_IMEXPORTER_CONTEXT *nctx=0; AB_IMEXPORTER_ACCOUNTINFO *iea=0; const char *bankId; const char *accountId; const char *bankName; const char *accountName; const GWEN_ARGS args[]={ { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "bankId", /* name */ 0, /* minnum */ 1, /* maxnum */ "b", /* short option */ "bank", /* long option */ "Specify the bank code", /* short description */ "Specify the bank code" /* long description */ }, { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "accountId", /* name */ 0, /* minnum */ 1, /* maxnum */ "a", /* short option */ "account", /* long option */ "Specify the account number", /* short description */ "Specify the account number" /* long description */ }, { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "bankName", /* name */ 0, /* minnum */ 1, /* maxnum */ "N", /* short option */ "bankname", /* long option */ "Specify the bank name", /* short description */ "Specify the bank name" /* long description */ }, { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "accountName", /* name */ 0, /* minnum */ 1, /* maxnum */ "n", /* short option */ "accountname", /* long option */ "Specify the account name", /* short description */ "Specify the account name" /* long description */ }, { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "ctxFile", /* name */ 0, /* minnum */ 1, /* maxnum */ "c", /* short option */ "ctxfile", /* long option */ "Specify the file to store the context in", /* short description */ "Specify the file to store the context in" /* long description */ }, { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "outFile", /* name */ 0, /* minnum */ 1, /* maxnum */ "o", /* short option */ "outfile", /* long option */ "Specify the file to store the data in", /* short description */ "Specify the file to store the data in" /* long description */ }, { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "exporterName", /* name */ 0, /* minnum */ 1, /* maxnum */ 0, /* short option */ "exporter", /* long option */ "Specify the exporter to use", /* short description */ "Specify the exporter to use" /* long description */ }, { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "profileName", /* name */ 0, /* minnum */ 1, /* maxnum */ 0, /* short option */ "profile", /* long option */ "Specify the export profile to use", /* short description */ "Specify the export profile to use" /* long description */ }, { GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */ GWEN_ArgsType_Char, /* type */ "profileFile", /* name */ 0, /* minnum */ 1, /* maxnum */ 0, /* short option */ "profile-file", /* long option */ "Specify the file to load the export profile from",/* short description */ "Specify the file to load the export profile from" /* long description */ }, { GWEN_ARGS_FLAGS_HELP | GWEN_ARGS_FLAGS_LAST, /* flags */ GWEN_ArgsType_Int, /* type */ "help", /* name */ 0, /* minnum */ 0, /* maxnum */ "h", /* short option */ "help", /* long option */ "Show this help screen", /* short description */ "Show this help screen" /* long description */ } }; db=GWEN_DB_GetGroup(dbArgs, GWEN_DB_FLAGS_DEFAULT, "local"); rv=GWEN_Args_Check(argc, argv, 1, 0 /*GWEN_ARGS_MODE_ALLOW_FREEPARAM*/, args, db); if (rv==GWEN_ARGS_RESULT_ERROR) { fprintf(stderr, "ERROR: Could not parse arguments\n"); return 1; } else if (rv==GWEN_ARGS_RESULT_HELP) { GWEN_BUFFER *ubuf; ubuf=GWEN_Buffer_new(0, 1024, 0, 1); if (GWEN_Args_Usage(args, ubuf, GWEN_ArgsOutType_Txt)) { fprintf(stderr, "ERROR: Could not create help string\n"); return 1; } fprintf(stderr, "%s\n", GWEN_Buffer_GetStart(ubuf)); GWEN_Buffer_free(ubuf); return 0; } exporterName=GWEN_DB_GetCharValue(db, "exporterName", 0, "csv"); profileName=GWEN_DB_GetCharValue(db, "profileName", 0, "default"); profileFile=GWEN_DB_GetCharValue(db, "profileFile", 0, NULL); bankId=GWEN_DB_GetCharValue(db, "bankId", 0, 0); bankName=GWEN_DB_GetCharValue(db, "bankName", 0, 0); accountId=GWEN_DB_GetCharValue(db, "accountId", 0, 0); accountName=GWEN_DB_GetCharValue(db, "accountName", 0, 0); outFile=GWEN_DB_GetCharValue(db, "outFile", 0, 0); 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; } nctx=AB_ImExporterContext_new(); iea=AB_ImExporterContext_GetFirstAccountInfo(ctx); while(iea) { int matches=1; const char *s; if (matches && bankId) { s=AB_ImExporterAccountInfo_GetBankCode(iea); if (!s || !*s || -1==GWEN_Text_ComparePattern(s, bankId, 0)) matches=0; } if (matches && bankName) { s=AB_ImExporterAccountInfo_GetBankName(iea); if (!s || !*s || -1==GWEN_Text_ComparePattern(s, bankName, 0)) matches=0; } if (matches && accountId) { s=AB_ImExporterAccountInfo_GetAccountNumber(iea); if (!s || !*s || -1==GWEN_Text_ComparePattern(s, accountId, 0)) matches=0; } if (matches && accountName) { s=AB_ImExporterAccountInfo_GetAccountName(iea); if (!s || !*s || -1==GWEN_Text_ComparePattern(s, accountName, 0)) matches=0; } if (matches) { AB_IMEXPORTER_ACCOUNTINFO *nai; nai=AB_ImExporterAccountInfo_dup(iea); AB_ImExporterContext_AddAccountInfo(nctx, nai); } /* if matches */ iea=AB_ImExporterContext_GetNextAccountInfo(ctx); } /* while */ AB_ImExporterContext_free(ctx); /* export new context */ rv=AB_Banking_ExportToFileWithProfile(ab, exporterName, nctx, profileName, profileFile, outFile); if (rv<0) { DBG_ERROR(0, "Error exporting (%d).", rv); AB_ImExporterContext_free(nctx); return 4; } AB_ImExporterContext_free(nctx); rv=AB_Banking_Fini(ab); if (rv) { fprintf(stderr, "ERROR: Error on deinit (%d)\n", rv); return 5; } return 0; }