int EBC_Provider_Execute(AB_PROVIDER *pro, AB_IMEXPORTER_CONTEXT *ctx) { EBC_PROVIDER *dp; int oks=0; int errors=0; AB_JOB_LIST2_ITERATOR *jit; int rv; assert(pro); dp=GWEN_INHERIT_GETDATA(AB_PROVIDER, EBC_PROVIDER, pro); assert(dp); rv=EBC_Provider_ExecQueue(pro, ctx); if (!rv) oks++; else { errors++; if (rv==GWEN_ERROR_USER_ABORTED) { EBC_Queue_Clear(dp->queue); AB_Job_List2_Clear(dp->bankingJobs); return rv; } } /* set results in referencing jobs, too */ jit=AB_Job_List2_First(dp->bankingJobs); if (jit) { AB_JOB *uj; uj=AB_Job_List2Iterator_Data(jit); assert(uj); while(uj) { if (AB_Job_GetStatus(uj)==AB_Job_StatusSent) { AB_JOB *rj; uint32_t rjid; rj=uj; /* find referenced job (if any) */ do { GWEN_DB_NODE *dbT; dbT=AB_Job_GetProviderData(rj, pro); assert(dbT); rjid=GWEN_DB_GetIntValue(dbT, "refJob", 0, 0); if (rjid) { rj=EBC_Provider_FindJobById(dp->bankingJobs, rjid); } } while(rjid && rj); if (rj && rj!=uj) { /* found referenced job, copy status and result text */ DBG_INFO(AQEBICS_LOGDOMAIN, "Copying status from referenced job"); AB_Job_SetStatus(uj, AB_Job_GetStatus(rj)); AB_Job_SetResultText(uj, AB_Job_GetResultText(rj)); } if (AB_Job_GetStatus(uj)==AB_Job_StatusSent) AB_Job_SetStatus(uj, AB_Job_StatusFinished); } uj=AB_Job_List2Iterator_Next(jit); } /* while */ AB_Job_List2Iterator_free(jit); } rv=AB_Banking_ExecutionProgress(AB_Provider_GetBanking(pro)); if (rv==GWEN_ERROR_USER_ABORTED) { DBG_INFO(AQEBICS_LOGDOMAIN, "User aborted"); return rv; } EBC_Queue_Clear(dp->queue); AB_Job_List2_Clear(dp->bankingJobs); if (!oks && errors) { DBG_INFO(AQEBICS_LOGDOMAIN, "Not a single job succeeded"); return GWEN_ERROR_GENERIC; } return 0; }
void gnc_ab_getbalance(GtkWidget *parent, Account *gnc_acc) { AB_BANKING *api; gboolean online = FALSE; AB_ACCOUNT *ab_acc; AB_JOB *job = NULL; AB_JOB_LIST2 *job_list = NULL; GncGWENGui *gui = NULL; AB_IMEXPORTER_CONTEXT *context = NULL; GncABImExContextImport *ieci = NULL; AB_JOB_STATUS job_status; g_return_if_fail(parent && gnc_acc); /* Get the API */ api = gnc_AB_BANKING_new(); if (!api) { g_warning("gnc_ab_gettrans: Couldn't get AqBanking API"); return; } if (AB_Banking_OnlineInit(api #ifdef AQBANKING_VERSION_4_EXACTLY , 0 #endif ) != 0) { g_warning("gnc_ab_gettrans: Couldn't initialize AqBanking API"); goto cleanup; } online = TRUE; /* Get the AqBanking Account */ ab_acc = gnc_ab_get_ab_account(api, gnc_acc); if (!ab_acc) { g_warning("gnc_ab_getbalance: No AqBanking account found"); gnc_error_dialog (GTK_WINDOW (parent), _("No valid online banking account assigned.")); goto cleanup; } /* Get a GetBalance job and enqueue it */ job = AB_JobGetBalance_new(ab_acc); if (!job || AB_Job_CheckAvailability(job #ifndef AQBANKING_VERSION_5_PLUS , 0 #endif )) { g_warning("gnc_ab_getbalance: JobGetBalance not available for this " "account"); gnc_error_dialog (GTK_WINDOW (parent), _("Online action \"Get Balance\" not available for this account.")); goto cleanup; } job_list = AB_Job_List2_new(); AB_Job_List2_PushBack(job_list, job); /* Get a GUI object */ gui = gnc_GWEN_Gui_get(parent); if (!gui) { g_warning("gnc_ab_getbalance: Couldn't initialize Gwenhywfar GUI"); goto cleanup; } /* Create a context to store the results */ context = AB_ImExporterContext_new(); /* Execute the job */ AB_Banking_ExecuteJobs(api, job_list, context #ifndef AQBANKING_VERSION_5_PLUS , 0 #endif ); /* Ignore the return value of AB_Banking_ExecuteJobs(), as the job's * status always describes better whether the job was actually * transferred to and accepted by the bank. See also * http://lists.gnucash.org/pipermail/gnucash-de/2008-September/006389.html */ job_status = AB_Job_GetStatus(job); if (job_status != AB_Job_StatusFinished && job_status != AB_Job_StatusPending) { g_warning("gnc_ab_getbalance: Error on executing job"); gnc_error_dialog (GTK_WINDOW (parent), _("Error on executing job.\n\nStatus: %s - %s"), AB_Job_Status2Char(job_status), AB_Job_GetResultText(job)); goto cleanup; } /* Import the results */ ieci = gnc_ab_import_context(context, AWAIT_BALANCES, FALSE, NULL, parent); cleanup: if (ieci) g_free(ieci); if (context) AB_ImExporterContext_free(context); if (gui) gnc_GWEN_Gui_release(gui); if (job_list) AB_Job_List2_free(job_list); if (job) AB_Job_free(job); if (online) #ifdef AQBANKING_VERSION_4_EXACTLY AB_Banking_OnlineFini(api, 0); #else AB_Banking_OnlineFini(api); #endif gnc_AB_BANKING_fini(api); }
void gnc_ab_gettrans(GtkWidget *parent, Account *gnc_acc) { AB_BANKING *api; gboolean online = FALSE; AB_ACCOUNT *ab_acc; GWEN_TIME *from_date = NULL, *to_date = NULL; Timespec until_timespec; AB_JOB *job = NULL; AB_JOB_LIST2 *job_list = NULL; GncGWENGui *gui = NULL; AB_IMEXPORTER_CONTEXT *context = NULL; GncABImExContextImport *ieci = NULL; AB_JOB_STATUS job_status; g_return_if_fail(parent && gnc_acc); /* Get the API */ api = gnc_AB_BANKING_new(); if (!api) { g_warning("gnc_ab_gettrans: Couldn't get AqBanking API"); return; } if (AB_Banking_OnlineInit(api #ifdef AQBANKING_VERSION_4_EXACTLY , 0 #endif ) != 0) { g_warning("gnc_ab_gettrans: Couldn't initialize AqBanking API"); goto cleanup; } online = TRUE; /* Get the AqBanking Account */ ab_acc = gnc_ab_get_ab_account(api, gnc_acc); if (!ab_acc) { g_warning("gnc_ab_gettrans: No AqBanking account found"); gnc_error_dialog(parent, _("No valid online banking account assigned.")); goto cleanup; } /* Get the start and end dates for the GetTransactions job. */ if (!gettrans_dates(parent, gnc_acc, &from_date, &to_date)) { g_debug("gnc_ab_gettrans: gettrans_dates aborted"); goto cleanup; } /* Use this as a local storage for the until_time below. */ timespecFromTime_t(&until_timespec, GWEN_Time_toTime_t(to_date)); /* Get a GetTransactions job and enqueue it */ job = AB_JobGetTransactions_new(ab_acc); if (!job || AB_Job_CheckAvailability(job #ifndef AQBANKING_VERSION_5_PLUS , 0 #endif )) { g_warning("gnc_ab_gettrans: JobGetTransactions not available for this " "account"); gnc_error_dialog(parent, _("Online action \"Get Transactions\" not available for this account.")); goto cleanup; } AB_JobGetTransactions_SetFromTime(job, from_date); AB_JobGetTransactions_SetToTime(job, to_date); job_list = AB_Job_List2_new(); AB_Job_List2_PushBack(job_list, job); /* Get a GUI object */ gui = gnc_GWEN_Gui_get(parent); if (!gui) { g_warning("gnc_ab_gettrans: Couldn't initialize Gwenhywfar GUI"); goto cleanup; } /* Create a context to store the results */ context = AB_ImExporterContext_new(); /* Execute the job */ AB_Banking_ExecuteJobs(api, job_list, context #ifndef AQBANKING_VERSION_5_PLUS , 0 #endif ); /* Ignore the return value of AB_Banking_ExecuteJobs(), as the job's * status always describes better whether the job was actually * transferred to and accepted by the bank. See also * http://lists.gnucash.org/pipermail/gnucash-de/2008-September/006389.html */ job_status = AB_Job_GetStatus(job); if (job_status != AB_Job_StatusFinished && job_status != AB_Job_StatusPending) { g_warning("gnc_ab_gettrans: Error on executing job"); gnc_error_dialog(parent, _("Error on executing job.\n\nStatus: %s - %s") , AB_Job_Status2Char(job_status) , AB_Job_GetResultText(job)); goto cleanup; } /* Import the results */ ieci = gnc_ab_import_context(context, AWAIT_TRANSACTIONS, FALSE, NULL, parent); if (!(gnc_ab_ieci_get_found(ieci) & FOUND_TRANSACTIONS)) { /* No transaction found */ GtkWidget *dialog = gtk_message_dialog_new( GTK_WINDOW(parent), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "%s", _("The Online Banking import returned no transactions " "for the selected time period.")); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); } /* Store the date of this retrieval */ gnc_ab_set_account_trans_retrieval(gnc_acc, until_timespec); cleanup: if (ieci) g_free(ieci); if (context) AB_ImExporterContext_free(context); if (gui) gnc_GWEN_Gui_release(gui); if (job_list) AB_Job_List2_free(job_list); if (job) AB_Job_free(job); if (to_date) GWEN_Time_free(to_date); if (from_date) GWEN_Time_free(from_date); if (online) #ifdef AQBANKING_VERSION_4_EXACTLY AB_Banking_OnlineFini(api, 0); #else AB_Banking_OnlineFini(api); #endif gnc_AB_BANKING_fini(api); }
/** Return the HBCI return code of the given 'job', or zero if none was * found. If 'verbose' is TRUE, make a lot of debugging messages about * this outboxjob. */ static int gnc_hbci_debug_outboxjob (GNCInteractor *inter, AB_JOB *job, gboolean verbose) { int cause = 0; AB_JOB_STATUS jobstatus; g_assert (job); if (verbose) { g_warning("gnc_hbci_debug_outboxjob: Job status: %s", AB_Job_Status2Char(AB_Job_GetStatus(job))); g_warning(", result: %s", AB_Job_GetResultText(job) ? AB_Job_GetResultText(job) : "(none)"); g_warning("\n"); } jobstatus = AB_Job_GetStatus (job); if (jobstatus == AB_Job_StatusError) { if (AB_Job_GetResultText (job)) { /* Add the "result text" to the log window */ char *logstring = g_strdup_printf("Job %s had an error: %s\n", AB_Job_Type2Char(AB_Job_GetType(job)), AB_Job_GetResultText(job)); GNCInteractor_add_log_text (inter, logstring); g_free (logstring); } if (!verbose) g_warning("gnc_hbci_debug_outboxjob: Job %s had an error: %s\n", AB_Job_Type2Char(AB_Job_GetType(job)), AB_Job_GetResultText(job) ? AB_Job_GetResultText(job) : "(none)"); cause = 9000; } else { cause = 0; } #if 0 /* hbci debugging code; might be adapted to aqbanking at a later point in time */ list = AB_JOB_resultCodes (job); if (list_int_size (list) > 0) { cause = get_resultcode_error (list); if (verbose) { g_warning("OutboxJob resultcodes: "); print_list_int (list); switch (cause) { case 9310: msg = "Schluessel noch nicht hinterlegt"; break; case 9320: msg = "Schluessel noch nicht freigeschaltet"; break; case 9330: msg = "Schluessel gesperrt"; break; case 9340: msg = "Schluessel falsch"; break; default: msg = "Unknown"; } g_warning("Probable cause of error was: code %d, msg: %s\n", cause, msg); } } else { if (verbose) g_warning("OutboxJob's resultCodes list has zero length.\n"); } list_int_delete (list); #endif return cause; }