static AB_ACCOUNT_STATUS *_getLastAccountStatus(AB_IMEXPORTER_ACCOUNTINFO *iea) { AB_ACCOUNT_STATUS *lastAst=0; const GWEN_TIME *lastTi=0; AB_ACCOUNT_STATUS *ast=0; ast=AB_ImExporterAccountInfo_GetFirstAccountStatus(iea); while(ast) { const GWEN_TIME *ti; if (lastAst && lastTi && (ti=AB_AccountStatus_GetTime(ast))) { if (GWEN_Time_Diff(ti, lastTi)>0) { lastAst=ast; lastTi=ti; } } else { lastAst=ast; lastTi=AB_AccountStatus_GetTime(ast); } ast=AB_ImExporterAccountInfo_GetNextAccountStatus(iea); } return lastAst; }
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"); }
static AB_IMEXPORTER_ACCOUNTINFO * bal_accountinfo_cb(AB_IMEXPORTER_ACCOUNTINFO *element, gpointer user_data) { GncABImExContextImport *data = user_data; Account *gnc_acc; AB_ACCOUNT_STATUS *item, *best = NULL; const GWEN_TIME *best_time = NULL; const AB_BALANCE *booked_bal, *noted_bal; const AB_VALUE *booked_val = NULL, *noted_val = NULL; gdouble booked_value, noted_value; gnc_numeric value; time64 booked_tt = 0; GtkWidget *dialog; gboolean show_recn_window = FALSE; g_return_val_if_fail(element && data, NULL); if (data->awaiting & IGNORE_BALANCES) /* Ignore them */ return NULL; if (!AB_ImExporterAccountInfo_GetFirstAccountStatus(element)) /* No balance found */ return NULL; else data->awaiting |= FOUND_BALANCES; /* Lookup the most recent ACCOUNT_STATUS available */ item = AB_ImExporterAccountInfo_GetFirstAccountStatus(element); while (item) { const GWEN_TIME *item_time = AB_AccountStatus_GetTime(item); if (!best || GWEN_Time_Diff(best_time, item_time) < 0.0) { best = item; best_time = item_time; } item = AB_ImExporterAccountInfo_GetNextAccountStatus(element); } booked_bal = AB_AccountStatus_GetBookedBalance(best); if (!(data->awaiting & AWAIT_BALANCES)) { /* Ignore zero balances if we don't await a balance */ if (!booked_bal || AB_Value_IsZero(AB_Balance_GetValue(booked_bal))) return NULL; /* Ask the user whether to import unawaited non-zero balance */ if (gnc_verify_dialog(data->parent, TRUE, "%s", _("The bank has sent balance information " "in its response." "\n" "Do you want to import it?"))) { data->awaiting |= AWAIT_BALANCES; } else { data->awaiting |= IGNORE_BALANCES; return NULL; } } /* Lookup the corresponding gnucash account */ gnc_acc = gnc_ab_accinfo_to_gnc_acc(element); if (!gnc_acc) return NULL; data->gnc_acc = gnc_acc; /* Lookup booked balance and time */ if (booked_bal) { const GWEN_TIME *ti = AB_Balance_GetTime(booked_bal); if (ti) { booked_tt = GWEN_Time_toTime_t(ti); } else { /* No time found? Use today because the HBCI query asked for today's * balance. */ booked_tt = gnc_time64_get_day_start(gnc_time(NULL)); } booked_val = AB_Balance_GetValue(booked_bal); if (booked_val) { booked_value = AB_Value_GetValueAsDouble(booked_val); } else { g_warning("bal_accountinfo_cb: booked_val == NULL. Assuming 0"); booked_value = 0.0; } } else { g_warning("bal_accountinfo_cb: booked_bal == NULL. Assuming 0"); booked_tt = 0; booked_value = 0.0; } /* Lookup noted balance */ noted_bal = AB_AccountStatus_GetNotedBalance(best); if (noted_bal) { noted_val = AB_Balance_GetValue(noted_bal); if (noted_val) noted_value = AB_Value_GetValueAsDouble(noted_val); else { g_warning("bal_accountinfo_cb: noted_val == NULL. Assuming 0"); noted_value = 0.0; } } else { g_warning("bal_accountinfo_cb: noted_bal == NULL. Assuming 0"); noted_value = 0.0; } value = double_to_gnc_numeric(booked_value, xaccAccountGetCommoditySCU(gnc_acc), GNC_HOW_RND_ROUND_HALF_UP); if (noted_value == 0.0 && booked_value == 0.0) { dialog = gtk_message_dialog_new( GTK_WINDOW(data->parent), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "%s", /* Translators: Strings from this file are needed only in * countries that have one of aqbanking's Online Banking * techniques available. This is 'OFX DirectConnect' * (U.S. and others), 'HBCI' (in Germany), or 'YellowNet' * (Switzerland). If none of these techniques are available * in your country, you may safely ignore strings from the * import-export/hbci subdirectory. */ _("The downloaded Online Banking Balance was zero.\n\n" "Either this is the correct balance, or your bank does not " "support Balance download in this Online Banking version. " "In the latter case you should choose a different " "Online Banking version number in the Online Banking " "(AqBanking or HBCI) Setup. After that, try again to " "download the Online Banking Balance.")); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); } else { gnc_numeric reconc_balance = xaccAccountGetReconciledBalance(gnc_acc); gchar *booked_str = gnc_AB_VALUE_to_readable_string(booked_val); gchar *message1 = g_strdup_printf( _("Result of Online Banking job: \n" "Account booked balance is %s"), booked_str); gchar *message2 = (noted_value == 0.0) ? g_strdup("") : g_strdup_printf(_("For your information: This account also " "has a noted balance of %s\n"), gnc_AB_VALUE_to_readable_string(noted_val)); if (gnc_numeric_equal(value, reconc_balance)) { const gchar *message3 = _("The booked balance is identical to the current " "reconciled balance of the account."); dialog = gtk_message_dialog_new( GTK_WINDOW(data->parent), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "%s\n%s\n%s", message1, message2, message3); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(GTK_WIDGET(dialog)); } else { const char *message3 = _("Reconcile account now?"); show_recn_window = gnc_verify_dialog(data->parent, TRUE, "%s\n%s\n%s", message1, message2, message3); } g_free(booked_str); g_free(message1); g_free(message2); } /* Show reconciliation window */ if (show_recn_window) recnWindowWithBalance(data->parent, gnc_acc, value, booked_tt); return NULL; }