1 /* *******************************************************************************/
2 /*                                 GRISBI                                        */
3 /*              Programme de gestion financière personnelle                      */
4 /*                              license : GPLv2                                  */
5 /*                                                                               */
6 /*     Copyright (C)    2000-2008 Cédric Auger (cedric@grisbi.org)               */
7 /*                      2003-2008 Benjamin Drieu (bdrieu@april.org)              */
8 /*          2008-2020 Pierre Biava (grisbi@pierre.biava.name)                    */
9 /*          http://www.grisbi.org                                                */
10 /*                                                                               */
11 /*     This program is free software; you can redistribute it and/or modify      */
12 /*     it under the terms of the GNU General Public License as published by      */
13 /*     the Free Software Foundation; either version 2 of the License, or         */
14 /*     (at your option) any later version.                                       */
15 /*                                                                               */
16 /*     This program is distributed in the hope that it will be useful,           */
17 /*     but WITHOUT ANY WARRANTY; without even the implied warranty of            */
18 /*     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             */
19 /*     GNU General Public License for more details.                              */
20 /*                                                                               */
21 /*     You should have received a copy of the GNU General Public License         */
22 /*     along with this program; if not, write to the Free Software               */
23 /*     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
24 /*                                                                               */
25 /* *******************************************************************************/
26 
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30 
31 #ifdef HAVE_CONFIG_H
32 #include "config.h"
33 #endif
34 
35 #include <errno.h>
36 #include <glib/gstdio.h>
37 #include <glib/gi18n.h>
38 
39 /*START_INCLUDE*/
40 #include "widget_transfer.h"
41 #include "bet_data.h"
42 #include "bet_future.h"
43 #include "dialog.h"
44 #include "grisbi_app.h"
45 #include "gsb_calendar_entry.h"
46 #include "gsb_data_account.h"
47 #include "gsb_data_budget.h"
48 #include "gsb_data_category.h"
49 #include "gsb_data_form.h"
50 #include "gsb_data_partial_balance.h"
51 #include "gsb_data_payee.h"
52 #include "gsb_data_payment.h"
53 #include "gsb_form.h"
54 #include "gsb_form_widget.h"
55 #include "gsb_payment_method.h"
56 #include "gtk_combofix.h"
57 #include "structures.h"
58 #include "utils.h"
59 #include "utils_dates.h"
60 #include "utils_str.h"
61 #include "erreur.h"
62 /*END_INCLUDE*/
63 
64 /*START_EXTERN*/
65 /*END_EXTERN*/
66 
67 /*START_STATIC*/
68 /*END_STATIC*/
69 
70 typedef struct _WidgetTransferPrivate   WidgetTransferPrivate;
71 
72 struct _WidgetTransferPrivate
73 {
74 	GtkWidget *			vbox_transfer;
75 	GtkWidget *			button_delete_transfer;
76 	GtkWidget *			treeview_transfer;
77 
78 	GtkWidget *			grid_card_div;
79 	GtkWidget *			combo_card_budget;
80 	GtkWidget *			combo_card_category;
81 	GtkWidget *			combo_card_payee;
82 	GtkWidget *			combo_card_payment;
83 	GtkWidget *			entry_card_budget;
84 	GtkWidget *			entry_card_category;
85 	GtkWidget *			entry_card_payee;
86 	GtkWidget *			entry_date_bascule;
87 	GtkWidget *			hbox_date_bascule;
88 	GtkWidget *			label_date_bascule;
89 	GtkWidget *			combo_card_choice_bascule_day;
90 
91 	GtkWidget *			grid_main_div;
92 	GtkWidget *			checkbutton_direct_debit;
93 	GtkWidget *			checkbutton_replace_data;
94 	GtkWidget *			combo_main_budget;
95 	GtkWidget *			combo_main_category;
96 	GtkWidget *			combo_main_choice_debit_day;
97 	GtkWidget *			combo_main_payee;
98 	GtkWidget *			combo_main_payment;
99 	GtkWidget *			entry_date_debit;
100 	GtkWidget *			entry_main_budget;
101 	GtkWidget *			entry_main_category;
102 	GtkWidget *			entry_main_payee;
103 	GtkWidget *			hbox_date_debit;
104 	GtkWidget *			label_date_debit;
105 
106 	/* data */
107 	gint				create_mode;
108 	gboolean			valid_card_date;
109 	gboolean			valid_card_payee;
110 	gboolean			valid_card_div;
111 	gboolean			valid_main_date;
112 	gboolean			valid_main_payee;
113 	gboolean			valid_main_div;
114 };
115 
116 G_DEFINE_TYPE_WITH_PRIVATE (WidgetTransfer, widget_transfer, GTK_TYPE_DIALOG)
117 
118 enum BetTransferColumns {
119 	BET_TRANSFER_NAME,
120 	BET_TRANSFERT_KIND,
121 	BET_TRANSFER_ACCOUNT,
122 	BET_TRANSFERT_PARTIAL,
123 	BET_TRANSFERT_BACKGROUND
124 };
125 
126 enum BetTransferFormType {
127 	BET_TRANSFER_PAYEE,
128 	BET_TRANSFER_CARD_DATE,
129 	BET_TRANSFER_CARD_CATEGORY,
130 	BET_TRANSFER_CARD_BUDGET,
131 	BET_TRANSFER_MAIN_DATE,
132 	BET_TRANSFER_MAIN_CATEGORY,
133 	BET_TRANSFER_MAIN_BUDGET
134 };
135 
136 /******************************************************************************/
137 /* Private functions                                                          */
138 /******************************************************************************/
139 /**
140  * validate data before return
141  *
142  * \param
143  *
144  * \return TRUE if all data are correctly
145  **/
widget_transfer_validate_all_data(WidgetTransfer * dialog)146 static gboolean widget_transfer_validate_all_data (WidgetTransfer *dialog)
147 {
148 	gboolean tmp_valid = FALSE;
149 	gboolean valid = FALSE;
150 	WidgetTransferPrivate *priv;
151 
152 	devel_debug (NULL);
153 	priv = widget_transfer_get_instance_private (dialog);
154 
155 	if ((gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->checkbutton_replace_data)) == FALSE
156 		 && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->checkbutton_direct_debit)) == FALSE)
157 		|| (priv->valid_main_payee && priv->valid_main_div))
158 	{
159 		tmp_valid = TRUE;
160 	}
161 	else
162 	{
163 		tmp_valid = FALSE;
164 
165 	}
166 
167 	if (priv->valid_card_date == TRUE
168 		&& priv->valid_card_payee == TRUE
169 		&& priv->valid_card_div == TRUE
170 		&& tmp_valid == TRUE)
171 		valid = TRUE;
172 	else
173 		valid = FALSE;
174 
175 	return valid;
176 }
177 
178 /**
179  * calcule et affiche la date d'arrêté si la date choisie n'est pas ouvrée
180  *
181  * \param dialog
182  * \param sensitive
183  *
184  * \return
185  **/
widget_transfer_set_effective_date_bascule(WidgetTransfer * dialog,GDate * date)186 static void widget_transfer_set_effective_date_bascule (WidgetTransfer *dialog,
187 														GDate *date)
188 {
189 	GDate *tmp_date;
190 	WidgetTransferPrivate *priv;
191 devel_debug (NULL);
192 
193 	priv = widget_transfer_get_instance_private (dialog);
194 
195 	gtk_widget_show (priv->hbox_date_bascule);
196 	tmp_date = gsb_date_get_first_banking_day_after_date (date);
197 	gtk_label_set_text (GTK_LABEL (priv->label_date_bascule), gsb_format_gdate (tmp_date));
198 }
199 
200 /**
201  * calcule et affiche la date d'arrêté si la date choisie n'est pas ouvrée
202  *
203  * \param dialog
204  * \param sensitive
205  *
206  * \return
207  **/
widget_transfer_set_effective_date_debit(WidgetTransfer * dialog,GDate * date)208 static void widget_transfer_set_effective_date_debit (WidgetTransfer *dialog,
209 													  GDate *date)
210 {
211 	GDate *tmp_date;
212 	WidgetTransferPrivate *priv;
213 devel_debug (NULL);
214 	priv = widget_transfer_get_instance_private (dialog);
215 
216 	gtk_widget_show (priv->hbox_date_debit);
217 	tmp_date = gsb_date_get_first_banking_day_before_date (date);
218 	gtk_label_set_text (GTK_LABEL (priv->label_date_debit), gsb_format_gdate (tmp_date));
219 }
220 
221 /**
222  * sensibilise ou insensibilise les éléments de l'opération du compte principal
223  *
224  * \param dialog
225  * \param sensitive
226  *
227  * \return
228  **/
widget_transfer_sensitive_direct_debit(WidgetTransfer * dialog,gboolean sensitive)229 static void widget_transfer_sensitive_direct_debit (WidgetTransfer *dialog,
230 													gboolean sensitive)
231 {
232 	GtkWidget *icon_1;
233 	GtkWidget *icon_2;
234 	WidgetTransferPrivate *priv;
235 devel_debug (NULL);
236 
237 	priv = widget_transfer_get_instance_private (dialog);
238 	icon_1 = g_object_get_data (G_OBJECT (priv->combo_main_payee), "icon");
239 	icon_2 = g_object_get_data (G_OBJECT (priv->combo_main_category), "icon");
240 	if (sensitive)
241 	{
242 		gtk_widget_set_sensitive (icon_1, TRUE);
243 		gtk_widget_set_sensitive (icon_2, TRUE);
244 		gtk_widget_set_sensitive (priv->combo_main_budget, TRUE);
245 		gtk_widget_set_sensitive (priv->combo_main_category, TRUE);
246 		gtk_widget_set_sensitive (priv->combo_main_payee, TRUE);
247 		gtk_widget_set_sensitive (priv->combo_main_payment, TRUE);
248 	}
249 	else
250 	{
251 		gtk_widget_set_sensitive (icon_1, FALSE);
252 		gtk_widget_set_sensitive (icon_2, FALSE);
253 		gtk_widget_set_sensitive (priv->combo_main_budget, FALSE);
254 		gtk_widget_set_sensitive (priv->combo_main_category, FALSE);
255 		gtk_widget_set_sensitive (priv->combo_main_payee, FALSE);
256 		gtk_widget_set_sensitive (priv->combo_main_payment, FALSE);
257 	}
258 }
259 
260 /**
261  *
262  *
263  * \param
264  * \param
265  *
266  * \return
267  **/
widget_transfer_direct_debit_toggle(GtkToggleButton * button,WidgetTransfer * dialog)268 static void widget_transfer_direct_debit_toggle (GtkToggleButton *button,
269 												 WidgetTransfer *dialog)
270 {
271 	devel_debug (NULL);
272 	if (gtk_toggle_button_get_active (button))
273 	{
274 		widget_transfer_sensitive_direct_debit (dialog, TRUE);
275 	}
276 	else
277 	{
278 		WidgetTransferPrivate *priv;
279 
280 		priv = widget_transfer_get_instance_private (dialog);
281 		if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->checkbutton_replace_data)) == FALSE)
282 			widget_transfer_sensitive_direct_debit (dialog, FALSE);
283 	}
284 
285 	if (widget_transfer_validate_all_data (dialog))
286 		gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, TRUE);
287 }
288 
289 /**
290  * sensibilise ou insensibilise la boite en fonction de l'état du bouton
291  *
292  * \param button
293  * \param box
294  *
295  * \return
296  **/
widget_transfer_replace_data_toggle(GtkToggleButton * button,WidgetTransfer * dialog)297 static void widget_transfer_replace_data_toggle (GtkToggleButton *button,
298 												 WidgetTransfer *dialog)
299 {
300 	devel_debug (NULL);
301 	if (gtk_toggle_button_get_active (button))
302 	{
303 		widget_transfer_sensitive_direct_debit (dialog, TRUE);
304 	}
305 	else
306 	{
307 		WidgetTransferPrivate *priv;
308 
309 		priv = widget_transfer_get_instance_private (dialog);
310 		if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->checkbutton_direct_debit)) == FALSE)
311 			widget_transfer_sensitive_direct_debit (dialog, FALSE);
312 	}
313 
314 	if (widget_transfer_validate_all_data (dialog))
315 		gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, TRUE);
316 }
317 
318 /**
319  *
320  *
321  * \param
322  * \param
323  *
324  * \return
325  **/
widget_transfer_combo_main_choice_debit_day_changed(GtkComboBox * combo,WidgetTransfer * dialog)326 static void widget_transfer_combo_main_choice_debit_day_changed (GtkComboBox *combo,
327 															 	 WidgetTransfer *dialog)
328 {
329 	GDate *date;
330 	GDate *tmp_date;
331 	gint active;
332 	WidgetTransferPrivate *priv;
333 devel_debug (NULL);
334 
335 	priv = widget_transfer_get_instance_private (dialog);
336 	if (!GTK_IS_DIALOG (dialog))
337 		return;
338 
339 	active = gtk_combo_box_get_active (GTK_COMBO_BOX (combo));
340 	switch (active)
341 	{
342 		case 2:
343 			date = gsb_calendar_entry_get_date (priv->entry_date_debit);
344 			widget_transfer_set_effective_date_debit (dialog, date);
345 			gtk_widget_set_sensitive (priv->entry_date_debit, TRUE);
346 			break;
347 		case 1:
348 			date = gsb_calendar_entry_get_date (priv->entry_date_debit);
349 			if (g_date_valid (date))
350 			{
351 				tmp_date = gsb_date_get_last_banking_day_of_month (date);
352 				g_date_free (date);
353 
354 				if (g_date_valid (tmp_date))
355 				{
356 					gsb_calendar_entry_set_date (priv->entry_date_debit, tmp_date);
357 					gtk_widget_set_sensitive (priv->entry_date_debit, FALSE);
358 					gtk_widget_hide (priv->hbox_date_debit);
359 					g_date_free (tmp_date);
360 				}
361 			}
362 
363 			break;
364 		default:
365 			gtk_widget_hide (priv->hbox_date_bascule);
366 			gtk_widget_set_sensitive (priv->entry_date_debit, TRUE);
367 	}
368 
369 	gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, TRUE);
370 }
371 
372 /**
373  *
374  *
375  * \param
376  * \param
377  *
378  * \return
379  **/
widget_transfer_card_choice_bascule_day_changed(GtkComboBox * combo,WidgetTransfer * dialog)380 static void widget_transfer_card_choice_bascule_day_changed (GtkComboBox *combo,
381 															 WidgetTransfer *dialog)
382 {
383 	WidgetTransferPrivate *priv;
384 devel_debug (NULL);
385 
386 	priv = widget_transfer_get_instance_private (dialog);
387 	if (!GTK_IS_DIALOG (dialog))
388 		return;
389 
390 	if (gtk_combo_box_get_active (GTK_COMBO_BOX (combo)))
391 	{
392 		GDate *date;
393 
394 		date = gsb_calendar_entry_get_date (priv->entry_date_bascule);
395 		widget_transfer_set_effective_date_bascule (dialog, date);
396 	}
397 	else
398 		gtk_widget_hide (priv->hbox_date_bascule);
399 
400 	gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, TRUE);
401 }
402 
403 /**
404  *
405  *
406  * \param
407  * \param
408  *
409  * \return
410  **/
widget_transfer_payment_method_changed(GtkComboBox * combo_box,WidgetTransfer * dialog)411 static void widget_transfer_payment_method_changed (GtkComboBox *combo_box,
412 													WidgetTransfer *dialog)
413 {
414 	devel_debug (NULL);
415 	if (!GTK_IS_DIALOG (dialog))
416 		return;
417 
418 	gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, TRUE);
419 }
420 
421 /**
422  * sélectionne le compte concerné par la modification du solde.
423  *
424  * \param struct transfert
425  * \param
426  *
427  * \return
428  **/
widget_transfert_select_account_in_treeview(GtkWidget * tree_view,TransfertData * transfert)429 static void widget_transfert_select_account_in_treeview (GtkWidget *tree_view,
430 														 TransfertData *transfert)
431 {
432 	GtkTreeModel *model;
433 	GtkTreeIter iter;
434 	GtkTreeSelection *selection;
435 	gboolean valid;
436 
437 	model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view));
438 	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
439 
440 	valid = gtk_tree_model_get_iter_first (model, &iter);
441 	while(valid)
442 	{
443 		gint tmp_number;
444 		gint type_de_compte;
445 
446 		gtk_tree_model_get (GTK_TREE_MODEL (model), &iter, 2, &tmp_number, 3, &type_de_compte, -1);
447 
448 		if (transfert->type == type_de_compte && tmp_number == transfert->replace_account)
449 		{
450 			gtk_tree_selection_select_iter (GTK_TREE_SELECTION (selection), &iter);
451 			break;
452 		}
453 		valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (model), &iter);
454 	}
455 }
456 
457 /**
458  * called when date changed
459  * check the date and set the entry red/invalid if not a good date
460  *
461  * \param entry
462  * \param null
463  *
464  * \return FALSE
465  * */
widget_transfert_calendar_entry_changed(GtkWidget * entry,WidgetTransfer * dialog)466 static void widget_transfert_calendar_entry_changed (GtkWidget *entry,
467 													 WidgetTransfer *dialog)
468 {
469 	GDate *date;
470 	WidgetTransferPrivate *priv;
471 
472 	priv = widget_transfer_get_instance_private (dialog);
473 
474 	devel_debug (NULL);
475 	/* if we are in the form and the entry is empty, do nothing
476 	 * because it's a special style too */
477 	if (gsb_form_widget_check_empty (entry))
478 	{
479 		priv->valid_card_date = FALSE;
480 
481 		return;
482 	}
483 
484 	/* if nothing in the entry, keep the normal style */
485 	if (!strlen (gtk_entry_get_text (GTK_ENTRY (entry))))
486 	{
487 		priv->valid_card_date = FALSE;
488 
489 		return;
490 	}
491 
492 	/* to check the date, we just try to see if can have a dote from the entry */
493 	date = gsb_date_get_last_entry_date (gtk_entry_get_text (GTK_ENTRY (entry)));
494 
495 	if (date)
496 	{
497 		if (g_object_get_data (G_OBJECT (entry), "form_type") == GINT_TO_POINTER (BET_TRANSFER_CARD_DATE))
498 		{
499 			/* the date is valid, make it normal */
500 			if (!gtk_widget_get_sensitive (priv->combo_card_choice_bascule_day))
501 			{
502 				gsb_calendar_entry_set_color (entry, TRUE);
503 				gtk_widget_set_sensitive (priv->combo_card_choice_bascule_day, TRUE);
504 			}
505 			if (gtk_combo_box_get_active (GTK_COMBO_BOX (priv->combo_card_choice_bascule_day)))
506 			{
507 				widget_transfer_set_effective_date_bascule (WIDGET_TRANSFER (dialog), date);
508 			}
509 		}
510 		else
511 		{
512 			if (gtk_combo_box_get_active (GTK_COMBO_BOX (priv->combo_main_choice_debit_day)) == 2)
513 			{
514 				widget_transfer_set_effective_date_debit (WIDGET_TRANSFER (dialog), date);
515 			}
516 		}
517 		priv->valid_card_date = TRUE;
518 	}
519 	else
520 		priv->valid_card_date = FALSE;
521 }
522 
523 /**
524  * called when an entry get the focus, if the entry is free,
525  * set it normal and erase the help content
526  *
527  * \param entry
528  * \param ev
529  * \param user_data		not used
530  *
531  * \return FALSE
532  **/
widget_transfert_entry_focus_in(GtkWidget * entry,GdkEventFocus * ev,gpointer user_data)533 static gboolean widget_transfert_entry_focus_in (GtkWidget *entry,
534 												 GdkEventFocus *ev,
535 												 gpointer user_data)
536 {
537 	devel_debug (NULL);
538 	/* the entry is a real entry */
539 	if (gsb_form_widget_check_empty (entry))
540 	{
541 		gtk_entry_set_text (GTK_ENTRY (entry), "");
542 		gsb_form_widget_set_empty (entry, FALSE);
543 	}
544 
545 	return FALSE;
546 }
547 
548 /**
549  * callback called on focus-out on the date entry
550  * complete and check the date
551  *
552  * \param entry		the entry which receive the signal
553  * \param
554  * \param
555  *
556  * \return true
557  * */
widget_transfert_calendar_entry_focus_out(GtkWidget * entry,GdkEventFocus * event,WidgetTransfer * dialog)558 static gboolean widget_transfert_calendar_entry_focus_out (GtkWidget *entry,
559 														   GdkEventFocus *event,
560 														   WidgetTransfer *dialog)
561 {
562 	devel_debug (NULL);
563 	if (widget_transfer_validate_all_data (dialog))
564 	{
565 		gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, TRUE);
566 	}
567 	else
568 	{
569 		gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
570 	}
571 	return FALSE;
572 }
573 
574 /**
575  *
576  *
577  * \param
578  * \param
579  * \param
580  *
581  * \return
582  **/
widget_transfert_div_entry_focus_out(GtkWidget * entry,GdkEventFocus * ev,WidgetTransfer * dialog)583 static gboolean widget_transfert_div_entry_focus_out (GtkWidget *entry,
584 													  GdkEventFocus *ev,
585 													  WidgetTransfer *dialog)
586 {
587 	GtkWidget *widget;
588 	const gchar *string;
589 	gint element_number;
590 	gint *ptr_origin;
591 	WidgetTransferPrivate *priv;
592 
593 	devel_debug (NULL);
594 	priv = widget_transfer_get_instance_private (dialog);
595 
596 	/* still not found, if change the content of the form, something come in entry
597 	 * which is nothing, so protect here */
598 	if (!GTK_IS_WIDGET (entry) || !GTK_IS_ENTRY (entry))
599 		return FALSE;
600 
601 	/* remove the selection */
602 	gtk_editable_select_region (GTK_EDITABLE (entry), 0, 0);
603 
604 	ptr_origin = g_object_get_data (G_OBJECT (entry), "form_type");
605 	element_number = GPOINTER_TO_INT (ptr_origin);
606 	if (element_number != BET_TRANSFER_PAYEE
607 		&& element_number != BET_TRANSFER_CARD_CATEGORY
608 		&& element_number != BET_TRANSFER_CARD_BUDGET
609 		&& element_number != BET_TRANSFER_MAIN_CATEGORY
610 		&& element_number != BET_TRANSFER_MAIN_BUDGET)
611 		return FALSE;
612 
613 	widget = g_object_get_data (G_OBJECT (entry), "combo");
614 
615 	/* sometimes the combofix popus stays showed, so remove here */
616 	gtk_combofix_hide_popup (GTK_COMBOFIX (widget));
617 
618 	/* string will be filled only if the field is empty */
619 	string = NULL;
620 	switch (element_number)
621 	{
622 		case BET_TRANSFER_PAYEE:
623 			if (strlen (gtk_entry_get_text (GTK_ENTRY (entry))))
624 			{
625 				utils_set_image_with_state (widget,TRUE);
626 				gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, TRUE);
627 			}
628 			else
629 			{
630 				string = gsb_form_widget_get_name (TRANSACTION_FORM_PARTY);
631 				gtk_combofix_set_text (GTK_COMBOFIX (widget), _(string));
632 				gsb_form_widget_set_empty (entry, TRUE);
633 				utils_set_image_with_state (widget, FALSE);
634 				gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
635 			}
636 			break;
637 
638 		case BET_TRANSFER_CARD_CATEGORY:
639 			if (strlen (gtk_entry_get_text (GTK_ENTRY (entry))))
640 			{
641 				utils_set_image_with_state (widget,TRUE);
642 				gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, TRUE);
643 			}
644 			else
645 			{
646 				string = gsb_form_widget_get_name (TRANSACTION_FORM_CATEGORY);
647 				gtk_combofix_set_text (GTK_COMBOFIX (widget), _(string));
648 				gsb_form_widget_set_empty (entry, TRUE);
649 				if (gsb_form_widget_check_empty (priv->combo_card_budget))
650 				{
651 					utils_set_image_with_state (widget, FALSE);
652 					gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
653 				}
654 				else
655 				{
656 					utils_set_image_with_state (widget, TRUE);
657 					gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, TRUE);
658 				}
659 			}
660 			break;
661 
662 		case BET_TRANSFER_MAIN_CATEGORY:
663 			if (strlen (gtk_entry_get_text (GTK_ENTRY (entry))))
664 			{
665 				utils_set_image_with_state (widget,TRUE);
666 				gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, TRUE);
667 			}
668 			else
669 			{
670 				string = gsb_form_widget_get_name (TRANSACTION_FORM_CATEGORY);
671 				gtk_combofix_set_text (GTK_COMBOFIX (widget), _(string));
672 				gsb_form_widget_set_empty (entry, TRUE);
673 				if (gsb_form_widget_check_empty (priv->combo_main_budget))
674 				{
675 					utils_set_image_with_state (widget, FALSE);
676 					gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
677 				}
678 				else
679 				{
680 					utils_set_image_with_state (widget, TRUE);
681 					gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, TRUE);
682 				}
683 			}
684 			break;
685 
686 		case BET_TRANSFER_CARD_BUDGET:
687 			if (strlen (gtk_entry_get_text (GTK_ENTRY (entry))))
688 			{
689 				utils_set_image_with_state (widget,TRUE);
690 				gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, TRUE);
691 			}
692 			else
693 			{
694 				string = gsb_form_widget_get_name (TRANSACTION_FORM_BUDGET);
695 				gtk_combofix_set_text (GTK_COMBOFIX (widget), _(string));
696 				gsb_form_widget_set_empty (entry, TRUE);
697 				if (gsb_form_widget_check_empty (priv->combo_card_category))
698 				{
699 					utils_set_image_with_state (widget, FALSE);
700 					gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
701 				}
702 				else
703 				{
704 					utils_set_image_with_state (widget, TRUE);
705 					gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, TRUE);
706 				}
707 			}
708 			break;
709 
710 		case BET_TRANSFER_MAIN_BUDGET:
711 			if (strlen (gtk_entry_get_text (GTK_ENTRY (entry))))
712 			{
713 				utils_set_image_with_state (widget,TRUE);
714 				gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, TRUE);
715 			}
716 			else
717 			{
718 				string = gsb_form_widget_get_name (TRANSACTION_FORM_BUDGET);
719 				gtk_combofix_set_text (GTK_COMBOFIX (widget), _(string));
720 				gsb_form_widget_set_empty (entry, TRUE);
721 				if (gsb_form_widget_check_empty (priv->combo_main_category))
722 				{
723 					utils_set_image_with_state (widget, FALSE);
724 					gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
725 				}
726 				else
727 				{
728 					utils_set_image_with_state (widget, TRUE);
729 					gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, TRUE);
730 				}
731 			}
732 			break;
733 
734 		default :
735 			break;
736 	}
737 
738 	return FALSE;
739 }
740 
741 /**
742  *
743  *
744  * \param
745  * \param
746  *
747  * \return
748  **/
widget_transfer_fill_list(GtkWidget * tree_view,gint account_number)749 static void widget_transfer_fill_list (GtkWidget *tree_view,
750 									   gint account_number)
751 {
752 	GtkTreeModel *model;
753 	GSList *tmp_list;
754 	gint nbre_rows = 0;
755 
756 	model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view));
757 	tmp_list = gsb_data_account_get_list_accounts ();
758 	while (tmp_list)
759 	{
760 		gint tmp_account_number;
761 		gint bet_credit_card;
762 		GtkTreeIter iter;
763 
764 		tmp_account_number = gsb_data_account_get_no_account (tmp_list->data);
765 
766 		/* On passe si le compte est clos */
767 		if (gsb_data_account_get_closed_account (tmp_account_number))
768 		{
769 			tmp_list = tmp_list->next;
770 			continue;
771 		}
772 
773 		if (tmp_account_number != account_number)
774 		{
775 			bet_credit_card = gsb_data_account_get_bet_credit_card (tmp_account_number);
776 			if (bet_credit_card)
777 			{
778 				KindAccount kind;
779 				gchar *tmp_str = NULL;
780 
781 				kind = gsb_data_account_get_kind (tmp_account_number);
782 				switch (kind)
783 				{
784 					case GSB_TYPE_BANK:
785 						tmp_str = g_strdup (_("Bank account"));
786 						break;
787 					case GSB_TYPE_CASH:
788 						tmp_str = g_strdup (_("Cash account"));
789 						break;
790 					case GSB_TYPE_LIABILITIES:
791 						tmp_str = g_strdup (_("Liabilities account"));
792 						break;
793 					case GSB_TYPE_BALANCE:
794 						tmp_str = NULL;
795 						break;
796 					case GSB_TYPE_ASSET:
797 						tmp_str = NULL;
798 						break;
799 				}
800 				gtk_list_store_append (GTK_LIST_STORE (model), &iter);
801 				gtk_list_store_set (GTK_LIST_STORE (model),
802 									&iter,
803 									0, gsb_data_account_get_name (tmp_account_number),
804 									1, tmp_str,
805 									2, tmp_account_number,
806 									3, FALSE,
807 									-1);
808 				nbre_rows ++;
809 				g_free (tmp_str);
810 			}
811 		}
812 
813 		tmp_list = tmp_list->next;
814 	}
815 
816 	tmp_list = gsb_data_partial_balance_get_list ();
817 	while (tmp_list)
818 	{
819 		gint tmp_number;
820 		GtkTreeIter iter;
821 		const gchar *liste_cptes;
822 		gchar **tab;
823 		gint bet_credit_card = 0;
824 		gint i;
825 
826 		tmp_number = gsb_data_partial_balance_get_number (tmp_list->data);
827 
828 		liste_cptes = gsb_data_partial_balance_get_liste_cptes (tmp_number);
829 		tab = g_strsplit (liste_cptes, ";", 0);
830 		for (i = 0; i < (gint) g_strv_length (tab); i++)
831 		{
832 			gint tmp_account_number;
833 
834 			tmp_account_number = utils_str_atoi (tab[i]);
835 			bet_credit_card = gsb_data_account_get_bet_credit_card (tmp_account_number);
836 		}
837 
838 		g_strfreev (tab);
839 
840 		if (bet_credit_card)
841 		{
842 			gtk_list_store_append (GTK_LIST_STORE (model), &iter);
843 			gtk_list_store_set (GTK_LIST_STORE (model),
844 								&iter,
845 								0, gsb_data_partial_balance_get_name (tmp_number),
846 								1, _("Partial balance"),
847 								2, tmp_number,
848 								3, TRUE,
849 								-1);
850 				nbre_rows ++;
851 		}
852 
853 		tmp_list = tmp_list->next;
854 	}
855 }
856 
857 /**
858  *
859  *
860  * \param
861  * \param
862  *
863  * \return
864  **/
widget_transfer_setup_card_part(WidgetTransfer * dialog,gint account_number)865 static void widget_transfer_setup_card_part (WidgetTransfer *dialog,
866 											 gint account_number)
867 {
868 	GtkWidget *combo;
869 	GtkWidget *icon;
870 	GSList *tmp_list;
871 	WidgetTransferPrivate *priv;
872 
873 	devel_debug (NULL);
874 	priv = widget_transfer_get_instance_private (dialog);
875 
876 	/* set entry_date_bascule */
877 	gsb_calendar_entry_new_from_ui (priv->entry_date_bascule, FALSE);
878 	g_object_set_data (G_OBJECT (priv->entry_date_bascule), "form_type", GINT_TO_POINTER (BET_TRANSFER_CARD_DATE));
879 	g_signal_connect (G_OBJECT (priv->entry_date_bascule),
880 					  "focus-in-event",
881 					  G_CALLBACK (widget_transfert_entry_focus_in),
882 					  NULL);
883 	g_signal_connect (G_OBJECT (priv->entry_date_bascule),
884 					  "focus-out-event",
885 					  G_CALLBACK (widget_transfert_calendar_entry_focus_out),
886 					  dialog);
887 
888 	/* init combo_card_choice_bascule_day */
889 	if (priv->create_mode)
890 	{
891 		gsb_form_widget_set_empty (priv->entry_date_bascule, TRUE);
892 		g_signal_connect_after (G_OBJECT (priv->entry_date_bascule),
893 								"changed",
894 								G_CALLBACK (widget_transfert_calendar_entry_changed),
895 								dialog);
896 
897 		gtk_widget_set_sensitive (priv->combo_card_choice_bascule_day, FALSE);
898 		g_signal_connect (G_OBJECT (priv->combo_card_choice_bascule_day),
899 						  "changed",
900 						  G_CALLBACK (widget_transfer_card_choice_bascule_day_changed),
901 						  dialog);
902 	}
903 
904 	/* set card payee */
905 	icon = utils_get_image_with_state (GTK_MESSAGE_ERROR, FALSE, _("This field is required"), NULL);
906 	gtk_grid_attach (GTK_GRID (priv->grid_card_div), icon, 0, 0, 1, 1);
907 
908 	tmp_list = gsb_data_payee_get_name_and_report_list ();
909 	combo = gtk_combofix_new_with_properties (tmp_list,
910 											  etat.combofix_force_payee,
911 											  etat.combofix_case_sensitive,
912 											  FALSE,
913 											  METATREE_PAYEE);
914 	gsb_data_payee_free_name_and_report_list (tmp_list);
915 
916 	gtk_grid_attach (GTK_GRID (priv->grid_card_div), combo, 1, 0, 1, 1);
917 	gsb_form_widget_set_empty (combo, TRUE);
918 	gtk_combofix_set_text (GTK_COMBOFIX (combo), _("Payee"));
919 
920 	priv->entry_card_payee = gtk_combofix_get_entry (GTK_COMBOFIX (combo));
921 	g_object_set_data (G_OBJECT (priv->entry_card_payee), "combo", combo);
922 	g_object_set_data (G_OBJECT (priv->entry_card_payee), "form_type", GINT_TO_POINTER (BET_TRANSFER_PAYEE));
923 	g_object_set_data (G_OBJECT (combo), "icon", icon);
924 	priv->combo_card_payee = combo;
925 
926 	g_signal_connect (G_OBJECT (priv->entry_card_payee),
927 					  "focus-in-event",
928 						G_CALLBACK (bet_form_entry_get_focus),
929 						NULL);
930 	g_signal_connect (G_OBJECT (priv->entry_card_payee),
931 						"focus-out-event",
932 						G_CALLBACK (widget_transfert_div_entry_focus_out),
933 						dialog);
934 
935 	/* saisie des (sous)catégories et (sous)IB */
936 	icon = utils_get_image_with_state (GTK_MESSAGE_WARNING,
937 									  FALSE,
938 									  _("One of the two fields is recommended"),
939 									  NULL);
940 	gtk_grid_attach (GTK_GRID (priv->grid_card_div), icon, 0, 1, 1, 1);
941 
942 	/* set categories */
943 	tmp_list = gsb_data_category_get_name_list (TRUE, TRUE, TRUE, TRUE);
944 	combo = gtk_combofix_new_with_properties (tmp_list,
945 											  etat.combofix_force_category,
946 											  etat.combofix_case_sensitive,
947 											  etat.combofix_mixed_sort,
948 											  METATREE_CATEGORY);
949 	gsb_data_categorie_free_name_list (tmp_list);
950 
951 	gtk_grid_attach (GTK_GRID (priv->grid_card_div), combo, 1, 1, 1, 1);
952 	gsb_form_widget_set_empty (combo, TRUE);
953 	gtk_combofix_set_text (GTK_COMBOFIX (combo), _("Categories : Sub-categories"));
954 
955 	priv->entry_card_category = gtk_combofix_get_entry (GTK_COMBOFIX (combo));
956 	g_object_set_data (G_OBJECT (priv->entry_card_category), "combo", combo);
957 	g_object_set_data (G_OBJECT (priv->entry_card_category), "form_type", GINT_TO_POINTER (BET_TRANSFER_CARD_CATEGORY));
958 	g_object_set_data (G_OBJECT (combo), "icon", icon);
959 	priv->combo_card_category = combo;
960 
961 	g_signal_connect (G_OBJECT (priv->entry_card_category),
962 					  "focus-in-event",
963 					  G_CALLBACK (bet_form_entry_get_focus),
964 					  NULL);
965 	g_signal_connect (G_OBJECT (priv->entry_card_category),
966 					  "focus-out-event",
967 					  G_CALLBACK (widget_transfert_div_entry_focus_out),
968 					  dialog);
969 
970 	/* set budget */
971 	tmp_list = gsb_data_budget_get_name_list (TRUE, TRUE);
972 	combo = gtk_combofix_new_with_properties (tmp_list,
973 											  etat.combofix_force_category,
974 											  etat.combofix_case_sensitive,
975 											  etat.combofix_mixed_sort,
976 											  METATREE_BUDGET);
977 	gsb_data_categorie_free_name_list (tmp_list);
978 	gtk_grid_attach (GTK_GRID (priv->grid_card_div), combo, 2, 1, 1, 1);
979 	gsb_form_widget_set_empty (combo, TRUE);
980 	gtk_combofix_set_text (GTK_COMBOFIX (combo), _("Budgetary line"));
981 
982 	priv->entry_card_budget = gtk_combofix_get_entry (GTK_COMBOFIX (combo));
983 	g_object_set_data (G_OBJECT (priv->entry_card_budget), "combo", combo);
984 	g_object_set_data (G_OBJECT (priv->entry_card_budget), "form_type", GINT_TO_POINTER (BET_TRANSFER_CARD_BUDGET));
985 	g_object_set_data (G_OBJECT (combo), "icon", icon);
986 	priv->combo_card_budget = combo;
987 
988 	g_signal_connect (G_OBJECT (priv->entry_card_budget),
989 					  "focus-in-event",
990 					  G_CALLBACK (bet_form_entry_get_focus),
991 					  NULL);
992 	g_signal_connect (G_OBJECT (priv->entry_card_budget),
993 					  "focus-out-event",
994 					  G_CALLBACK (widget_transfert_div_entry_focus_out),
995 					  dialog);
996 
997 	gtk_widget_show_all (priv->grid_card_div);
998 }
999 
1000 /**
1001  *
1002  *
1003  * \param
1004  * \param
1005  *
1006  * \return
1007  **/
widget_transfer_setup_main_part(WidgetTransfer * dialog,gint account_number)1008 static void widget_transfer_setup_main_part (WidgetTransfer *dialog,
1009 											 gint account_number)
1010 {
1011 	GtkWidget *combo;
1012 	GtkWidget *icon;
1013 	GSList *tmp_list;
1014 	WidgetTransferPrivate *priv;
1015 
1016 	devel_debug (NULL);
1017 	priv = widget_transfer_get_instance_private (dialog);
1018 
1019 	/* entry_date_debit */
1020 	gsb_calendar_entry_new_from_ui (priv->entry_date_debit, FALSE);
1021 	g_signal_connect (G_OBJECT (priv->entry_date_debit),
1022 					  "focus-out-event",
1023 					  G_CALLBACK (widget_transfert_calendar_entry_focus_out),
1024 					  dialog);
1025 
1026 	/* création de la boite de sélection du tiers */
1027 	icon = utils_get_image_with_state (GTK_MESSAGE_ERROR, FALSE, _("This field is required"), NULL);
1028 	gtk_grid_attach (GTK_GRID (priv->grid_main_div), icon, 0, 2, 1, 1);
1029 
1030 	tmp_list = gsb_data_payee_get_name_and_report_list ();
1031 	combo = gtk_combofix_new_with_properties (tmp_list,
1032 											  etat.combofix_force_payee,
1033 											  etat.combofix_case_sensitive,
1034 											  FALSE,
1035 											  METATREE_PAYEE);
1036 	gsb_data_payee_free_name_and_report_list (tmp_list);
1037 
1038 	gtk_grid_attach (GTK_GRID (priv->grid_main_div), combo, 1, 2, 1, 1);
1039 	gsb_form_widget_set_empty (combo, TRUE);
1040 	gtk_combofix_set_text (GTK_COMBOFIX (combo), _("Payee"));
1041 
1042 	priv->entry_main_payee = gtk_combofix_get_entry (GTK_COMBOFIX (combo));
1043 	g_object_set_data (G_OBJECT (priv->entry_main_payee), "combo", combo);
1044 	g_object_set_data (G_OBJECT (priv->entry_main_payee), "form_type", GINT_TO_POINTER (BET_TRANSFER_PAYEE));
1045 	g_object_set_data (G_OBJECT (combo), "icon", icon);
1046 	priv->combo_main_payee = combo;
1047 
1048 	g_signal_connect (G_OBJECT (priv->entry_main_payee),
1049 					  "focus-in-event",
1050 					  G_CALLBACK (bet_form_entry_get_focus),
1051 					  NULL);
1052 	g_signal_connect (G_OBJECT (priv->entry_main_payee),
1053 					  "focus-out-event",
1054 					  G_CALLBACK (widget_transfert_div_entry_focus_out),
1055 					  dialog);
1056 
1057 	/* Création du mode de payement */
1058 	gsb_payment_method_create_combo_list (priv->combo_main_payment,
1059 										  GSB_PAYMENT_DEBIT,
1060 										  account_number,
1061 										  0,
1062 										  FALSE);
1063 	gtk_combo_box_set_active (GTK_COMBO_BOX (priv->combo_main_payment), 0);
1064 	gtk_widget_set_tooltip_text (GTK_WIDGET (priv->combo_main_payment), _("Choose the method of payment"));
1065 
1066 	/* saisie des (sous)catégories et (sous)IB */
1067 	icon = utils_get_image_with_state (GTK_MESSAGE_ERROR, FALSE, _("One of the two fields is required"), NULL);
1068 	gtk_grid_attach (GTK_GRID (priv->grid_main_div), icon, 0, 3, 1, 1);
1069 
1070 	/* set categories */
1071 	tmp_list = gsb_data_category_get_name_list (TRUE, TRUE, TRUE, TRUE);
1072 	combo = gtk_combofix_new_with_properties (tmp_list,
1073 											  etat.combofix_force_category,
1074 											  etat.combofix_case_sensitive,
1075 											  etat.combofix_mixed_sort,
1076 											  METATREE_CATEGORY);
1077 	gsb_data_categorie_free_name_list (tmp_list);
1078 
1079 	gtk_grid_attach (GTK_GRID (priv->grid_main_div), combo, 1, 3, 1, 1);
1080 	gsb_form_widget_set_empty (combo, TRUE);
1081 	gtk_combofix_set_text (GTK_COMBOFIX (combo), _("Categories : Sub-categories"));
1082 
1083 	priv->entry_main_category = gtk_combofix_get_entry (GTK_COMBOFIX (combo));
1084 	g_object_set_data (G_OBJECT (priv->entry_main_category), "combo", combo);
1085 	g_object_set_data (G_OBJECT (priv->entry_main_category), "form_type", GINT_TO_POINTER (BET_TRANSFER_MAIN_CATEGORY));
1086 	g_object_set_data (G_OBJECT (combo), "icon", icon);
1087 	priv->combo_main_category = combo;
1088 
1089 	g_signal_connect (G_OBJECT (priv->entry_main_category),
1090 					  "focus-in-event",
1091 					  G_CALLBACK (bet_form_entry_get_focus),
1092 					  NULL);
1093 	g_signal_connect (G_OBJECT (priv->entry_main_category),
1094 					  "focus-out-event",
1095 					  G_CALLBACK (widget_transfert_div_entry_focus_out),
1096 					  dialog);
1097 
1098 	/* set budget */
1099 	tmp_list = gsb_data_budget_get_name_list (TRUE, TRUE);
1100 	combo = gtk_combofix_new_with_properties (tmp_list,
1101 											  etat.combofix_force_category,
1102 											  etat.combofix_case_sensitive,
1103 											  etat.combofix_mixed_sort,
1104 											  METATREE_BUDGET);
1105 	gsb_data_categorie_free_name_list (tmp_list);
1106 
1107 	gtk_grid_attach (GTK_GRID (priv->grid_main_div), combo, 2, 3, 1, 1);
1108 	gsb_form_widget_set_empty (combo, TRUE);
1109 	gtk_combofix_set_text (GTK_COMBOFIX (combo), _("Budgetary line"));
1110 
1111 	priv->entry_main_budget = gtk_combofix_get_entry (GTK_COMBOFIX (combo));
1112 	g_object_set_data (G_OBJECT (priv->entry_main_budget), "combo", combo);
1113 	g_object_set_data (G_OBJECT (priv->entry_main_budget), "form_type", GINT_TO_POINTER (BET_TRANSFER_MAIN_BUDGET));
1114 	g_object_set_data (G_OBJECT (combo), "icon", icon);
1115 	priv->combo_main_budget = combo;
1116 
1117 	g_signal_connect (G_OBJECT (priv->entry_main_budget),
1118 					  "focus-in-event",
1119 					  G_CALLBACK (bet_form_entry_get_focus),
1120 					  NULL);
1121 	g_signal_connect (G_OBJECT (priv->entry_main_budget),
1122 					  "focus-out-event",
1123 					  G_CALLBACK (widget_transfert_div_entry_focus_out),
1124 					  dialog);
1125 	/* set checkbuttons */
1126 	widget_transfer_sensitive_direct_debit (dialog, FALSE);
1127 	if (priv->create_mode)
1128 	{
1129 		/* set checkbutton_direct_debit */
1130 		g_signal_connect (G_OBJECT (priv->checkbutton_direct_debit),
1131 						  "toggled",
1132 						  G_CALLBACK (widget_transfer_direct_debit_toggle),
1133 						  dialog);
1134 		/* checkbutton_replace_data */
1135 		g_signal_connect (G_OBJECT (priv->checkbutton_replace_data),
1136 						  "toggled",
1137 						  G_CALLBACK (widget_transfer_replace_data_toggle),
1138 						  dialog);
1139 	}
1140 
1141 	gtk_widget_show_all (priv->grid_main_div);
1142 }
1143 
1144 /**
1145  *
1146  *
1147  * \param
1148  * \param
1149  * \param
1150  * \param
1151  * \param
1152  *
1153  * \return
1154  **/
widget_transfer_selection_changed(GtkTreeSelection * selection,GtkTreeModel * model,GtkTreePath * path,gboolean path_currently_selected,WidgetTransfer * dialog)1155 static gboolean widget_transfer_selection_changed (GtkTreeSelection *selection,
1156 												   GtkTreeModel *model,
1157 												   GtkTreePath *path,
1158 												   gboolean path_currently_selected,
1159 												   WidgetTransfer *dialog)
1160 {
1161 	WidgetTransferPrivate *priv;
1162 
1163 	devel_debug (NULL);
1164 	priv = widget_transfer_get_instance_private (dialog);
1165 
1166 	if (!GTK_IS_DIALOG (dialog))
1167 		return FALSE;
1168 
1169 	if (gtk_tree_selection_get_selected (GTK_TREE_SELECTION (selection), NULL, NULL))
1170 		gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, TRUE);
1171 	else
1172 		gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
1173 
1174 	if (priv->create_mode)
1175 	{
1176 		GtkTreeIter iter;
1177 		gint tmp_number;
1178 		gint type_de_compte;
1179 
1180 		gtk_tree_model_get_iter (model, &iter, path);
1181 		gtk_tree_model_get (GTK_TREE_MODEL (model), &iter, 2, &tmp_number, 3, &type_de_compte, -1);
1182 
1183 		if (type_de_compte)
1184 		{
1185 			gtk_widget_hide (priv->combo_card_payment);
1186 		}
1187 		else
1188 		{
1189 			gsb_payment_method_create_combo_list (priv->combo_card_payment,
1190 												  GSB_PAYMENT_CREDIT,
1191 												  tmp_number,
1192 												  0,
1193 												  FALSE);
1194 			gtk_widget_set_tooltip_text (GTK_WIDGET (priv->combo_card_payment), _("Choose the method of payment"));
1195 			gsb_payment_method_set_payment_position (priv->combo_card_payment,
1196 													 gsb_data_account_get_default_credit (tmp_number));
1197 
1198 			if (!GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (priv->combo_card_payment), "handler_id")))
1199 			{
1200 				gulong handler_id;
1201 
1202 				handler_id = g_signal_connect (G_OBJECT (priv->combo_card_payment),
1203 											   "changed",
1204 											   G_CALLBACK (widget_transfer_payment_method_changed),
1205 											   dialog);
1206 				g_object_set_data (G_OBJECT (priv->combo_card_payment), "handler_id", GUINT_TO_POINTER (handler_id));
1207 			}
1208 
1209 			gtk_widget_show (priv->combo_card_payment);
1210 		}
1211 
1212 		return TRUE;
1213 	}
1214 	else
1215 		return FALSE;
1216 }
1217 
1218 /**
1219  *
1220  *
1221  * \param
1222  * \param
1223  *
1224  * \return
1225  **/
widget_transfer_setup_treeview(WidgetTransfer * dialog,gint account_number)1226 static void widget_transfer_setup_treeview (WidgetTransfer *dialog,
1227 											gint account_number)
1228 {
1229 	GtkListStore *model;
1230 	GtkTreeViewColumn *column;
1231 	GtkCellRenderer *cell;
1232 	GtkTreeSelection *selection;
1233 	WidgetTransferPrivate *priv;
1234 
1235 	devel_debug (NULL);
1236 	priv = widget_transfer_get_instance_private (dialog);
1237 
1238 	/* create the model */
1239 	model = gtk_list_store_new (5,
1240 								G_TYPE_STRING,		/* account name */
1241 								G_TYPE_STRING,		/* account kind : Cash account or Partial balance */
1242 								G_TYPE_INT,			/* account_number or partial_balance_number */
1243 								G_TYPE_BOOLEAN,		/* FALSE = account, TRUE = partial balance */
1244 								GDK_TYPE_RGBA);
1245 
1246 
1247 	/* create the treeview */
1248 	gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview_transfer), GTK_TREE_MODEL (model));
1249 	g_object_unref (model);
1250 
1251 	/* Account_name */
1252 	cell = gtk_cell_renderer_text_new ();
1253 	column = gtk_tree_view_column_new_with_attributes (_("Name"),
1254 													   cell,
1255 													   "text", BET_TRANSFER_NAME,
1256 													   "cell-background-rgba", BET_TRANSFERT_BACKGROUND,
1257 													   NULL);
1258 	gtk_tree_view_column_set_expand (column, TRUE);
1259 	gtk_tree_view_column_set_alignment (column, COLUMN_CENTER);
1260 	gtk_tree_view_column_set_sort_column_id (column, 0);
1261 	gtk_tree_view_append_column (GTK_TREE_VIEW (priv->treeview_transfer), column);
1262 
1263 	/* type of account */
1264 	cell = gtk_cell_renderer_text_new ();
1265 	column = gtk_tree_view_column_new_with_attributes (_("Type"),
1266 													   cell,
1267 													   "text", BET_TRANSFERT_KIND,
1268 													   "cell-background-rgba", BET_TRANSFERT_BACKGROUND,
1269 													   NULL);
1270 	gtk_tree_view_column_set_expand (column, TRUE);
1271 	gtk_tree_view_column_set_alignment (column, COLUMN_CENTER);
1272 	gtk_tree_view_column_set_sort_column_id (column, 1);
1273 	gtk_tree_view_append_column (GTK_TREE_VIEW (priv->treeview_transfer), column);
1274 
1275 	/* fill the list */
1276 	widget_transfer_fill_list (GTK_WIDGET (priv->treeview_transfer), account_number);
1277 
1278 	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview_transfer));
1279 	gtk_tree_selection_set_select_function (selection,
1280 											(GtkTreeSelectionFunc) widget_transfer_selection_changed,
1281 											dialog,
1282 											NULL);
1283 
1284 	/*colorize the tree_view */
1285 	utils_set_list_store_background_color (priv->treeview_transfer, BET_TRANSFERT_BACKGROUND);
1286 }
1287 
1288 /**
1289  * Création de la page de gestion des transfer
1290  *
1291  * \param
1292  * \param
1293  * \param
1294  *
1295  * \return
1296  **/
widget_transfer_setup_page(WidgetTransfer * dialog,gint account_number,gboolean create_mode)1297 static void widget_transfer_setup_page (WidgetTransfer *dialog,
1298 										gint account_number,
1299 										gboolean create_mode)
1300 {
1301 	WidgetTransferPrivate *priv;
1302 
1303 	devel_debug (NULL);
1304 	priv = widget_transfer_get_instance_private (dialog);
1305 	priv->create_mode = create_mode;
1306 
1307 	if (create_mode)
1308 		gtk_widget_hide (priv->button_delete_transfer);
1309 
1310 	widget_transfer_setup_treeview (dialog, account_number);
1311 	widget_transfer_setup_card_part (dialog, account_number);
1312 	widget_transfer_setup_main_part (dialog, account_number);
1313 
1314 	gtk_widget_show (GTK_WIDGET (dialog));
1315 }
1316 
1317 /******************************************************************************/
1318 /* Fonctions propres à l'initialisation des fenêtres                          */
1319 /******************************************************************************/
widget_transfer_init(WidgetTransfer * page)1320 static void widget_transfer_init (WidgetTransfer *page)
1321 {
1322 	gtk_widget_init_template (GTK_WIDGET (page));
1323 }
1324 
widget_transfer_dispose(GObject * object)1325 static void widget_transfer_dispose (GObject *object)
1326 {
1327 	G_OBJECT_CLASS (widget_transfer_parent_class)->dispose (object);
1328 }
1329 
widget_transfer_class_init(WidgetTransferClass * klass)1330 static void widget_transfer_class_init (WidgetTransferClass *klass)
1331 {
1332 	G_OBJECT_CLASS (klass)->dispose = widget_transfer_dispose;
1333 
1334 	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass),
1335 												 "/org/gtk/grisbi/widgets/widget_transfer.ui");
1336 
1337 	gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), WidgetTransfer, vbox_transfer);
1338 	gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), WidgetTransfer, button_delete_transfer);
1339 	gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), WidgetTransfer, treeview_transfer);
1340 
1341 	gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), WidgetTransfer, grid_card_div);
1342 	gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), WidgetTransfer, combo_card_payment);
1343 	gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), WidgetTransfer, entry_date_bascule);
1344 	gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), WidgetTransfer, hbox_date_bascule);
1345 	gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), WidgetTransfer, label_date_bascule);
1346 	gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), WidgetTransfer, combo_card_choice_bascule_day);
1347 
1348 	gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), WidgetTransfer, grid_main_div);
1349 	gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), WidgetTransfer, checkbutton_direct_debit);
1350 	gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), WidgetTransfer, checkbutton_replace_data);
1351 	gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), WidgetTransfer, combo_main_payment);
1352 	gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), WidgetTransfer, entry_date_debit);
1353 	gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), WidgetTransfer, hbox_date_debit);
1354 	gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), WidgetTransfer, label_date_debit);
1355 	gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), WidgetTransfer, combo_main_choice_debit_day);
1356 }
1357 
1358 /******************************************************************************/
1359 /* Public functions                                                           */
1360 /******************************************************************************/
1361 /**
1362  *
1363  *
1364  * \param
1365  * \param
1366  *
1367  * \return
1368  **/
widget_transfer_new(gint account_number,gboolean create_mode)1369 WidgetTransfer *widget_transfer_new (gint account_number,
1370 									 gboolean create_mode)
1371 {
1372 	WidgetTransfer *dialog;
1373 
1374 	dialog =  g_object_new (WIDGET_TRANSFER_TYPE, NULL);
1375 	widget_transfer_setup_page (dialog, account_number, create_mode);
1376 	gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (grisbi_app_get_active_window (NULL)));
1377 
1378 	return dialog;
1379 }
1380 
1381 /**
1382  * remplit la boite de dialogue avec les données du solde de compte
1383  *
1384  * \param account_number
1385  * \param number			numéro du solde partiel
1386  * \param
1387  *
1388  * \return					TRUE if OK or FALSE
1389  **/
widget_transfer_fill_data_from_line(GtkWidget * dialog,gint account_number,gint number)1390 void widget_transfer_fill_data_from_line (GtkWidget *dialog,
1391 										  gint account_number,
1392 										  gint number)
1393 {
1394 	GHashTable *transfert_list;
1395 	gchar *key;
1396 	TransfertData *transfert;
1397 	WidgetTransferPrivate *priv;
1398 
1399 	devel_debug (NULL);
1400 	priv = widget_transfer_get_instance_private (WIDGET_TRANSFER (dialog));
1401 
1402 	if (account_number == 0)
1403 		key = g_strconcat ("0:", utils_str_itoa (number), NULL);
1404 	else
1405 		key = g_strconcat (utils_str_itoa (account_number), ":", utils_str_itoa (number), NULL);
1406 
1407 	transfert_list = bet_data_transfert_get_list ();
1408 
1409 	transfert = g_hash_table_lookup (transfert_list, key);
1410 	if (transfert == NULL)
1411 		return;
1412 
1413 	/* selectionne le compte concerné */
1414 	priv->create_mode = TRUE;
1415 	widget_transfert_select_account_in_treeview (priv->treeview_transfer, transfert);
1416 	priv->create_mode = FALSE;
1417 
1418 	/* debit card part*/
1419 
1420 	/* set date bascule and combo_card_choice_bascule_day */
1421 	if (transfert->date_bascule)
1422 	{
1423 		gsb_calendar_entry_set_date (priv->entry_date_bascule, transfert->date_bascule);
1424 		gsb_form_widget_set_empty (priv->entry_date_bascule, FALSE);
1425 		gtk_combo_box_set_active (GTK_COMBO_BOX (priv->combo_card_choice_bascule_day),
1426 								  transfert->card_choice_bascule_day);
1427 
1428 		if (transfert->card_choice_bascule_day)
1429 		{
1430 			widget_transfer_set_effective_date_bascule (WIDGET_TRANSFER (dialog), transfert->date_bascule);
1431 		}
1432 	}
1433 	else
1434 		gsb_form_widget_set_empty (priv->entry_date_bascule, TRUE);
1435 
1436 	g_signal_connect_after (G_OBJECT (priv->entry_date_bascule),
1437 							"changed",
1438 							G_CALLBACK (widget_transfert_calendar_entry_changed),
1439 							dialog);
1440 
1441 	g_signal_connect (G_OBJECT (priv->combo_card_choice_bascule_day),
1442 					  "changed",
1443 					  G_CALLBACK (widget_transfer_card_choice_bascule_day_changed),
1444 					  dialog);
1445 
1446 	/* set card_payee */
1447 	if (transfert->card_payee_number > 0)
1448 	{
1449 		gtk_combofix_set_text (GTK_COMBOFIX (priv->combo_card_payee),
1450 							   gsb_data_payee_get_name (transfert->card_payee_number, FALSE));
1451 
1452 		gsb_form_widget_set_empty (priv->combo_card_payee, FALSE);
1453 		gtk_editable_set_position (GTK_EDITABLE (gtk_combofix_get_entry
1454 												 (GTK_COMBOFIX (priv->combo_card_payee))), 0);
1455 
1456 		/* on actualise l'état de l'icone associée */
1457 		utils_set_image_with_state (priv->combo_card_payee, TRUE);
1458 	}
1459 	else
1460 	{
1461 		gtk_combofix_set_text (GTK_COMBOFIX (priv->combo_card_payee), _("Payee"));
1462 		gsb_form_widget_set_empty (priv->combo_card_payee, TRUE);
1463 
1464 		/* on actualise l'état de l'icone associée */
1465 		utils_set_image_with_state (priv->combo_card_payee, FALSE);
1466 	}
1467 
1468 	/* set card_payment_method if type = account */
1469 	if (transfert->type == 0)
1470 	{
1471 		gsb_payment_method_create_combo_list (priv->combo_card_payment,
1472 											  GSB_PAYMENT_CREDIT,
1473 											  transfert->replace_account,
1474 											  0,
1475 											  FALSE);
1476 		gtk_widget_set_tooltip_text (GTK_WIDGET (priv->combo_card_payment), _("Choose the method of payment"));
1477 		gsb_payment_method_set_payment_position (priv->combo_card_payment, transfert->card_payment_number);
1478 		g_signal_connect (G_OBJECT (priv->combo_card_payment),
1479 						  "changed",
1480 						  G_CALLBACK (widget_transfer_payment_method_changed),
1481 						  dialog);
1482 	}
1483 	else
1484 	{
1485 		gtk_widget_set_sensitive (priv->combo_card_payment, FALSE);
1486 	}
1487 
1488 	/* set card_category */
1489 	if (transfert->card_category_number > 0)
1490 	{
1491 		gtk_combofix_set_text (GTK_COMBOFIX (priv->combo_card_category),
1492 							   gsb_data_category_get_name (transfert->card_category_number,
1493 														   transfert->card_sub_category_number,
1494 														   NULL));
1495 		gsb_form_widget_set_empty (priv->combo_card_category, FALSE);
1496 		gtk_editable_set_position (GTK_EDITABLE (gtk_combofix_get_entry
1497 												 (GTK_COMBOFIX (priv->combo_card_category))), 0);
1498 	}
1499 	else
1500 	{
1501 		gtk_combofix_set_text (GTK_COMBOFIX (priv->combo_card_category), _("Categories : Sub-categories"));
1502 		gsb_form_widget_set_empty (priv->combo_card_category, TRUE);
1503 	}
1504 
1505 	/* set card_budget */
1506 	if (transfert->card_budgetary_number > 0)
1507 	{
1508 		gtk_combofix_set_text (GTK_COMBOFIX (priv->combo_card_budget),
1509 							   gsb_data_budget_get_name (transfert->card_budgetary_number,
1510 														 transfert->card_sub_budgetary_number,
1511 														 NULL));
1512 		gsb_form_widget_set_empty (priv->combo_card_budget, FALSE);
1513 	}
1514 	else
1515 	{
1516 		gtk_combofix_set_text (GTK_COMBOFIX (priv->combo_card_budget), _("Budgetary line"));
1517 		gsb_form_widget_set_empty (priv->combo_card_budget, TRUE);
1518 	}
1519 
1520 	if (transfert->card_category_number > 0 || transfert->card_budgetary_number > 0)
1521 		utils_set_image_with_state (priv->combo_card_budget, TRUE);
1522 	else
1523 		utils_set_image_with_state (priv->combo_card_budget, FALSE);
1524 
1525 	/* main account part */
1526 
1527 	/* date debit */
1528 	gsb_calendar_entry_set_date (priv->entry_date_debit, transfert->date_debit);
1529 	gsb_form_widget_set_empty (priv->entry_date_debit, FALSE);
1530 
1531 	/* set main_previous_day and init hbox_debit_day */
1532 	g_signal_connect (G_OBJECT (priv->combo_main_choice_debit_day),
1533 					  "changed",
1534 					  G_CALLBACK (widget_transfer_combo_main_choice_debit_day_changed),
1535 					  dialog);
1536 	gtk_combo_box_set_active (GTK_COMBO_BOX (priv->combo_main_choice_debit_day),
1537 							  transfert->main_choice_debit_day);
1538 
1539 	/* set main_payee */
1540 	if (transfert->main_payee_number > 0)
1541 	{
1542 		gtk_combofix_set_text (GTK_COMBOFIX (priv->combo_main_payee),
1543 							   gsb_data_payee_get_name (transfert->main_payee_number, FALSE));
1544 
1545 		gsb_form_widget_set_empty (priv->combo_main_payee, FALSE);
1546 		gtk_editable_set_position (GTK_EDITABLE (gtk_combofix_get_entry
1547 												 (GTK_COMBOFIX (priv->combo_main_payee))), 0);
1548 
1549 		 /* on actualise l'état de l'icone associée */
1550 		utils_set_image_with_state (priv->combo_main_payee, TRUE);
1551    }
1552 	else
1553 	{
1554 		gtk_combofix_set_text (GTK_COMBOFIX (priv->combo_main_payee), _("Payee"));
1555 		gsb_form_widget_set_empty (priv->combo_main_payee, TRUE);
1556 	}
1557 
1558 	/* set main_payment_method */
1559 	gsb_payment_method_set_payment_position (priv->combo_main_payment, transfert->main_payment_number);
1560 
1561 	g_signal_connect (G_OBJECT (priv->combo_main_payment),
1562 					  "changed",
1563 					  G_CALLBACK (widget_transfer_payment_method_changed),
1564 					  dialog);
1565 
1566 	/* set main category */
1567 	if (transfert->main_category_number > 0)
1568 	{
1569 		gtk_combofix_set_text (GTK_COMBOFIX (priv->combo_main_category),
1570 							   gsb_data_category_get_name (transfert->main_category_number,
1571 														   transfert->main_sub_category_number,
1572 														   NULL));
1573 		gsb_form_widget_set_empty (priv->combo_main_category, FALSE);
1574 		gtk_editable_set_position (GTK_EDITABLE (gtk_combofix_get_entry
1575 												 (GTK_COMBOFIX (priv->combo_main_category))), 0);
1576 	}
1577 	else
1578 	{
1579 		gtk_combofix_set_text (GTK_COMBOFIX (priv->combo_main_category), _("Categories : Sub-categories"));
1580 		gsb_form_widget_set_empty (priv->combo_main_category, TRUE);
1581 
1582 		/* on actualise l'état de l'icone associée */
1583 		utils_set_image_with_state (priv->combo_main_category, FALSE);
1584 	}
1585 
1586 	/* main budget */
1587 	if (transfert->main_budgetary_number > 0)
1588 	{
1589 		gtk_combofix_set_text (GTK_COMBOFIX (priv->combo_main_budget),
1590 							   gsb_data_budget_get_name (transfert->main_budgetary_number,
1591 														 transfert->main_sub_budgetary_number,
1592 														 NULL));
1593 		gsb_form_widget_set_empty (priv->combo_main_budget, FALSE);
1594 	}
1595 	else
1596 	{
1597 		gtk_combofix_set_text (GTK_COMBOFIX (priv->combo_main_budget), _("Budgetary line"));
1598 		gsb_form_widget_set_empty (priv->combo_main_budget, TRUE);
1599 	}
1600 
1601 	if (transfert->main_category_number > 0 || transfert->main_budgetary_number > 0)
1602 		utils_set_image_with_state (priv->combo_main_budget, TRUE);
1603 	else
1604 		utils_set_image_with_state (priv->combo_main_budget, FALSE);
1605 
1606 	/* set checkbutton_direct_debit */
1607 	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->checkbutton_direct_debit), transfert->direct_debit);
1608 	g_signal_connect (G_OBJECT (priv->checkbutton_direct_debit),
1609 					  "toggled",
1610 					  G_CALLBACK (widget_transfer_direct_debit_toggle),
1611 					  dialog);
1612 
1613 	/* checkbutton_replace_data */
1614 	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->checkbutton_replace_data),
1615 								  transfert->replace_transaction);
1616 	g_signal_connect (G_OBJECT (priv->checkbutton_replace_data),
1617 					  "toggled",
1618 					  G_CALLBACK (widget_transfer_replace_data_toggle),
1619 					  dialog);
1620 
1621 	gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
1622 }
1623 
1624 /**
1625  *
1626  *
1627  * \param
1628  * \param
1629  *
1630  * \return
1631  **/
widget_transfer_set_date_debit(GtkWidget * dialog,GDate * date_debit)1632 void widget_transfer_set_date_debit (GtkWidget *dialog,
1633 									 GDate *date_debit)
1634 {
1635 	WidgetTransferPrivate *priv;
1636 
1637 	devel_debug (NULL);
1638 	priv = widget_transfer_get_instance_private (WIDGET_TRANSFER (dialog));
1639 
1640 	gsb_calendar_entry_set_date (priv->entry_date_debit, date_debit);
1641 	gsb_form_widget_set_empty (priv->entry_date_debit, FALSE);
1642 
1643 	if (priv->create_mode)
1644 		g_signal_connect (G_OBJECT (priv->combo_main_choice_debit_day),
1645 						  "changed",
1646 						  G_CALLBACK (widget_transfer_combo_main_choice_debit_day_changed),
1647 						  dialog);
1648 }
1649 
1650 /**
1651  * récupère les données du formulaire dialog
1652  *
1653  * \param   structure transfert
1654  * \param   dialog
1655  *
1656  * \return TRUE if OK FALSE if error
1657  **/
widget_transfer_take_data(GtkWidget * dialog,gint account_number,gint number)1658 TransfertData *widget_transfer_take_data (GtkWidget *dialog,
1659 										  gint account_number,
1660 										  gint number)
1661 {
1662 	GtkTreeModel *model;
1663 	GtkTreeIter iter;
1664 	GtkTreeSelection *selection;
1665 	gint replace_account;
1666 	gint type;
1667 	TransfertData *transfert;
1668 	WidgetTransferPrivate *priv;
1669 
1670 	devel_debug (NULL);
1671 	priv = widget_transfer_get_instance_private (WIDGET_TRANSFER (dialog));
1672 
1673 	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview_transfer));
1674 	if (!gtk_tree_selection_get_selected (GTK_TREE_SELECTION (selection), &model, &iter))
1675 		return NULL;
1676 
1677 	transfert = struct_initialise_bet_transfert ();
1678 	transfert->account_number = account_number;
1679 	transfert->number = number;
1680 
1681 	gtk_tree_model_get (GTK_TREE_MODEL (model),
1682 						&iter,
1683 						BET_TRANSFER_ACCOUNT, &replace_account,
1684 						BET_TRANSFERT_PARTIAL, &type,
1685 						-1);
1686 	transfert->replace_account = replace_account;
1687 	transfert->type = type;
1688 
1689 	/* Account with deferred debit card */
1690 	if (gsb_form_widget_check_empty (priv->entry_date_bascule) == FALSE)
1691 	{
1692 		transfert->date_bascule = gsb_calendar_entry_get_date (priv->entry_date_bascule);
1693 		if (transfert->date_bascule == NULL)
1694 		{
1695 			struct_free_bet_transfert (transfert);
1696 
1697 			return NULL;
1698 		}
1699 	}
1700 	else
1701 	{
1702 		struct_free_bet_transfert (transfert);
1703 
1704 		return NULL;
1705 	}
1706 
1707 	/* get combo_card_choice_bascule_day */
1708 	transfert->card_choice_bascule_day = gtk_combo_box_get_active (GTK_COMBO_BOX
1709 																   (priv->combo_card_choice_bascule_day));
1710 
1711 	if (gsb_form_widget_check_empty (priv->combo_card_payee) == FALSE)
1712 	{
1713 		bet_utils_get_payee_data (priv->combo_card_payee, 2, (gpointer) transfert);
1714 		if (transfert->card_payee_number == 0)
1715 		{
1716 			struct_free_bet_transfert (transfert);
1717 
1718 			return NULL;
1719 		}
1720 	}
1721 	else
1722 	{
1723 		struct_free_bet_transfert (transfert);
1724 
1725 		return NULL;
1726 	}
1727 
1728 	bet_utils_get_payment_data (priv->combo_card_payment, 2, (gpointer) transfert);
1729 
1730 	if (gsb_form_widget_check_empty (priv->combo_card_category) == FALSE)
1731 	{
1732 		bet_utils_get_category_data (priv->combo_card_category, 2, (gpointer) transfert);
1733 	}
1734 
1735 	if (gsb_form_widget_check_empty(priv->combo_card_budget) == FALSE)
1736 	{
1737 		bet_utils_get_budget_data (priv->combo_card_budget, 2, (gpointer) transfert);
1738 	}
1739 
1740 	/* Main account */
1741 	if (gsb_form_widget_check_empty (priv->entry_date_debit) == FALSE)
1742 	{
1743 		transfert->date_debit = gsb_calendar_entry_get_date (priv->entry_date_debit);
1744 		if (transfert->date_debit == NULL)
1745 		{
1746 			struct_free_bet_transfert (transfert);
1747 
1748 			return NULL;
1749 		}
1750 	}
1751 	else
1752 	{
1753 		struct_free_bet_transfert (transfert);
1754 
1755 		return NULL;
1756 	}
1757 	transfert->main_choice_debit_day = gtk_combo_box_get_active (GTK_COMBO_BOX
1758 																 (priv->combo_main_choice_debit_day));
1759 
1760 	transfert->replace_transaction = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
1761 																   (priv->checkbutton_replace_data));
1762 
1763 	transfert->direct_debit = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
1764 															(priv->checkbutton_direct_debit));
1765 
1766 	if (transfert->replace_transaction || transfert->direct_debit)
1767 	{
1768 		gboolean empty = TRUE;
1769 
1770 		if (gsb_form_widget_check_empty (priv->combo_main_payee) == FALSE)
1771 		{
1772 			bet_utils_get_payee_data (priv->combo_main_payee, 1, (gpointer) transfert);
1773 			if (transfert->main_payee_number > 0)
1774 				empty = FALSE;
1775 		}
1776 
1777 		bet_utils_get_payment_data (priv->combo_main_payment, 1, (gpointer) transfert);
1778 
1779 		if (gsb_form_widget_check_empty (priv->combo_main_category) == FALSE)
1780 		{
1781 			bet_utils_get_category_data (priv->combo_main_category, 1, (gpointer) transfert);
1782 			empty = FALSE;
1783 		}
1784 
1785 		if (gsb_form_widget_check_empty(priv->combo_main_budget) == FALSE)
1786 		{
1787 			bet_utils_get_budget_data (priv->combo_main_budget, 1, (gpointer) transfert);
1788 			empty = FALSE;
1789 		}
1790 
1791 		if (empty)
1792 		{
1793 			struct_free_bet_transfert (transfert);
1794 
1795 			return NULL;
1796 		}
1797 	}
1798 
1799 	return transfert;
1800 }
1801 
1802 /**
1803  *
1804  *
1805  * \param
1806  *
1807  * \return
1808  **/
1809 /* Local Variables: */
1810 /* c-basic-offset: 4 */
1811 /* End: */
1812 
1813