示例#1
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;
}
示例#2
0
/**
 * set the end date of the archive
 * the value is dupplicate in memory
 *
 * \param archive_number the number of the archive
 * \param date the end date of the archive
 *
 * \return TRUE if ok or FALSE if problem
 * */
gboolean gsb_data_archive_set_end_date ( gint archive_number,
                        const GDate *date )
{
    struct_archive *archive;

    archive = gsb_data_archive_get_structure ( archive_number );

    if (!archive)
	return FALSE;

    /* we free the last date */
    if ( archive -> end_date )
	g_date_free (archive -> end_date);

    /* and copy the new one */
    archive -> end_date = gsb_date_copy (date);

    return TRUE;
}
/**
 * set the init_date of the reconcile
 * the value is dupplicate in memory (so parameter can be freed after)
 *
 * \param reconcile_number the number of the reconcile
 * \param date the init_date of the reconcile
 *
 * \return TRUE if ok or FALSE if problem
 * */
gboolean gsb_data_reconcile_set_init_date ( gint reconcile_number,
					    const GDate *date )
{
    struct_reconcile *reconcile;

    reconcile = gsb_data_reconcile_get_structure ( reconcile_number );

    if (!reconcile)
	return FALSE;

    /* we free the last date */
    if ( reconcile -> reconcile_init_date )
	g_date_free (reconcile -> reconcile_init_date);

    /* and copy the new one */
    reconcile -> reconcile_init_date = gsb_date_copy (date);

    return TRUE;
}
/**
 * set the final_date of the reconcile
 * the value is dupplicate in memory (so parameter can be freed after)
 *
 * \param reconcile_number the number of the reconcile
 * \param date the final_date of the reconcile
 *
 * \return TRUE if ok or FALSE if problem
 * */
gboolean gsb_data_reconcile_set_final_date ( gint reconcile_number,
                        const GDate *date )
{
    struct_reconcile *reconcile;

    reconcile = gsb_data_reconcile_get_structure ( reconcile_number );

    if (!reconcile)
	return FALSE;

    /* we free the last date */
    if ( reconcile -> reconcile_final_date )
        g_date_free (reconcile -> reconcile_final_date);

    /* and copy the new one */
    reconcile -> reconcile_final_date = gsb_date_copy (date);

    /* retrie la liste */
    reconcile_list = g_list_sort ( reconcile_list, (GCompareFunc) gsb_data_reconcile_cmp_int );

    return TRUE;
}
示例#5
0
/**
 * start the reconciliation, called by a click on the
 * reconcile button
 *
 * \param button the button we click to come here
 * \param null not used
 *
 * \return FALSE
 * */
gboolean gsb_reconcile_run_reconciliation ( GtkWidget *button,
                        gpointer null )
{
    GDate *date;
    gint account_number;
    gint reconcile_number;
    gchar *label;
    gchar *string;
    gchar* tmpstr;

    account_number = gsb_gui_navigation_get_current_account ();
    reconcile_number = gsb_data_reconcile_get_account_last_number (account_number);

    label = gsb_reconcile_build_label ( reconcile_number );
    gtk_entry_set_text ( GTK_ENTRY ( reconcile_number_entry ), label );
    g_free ( label );

    /* reset records in run structure if user has changed of account */
    if (run.reconcile_account_number != account_number)
    {
        g_free (run.reconcile_final_balance);
        if (run.reconcile_new_date)
            g_date_free (run.reconcile_new_date);
        run.reconcile_final_balance = NULL;
        run.reconcile_new_date = NULL;
        run.reconcile_account_number = -1;
    }

    /* set last input date/amount if available */
    if (run.reconcile_new_date)
    {
        date = run.reconcile_new_date;
    }
    else
    {
        /* increase the last date of 1 month */
        date = gsb_date_copy (gsb_data_reconcile_get_final_date (reconcile_number));
        if (date)
        {
            GDate *today;
            gchar *string ;

            string = gsb_format_gdate ( date );
            gtk_label_set_text ( GTK_LABEL ( reconcile_last_date_label ),
                    string);
            gtk_widget_set_sensitive ( GTK_WIDGET ( reconcile_last_date_label ),
                    FALSE );
            g_free (string);
            g_date_add_months ( date, 1 );

            /* if etat.reconcile_end_date or the new date is after today, set today */
            today = gdate_today();
            if ( etat.reconcile_end_date || g_date_compare ( date, today) > 0 )
            {
                g_date_free (date);
                date = gdate_today();
            }
            else
                g_date_free (today);

            /* it's not the first reconciliation, set the old balance and unsensitive the old balance entry */
            tmpstr = utils_real_get_string (gsb_data_reconcile_get_final_balance (reconcile_number));
            gtk_entry_set_text ( GTK_ENTRY ( reconcile_initial_balance_entry ), tmpstr);
            g_free ( tmpstr );
            gtk_widget_set_sensitive ( GTK_WIDGET ( reconcile_initial_balance_entry ),
                    FALSE );
        }
        else
        {
            gtk_label_set_text ( GTK_LABEL ( reconcile_last_date_label ), _("None") );

            date = gdate_today();

            /* it's the first reconciliation, set the initial balance and make sensitive the old balance to change
             * it if necessary */
            tmpstr = utils_real_get_string ( gsb_data_account_get_init_balance (account_number, -1));
            gtk_entry_set_text ( GTK_ENTRY ( reconcile_initial_balance_entry ), tmpstr);
            g_free ( tmpstr );
            gtk_widget_set_sensitive ( GTK_WIDGET ( reconcile_initial_balance_entry ), TRUE );
        }
    }

    string = gsb_format_gdate (date);
    gtk_entry_set_text ( GTK_ENTRY ( reconcile_new_date_entry ),
			 string );
    g_free (string);
    g_date_free (date);

    /* set last input amount if available and if the account is the good one */
    gtk_entry_set_text ( GTK_ENTRY ( reconcile_final_balance_entry ),
            (run.reconcile_final_balance) ? run.reconcile_final_balance : "");
    g_free(run.reconcile_final_balance);

    /* set the title */
    tmpstr = g_markup_printf_escaped ( _(" <b>%s reconciliation</b> "),
					     gsb_data_account_get_name (account_number));
    gtk_label_set_markup ( GTK_LABEL (gtk_frame_get_label_widget (GTK_FRAME (reconcile_panel))),
			   tmpstr );
    g_free ( tmpstr );

    /* we go to the reconciliation mode */
    run.equilibrage = 1;

    /* set all the balances for reconciliation */
    gsb_reconcile_update_amounts (NULL, NULL);

    /* set the transactions list to reconciliation mode */
    /* only change the current account */
    reconcile_save_account_display = etat.retient_affichage_par_compte;
    etat.retient_affichage_par_compte = 1;

    /* hide the marked R transactions */
    reconcile_save_show_marked = gsb_data_account_get_r (account_number);
    if (reconcile_save_show_marked)
    {
        gsb_data_account_set_r (account_number, FALSE );
        mise_a_jour_affichage_r (FALSE);
    }

    /* 1 line on the transaction list */
    reconcile_save_rows_number = gsb_data_account_get_nb_rows (account_number);
    if (reconcile_save_rows_number != 1)
        gsb_transactions_list_set_visible_rows_number ( 1 );

    /* sort by method of payment if in conf */
    if (gsb_data_account_get_reconcile_sort_type (account_number))
	gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON (reconcile_sort_list_button),
				       TRUE );

    gtk_widget_show_all ( reconcile_panel );

    transaction_list_show_toggle_mark (TRUE);

    /* unsensitive all that could change the account number */
    gsb_reconcile_sensitive (FALSE);

    gtk_widget_grab_focus ( GTK_WIDGET ( reconcile_number_entry ) );
    return FALSE;
}
示例#6
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;
}
示例#7
0
/**
 * find and return the next date after the given date for the given scheduled
 * transaction
 *
 * \param scheduled_number
 * \param date the current date, we want the next one after that one
 *
 * \return a newly allocated date, the next date or NULL if over the limit
 * */
