1 /* ************************************************************************** */
2 /*                                                                            */
3 /*     Copyright (C)	2000-2008 Cédric Auger (cedric@grisbi.org)	          */
4 /*			2003-2008 Benjamin Drieu (bdrieu@april.org)	                      */
5 /* 			https://www.grisbi.org				                              */
6 /*                                                                            */
7 /*  This program is free software; you can redistribute it and/or modify      */
8 /*  it under the terms of the GNU General Public License as published by      */
9 /*  the Free Software Foundation; either version 2 of the License, or         */
10 /*  (at your option) any later version.                                       */
11 /*                                                                            */
12 /*  This program is distributed in the hope that it will be useful,           */
13 /*  but WITHOUT ANY WARRANTY; without even the implied warranty of            */
14 /*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             */
15 /*  GNU General Public License for more details.                              */
16 /*                                                                            */
17 /*  You should have received a copy of the GNU General Public License         */
18 /*  along with this program; if not, write to the Free Software               */
19 /*  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
20 /*                                                                            */
21 /* ************************************************************************** */
22 
23 /**
24  * \file gsb_scheduler.c
25  * contains several functions to work with the schedulers transactions
26  */
27 
28 
29 #ifdef HAVE_CONFIG_H
30 #include "config.h"
31 #endif
32 
33 #include "include.h"
34 
35 /*START_INCLUDE*/
36 #include "gsb_scheduler.h"
37 #include "accueil.h"
38 #include "bet_finance_ui.h"
39 #include "grisbi_app.h"
40 #include "gsb_currency.h"
41 #include "gsb_data_account.h"
42 #include "gsb_data_fyear.h"
43 #include "gsb_data_payment.h"
44 #include "gsb_data_scheduled.h"
45 #include "gsb_data_transaction.h"
46 #include "gsb_form_transaction.h"
47 #include "gsb_file.h"
48 #include "gsb_scheduler_list.h"
49 #include "gsb_transactions_list.h"
50 #include "structures.h"
51 #include "traitement_variables.h"
52 #include "utils_dates.h"
53 #include "utils_real.h"
54 #include "erreur.h"
55 /*END_INCLUDE*/
56 
57 /*START_STATIC*/
58 static gint gsb_scheduler_create_transaction_from_scheduled_transaction ( gint scheduled_number,
59 								   gint transaction_mother );
60 static gboolean gsb_scheduler_get_category_for_transaction_from_transaction ( gint transaction_number,
61 								       gint scheduled_number );
62 /*END_STATIC*/
63 
64 /*START_EXTERN*/
65 extern GSList *scheduled_transactions_taken;
66 extern GSList *scheduled_transactions_to_take;
67 /*END_EXTERN*/
68 
69 /**
70  * set the next date in the scheduled transaction
71  * if it's above the limit date, that transaction is deleted
72  * if it's a split, the children are updated too
73  * if the scheduled transaction is finished, it's removed from the list and from the scheduled transactions
74  *
75  * \param scheduled_number the scheduled transaction we want to increase
76  *
77  * \return FALSE if the scheduled transaction is finished, TRUE else
78  * */
gsb_scheduler_increase_scheduled(gint scheduled_number)79 gboolean gsb_scheduler_increase_scheduled ( gint scheduled_number )
80 {
81     GDate *new_date;
82 
83     g_return_val_if_fail ( g_date_valid (gsb_data_scheduled_get_date (scheduled_number)), TRUE );
84 
85 devel_debug (NULL);
86     /* increase the date of the scheduled_transaction */
87     new_date = gsb_scheduler_get_next_date ( scheduled_number,
88 					     gsb_data_scheduled_get_date (scheduled_number));
89 
90     /* we continue to work only if new_date is not null (null mean reach the end) */
91     if (new_date)
92     {
93 	/* set the new date */
94 	gsb_data_scheduled_set_date ( scheduled_number, new_date);
95 
96 	if ( gsb_data_scheduled_get_split_of_scheduled ( scheduled_number ))
97 	{
98 	    GSList *children_numbers_list;
99 		gint transfer_account;
100 		gint init_sch_with_loan;
101 		GsbReal amount;
102 
103 		transfer_account = gsb_data_scheduled_get_account_number_transfer (scheduled_number+1);
104 		init_sch_with_loan = gsb_data_account_get_bet_init_sch_with_loan (transfer_account);
105 		if (init_sch_with_loan)
106 		{
107 			amount = bet_finance_get_loan_amount_at_date (scheduled_number, transfer_account, new_date, FALSE);
108 			gsb_data_scheduled_set_amount (scheduled_number, amount);
109 		}
110 
111 	    /* if there is some children, set the new date too */
112 	    children_numbers_list = gsb_data_scheduled_get_children ( scheduled_number, TRUE );
113 
114 	    while ( children_numbers_list )
115 	    {
116 			gint child_number;
117 
118 			child_number = GPOINTER_TO_INT ( children_numbers_list -> data );
119 
120 			gsb_data_scheduled_set_date (child_number, new_date);
121 			if (init_sch_with_loan)
122 			{
123 				amount = bet_finance_get_loan_amount_at_date (child_number, transfer_account, new_date, FALSE);
124 				gsb_data_scheduled_set_amount (child_number, amount);
125 			}
126 
127 			children_numbers_list = children_numbers_list -> next;
128 	    }
129 	    g_slist_free (children_numbers_list);
130 	}
131 	g_date_free (new_date);
132     }
133     else
134     {
135 	/* the scheduled transaction is over, we remove it */
136 	/* update the main page */
137 	gsb_main_page_update_finished_scheduled_transactions (scheduled_number);
138 
139 	/* remove the scheduled transaction */
140 	/* A ce stade la liste n'est pas initialisée  */
141 	//~ gsb_scheduler_list_remove_transaction_from_list ( scheduled_number );
142 	gsb_data_scheduled_remove_scheduled (scheduled_number);
143 	return FALSE;
144     }
145     return TRUE;
146 }
147 
148 
149 
150 /**
151  * find and return the next date after the given date for the given scheduled
152  * transaction
153  *
154  * \param scheduled_number
155  * \param date the current date, we want the next one after that one
156  *
157  * \return a newly allocated date, the next date or NULL if over the limit
158  * */
gsb_scheduler_get_next_date(gint scheduled_number,const GDate * date)159 GDate *gsb_scheduler_get_next_date ( gint scheduled_number,
160 				     const GDate *date )
161 {
162 	GDate *tmp_date;
163     GDate *return_date;
164 	gint fixed_date;
165 
166     if ( !scheduled_number
167 	 ||
168 	 !gsb_data_scheduled_get_frequency (scheduled_number)
169 	 ||
170 	 !date
171 	 ||
172 	 !g_date_valid (date))
173 	return NULL;
174 
175 	/* we don't change the initial date */
176     return_date = gsb_date_copy (date);
177 
178 	/* initialise les données pour fixed date */
179 	fixed_date = gsb_data_scheduled_get_fixed_date (scheduled_number);
180 
181     switch (gsb_data_scheduled_get_frequency (scheduled_number))
182     {
183 		case SCHEDULER_PERIODICITY_ONCE_VIEW:
184 			return NULL;
185 			break;
186 
187 		case SCHEDULER_PERIODICITY_WEEK_VIEW:
188 			g_date_add_days ( return_date, 7 );
189 			/* FIXME : there were a bug in gtk and we had to add 0 month to have the good date,
190 			 * it seems fixed but we should wait the stable debian is upgraded to
191 			 * remove that [26/10/2008] */
192 			g_date_add_months ( return_date, 0 );
193 			break;
194 
195 		case SCHEDULER_PERIODICITY_MONTH_VIEW:
196 			g_date_add_months ( return_date, 1 );
197 			/* set the correct date if necessary */
198 			if (fixed_date)
199 			{
200 				tmp_date = gsb_date_copy (return_date);
201 				g_date_set_day (return_date, fixed_date);
202 				if (!g_date_valid (return_date))
203 				{
204 					g_date_free (return_date);
205 					return_date = gsb_date_get_last_day_of_month (tmp_date);
206 				}
207 				g_date_free (tmp_date);
208 			}
209 			break;
210 
211 		case SCHEDULER_PERIODICITY_TWO_MONTHS_VIEW:
212 			g_date_add_months ( return_date, 2 );
213 			/* set the correct date if necessary */
214 			if (fixed_date)
215 			{
216 				tmp_date = gsb_date_copy (return_date);
217 				g_date_set_day (return_date, fixed_date);
218 				if (!g_date_valid (return_date))
219 				{
220 					g_date_free (return_date);
221 					return_date = gsb_date_get_last_day_of_month (tmp_date);
222 				}
223 				g_date_free (tmp_date);
224 			}
225 			break;
226 
227 		case SCHEDULER_PERIODICITY_TRIMESTER_VIEW:
228 			g_date_add_months ( return_date, 3 );
229 			/* set the correct date if necessary */
230 			if (fixed_date)
231 			{
232 				tmp_date = gsb_date_copy (return_date);
233 				g_date_set_day (return_date, fixed_date);
234 				if (!g_date_valid (return_date))
235 				{
236 					g_date_free (return_date);
237 					return_date = gsb_date_get_last_day_of_month (tmp_date);
238 				}
239 				g_date_free (tmp_date);
240 			}
241 			break;
242 
243 		case SCHEDULER_PERIODICITY_YEAR_VIEW:
244 			g_date_add_years ( return_date, 1 );
245 			break;
246 
247 		case SCHEDULER_PERIODICITY_CUSTOM_VIEW:
248 			if ( gsb_data_scheduled_get_user_entry (scheduled_number) <= 0 )
249 			{
250 				g_date_free (return_date);
251 				return NULL;
252 			}
253 
254 			switch (gsb_data_scheduled_get_user_interval (scheduled_number))
255 			{
256 				case PERIODICITY_DAYS:
257 					g_date_add_days ( return_date,
258 							  gsb_data_scheduled_get_user_entry (scheduled_number));
259 					/* FIXME : there were a bug in gtk and we had to add 0 month to have the good date,
260 					 * it seems fixed but we should wait the stable debian is upgraded to
261 					 * remove that [26/10/2008] */
262 					g_date_add_months ( return_date, 0 );
263 					break;
264 
265 				case PERIODICITY_WEEKS:
266 					g_date_add_days ( return_date,
267 							  gsb_data_scheduled_get_user_entry (scheduled_number) * 7 );
268 					g_date_add_months ( return_date, 0 );
269 					break;
270 
271 				case PERIODICITY_MONTHS:
272 					g_date_add_months ( return_date,
273 							gsb_data_scheduled_get_user_entry (scheduled_number));
274 			/* set the correct date if necessary */
275 			if (fixed_date)
276 			{
277 				tmp_date = gsb_date_copy (return_date);
278 				g_date_set_day (return_date, fixed_date);
279 				if (!g_date_valid (return_date))
280 				{
281 					g_date_free (return_date);
282 					return_date = gsb_date_get_last_day_of_month (tmp_date);
283 				}
284 				g_date_free (tmp_date);
285 			}
286 					break;
287 
288 				case PERIODICITY_YEARS:
289 					g_date_add_years ( return_date,
290 							   gsb_data_scheduled_get_user_entry (scheduled_number));
291 					g_date_add_months ( return_date, 0 );
292 					break;
293 			}
294 			break;
295     }
296 
297     if ( gsb_data_scheduled_get_limit_date (scheduled_number)
298 	 &&
299 	 g_date_compare ( return_date,
300 			  gsb_data_scheduled_get_limit_date (scheduled_number)) > 0 )
301     {
302 	g_date_free (return_date);
303 	return_date = NULL;
304     }
305 
306     return ( return_date );
307 }
308 
309 
310 
311 /**
312  * create a new transaction and fill it directly from a scheduled transaction
313  * (don't pass throw the form)
314  * if it's a child of split, append it automatickly to the mother
315  *
316  * \param scheduled_number the transaction we use to fill the new transaction
317  * \param transaction_mother the number of the mother if it's a split child, 0 else
318  *
319  * \return the number of the new transaction
320  * */
gsb_scheduler_create_transaction_from_scheduled_transaction(gint scheduled_number,gint transaction_mother)321 gint gsb_scheduler_create_transaction_from_scheduled_transaction ( gint scheduled_number,
322 								   gint transaction_mother )
323 {
324 	GDate *date;
325     gint account_number;
326     gint payment_number;
327 	gint transfer_account;
328     gint transaction_number;
329 
330 	devel_debug_int (scheduled_number);
331     account_number = gsb_data_scheduled_get_account_number (scheduled_number);
332 
333 	transfer_account = gsb_data_scheduled_get_account_number_transfer (scheduled_number+1);
334     transaction_number = gsb_data_transaction_new_transaction (account_number);
335 
336 	/* initialise les données pour fixed date */
337 	date = gsb_data_scheduled_get_date (scheduled_number);
338 
339 	/* begin to fill the new transaction */
340     gsb_data_transaction_set_date (transaction_number, date);
341 
342 	gsb_data_transaction_set_party_number ( transaction_number,
343 					    gsb_data_scheduled_get_party_number (scheduled_number));
344 	if (gsb_data_scheduled_get_split_of_scheduled (scheduled_number)
345 		&& gsb_data_account_get_bet_init_sch_with_loan (transfer_account))
346 	{
347 		GsbReal amount;
348 
349 		amount = bet_finance_get_loan_amount_at_date (scheduled_number, transfer_account, date, TRUE);
350 		gsb_data_transaction_set_amount (transaction_number, amount);
351 	}
352 	else if (transaction_mother && transfer_account > 0)
353 	{
354 		gint scheduled_mother;
355 
356 		if (bet_data_loan_get_last_loan_struct_by_account (transfer_account))
357 		{
358 			scheduled_mother = gsb_data_scheduled_get_mother_scheduled_number (scheduled_number);
359 			if (scheduled_mother == scheduled_number -1
360 				|| scheduled_mother == scheduled_number -2
361 				|| scheduled_mother == scheduled_number -3)
362 			{
363 				GsbReal amount;
364 
365 				amount = bet_finance_get_loan_amount_at_date (scheduled_number, transfer_account, date, FALSE);
366 				gsb_data_transaction_set_amount (transaction_number, amount);
367 			}
368 		}
369 		else
370 			gsb_data_transaction_set_amount ( transaction_number, gsb_data_scheduled_get_amount (scheduled_number));
371 
372 	}
373 	else
374 		gsb_data_transaction_set_amount ( transaction_number, gsb_data_scheduled_get_amount (scheduled_number));
375 
376 	gsb_data_transaction_set_currency_number ( transaction_number,
377 					       gsb_data_scheduled_get_currency_number (scheduled_number));
378     gsb_data_transaction_set_account_number ( transaction_number,
379 					      account_number );
380 
381     /* ask for change if necessary, only for normal transaction ; a child must have the same currency number
382      * than the mother */
383     if (!transaction_mother)
384 	gsb_currency_check_for_change ( transaction_number );
385 
386     gsb_data_transaction_set_method_of_payment_number ( transaction_number,
387 							gsb_data_scheduled_get_method_of_payment_number (scheduled_number));
388     gsb_data_transaction_set_notes ( transaction_number,
389 				     gsb_data_scheduled_get_notes (scheduled_number));
390 
391     payment_number = gsb_data_scheduled_get_method_of_payment_number (scheduled_number);
392     if ( payment_number )
393     {
394 	if (gsb_data_payment_get_show_entry (payment_number))
395 	{
396 	    if (gsb_data_payment_get_automatic_numbering (payment_number))
397 	    {
398 		gchar* tmpstr;
399 
400 		tmpstr = gsb_data_payment_incremente_last_number ( payment_number, 1 );
401 		gsb_data_transaction_set_method_of_payment_content ( transaction_number,
402 								     tmpstr);
403 		gsb_data_payment_set_last_number ( payment_number, tmpstr );
404         g_free ( tmpstr );
405 	    }
406 	    else
407 		gsb_data_transaction_set_method_of_payment_content ( transaction_number,
408 								     gsb_data_scheduled_get_method_of_payment_content (
409                                      scheduled_number ) );
410 	}
411     }
412     else
413     {
414 	gsb_data_transaction_set_method_of_payment_content ( transaction_number,
415 							     gsb_data_scheduled_get_method_of_payment_content (
416                                  scheduled_number ) );
417     }
418     gsb_data_transaction_set_automatic_transaction ( transaction_number,
419 						     gsb_data_scheduled_get_automatic_scheduled (scheduled_number));
420     gsb_data_transaction_set_budgetary_number ( transaction_number,
421 						gsb_data_scheduled_get_budgetary_number (scheduled_number));
422     gsb_data_transaction_set_sub_budgetary_number ( transaction_number,
423 						    gsb_data_scheduled_get_sub_budgetary_number (scheduled_number));
424 
425     /* if the financial year is automatic, we set it here */
426     if ( gsb_data_scheduled_get_financial_year_number ( scheduled_number ) == 0 )
427         gsb_data_transaction_set_financial_year_number ( transaction_number,
428     				    gsb_data_fyear_get_from_date ( gsb_data_transaction_get_date ( transaction_number ) ) );
429     else
430         gsb_data_transaction_set_financial_year_number ( transaction_number,
431     				    gsb_data_scheduled_get_financial_year_number ( scheduled_number ) );
432 
433     /* get the category */
434 
435     gsb_scheduler_get_category_for_transaction_from_transaction ( transaction_number,
436 								  scheduled_number );
437 
438      /* set the mother split if exists */
439     gsb_data_transaction_set_mother_transaction_number ( transaction_number,
440 							 transaction_mother );
441 
442     /* we show the new transaction in the tree view */
443     gsb_transactions_list_append_new_transaction (transaction_number, TRUE);
444 
445     return transaction_number;
446 }
447 
448 
449 /**
450  * used to catch a transaction from a scheduled transaction
451  * take the category, check if it's a transfer or a split and
452  * do the necessary (create contra-transaction)
453  * don't execute the children if it's a split, need to call
454  * gsb_scheduler_execute_children_of_scheduled_transaction later
455  *
456  *
457  * \param transaction_number
458  * \param scheduled_number
459  *
460  * \return TRUE if ok, FALSE else
461  * */
gsb_scheduler_get_category_for_transaction_from_transaction(gint transaction_number,gint scheduled_number)462 gboolean gsb_scheduler_get_category_for_transaction_from_transaction ( gint transaction_number,
463 								       gint scheduled_number )
464 {
465     /* if category is set, it's a normal category */
466 
467     if ( gsb_data_scheduled_get_category_number (scheduled_number))
468     {
469 	/* it's a normal category */
470 
471 	gsb_data_transaction_set_category_number ( transaction_number,
472 						   gsb_data_scheduled_get_category_number (scheduled_number));
473 	gsb_data_transaction_set_sub_category_number ( transaction_number,
474 						       gsb_data_scheduled_get_sub_category_number (scheduled_number));
475 	return TRUE;
476     }
477 
478     if ( gsb_data_scheduled_get_split_of_scheduled (scheduled_number))
479     {
480 	/* it's a split of transaction,
481 	 * we don't append the children here, we need to call later
482 	 * the function gsb_scheduler_execute_children_of_scheduled_transaction */
483 
484 	gsb_data_transaction_set_split_of_transaction ( transaction_number,
485 							    1 );
486     }
487     else
488     {
489 		gint contra_account_number;
490 
491 		/* it's not a split of transaction and not a normal category so it's a transfer
492 		 * except if the target account is -1 then it's a
493 		 * transaction with no category */
494 
495 		contra_account_number = gsb_data_scheduled_get_account_number_transfer (scheduled_number);
496 		if (contra_account_number == 0)
497 		{
498 			GrisbiWinRun *w_run;
499 
500 			w_run = grisbi_win_get_w_run ();
501 			if (w_run->account_number_is_0 == FALSE)
502 				return FALSE;
503 		}
504 
505 		if (contra_account_number != -1)
506 		{
507 			gint contra_transaction_number;
508 
509 			contra_transaction_number = gsb_form_transaction_validate_transfer ( transaction_number,
510 											 TRUE,
511 											 gsb_data_scheduled_get_account_number_transfer (scheduled_number));
512 			gsb_data_transaction_set_method_of_payment_number ( contra_transaction_number,
513 									gsb_data_scheduled_get_contra_method_of_payment_number (scheduled_number));
514 		}
515     }
516     return TRUE;
517 }
518 
519 
520 /**
521  * get the children of a split scheduled transaction,
522  * make the transactions from them and append them to the transactions list
523  *
524  *
525  * \param scheduled_number the number of the mother scheduled transaction (the split)
526  * \param transaction_number the number of the transaction created from that scheduled (so, the future mother of the children)
527  *
528  * \return FALSE
529  *
530  * */
gsb_scheduler_execute_children_of_scheduled_transaction(gint scheduled_number,gint transaction_number)531 gboolean gsb_scheduler_execute_children_of_scheduled_transaction ( gint scheduled_number,
532 								   gint transaction_number )
533 {
534     GSList *children_numbers_list;
535 
536 devel_debug (NULL);
537     children_numbers_list = gsb_data_scheduled_get_children ( scheduled_number, TRUE );
538 
539     while ( children_numbers_list )
540     {
541 	gint child_number;
542 
543 	child_number = GPOINTER_TO_INT ( children_numbers_list -> data );
544     /* pbiava the 03/16/2009 supprime le crash quand on execute la transaction
545      * a partir du planificateur risque d'effet de bord */
546     if ( child_number > 0 )
547 		gsb_scheduler_create_transaction_from_scheduled_transaction ( child_number,
548 								      transaction_number );
549 
550 	children_numbers_list = children_numbers_list -> next;
551     }
552     g_slist_free (children_numbers_list);
553     return FALSE;
554 }
555 
556 
557 
558 /**
559  * check the scheduled transactions if the are in time limit
560  * and record the automatic transactions
561  *
562  * \param
563  *
564  * \return
565  * */
gsb_scheduler_check_scheduled_transactions_time_limit(void)566 void gsb_scheduler_check_scheduled_transactions_time_limit ( void )
567 {
568     GDate *date;
569     GSList *tmp_list;
570     gboolean automatic_transactions_taken = FALSE;
571 	GrisbiAppConf *a_conf;
572 
573     devel_debug (NULL);
574 	a_conf = (GrisbiAppConf *) grisbi_app_get_a_conf ();
575 
576     /* the scheduled transactions to take will be check here,
577      * but the scheduled transactions taken will be add to the already appended ones */
578 
579     scheduled_transactions_to_take = NULL;
580 
581     /* get the date today + a_conf->nb_days_before_scheduled */
582 
583     /* the date untill we execute the scheduled transactions is :
584      * - either today + a_conf->nb_days_before_scheduled if warn n days before the scheduled
585      * - either the end of the month in a_conf->nb_days_before_scheduled days (so current month or next month)
586 	 *   or the fixed date
587      *   */
588     date = gdate_today ();
589     /* now date is in a_conf->nb_days_before_scheduled, if we want the transactions of the month,
590      * we change date to the end of its month */
591     if (a_conf->execute_scheduled_of_month)
592     {
593 		gint last_day;
594 
595 		if (a_conf->scheduler_set_fixed_day
596 			&&
597 			g_date_get_day (date) >= a_conf->scheduler_fixed_day )
598 
599 		{
600 			g_date_add_months (date, 1);
601 		}
602 
603 		last_day = g_date_get_days_in_month (g_date_get_month (date),
604 											 g_date_get_year (date));
605 		g_date_set_day (date, last_day);
606     }
607 	else
608 	{
609 		g_date_add_days ( date, a_conf->nb_days_before_scheduled );
610 	}
611 
612     /* check all the scheduled transactions,
613      * if automatic, it's taken
614      * if manual, appended into scheduled_transactions_to_take */
615     tmp_list = gsb_data_scheduled_get_scheduled_list ();
616 
617     while ( tmp_list )
618     {
619 		gint scheduled_number;
620 
621 		scheduled_number = gsb_data_scheduled_get_scheduled_number (tmp_list -> data);
622 
623 		/* we check that scheduled transaction only if it's not a child of a split */
624 		if ( !gsb_data_scheduled_get_mother_scheduled_number (scheduled_number)
625 			 &&
626 			 gsb_data_scheduled_get_date (scheduled_number)
627 			 &&
628 			 g_date_compare ( gsb_data_scheduled_get_date (scheduled_number),
629 					  date ) <= 0 )
630 		{
631 			if ( gsb_data_scheduled_get_automatic_scheduled (scheduled_number))
632 			{
633 				/* this is an automatic scheduled, we get it */
634 				gint transaction_number;
635 
636 				/* take automatically the scheduled transaction untill today */
637 				transaction_number = gsb_scheduler_create_transaction_from_scheduled_transaction (scheduled_number,
638 														  0 );
639 				if ( gsb_data_scheduled_get_split_of_scheduled (scheduled_number))
640 					gsb_scheduler_execute_children_of_scheduled_transaction ( scheduled_number,
641 												  transaction_number );
642 
643 				scheduled_transactions_taken = g_slist_append ( scheduled_transactions_taken,
644 										GINT_TO_POINTER (transaction_number));
645 				automatic_transactions_taken = TRUE;
646 
647 				/* set the scheduled transaction to the next date,
648 				 * if it's not finished, we check them again if it need to be
649 				 * executed more than one time (the easiest way is to check
650 				 * all again, i don't think it will have thousand of scheduled transactions,
651 				 * so no much waste of time...) */
652 
653 				/* On protège tmp_list si gsb_scheduler_increase_scheduled () return FALSE */
654 				tmp_list = tmp_list->next;
655 
656 				if (gsb_scheduler_increase_scheduled (scheduled_number))
657 				{
658 					scheduled_transactions_to_take = NULL;
659 					tmp_list = gsb_data_scheduled_get_scheduled_list ();
660 
661 				}
662 			}
663 			else
664 			{
665 				/* it's a manual scheduled transaction, we put it in the slist */
666 				scheduled_transactions_to_take = g_slist_append ( scheduled_transactions_to_take ,
667 										  GINT_TO_POINTER (scheduled_number));
668 				tmp_list = tmp_list -> next;
669 			}
670 		}
671 		else
672 			tmp_list = tmp_list -> next;
673     }
674 
675     if ( automatic_transactions_taken )
676     {
677         run.mise_a_jour_liste_echeances_auto_accueil = TRUE;
678         gsb_file_set_modified ( TRUE );
679     }
680 
681     if ( scheduled_transactions_to_take )
682 		run.mise_a_jour_liste_echeances_manuelles_accueil = TRUE;
683 
684     g_date_free ( date );
685 }
686 
687 
688 
689