1 /* ************************************************************************** */
2 /* */
3 /* copyright (c) 2000-2008 Cédric Auger (cedric@grisbi.org) */
4 /* 2004-2008 Benjamin Drieu (bdrieu@april.org) */
5 /* 2008-2009 Pierre Biava (grisbi@pierre.biava.name) */
6 /* https://www.grisbi.org/ */
7 /* */
8 /* This program is free software; you can redistribute it and/or modify */
9 /* it under the terms of the GNU General Public License as published by */
10 /* the Free Software Foundation; either version 2 of the License, or */
11 /* (at your option) any later version. */
12 /* */
13 /* This program is distributed in the hope that it will be useful, */
14 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
15 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
16 /* GNU General Public License for more details. */
17 /* */
18 /* You should have received a copy of the GNU General Public License */
19 /* along with this program; if not, write to the Free Software */
20 /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
21 /* */
22 /* ************************************************************************** */
23
24 /**
25 * \file gsb_form_transaction.c
26 * this file contains function of form for transactions (not scheduled transactions)
27 */
28
29
30 #ifdef HAVE_CONFIG_H
31 #include "config.h"
32 #endif
33
34 #include "include.h"
35 #include <glib/gi18n.h>
36
37 /*START_INCLUDE*/
38 #include "gsb_form_transaction.h"
39 #include "etats_calculs.h"
40 #include "grisbi_app.h"
41 #include "gsb_currency.h"
42 #include "gsb_data_account.h"
43 #include "gsb_data_currency_link.h"
44 #include "gsb_data_form.h"
45 #include "gsb_data_mix.h"
46 #include "gsb_data_payee.h"
47 #include "gsb_data_payment.h"
48 #include "gsb_data_report.h"
49 #include "gsb_data_transaction.h"
50 #include "gsb_form.h"
51 #include "gsb_form_widget.h"
52 #include "gsb_payment_method.h"
53 #include "gsb_real.h"
54 #include "gsb_transactions_list.h"
55 #include "gtk_combofix.h"
56 #include "structures.h"
57 #include "utils_dates.h"
58 #include "erreur.h"
59 /*END_INCLUDE*/
60
61 /*START_STATIC*/
62 /*END_STATIC*/
63
64 /*START_EXTERN*/
65 /*END_EXTERN*/
66
67
68 /**
69 * if only the date and payee are filled in the form, fill all the fields with
70 * the same datas that the last transaction found with the same payee
71 *
72 * \param payee_name
73 *
74 * \return FALSE if no payee name or problem (and the entry payee will be erased), TRUE if ok
75 * */
gsb_form_transaction_complete_form_by_payee(const gchar * payee_name)76 gboolean gsb_form_transaction_complete_form_by_payee ( const gchar *payee_name )
77 {
78 gint payee_number;
79 gint transaction_number = 0;
80 gint account_number;
81 GSList *tmp_list;
82 GrisbiAppConf *a_conf;
83
84 devel_debug (payee_name);
85 a_conf = (GrisbiAppConf *) grisbi_app_get_a_conf ();
86
87 if ( !strlen (payee_name))
88 return FALSE;
89
90 account_number = gsb_form_get_account_number ();
91
92 /* check if another field than date and payee is filled */
93 tmp_list = gsb_form_widget_get_list ();
94 while (tmp_list)
95 {
96 struct_element *element;
97
98 element = tmp_list -> data;
99
100 if ( element -> element_number
101 &&
102 element -> element_number < TRANSACTION_FORM_MAX_WIDGETS
103 &&
104 element -> element_number != TRANSACTION_FORM_DATE
105 &&
106 element -> element_number != TRANSACTION_FORM_PARTY
107 &&
108 element -> element_number != TRANSACTION_FORM_CHEQUE
109 &&
110 ( ( GTK_IS_ENTRY ( element -> element_widget )
111 &&
112 !gsb_form_widget_check_empty ( element -> element_widget ) )
113 ||
114 (GTK_IS_COMBOFIX (element -> element_widget)
115 &&
116 !gsb_form_widget_check_empty (element->element_widget) ) ) )
117 return TRUE;
118
119 tmp_list = tmp_list -> next;
120 }
121
122 /* get the payee_number */
123 payee_number = gsb_data_payee_get_number_by_name ( payee_name, FALSE );
124
125 /* if it's a new payee, go away */
126 if ( !payee_number )
127 return TRUE;
128
129 /* find the last transaction with that payee */
130 if ( a_conf->automatic_completion_payee )
131 transaction_number = gsb_form_transactions_look_for_last_party (payee_number, 0, account_number);
132
133 /* if no same transaction, go away */
134 if ( !transaction_number )
135 return TRUE;
136
137 /* fill the form */
138 tmp_list = gsb_form_widget_get_list ();
139 while (tmp_list)
140 {
141 struct_element *element;
142
143 element = tmp_list -> data;
144
145 if ( element -> element_number != TRANSACTION_FORM_OP_NB
146 &&
147 element -> element_number != TRANSACTION_FORM_DATE
148 &&
149 element -> element_number != TRANSACTION_FORM_VALUE_DATE
150 &&
151 element -> element_number != TRANSACTION_FORM_CREDIT
152 &&
153 element -> element_number != TRANSACTION_FORM_DEBIT
154 &&
155 element -> element_number != TRANSACTION_FORM_EXERCICE
156 &&
157 element -> element_number != TRANSACTION_FORM_PARTY
158 &&
159 element -> element_number != TRANSACTION_FORM_MODE
160 &&
161 element -> element_number != TRANSACTION_FORM_TYPE
162 &&
163 element -> element_number != TRANSACTION_FORM_DEVISE )
164 {
165 gsb_form_fill_element ( element -> element_number,
166 account_number,
167 transaction_number,
168 TRUE );
169
170 /* if split of transaction, propose to recover the children */
171 if (element -> element_number == TRANSACTION_FORM_CATEGORY
172 &&
173 gsb_data_transaction_get_split_of_transaction (transaction_number))
174 {
175 GtkWidget *form_button_recover_split;
176
177 form_button_recover_split = gsb_form_get_recover_split_button ();
178 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON ( form_button_recover_split ),
179 a_conf->automatic_recover_splits );
180 gtk_widget_show ( form_button_recover_split );
181 }
182 }
183 else if ( ( element -> element_number == TRANSACTION_FORM_CREDIT && !a_conf->automatic_erase_credit_debit )
184 ||
185 ( element -> element_number == TRANSACTION_FORM_DEBIT && !a_conf->automatic_erase_credit_debit ) )
186 {
187 gsb_form_fill_element ( element -> element_number,
188 account_number,
189 transaction_number,
190 TRUE );
191 }
192 else if ( element -> element_number == TRANSACTION_FORM_TYPE )
193 {
194 GtkWidget *widget;
195 gint number;
196
197 number = gsb_data_mix_get_mother_transaction_number (transaction_number, TRUE);
198 if ( !number )
199 /* it's not a child split, so set number to transaction_number */
200 number = transaction_number;
201
202 /* ok, now number contains either the transaction_number, either the mother transaction number,
203 * we can check the sign with it */
204 widget = gsb_form_widget_get_widget ( TRANSACTION_FORM_TYPE );
205 if ( gsb_data_mix_get_amount ( number, TRUE ).mantissa < 0 )
206 gsb_payment_method_create_combo_list ( widget,
207 GSB_PAYMENT_DEBIT,
208 account_number, 0, FALSE );
209 else
210 gsb_payment_method_create_combo_list ( widget, GSB_PAYMENT_CREDIT,
211 account_number, 0, FALSE );
212
213 if ( gtk_widget_get_visible (widget))
214 {
215 gint tmp_account;
216
217 number = gsb_data_mix_get_method_of_payment_number (transaction_number, TRUE);
218 tmp_account = gsb_data_transaction_get_account_number ( transaction_number );
219
220 if ( account_number != tmp_account )
221 number = gsb_data_payment_search_number_other_account_by_name ( number,
222 account_number );
223
224 /* we show the cheque entry only for transactions */
225 if (gsb_payment_method_set_combobox_history ( widget, number, TRUE )
226 &&
227 gsb_data_payment_get_show_entry ( number )
228 &&
229 !gsb_data_mix_get_mother_transaction_number (transaction_number, TRUE))
230 {
231 gsb_form_entry_get_focus ( gsb_form_widget_get_widget (
232 TRANSACTION_FORM_CHEQUE) );
233 gtk_widget_show (gsb_form_widget_get_widget (
234 TRANSACTION_FORM_CHEQUE) );
235 }
236 }
237 else
238 gtk_widget_hide ( gsb_form_widget_get_widget ( TRANSACTION_FORM_CHEQUE ) );
239 }
240
241 tmp_list = tmp_list -> next;
242 }
243
244 return TRUE;
245 }
246
247
248
249 /**
250 * Look for the last transaction with the same party. Begin in the current account,
251 * and continue in other accounts if necessary.
252 *
253 * \param no_party the party we are looking for
254 * \param no_new_transaction if the transaction found is that transaction, we don't
255 * \param account_number the account we want to find first the party
256 * keep it
257 *
258 * \return the number of the transaction found, or 0
259 * */
gsb_form_transactions_look_for_last_party(gint no_party,gint no_new_transaction,gint account_number)260 gint gsb_form_transactions_look_for_last_party (gint no_party,
261 gint no_new_transaction,
262 gint account_number)
263 {
264 GSList *list_tmp_transactions;
265 gint last_transaction_with_party_in_account = 0;
266 gint last_transaction_with_party_not_in_account = 0;
267 GrisbiAppConf *a_conf;
268
269 a_conf = (GrisbiAppConf *) grisbi_app_get_a_conf ();
270 list_tmp_transactions = gsb_data_transaction_get_complete_transactions_list ();
271
272 while ( list_tmp_transactions )
273 {
274 gint transaction_number_tmp;
275 transaction_number_tmp = gsb_data_transaction_get_transaction_number (list_tmp_transactions -> data);
276
277 if ( gsb_data_transaction_get_party_number (transaction_number_tmp) == no_party
278 &&
279 transaction_number_tmp != no_new_transaction
280 &&
281 !gsb_data_transaction_get_mother_transaction_number (transaction_number_tmp))
282 {
283 /* we are on a transaction with the same party, it's also a split, so we keep it */
284 if ( gsb_data_transaction_get_account_number (transaction_number_tmp) == account_number)
285 last_transaction_with_party_in_account = transaction_number_tmp;
286 else
287 last_transaction_with_party_not_in_account = transaction_number_tmp;
288 }
289 list_tmp_transactions = list_tmp_transactions -> next;
290 }
291
292 if ( last_transaction_with_party_in_account )
293 return last_transaction_with_party_in_account;
294
295 /* if we don't want to complete with a transaction in another account,
296 * go away here */
297 if ( a_conf->limit_completion_to_current_account )
298 return 0;
299
300 return last_transaction_with_party_not_in_account;
301 }
302
303
304 /**
305 * Clone the children of a split transaction to add the to the new split
306 *
307 * \param new_transaction_number the number of the new mother of the cloned transaction
308 * \param no_last_split the no of last split mother
309 *
310 * \return FALSE
311 * */
gsb_form_transaction_recover_splits_of_transaction(gint new_transaction_number,gint no_last_split)312 gboolean gsb_form_transaction_recover_splits_of_transaction ( gint new_transaction_number,
313 gint no_last_split )
314 {
315 GSList *list_tmp_transactions;
316
317 /* go around the transactions list to get the daughters of the last split */
318 list_tmp_transactions = gsb_data_transaction_get_complete_transactions_list ();
319
320 while ( list_tmp_transactions )
321 {
322 gint transaction_number_tmp;
323
324 transaction_number_tmp = gsb_data_transaction_get_transaction_number (list_tmp_transactions -> data);
325
326 if ( gsb_data_transaction_get_mother_transaction_number (transaction_number_tmp) == no_last_split)
327 {
328 gint new_child_number;
329
330 new_child_number = gsb_data_transaction_new_transaction ( gsb_data_transaction_get_account_number (new_transaction_number));
331 gsb_data_transaction_copy_transaction ( transaction_number_tmp,
332 new_child_number, TRUE );
333 gsb_data_transaction_set_mother_transaction_number ( new_child_number,
334 new_transaction_number);
335 gsb_data_transaction_set_date ( new_child_number,
336 gsb_data_transaction_get_date (new_transaction_number));
337
338 /* if this is a transfer, create the contra transaction */
339 if ( gsb_data_transaction_get_contra_transaction_number (transaction_number_tmp) > 0)
340 gsb_form_transaction_validate_transfer ( new_child_number,
341 TRUE,
342 gsb_data_transaction_get_contra_transaction_account (transaction_number_tmp));
343
344 /* add the transaction to the list */
345 gsb_transactions_list_append_new_transaction (new_child_number, TRUE);
346 }
347 list_tmp_transactions = list_tmp_transactions -> next;
348 }
349 return FALSE;
350 }
351
352
353 /**
354 * return a list of numbers of parties if the party in the form is a
355 * report
356 *
357 * \param none
358 *
359 * \return a g_slist, with -1 if it's a normal party or a list of parties if it's a report
360 * */
gsb_form_transaction_get_parties_list_from_report(void)361 GSList *gsb_form_transaction_get_parties_list_from_report ( void )
362 {
363 GSList *parties_list;
364
365 parties_list = NULL;
366
367 /* check that the party's form exist, else, append -1 and go away */
368 if ( gsb_data_form_check_for_value (TRANSACTION_FORM_PARTY))
369 {
370 GtkWidget *combofix;
371 const gchar *string;
372
373 combofix = gsb_form_widget_get_widget ( TRANSACTION_FORM_PARTY );
374 if ( GTK_IS_COMBOFIX ( combofix ) )
375 string = gtk_combofix_get_text ( GTK_COMBOFIX ( combofix ) );
376 else
377 {
378 parties_list = g_slist_append ( parties_list, GINT_TO_POINTER ( - 1) );
379 return parties_list;
380 }
381
382 if ( string == NULL || strlen ( string ) == 0 )
383 {
384 parties_list = g_slist_append ( parties_list, GINT_TO_POINTER ( - 1) );
385 return parties_list;
386 }
387
388 if ( strncmp ( string, _("Report: "), 7 ) )
389 /* the party is not a report, set -1 and go away */
390 parties_list = g_slist_append ( parties_list, GINT_TO_POINTER ( -1 ) );
391 else
392 {
393 /* it's a report */
394 gchar **tab_char;
395 gint report_number;
396
397 tab_char = g_strsplit ( string, " : ", 2 );
398
399 report_number = gsb_data_report_get_report_by_name (tab_char[1]);
400 if (report_number)
401 {
402 GSList *list_payees;
403 GSList *list_tmp;
404
405 list_payees = gsb_data_report_get_payee_numbers_list ( report_number );
406 list_tmp = list_payees;
407 while ( list_tmp )
408 {
409 parties_list = g_slist_append ( parties_list, list_tmp->data );
410
411 list_tmp = list_tmp->next;
412 }
413
414 }
415 else
416 /* the report was not found, set -1 */
417 parties_list = g_slist_append ( parties_list, GINT_TO_POINTER ( -1 ) );
418 g_strfreev ( tab_char );
419 }
420 }
421 else
422 /* no party so not a report */
423 parties_list = g_slist_append ( parties_list, GINT_TO_POINTER ( - 1) );
424
425 return parties_list;
426 }
427
428
429
430 /**
431 * validate a transfert from a form :
432 * - create the contra-transaction
433 * - delete the last contra-transaction if it's a modification
434 * - append the contra-transaction to the tree view or update the tree_view
435 *
436 * \param transaction_number the new transaction or the modifed transaction
437 * \param new_transaction TRUE if it's a new transaction
438 * \param account_transfer the number of the account we want to create the contra-transaction
439 *
440 * \return the number of the contra-transaction
441 * */
gsb_form_transaction_validate_transfer(gint transaction_number,gint new_transaction,gint account_transfer)442 gint gsb_form_transaction_validate_transfer ( gint transaction_number,
443 gint new_transaction,
444 gint account_transfer )
445 {
446 GDate *contra_value_date = NULL;
447 const gchar *contra_transaction_content = NULL;
448 gint contra_payment_number = 0;
449 gint contra_transaction_number = 0;
450 gint contra_mother_number = 0;
451 gint contra_marked_transaction = 0;
452 GtkWidget *contra_payment_button;
453
454 g_return_val_if_fail ( account_transfer >= 0, -1 );
455
456 /* either it's a new transfer or a change of a non-transfer transaction
457 * either it was already a transfer, in that case, if we change the target account,
458 * we delete the contra-transaction and it's the same as a new transfer */
459 if ( !new_transaction )
460 {
461 /* it's a modification of a transaction */
462
463 /* as we will do a transfer, the category number is null */
464 gsb_data_transaction_set_category_number ( transaction_number, 0 );
465 gsb_data_transaction_set_sub_category_number ( transaction_number, 0 );
466 contra_transaction_number = gsb_data_transaction_get_contra_transaction_number (
467 transaction_number);
468 if (contra_transaction_number > 0)
469 {
470 const GDate *value_date;
471
472 /* the transaction is a transfer */
473
474 /* if the contra transaction was a child of split, copying/deleting it
475 * will remove the information of the mother, so we get it here */
476 contra_mother_number = gsb_data_transaction_get_mother_transaction_number (
477 contra_transaction_number );
478
479 /* on récupère le moyen de payement de l'opération fille qui ne doit pas changer */
480 if ( contra_mother_number > 0 )
481 contra_payment_number = gsb_data_transaction_get_method_of_payment_number (
482 contra_transaction_number );
483
484 /* Copying/deleting remove the marked information, so we get it here */
485 contra_marked_transaction = gsb_data_transaction_get_marked_transaction (
486 contra_transaction_number );
487
488 /* Copying/deleting remove the content information, so we get it here */
489 contra_transaction_content = gsb_data_transaction_get_method_of_payment_content (
490 contra_transaction_number );
491
492 /* Copying/deleting remove the value date, so we get it here */
493 value_date = gsb_data_transaction_get_value_date ( contra_transaction_number );
494 if ( value_date )
495 contra_value_date = gsb_date_copy ( value_date );
496
497 /* check if we change the account target */
498 if ( gsb_data_transaction_get_contra_transaction_account (
499 transaction_number) != account_transfer )
500 {
501 /* it was a transfer and the user changed the target account so we delete
502 * the last contra transaction contra_transaction_transfer has just been set */
503 gsb_data_transaction_set_contra_transaction_number (
504 contra_transaction_number, 0);
505 gsb_transactions_list_delete_transaction (contra_transaction_number, FALSE);
506 new_transaction = 1;
507 }
508 }
509 else
510 {
511 /* the transaction was not a transfer, so it's the same as a new transaction, to do the contra-transaction */
512 new_transaction = 1;
513 }
514 }
515
516 /* so, now, it's either a new transfer and new_transaction is TRUE,
517 * either a transfer without changing the target account and in that case, contra_transaction_number is
518 * already set */
519 if ( new_transaction )
520 contra_transaction_number = gsb_data_transaction_new_transaction ( account_transfer );
521
522 gsb_data_transaction_copy_transaction ( transaction_number,
523 contra_transaction_number, new_transaction );
524
525 /* contra_mother_number contains the mother number of the contra transaction if it was a modification
526 * and that contra-transaction was a child of split, and if not it is 0, and it's a good thing because
527 * now contra-transaction has a mother number if the transaction was a child of split, and we have to
528 * set that mother number to 0 (for the contra-transaction) */
529 gsb_data_transaction_set_mother_transaction_number ( contra_transaction_number,
530 contra_mother_number );
531
532 /* si la contre opération est une fille et pas rapprochée on change la date */
533 if ( contra_mother_number > 0 && contra_marked_transaction != OPERATION_RAPPROCHEE )
534 {
535 const GDate *date;
536
537 date = gsb_data_transaction_get_date ( transaction_number );
538 if (g_date_valid (date))
539 {
540 gsb_data_transaction_set_date ( contra_mother_number, date );
541 gsb_transactions_list_update_transaction ( contra_mother_number );
542 }
543 }
544
545 /* If this is not a new transaction it restores the marked statement */
546 gsb_data_transaction_set_marked_transaction ( contra_transaction_number,
547 contra_marked_transaction );
548
549 /* If this is not a new transaction it restores the value date */
550 if ( contra_value_date )
551 {
552 gsb_data_transaction_set_value_date ( contra_transaction_number, contra_value_date );
553
554 g_date_free ( contra_value_date );
555 }
556
557 /* we have to change the amount by the opposite */
558 gsb_data_transaction_set_amount (contra_transaction_number,
559 gsb_real_opposite (gsb_data_transaction_get_amount (transaction_number)));
560
561
562 /* we have to check the change */
563 gsb_currency_check_for_change ( contra_transaction_number );
564
565 /* set the contra-method of payment if the contra-transaction was not a child of split,
566 * there is no place into the transaction structure for that, so it was not taken with the form,
567 * we need to get it now from the form */
568 if ( contra_mother_number == 0 )
569 {
570 contra_payment_button = gsb_form_widget_get_widget ( TRANSACTION_FORM_CONTRA );
571 if ( contra_payment_button
572 &&
573 gtk_widget_get_visible ( contra_payment_button ) )
574 gsb_data_transaction_set_method_of_payment_number ( contra_transaction_number,
575 gsb_payment_method_get_selected_number ( contra_payment_button ) );
576 }
577 else
578 gsb_data_transaction_set_method_of_payment_number ( contra_transaction_number,
579 contra_payment_number );
580
581 /* set the content of the contra-method of paiement if it is not a new transaction */
582 if ( !new_transaction )
583 gsb_data_transaction_set_method_of_payment_content ( contra_transaction_number,
584 contra_transaction_content );
585
586 /* set the link between the transactions */
587 gsb_data_transaction_set_contra_transaction_number ( transaction_number,
588 contra_transaction_number);
589 gsb_data_transaction_set_contra_transaction_number ( contra_transaction_number,
590 transaction_number);
591
592 /* show the contra_transaction */
593 if ( new_transaction )
594 gsb_transactions_list_append_new_transaction (contra_transaction_number, TRUE);
595 else
596 gsb_transactions_list_update_transaction (contra_transaction_number);
597
598 return contra_transaction_number;
599 }
600
601
602 /**
603 * callback called when the user click on the 'change' button in the form
604 * show a popup to modify the values
605 *
606 * \param button
607 * \param null
608 *
609 * \return FALSE
610 * */
gsb_form_transaction_change_clicked(GtkWidget * button,gpointer null)611 gboolean gsb_form_transaction_change_clicked ( GtkWidget *button,
612 gpointer null )
613 {
614 gint transaction_number;
615 gint account_number;
616 gint currency_number;
617 gint account_currency_number;
618
619 account_number = gsb_form_get_account_number ( );
620 account_currency_number = gsb_data_account_get_currency ( account_number );
621 gtk_widget_grab_focus ( gsb_form_widget_get_widget ( TRANSACTION_FORM_DATE ));
622
623 transaction_number = GPOINTER_TO_INT (g_object_get_data (
624 G_OBJECT ( gsb_form_get_form_widget ( ) ),
625 "transaction_number_in_form" ));
626
627 if ( transaction_number == -1 )
628 {
629 gint link_number;
630
631 currency_number = gsb_currency_get_currency_from_combobox (
632 gsb_form_widget_get_widget ( TRANSACTION_FORM_DEVISE ) );
633 link_number = gsb_data_currency_link_search ( account_currency_number,
634 currency_number );
635 if ( link_number
636 &&
637 gsb_data_currency_link_get_first_currency ( link_number )
638 == account_currency_number )
639 gsb_currency_exchange_dialog ( account_currency_number, currency_number,
640 1,
641 gsb_data_currency_link_get_change_rate ( link_number ),
642 null_real,
643 TRUE );
644 else
645 gsb_currency_exchange_dialog ( account_currency_number, currency_number,
646 0,
647 gsb_data_currency_link_get_change_rate ( link_number ),
648 null_real,
649 TRUE );
650 }
651 else
652 {
653 currency_number = gsb_data_transaction_get_currency_number ( transaction_number );
654 gsb_currency_exchange_dialog ( account_currency_number, currency_number,
655 gsb_data_transaction_get_change_between ( transaction_number ),
656 gsb_data_transaction_get_exchange_rate ( transaction_number ),
657 gsb_data_transaction_get_exchange_fees ( transaction_number ),
658 TRUE );
659 }
660
661 return FALSE;
662 }
663
664
gsb_form_transaction_currency_changed(GtkWidget * widget,gpointer null)665 void gsb_form_transaction_currency_changed ( GtkWidget *widget, gpointer null )
666 {
667 gint account_number;
668 gint currency_number;
669 gint account_currency_number;
670 gint transaction_number;
671 gint link_number;
672
673 account_number = gsb_form_get_account_number ( );
674 gtk_widget_grab_focus ( gsb_form_widget_get_widget ( TRANSACTION_FORM_DATE ) );
675
676 account_currency_number = gsb_data_account_get_currency ( account_number );
677
678 transaction_number = GPOINTER_TO_INT ( g_object_get_data (
679 G_OBJECT ( gsb_form_get_form_widget ( ) ),
680 "transaction_number_in_form" ) );
681
682 currency_number = gsb_currency_get_currency_from_combobox ( widget );
683 if ( account_currency_number == currency_number )
684 gtk_widget_hide ( gsb_form_widget_get_widget ( TRANSACTION_FORM_CHANGE ) );
685 else
686 gtk_widget_show ( gsb_form_widget_get_widget ( TRANSACTION_FORM_CHANGE ) );
687
688 link_number = gsb_data_currency_link_search ( account_currency_number,
689 currency_number );
690 if ( link_number == 0 )
691 {
692 if ( gsb_data_transaction_get_marked_transaction ( transaction_number ) == OPERATION_RAPPROCHEE )
693 {
694 gtk_widget_set_sensitive ( widget, FALSE );
695 gtk_widget_hide ( gsb_form_widget_get_widget (
696 TRANSACTION_FORM_CHANGE ) );
697 }
698 else if ( transaction_number == -1 )
699 gsb_currency_exchange_dialog ( account_currency_number,
700 currency_number,
701 0,
702 null_real,
703 null_real,
704 TRUE );
705 else
706 {
707 gsb_currency_exchange_dialog ( account_currency_number,
708 currency_number,
709 gsb_data_transaction_get_change_between ( transaction_number ),
710 gsb_data_transaction_get_exchange_rate ( transaction_number ),
711 gsb_data_transaction_get_exchange_fees ( transaction_number ),
712 TRUE );
713 }
714 }
715 else if ( transaction_number > 0 )
716 {
717 gsb_currency_set_current_exchange ( gsb_data_transaction_get_exchange_rate ( transaction_number ) );
718 gsb_currency_set_current_exchange_fees ( gsb_data_transaction_get_exchange_fees ( transaction_number ) );
719 }
720 }
721 /* Local Variables: */
722 /* c-basic-offset: 4 */
723 /* End: */
724