2003-06-24 Christian Stimming <stimming@tuhh.de>

* src/import-export/hbci/*: Refactor many HBCI functions to
	eventually enable queued processing of several HBCI jobs.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@8660 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Christian Stimming 2003-06-23 22:57:55 +00:00
parent bed1d91aa9
commit 7149c52213
10 changed files with 602 additions and 438 deletions

View File

@ -1,3 +1,8 @@
2003-06-24 Christian Stimming <stimming@tuhh.de>
* src/import-export/hbci/*: Refactor many HBCI functions to
eventually enable queued processing of several HBCI jobs.
2003-06-23 David Hampton <hampton@employees.org>
* src/gnome-utils/dialog-account.c: Limit the commodity choices

View File

@ -74,6 +74,7 @@ struct _trans_data
};
typedef struct _trans_data TransData;
static void TransData_delete_helper(TransData *td)
{
if (!td) return;
@ -88,6 +89,17 @@ static void TransData_delete_helper(TransData *td)
/* Prototypes; callbacks for dialog function */
/* -------------------------------------- */
HBCI_Transaction *
hbci_trans_fill_values(const HBCI_Account *h_acc, TransData *td);
gboolean
check_ktoblzcheck(GtkWidget *parent, const TransData *td,
const HBCI_Transaction *trans);
HBCI_OutboxJob *
hbci_trans_create_outboxjob(const HBCI_Customer *customer,
HBCI_Account *h_acc,
const HBCI_Transaction *trans,
GNC_HBCI_Transtype trans_type);
void template_selection_cb(GtkButton *b, gpointer user_data);
void add_template_cb(GtkButton *b, gpointer user_data);
void blz_changed_cb(GtkEditable *e, gpointer user_data);
@ -295,12 +307,14 @@ gnc_hbci_trans (GtkWidget *parent,
/* Make sure to show the dialog here */
gtk_widget_show_all (dialog);
/* Now run the dialog until it gets closed by a button press. */
result = gnome_dialog_run (GNOME_DIALOG (dialog));
/* printf("hbci_trans: result button was %d.\n", result); */
/* The dialog gets hidden anyway as soon as any button is pressed. */
gtk_widget_hide_all (dialog);
/* Set the template list in case the dialog got cancelled. */
*templ = td.templ;
/* Was cancel pressed or dialog closed? 0 == execute now, 1 ==
@ -310,42 +324,12 @@ gnc_hbci_trans (GtkWidget *parent,
TransData_delete_helper(&td);
return NULL;
}
/* Fill in the user-entered values */
trans = HBCI_Transaction_new();
/* Now fill in the values from the entry fields into a new
HBCI_Transaction. */
trans = hbci_trans_fill_values(h_acc, &td);
values_ok = TRUE;
/* OpenHBCI newer than 0.9.8: use account's bankCode values
* instead of the bank's ones since this is what some banks
* require. */
HBCI_Transaction_setOurCountryCode (trans,
HBCI_Account_countryCode (h_acc));
HBCI_Transaction_setOurBankCode (trans,
HBCI_Account_instituteCode (h_acc));
HBCI_Transaction_setOurAccountId (trans, HBCI_Account_accountId (h_acc));
HBCI_Transaction_setOurSuffix (trans, HBCI_Account_accountSuffix (h_acc));
HBCI_Transaction_setOtherCountryCode (trans, 280);
HBCI_Transaction_setOtherBankCode
(trans, gtk_entry_get_text (GTK_ENTRY (td.recp_bankcode_entry)));
/* printf("Got otherBankCode %s.\n",
HBCI_Transaction_otherBankCode (trans)); */
HBCI_Transaction_setOtherAccountId
(trans, gtk_entry_get_text (GTK_ENTRY (td.recp_account_entry)));
/* printf("Got otherAccountId %s.\n",
HBCI_Transaction_otherAccountId (trans)); */
HBCI_Transaction_addOtherName
(trans, gtk_entry_get_text (GTK_ENTRY (td.recp_name_entry)));
HBCI_Transaction_addDescription
(trans, gtk_entry_get_text (GTK_ENTRY (td.purpose_entry)));
HBCI_Transaction_addDescription
(trans, gtk_entry_get_text (GTK_ENTRY (td.purpose_cont_entry)));
/* FIXME: Replace "EUR" by account-dependent string here. */
HBCI_Transaction_setValue
(trans, HBCI_Value_new_double
(gnc_amount_edit_get_damount (GNC_AMOUNT_EDIT (td.amount_edit)), "EUR"));
/*printf("dialog-hbcitrans: Got value as %s .\n",
HBCI_Value_toReadableString (HBCI_Transaction_value (trans)));*/
if (HBCI_Value_getValue (HBCI_Transaction_value (trans)) == 0.0) {
@ -353,6 +337,7 @@ gnc_hbci_trans (GtkWidget *parent,
values_ok = !gnc_verify_dialog_parented
(GTK_WIDGET (dialog),
TRUE,
"%s",
_("The amount is zero or the amount field could not be \n"
"interpreted correctly. You might have mixed up decimal \n"
"point and comma, compared to your locale settings. \n"
@ -368,78 +353,26 @@ gnc_hbci_trans (GtkWidget *parent,
continue;
} /* check Transaction_value */
#if HAVE_KTOBLZCHECK_H
{
int blzresult;
const char *blztext;
blzresult = AccountNumberCheck_check
(td.blzcheck,
HBCI_Transaction_otherBankCode (trans),
HBCI_Transaction_otherAccountId (trans));
switch (blzresult) {
case 2:
gtk_widget_show_all (dialog);
values_ok = gnc_verify_dialog_parented
(GTK_WIDGET (dialog),
TRUE,
_("The internal check of the destination account number '%s' \n"
"at the specified bank with bank code '%s' failed. This means \n"
"the account number might contain an error. Should the online \n"
"transfer job be sent with this account number anyway?"),
HBCI_Transaction_otherAccountId (trans),
HBCI_Transaction_otherBankCode (trans));
blztext = "Kontonummer wahrscheinlich falsch";
break;
case 0:
blztext = "Kontonummer ok";
break;
case 3:
blztext = "bank unbekannt";
break;
default:
case 1:
blztext = "unbekannt aus unbekanntem grund";
break;
}
printf("gnc_hbci_trans: KtoBlzCheck said check is %d = %s\n",
blzresult, blztext);
}
#endif
/* And finally check the account code, if ktoblzcheck is available. */
values_ok = check_ktoblzcheck(GTK_WIDGET (dialog), &td, trans);
} while (!values_ok);
/* Make really sure the dialog is hidden now. */
gtk_widget_hide_all (dialog);
{
/* Create a Do-Transaction (Transfer) job. */
HBCI_OutboxJobTransfer *transfer_job;
HBCI_OutboxJobDebitNote *debit_job;
HBCI_OutboxJob *job = NULL;
switch (trans_type) {
case SINGLE_DEBITNOTE:
debit_job =
HBCI_OutboxJobDebitNote_new (customer, (HBCI_Account *)h_acc, trans);
job = HBCI_OutboxJobDebitNote_OutboxJob (debit_job);
break;
case SINGLE_TRANSFER:
transfer_job =
HBCI_OutboxJobTransfer_new (customer, (HBCI_Account *)h_acc, trans);
job = HBCI_OutboxJobTransfer_OutboxJob (transfer_job);
break;
default:
printf("dialog-hbcitrans: Oops, unknown GNC_HBCI_Transtype %d.\n",
trans_type);
transfer_job =
HBCI_OutboxJobTransfer_new (customer, (HBCI_Account *)h_acc, trans);
job = HBCI_OutboxJobTransfer_OutboxJob (transfer_job);
}
HBCI_OutboxJob *job;
/* Create a Do-Transaction (Transfer) job. */
job = hbci_trans_create_outboxjob(customer, (HBCI_Account *)h_acc,
trans, trans_type);
g_assert (job);
/* Make really sure there is no other job in the queue */
HBCI_API_clearQueueByStatus (api, HBCI_JOB_STATUS_NONE);
g_assert (job);
/* Add job to queue */
HBCI_API_addJob (api, job);
if (result == 0) {
@ -457,6 +390,7 @@ gnc_hbci_trans (GtkWidget *parent,
successful = !gnc_verify_dialog_parented
(parent,
FALSE,
"%s",
_("The job was successfully sent to the bank, but the \n"
"bank is refusing to execute the job. Please check \n"
"the log window for the exact error message of the \n"
@ -467,6 +401,8 @@ gnc_hbci_trans (GtkWidget *parent,
HBCI_Transaction_delete (trans);
trans = NULL;
/* Watch out! The job *has* to be removed from the queue
here because otherwise it might be executed again. */
HBCI_API_clearQueueByStatus (api, HBCI_JOB_STATUS_NONE);
}
} /* result == 0 */
@ -490,6 +426,137 @@ gnc_hbci_trans (GtkWidget *parent,
/** Fills the values from the entry fields into a new HBCI_Transaction
and returns it. The caller must delete() it when finished. */
HBCI_Transaction *
hbci_trans_fill_values(const HBCI_Account *h_acc, TransData *td)
{
/* Fill in the user-entered values */
HBCI_Transaction *trans = HBCI_Transaction_new();
/* OpenHBCI newer than 0.9.8: use account's bankCode values
* instead of the bank's ones since this is what some banks
* require. */
HBCI_Transaction_setOurCountryCode (trans,
HBCI_Account_countryCode (h_acc));
HBCI_Transaction_setOurBankCode (trans,
HBCI_Account_instituteCode (h_acc));
HBCI_Transaction_setOurAccountId (trans, HBCI_Account_accountId (h_acc));
HBCI_Transaction_setOurSuffix (trans, HBCI_Account_accountSuffix (h_acc));
HBCI_Transaction_setOtherCountryCode (trans, 280);
HBCI_Transaction_setOtherBankCode
(trans, gtk_entry_get_text (GTK_ENTRY (td->recp_bankcode_entry)));
/* printf("Got otherBankCode %s.\n",
HBCI_Transaction_otherBankCode (trans)); */
HBCI_Transaction_setOtherAccountId
(trans, gtk_entry_get_text (GTK_ENTRY (td->recp_account_entry)));
/* printf("Got otherAccountId %s.\n",
HBCI_Transaction_otherAccountId (trans)); */
HBCI_Transaction_addOtherName
(trans, gtk_entry_get_text (GTK_ENTRY (td->recp_name_entry)));
HBCI_Transaction_addDescription
(trans, gtk_entry_get_text (GTK_ENTRY (td->purpose_entry)));
HBCI_Transaction_addDescription
(trans, gtk_entry_get_text (GTK_ENTRY (td->purpose_cont_entry)));
/* FIXME: Replace "EUR" by account-dependent string here. */
HBCI_Transaction_setValue
(trans, HBCI_Value_new_double
(gnc_amount_edit_get_damount (GNC_AMOUNT_EDIT (td->amount_edit)), "EUR"));
return trans;
}
/** Checks the account code in the HBCI_Transaction, if the
ktoblzcheck package is available. Returns TRUE if everything is
fine, or FALSE if this transaction should be entered again. */
gboolean
check_ktoblzcheck(GtkWidget *parent, const TransData *td,
const HBCI_Transaction *trans)
{
#if HAVE_KTOBLZCHECK_H
int blzresult;
const char *blztext;
gboolean values_ok = TRUE;
blzresult = AccountNumberCheck_check
(td->blzcheck,
HBCI_Transaction_otherBankCode (trans),
HBCI_Transaction_otherAccountId (trans));
switch (blzresult) {
case 2:
gtk_widget_show_all (parent);
values_ok = gnc_verify_dialog_parented
(parent,
TRUE,
_("The internal check of the destination account number '%s' \n"
"at the specified bank with bank code '%s' failed. This means \n"
"the account number might contain an error. Should the online \n"
"transfer job be sent with this account number anyway?"),
HBCI_Transaction_otherAccountId (trans),
HBCI_Transaction_otherBankCode (trans));
blztext = "Kontonummer wahrscheinlich falsch";
break;
case 0:
blztext = "Kontonummer ok";
break;
case 3:
blztext = "bank unbekannt";
break;
default:
case 1:
blztext = "unbekannt aus unbekanntem grund";
break;
}
printf("gnc_hbci_trans: KtoBlzCheck said check is %d = %s\n",
blzresult, blztext);
return values_ok;
#else
return TRUE;
#endif
}
/** Create and return the HBCI_OutboxJob according to the given
trans_type. */
HBCI_OutboxJob *
hbci_trans_create_outboxjob(const HBCI_Customer *customer,
HBCI_Account *h_acc,
const HBCI_Transaction *trans,
GNC_HBCI_Transtype trans_type)
{
HBCI_OutboxJob *job = NULL;
switch (trans_type) {
case SINGLE_DEBITNOTE:
{
HBCI_OutboxJobDebitNote *debit_job =
HBCI_OutboxJobDebitNote_new (customer, h_acc, trans);
job = HBCI_OutboxJobDebitNote_OutboxJob (debit_job);
}
break;
case SINGLE_TRANSFER:
{
HBCI_OutboxJobTransfer *transfer_job =
HBCI_OutboxJobTransfer_new (customer, h_acc, trans);
job = HBCI_OutboxJobTransfer_OutboxJob (transfer_job);
}
break;
default:
{
printf("dialog-hbcitrans: Oops, unknown GNC_HBCI_Transtype %d.\n",
trans_type);
HBCI_OutboxJobTransfer *transfer_job =
HBCI_OutboxJobTransfer_new (customer, h_acc, trans);
job = HBCI_OutboxJobTransfer_OutboxJob (transfer_job);
}
}
return job;
}
/* -------------------------------------- */
/* Callbacks */

View File

@ -24,7 +24,6 @@
#include "gnc-hbci-getbalance.h"
#include <openhbci/api.h>
#include <openhbci/outboxaccjobs.h>
#include "gnc-ui.h"
#include "gnc-numeric.h"
@ -36,6 +35,9 @@
#include "dialog-hbcitrans.h"
void gnc_hbci_getbalance_debugprint(HBCI_OutboxJobGetBalance *balance_job,
const HBCI_Account *h_acc);
static void
bal_print_debug(const char *name,
const HBCI_Value *val,
@ -61,13 +63,15 @@ gnc_hbci_getbalance (GtkWidget *parent, Account *gnc_acc)
if (gnc_acc == NULL)
return;
/* Get API */
api = gnc_hbci_api_new_currentbook (parent, &interactor);
if (api == NULL) {
printf("gnc_hbci_getbalance: Couldn't get HBCI API.\n");
return;
}
g_assert (interactor);
/* Get HBCI account */
h_acc = gnc_hbci_get_hbci_acc (api, gnc_acc);
if (h_acc == NULL) {
printf("gnc_hbci_getbalance: No HBCI account found.\n");
@ -76,29 +80,10 @@ gnc_hbci_getbalance (GtkWidget *parent, Account *gnc_acc)
/* printf("gnc_hbci_getbalance: HBCI account no. %s found.\n",
HBCI_Account_accountId (h_acc)); */
{
/* Get one customer. */
const list_HBCI_Customer *custlist;
list_HBCI_Customer_iter *iter;
custlist = HBCI_Account_authorizedCustomers (h_acc);
g_assert (custlist);
switch (list_HBCI_Customer_size (custlist)) {
case 0:
printf("gnc_hbci_getbalance: No HBCI customer found.\n");
return;
case 1:
break;
default:
gnc_warning_dialog_parented(gnc_ui_get_toplevel (),
"Sorry, Choosing one out of several HBCI Customers not yet implemented.");
return;
}
iter = list_HBCI_Customer_begin (custlist);
customer = list_HBCI_Customer_iter_get (iter);
list_HBCI_Customer_iter_delete (iter);
}
g_assert (customer);
/* Get the customer that should be doing this job. */
customer = gnc_hbci_get_first_customer(h_acc);
if (!customer)
return;
/* printf("gnc_hbci_getbalance: Customer id %s found.\n",
HBCI_Customer_custId ((HBCI_Customer *)customer)); */
@ -111,111 +96,152 @@ gnc_hbci_getbalance (GtkWidget *parent, Account *gnc_acc)
HBCI_OutboxJobGetBalance_new (customer, (HBCI_Account *)h_acc);
job = HBCI_OutboxJobGetBalance_OutboxJob (balance_job);
g_assert (job);
/* Add job to API queue */
HBCI_API_addJob (api, job);
/* Execute Outbox. */
if (!gnc_hbci_api_execute (parent, api, job, interactor)) {
/* HBCI_API_executeOutbox failed. */
HBCI_API_clearQueueByStatus (api, HBCI_JOB_STATUS_NONE);
return;
}
{
const HBCI_AccountBalance *acc_bal;
const HBCI_Balance *noted_bal, *booked_bal;
const HBCI_Value *booked_val;
gboolean booked_debit;
time_t balance_tt, noted_tt, booked_tt;
gboolean dialogres;
acc_bal = HBCI_OutboxJobGetBalance_getBalance (balance_job);
balance_tt =
HBCI_DateTime_to_time_t (HBCI_AccountBalance_date (acc_bal),
HBCI_AccountBalance_time (acc_bal));
gnc_hbci_getbalance_debugprint(balance_job, h_acc);
/* Finish this job. */
gnc_hbci_getbalance_finish (parent,
gnc_acc,
balance_job);
booked_bal = HBCI_AccountBalance_bookedBalance (acc_bal);
booked_tt = HBCI_DateTime_to_time_t (HBCI_Balance_date (booked_bal),
HBCI_Balance_time (booked_bal));
booked_val = HBCI_Balance_value (booked_bal);
booked_debit = HBCI_Balance_isDebit (booked_bal),
noted_bal = HBCI_AccountBalance_notedBalance (acc_bal);
noted_tt = HBCI_DateTime_to_time_t (HBCI_Balance_date (noted_bal),
HBCI_Balance_time (noted_bal));
printf("GetBalance: Balances for account %s :\n",
HBCI_Account_accountId (h_acc));
bal_print_debug("Booked balance",
booked_val,
booked_debit,
booked_tt);
bal_print_debug("Noted balance",
HBCI_Balance_value (noted_bal),
HBCI_Balance_isDebit (noted_bal),
noted_tt);
bal_print_debug("Bank Line",
HBCI_AccountBalance_bankLine (acc_bal), FALSE,
balance_tt);
bal_print_debug("Disposable amount",
HBCI_AccountBalance_disposable (acc_bal), FALSE,
balance_tt);
bal_print_debug("Already disposed",
HBCI_AccountBalance_disposed (acc_bal), FALSE,
balance_tt);
if ((HBCI_Value_getValue (HBCI_Balance_value (noted_bal)) == 0) &&
(HBCI_Value_getValue (HBCI_Balance_value (booked_bal)) == 0))
{
gnome_ok_dialog_parented
/* Translators: Strings from this file are really only
* needed inside Germany (HBCI is not supported anywhere
* else). You may safely ignore strings from the
* import-export/hbci subdirectory in other countries.
*/
(_("The downloaded HBCI Balance was zero.\n"
"It seems as if your bank does not support Balance download \n"
"in this HBCI version. You should choose a higher HBCI version \n"
"number in the HBCI Setup. After that, try again to download \n"
"the HBCI Balance.\n"),
GTK_WINDOW (parent));
dialogres = FALSE;
}
else
{
gboolean booked_debit = HBCI_Balance_isDebit (booked_bal);
char *booked_str = HBCI_Value_toReadableString (booked_val);
dialogres = gnc_verify_dialog_parented
(parent,
TRUE,
/* Translators: %s is the amount. */
_("Result of HBCI job: \n"
"Account booked balance is %s%s\n"
"Reconcile account now?"),
(booked_debit ? "-" : ""),
booked_str);
free (booked_str);
}
GNCInteractor_hide (interactor);
if (dialogres)
{
gnc_numeric abs_value =
double_to_gnc_numeric (HBCI_Value_getValue (booked_val),
xaccAccountGetCommoditySCU(gnc_acc),
GNC_RND_ROUND);
recnWindowWithBalance (parent,
gnc_acc,
(booked_debit
? gnc_numeric_neg (abs_value)
: abs_value),
booked_tt);
}
HBCI_API_clearQueueByStatus (api, HBCI_JOB_STATUS_NONE);
}
/* Clean up after ourselves. */
HBCI_API_clearQueueByStatus (api, HBCI_JOB_STATUS_NONE);
GNCInteractor_hide (interactor);
}
}
void gnc_hbci_getbalance_debugprint(HBCI_OutboxJobGetBalance *balance_job,
const HBCI_Account *h_acc)
{
const HBCI_AccountBalance *acc_bal;
const HBCI_Balance *noted_bal, *booked_bal;
time_t balance_tt, noted_tt, booked_tt;
acc_bal = HBCI_OutboxJobGetBalance_getBalance (balance_job);
balance_tt =
HBCI_DateTime_to_time_t (HBCI_AccountBalance_date (acc_bal),
HBCI_AccountBalance_time (acc_bal));
booked_bal = HBCI_AccountBalance_bookedBalance (acc_bal);
booked_tt = HBCI_DateTime_to_time_t (HBCI_Balance_date (booked_bal),
HBCI_Balance_time (booked_bal));
noted_bal = HBCI_AccountBalance_notedBalance (acc_bal);
noted_tt = HBCI_DateTime_to_time_t (HBCI_Balance_date (noted_bal),
HBCI_Balance_time (noted_bal));
printf("GetBalance: Balances for account %s :\n",
HBCI_Account_accountId (h_acc));
bal_print_debug("Booked balance",
HBCI_Balance_value (booked_bal),
HBCI_Balance_isDebit (booked_bal),
booked_tt);
bal_print_debug("Noted balance",
HBCI_Balance_value (noted_bal),
HBCI_Balance_isDebit (noted_bal),
noted_tt);
bal_print_debug("Bank Line",
HBCI_AccountBalance_bankLine (acc_bal), FALSE,
balance_tt);
bal_print_debug("Disposable amount",
HBCI_AccountBalance_disposable (acc_bal), FALSE,
balance_tt);
bal_print_debug("Already disposed",
HBCI_AccountBalance_disposed (acc_bal), FALSE,
balance_tt);
}
gboolean
gnc_hbci_getbalance_finish (GtkWidget *parent,
Account *gnc_acc,
const HBCI_OutboxJobGetBalance *balance_job)
{
const HBCI_AccountBalance *acc_bal;
const HBCI_Balance *noted_bal, *booked_bal;
const HBCI_Value *booked_val;
time_t booked_tt;
/*time_t balance_tt, noted_tt;*/
gboolean booked_debit;
gboolean dialogres;
acc_bal = HBCI_OutboxJobGetBalance_getBalance (balance_job);
/*balance_tt =
HBCI_DateTime_to_time_t (HBCI_AccountBalance_date (acc_bal),
HBCI_AccountBalance_time (acc_bal));*/
booked_bal = HBCI_AccountBalance_bookedBalance (acc_bal);
booked_tt = HBCI_DateTime_to_time_t (HBCI_Balance_date (booked_bal),
HBCI_Balance_time (booked_bal));
booked_val = HBCI_Balance_value (booked_bal);
booked_debit = HBCI_Balance_isDebit (booked_bal);
noted_bal = HBCI_AccountBalance_notedBalance (acc_bal);
/*noted_tt = HBCI_DateTime_to_time_t (HBCI_Balance_date (noted_bal),
HBCI_Balance_time (noted_bal));*/
if ((HBCI_Value_getValue (HBCI_Balance_value (noted_bal)) == 0) &&
(HBCI_Value_getValue (HBCI_Balance_value (booked_bal)) == 0))
{
gnome_ok_dialog_parented
/* Translators: Strings from this file are really only
* needed inside Germany (HBCI is not supported anywhere
* else). You may safely ignore strings from the
* import-export/hbci subdirectory in other countries.
*/
(_("The downloaded HBCI Balance was zero.\n"
"It seems as if your bank does not support Balance download \n"
"in this HBCI version. You should choose a higher HBCI version \n"
"number in the HBCI Setup. After that, try again to download \n"
"the HBCI Balance.\n"),
GTK_WINDOW (parent));
dialogres = FALSE;
}
else
{
char *booked_str = HBCI_Value_toReadableString (booked_val);
dialogres = gnc_verify_dialog_parented
(parent,
TRUE,
/* Translators: %s is the amount. */
_("Result of HBCI job: \n"
"Account booked balance is %s%s\n"
"Reconcile account now?"),
(booked_debit ? "-" : ""),
booked_str);
free (booked_str);
}
if (dialogres)
{
gnc_numeric abs_value =
double_to_gnc_numeric (HBCI_Value_getValue (booked_val),
xaccAccountGetCommoditySCU(gnc_acc),
GNC_RND_ROUND);
recnWindowWithBalance (parent,
gnc_acc,
(booked_debit
? gnc_numeric_neg (abs_value)
: abs_value),
booked_tt);
}
return TRUE;
}

View File

@ -25,10 +25,19 @@
#include <gnome.h>
#include "Account.h"
#include <openhbci/outboxaccjobs.h>
/** Starts a GetBalance job, adds the job to the HBCI_API, and
* (currently) calls executeOutbox. */
void
gnc_hbci_getbalance (GtkWidget *parent, Account *gnc_acc);
/** Finalizes all the things that have to be done with a GetBalance
* job. Returns true if everything has been finished succesfully. */
gboolean
gnc_hbci_getbalance_finish (GtkWidget *parent,
Account *gnc_acc,
const HBCI_OutboxJobGetBalance *balance_job);
#endif /* GNC_HBCI_GETBALANCE_H */

View File

@ -24,7 +24,6 @@
#include "gnc-hbci-gettrans.h"
#include <openhbci/api.h>
#include <openhbci/outboxaccjobs.h>
#include "gnc-ui.h"
#include "gnc-numeric.h"
@ -44,20 +43,20 @@
/* static short module = MOD_IMPORT; */
/*static const gboolean DEFAULT_USE_GENERIC_MATCHER = FALSE; */
gboolean
gettrans_dates(GtkWidget *parent, Account *gnc_acc,
HBCI_Date **from_date, HBCI_Date **to_date);
static void *trans_list_cb (const HBCI_Transaction *trans, void *user_data);
struct trans_list_data
{
Account *gnc_acc;
/*GNCGenTransaction *importer;*/
GNCImportMainMatcher *importer_generic;
/*gboolean use_generic_matcher;*/
};
void
gnc_hbci_gettrans (GtkWidget *parent, Account *gnc_acc)
{
@ -69,13 +68,15 @@ gnc_hbci_gettrans (GtkWidget *parent, Account *gnc_acc)
g_assert(parent);
g_assert(gnc_acc);
/* Get the api */
api = gnc_hbci_api_new_currentbook (parent, &interactor);
if (api == NULL) {
printf("gnc_hbci_gettrans: Couldn't get HBCI API.\n");
return;
}
g_assert (interactor);
/* Get the HBCI account */
h_acc = gnc_hbci_get_hbci_acc (api, gnc_acc);
if (h_acc == NULL) {
printf("gnc_hbci_gettrans: No HBCI account found.\n");
@ -83,30 +84,13 @@ gnc_hbci_gettrans (GtkWidget *parent, Account *gnc_acc)
}
/* printf("gnc_hbci_gettrans: HBCI account no. %s found.\n",
HBCI_Account_accountId (h_acc)); */
{
/* Get one customer. */
const list_HBCI_Customer *custlist;
list_HBCI_Customer_iter *iter;
custlist = HBCI_Account_authorizedCustomers (h_acc);
g_assert (custlist);
switch (list_HBCI_Customer_size (custlist)) {
case 0:
printf("gnc_hbci_gettrans: No HBCI customer found.\n");
return;
case 1:
break;
default:
gnc_warning_dialog_parented(gnc_ui_get_toplevel (),
"Sorry, Choosing one out of several HBCI Customers not yet implemented.");
return;
}
iter = list_HBCI_Customer_begin (custlist);
customer = list_HBCI_Customer_iter_get (iter);
list_HBCI_Customer_iter_delete (iter);
}
g_assert (customer);
/* Get the customer that should be doing this job. */
customer = gnc_hbci_get_first_customer(h_acc);
if (!customer)
return;
/* g_assert (customer); */
/* printf("gnc_hbci_gettrans: Customer id %s found.\n",
HBCI_Customer_custId ((HBCI_Customer *)customer)); */
@ -114,17 +98,69 @@ gnc_hbci_gettrans (GtkWidget *parent, Account *gnc_acc)
/* Execute a GetTransactions job. */
HBCI_OutboxJobGetTransactions *trans_job;
HBCI_OutboxJob *job;
Timespec last_timespec, until_timespec;
time_t now = time(NULL), time_convert;
struct tm tm;
Timespec until_timespec;
HBCI_Date *from_date, *to_date;
gboolean use_last_date = TRUE,
use_earliest_date = TRUE, use_until_now = TRUE;
/* Get time of last retrieval */
last_timespec = gnc_hbci_get_account_trans_retrieval (gnc_acc);
if (last_timespec.tv_sec == 0) {
use_last_date = FALSE;
/* Get the start and end dates for the Gettrans job. */
if (!gettrans_dates(parent, gnc_acc, &from_date, &to_date))
return;
/* Use this as a local storage for the until_time below. */
timespecFromTime_t(&until_timespec, HBCI_Date_to_time_t(to_date));
/* Create OutboxJob */
trans_job =
HBCI_OutboxJobGetTransactions_new (customer,
(HBCI_Account *)h_acc,
from_date,
to_date);
HBCI_Date_delete (from_date);
HBCI_Date_delete (to_date);
job = HBCI_OutboxJobGetTransactions_OutboxJob (trans_job);
g_assert (job);
/* Add job to HBCI_API queue. */
HBCI_API_addJob (api, job);
/* Execute Outbox. */
if (!gnc_hbci_api_execute (parent, api, job, interactor)) {
/* HBCI_API_executeOutbox failed. */
HBCI_API_clearQueueByStatus (api, HBCI_JOB_STATUS_NONE);
return;
}
/* Store the date of this retrieval */
gnc_hbci_set_account_trans_retrieval (gnc_acc, until_timespec);
/* Now finish the job duties. */
gnc_hbci_gettrans_final(parent, gnc_acc, trans_job, FALSE);
/* Clean up behind ourself. */
HBCI_API_clearQueueByStatus (api, HBCI_JOB_STATUS_NONE);
GNCInteractor_hide (interactor);
}
}
/** Create and set the from_date and to_date objects, and return TRUE
if they have been set. If FALSE is returned, then from_date and
to_date are not pointing to valid objects and may not be
deleted. */
gboolean
gettrans_dates(GtkWidget *parent, Account *gnc_acc,
HBCI_Date **from_date, HBCI_Date **to_date)
{
Timespec last_timespec, until_timespec;
time_t now = time(NULL), time_convert;
struct tm tm;
gboolean use_last_date = TRUE,
use_earliest_date = TRUE, use_until_now = TRUE;
g_assert(from_date);
g_assert(to_date);
/* Get time of last retrieval */
last_timespec = gnc_hbci_get_account_trans_retrieval (gnc_acc);
if (last_timespec.tv_sec == 0) {
use_last_date = FALSE;
timespecFromTime_t (&last_timespec, now);
}
timespecFromTime_t (&until_timespec, now);
@ -134,112 +170,73 @@ gnc_hbci_gettrans (GtkWidget *parent, Account *gnc_acc)
&last_timespec,
&use_last_date, &use_earliest_date,
&until_timespec, &use_until_now))
return;
return FALSE;
/*printf("Retrieving transactions from date %s to date %s. \n",
ctime(&()))*/
/* Now calculate from date */
if (use_earliest_date)
from_date = HBCI_Date_new_blank();
*from_date = HBCI_Date_new_blank();
else {
if (use_last_date)
last_timespec = gnc_hbci_get_account_trans_retrieval (gnc_acc);
time_convert = timespecToTime_t(last_timespec);
from_date = HBCI_Date_new (localtime_r (&time_convert, &tm));
*from_date = HBCI_Date_new (localtime_r (&time_convert, &tm));
}
/* Now calculate to date */
if (use_until_now)
timespecFromTime_t (&until_timespec, now);
time_convert = timespecToTime_t (until_timespec);
to_date = HBCI_Date_new (localtime_r (&time_convert, &tm));
*to_date = HBCI_Date_new (localtime_r (&time_convert, &tm));
/* Create OutboxJob */
trans_job =
HBCI_OutboxJobGetTransactions_new (customer,
(HBCI_Account *)h_acc,
from_date,
to_date);
job = HBCI_OutboxJobGetTransactions_OutboxJob (trans_job);
g_assert (job);
HBCI_API_addJob (api, job);
/* Execute Outbox. */
if (!gnc_hbci_api_execute (parent, api, job, interactor)) {
/* HBCI_API_executeOutbox failed. */
HBCI_Date_delete (from_date);
HBCI_Date_delete (to_date);
return;
}
HBCI_Date_delete (from_date);
HBCI_Date_delete (to_date);
/* Store the date of this retrieval */
gnc_hbci_set_account_trans_retrieval (gnc_acc, until_timespec);
{
/* Now add the retrieved transactions to the gnucash account. */
const list_HBCI_Transaction *trans_list;
trans_list = HBCI_OutboxJobGetTransactions_transactions (trans_job);
/*printf("gnc_hbci_gettrans: Got %d transactions.\n",
list_HBCI_Transaction_size(trans_list));*/
if (list_HBCI_Transaction_size(trans_list) > 0) {
struct trans_list_data data;
/*GNCGenTransaction *importer_gui = NULL;*/
GNCImportMainMatcher *importer_generic_gui = NULL;
/*data.use_generic_matcher =
gnc_lookup_boolean_option("Online Banking & Importing",
"HBCI Use generic import matcher",
DEFAULT_USE_GENERIC_MATCHER);
if(data.use_generic_matcher == TRUE)
{*/
importer_generic_gui = gnc_gen_trans_list_new(NULL, NULL, TRUE);
data.importer_generic = importer_generic_gui;
/* }
else
{
importer_gui = gnc_gen_trans_new (NULL, NULL);
gnc_gen_trans_freeze (importer_gui);
gnc_gen_trans_set_fuzzy_amount (importer_gui, 0.0);
data.importer = importer_gui;
}*/
data.gnc_acc = gnc_acc;
list_HBCI_Transaction_foreach (trans_list, trans_list_cb, &data);
/*if(data.use_generic_matcher == FALSE)
gnc_gen_trans_thaw (importer_gui);*/
GNCInteractor_hide (interactor);
/*if(data.use_generic_matcher == TRUE)*/
gnc_gen_trans_list_run (importer_generic_gui);
/*else
gnc_gen_trans_run (importer_gui);*/
}
else {
GNCInteractor_hide (interactor);
gnome_ok_dialog_parented
(_("The HBCI import returned no transactions for the selected time period."),
GTK_WINDOW (parent));
}
}
/* Clean up behind ourself. */
HBCI_API_clearQueueByStatus (api, HBCI_JOB_STATUS_NONE);
}
return TRUE;
}
/* list_HBCI_Transaction_foreach callback */
/** Finalizes all the things that have to be done with a GetTrans
* job. Returns true if everything has been finished succesfully. */
gboolean
gnc_hbci_gettrans_final(GtkWidget *parent,
Account *gnc_acc,
const HBCI_OutboxJobGetTransactions *trans_job,
gboolean run_until_done)
{
/* Now add the retrieved transactions to the gnucash account. */
const list_HBCI_Transaction *trans_list;
trans_list = HBCI_OutboxJobGetTransactions_transactions (trans_job);
/*printf("gnc_hbci_gettrans: Got %d transactions.\n",
list_HBCI_Transaction_size(trans_list));*/
if (list_HBCI_Transaction_size(trans_list) > 0) {
struct trans_list_data data;
GNCImportMainMatcher *importer_generic_gui =
gnc_gen_trans_list_new(NULL, NULL, TRUE);
data.importer_generic = importer_generic_gui;
data.gnc_acc = gnc_acc;
list_HBCI_Transaction_foreach (trans_list, trans_list_cb, &data);
if (run_until_done)
return gnc_gen_trans_list_run (importer_generic_gui);
}
else {
gnome_ok_dialog_parented
(_("The HBCI import returned no transactions for the selected time period."),
GTK_WINDOW (parent));
}
return TRUE;
}
/* list_HBCI_Transaction_foreach callback. The Conversion from HBCI to
GNC transaction is done here, once for each HBCI_Transaction. */
static void *trans_list_cb (const HBCI_Transaction *h_trans,
void *user_data)
{
@ -323,16 +320,8 @@ static void *trans_list_cb (const HBCI_Transaction *h_trans,
}
/* Instead of xaccTransCommitEdit(gnc_trans) */
/*gnc_import_add_trans(gnc_trans);*/
/*if(data->use_generic_matcher == TRUE)
{*/
g_assert (data->importer_generic);
gnc_gen_trans_list_add_trans (data->importer_generic, gnc_trans);
/*}
else
{
g_assert (data->importer);
gnc_gen_trans_add_trans (data->importer, gnc_trans);
}*/
return NULL;
}

View File

@ -24,9 +24,20 @@
#define GNC_HBCI_GETTRANS_H
#include <gnome.h>
#include <openhbci/outboxaccjobs.h>
#include "Account.h"
/** Start a GetTrans job. */
void
gnc_hbci_gettrans (GtkWidget *parent, Account *gnc_acc);
/** Finalizes all the things that have to be done with a GetTrans
* job. Returns true if everything has been finished succesfully. */
gboolean
gnc_hbci_gettrans_final(GtkWidget *parent,
Account *gnc_acc,
const HBCI_OutboxJobGetTransactions *trans_job,
gboolean run_until_done);
#endif /* GNC_HBCI_GETTRANS_H */

View File

@ -38,6 +38,10 @@
#include "gnc-hbci-kvp.h"
void maketrans_save_templates(GtkWidget *parent, Account *gnc_acc,
GList *template_list, gboolean dont_ask);
void
gnc_hbci_maketrans (GtkWidget *parent, Account *gnc_acc,
GNC_HBCI_Transtype trans_type)
@ -50,13 +54,15 @@ gnc_hbci_maketrans (GtkWidget *parent, Account *gnc_acc,
g_assert(parent);
g_assert(gnc_acc);
/* Get API */
api = gnc_hbci_api_new_currentbook (parent, &interactor);
if (api == NULL) {
printf("gnc_hbci_maketrans: Couldn't get HBCI API. Nothing will happen.\n");
return;
}
g_assert (interactor);
/* Get HBCI account */
h_acc = gnc_hbci_get_hbci_acc (api, gnc_acc);
if (h_acc == NULL) {
printf("gnc_hbci_maketrans: No HBCI account found. Nothing will happen.\n");
@ -65,31 +71,10 @@ gnc_hbci_maketrans (GtkWidget *parent, Account *gnc_acc,
/*printf("gnc_hbci_maketrans: HBCI account no. %s found.\n",
HBCI_Account_accountId (h_acc));*/
{
/* Get one customer. */
const list_HBCI_Customer *custlist;
list_HBCI_Customer_iter *iter;
custlist = HBCI_Account_authorizedCustomers (h_acc);
g_assert (custlist);
switch (list_HBCI_Customer_size (custlist)) {
case 0:
printf("gnc_hbci_maketrans: No HBCI customer found. Nothing will happen.\n");
return;
case 1:
break;
default:
gnc_warning_dialog_parented(gnc_ui_get_toplevel (),
"Sorry, Choosing one out of several HBCI Customers not yet implemented.");
return;
}
iter = list_HBCI_Customer_begin (custlist);
customer = list_HBCI_Customer_iter_get (iter);
list_HBCI_Customer_iter_delete (iter);
}
g_assert (customer);
/*printf("gnc_hbci_maketrans: Customer id %s found.\n",
HBCI_Customer_custId ((HBCI_Customer *)customer));*/
/* Get the customer that should be doing this job. */
customer = gnc_hbci_get_first_customer(h_acc);
if (!customer)
return;
{
GList *template_list =
@ -98,81 +83,109 @@ gnc_hbci_maketrans (GtkWidget *parent, Account *gnc_acc,
( xaccAccountGetBook(gnc_acc)));
unsigned nr_templates = g_list_length(template_list);
/* Now open the HBCI_trans_dialog. */
/* Now open the HBCI_trans_dialog, which also calls
HBCI_API_executeQueue. */
HBCI_Transaction *h_trans = gnc_hbci_trans (parent, api, interactor,
h_acc, customer,
gnc_acc,
trans_type, &template_list);
/* New templates? If yes, store them */
if (nr_templates < g_list_length(template_list)) {
if (h_trans || (gnc_verify_dialog_parented
(parent,
FALSE,
_("You have created a new online transfer template, but \n"
"you cancelled the transfer dialog. Do you nevertheless \n"
"want to store the new online transfer template?")))) {
GList *kvp_list = gnc_trans_templ_kvp_glist_from_glist (template_list);
/*printf ("Now having %d templates. List: '%s'\n",
g_list_length(template_list),
kvp_value_glist_to_string(kvp_list));*/
gnc_hbci_set_book_template_list
(xaccAccountGetBook(gnc_acc), kvp_list);
}
}
if (nr_templates < g_list_length(template_list))
maketrans_save_templates(parent, gnc_acc, template_list, (h_trans != NULL));
gnc_trans_templ_delete_glist (template_list);
if (!h_trans)
return;
/* GNCInteractor_hide (interactor); */
{
/* HBCI Transaction has finished, so now open the gnucash
transaction dialog and fill in all values. */
gnc_numeric amount;
XferDialog *transdialog;
transdialog = gnc_xfer_dialog (parent, gnc_acc);
switch (trans_type) {
case SINGLE_DEBITNOTE:
gnc_xfer_dialog_set_title (transdialog, _("Online HBCI Direct Debit Note"));
case SINGLE_TRANSFER:
default:
gnc_xfer_dialog_set_title (transdialog, _("Online HBCI Transaction"));
}
/* Amount */
amount = double_to_gnc_numeric
(HBCI_Value_getValue (HBCI_Transaction_value (h_trans)),
xaccAccountGetCommoditySCU(gnc_acc),
GNC_RND_ROUND);
/*switch (trans_type) {
case SINGLE_DEBITNOTE:
gnc_xfer_dialog_set_amount (transdialog, gnc_numeric_neg (amount));
case SINGLE_TRANSFER:
default:*/
gnc_xfer_dialog_set_amount (transdialog, amount);
/*}*/
/* gnc_xfer_dialog_toggle_currency_frame (transdialog, FALSE); */
/* HBCI Transaction has finished, so now open the gnucash
transaction dialog and fill in all values. */
gnc_hbci_maketrans_final (parent, gnc_acc, trans_type, h_trans, FALSE);
{
/* Description */
char *g_descr = gnc_hbci_descr_tognc (h_trans);
gnc_xfer_dialog_set_description (transdialog, g_descr);
g_free (g_descr);
}
{
/* Memo. */
char *g_memo = gnc_hbci_memo_tognc (h_trans);
gnc_xfer_dialog_set_memo (transdialog, g_memo);
g_free (g_memo);
}
/*gnc_xfer_dialog_set_date(XferDialog *xferData, time_t set_time)*/
}
/* Everything finished. */
HBCI_Transaction_delete (h_trans);
}
}
/** Store the template_list in the given Account gnc_acc. If dont_ask
is FALSE, first ask whether they really should be saved. */
void maketrans_save_templates(GtkWidget *parent, Account *gnc_acc,
GList *template_list, gboolean dont_ask)
{
if (dont_ask || gnc_verify_dialog_parented
(parent,
FALSE,
"%s",
_("You have created a new online transfer template, but \n"
"you cancelled the transfer dialog. Do you nevertheless \n"
"want to store the new online transfer template?"))) {
GList *kvp_list = gnc_trans_templ_kvp_glist_from_glist (template_list);
/*printf ("Now having %d templates. List: '%s'\n",
g_list_length(template_list),
kvp_value_glist_to_string(kvp_list));*/
gnc_hbci_set_book_template_list
(xaccAccountGetBook(gnc_acc), kvp_list);
}
}
gboolean
gnc_hbci_maketrans_final (GtkWidget *parent, Account *gnc_acc,
GNC_HBCI_Transtype trans_type,
const HBCI_Transaction *h_trans,
gboolean run_until_done)
{
/* HBCI Transaction has finished, so now open the gnucash
transaction dialog and fill in all values. */
gnc_numeric amount;
XferDialog *transdialog;
transdialog = gnc_xfer_dialog (parent, gnc_acc);
switch (trans_type) {
case SINGLE_DEBITNOTE:
gnc_xfer_dialog_set_title (transdialog, _("Online HBCI Direct Debit Note"));
case SINGLE_TRANSFER:
default:
gnc_xfer_dialog_set_title (transdialog, _("Online HBCI Transaction"));
}
/* Amount */
amount = double_to_gnc_numeric
(HBCI_Value_getValue (HBCI_Transaction_value (h_trans)),
xaccAccountGetCommoditySCU(gnc_acc),
GNC_RND_ROUND);
/*switch (trans_type) {
case SINGLE_DEBITNOTE:
gnc_xfer_dialog_set_amount (transdialog, gnc_numeric_neg (amount));
case SINGLE_TRANSFER:
default:*/
gnc_xfer_dialog_set_amount (transdialog, amount);
/*}*/
/* gnc_xfer_dialog_toggle_currency_frame (transdialog, FALSE); */
{
/* Description */
char *g_descr = gnc_hbci_descr_tognc (h_trans);
gnc_xfer_dialog_set_description (transdialog, g_descr);
g_free (g_descr);
}
{
/* Memo. */
char *g_memo = gnc_hbci_memo_tognc (h_trans);
gnc_xfer_dialog_set_memo (transdialog, g_memo);
g_free (g_memo);
}
/*gnc_xfer_dialog_set_date(XferDialog *xferData, time_t set_time)*/
/* Run the dialog until the user has either successfully completed the
* transaction (just clicking OK doesn't always count) or clicked Cancel.
* Return TRUE if the transaction was a success, FALSE otherwise.
*/
return run_until_done
? gnc_xfer_dialog_run_until_done( transdialog )
: TRUE;
}

View File

@ -24,6 +24,7 @@
#define GNC_HBCI_TRANSFER_H
#include <gnome.h>
#include <openhbci/transaction.h>
#include "Account.h"
#include "dialog-hbcitrans.h"
@ -31,6 +32,14 @@ void
gnc_hbci_maketrans (GtkWidget *parent, Account *gnc_acc,
GNC_HBCI_Transtype trans_type);
/** Open a gnucash transfer dialog for gnucash Account gnc_acc and
* fill in all the values from the HBCI_Transaction h_trans. Returns
* TRUE if the gnucash transaction has been successfully created. */
gboolean
gnc_hbci_maketrans_final (GtkWidget *parent, Account *gnc_acc,
GNC_HBCI_Transtype trans_type,
const HBCI_Transaction *h_trans,
gboolean run_until_done);
#endif /* GNC_HBCI_TRANSFER_H */

View File

@ -532,3 +532,32 @@ char *gnc_hbci_memo_tognc (const HBCI_Transaction *h_trans)
return g_memo;
}
/** Return the only customer that can act on the specified account, or
NULL if none was found. */
const HBCI_Customer *
gnc_hbci_get_first_customer(const HBCI_Account *h_acc)
{
/* Get one customer. */
const list_HBCI_Customer *custlist;
list_HBCI_Customer_iter *iter;
const HBCI_Customer *customer;
custlist = HBCI_Account_authorizedCustomers (h_acc);
g_assert (custlist);
switch (list_HBCI_Customer_size (custlist)) {
case 0:
printf("gnc_hbci_get_first_customer: No HBCI customer found.\n");
return NULL;
case 1:
break;
default:
gnc_warning_dialog_parented(gnc_ui_get_toplevel (),
"Sorry, Choosing one out of several HBCI Customers not yet implemented.");
return NULL;
}
iter = list_HBCI_Customer_begin (custlist);
customer = list_HBCI_Customer_iter_get (iter);
list_HBCI_Customer_iter_delete (iter);
return customer;
}

View File

@ -117,5 +117,11 @@ char *gnc_hbci_descr_tognc (const HBCI_Transaction *h_trans);
* string must be g_free'd by the caller. */
char *gnc_hbci_memo_tognc (const HBCI_Transaction *h_trans);
/** Return the first customer that can act on the specified account,
or NULL if none was found (and an error message is printed on
stdout). */
const HBCI_Customer *
gnc_hbci_get_first_customer(const HBCI_Account *h_acc);
#endif