Exemplo n.º 1
0
gint gsb_data_mix_get_split_of_transaction ( gint transaction_number,
                        gboolean is_transaction )
{
    if ( is_transaction )
        return ( gsb_data_transaction_get_split_of_transaction ( transaction_number ) );
    else
        return ( gsb_data_scheduled_get_split_of_scheduled ( transaction_number ) );
}
Exemplo n.º 2
0
/**
 * set the next date in the scheduled transaction
 * if it's above the limit date, that transaction is deleted
 * if it's a split, the children are updated too
 * if the scheduled transaction is finished, it's removed from the list and from the scheduled transactions
 * 
 * \param scheduled_number the scheduled transaction we want to increase
 * 
 * \return FALSE if the scheduled transaction is finished, TRUE else
 * */
gboolean gsb_scheduler_increase_scheduled ( gint scheduled_number )
{
    GDate *new_date;

    g_return_val_if_fail ( g_date_valid (gsb_data_scheduled_get_date (scheduled_number)), TRUE );

    /* increase the date of the scheduled_transaction */
    new_date = gsb_scheduler_get_next_date ( scheduled_number,
					     gsb_data_scheduled_get_date (scheduled_number));

    /* we continue to work only if new_date is not null (null mean reach the end) */
    if (new_date)
    {
	/* set the new date */
	gsb_data_scheduled_set_date ( scheduled_number, new_date);

	if ( gsb_data_scheduled_get_split_of_scheduled ( scheduled_number ))
	{
	    GSList *children_numbers_list;

	    /* if there is some children, set the new date too */
	    children_numbers_list = gsb_data_scheduled_get_children ( scheduled_number, TRUE );

	    while ( children_numbers_list )
	    {
		gint child_number;

		child_number = GPOINTER_TO_INT ( children_numbers_list -> data );

		gsb_data_scheduled_set_date ( child_number,
					      new_date );

		children_numbers_list = children_numbers_list -> next;
	    }
	    g_slist_free (children_numbers_list);
	}
	g_date_free (new_date);
    }
    else
    {
	/* the scheduled transaction is over, we remove it */
	/* update the main page */
	gsb_main_page_update_finished_scheduled_transactions (scheduled_number);

	/* remove the scheduled transaction */
	/* !! important to remove first from the list... */
	gsb_scheduler_list_remove_transaction_from_list ( scheduled_number );
	gsb_data_scheduled_remove_scheduled (scheduled_number);
	return FALSE;
    }
    return TRUE;
}
Exemplo n.º 3
0
/**
 * used to catch a transaction from a scheduled transaction
 * take the category, check if it's a transfer or a split and
 * do the necessary (create contra-transaction)
 * don't execute the children if it's a split, need to call 
 * gsb_scheduler_execute_children_of_scheduled_transaction later
 * 
 *
 * \param transaction_number
 * \param scheduled_number
 *
 * \return TRUE if ok, FALSE else
 * */
gboolean gsb_scheduler_get_category_for_transaction_from_transaction ( gint transaction_number,
								       gint scheduled_number )
{
    /* if category is set, it's a normal category */

    if ( gsb_data_scheduled_get_category_number (scheduled_number))
    {
	/* it's a normal category */

	gsb_data_transaction_set_category_number ( transaction_number,
						   gsb_data_scheduled_get_category_number (scheduled_number));
	gsb_data_transaction_set_sub_category_number ( transaction_number,
						       gsb_data_scheduled_get_sub_category_number (scheduled_number));
	return TRUE;
    }

    if ( gsb_data_scheduled_get_split_of_scheduled (scheduled_number))
    {
	/* it's a split of transaction,
	 * we don't append the children here, we need to call later
	 * the function gsb_scheduler_execute_children_of_scheduled_transaction */

	gsb_data_transaction_set_split_of_transaction ( transaction_number,
							    1 );
    }
    else
    {
	/* it's not a split of transaction and not a normal category so it's a transfer
	 * except if the target account is -1 then it's a
	 * transaction with no category */

	if ( gsb_data_scheduled_get_account_number_transfer (scheduled_number) != -1 )
	{
	    gint contra_transaction_number;

	    contra_transaction_number = gsb_form_transaction_validate_transfer ( transaction_number,
										 TRUE,
										 gsb_data_scheduled_get_account_number_transfer (scheduled_number));
	    gsb_data_transaction_set_method_of_payment_number ( contra_transaction_number,
								gsb_data_scheduled_get_contra_method_of_payment_number (scheduled_number));
	}
    }
    return TRUE;
}
Exemplo n.º 4
0
/**
 * check the scheduled transactions if the are in time limit
 * and record the automatic transactions
 * 
 * \param
 * 
 * \return
 * */
