AB_PROVIDER *EBC_Provider_new(AB_BANKING *ab){ AB_PROVIDER *pro; EBC_PROVIDER *dp; pro=AB_Provider_new(ab, "aqebics"); GWEN_NEW_OBJECT(EBC_PROVIDER, dp); GWEN_INHERIT_SETDATA(AB_PROVIDER, EBC_PROVIDER, pro, dp, EBC_Provider_FreeData); dp->bankingJobs=AB_Job_List2_new(); dp->queue=EBC_Queue_new(); AB_Provider_SetInitFn(pro, EBC_Provider_Init); AB_Provider_SetFiniFn(pro, EBC_Provider_Fini); AB_Provider_SetUpdateJobFn(pro, EBC_Provider_UpdateJob); AB_Provider_SetAddJobFn(pro, EBC_Provider_AddJob); AB_Provider_SetExecuteFn(pro, EBC_Provider_Execute); AB_Provider_SetResetQueueFn(pro, EBC_Provider_ResetQueue); AB_Provider_SetExtendUserFn(pro, EBC_Provider_ExtendUser); AB_Provider_SetExtendAccountFn(pro, EBC_Provider_ExtendAccount); AB_Provider_SetGetEditUserDialogFn(pro, EBC_Provider_GetEditUserDialog); AB_Provider_AddFlags(pro, AB_PROVIDER_FLAGS_HAS_EDITUSER_DIALOG); AB_Provider_SetGetNewUserDialogFn(pro, EBC_Provider_GetNewUserDialog); AB_Provider_AddFlags(pro, AB_PROVIDER_FLAGS_HAS_NEWUSER_DIALOG); return pro; }
AB_JOBQUEUE *AB_JobQueue_new(void) { AB_JOBQUEUE *p_struct; GWEN_NEW_OBJECT(AB_JOBQUEUE, p_struct) p_struct->_refCount=1; GWEN_INHERIT_INIT(AB_JOBQUEUE, p_struct) GWEN_LIST_INIT(AB_JOBQUEUE, p_struct) /* members */ p_struct->jobList=AB_Job_List2_new(); p_struct->jobType=AB_Job_TypeUnknown; /* virtual functions */ return p_struct; }
GncABImExContextImport * gnc_ab_import_context(AB_IMEXPORTER_CONTEXT *context, guint awaiting, gboolean execute_txns, AB_BANKING *api, GtkWidget *parent) { GncABImExContextImport *data = g_new(GncABImExContextImport, 1); g_return_val_if_fail(context, NULL); /* Do not await and ignore at the same time */ g_return_val_if_fail(!(awaiting & AWAIT_BALANCES) || !(awaiting & IGNORE_BALANCES), NULL); g_return_val_if_fail(!(awaiting & AWAIT_TRANSACTIONS) || !(awaiting & IGNORE_TRANSACTIONS), NULL); /* execute_txns must be FALSE if txns are not awaited */ g_return_val_if_fail(awaiting & AWAIT_TRANSACTIONS || !execute_txns, NULL); /* An api is needed for the jobs */ g_return_val_if_fail(!execute_txns || api, NULL); data->awaiting = awaiting; data->txn_found = FALSE; data->execute_txns = execute_txns; data->api = api; data->parent = parent; data->job_list = AB_Job_List2_new(); data->tmp_job_list = NULL; data->generic_importer = NULL; g_datalist_init(&data->tmp_job_list); /* Import transactions */ if (!(awaiting & IGNORE_TRANSACTIONS)) AB_ImExporterContext_AccountInfoForEach(context, txn_accountinfo_cb, data); /* Check balances */ if (!(awaiting & IGNORE_BALANCES)) AB_ImExporterContext_AccountInfoForEach(context, bal_accountinfo_cb, data); return data; }
static PyObject *aqbanking_Account_transactions(aqbanking_Account* self, PyObject *args, PyObject *kwds) { int rv; double tmpDateTime = 0; const char *bank_code; const char *account_no; #if PY_VERSION_HEX >= 0x03030000 bank_code = PyUnicode_AsUTF8(self->bank_code); account_no = PyUnicode_AsUTF8(self->no); #else PyObject *s = _PyUnicode_AsDefaultEncodedString(self->bank_code, NULL); bank_code = PyBytes_AS_STRING(s); s = _PyUnicode_AsDefaultEncodedString(self->no, NULL); account_no = PyBytes_AS_STRING(s); #endif GWEN_TIME *gwTime; const char *dateFrom=NULL, *dateTo=NULL; static char *kwlist[] = {"dateFrom", "dateTo", NULL}; if (! PyArg_ParseTupleAndKeywords(args, kwds, "|ss", kwlist, &dateFrom, &dateTo)) { return NULL; } AB_ACCOUNT *a; AB_JOB *job = 0; AB_JOB_LIST2 *jl = 0; AB_IMEXPORTER_CONTEXT *ctx = 0; AB_IMEXPORTER_ACCOUNTINFO *ai; /*aqbanking_Transaction *trans = NULL;*/ PyObject *transList = PyList_New(0); // Valid data set? if (self->no == NULL) { PyErr_SetString(PyExc_AttributeError, "no"); } if (self->bank_code == NULL) { PyErr_SetString(PyExc_AttributeError, "bank_code"); } // Initialize aqbanking. rv = AB_create(self); if (rv > 0) { Py_DECREF(transList); return NULL; } // Let us find the account! a = AB_Banking_GetAccountByCodeAndNumber(self->ab, bank_code, account_no); if (!a) { PyErr_SetString(AccountNotFound, "Could not find the given account! "); Py_DECREF(transList); return NULL; } // Create job and execute it. job = AB_JobGetTransactions_new(a); if (dateFrom != NULL) { gwTime = GWEN_Time_fromString(dateFrom, "YYYYMMDD"); AB_JobGetTransactions_SetFromTime(job, gwTime); } if (dateTo != NULL) { gwTime = GWEN_Time_fromString(dateTo, "YYYYMMDD"); AB_JobGetTransactions_SetToTime(job, gwTime); } // Check for availability rv = AB_Job_CheckAvailability(job); if (rv) { PyErr_SetString(ExecutionFailed, "Transaction retrieval is not supported!"); Py_DECREF(transList); return NULL; } jl = AB_Job_List2_new(); AB_Job_List2_PushBack(jl, job); ctx = AB_ImExporterContext_new(); rv = AB_Banking_ExecuteJobs(self->ab, jl, ctx); if (rv) { PyErr_SetString(ExecutionFailed, "Could not retrieve transactions!"); Py_DECREF(transList); return NULL; } // With success. No process the result. ai = AB_ImExporterContext_GetFirstAccountInfo (ctx); while(ai) { const AB_TRANSACTION *t; t = AB_ImExporterAccountInfo_GetFirstTransaction(ai); while(t) { const AB_VALUE *v; AB_TRANSACTION_STATUS state; v=AB_Transaction_GetValue(t); if (v) { const GWEN_STRINGLIST *sl; const GWEN_TIME *tdtime; const char *purpose; const char *remoteName; aqbanking_Transaction *trans = (aqbanking_Transaction*) PyObject_CallObject((PyObject *) &aqbanking_TransactionType, NULL); /* The purpose (memo field) might contain multiple lines. * Therefore AqBanking stores the purpose in a string list * of which the first entry is used in this tutorial */ sl = AB_Transaction_GetPurpose(t); if (sl) { purpose = GWEN_StringList_FirstString(sl); if (purpose == NULL) { purpose = ""; } } else { purpose = ""; } #ifdef DEBUGSTDERR fprintf(stderr, "[%-10d]: [%-10s/%-10s][%-10s/%-10s] %-32s (%.2f %s)\n", AB_Transaction_GetUniqueId(t), AB_Transaction_GetRemoteIban(t), AB_Transaction_GetRemoteBic(t), AB_Transaction_GetRemoteAccountNumber(t), AB_Transaction_GetRemoteBankCode(t), purpose, AB_Value_GetValueAsDouble(v), AB_Value_GetCurrency(v) ); #endif tdtime = AB_Transaction_GetDate(t); tmpDateTime = PyLong_AsDouble(PyLong_FromSize_t(GWEN_Time_Seconds(tdtime))); trans->date = PyDate_FromTimestamp(Py_BuildValue("(O)", PyFloat_FromDouble(tmpDateTime))); tdtime = AB_Transaction_GetValutaDate(t); tmpDateTime = PyLong_AsDouble(PyLong_FromSize_t(GWEN_Time_Seconds(tdtime))); trans->valutaDate = PyDate_FromTimestamp(Py_BuildValue("(O)", PyFloat_FromDouble(tmpDateTime))); trans->purpose = PyUnicode_FromString(purpose); // Local user if (AB_Transaction_GetLocalAccountNumber(t) == NULL) { trans->localAccount = Py_None; Py_INCREF(Py_None); } else { trans->localAccount = PyUnicode_FromString(AB_Transaction_GetLocalAccountNumber(t)); } if (AB_Transaction_GetLocalBankCode(t) == NULL) { trans->localBank = Py_None; Py_INCREF(Py_None); } else { trans->localBank = PyUnicode_FromString(AB_Transaction_GetLocalBankCode(t)); } if (AB_Transaction_GetLocalIban(t) == NULL) { trans->localIban = Py_None; Py_INCREF(Py_None); } else { trans->localIban = PyUnicode_FromString(AB_Transaction_GetLocalIban(t)); } if (AB_Transaction_GetLocalBic(t) == NULL) { trans->localBic = Py_None; Py_INCREF(Py_None); } else { trans->localBic = PyUnicode_FromString(AB_Transaction_GetLocalBic(t)); } if (AB_Transaction_GetLocalName(t) == NULL) { trans->localName = Py_None; Py_INCREF(Py_None); } else { trans->localName = PyUnicode_FromString(AB_Transaction_GetLocalName(t)); } // Remote user if (AB_Transaction_GetRemoteAccountNumber(t) == NULL) { trans->remoteAccount = Py_None; Py_INCREF(Py_None); } else { trans->remoteAccount = PyUnicode_FromString(AB_Transaction_GetRemoteAccountNumber(t)); } if (AB_Transaction_GetRemoteBankCode(t) == NULL) { trans->remoteBank = Py_None; Py_INCREF(Py_None); } else { trans->remoteBank = PyUnicode_FromString(AB_Transaction_GetRemoteBankCode(t)); } if (AB_Transaction_GetRemoteIban(t) == NULL) { trans->remoteIban = Py_None; Py_INCREF(Py_None); } else { trans->remoteIban = PyUnicode_FromString(AB_Transaction_GetRemoteIban(t)); } if (AB_Transaction_GetRemoteBic(t) == NULL) { trans->remoteBic = Py_None; Py_INCREF(Py_None); } else { trans->remoteBic = PyUnicode_FromString(AB_Transaction_GetRemoteBic(t)); } if (AB_Transaction_GetRemoteName(t) == NULL) { trans->remoteName = Py_None; Py_INCREF(Py_None); } else { sl = AB_Transaction_GetRemoteName(t); remoteName = GWEN_StringList_FirstString(sl); if (remoteName == NULL) { trans->remoteName = Py_None; } else { trans->remoteName = PyUnicode_FromString(remoteName); } } trans->value = PyFloat_FromDouble(AB_Value_GetValueAsDouble(v)); trans->currency = PyUnicode_FromString("EUR"); trans->uniqueId = PyLong_FromLong(AB_Transaction_GetUniqueId(t)); if (AB_Transaction_GetTransactionText(t) == NULL) { trans->transactionText = PyUnicode_FromString(""); } else { trans->transactionText = PyUnicode_FromString(AB_Transaction_GetTransactionText(t)); } trans->transactionCode = PyLong_FromLong(AB_Transaction_GetTransactionCode(t)); trans->textKey = PyLong_FromLong(AB_Transaction_GetTextKey(t)); trans->textKeyExt = PyLong_FromLong(AB_Transaction_GetTextKeyExt(t)); if (AB_Transaction_GetMandateId(t) == NULL) { trans->sepaMandateId = Py_None; } else { trans->sepaMandateId = PyUnicode_FromString(AB_Transaction_GetMandateId(t)); } if (AB_Transaction_GetCustomerReference(t) == NULL) { trans->customerReference = PyUnicode_FromString(""); } else { trans->customerReference = PyUnicode_FromString(AB_Transaction_GetCustomerReference(t)); } if (AB_Transaction_GetBankReference(t) == NULL) { trans->bankReference = PyUnicode_FromString(""); } else { trans->bankReference = PyUnicode_FromString(AB_Transaction_GetBankReference(t)); } if (AB_Transaction_GetEndToEndReference(t) == NULL) { trans->endToEndReference = PyUnicode_FromString(""); } else { trans->endToEndReference = PyUnicode_FromString(AB_Transaction_GetEndToEndReference(t)); } trans->state = 0; state = AB_Transaction_GetStatus(t); switch(state) { case AB_Transaction_StatusUnknown: trans->state = -1; break; case AB_Transaction_StatusNone: trans->state = 0; break; case AB_Transaction_StatusAccepted: trans->state = 1; break; case AB_Transaction_StatusRejected: trans->state = 2; break; case AB_Transaction_StatusPending: trans->state = 4; break; case AB_Transaction_StatusSending: trans->state = 8; break; case AB_Transaction_StatusAutoReconciled: trans->state = 16; break; case AB_Transaction_StatusManuallyReconciled: trans->state = 32; break; case AB_Transaction_StatusRevoked: trans->state = 64; break; case AB_Transaction_StatusAborted: trans->state = 128; break; } PyList_Append(transList, (PyObject *)trans); Py_DECREF(trans); } t = AB_ImExporterAccountInfo_GetNextTransaction(ai); } ai = AB_ImExporterContext_GetNextAccountInfo(ctx); } // Free jobs. AB_Job_free(job); AB_Job_List2_free(jl); AB_ImExporterContext_free(ctx); // Exit aqbanking. rv = AB_free(self); if (rv > 0) { //Py_XDECREF(trans); Py_DECREF(transList); return NULL; } return transList; }
static PyObject *aqbanking_Account_balance(aqbanking_Account* self, PyObject *args, PyObject *keywds) { const AB_ACCOUNT_STATUS * status; const AB_BALANCE * bal; const AB_VALUE *v = 0; int rv; double balance; const char *bank_code; const char *account_no; #if PY_VERSION_HEX >= 0x03030000 bank_code = PyUnicode_AsUTF8(self->bank_code); account_no = PyUnicode_AsUTF8(self->no); #else PyObject *s = _PyUnicode_AsDefaultEncodedString(self->bank_code, NULL); bank_code = PyBytes_AS_STRING(s); s = _PyUnicode_AsDefaultEncodedString(self->no, NULL); account_no = PyBytes_AS_STRING(s); #endif AB_ACCOUNT *a; AB_JOB *job = 0; AB_JOB_LIST2 *jl = 0; AB_IMEXPORTER_CONTEXT *ctx = 0; AB_IMEXPORTER_ACCOUNTINFO *ai; // Valid data set? if (self->no == NULL) { PyErr_SetString(PyExc_AttributeError, "no"); } if (self->bank_code == NULL) { PyErr_SetString(PyExc_AttributeError, "bank_code"); } // Initialize aqbanking. rv = AB_create(self); if (rv > 0) { return NULL; } // Let us find the account! a = AB_Banking_GetAccountByCodeAndNumber(self->ab, bank_code, account_no); if (!a) { PyErr_SetString(AccountNotFound, "Could not find the given account! "); return NULL; } // Create job and execute it. ctx = AB_ImExporterContext_new(); jl = AB_Job_List2_new(); job = AB_JobGetBalance_new(a); AB_Job_List2_PushBack(jl, job); rv = AB_Banking_ExecuteJobs(self->ab, jl, ctx); if (rv) { PyErr_SetString(ExecutionFailed, "Could not get the balance!"); return NULL; } // With success. No process the result. ai = AB_ImExporterContext_GetFirstAccountInfo (ctx); status = AB_ImExporterAccountInfo_GetFirstAccountStatus (ai); bal = AB_AccountStatus_GetBookedBalance (status); v = AB_Balance_GetValue (bal); balance = AB_Value_GetValueAsDouble(v); // Free jobs. AB_Job_List2_free(jl); AB_ImExporterContext_free(ctx); // Exit aqbanking. rv = AB_free(self); if (rv > 0) { return NULL; } // FIXME: currency! return Py_BuildValue("(d,s)", balance, "EUR"); }
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); }
void gnc_ab_maketrans(GtkWidget *parent, Account *gnc_acc, GncABTransType trans_type) { AB_BANKING *api; gboolean online = FALSE; AB_ACCOUNT *ab_acc; GList *templates = NULL; GncABTransDialog *td = NULL; gboolean successful = FALSE; gboolean aborted = FALSE; g_return_if_fail(parent && gnc_acc); /* Get the API */ api = gnc_AB_BANKING_new(); if (!api) { g_warning("gnc_ab_maketrans: Couldn't get AqBanking API"); return; } if (AB_Banking_OnlineInit(api #ifdef AQBANKING_VERSION_4_EXACTLY , 0 #endif ) != 0) { g_warning("gnc_ab_maketrans: 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 list of template transactions */ templates = gnc_ab_trans_templ_list_new_from_book( gnc_account_get_book(gnc_acc)); /* Create new ABTransDialog */ td = gnc_ab_trans_dialog_new(parent, ab_acc, xaccAccountGetCommoditySCU(gnc_acc), trans_type, templates); templates = NULL; /* Repeat until AqBanking action was successful or user pressed cancel */ do { GncGWENGui *gui = NULL; gint result; gboolean changed; const AB_TRANSACTION *ab_trans; AB_JOB *job = NULL; AB_JOB_LIST2 *job_list = NULL; XferDialog *xfer_dialog = NULL; gnc_numeric amount; gchar *description; gchar *memo; Transaction *gnc_trans = NULL; AB_IMEXPORTER_CONTEXT *context = NULL; AB_JOB_STATUS job_status; GncABImExContextImport *ieci = NULL; /* Get a GUI object */ gui = gnc_GWEN_Gui_get(parent); if (!gui) { g_warning("gnc_ab_maketrans: Couldn't initialize Gwenhywfar GUI"); aborted = TRUE; goto repeat; } /* Let the user enter the values */ result = gnc_ab_trans_dialog_run_until_ok(td); /* Save the templates */ templates = gnc_ab_trans_dialog_get_templ(td, &changed); if (changed) save_templates(parent, gnc_acc, templates, (result == GNC_RESPONSE_NOW)); g_list_free(templates); templates = NULL; if (result != GNC_RESPONSE_NOW && result != GNC_RESPONSE_LATER) { aborted = TRUE; goto repeat; } /* Get a job and enqueue it */ ab_trans = gnc_ab_trans_dialog_get_ab_trans(td); job = gnc_ab_trans_dialog_get_job(td); if (!job || AB_Job_CheckAvailability(job #ifndef AQBANKING_VERSION_5_PLUS , 0 #endif )) { if (!gnc_verify_dialog( parent, FALSE, "%s", _("The backend found an error during the preparation " "of the job. It is not possible to execute this job. \n" "\n" "Most probable the bank does not support your chosen " "job or your Online Banking account does not have the permission " "to execute this job. More error messages might be " "visible on your console log.\n" "\n" "Do you want to enter the job again?"))) aborted = TRUE; goto repeat; } job_list = AB_Job_List2_new(); AB_Job_List2_PushBack(job_list, job); /* Setup a Transfer Dialog for the GnuCash transaction */ xfer_dialog = gnc_xfer_dialog(gnc_ab_trans_dialog_get_parent(td), gnc_acc); switch (trans_type) { case SINGLE_DEBITNOTE: gnc_xfer_dialog_set_title( xfer_dialog, _("Online Banking Direct Debit Note")); gnc_xfer_dialog_lock_to_account_tree(xfer_dialog); break; case SINGLE_INTERNAL_TRANSFER: gnc_xfer_dialog_set_title( xfer_dialog, _("Online Banking Bank-Internal Transfer")); gnc_xfer_dialog_lock_from_account_tree(xfer_dialog); break; case SEPA_TRANSFER: gnc_xfer_dialog_set_title( xfer_dialog, _("Online Banking European (SEPA) Transfer")); gnc_xfer_dialog_lock_from_account_tree(xfer_dialog); break; case SEPA_DEBITNOTE: gnc_xfer_dialog_set_title( xfer_dialog, _("Online Banking European (SEPA) Debit Note")); gnc_xfer_dialog_lock_to_account_tree(xfer_dialog); break; case SINGLE_TRANSFER: default: gnc_xfer_dialog_set_title( xfer_dialog, _("Online Banking Transaction")); gnc_xfer_dialog_lock_from_account_tree(xfer_dialog); } gnc_xfer_dialog_set_to_show_button_active(xfer_dialog, TRUE); amount = double_to_gnc_numeric( AB_Value_GetValueAsDouble(AB_Transaction_GetValue(ab_trans)), xaccAccountGetCommoditySCU(gnc_acc), GNC_HOW_RND_ROUND_HALF_UP); gnc_xfer_dialog_set_amount(xfer_dialog, amount); gnc_xfer_dialog_set_amount_sensitive(xfer_dialog, FALSE); gnc_xfer_dialog_set_date_sensitive(xfer_dialog, FALSE); description = gnc_ab_description_to_gnc(ab_trans); gnc_xfer_dialog_set_description(xfer_dialog, description); g_free(description); memo = gnc_ab_memo_to_gnc(ab_trans); gnc_xfer_dialog_set_memo(xfer_dialog, memo); g_free(memo); gnc_xfer_dialog_set_txn_cb(xfer_dialog, txn_created_cb, &gnc_trans); /* And run it */ successful = gnc_xfer_dialog_run_until_done(xfer_dialog); /* On cancel, go back to the AB transaction dialog */ if (!successful || !gnc_trans) { successful = FALSE; goto repeat; } if (result == GNC_RESPONSE_NOW) { /* Create a context to store possible results */ context = AB_ImExporterContext_new(); gui = gnc_GWEN_Gui_get(parent); if (!gui) { g_warning("gnc_ab_maketrans: Couldn't initialize Gwenhywfar GUI"); aborted = TRUE; goto repeat; } /* Finally, 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) { successful = FALSE; if (!gnc_verify_dialog( parent, FALSE, "%s", _("An error occurred while executing the job. Please check " "the log window for the exact error message.\n" "\n" "Do you want to enter the job again?"))) { aborted = TRUE; } } else { successful = TRUE; } if (successful) { /* Import the results, awaiting nothing */ ieci = gnc_ab_import_context(context, 0, FALSE, NULL, parent); } } /* Simply ignore any other case */ repeat: /* Clean up */ if (gnc_trans && !successful) { xaccTransBeginEdit(gnc_trans); xaccTransDestroy(gnc_trans); xaccTransCommitEdit(gnc_trans); gnc_trans = NULL; } if (ieci) g_free(ieci); if (context) AB_ImExporterContext_free(context); if (job_list) { AB_Job_List2_free(job_list); job_list = NULL; } if (job) { AB_Job_free(job); job = NULL; } if (gui) { gnc_GWEN_Gui_release(gui); gui = NULL; } } while (!successful && !aborted); cleanup: if (td) gnc_ab_trans_dialog_free(td); 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_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); }