Esempio n. 1
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;
}
Esempio n. 2
0
const GDate *gsb_data_mix_get_date ( gint transaction_number,
                        gboolean is_transaction )
{
    if ( is_transaction )
        return ( gsb_data_transaction_get_date ( transaction_number ) );
    else
        return ( gsb_data_scheduled_get_date ( transaction_number ) );
}
Esempio n. 3
0
/**
 * update the calendar of the scheduled transactions
 *
 * \param
 *
 * \return FALSE
 * */
gboolean gsb_calendar_update ( void )
{
    time_t temps;
    GSList *tmp_list;
    gint calendar_month;
	gint calendar_year;

    gtk_calendar_clear_marks ( GTK_CALENDAR ( scheduled_calendar ));

    /* select the current day */
    time ( &temps );

    if ( ( localtime ( &temps ) -> tm_mon == GTK_CALENDAR ( scheduled_calendar ) -> month )
	 &&
	 ( ( localtime ( &temps ) -> tm_year + 1900 ) == GTK_CALENDAR ( scheduled_calendar ) -> year ) )
	gtk_calendar_select_day ( GTK_CALENDAR ( scheduled_calendar ),
				  localtime ( &temps ) -> tm_mday );
    else
	gtk_calendar_select_day ( GTK_CALENDAR ( scheduled_calendar ),
				  FALSE );

    calendar_month = GTK_CALENDAR ( scheduled_calendar ) -> month + 1;
	calendar_year = GTK_CALENDAR ( scheduled_calendar ) -> year + 25;

    /* check the scheduled transactions and bold them in the calendar */
    tmp_list = gsb_data_scheduled_get_scheduled_list ();

    while ( tmp_list )
    {
	GDate *tmp_date;
	gint scheduled_number;

	scheduled_number = gsb_data_scheduled_get_scheduled_number (tmp_list -> data);

	tmp_date = gsb_date_copy (gsb_data_scheduled_get_date (scheduled_number));

	while (tmp_date && g_date_get_month (tmp_date) == calendar_month && g_date_get_year (tmp_date) < calendar_year)
	{
	    GDate *new_date;

	    gtk_calendar_mark_day ( GTK_CALENDAR ( scheduled_calendar ),
				    g_date_get_day (tmp_date));
	    new_date = gsb_scheduler_get_next_date (scheduled_number, tmp_date);
	    g_free (tmp_date);
	    tmp_date = new_date;
	}
	tmp_list = tmp_list -> next;
    }
    return FALSE;
}
Esempio 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 );
}
Esempio n. 5
0
/**
 * create a new transaction and fill it directly from a scheduled transaction
 * (don't pass throw the form)
 * if it's a child of split, append it automatickly to the mother
 * 
 * \param scheduled_number the transaction we use to fill the new transaction
 * \param transaction_mother the number of the mother if it's a split child, 0 else
 *
 * \return the number of the new transaction
 * */
gint gsb_scheduler_create_transaction_from_scheduled_transaction ( gint scheduled_number,
								   gint transaction_mother )
{
    gint transaction_number, payment_number;
    gint account_number;

    account_number = gsb_data_scheduled_get_account_number (scheduled_number);

    transaction_number = gsb_data_transaction_new_transaction (account_number);

    /* begin to fill the new transaction */
    gsb_data_transaction_set_date ( transaction_number,
				    gsb_date_copy (gsb_data_scheduled_get_date (scheduled_number)));
    gsb_data_transaction_set_party_number ( transaction_number,
					    gsb_data_scheduled_get_party_number (scheduled_number));
    gsb_data_transaction_set_amount ( transaction_number,
				      gsb_data_scheduled_get_amount (scheduled_number));
    gsb_data_transaction_set_currency_number ( transaction_number,
					       gsb_data_scheduled_get_currency_number (scheduled_number));
    gsb_data_transaction_set_account_number ( transaction_number,
					      account_number );

    /* ask for change if necessary, only for normal transaction ; a child must have the same currency number
     * than the mother */
    if (!transaction_mother)
	gsb_currency_check_for_change ( transaction_number );

    gsb_data_transaction_set_method_of_payment_number ( transaction_number,
							gsb_data_scheduled_get_method_of_payment_number (scheduled_number));
    gsb_data_transaction_set_notes ( transaction_number,
				     gsb_data_scheduled_get_notes (scheduled_number));

    payment_number = gsb_data_scheduled_get_method_of_payment_number (scheduled_number);
    if ( payment_number )
    {
	if (gsb_data_payment_get_show_entry (payment_number))
	{
	    if (gsb_data_payment_get_automatic_numbering (payment_number))
	    {
		gchar* tmpstr;

		tmpstr = gsb_data_payment_incremente_last_number ( payment_number, 1 );
		gsb_data_transaction_set_method_of_payment_content ( transaction_number,
								     tmpstr);
		gsb_data_payment_set_last_number ( payment_number, tmpstr );
        g_free ( tmpstr );
	    }
	    else
		gsb_data_transaction_set_method_of_payment_content ( transaction_number,
								     gsb_data_scheduled_get_method_of_payment_content (
                                     scheduled_number ) );
	}
    }
    else
    {
	gsb_data_transaction_set_method_of_payment_content ( transaction_number,
							     gsb_data_scheduled_get_method_of_payment_content (
                                 scheduled_number ) );
    }
    gsb_data_transaction_set_automatic_transaction ( transaction_number,
						     gsb_data_scheduled_get_automatic_scheduled (scheduled_number));
    gsb_data_transaction_set_budgetary_number ( transaction_number,
						gsb_data_scheduled_get_budgetary_number (scheduled_number));
    gsb_data_transaction_set_sub_budgetary_number ( transaction_number,
						    gsb_data_scheduled_get_sub_budgetary_number (scheduled_number));

    /* if the financial year is automatic, we set it here */

    if ( gsb_data_scheduled_get_financial_year_number (scheduled_number) == -2 )
	gsb_data_transaction_set_financial_year_number ( transaction_number,
							 gsb_data_fyear_get_from_date ( gsb_data_transaction_get_date (transaction_number)));
    else
	gsb_data_transaction_set_financial_year_number ( transaction_number,
							 gsb_data_scheduled_get_financial_year_number (scheduled_number));

    /* get the category */

    gsb_scheduler_get_category_for_transaction_from_transaction ( transaction_number,
								  scheduled_number );

     /* set the mother split if exists */
    gsb_data_transaction_set_mother_transaction_number ( transaction_number,
							 transaction_mother );

    /* we show the new transaction in the tree view */
    gsb_transactions_list_append_new_transaction (transaction_number, TRUE);

    return transaction_number;
}