void gsb_scheduler_check_scheduled_transactions_time_limit ( void )
{
    GDate *date;
    GSList *tmp_list;
    gboolean automatic_transactions_taken = FALSE;

    devel_debug (NULL);

    /* the scheduled transactions to take will be check here,
     * but the scheduled transactions taken will be add to the already appended ones */

    scheduled_transactions_to_take = NULL;

    /* get the date today + nb_days_before_scheduled */

    /* the date untill we execute the scheduled transactions is :
     * - either today + nb_days_before_scheduled if warn n days before the scheduled
     * - either the end of the month in nb_days_before_scheduled days (so current month or next month)
     *   */
    date = gdate_today ();
    g_date_add_days ( date,
		      nb_days_before_scheduled );
    /* now date is in nb_days_before_scheduled, if we want the transactions of the month,
     * we change date to the end of its month */
    if (execute_scheduled_of_month)
    {
	gint last_day;
	
	last_day = g_date_get_days_in_month ( g_date_get_month (date),
					      g_date_get_year (date));
	g_date_set_day (date, last_day);
    }

    /* check all the scheduled transactions,
     * if automatic, it's taken
     * if manual, appended into scheduled_transactions_to_take */
    tmp_list = gsb_data_scheduled_get_scheduled_list ();

    while ( tmp_list )
    {
	gint scheduled_number;

	scheduled_number = gsb_data_scheduled_get_scheduled_number (tmp_list -> data);

	/* we check that scheduled transaction only if it's not a child of a split */
	if ( !gsb_data_scheduled_get_mother_scheduled_number (scheduled_number)
	     &&
	     gsb_data_scheduled_get_date (scheduled_number)
	     &&
	     g_date_compare ( gsb_data_scheduled_get_date (scheduled_number),
			      date ) <= 0 )
	{
	    if ( gsb_data_scheduled_get_automatic_scheduled (scheduled_number))
	    {
		/* this is an automatic scheduled, we get it */
		gint transaction_number;

		/* take automatically the scheduled transaction untill today */
		transaction_number = gsb_scheduler_create_transaction_from_scheduled_transaction (scheduled_number,
												  0 );
		if ( gsb_data_scheduled_get_split_of_scheduled (scheduled_number))
		    gsb_scheduler_execute_children_of_scheduled_transaction ( scheduled_number,
									      transaction_number );

		scheduled_transactions_taken = g_slist_append ( scheduled_transactions_taken,
								GINT_TO_POINTER (transaction_number));
		automatic_transactions_taken = TRUE;

		/* set the scheduled transaction to the next date,
		 * if it's not finished, we check them again if it need to be
		 * executed more than one time (the easiest way is to check
		 * all again, i don't think it will have thousand of scheduled transactions, 
		 * so no much waste of time...) */
		if (gsb_scheduler_increase_scheduled (scheduled_number))
		{
		    scheduled_transactions_to_take = NULL;
		    tmp_list = gsb_data_scheduled_get_scheduled_list ();
		}
		else
		    /* the scheduled is finish, so we needn't to check it again ... */
		    tmp_list = tmp_list -> next;
	    }
	    else
	    {
		/* it's a manual scheduled transaction, we put it in the slist */
		scheduled_transactions_to_take = g_slist_append ( scheduled_transactions_to_take ,
								  GINT_TO_POINTER (scheduled_number));
		tmp_list = tmp_list -> next;
	    }
	}
	else
	    tmp_list = tmp_list -> next;
    }

    if ( automatic_transactions_taken )
    {
	mise_a_jour_liste_echeances_auto_accueil = 1;
        gsb_file_set_modified ( TRUE );
    }

    if ( scheduled_transactions_to_take )
	mise_a_jour_liste_echeances_manuelles_accueil = 1;

    g_date_free ( date );
}