void AB_Value_toHumanReadableString2(const AB_VALUE *v, GWEN_BUFFER *buf, int prec, int withCurrency) { char numbuf[128]; double num; int rv; #ifdef HAVE_SETLOCALE const char *orig_locale = setlocale(LC_NUMERIC, NULL); char *currentLocale = strdup(orig_locale ? orig_locale : "C"); setlocale(LC_NUMERIC, "C"); #endif num=AB_Value_GetValueAsDouble(v); rv=snprintf(numbuf, sizeof(numbuf), "%.*f", prec, num); #ifdef HAVE_SETLOCALE setlocale(LC_NUMERIC, currentLocale); free(currentLocale); #endif if (rv<1 || rv>=sizeof(numbuf)) { assert(0); } GWEN_Buffer_AppendString(buf, numbuf); if (v->currency && withCurrency) { GWEN_Buffer_AppendString(buf, " "); GWEN_Buffer_AppendString(buf, v->currency); } }
gchar * gnc_AB_VALUE_to_readable_string(const AB_VALUE *value) { if (value) return g_strdup_printf("%.2f %s", AB_Value_GetValueAsDouble(value), AB_Value_GetCurrency(value)); else return g_strdup_printf("%.2f", 0.0); }
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"); }
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; }
Transaction * gnc_ab_trans_to_gnc(const AB_TRANSACTION *ab_trans, Account *gnc_acc) { QofBook *book; Transaction *gnc_trans; const gchar *fitid; const GWEN_TIME *valuta_date; time64 current_time; const char *custref; gchar *description; Split *split; gchar *memo; g_return_val_if_fail(ab_trans && gnc_acc, NULL); /* Create new GnuCash transaction for the given AqBanking one */ book = gnc_account_get_book(gnc_acc); gnc_trans = xaccMallocTransaction(book); xaccTransBeginEdit(gnc_trans); /* Date / Time */ valuta_date = AB_Transaction_GetValutaDate(ab_trans); if (!valuta_date) { const GWEN_TIME *normal_date = AB_Transaction_GetDate(ab_trans); if (normal_date) valuta_date = normal_date; } if (valuta_date) xaccTransSetDatePostedSecsNormalized(gnc_trans, GWEN_Time_toTime_t(valuta_date)); else g_warning("transaction_cb: Oops, date 'valuta_date' was NULL"); xaccTransSetDateEnteredSecs(gnc_trans, gnc_time (NULL)); /* Currency. We take simply the default currency of the gnucash account */ xaccTransSetCurrency(gnc_trans, xaccAccountGetCommodity(gnc_acc)); /* Trans-Num or Split-Action set with gnc_set_num_action below per book * option */ /* Description */ description = gnc_ab_description_to_gnc(ab_trans); xaccTransSetDescription(gnc_trans, description); g_free(description); /* Notes. */ /* xaccTransSetNotes(gnc_trans, g_notes); */ /* But Nobody ever uses the Notes field? */ /* Add one split */ split = xaccMallocSplit(book); xaccSplitSetParent(split, gnc_trans); xaccSplitSetAccount(split, gnc_acc); /* Set the transaction number or split action field based on book option. * We use the "customer reference", if there is one. */ custref = AB_Transaction_GetCustomerReference(ab_trans); if (custref && *custref && g_ascii_strncasecmp(custref, "NONREF", 6) != 0) gnc_set_num_action (gnc_trans, split, custref, NULL); /* Set OFX unique transaction ID */ fitid = AB_Transaction_GetFiId(ab_trans); if (fitid && *fitid) gnc_import_set_split_online_id(split, fitid); { /* Amount into the split */ const AB_VALUE *ab_value = AB_Transaction_GetValue(ab_trans); double d_value = ab_value ? AB_Value_GetValueAsDouble (ab_value) : 0.0; AB_TRANSACTION_TYPE ab_type = AB_Transaction_GetType (ab_trans); gnc_numeric gnc_amount; /*printf("Transaction with value %f has type %d\n", d_value, ab_type);*/ /* If the value is positive, but the transaction type says the money is transferred away from our account (Transfer instead of DebitNote), we switch the value to negative. */ if (d_value > 0.0 && ab_type == AB_Transaction_TypeTransfer) d_value = -d_value; gnc_amount = double_to_gnc_numeric( d_value, xaccAccountGetCommoditySCU(gnc_acc), GNC_HOW_RND_ROUND_HALF_UP); if (!ab_value) g_warning("transaction_cb: Oops, value was NULL. Using 0"); xaccSplitSetBaseValue(split, gnc_amount, xaccAccountGetCommodity(gnc_acc)); } /* Memo in the Split. */ memo = gnc_ab_memo_to_gnc(ab_trans); xaccSplitSetMemo(split, memo); g_free(memo); return gnc_trans; }
int AHB_DTAUS__CreateSetE(GWEN_BUFFER *dst, GWEN_DB_NODE *cfg, int csets, AB_VALUE *sumEUR, AB_VALUE *sumDEM, AB_VALUE *sumBankCodes, AB_VALUE *sumAccountIds){ unsigned int i; char buffer[32]; DBG_DEBUG(AQBANKING_LOGDOMAIN, "Creating E set"); /* field 1, 2: record header */ GWEN_Buffer_AppendString(dst, "0128E"); /* field 3: reserved */ for (i=0; i<5; i++) GWEN_Buffer_AppendByte(dst, ' '); /* field 4: number of C sets */ snprintf(buffer, sizeof(buffer), "%07d", csets); if (AHB_DTAUS__AddNum(dst, 7, buffer)) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer"); return -1; } /* field 5: sum of DEM values */ snprintf(buffer, sizeof(buffer), "%013.0f", AB_Value_GetValueAsDouble(sumDEM)*100.0); if (AHB_DTAUS__AddNum(dst, 13, buffer)) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer"); return -1; } /* field 6: sum of peer account ids */ snprintf(buffer, sizeof(buffer), "%017.0f", AB_Value_GetValueAsDouble(sumAccountIds)); if (AHB_DTAUS__AddNum(dst, 17, buffer)) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer"); return -1; } /* field 7: sum of peer bank codes */ snprintf(buffer, sizeof(buffer), "%017.0f", AB_Value_GetValueAsDouble(sumBankCodes)); if (AHB_DTAUS__AddNum(dst, 17, buffer)) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer"); return -1; } /* field 8: sum of EUR values */ snprintf(buffer, sizeof(buffer), "%013.0f", AB_Value_GetValueAsDouble(sumEUR)*100.0); if (AHB_DTAUS__AddNum(dst, 13, buffer)) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer"); return -1; } /* field 9: reserved */ for (i=0; i<51; i++) GWEN_Buffer_AppendByte(dst, ' '); return 0; }
int AHB_DTAUS__CreateSetC(GWEN_BUFFER *dst, GWEN_DB_NODE *cfg, GWEN_DB_NODE *xa, AB_VALUE *sumEUR, AB_VALUE *sumDEM, AB_VALUE *sumBankCodes, AB_VALUE *sumAccountIds){ unsigned int i; const char *p; char buffer[32]; int isDebitNote; int isEuro; unsigned int extSets; //unsigned int startPos; AB_VALUE *val; GWEN_STRINGLIST *purposeList; DBG_DEBUG(AQBANKING_LOGDOMAIN, "Creating C set"); /* ______________________________________________________________________ * preparations */ purposeList=GWEN_StringList_new(); /* cut purpose lines into manageable portions (max 27 chars) */ for (i=0; ; i++) { int slen; GWEN_BUFFER *nbuf; p=GWEN_DB_GetCharValue(xa, "purpose", i, 0); if (p==NULL) break; if (i>14) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Too many purpose lines (maxmimum is 14)"); GWEN_StringList_free(purposeList); return -1; } slen=strlen(p); nbuf=GWEN_Buffer_new(0, slen+1, 0, 1); AB_ImExporter_Utf8ToDta(p, -1, nbuf); p=GWEN_Buffer_GetStart(nbuf); while(*p) { while(*p>0 && *p<33) p++; slen=strlen(p); if (slen==0) break; else if (slen>27) { char *ns; ns=(char*) malloc(28); assert(ns); memmove(ns, p, 27); ns[27]=0; /* let stringlist take over ownership of the the string */ GWEN_StringList_AppendString(purposeList, ns, 1, 0); p+=27; } else { GWEN_StringList_AppendString(purposeList, p, 0, 0); break; } } GWEN_Buffer_free(nbuf); } /* for */ //startPos=GWEN_Buffer_GetPos(dst); GWEN_Buffer_AllocRoom(dst, 256); isDebitNote=(strcasecmp(GWEN_DB_GetCharValue(cfg, "type", 0, "transfer"), "debitnote")==0); isEuro=(strcasecmp(GWEN_DB_GetCharValue(cfg, "currency", 0, "EUR"), "EUR")==0); /* compute number of extension sets */ extSets=0; /* add purpose */ if (GWEN_StringList_Count(purposeList)) extSets+=GWEN_StringList_Count(purposeList)-1; /* add name */ for (i=1; i<2; i++) { /* max 1 extset for local name */ if (GWEN_DB_GetCharValue(xa, "localName", i, 0)==0) break; if (i>1) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Too many name lines (maxmimum is 2)"); GWEN_StringList_free(purposeList); return -1; } extSets++; } /* for */ /* add other name */ for (i=1; i<2; i++) { /* max 1 extset for remote name */ if (GWEN_DB_GetCharValue(xa, "remoteName", i, 0)==0) break; if (i>1) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Too many peer name lines (maxmimum is 2)"); GWEN_StringList_free(purposeList); return -1; } extSets++; } /* for */ /* check number of extension sets */ if (extSets>15) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Too many extension sets (%d)", extSets); GWEN_StringList_free(purposeList); return -1; } /* ______________________________________________________________________ * actually write C set */ /* field 1, 2: record header */ snprintf(buffer, sizeof(buffer), "%04d", 187+(extSets*29)); GWEN_Buffer_AppendString(dst, buffer); GWEN_Buffer_AppendByte(dst, 'C'); /* field 3: acting bank code */ if (AHB_DTAUS__AddNum(dst, 8, GWEN_DB_GetCharValue(cfg, "bankCode", 0, ""))) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer"); GWEN_StringList_free(purposeList); return -1; } /* field 4: destination bank code */ p=GWEN_DB_GetCharValue(xa, "remoteBankCode", 0, 0); if (p) { val=AB_Value_fromString(p); if (val==NULL) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Bad bank code"); GWEN_StringList_free(purposeList); return -1; } AB_Value_AddValue(sumBankCodes, val); AB_Value_free(val); if (AHB_DTAUS__AddNum(dst, 8, p)) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer"); GWEN_StringList_free(purposeList); return -1; } } else { DBG_ERROR(AQBANKING_LOGDOMAIN, "Peer bank code missing"); GWEN_StringList_free(purposeList); return -1; } /* field 5: destination account id */ p=GWEN_DB_GetCharValue(xa, "remoteAccountNumber", 0, 0); if (p) { val=AB_Value_fromString(p); if (val==NULL) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Bad account id"); GWEN_StringList_free(purposeList); return -1; } AB_Value_AddValue(sumAccountIds, val); AB_Value_free(val); if (AHB_DTAUS__AddNum(dst, 10, p)) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer"); GWEN_StringList_free(purposeList); return -1; } } else { DBG_ERROR(AQBANKING_LOGDOMAIN, "Peer account id missing"); GWEN_StringList_free(purposeList); return -1; } /* field 6: internal customer number (0s for now) */ for (i=0; i<13; i++) GWEN_Buffer_AppendByte(dst, '0'); /* field 7a: text key */ snprintf(buffer, sizeof(buffer), "%02d", GWEN_DB_GetIntValue(xa, "textkey", 0, isDebitNote?5:51)); if (AHB_DTAUS__AddNum(dst, 2, buffer)) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer"); GWEN_StringList_free(purposeList); return -1; } /* field 7b: text key extension */ snprintf(buffer, sizeof(buffer), "%03d", GWEN_DB_GetIntValue(xa, "textkeyext", 0, 0)); if (AHB_DTAUS__AddNum(dst, 3, buffer)) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer"); GWEN_StringList_free(purposeList); return -1; } /* field 8: bank internal field */ GWEN_Buffer_AppendByte(dst, ' '); /* field 9: value in DEM */ if (!isEuro) { val=AB_Value_fromString(GWEN_DB_GetCharValue(xa, "value/value", 0, "0,0")); if (val==NULL || AB_Value_IsZero(val)) { AB_Value_free(val); DBG_ERROR(AQBANKING_LOGDOMAIN, "Bad DEM value:"); GWEN_StringList_free(purposeList); return -1; } AB_Value_AddValue(sumDEM, val); snprintf(buffer, sizeof(buffer), "%011.0f", AB_Value_GetValueAsDouble(val)*100.0); AB_Value_free(val); if (AHB_DTAUS__AddNum(dst, 11, buffer)) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer"); GWEN_StringList_free(purposeList); return -1; } } else { if (AHB_DTAUS__AddNum(dst, 11, "0")) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer"); GWEN_StringList_free(purposeList); return -1; } } /* field 10: local bank code */ p=GWEN_DB_GetCharValue(xa, "localbankCode", 0, 0); if (!p) p=GWEN_DB_GetCharValue(cfg, "bankCode", 0, 0); if (!p) { DBG_ERROR(AQBANKING_LOGDOMAIN, "No local bank code"); GWEN_StringList_free(purposeList); return -1; } if (AHB_DTAUS__AddNum(dst, 8, p)) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer"); GWEN_StringList_free(purposeList); return -1; } /* field 11: local account id */ p=GWEN_DB_GetCharValue(xa, "localAccountNumber", 0, 0); if (!p) GWEN_DB_GetCharValue(cfg, "accountId", 0, 0); if (!p) { DBG_ERROR(AQBANKING_LOGDOMAIN, "No local account number"); GWEN_StringList_free(purposeList); return -1; } if (AHB_DTAUS__AddNum(dst, 10, p)) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer"); GWEN_StringList_free(purposeList); return -1; } /* field 12: value in EUR */ if (isEuro) { val=AB_Value_fromString(GWEN_DB_GetCharValue(xa, "value/value", 0, "0,0")); if (val==NULL || AB_Value_IsZero(val)) { AB_Value_free(val); DBG_ERROR(AQBANKING_LOGDOMAIN, "Bad EUR value:"); GWEN_StringList_free(purposeList); return -1; } AB_Value_AddValue(sumEUR, val); snprintf(buffer, sizeof(buffer), "%011.0f", AB_Value_GetValueAsDouble(val)*100.0); AB_Value_free(val); if (AHB_DTAUS__AddNum(dst, 11, buffer)) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer"); GWEN_StringList_free(purposeList); return -1; } } else { if (AHB_DTAUS__AddNum(dst, 11, "0")) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer"); GWEN_StringList_free(purposeList); return -1; } } /* field 13: blanks */ for (i=0; i<3; i++) GWEN_Buffer_AppendByte(dst, ' '); /* field 14a: peer name */ if (AHB_DTAUS__AddWord(dst, 27, GWEN_DB_GetCharValue(xa, "remoteName", 0, ""))) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer"); GWEN_StringList_free(purposeList); return -1; } /* field 14b: blanks */ for (i=0; i<8; i++) GWEN_Buffer_AppendByte(dst, ' '); /* field 15: name */ if (AHB_DTAUS__AddWord(dst, 27, GWEN_DB_GetCharValue(xa, "localname", 0, ""))) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer"); GWEN_StringList_free(purposeList); return -1; } /* field 16: purpose */ p=GWEN_StringList_FirstString(purposeList); if (p==NULL) p=""; if (AHB_DTAUS__AddWord(dst, 27, p)) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer"); GWEN_StringList_free(purposeList); return -1; } /* field 17a: currency */ if (isEuro) GWEN_Buffer_AppendByte(dst, '1'); else GWEN_Buffer_AppendByte(dst, ' '); /* field 17b: blanks */ for (i=0; i<2; i++) GWEN_Buffer_AppendByte(dst, ' '); /* field 18: number of extension sets */ snprintf(buffer, sizeof(buffer), "%02d", extSets); if (AHB_DTAUS__AddNum(dst, 2, buffer)) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer"); GWEN_StringList_free(purposeList); return -1; } if (extSets) { unsigned int writtenExtSets=0; /* now append extension sets */ /* add peer name lines */ for (i=1; i<2; i++) { /* max: 1 extset */ unsigned int j; p=GWEN_DB_GetCharValue(xa, "remoteName", i, 0); if (!p) break; /* append extension set */ GWEN_Buffer_AppendString(dst, "01"); if (AHB_DTAUS__AddWord(dst, 27, p)) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer"); GWEN_StringList_free(purposeList); return -1; } writtenExtSets++; if (writtenExtSets==2) /* 2 ext sets written, so we need to align "C 2.Satzabschnitt" to 128 now */ for (j=0; j<11; j++) GWEN_Buffer_AppendByte(dst, ' '); else if (writtenExtSets>2 && ((writtenExtSets-2) % 4)==0) /* "C 3-5.Satzabschnitt" complete, align to 128 bytes */ for (j=0; j<12; j++) GWEN_Buffer_AppendByte(dst, ' '); } /* for */ /* add purpose lines */ for (i=1; i<GWEN_StringList_Count(purposeList); i++) { unsigned int j; p=GWEN_StringList_StringAt(purposeList, i); if (!p) break; /* append extension set */ GWEN_Buffer_AppendString(dst, "02"); /* strings in the list are already in DTA charset */ if (AHB_DTAUS__AddDtaWord(dst, 27, p)) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer"); GWEN_StringList_free(purposeList); return -1; } writtenExtSets++; if (writtenExtSets==2) /* 2 ext sets written, so we need to align "C 2.Satzabschnitt" to 128 now */ for (j=0; j<11; j++) GWEN_Buffer_AppendByte(dst, ' '); else if (writtenExtSets>2 && ((writtenExtSets-2) % 4)==0) /* "C 3-5.Satzabschnitt" complete, align to 128 bytes */ for (j=0; j<12; j++) GWEN_Buffer_AppendByte(dst, ' '); } /* for */ /* add name lines */ for (i=1; i<2; i++) { /* max: 1 extset */ unsigned int j; p=GWEN_DB_GetCharValue(xa, "localname", i, 0); if (!p) break; /* append extension set */ GWEN_Buffer_AppendString(dst, "03"); if (AHB_DTAUS__AddWord(dst, 27, p)) { DBG_ERROR(AQBANKING_LOGDOMAIN, "Error writing to buffer"); GWEN_StringList_free(purposeList); return -1; } writtenExtSets++; if (writtenExtSets==2) /* 2 ext sets written, so we need to align "C 2.Satzabschnitt" to 128 now */ for (j=0; j<11; j++) GWEN_Buffer_AppendByte(dst, ' '); else if (writtenExtSets>2 && ((writtenExtSets-2) % 4)==0) /* "C 3-5.Satzabschnitt" complete, align to 128 bytes */ for (j=0; j<12; j++) GWEN_Buffer_AppendByte(dst, ' '); } /* for */ } i=((GWEN_Buffer_GetUsedBytes(dst)+127) & ~127)-GWEN_Buffer_GetUsedBytes(dst); while(i--) GWEN_Buffer_AppendByte(dst, ' '); GWEN_StringList_free(purposeList); return 0; }
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); }
gint gnc_ab_trans_dialog_run_until_ok(GncABTransDialog *td) { gint result; AB_JOB *job; const AB_TRANSACTION_LIMITS *joblimits; guint8 max_purpose_lines; gboolean values_ok; gchar *purpose; gchar *othername; /* Check whether the account supports this job */ job = get_available_empty_job(td->ab_acc, td->trans_type); if (!job) { g_warning("gnc_ab_trans_dialog_run_until_ok: Oops, job not available"); return GTK_RESPONSE_CANCEL; } /* Activate as many purpose entries as available for the job */ joblimits = AB_JobSingleTransfer_GetFieldLimits(job); max_purpose_lines = joblimits ? AB_TransactionLimits_GetMaxLinesPurpose(joblimits) : 2; gtk_widget_set_sensitive(td->purpose_cont_entry, max_purpose_lines > 1); gtk_widget_set_sensitive(td->purpose_cont2_entry, max_purpose_lines > 2); gtk_widget_set_sensitive(td->purpose_cont3_entry, max_purpose_lines > 3); /* Show the dialog */ gtk_widget_show(td->dialog); /* Repeat until entered values make sense */ do { /* Now run the dialog until it gets closed by a button press */ result = gtk_dialog_run (GTK_DIALOG (td->dialog)); /* Was cancel pressed or dialog closed? * GNC_RESPONSE_NOW == execute now * GNC_RESPONSE_LATER == scheduled for later execution (unimplemented) * GTK_RESPONSE_CANCEL == cancel * GTK_RESPONSE_DELETE_EVENT == window destroyed */ if (result != GNC_RESPONSE_NOW && result != GNC_RESPONSE_LATER) { gtk_widget_destroy(td->dialog); td->dialog = NULL; break; } /* Now fill in the values from the entry fields into a new * AB_TRANSACTION */ td->ab_trans = ab_trans_fill_values(td); values_ok = TRUE; /* Check transaction value */ values_ok = AB_Value_GetValueAsDouble(AB_Transaction_GetValue(td->ab_trans)) != 0.0; if (!values_ok) { gtk_widget_show(td->dialog); if (gnc_verify_dialog( td->dialog, TRUE, "%s", _("The amount is zero or the amount field could not be " "interpreted correctly. You might have mixed up decimal " "point and comma, compared to your locale settings. " "This does not result in a valid online transfer job. \n" "\n" "Do you want to enter the job again?"))) { continue; } else { AB_Transaction_free(td->ab_trans); td->ab_trans = NULL; result = GTK_RESPONSE_CANCEL; break; } } /* Check transaction purpose */ purpose = gnc_ab_get_purpose(td->ab_trans); values_ok = *purpose; g_free(purpose); if (!values_ok) { gtk_widget_show(td->dialog); if (gnc_verify_dialog( td->dialog, TRUE, "%s", _("You did not enter any transaction purpose. A purpose is " "required for an online transfer.\n" "\n" "Do you want to enter the job again?"))) { continue; } else { AB_Transaction_free(td->ab_trans); td->ab_trans = NULL; result = GTK_RESPONSE_CANCEL; break; } } /* Check recipient / remote name */ othername = gnc_ab_get_remote_name(td->ab_trans); values_ok = othername && *othername; g_free(othername); if (!values_ok) { gtk_widget_show(td->dialog); if (gnc_verify_dialog( td->dialog, TRUE, "%s", _("You did not enter a recipient name. A recipient name is " "required for an online transfer.\n" "\n" "Do you want to enter the job again?"))) { continue; } else { AB_Transaction_free(td->ab_trans); td->ab_trans = NULL; result = GTK_RESPONSE_CANCEL; break; } } /* FIXME: If this is a direct debit, set the textkey/ "Textschluessel"/ * transactionCode according to some GUI selection here!! */ /*if (td->trans_type == SINGLE_DEBITNOTE) AB_TRANSACTION_setTextKey (td->hbci_trans, 05); */ /* And finally check the account code, if ktoblzcheck is available */ values_ok = check_ktoblzcheck(td->dialog, td, td->ab_trans); } while (!values_ok); /* Hide the dialog */ if (td->dialog) gtk_widget_hide(td->dialog); return result; }
int main(int argc, char **argv) { GWEN_GUI *gui; AB_BANKING *ab; AB_ACCOUNT_SPEC_LIST *accs=NULL; AB_ACCOUNT_SPEC *as; AB_IMEXPORTER_ACCOUNTINFO *ai; gui=GWEN_Gui_CGui_new(); GWEN_Gui_SetGui(gui); ab=AB_Banking_new("tutorial3", 0, 0); AB_Banking_Init(ab); fprintf(stderr, "AqBanking successfully initialized.\n"); /* get the list of known accounts */ AB_Banking_GetAccountSpecList(ab, &accs); /* find a matching account within the given list */ as=AB_AccountSpec_List_FindFirst(accs, "aqhbci", /* backendName */ "de", /* country */ "28*", /* bankId bank */ "*", /* accountNumber */ "*", /* subAccountId */ "*", /* iban */ "*", /* currency */ AB_AccountType_Unknown); /* ty */ if (as) { AB_TRANSACTION_LIST2 *cmdList; AB_TRANSACTION *t; AB_IMEXPORTER_CONTEXT *ctx; cmdList=AB_Transaction_List2_new(); t=AB_Transaction_new(); AB_Transaction_SetCommand(t, AB_Transaction_CommandGetTransactions); AB_Transaction_SetUniqueAccountId(t, AB_AccountSpec_GetUniqueId(as)); AB_Transaction_List2_PushBack(cmdList, t); ctx=AB_ImExporterContext_new(); AB_Banking_SendCommands(ab, cmdList, ctx); ai=AB_ImExporterContext_GetFirstAccountInfo(ctx); while (ai) { const AB_TRANSACTION *t; t=AB_ImExporterAccountInfo_GetFirstTransaction(ai, 0, 0); while (t) { const AB_VALUE *v; v=AB_Transaction_GetValue(t); if (v) { const char *purpose; purpose=AB_Transaction_GetPurpose(t); fprintf(stderr, " %-32s (%.2f %s)\n", purpose, AB_Value_GetValueAsDouble(v), AB_Value_GetCurrency(v)); } t=AB_Transaction_List_Next(t); } /* while transactions */ ai=AB_ImExporterAccountInfo_List_Next(ai); } /* while ai */ AB_ImExporterContext_free(ctx); } /* if (as) */ AB_Banking_Fini(ab); AB_Banking_free(ab); return 0; }