/** * remove a reconcile * all the transactions marked by that reconcile will be marked P * and lose the link to that reconcile * * \param reconcile_number the reconcile we want to remove * * \return TRUE ok * */ gboolean gsb_data_reconcile_remove ( gint reconcile_number ) { struct_reconcile *reconcile; GSList *list_tmp; reconcile = gsb_data_reconcile_get_structure ( reconcile_number ); if (!reconcile) return FALSE; reconcile_list = g_list_remove ( reconcile_list, reconcile ); _gsb_data_reconcile_free ( reconcile ); /* remove that reconcile of the transactions */ list_tmp = gsb_data_transaction_get_complete_transactions_list (); while (list_tmp) { gint transaction_number = gsb_data_transaction_get_transaction_number (list_tmp -> data); if ( gsb_data_transaction_get_reconcile_number (transaction_number) == reconcile_number ) { gsb_data_transaction_set_reconcile_number ( transaction_number, 0 ); gsb_data_transaction_set_marked_transaction ( transaction_number, OPERATION_POINTEE ); } list_tmp = list_tmp -> next; } return TRUE; }
/** * callback called by the button to launch the automatic association * between transactions and reconcile * * \param button * \param assistant * * \return FALSE * */ static gboolean gsb_assistant_reconcile_config_lauch_auto_asso ( GtkWidget *button, GtkWidget *assistant ) { GSList *tmp_list; /* we will use the list already created */ tmp_list = list_association; while (tmp_list) { struct association_transaction_reconcile *association; association = tmp_list -> data; gsb_data_transaction_set_reconcile_number ( association -> transaction_number, association -> reconcile_number ); tmp_list = tmp_list -> next; } transactions_to_link = transactions_to_link - g_slist_length (list_association); g_slist_free (list_association); list_association = NULL; /* now there is 2 way : * either transactions_to_link is 0, we go directly to the succes page * either it's not null, and the user should create more reconciliations */ if (transactions_to_link) { gchar *string; /* update the labels */ string = g_strdup_printf (_("Still %d transactions to link with a reconciliation."), transactions_to_link); gtk_label_set_text ( GTK_LABEL (label_transactions_to_link_2), string); g_free (string); gtk_misc_set_alignment ( GTK_MISC (label_transactions_to_link_2), 0, 0.5 ); gtk_label_set_text ( GTK_LABEL (label_possible_association), _("There is no transaction that Grisbi can link.\n" "Check if you created all the necesssary reconciliations.")); gtk_widget_set_sensitive ( button_run_association, FALSE ); } else { /* go to the success page */ gsb_assistant_set_next ( assistant, RECONCILE_ASSISTANT_AUTOMATICALLY_ASSOCIATE, RECONCILE_ASSISTANT_SUCCESS ); gsb_assistant_next_page (assistant); } return FALSE; }
/** * finish the reconciliation, * called by a click on the finish button * * \param button * \param null * * \return FALSE */ gboolean gsb_reconcile_finish_reconciliation ( GtkWidget *button, gpointer null ) { GSList *list_tmp_transactions; GDate *date; gint account_number; gint reconcile_number; gsb_real real; gchar* tmpstr; account_number = gsb_gui_navigation_get_current_account (); if ( gsb_real_sub ( gsb_real_add ( utils_real_get_from_string (gtk_entry_get_text ( GTK_ENTRY ( reconcile_initial_balance_entry ))), gsb_data_account_calculate_waiting_marked_balance (account_number)), utils_real_get_from_string (gtk_entry_get_text ( GTK_ENTRY ( reconcile_final_balance_entry )))).mantissa != 0 ) { dialogue_warning_hint ( _("There is a variance in balances, check that both final balance and initial balance minus marked transactions are equal."), _("Reconciliation can't be completed.") ); return FALSE; } /* get and check the reconcile name */ reconcile_number = gsb_data_reconcile_get_number_by_name (gtk_entry_get_text ( GTK_ENTRY ( reconcile_number_entry ))); if (reconcile_number) { dialogue_warning_hint ( _("There is already a reconcile with that name, you must use another name or let it free.\nIf the reconcile name is ending by a number,\nit will be automatically incremented."), _("Reconciliation can't be completed.") ); return FALSE; } /* get and save the date */ date = gsb_calendar_entry_get_date (reconcile_new_date_entry); if (!date) { gchar* tmpstr = g_strdup_printf ( _("Invalid date: '%s'"), gtk_entry_get_text ( GTK_ENTRY ( reconcile_new_date_entry ))); dialogue_warning_hint ( tmpstr, _("Reconciliation can't be completed.") ); g_free ( tmpstr ); return FALSE; } if (!strlen (gtk_entry_get_text ( GTK_ENTRY ( reconcile_number_entry )))) { dialogue_warning_hint ( _("You need to set a name to the reconciliation ; at least, set a number,\nit will be automatically incremented later"), _("Reconciliation can't be completed.") ); return FALSE; } /* restore the good sort of the list */ if (transaction_list_sort_get_reconcile_sort ()) { gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON (reconcile_sort_list_button), FALSE ); gsb_reconcile_list_button_clicked (reconcile_sort_list_button, NULL); } tmpstr = g_strdup_printf ( _("Last statement: %s"), gsb_format_gdate (date)); gtk_label_set_text ( GTK_LABEL ( label_last_statement ), tmpstr); g_free ( tmpstr ); /* create the new reconcile structure */ reconcile_number = gsb_data_reconcile_new (gtk_entry_get_text (GTK_ENTRY (reconcile_number_entry))); gsb_data_reconcile_set_account ( reconcile_number, account_number ); /* set the variables of the reconcile */ gsb_data_reconcile_set_final_date ( reconcile_number, date ); g_date_free (date); date = gsb_parse_date_string (gtk_label_get_text (GTK_LABEL (reconcile_last_date_label))); gsb_data_reconcile_set_init_date ( reconcile_number, date ); g_free (date); real = utils_real_get_from_string ( gtk_entry_get_text ( GTK_ENTRY ( reconcile_initial_balance_entry ) ) ); gsb_data_reconcile_set_init_balance ( reconcile_number, real ); real = utils_real_get_from_string ( gtk_entry_get_text ( GTK_ENTRY ( reconcile_final_balance_entry ) ) ); gsb_data_reconcile_set_final_balance ( reconcile_number, real ); /* modify the reconciled transactions */ list_tmp_transactions = gsb_data_transaction_get_transactions_list (); while ( list_tmp_transactions ) { gint transaction_number_tmp; transaction_number_tmp = gsb_data_transaction_get_transaction_number ( list_tmp_transactions -> data); if ( gsb_data_transaction_get_account_number (transaction_number_tmp) == account_number && ( gsb_data_transaction_get_marked_transaction (transaction_number_tmp) == OPERATION_POINTEE || gsb_data_transaction_get_marked_transaction (transaction_number_tmp) == OPERATION_TELERAPPROCHEE )) { gsb_data_transaction_set_marked_transaction ( transaction_number_tmp, OPERATION_RAPPROCHEE ); gsb_data_transaction_set_reconcile_number ( transaction_number_tmp, reconcile_number ); } list_tmp_transactions = list_tmp_transactions -> next; } /* update the P and T to R in the list */ transaction_list_update_element (ELEMENT_MARK); run.mise_a_jour_liste_comptes_accueil = TRUE; /* go back to the normal transactions list */ gsb_reconcile_cancel (NULL, NULL); /* reset records in run: to do after gsb_reconcile_cancel */ 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; gsb_file_set_modified ( TRUE ); if ( reconcile_save_last_scheduled_convert ) { gsb_gui_navigation_set_selection ( GSB_SCHEDULER_PAGE, 0, NULL ); gsb_scheduler_list_select ( reconcile_save_last_scheduled_convert ); gsb_scheduler_list_edit_transaction ( reconcile_save_last_scheduled_convert ); reconcile_save_last_scheduled_convert = 0; } return FALSE; }
/** * callback called by the button to launch the automatic association * between transactions and reconcile * * \param button * \param assistant * * \return FALSE * */ static gboolean gsb_assistant_reconcile_config_lauch_manu_asso ( GtkWidget *button, GtkWidget *assistant ) { GList *tmp_list; GtkTreeIter iter; GtkTreeModel *model; GtkTreeSelection *selection; GList *path_list; gint account_number = -1; GtkWidget *dialog; GtkWidget *label; GtkWidget *scrolled_window; GtkWidget *dialog_tree_view; GtkListStore *dialog_store; gint return_value; gint i; enum dialog_column { DIALOG_NAME = 0, DIALOG_INIT_DATE, DIALOG_FINAL_DATE, DIALOG_RECONCILE_NUMBER, DIALOG_NB_COL }; gint selected_reconcile_number; gint transaction_number; /* get the selection */ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview_transactions_to_link)); /* get the selected transactions */ path_list = gtk_tree_selection_get_selected_rows ( GTK_TREE_SELECTION (selection), &model ); if (!path_list) return FALSE; /* ok, we have a selection, before continuing, * we check that all the transactions are on the same account */ tmp_list = path_list; while (tmp_list) { GtkTreePath *path; path = tmp_list -> data; if (gtk_tree_model_get_iter ( GTK_TREE_MODEL (model), &iter, path )) { gtk_tree_model_get ( GTK_TREE_MODEL (model), &iter, TRANSACTION_NUMBER, &transaction_number, -1 ); if (account_number == -1) account_number = gsb_data_transaction_get_account_number (transaction_number); else { if (gsb_data_transaction_get_account_number (transaction_number) != account_number) { dialogue_error (_("All the selected transactions have to belong to the same account !")); /* erase the path_list */ g_list_foreach (path_list, (GFunc) gtk_tree_path_free, NULL); g_list_free (path_list); return FALSE; } } } tmp_list = tmp_list -> next; } if (account_number == -1) { /* erase the path_list */ g_list_foreach (path_list, (GFunc) gtk_tree_path_free, NULL); g_list_free (path_list); return FALSE; } /* ok, all the transactions belong to the same account, we can * show a dialog to select the reconcile */ dialog = gtk_dialog_new_with_buttons ( _("Selection of a reconciliation"), GTK_WINDOW ( assistant ), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, "gtk-cancel", GTK_RESPONSE_CANCEL, "gtk-ok", GTK_RESPONSE_OK, NULL ); gtk_window_set_default_size ( GTK_WINDOW ( dialog ), 770, 412 ); gtk_window_set_position ( GTK_WINDOW ( dialog ), GTK_WIN_POS_CENTER_ON_PARENT ); gtk_window_set_resizable ( GTK_WINDOW ( dialog ), TRUE ); gtk_container_set_border_width ( GTK_CONTAINER ( dialog ), 12 ); label = gtk_label_new ( _("Select the reconciliation to associate to the selected transactions: ") ); gtk_misc_set_alignment ( GTK_MISC ( label ), 0.0, 0.0 ); gtk_box_pack_start ( GTK_BOX ( dialog_get_content_area ( dialog ) ), label, FALSE, FALSE, 10 ); /* make the list */ scrolled_window = gtk_scrolled_window_new (FALSE, FALSE); gtk_scrolled_window_set_policy ( GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC ); gtk_box_pack_start ( GTK_BOX ( dialog_get_content_area ( dialog ) ), scrolled_window, TRUE, TRUE, 0 ); dialog_store = gtk_list_store_new ( DIALOG_NB_COL, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT ); dialog_tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (dialog_store)); g_object_unref (G_OBJECT(dialog_store)); gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (dialog_tree_view), TRUE); gtk_container_add ( GTK_CONTAINER (scrolled_window), dialog_tree_view ); /* set the columns */ for (i=DIALOG_NAME ; i<DIALOG_RECONCILE_NUMBER ; i++) { GtkTreeViewColumn *column; GtkCellRenderer *cell; gchar *titles[] = { _("Reconciliation reference"), _("Initial date"), _("Final date") }; gfloat alignment[] = { COLUMN_LEFT, COLUMN_CENTER, COLUMN_CENTER }; cell = gtk_cell_renderer_text_new (); g_object_set ( G_OBJECT (cell), "xalign", alignment[i], NULL ); column = gtk_tree_view_column_new (); gtk_tree_view_column_set_sizing ( column, GTK_TREE_VIEW_COLUMN_AUTOSIZE ); gtk_tree_view_column_set_alignment ( column, alignment[i] ); gtk_tree_view_column_pack_start ( column, cell, TRUE ); gtk_tree_view_column_set_title ( column, titles[i] ); gtk_tree_view_column_set_attributes (column, cell, "text", i, NULL); gtk_tree_view_column_set_expand ( column, TRUE ); gtk_tree_view_column_set_resizable ( column, TRUE ); gtk_tree_view_append_column ( GTK_TREE_VIEW(dialog_tree_view), column); } /* fill the tree view */ tmp_list = gsb_data_reconcile_get_reconcile_list (); while (tmp_list) { gint reconcile_number; reconcile_number = gsb_data_reconcile_get_no_reconcile (tmp_list -> data); if (gsb_data_reconcile_get_account (reconcile_number) == account_number) { gchar *init_date_str; gchar *final_date_str; init_date_str = gsb_format_gdate (gsb_data_reconcile_get_init_date (reconcile_number)); final_date_str = gsb_format_gdate (gsb_data_reconcile_get_final_date (reconcile_number)); gtk_list_store_append ( GTK_LIST_STORE (dialog_store), &iter ); gtk_list_store_set ( GTK_LIST_STORE (dialog_store), &iter, DIALOG_NAME, gsb_data_reconcile_get_name (reconcile_number), DIALOG_INIT_DATE, init_date_str, DIALOG_FINAL_DATE, final_date_str, DIALOG_RECONCILE_NUMBER, reconcile_number, -1 ); g_free (init_date_str); g_free (final_date_str); } tmp_list = tmp_list -> next; } gtk_widget_show_all (dialog); /* launch the dialog */ return_value = gtk_dialog_run (GTK_DIALOG (dialog)); if (return_value != GTK_RESPONSE_OK) { gtk_widget_destroy (dialog); return FALSE; } /* we get the selected reconcile */ if (!gtk_tree_selection_get_selected ( gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog_tree_view)), NULL, &iter )) { dialogue_warning (_("No selection found, the transactions are not modified.")); gtk_widget_destroy (dialog); return FALSE; } gtk_tree_model_get ( GTK_TREE_MODEL (dialog_store), &iter, DIALOG_RECONCILE_NUMBER, &selected_reconcile_number, -1 ); /* ok we have the reconcile number, we can destroy the dialog */ gtk_widget_destroy (dialog); /* and now, fill the selected transactions with that reconcile number */ tmp_list = g_list_last (path_list); while (tmp_list) { GtkTreePath *path; path = tmp_list -> data; if (gtk_tree_model_get_iter ( GTK_TREE_MODEL (model), &iter, path )) { gtk_tree_model_get ( GTK_TREE_MODEL (model), &iter, TRANSACTION_NUMBER, &transaction_number, -1 ); gtk_list_store_remove ( GTK_LIST_STORE (model), &iter ); gsb_data_transaction_set_reconcile_number ( transaction_number, selected_reconcile_number ); transactions_to_link--; } tmp_list = tmp_list -> prev; } /* erase the path_list */ g_list_foreach (path_list, (GFunc) gtk_tree_path_free, NULL); g_list_free (path_list); /* now there is 2 way : * either transactions_to_link is 0, we go directly to the succes page * either it's not null, and the user should create more reconciles */ if (transactions_to_link) { gchar *string; /* update the labels */ string = g_strdup_printf (_("Still %d transactions to link with a reconciliation."), transactions_to_link); gtk_label_set_text ( GTK_LABEL (label_transactions_to_link_1), string); gtk_label_set_text ( GTK_LABEL (label_transactions_to_link_3), string); g_free (string); gtk_widget_grab_focus (treeview_transactions_to_link); } else { /* go to the success page */ gsb_assistant_set_next ( assistant, RECONCILE_ASSISTANT_MANUALLY_ASSOCIATE, RECONCILE_ASSISTANT_SUCCESS ); gsb_assistant_next_page (assistant); } return FALSE; }