mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
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:
parent
bed1d91aa9
commit
7149c52213
@ -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>
|
2003-06-23 David Hampton <hampton@employees.org>
|
||||||
|
|
||||||
* src/gnome-utils/dialog-account.c: Limit the commodity choices
|
* src/gnome-utils/dialog-account.c: Limit the commodity choices
|
||||||
|
@ -74,6 +74,7 @@ struct _trans_data
|
|||||||
};
|
};
|
||||||
typedef struct _trans_data TransData;
|
typedef struct _trans_data TransData;
|
||||||
|
|
||||||
|
|
||||||
static void TransData_delete_helper(TransData *td)
|
static void TransData_delete_helper(TransData *td)
|
||||||
{
|
{
|
||||||
if (!td) return;
|
if (!td) return;
|
||||||
@ -88,6 +89,17 @@ static void TransData_delete_helper(TransData *td)
|
|||||||
/* Prototypes; callbacks for dialog function */
|
/* 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 template_selection_cb(GtkButton *b, gpointer user_data);
|
||||||
void add_template_cb(GtkButton *b, gpointer user_data);
|
void add_template_cb(GtkButton *b, gpointer user_data);
|
||||||
void blz_changed_cb(GtkEditable *e, 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 */
|
/* Make sure to show the dialog here */
|
||||||
gtk_widget_show_all (dialog);
|
gtk_widget_show_all (dialog);
|
||||||
|
|
||||||
|
/* Now run the dialog until it gets closed by a button press. */
|
||||||
result = gnome_dialog_run (GNOME_DIALOG (dialog));
|
result = gnome_dialog_run (GNOME_DIALOG (dialog));
|
||||||
/* printf("hbci_trans: result button was %d.\n", result); */
|
/* printf("hbci_trans: result button was %d.\n", result); */
|
||||||
|
|
||||||
/* The dialog gets hidden anyway as soon as any button is pressed. */
|
/* The dialog gets hidden anyway as soon as any button is pressed. */
|
||||||
gtk_widget_hide_all (dialog);
|
gtk_widget_hide_all (dialog);
|
||||||
|
|
||||||
|
/* Set the template list in case the dialog got cancelled. */
|
||||||
*templ = td.templ;
|
*templ = td.templ;
|
||||||
|
|
||||||
/* Was cancel pressed or dialog closed? 0 == execute now, 1 ==
|
/* Was cancel pressed or dialog closed? 0 == execute now, 1 ==
|
||||||
@ -311,41 +325,11 @@ gnc_hbci_trans (GtkWidget *parent,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fill in the user-entered values */
|
/* Now fill in the values from the entry fields into a new
|
||||||
trans = HBCI_Transaction_new();
|
HBCI_Transaction. */
|
||||||
|
trans = hbci_trans_fill_values(h_acc, &td);
|
||||||
values_ok = TRUE;
|
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",
|
/*printf("dialog-hbcitrans: Got value as %s .\n",
|
||||||
HBCI_Value_toReadableString (HBCI_Transaction_value (trans)));*/
|
HBCI_Value_toReadableString (HBCI_Transaction_value (trans)));*/
|
||||||
if (HBCI_Value_getValue (HBCI_Transaction_value (trans)) == 0.0) {
|
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
|
values_ok = !gnc_verify_dialog_parented
|
||||||
(GTK_WIDGET (dialog),
|
(GTK_WIDGET (dialog),
|
||||||
TRUE,
|
TRUE,
|
||||||
|
"%s",
|
||||||
_("The amount is zero or the amount field could not be \n"
|
_("The amount is zero or the amount field could not be \n"
|
||||||
"interpreted correctly. You might have mixed up decimal \n"
|
"interpreted correctly. You might have mixed up decimal \n"
|
||||||
"point and comma, compared to your locale settings. \n"
|
"point and comma, compared to your locale settings. \n"
|
||||||
@ -368,20 +353,143 @@ gnc_hbci_trans (GtkWidget *parent,
|
|||||||
continue;
|
continue;
|
||||||
} /* check Transaction_value */
|
} /* check Transaction_value */
|
||||||
|
|
||||||
#if HAVE_KTOBLZCHECK_H
|
/* 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);
|
||||||
|
|
||||||
{
|
{
|
||||||
|
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);
|
||||||
|
|
||||||
|
/* Add job to queue */
|
||||||
|
HBCI_API_addJob (api, job);
|
||||||
|
|
||||||
|
if (result == 0) {
|
||||||
|
|
||||||
|
/* If the user pressed "execute now", then execute this job now. */
|
||||||
|
successful = gnc_hbci_api_execute (parent, api, job, interactor);
|
||||||
|
|
||||||
|
/*printf("dialog-hbcitrans: Ok, result of api_execute was %d.\n",
|
||||||
|
successful);*/
|
||||||
|
|
||||||
|
if (!successful) {
|
||||||
|
/* HBCI_API_executeOutbox failed. */
|
||||||
|
if ((HBCI_OutboxJob_status (job) == HBCI_JOB_STATUS_DONE) &&
|
||||||
|
(HBCI_OutboxJob_result (job) == HBCI_JOB_RESULT_FAILED))
|
||||||
|
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"
|
||||||
|
"bank. The line with the error message contains a \n"
|
||||||
|
"code number that is greater than 9000.\n"
|
||||||
|
"\n"
|
||||||
|
"Do you want to enter the job again?"));
|
||||||
|
|
||||||
|
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 */
|
||||||
|
else {
|
||||||
|
/* huh? Only result == 0 should be possible. Simply ignore
|
||||||
|
this case. */
|
||||||
|
break;
|
||||||
|
} /* result == 0 */
|
||||||
|
|
||||||
|
} /* Create a do-transaction (transfer) job */
|
||||||
|
|
||||||
|
} while (!successful);
|
||||||
|
|
||||||
|
} /* GtkWidget declarations/definitions */
|
||||||
|
|
||||||
|
HBCI_API_clearQueueByStatus (api, HBCI_JOB_STATUS_NONE);
|
||||||
|
gtk_widget_destroy (GTK_WIDGET (dialog));
|
||||||
|
TransData_delete_helper(&td);
|
||||||
|
return trans;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** 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;
|
int blzresult;
|
||||||
const char *blztext;
|
const char *blztext;
|
||||||
|
gboolean values_ok = TRUE;
|
||||||
|
|
||||||
blzresult = AccountNumberCheck_check
|
blzresult = AccountNumberCheck_check
|
||||||
(td.blzcheck,
|
(td->blzcheck,
|
||||||
HBCI_Transaction_otherBankCode (trans),
|
HBCI_Transaction_otherBankCode (trans),
|
||||||
HBCI_Transaction_otherAccountId (trans));
|
HBCI_Transaction_otherAccountId (trans));
|
||||||
switch (blzresult) {
|
switch (blzresult) {
|
||||||
case 2:
|
case 2:
|
||||||
gtk_widget_show_all (dialog);
|
gtk_widget_show_all (parent);
|
||||||
values_ok = gnc_verify_dialog_parented
|
values_ok = gnc_verify_dialog_parented
|
||||||
(GTK_WIDGET (dialog),
|
(parent,
|
||||||
TRUE,
|
TRUE,
|
||||||
_("The internal check of the destination account number '%s' \n"
|
_("The internal check of the destination account number '%s' \n"
|
||||||
"at the specified bank with bank code '%s' failed. This means \n"
|
"at the specified bank with bank code '%s' failed. This means \n"
|
||||||
@ -405,92 +513,51 @@ gnc_hbci_trans (GtkWidget *parent,
|
|||||||
|
|
||||||
printf("gnc_hbci_trans: KtoBlzCheck said check is %d = %s\n",
|
printf("gnc_hbci_trans: KtoBlzCheck said check is %d = %s\n",
|
||||||
blzresult, blztext);
|
blzresult, blztext);
|
||||||
}
|
return values_ok;
|
||||||
|
#else
|
||||||
|
return TRUE;
|
||||||
#endif
|
#endif
|
||||||
} while (!values_ok);
|
}
|
||||||
|
|
||||||
/* Make really sure the dialog is hidden now. */
|
/** Create and return the HBCI_OutboxJob according to the given
|
||||||
gtk_widget_hide_all (dialog);
|
trans_type. */
|
||||||
|
HBCI_OutboxJob *
|
||||||
{
|
hbci_trans_create_outboxjob(const HBCI_Customer *customer,
|
||||||
/* Create a Do-Transaction (Transfer) job. */
|
HBCI_Account *h_acc,
|
||||||
HBCI_OutboxJobTransfer *transfer_job;
|
const HBCI_Transaction *trans,
|
||||||
HBCI_OutboxJobDebitNote *debit_job;
|
GNC_HBCI_Transtype trans_type)
|
||||||
|
{
|
||||||
HBCI_OutboxJob *job = NULL;
|
HBCI_OutboxJob *job = NULL;
|
||||||
|
|
||||||
switch (trans_type) {
|
switch (trans_type) {
|
||||||
case SINGLE_DEBITNOTE:
|
case SINGLE_DEBITNOTE:
|
||||||
debit_job =
|
{
|
||||||
HBCI_OutboxJobDebitNote_new (customer, (HBCI_Account *)h_acc, trans);
|
HBCI_OutboxJobDebitNote *debit_job =
|
||||||
|
HBCI_OutboxJobDebitNote_new (customer, h_acc, trans);
|
||||||
job = HBCI_OutboxJobDebitNote_OutboxJob (debit_job);
|
job = HBCI_OutboxJobDebitNote_OutboxJob (debit_job);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case SINGLE_TRANSFER:
|
case SINGLE_TRANSFER:
|
||||||
transfer_job =
|
{
|
||||||
HBCI_OutboxJobTransfer_new (customer, (HBCI_Account *)h_acc, trans);
|
HBCI_OutboxJobTransfer *transfer_job =
|
||||||
|
HBCI_OutboxJobTransfer_new (customer, h_acc, trans);
|
||||||
job = HBCI_OutboxJobTransfer_OutboxJob (transfer_job);
|
job = HBCI_OutboxJobTransfer_OutboxJob (transfer_job);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
{
|
||||||
printf("dialog-hbcitrans: Oops, unknown GNC_HBCI_Transtype %d.\n",
|
printf("dialog-hbcitrans: Oops, unknown GNC_HBCI_Transtype %d.\n",
|
||||||
trans_type);
|
trans_type);
|
||||||
transfer_job =
|
HBCI_OutboxJobTransfer *transfer_job =
|
||||||
HBCI_OutboxJobTransfer_new (customer, (HBCI_Account *)h_acc, trans);
|
HBCI_OutboxJobTransfer_new (customer, h_acc, trans);
|
||||||
job = HBCI_OutboxJobTransfer_OutboxJob (transfer_job);
|
job = HBCI_OutboxJobTransfer_OutboxJob (transfer_job);
|
||||||
}
|
}
|
||||||
|
|
||||||
HBCI_API_clearQueueByStatus (api, HBCI_JOB_STATUS_NONE);
|
|
||||||
|
|
||||||
g_assert (job);
|
|
||||||
HBCI_API_addJob (api, job);
|
|
||||||
|
|
||||||
if (result == 0) {
|
|
||||||
|
|
||||||
/* If the user pressed "execute now", then execute this job now. */
|
|
||||||
successful = gnc_hbci_api_execute (parent, api, job, interactor);
|
|
||||||
|
|
||||||
/*printf("dialog-hbcitrans: Ok, result of api_execute was %d.\n",
|
|
||||||
successful);*/
|
|
||||||
|
|
||||||
if (!successful) {
|
|
||||||
/* HBCI_API_executeOutbox failed. */
|
|
||||||
if ((HBCI_OutboxJob_status (job) == HBCI_JOB_STATUS_DONE) &&
|
|
||||||
(HBCI_OutboxJob_result (job) == HBCI_JOB_RESULT_FAILED))
|
|
||||||
successful = !gnc_verify_dialog_parented
|
|
||||||
(parent,
|
|
||||||
FALSE,
|
|
||||||
_("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"
|
|
||||||
"bank. The line with the error message contains a \n"
|
|
||||||
"code number that is greater than 9000.\n"
|
|
||||||
"\n"
|
|
||||||
"Do you want to enter the job again?"));
|
|
||||||
|
|
||||||
HBCI_Transaction_delete (trans);
|
|
||||||
trans = NULL;
|
|
||||||
HBCI_API_clearQueueByStatus (api, HBCI_JOB_STATUS_NONE);
|
|
||||||
}
|
}
|
||||||
} /* result == 0 */
|
return job;
|
||||||
else {
|
|
||||||
/* huh? Only result == 0 should be possible. Simply ignore
|
|
||||||
this case. */
|
|
||||||
break;
|
|
||||||
} /* result == 0 */
|
|
||||||
|
|
||||||
} /* Create a do-transaction (transfer) job */
|
|
||||||
|
|
||||||
} while (!successful);
|
|
||||||
|
|
||||||
} /* GtkWidget declarations/definitions */
|
|
||||||
|
|
||||||
HBCI_API_clearQueueByStatus (api, HBCI_JOB_STATUS_NONE);
|
|
||||||
gtk_widget_destroy (GTK_WIDGET (dialog));
|
|
||||||
TransData_delete_helper(&td);
|
|
||||||
return trans;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* -------------------------------------- */
|
/* -------------------------------------- */
|
||||||
/* Callbacks */
|
/* Callbacks */
|
||||||
/* -------------------------------------- */
|
/* -------------------------------------- */
|
||||||
|
@ -24,7 +24,6 @@
|
|||||||
#include "gnc-hbci-getbalance.h"
|
#include "gnc-hbci-getbalance.h"
|
||||||
|
|
||||||
#include <openhbci/api.h>
|
#include <openhbci/api.h>
|
||||||
#include <openhbci/outboxaccjobs.h>
|
|
||||||
|
|
||||||
#include "gnc-ui.h"
|
#include "gnc-ui.h"
|
||||||
#include "gnc-numeric.h"
|
#include "gnc-numeric.h"
|
||||||
@ -36,6 +35,9 @@
|
|||||||
#include "dialog-hbcitrans.h"
|
#include "dialog-hbcitrans.h"
|
||||||
|
|
||||||
|
|
||||||
|
void gnc_hbci_getbalance_debugprint(HBCI_OutboxJobGetBalance *balance_job,
|
||||||
|
const HBCI_Account *h_acc);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
bal_print_debug(const char *name,
|
bal_print_debug(const char *name,
|
||||||
const HBCI_Value *val,
|
const HBCI_Value *val,
|
||||||
@ -61,6 +63,7 @@ gnc_hbci_getbalance (GtkWidget *parent, Account *gnc_acc)
|
|||||||
if (gnc_acc == NULL)
|
if (gnc_acc == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
/* Get API */
|
||||||
api = gnc_hbci_api_new_currentbook (parent, &interactor);
|
api = gnc_hbci_api_new_currentbook (parent, &interactor);
|
||||||
if (api == NULL) {
|
if (api == NULL) {
|
||||||
printf("gnc_hbci_getbalance: Couldn't get HBCI API.\n");
|
printf("gnc_hbci_getbalance: Couldn't get HBCI API.\n");
|
||||||
@ -68,6 +71,7 @@ gnc_hbci_getbalance (GtkWidget *parent, Account *gnc_acc)
|
|||||||
}
|
}
|
||||||
g_assert (interactor);
|
g_assert (interactor);
|
||||||
|
|
||||||
|
/* Get HBCI account */
|
||||||
h_acc = gnc_hbci_get_hbci_acc (api, gnc_acc);
|
h_acc = gnc_hbci_get_hbci_acc (api, gnc_acc);
|
||||||
if (h_acc == NULL) {
|
if (h_acc == NULL) {
|
||||||
printf("gnc_hbci_getbalance: No HBCI account found.\n");
|
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",
|
/* printf("gnc_hbci_getbalance: HBCI account no. %s found.\n",
|
||||||
HBCI_Account_accountId (h_acc)); */
|
HBCI_Account_accountId (h_acc)); */
|
||||||
|
|
||||||
{
|
/* Get the customer that should be doing this job. */
|
||||||
/* Get one customer. */
|
customer = gnc_hbci_get_first_customer(h_acc);
|
||||||
const list_HBCI_Customer *custlist;
|
if (!customer)
|
||||||
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;
|
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_getbalance: Customer id %s found.\n",
|
/* printf("gnc_hbci_getbalance: Customer id %s found.\n",
|
||||||
HBCI_Customer_custId ((HBCI_Customer *)customer)); */
|
HBCI_Customer_custId ((HBCI_Customer *)customer)); */
|
||||||
|
|
||||||
@ -111,22 +96,39 @@ gnc_hbci_getbalance (GtkWidget *parent, Account *gnc_acc)
|
|||||||
HBCI_OutboxJobGetBalance_new (customer, (HBCI_Account *)h_acc);
|
HBCI_OutboxJobGetBalance_new (customer, (HBCI_Account *)h_acc);
|
||||||
job = HBCI_OutboxJobGetBalance_OutboxJob (balance_job);
|
job = HBCI_OutboxJobGetBalance_OutboxJob (balance_job);
|
||||||
g_assert (job);
|
g_assert (job);
|
||||||
|
|
||||||
|
/* Add job to API queue */
|
||||||
HBCI_API_addJob (api, job);
|
HBCI_API_addJob (api, job);
|
||||||
|
|
||||||
/* Execute Outbox. */
|
/* Execute Outbox. */
|
||||||
if (!gnc_hbci_api_execute (parent, api, job, interactor)) {
|
if (!gnc_hbci_api_execute (parent, api, job, interactor)) {
|
||||||
|
|
||||||
/* HBCI_API_executeOutbox failed. */
|
/* HBCI_API_executeOutbox failed. */
|
||||||
|
HBCI_API_clearQueueByStatus (api, HBCI_JOB_STATUS_NONE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
gnc_hbci_getbalance_debugprint(balance_job, h_acc);
|
||||||
|
|
||||||
|
/* Finish this job. */
|
||||||
|
gnc_hbci_getbalance_finish (parent,
|
||||||
|
gnc_acc,
|
||||||
|
balance_job);
|
||||||
|
|
||||||
|
/* 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_AccountBalance *acc_bal;
|
||||||
const HBCI_Balance *noted_bal, *booked_bal;
|
const HBCI_Balance *noted_bal, *booked_bal;
|
||||||
const HBCI_Value *booked_val;
|
|
||||||
gboolean booked_debit;
|
|
||||||
time_t balance_tt, noted_tt, booked_tt;
|
time_t balance_tt, noted_tt, booked_tt;
|
||||||
gboolean dialogres;
|
|
||||||
|
|
||||||
acc_bal = HBCI_OutboxJobGetBalance_getBalance (balance_job);
|
acc_bal = HBCI_OutboxJobGetBalance_getBalance (balance_job);
|
||||||
balance_tt =
|
balance_tt =
|
||||||
@ -136,8 +138,6 @@ gnc_hbci_getbalance (GtkWidget *parent, Account *gnc_acc)
|
|||||||
booked_bal = HBCI_AccountBalance_bookedBalance (acc_bal);
|
booked_bal = HBCI_AccountBalance_bookedBalance (acc_bal);
|
||||||
booked_tt = HBCI_DateTime_to_time_t (HBCI_Balance_date (booked_bal),
|
booked_tt = HBCI_DateTime_to_time_t (HBCI_Balance_date (booked_bal),
|
||||||
HBCI_Balance_time (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_bal = HBCI_AccountBalance_notedBalance (acc_bal);
|
||||||
noted_tt = HBCI_DateTime_to_time_t (HBCI_Balance_date (noted_bal),
|
noted_tt = HBCI_DateTime_to_time_t (HBCI_Balance_date (noted_bal),
|
||||||
@ -146,8 +146,8 @@ gnc_hbci_getbalance (GtkWidget *parent, Account *gnc_acc)
|
|||||||
printf("GetBalance: Balances for account %s :\n",
|
printf("GetBalance: Balances for account %s :\n",
|
||||||
HBCI_Account_accountId (h_acc));
|
HBCI_Account_accountId (h_acc));
|
||||||
bal_print_debug("Booked balance",
|
bal_print_debug("Booked balance",
|
||||||
booked_val,
|
HBCI_Balance_value (booked_bal),
|
||||||
booked_debit,
|
HBCI_Balance_isDebit (booked_bal),
|
||||||
booked_tt);
|
booked_tt);
|
||||||
bal_print_debug("Noted balance",
|
bal_print_debug("Noted balance",
|
||||||
HBCI_Balance_value (noted_bal),
|
HBCI_Balance_value (noted_bal),
|
||||||
@ -162,6 +162,37 @@ gnc_hbci_getbalance (GtkWidget *parent, Account *gnc_acc)
|
|||||||
bal_print_debug("Already disposed",
|
bal_print_debug("Already disposed",
|
||||||
HBCI_AccountBalance_disposed (acc_bal), FALSE,
|
HBCI_AccountBalance_disposed (acc_bal), FALSE,
|
||||||
balance_tt);
|
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) &&
|
if ((HBCI_Value_getValue (HBCI_Balance_value (noted_bal)) == 0) &&
|
||||||
(HBCI_Value_getValue (HBCI_Balance_value (booked_bal)) == 0))
|
(HBCI_Value_getValue (HBCI_Balance_value (booked_bal)) == 0))
|
||||||
@ -182,7 +213,6 @@ gnc_hbci_getbalance (GtkWidget *parent, Account *gnc_acc)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
gboolean booked_debit = HBCI_Balance_isDebit (booked_bal);
|
|
||||||
char *booked_str = HBCI_Value_toReadableString (booked_val);
|
char *booked_str = HBCI_Value_toReadableString (booked_val);
|
||||||
|
|
||||||
dialogres = gnc_verify_dialog_parented
|
dialogres = gnc_verify_dialog_parented
|
||||||
@ -199,7 +229,6 @@ gnc_hbci_getbalance (GtkWidget *parent, Account *gnc_acc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
GNCInteractor_hide (interactor);
|
|
||||||
if (dialogres)
|
if (dialogres)
|
||||||
{
|
{
|
||||||
gnc_numeric abs_value =
|
gnc_numeric abs_value =
|
||||||
@ -214,8 +243,5 @@ gnc_hbci_getbalance (GtkWidget *parent, Account *gnc_acc)
|
|||||||
booked_tt);
|
booked_tt);
|
||||||
}
|
}
|
||||||
|
|
||||||
HBCI_API_clearQueueByStatus (api, HBCI_JOB_STATUS_NONE);
|
return TRUE;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,10 +25,19 @@
|
|||||||
|
|
||||||
#include <gnome.h>
|
#include <gnome.h>
|
||||||
#include "Account.h"
|
#include "Account.h"
|
||||||
|
#include <openhbci/outboxaccjobs.h>
|
||||||
|
|
||||||
|
/** Starts a GetBalance job, adds the job to the HBCI_API, and
|
||||||
|
* (currently) calls executeOutbox. */
|
||||||
void
|
void
|
||||||
gnc_hbci_getbalance (GtkWidget *parent, Account *gnc_acc);
|
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 */
|
#endif /* GNC_HBCI_GETBALANCE_H */
|
||||||
|
@ -24,7 +24,6 @@
|
|||||||
#include "gnc-hbci-gettrans.h"
|
#include "gnc-hbci-gettrans.h"
|
||||||
|
|
||||||
#include <openhbci/api.h>
|
#include <openhbci/api.h>
|
||||||
#include <openhbci/outboxaccjobs.h>
|
|
||||||
|
|
||||||
#include "gnc-ui.h"
|
#include "gnc-ui.h"
|
||||||
#include "gnc-numeric.h"
|
#include "gnc-numeric.h"
|
||||||
@ -44,20 +43,20 @@
|
|||||||
|
|
||||||
/* static short module = MOD_IMPORT; */
|
/* 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);
|
static void *trans_list_cb (const HBCI_Transaction *trans, void *user_data);
|
||||||
|
|
||||||
struct trans_list_data
|
struct trans_list_data
|
||||||
{
|
{
|
||||||
Account *gnc_acc;
|
Account *gnc_acc;
|
||||||
/*GNCGenTransaction *importer;*/
|
|
||||||
GNCImportMainMatcher *importer_generic;
|
GNCImportMainMatcher *importer_generic;
|
||||||
/*gboolean use_generic_matcher;*/
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
gnc_hbci_gettrans (GtkWidget *parent, Account *gnc_acc)
|
gnc_hbci_gettrans (GtkWidget *parent, Account *gnc_acc)
|
||||||
{
|
{
|
||||||
@ -69,6 +68,7 @@ gnc_hbci_gettrans (GtkWidget *parent, Account *gnc_acc)
|
|||||||
g_assert(parent);
|
g_assert(parent);
|
||||||
g_assert(gnc_acc);
|
g_assert(gnc_acc);
|
||||||
|
|
||||||
|
/* Get the api */
|
||||||
api = gnc_hbci_api_new_currentbook (parent, &interactor);
|
api = gnc_hbci_api_new_currentbook (parent, &interactor);
|
||||||
if (api == NULL) {
|
if (api == NULL) {
|
||||||
printf("gnc_hbci_gettrans: Couldn't get HBCI API.\n");
|
printf("gnc_hbci_gettrans: Couldn't get HBCI API.\n");
|
||||||
@ -76,6 +76,7 @@ gnc_hbci_gettrans (GtkWidget *parent, Account *gnc_acc)
|
|||||||
}
|
}
|
||||||
g_assert (interactor);
|
g_assert (interactor);
|
||||||
|
|
||||||
|
/* Get the HBCI account */
|
||||||
h_acc = gnc_hbci_get_hbci_acc (api, gnc_acc);
|
h_acc = gnc_hbci_get_hbci_acc (api, gnc_acc);
|
||||||
if (h_acc == NULL) {
|
if (h_acc == NULL) {
|
||||||
printf("gnc_hbci_gettrans: No HBCI account found.\n");
|
printf("gnc_hbci_gettrans: No HBCI account found.\n");
|
||||||
@ -84,29 +85,12 @@ gnc_hbci_gettrans (GtkWidget *parent, Account *gnc_acc)
|
|||||||
/* printf("gnc_hbci_gettrans: HBCI account no. %s found.\n",
|
/* printf("gnc_hbci_gettrans: HBCI account no. %s found.\n",
|
||||||
HBCI_Account_accountId (h_acc)); */
|
HBCI_Account_accountId (h_acc)); */
|
||||||
|
|
||||||
{
|
/* Get the customer that should be doing this job. */
|
||||||
/* Get one customer. */
|
customer = gnc_hbci_get_first_customer(h_acc);
|
||||||
const list_HBCI_Customer *custlist;
|
if (!customer)
|
||||||
list_HBCI_Customer_iter *iter;
|
return;
|
||||||
|
|
||||||
custlist = HBCI_Account_authorizedCustomers (h_acc);
|
/* g_assert (customer); */
|
||||||
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);
|
|
||||||
/* printf("gnc_hbci_gettrans: Customer id %s found.\n",
|
/* printf("gnc_hbci_gettrans: Customer id %s found.\n",
|
||||||
HBCI_Customer_custId ((HBCI_Customer *)customer)); */
|
HBCI_Customer_custId ((HBCI_Customer *)customer)); */
|
||||||
|
|
||||||
@ -114,13 +98,65 @@ gnc_hbci_gettrans (GtkWidget *parent, Account *gnc_acc)
|
|||||||
/* Execute a GetTransactions job. */
|
/* Execute a GetTransactions job. */
|
||||||
HBCI_OutboxJobGetTransactions *trans_job;
|
HBCI_OutboxJobGetTransactions *trans_job;
|
||||||
HBCI_OutboxJob *job;
|
HBCI_OutboxJob *job;
|
||||||
|
Timespec until_timespec;
|
||||||
|
HBCI_Date *from_date, *to_date;
|
||||||
|
|
||||||
|
/* 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;
|
Timespec last_timespec, until_timespec;
|
||||||
time_t now = time(NULL), time_convert;
|
time_t now = time(NULL), time_convert;
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
HBCI_Date *from_date, *to_date;
|
|
||||||
gboolean use_last_date = TRUE,
|
gboolean use_last_date = TRUE,
|
||||||
use_earliest_date = TRUE, use_until_now = TRUE;
|
use_earliest_date = TRUE, use_until_now = TRUE;
|
||||||
|
|
||||||
|
g_assert(from_date);
|
||||||
|
g_assert(to_date);
|
||||||
/* Get time of last retrieval */
|
/* Get time of last retrieval */
|
||||||
last_timespec = gnc_hbci_get_account_trans_retrieval (gnc_acc);
|
last_timespec = gnc_hbci_get_account_trans_retrieval (gnc_acc);
|
||||||
if (last_timespec.tv_sec == 0) {
|
if (last_timespec.tv_sec == 0) {
|
||||||
@ -134,53 +170,39 @@ gnc_hbci_gettrans (GtkWidget *parent, Account *gnc_acc)
|
|||||||
&last_timespec,
|
&last_timespec,
|
||||||
&use_last_date, &use_earliest_date,
|
&use_last_date, &use_earliest_date,
|
||||||
&until_timespec, &use_until_now))
|
&until_timespec, &use_until_now))
|
||||||
return;
|
return FALSE;
|
||||||
|
|
||||||
/*printf("Retrieving transactions from date %s to date %s. \n",
|
/*printf("Retrieving transactions from date %s to date %s. \n",
|
||||||
ctime(&()))*/
|
ctime(&()))*/
|
||||||
|
|
||||||
/* Now calculate from date */
|
/* Now calculate from date */
|
||||||
if (use_earliest_date)
|
if (use_earliest_date)
|
||||||
from_date = HBCI_Date_new_blank();
|
*from_date = HBCI_Date_new_blank();
|
||||||
else {
|
else {
|
||||||
if (use_last_date)
|
if (use_last_date)
|
||||||
last_timespec = gnc_hbci_get_account_trans_retrieval (gnc_acc);
|
last_timespec = gnc_hbci_get_account_trans_retrieval (gnc_acc);
|
||||||
time_convert = timespecToTime_t(last_timespec);
|
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 */
|
/* Now calculate to date */
|
||||||
if (use_until_now)
|
if (use_until_now)
|
||||||
timespecFromTime_t (&until_timespec, now);
|
timespecFromTime_t (&until_timespec, now);
|
||||||
time_convert = timespecToTime_t (until_timespec);
|
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 */
|
return TRUE;
|
||||||
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. */
|
/** Finalizes all the things that have to be done with a GetTrans
|
||||||
HBCI_Date_delete (from_date);
|
* job. Returns true if everything has been finished succesfully. */
|
||||||
HBCI_Date_delete (to_date);
|
gboolean
|
||||||
return;
|
gnc_hbci_gettrans_final(GtkWidget *parent,
|
||||||
}
|
Account *gnc_acc,
|
||||||
|
const HBCI_OutboxJobGetTransactions *trans_job,
|
||||||
HBCI_Date_delete (from_date);
|
gboolean run_until_done)
|
||||||
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. */
|
/* Now add the retrieved transactions to the gnucash account. */
|
||||||
const list_HBCI_Transaction *trans_list;
|
const list_HBCI_Transaction *trans_list;
|
||||||
|
|
||||||
@ -190,56 +212,31 @@ gnc_hbci_gettrans (GtkWidget *parent, Account *gnc_acc)
|
|||||||
|
|
||||||
if (list_HBCI_Transaction_size(trans_list) > 0) {
|
if (list_HBCI_Transaction_size(trans_list) > 0) {
|
||||||
struct trans_list_data data;
|
struct trans_list_data data;
|
||||||
/*GNCGenTransaction *importer_gui = NULL;*/
|
GNCImportMainMatcher *importer_generic_gui =
|
||||||
GNCImportMainMatcher *importer_generic_gui = NULL;
|
gnc_gen_trans_list_new(NULL, NULL, TRUE);
|
||||||
|
|
||||||
/*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;
|
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;
|
data.gnc_acc = gnc_acc;
|
||||||
|
|
||||||
list_HBCI_Transaction_foreach (trans_list, trans_list_cb, &data);
|
list_HBCI_Transaction_foreach (trans_list, trans_list_cb, &data);
|
||||||
|
|
||||||
/*if(data.use_generic_matcher == FALSE)
|
if (run_until_done)
|
||||||
gnc_gen_trans_thaw (importer_gui);*/
|
return gnc_gen_trans_list_run (importer_generic_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 {
|
else {
|
||||||
GNCInteractor_hide (interactor);
|
|
||||||
gnome_ok_dialog_parented
|
gnome_ok_dialog_parented
|
||||||
(_("The HBCI import returned no transactions for the selected time period."),
|
(_("The HBCI import returned no transactions for the selected time period."),
|
||||||
GTK_WINDOW (parent));
|
GTK_WINDOW (parent));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
return TRUE;
|
||||||
|
|
||||||
/* Clean up behind ourself. */
|
|
||||||
HBCI_API_clearQueueByStatus (api, HBCI_JOB_STATUS_NONE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* list_HBCI_Transaction_foreach callback */
|
|
||||||
|
/* 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,
|
static void *trans_list_cb (const HBCI_Transaction *h_trans,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
@ -323,16 +320,8 @@ static void *trans_list_cb (const HBCI_Transaction *h_trans,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Instead of xaccTransCommitEdit(gnc_trans) */
|
/* Instead of xaccTransCommitEdit(gnc_trans) */
|
||||||
/*gnc_import_add_trans(gnc_trans);*/
|
|
||||||
/*if(data->use_generic_matcher == TRUE)
|
|
||||||
{*/
|
|
||||||
g_assert (data->importer_generic);
|
g_assert (data->importer_generic);
|
||||||
gnc_gen_trans_list_add_trans (data->importer_generic, gnc_trans);
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -24,9 +24,20 @@
|
|||||||
#define GNC_HBCI_GETTRANS_H
|
#define GNC_HBCI_GETTRANS_H
|
||||||
|
|
||||||
#include <gnome.h>
|
#include <gnome.h>
|
||||||
|
#include <openhbci/outboxaccjobs.h>
|
||||||
#include "Account.h"
|
#include "Account.h"
|
||||||
|
|
||||||
|
/** Start a GetTrans job. */
|
||||||
void
|
void
|
||||||
gnc_hbci_gettrans (GtkWidget *parent, Account *gnc_acc);
|
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 */
|
#endif /* GNC_HBCI_GETTRANS_H */
|
||||||
|
@ -38,6 +38,10 @@
|
|||||||
#include "gnc-hbci-kvp.h"
|
#include "gnc-hbci-kvp.h"
|
||||||
|
|
||||||
|
|
||||||
|
void maketrans_save_templates(GtkWidget *parent, Account *gnc_acc,
|
||||||
|
GList *template_list, gboolean dont_ask);
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
gnc_hbci_maketrans (GtkWidget *parent, Account *gnc_acc,
|
gnc_hbci_maketrans (GtkWidget *parent, Account *gnc_acc,
|
||||||
GNC_HBCI_Transtype trans_type)
|
GNC_HBCI_Transtype trans_type)
|
||||||
@ -50,6 +54,7 @@ gnc_hbci_maketrans (GtkWidget *parent, Account *gnc_acc,
|
|||||||
g_assert(parent);
|
g_assert(parent);
|
||||||
g_assert(gnc_acc);
|
g_assert(gnc_acc);
|
||||||
|
|
||||||
|
/* Get API */
|
||||||
api = gnc_hbci_api_new_currentbook (parent, &interactor);
|
api = gnc_hbci_api_new_currentbook (parent, &interactor);
|
||||||
if (api == NULL) {
|
if (api == NULL) {
|
||||||
printf("gnc_hbci_maketrans: Couldn't get HBCI API. Nothing will happen.\n");
|
printf("gnc_hbci_maketrans: Couldn't get HBCI API. Nothing will happen.\n");
|
||||||
@ -57,6 +62,7 @@ gnc_hbci_maketrans (GtkWidget *parent, Account *gnc_acc,
|
|||||||
}
|
}
|
||||||
g_assert (interactor);
|
g_assert (interactor);
|
||||||
|
|
||||||
|
/* Get HBCI account */
|
||||||
h_acc = gnc_hbci_get_hbci_acc (api, gnc_acc);
|
h_acc = gnc_hbci_get_hbci_acc (api, gnc_acc);
|
||||||
if (h_acc == NULL) {
|
if (h_acc == NULL) {
|
||||||
printf("gnc_hbci_maketrans: No HBCI account found. Nothing will happen.\n");
|
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",
|
/*printf("gnc_hbci_maketrans: HBCI account no. %s found.\n",
|
||||||
HBCI_Account_accountId (h_acc));*/
|
HBCI_Account_accountId (h_acc));*/
|
||||||
|
|
||||||
{
|
/* Get the customer that should be doing this job. */
|
||||||
/* Get one customer. */
|
customer = gnc_hbci_get_first_customer(h_acc);
|
||||||
const list_HBCI_Customer *custlist;
|
if (!customer)
|
||||||
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;
|
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));*/
|
|
||||||
|
|
||||||
{
|
{
|
||||||
GList *template_list =
|
GList *template_list =
|
||||||
@ -98,20 +83,45 @@ gnc_hbci_maketrans (GtkWidget *parent, Account *gnc_acc,
|
|||||||
( xaccAccountGetBook(gnc_acc)));
|
( xaccAccountGetBook(gnc_acc)));
|
||||||
unsigned nr_templates = g_list_length(template_list);
|
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,
|
HBCI_Transaction *h_trans = gnc_hbci_trans (parent, api, interactor,
|
||||||
h_acc, customer,
|
h_acc, customer,
|
||||||
gnc_acc,
|
gnc_acc,
|
||||||
trans_type, &template_list);
|
trans_type, &template_list);
|
||||||
|
|
||||||
/* New templates? If yes, store them */
|
/* New templates? If yes, store them */
|
||||||
if (nr_templates < g_list_length(template_list)) {
|
if (nr_templates < g_list_length(template_list))
|
||||||
if (h_trans || (gnc_verify_dialog_parented
|
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_hbci_maketrans_final (parent, gnc_acc, trans_type, h_trans, FALSE);
|
||||||
|
|
||||||
|
/* 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,
|
(parent,
|
||||||
FALSE,
|
FALSE,
|
||||||
|
"%s",
|
||||||
_("You have created a new online transfer template, but \n"
|
_("You have created a new online transfer template, but \n"
|
||||||
"you cancelled the transfer dialog. Do you nevertheless \n"
|
"you cancelled the transfer dialog. Do you nevertheless \n"
|
||||||
"want to store the new online transfer template?")))) {
|
"want to store the new online transfer template?"))) {
|
||||||
GList *kvp_list = gnc_trans_templ_kvp_glist_from_glist (template_list);
|
GList *kvp_list = gnc_trans_templ_kvp_glist_from_glist (template_list);
|
||||||
/*printf ("Now having %d templates. List: '%s'\n",
|
/*printf ("Now having %d templates. List: '%s'\n",
|
||||||
g_list_length(template_list),
|
g_list_length(template_list),
|
||||||
@ -119,14 +129,14 @@ gnc_hbci_maketrans (GtkWidget *parent, Account *gnc_acc,
|
|||||||
gnc_hbci_set_book_template_list
|
gnc_hbci_set_book_template_list
|
||||||
(xaccAccountGetBook(gnc_acc), kvp_list);
|
(xaccAccountGetBook(gnc_acc), kvp_list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gnc_trans_templ_delete_glist (template_list);
|
|
||||||
|
|
||||||
if (!h_trans)
|
gboolean
|
||||||
return;
|
gnc_hbci_maketrans_final (GtkWidget *parent, Account *gnc_acc,
|
||||||
|
GNC_HBCI_Transtype trans_type,
|
||||||
/* GNCInteractor_hide (interactor); */
|
const HBCI_Transaction *h_trans,
|
||||||
{
|
gboolean run_until_done)
|
||||||
|
{
|
||||||
/* HBCI Transaction has finished, so now open the gnucash
|
/* HBCI Transaction has finished, so now open the gnucash
|
||||||
transaction dialog and fill in all values. */
|
transaction dialog and fill in all values. */
|
||||||
gnc_numeric amount;
|
gnc_numeric amount;
|
||||||
@ -170,9 +180,12 @@ gnc_hbci_maketrans (GtkWidget *parent, Account *gnc_acc,
|
|||||||
g_free (g_memo);
|
g_free (g_memo);
|
||||||
}
|
}
|
||||||
/*gnc_xfer_dialog_set_date(XferDialog *xferData, time_t set_time)*/
|
/*gnc_xfer_dialog_set_date(XferDialog *xferData, time_t set_time)*/
|
||||||
}
|
|
||||||
|
|
||||||
HBCI_Transaction_delete (h_trans);
|
/* 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#define GNC_HBCI_TRANSFER_H
|
#define GNC_HBCI_TRANSFER_H
|
||||||
|
|
||||||
#include <gnome.h>
|
#include <gnome.h>
|
||||||
|
#include <openhbci/transaction.h>
|
||||||
#include "Account.h"
|
#include "Account.h"
|
||||||
#include "dialog-hbcitrans.h"
|
#include "dialog-hbcitrans.h"
|
||||||
|
|
||||||
@ -31,6 +32,14 @@ void
|
|||||||
gnc_hbci_maketrans (GtkWidget *parent, Account *gnc_acc,
|
gnc_hbci_maketrans (GtkWidget *parent, Account *gnc_acc,
|
||||||
GNC_HBCI_Transtype trans_type);
|
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 */
|
#endif /* GNC_HBCI_TRANSFER_H */
|
||||||
|
@ -532,3 +532,32 @@ char *gnc_hbci_memo_tognc (const HBCI_Transaction *h_trans)
|
|||||||
return g_memo;
|
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;
|
||||||
|
}
|
||||||
|
@ -117,5 +117,11 @@ char *gnc_hbci_descr_tognc (const HBCI_Transaction *h_trans);
|
|||||||
* string must be g_free'd by the caller. */
|
* string must be g_free'd by the caller. */
|
||||||
char *gnc_hbci_memo_tognc (const HBCI_Transaction *h_trans);
|
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
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user