GDate *gsb_scheduler_get_next_date ( gint scheduled_number,
				     const GDate *date )
{
    GDate *return_date;

    if ( !scheduled_number
	 ||
	 !gsb_data_scheduled_get_frequency (scheduled_number)
	 ||
	 !date
	 ||
	 !g_date_valid (date))
	return NULL;

    /* we don't change the initial date */
    return_date = gsb_date_copy (date);

    switch (gsb_data_scheduled_get_frequency (scheduled_number))
    {
	case SCHEDULER_PERIODICITY_ONCE_VIEW:
	    return NULL;
	    break;

	case SCHEDULER_PERIODICITY_WEEK_VIEW:
	    g_date_add_days ( return_date, 7 );
	    /* FIXME : there were a bug in gtk and we had to add 0 month to have the good date,
	     * it seems fixed but we should wait the stable debian is upgraded to
	     * remove that [26/10/2008] */
	    g_date_add_months ( return_date, 0 );
	    break;

	case SCHEDULER_PERIODICITY_MONTH_VIEW:
	    g_date_add_months ( return_date, 1 );
	    break;

	case SCHEDULER_PERIODICITY_TWO_MONTHS_VIEW:
	    g_date_add_months ( return_date, 2 );
	    break;

	case SCHEDULER_PERIODICITY_TRIMESTER_VIEW:
	    g_date_add_months ( return_date, 3 );
	    break;

	case SCHEDULER_PERIODICITY_YEAR_VIEW:
	    g_date_add_years ( return_date, 1 );
	    break;

	case SCHEDULER_PERIODICITY_CUSTOM_VIEW:
	    if ( gsb_data_scheduled_get_user_entry (scheduled_number) <= 0 )
	    {
		g_date_free (return_date);
		return NULL;
	    }

	    switch (gsb_data_scheduled_get_user_interval (scheduled_number))
	    {
		case PERIODICITY_DAYS:
		    g_date_add_days ( return_date, 
				      gsb_data_scheduled_get_user_entry (scheduled_number));
		    /* FIXME : there were a bug in gtk and we had to add 0 month to have the good date,
		     * it seems fixed but we should wait the stable debian is upgraded to
		     * remove that [26/10/2008] */
		    g_date_add_months ( return_date, 0 );
		    break;

		case PERIODICITY_WEEKS:
		    g_date_add_days ( return_date, 
				      gsb_data_scheduled_get_user_entry (scheduled_number) * 7 );
		    g_date_add_months ( return_date, 0 );
		    break;

		case PERIODICITY_MONTHS:
		    g_date_add_months ( return_date,
					gsb_data_scheduled_get_user_entry (scheduled_number));
		    break;

		case PERIODICITY_YEARS:
		    g_date_add_years ( return_date,
				       gsb_data_scheduled_get_user_entry (scheduled_number));
		    g_date_add_months ( return_date, 0 );
		    break;
	    }
	    break;
    }

    if ( gsb_data_scheduled_get_limit_date (scheduled_number)
	 &&
	 g_date_compare ( return_date,
			  gsb_data_scheduled_get_limit_date (scheduled_number)) > 0 )
    {
	g_date_free (return_date);
	return_date = NULL;
    }
    
    return ( return_date );
}