"Fossies" - the Fresh Open Source Software Archive

Member "gnucash-3.7/gnucash/import-export/aqb/gnc-ab-getbalance.c" (7 Sep 2019, 5739 Bytes) of package /linux/misc/gnucash-3.7.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "gnc-ab-getbalance.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 3.6_vs_3.7.

    1 /*
    2  * gnc-ab-getbalance.c --
    3  *
    4  * This program is free software; you can redistribute it and/or
    5  * modify it under the terms of the GNU General Public License as
    6  * published by the Free Software Foundation; either version 2 of
    7  * the License, or (at your option) any later version.
    8  *
    9  * This program is distributed in the hope that it will be useful,
   10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12  * GNU General Public License for more details.
   13  *
   14  * You should have received a copy of the GNU General Public License
   15  * along with this program; if not, contact:
   16  *
   17  * Free Software Foundation           Voice:  +1-617-542-5942
   18  * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
   19  * Boston, MA  02110-1301,  USA       gnu@gnu.org
   20  */
   21 
   22 /**
   23  * @internal
   24  * @file gnc-ab-getbalance.c
   25  * @brief AqBanking getbalance functions
   26  * @author Copyright (C) 2002 Christian Stimming <stimming@tuhh.de>
   27  * @author Copyright (C) 2008 Andreas Koehler <andi5.py@gmx.net>
   28  */
   29 
   30 #include <config.h>
   31 
   32 #include "gnc-ab-utils.h"
   33 
   34 #include <glib/gi18n.h>
   35 #include <aqbanking/banking.h>
   36 #ifdef AQBANKING6
   37 # include <aqbanking/types/transaction.h>
   38 #else
   39 #include <aqbanking/jobgetbalance.h>
   40 #endif
   41 
   42 #include "gnc-ab-getbalance.h"
   43 #include "gnc-ab-kvp.h"
   44 #include "gnc-gwen-gui.h"
   45 #include "gnc-ui.h"
   46 
   47 /* This static indicates the debugging module that this .o belongs to.  */
   48 G_GNUC_UNUSED static QofLogModule log_module = G_LOG_DOMAIN;
   49 
   50 void
   51 gnc_ab_getbalance(GtkWidget *parent, Account *gnc_acc)
   52 {
   53     AB_BANKING *api;
   54     gboolean online = FALSE;
   55     GNC_AB_ACCOUNT_SPEC *ab_acc;
   56     GNC_AB_JOB *job = NULL;
   57     GNC_AB_JOB_LIST2 *job_list = NULL;
   58     GncGWENGui *gui = NULL;
   59     AB_IMEXPORTER_CONTEXT *context = NULL;
   60     GncABImExContextImport *ieci = NULL;
   61     GNC_AB_JOB_STATUS job_status;
   62 
   63     g_return_if_fail(parent && gnc_acc);
   64 
   65     /* Get the API */
   66     api = gnc_AB_BANKING_new();
   67     if (!api)
   68     {
   69         g_warning("gnc_ab_gettrans: Couldn't get AqBanking API");
   70         return;
   71     }
   72 
   73 #ifndef AQBANKING6
   74     if (AB_Banking_OnlineInit(api) != 0)
   75     {
   76         g_warning("gnc_ab_gettrans: Couldn't initialize AqBanking API");
   77         goto cleanup;
   78     }
   79     online = TRUE;
   80 #endif
   81     /* Get the AqBanking Account */
   82     ab_acc = gnc_ab_get_ab_account(api, gnc_acc);
   83     if (!ab_acc)
   84     {
   85         g_warning("gnc_ab_getbalance: No AqBanking account found");
   86         gnc_error_dialog (GTK_WINDOW (parent), _("No valid online banking account assigned."));
   87         goto cleanup;
   88     }
   89 
   90     /* Get a GetBalance job and enqueue it */
   91 #ifdef AQBANKING6
   92     if (!AB_AccountSpec_GetTransactionLimitsForCommand(ab_acc, AB_Transaction_CommandGetBalance))
   93 #else
   94     job = AB_JobGetBalance_new(ab_acc);
   95     if (!job || AB_Job_CheckAvailability(job))
   96 #endif
   97     {
   98         g_warning("gnc_ab_getbalance: JobGetBalance not available for this "
   99                   "account");
  100         gnc_error_dialog (GTK_WINDOW (parent), _("Online action \"Get Balance\" not available for this account."));
  101         goto cleanup;
  102     }
  103 #ifdef AQBANKING6
  104     job = AB_Transaction_new();
  105     AB_Transaction_SetCommand(job, AB_Transaction_CommandGetBalance);
  106     AB_Transaction_SetUniqueAccountId(job, AB_AccountSpec_GetUniqueId(ab_acc));
  107 
  108     job_list = AB_Transaction_List2_new();
  109     AB_Transaction_List2_PushBack(job_list, job);
  110 #else
  111     job_list = AB_Job_List2_new();
  112     AB_Job_List2_PushBack(job_list, job);
  113 #endif
  114     /* Get a GUI object */
  115     gui = gnc_GWEN_Gui_get(parent);
  116     if (!gui)
  117     {
  118         g_warning("gnc_ab_getbalance: Couldn't initialize Gwenhywfar GUI");
  119         goto cleanup;
  120     }
  121 
  122     /* Create a context to store the results */
  123     context = AB_ImExporterContext_new();
  124 
  125     /* Execute the job */
  126 #ifdef AQBANKING6
  127     AB_Banking_SendCommands(api, job_list, context);
  128 #else
  129     AB_Banking_ExecuteJobs(api, job_list, context);
  130 #endif
  131     /* Ignore the return value of AB_Banking_ExecuteJobs(), as the job's
  132      * status always describes better whether the job was actually
  133      * transferred to and accepted by the bank.  See also
  134      * https://lists.gnucash.org/pipermail/gnucash-de/2008-September/006389.html
  135      */
  136 #ifdef AQBANKING6
  137     job_status = AB_Transaction_GetStatus(job);
  138     if (job_status != AB_Transaction_StatusEnqueued
  139             && job_status != AB_Transaction_StatusPending
  140             && job_status != AB_Transaction_StatusAccepted)
  141 #else
  142     job_status = AB_Job_GetStatus(job);
  143     if (job_status != AB_Job_StatusFinished
  144             && job_status != AB_Job_StatusPending)
  145 #endif
  146     {
  147         g_warning("gnc_ab_getbalance: Error on executing job: %d", job_status);
  148 #ifdef AQBANKING6
  149         gnc_error_dialog (GTK_WINDOW (parent),
  150                           _("Error on executing job.\n\nStatus: %s"),
  151                           AB_Transaction_Status_toString(job_status));
  152 #else
  153         gnc_error_dialog (GTK_WINDOW (parent),
  154                           _("Error on executing job.\n\nStatus: %s - %s"),
  155                           AB_Job_Status2Char(job_status),
  156                           AB_Job_GetResultText(job));
  157 #endif
  158         goto cleanup;
  159     }
  160 
  161     /* Import the results */
  162     ieci = gnc_ab_import_context(context, AWAIT_BALANCES, FALSE, NULL, parent);
  163 
  164 cleanup:
  165     if (ieci)
  166         g_free(ieci);
  167     if (context)
  168         AB_ImExporterContext_free(context);
  169     if (gui)
  170         gnc_GWEN_Gui_release(gui);
  171 #ifdef AQBANKING6
  172      if (job_list)
  173          AB_Transaction_List2_free(job_list);
  174      if (job)
  175          AB_Transaction_free(job);
  176 #else
  177     if (job_list)
  178         AB_Job_List2_free(job_list);
  179     if (job)
  180         AB_Job_free(job);
  181     if (online)
  182         AB_Banking_OnlineFini(api);
  183 #endif
  184     gnc_AB_BANKING_fini(api);
  185 }