1 /* HomeBank -- Free, easy, personal accounting for everyone.
2 * Copyright (C) 1995-2019 Maxime DOYEN
4 * This file is part of HomeBank.
6 * HomeBank is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * HomeBank is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "hub-transaction.h"
24 #include "hub-account.h"
25 #include "dsp-mainwindow.h"
26 #include "list-operation.h"
28 #include "ui-transaction.h"
31 /****************************************************************************/
33 /****************************************************************************/
42 /* our global datas */
43 extern struct HomeBank
*GLOBALS
;
44 extern struct Preferences
*PREFS
;
47 void ui_hub_transaction_populate(struct hbfile_data
*data
)
49 GList
*lst_acc
, *lnk_acc
;
51 GtkTreeModel
*model1
, *model2
;
54 DB( g_print("\n[ui_hub_txn] populate\n") );
56 model1
= gtk_tree_view_get_model(GTK_TREE_VIEW(data
->LV_txn
[HUB_TXN_TYPE_FUTURE
]));
57 model2
= gtk_tree_view_get_model(GTK_TREE_VIEW(data
->LV_txn
[HUB_TXN_TYPE_REMIND
]));
59 gtk_list_store_clear (GTK_LIST_STORE(model1
));
60 gtk_list_store_clear (GTK_LIST_STORE(model2
));
63 lst_acc
= g_hash_table_get_values(GLOBALS
->h_acc
);
64 lnk_acc
= g_list_first(lst_acc
);
65 while (lnk_acc
!= NULL
)
67 Account
*acc
= lnk_acc
->data
;
69 // skip closed in showall mode
70 if( (acc
->flags
& AF_CLOSED
) )
73 lnk_txn
= g_queue_peek_head_link(acc
->txn_queue
);
74 while (lnk_txn
!= NULL
)
76 Transaction
*txn
= lnk_txn
->data
;
78 if(txn
->date
> GLOBALS
->today
)
80 gtk_list_store_insert_with_values(GTK_LIST_STORE(model1
), &iter
, -1,
81 MODEL_TXN_POINTER
, txn
,
85 if(txn
->status
== TXN_STATUS_REMIND
)
87 gtk_list_store_insert_with_values(GTK_LIST_STORE(model2
), &iter
, -1,
88 MODEL_TXN_POINTER
, txn
,
91 lnk_txn
= g_list_next(lnk_txn
);
95 lnk_acc
= g_list_next(lnk_acc
);
101 static void ui_hub_transaction_onRowActivated (GtkTreeView
*treeview
,
103 GtkTreeViewColumn
*col
,
106 struct hbfile_data
*data
= userdata
;
107 Transaction
*active_txn
;
111 DB( g_print ("\n[ui_hub_txn] row double-clicked\n") );
113 active_txn
= list_txn_get_active_transaction(treeview
);
116 Transaction
*old_txn
, *new_txn
;
118 old_txn
= da_transaction_clone (active_txn
);
119 new_txn
= active_txn
;
120 result
= deftransaction_external_edit(GTK_WINDOW(data
->window
), old_txn
, new_txn
);
122 if(result
== GTK_RESPONSE_ACCEPT
)
125 GLOBALS
->changes_count
++;
126 ui_hub_transaction_populate(data
);
128 //#1824515 when amount change update acc panel
129 if( old_txn
->amount
!= new_txn
->amount
)
130 ui_hub_account_populate(GLOBALS
->mainwindow
, NULL
);
134 da_transaction_free (old_txn
);
140 GtkWidget
*ui_hub_transaction_create(struct hbfile_data
*data
, HbHubTxnType type
)
142 GtkWidget
*hub
, *vbox
, *sw
, *widget
;
144 DB( g_print("\n[ui_hub_txn] create %d\n", type
) );
146 if( type
> HUB_TXN_TYPE_REMIND
)
149 hub
= gtk_box_new (GTK_ORIENTATION_VERTICAL
, 0);
150 gtk_container_set_border_width(GTK_CONTAINER(hub
), SPACING_SMALL
);
152 vbox
= gtk_box_new (GTK_ORIENTATION_VERTICAL
, 0);
153 //gtk_widget_set_margin_top(GTK_WIDGET(vbox), 0);
154 //gtk_widget_set_margin_bottom(GTK_WIDGET(vbox), SPACING_SMALL);
155 //gtk_widget_set_margin_start(GTK_WIDGET(vbox), 2*SPACING_SMALL);
156 //gtk_widget_set_margin_end(GTK_WIDGET(vbox), SPACING_SMALL);
157 gtk_box_pack_start (GTK_BOX (hub
), vbox
, TRUE
, TRUE
, 0);
159 sw
= gtk_scrolled_window_new (NULL
, NULL
);
160 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw
), GTK_SHADOW_ETCHED_IN
);
161 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw
), GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
162 gtk_box_pack_start (GTK_BOX (vbox
), sw
, TRUE
, TRUE
, 0);
164 widget
= (GtkWidget
*)create_list_transaction(LIST_TXN_TYPE_DETAIL
, PREFS
->lst_ope_columns
);
165 list_txn_set_column_acc_visible(GTK_TREE_VIEW(widget
), TRUE
);
166 data
->LV_txn
[type
] = widget
;
167 gtk_container_add (GTK_CONTAINER (sw
), widget
);
169 g_signal_connect (GTK_TREE_VIEW(data
->LV_txn
[type
]), "row-activated", G_CALLBACK (ui_hub_transaction_onRowActivated
), data
);