/** * Update the clickable list of closed accounts and target * accounts to move a transaction, in menu. * * \param * \return FALSE * */ gboolean gsb_menu_update_accounts_in_menus ( void ) { GSList *list_tmp; GtkActionGroup * action_group; if ( move_to_account_merge_id != -1 ) gtk_ui_manager_remove_ui ( ui_manager, move_to_account_merge_id ); move_to_account_merge_id = gtk_ui_manager_new_merge_id ( ui_manager ); action_group = gtk_action_group_new ( "Group3" ); /* create the closed accounts and accounts in the menu to move a transaction */ list_tmp = gsb_data_account_get_list_accounts (); while ( list_tmp ) { gint i; i = gsb_data_account_get_no_account ( list_tmp -> data ); if ( !gsb_data_account_get_closed_account ( i ) ) { gchar *tmp_name; gchar *account_name; GtkAction *action; tmp_name = g_strdup_printf ( "MoveToAccount%d", i ); account_name = gsb_data_account_get_name ( i ); if ( !account_name ) account_name = _("Unnamed account"); action = gtk_action_new ( tmp_name, account_name, "", "" ); if ( gsb_gui_navigation_get_current_account () == i ) gtk_action_set_sensitive ( action, FALSE ); gtk_action_group_add_action ( action_group, action ); g_signal_connect ( action, "activate", G_CALLBACK ( move_selected_operation_to_account_nb ), GINT_TO_POINTER ( i ) ); gtk_ui_manager_add_ui ( ui_manager, move_to_account_merge_id, "/menubar/EditMenu/MoveToAnotherAccount/", tmp_name, tmp_name, GTK_UI_MANAGER_MENUITEM, FALSE ); g_free ( tmp_name ); } list_tmp = list_tmp -> next; } gtk_ui_manager_insert_action_group ( ui_manager, action_group, 2 ); gtk_ui_manager_ensure_update ( ui_manager ); return FALSE; }
/** * create a combobox containing the list of the accounts * * \param func Function to call when a line is selected (type : gboolean func ( GtkWidget *button, gpointer data ) * \param data data to send to the function * \param include_closed If set to TRUE, include the closed accounts * * \return a new GtkCombobox containing the list of the accounts */ GtkWidget *gsb_account_create_combo_list ( GCallback func, gpointer data, gboolean include_closed ) { GSList *list_tmp; GtkListStore *store; GtkCellRenderer *renderer; GtkWidget *combobox; combobox = gtk_combo_box_new (); store = gtk_list_store_new ( 2, G_TYPE_STRING, G_TYPE_INT ); list_tmp = gsb_data_account_get_list_accounts (); while ( list_tmp ) { gint account_number; GtkTreeIter iter; account_number = gsb_data_account_get_no_account ( list_tmp -> data ); if ( account_number >= 0 && ( !gsb_data_account_get_closed_account (account_number) || include_closed ) ) { gtk_list_store_append ( GTK_LIST_STORE (store), &iter ); gtk_list_store_set ( store, &iter, 0, gsb_data_account_get_name (account_number), 1, account_number, -1 ); } list_tmp = list_tmp -> next; } gtk_combo_box_set_model ( GTK_COMBO_BOX (combobox), GTK_TREE_MODEL (store)); /* by default, this is blank, so set the first */ gtk_combo_box_set_active ( GTK_COMBO_BOX (combobox), 0 ); if ( func ) g_signal_connect ( G_OBJECT (combobox), "changed", G_CALLBACK(func), data ); renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, TRUE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer, "text", 0, NULL); return combobox; }
/** * function called when the user come to the manually association page * update the list of transactions to associate and fill the labels * * \param assistant * \param new_page * * \return FALSE * */ gboolean gsb_assistant_reconcile_config_update_manu_asso ( GtkWidget *assistant, gint new_page ) { gchar *string; GSList *tmp_list; gint transaction_number; GtkListStore *store; /* update the string containing the number of transactions to link */ 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_3), string); g_free (string); gtk_misc_set_alignment ( GTK_MISC (label_transactions_to_link_3), 0, 0.5 ); /* fill the list with the transactions to link */ store = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (treeview_transactions_to_link))); gtk_list_store_clear (GTK_LIST_STORE (store)); tmp_list = gsb_data_transaction_get_transactions_list (); while (tmp_list) { transaction_number = gsb_data_transaction_get_transaction_number (tmp_list -> data); if ( gsb_data_transaction_get_marked_transaction (transaction_number) == OPERATION_RAPPROCHEE && !gsb_data_transaction_get_reconcile_number (transaction_number)) { gchar *amount_str; gchar *date_str; GtkTreeIter iter; date_str = gsb_format_gdate (gsb_data_transaction_get_date (transaction_number)); amount_str = utils_real_get_string (gsb_data_transaction_get_amount (transaction_number)); gtk_list_store_append ( GTK_LIST_STORE (store), &iter ); gtk_list_store_set ( GTK_LIST_STORE (store), &iter, TRANSACTION_DATE, date_str, TRANSACTION_PAYEE, gsb_data_payee_get_name (gsb_data_transaction_get_party_number (transaction_number), TRUE), TRANSACTION_AMOUNT, amount_str, TRANSACTION_ACCOUNT, gsb_data_account_get_name (gsb_data_transaction_get_account_number (transaction_number)), TRANSACTION_NUMBER, transaction_number, -1 ); g_free (amount_str); g_free (date_str); } tmp_list = tmp_list -> next; } return FALSE; }
/** * Create a menu with the list of accounts. This list is * clickable and activates func if specified. * used for now to add a submenu item in a main menu * * \param func Function to call when a line is selected * \param activate_currrent If set to TRUE, does not mark as * unsensitive current account * \param include_closed If set to TRUE, include the closed accounts * * \return A newly created menu */ GtkWidget *gsb_account_create_menu_list ( GCallback func, gboolean activate_currrent, gboolean include_closed ) { GtkWidget *menu; GtkWidget *item; GSList *list_tmp; menu = gtk_menu_new (); list_tmp = gsb_data_account_get_list_accounts (); while ( list_tmp ) { gint i; i = gsb_data_account_get_no_account ( list_tmp -> data ); if ( i >= 0 && ( !gsb_data_account_get_closed_account (i) || include_closed ) ) { item = gtk_menu_item_new_with_label ( gsb_data_account_get_name (i)); g_object_set_data ( G_OBJECT ( item ), "account_number", GINT_TO_POINTER (i)); if ( func ) g_signal_connect ( G_OBJECT ( item ), "activate", G_CALLBACK(func), NULL ); gtk_menu_shell_append ( GTK_MENU_SHELL ( menu ), item ); if ( !activate_currrent && gsb_gui_navigation_get_current_account () == i) { gtk_widget_set_sensitive ( item, FALSE ); } gtk_widget_show ( item ); } list_tmp = list_tmp -> next; } return ( menu ); }
/** * update the list of accounts in a combo_box filled * by gsb_account_create_combo_list * * \param combo_box * \param include_closed * * \return FALSE * */ gboolean gsb_account_update_combo_list ( GtkWidget *combo_box, gboolean include_closed ) { GSList *list_tmp; GtkListStore *store; if (!combo_box) return FALSE; store = GTK_LIST_STORE (gtk_combo_box_get_model ( GTK_COMBO_BOX (combo_box))); gtk_list_store_clear (store); list_tmp = gsb_data_account_get_list_accounts (); while ( list_tmp ) { gint account_number; GtkTreeIter iter; account_number = gsb_data_account_get_no_account ( list_tmp -> data ); if ( account_number >= 0 && ( !gsb_data_account_get_closed_account (account_number) || include_closed ) ) { gtk_list_store_append ( GTK_LIST_STORE (store), &iter ); gtk_list_store_set ( store, &iter, 0, gsb_data_account_get_name (account_number), 1, account_number, -1 ); } list_tmp = list_tmp -> next; } return FALSE; }
/** * 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; }
/** * Build the new label for the reconciliation, given the old one. * The expected format is NAME+NUMBER, so this function returns * a newly allocated string whose format is NAME+(NUMBER+1). It * preserves leading '0' for the NUMBER string. * * If this is the first label building (first reconciliation for * this account), then the function returns a standard string * of the account name (lower case) + '-1'. * * \param reconcile_number * * \return the new string label */ gchar *gsb_reconcile_build_label ( int reconcile_number ) { gchar *tmp; gchar *old_label; gchar *new_label; gchar format[6] = "%s%0d"; int __reconcile_number; int __size; int __expand; /* old_label = NAME + NUMBER */ old_label = g_strdup ( gsb_data_reconcile_get_name ( reconcile_number ) ); /* return account NAME + '1' */ if ( !old_label ) { tmp = gsb_data_account_get_name ( gsb_gui_navigation_get_current_account () ); new_label = g_strconcat ( tmp, "-1", NULL ); tmp = new_label; while ( *tmp != '\0' ) { if ( *tmp == ' ' ) *tmp = '-'; else *tmp = tolower ( *tmp ); tmp ++; } return new_label; } /* we try to find some digits at the end of the name, * if found, get the biggest number until we find a non digit character */ __expand = 1; tmp = old_label + ( strlen ( old_label ) - 1 ) * sizeof ( gchar ); while ( isdigit ( *tmp ) && tmp >= old_label ) { if ( *tmp != '9' ) __expand = 0; tmp--; } tmp ++; /* step forward to the first digit */ __reconcile_number = utils_str_atoi ( tmp ) + 1; /* if stage 99 -> 100 for example, * then we have to allocate one more byte */ __size = strlen ( tmp ) + __expand; /* format string for the output (according NUMBER string length) */ format[3] = 48 + __size; /* close the NAME string */ *tmp = 0; /* NAME + NUMBER + '\0' */ __size += strlen ( old_label ) * sizeof ( gchar ) + 1; new_label = g_malloc0 ( __size * sizeof ( gchar ) ); sprintf ( new_label, format, old_label, __reconcile_number ); /* replace ' ' by '0' in number */ tmp = new_label + strlen ( old_label ) * sizeof ( gchar ); while ( *tmp == ' ' ) *tmp++ = '0'; g_free ( old_label ); return new_label; }
/** that function delete the current account selected in the account properties * \param none * \return FALSE FALSE * */ gboolean gsb_account_delete ( void ) { gint deleted_account; gint page_number; GSList *list_tmp; gchar* tmpstr; deleted_account = gsb_gui_navigation_get_current_account (); tmpstr = g_strdup_printf (_("Delete account \"%s\"?"), gsb_data_account_get_name ( deleted_account ) ) ; if ( !question_yes_no_hint ( tmpstr, _("This will irreversibly remove this account and all operations " "that were previously contained. There is no undo for this. " "Usually it's a better way to close an account."), GTK_RESPONSE_NO )) { g_free ( tmpstr ); return FALSE; } g_free ( tmpstr ); /* if the last account, close the file */ if ( gsb_data_account_get_accounts_amount () == 1 ) { gsb_file_set_modified ( FALSE ); gsb_file_close (); return FALSE; } /* delete the schedules transactions on that account */ list_tmp = gsb_data_scheduled_get_scheduled_list (); while (list_tmp) { gint scheduled_number; scheduled_number = gsb_data_scheduled_get_scheduled_number ( list_tmp -> data ); if ( gsb_data_scheduled_get_account_number (scheduled_number) == deleted_account ) gsb_data_scheduled_remove_scheduled (scheduled_number); list_tmp = list_tmp -> next; } /* remove all the transactions of that account */ list_tmp = gsb_data_transaction_get_complete_transactions_list (); while (list_tmp) { gint transaction_number; transaction_number = gsb_data_transaction_get_transaction_number ( list_tmp -> data ); /* better to go to the next transaction now */ list_tmp = list_tmp -> next; if (gsb_data_transaction_get_account_number (transaction_number) == deleted_account) { gint contra_transaction_number; /* we are on a transaction on the deleted account, we delete that transaction, * but if it's a transfer, modify the contra-transaction to set transfer to deleted account */ contra_transaction_number = gsb_data_transaction_get_contra_transaction_number ( transaction_number); if (contra_transaction_number > 0) /* it's a transfer, modify the contra-transaction */ gsb_data_transaction_set_contra_transaction_number ( contra_transaction_number, -1); /* now can remove the transaction */ gsb_data_transaction_remove_transaction_without_check ( transaction_number ); } } /* delete the payment_number */ list_tmp = gsb_data_account_get_sort_list ( deleted_account ); while (list_tmp) { gpointer ptr; gint payment_number; ptr = list_tmp -> data; payment_number = GPOINTER_TO_INT ( ptr ); gsb_data_payment_remove ( payment_number ); list_tmp = list_tmp -> next; } /* delete the account */ gsb_data_account_delete ( deleted_account ); /* check gsb_gui_navigation_get_current_account () and gsb_gui_navigation_get_current_account ()_onglet and put them * on the first account if they are on the deleted account */ if ( gsb_gui_navigation_get_current_account () == deleted_account ) { GtkWidget *notebook_general; /* update the transaction list */ notebook_general = gsb_gui_get_general_notebook ( ); page_number = gtk_notebook_get_current_page ( GTK_NOTEBOOK ( notebook_general ) ); navigation_change_account ( gsb_data_account_first_number () ); gtk_notebook_set_current_page ( GTK_NOTEBOOK ( notebook_general ), page_number ); } /* update the buttons lists */ gsb_menu_update_accounts_in_menus(); /* Replace trees contents. */ categories_fill_list (); budgetary_lines_fill_list (); payees_fill_list (); /* update the categories in lists */ transaction_list_update_element (ELEMENT_CATEGORY); /* update the name of accounts in form */ gsb_account_update_combo_list ( gsb_form_scheduler_get_element_widget (SCHEDULED_FORM_ACCOUNT), FALSE ); gsb_scheduler_list_fill_list (gsb_scheduler_list_get_tree_view ()); mise_a_jour_liste_echeances_manuelles_accueil = 1; mise_a_jour_liste_comptes_accueil = 1; mise_a_jour_soldes_minimaux = 1; mise_a_jour_fin_comptes_passifs = 1; /* Update navigation pane. */ gsb_gui_navigation_remove_account ( deleted_account ); gsb_file_set_modified ( TRUE ); return FALSE; }
/** * create a qif export, according to the filename, the account * and eventually, limit the export to the archive if exists * this will export all the transactions of the account (except if we ask for an archive...) * including the archived transactions * * \param filename that file will be checked and ask to overwrite if needed * \param account_nb * \param archive_number if 0, just export in qif the account transactions ; if non 0, export just the transactions for that archive and account * * \return TRUE ok, FALSE pb */ gboolean qif_export ( const gchar *filename, gint account_nb, gint archive_number ) { FILE * fichier_qif; GSList *list_tmp_transactions; gint beginning; gint floating_point; gchar* tmpstr; if (!gsb_file_util_test_overwrite (filename)) return FALSE; if ( !( fichier_qif = utf8_fopen ( filename, "w" ) )) { dialogue_error_hint ( g_strerror(errno), g_strdup_printf ( _("Error opening file '%s'"), filename ) ); return FALSE; } /* get the floating point of the currency of the amount, * ie the number of digits after the . */ floating_point = gsb_data_currency_get_floating_point (gsb_data_account_get_currency (account_nb)); /* kind of account */ if ( gsb_data_account_get_kind (account_nb) == GSB_TYPE_CASH ) fprintf ( fichier_qif, "!Type:Cash\n" ); else if ( gsb_data_account_get_kind (account_nb) == GSB_TYPE_LIABILITIES || gsb_data_account_get_kind (account_nb) == GSB_TYPE_ASSET ) fprintf ( fichier_qif, "!Type:Oth L\n" ); else fprintf ( fichier_qif, "!Type:Bank\n" ); list_tmp_transactions = gsb_data_transaction_get_complete_transactions_list (); beginning = 1; 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_nb && (!archive_number || gsb_data_transaction_get_archive_number (transaction_number_tmp) == archive_number)) { if ( beginning ) { /* this is the beginning of the qif file, we set some beginnings things */ fprintf ( fichier_qif, "D%d/%d/%d\n", g_date_get_day (gsb_data_transaction_get_date (transaction_number_tmp)), g_date_get_month (gsb_data_transaction_get_date (transaction_number_tmp)), g_date_get_year (gsb_data_transaction_get_date (transaction_number_tmp))); /* met le solde initial */ tmpstr = utils_real_get_string (gsb_data_account_get_init_balance (account_nb, -1)); fprintf ( fichier_qif, "T%s\n", tmpstr); g_free ( tmpstr ); fprintf ( fichier_qif, "CX\nPOpening Balance\n" ); /* met le nom du imported_account */ fprintf ( fichier_qif, "L%s\n^\n", g_strconcat ( "[", gsb_data_account_get_name (account_nb), "]", NULL ) ); beginning = 0; } /* si c'est une opé de ventil, on la saute pas elle sera recherchée quand */ /* son opé ventilée sera exportée */ if ( !gsb_data_transaction_get_mother_transaction_number ( transaction_number_tmp)) { /* met la date */ fprintf ( fichier_qif, "D%d/%d/%d\n", g_date_get_day (gsb_data_transaction_get_date (transaction_number_tmp)), g_date_get_month (gsb_data_transaction_get_date (transaction_number_tmp)), g_date_get_year (gsb_data_transaction_get_date (transaction_number_tmp))); /* met le pointage */ if ( gsb_data_transaction_get_marked_transaction ( transaction_number_tmp)== OPERATION_POINTEE || gsb_data_transaction_get_marked_transaction ( transaction_number_tmp)== OPERATION_TELERAPPROCHEE ) fprintf ( fichier_qif, "C*\n" ); else if ( gsb_data_transaction_get_marked_transaction ( transaction_number_tmp)== OPERATION_RAPPROCHEE ) fprintf ( fichier_qif, "CX\n" ); /* met les notes */ if ( gsb_data_transaction_get_notes ( transaction_number_tmp)) fprintf ( fichier_qif, "M%s\n", gsb_data_transaction_get_notes ( transaction_number_tmp)); /* met le montant, transforme la devise si necessaire */ tmpstr = utils_real_get_string (gsb_data_transaction_get_adjusted_amount ( transaction_number_tmp, floating_point)); fprintf ( fichier_qif, "T%s\n", tmpstr); g_free ( tmpstr ); /* met le chèque si c'est un type à numérotation automatique */ if ( gsb_data_payment_get_automatic_numbering (gsb_data_transaction_get_method_of_payment_number (transaction_number_tmp))) fprintf ( fichier_qif, "N%s\n", gsb_data_transaction_get_method_of_payment_content ( transaction_number_tmp)); /* met le tiers */ fprintf ( fichier_qif, "P%s\n", gsb_data_payee_get_name ( gsb_data_transaction_get_party_number ( transaction_number_tmp), FALSE )); /* on met soit un virement, soit une ventil, soit les catégories */ /* si c'est une imported_splitted, on recherche toutes les opés de cette imported_splitted */ /* et les met à la suite */ /* la catégorie de l'opé sera celle de la première opé de imported_splitted */ if ( gsb_data_transaction_get_split_of_transaction ( transaction_number_tmp)) { /* it's a split of transactions, look for the children and append them */ gint mother_transaction_category_written; GSList *list_tmp_transactions_2; mother_transaction_category_written = 0; list_tmp_transactions_2 = gsb_data_transaction_get_transactions_list (); while ( list_tmp_transactions_2 ) { gint transaction_number_tmp_2; transaction_number_tmp_2 = gsb_data_transaction_get_transaction_number (list_tmp_transactions_2 -> data); if (gsb_data_transaction_get_mother_transaction_number (transaction_number_tmp_2) == transaction_number_tmp) { /* we are on a child, for the first one, we set the mother category */ /* the child can only be a normal category or a transfer */ if ( gsb_data_transaction_get_contra_transaction_number (transaction_number_tmp_2) > 0) { /* the child is a transfer */ if ( !mother_transaction_category_written ) { fprintf ( fichier_qif, "L%s\n", g_strconcat ( "[", gsb_data_account_get_name (gsb_data_transaction_get_contra_transaction_account (transaction_number_tmp_2)), "]", NULL )); mother_transaction_category_written = 1; } fprintf ( fichier_qif, "S%s\n", g_strconcat ( "[", gsb_data_account_get_name (gsb_data_transaction_get_contra_transaction_account ( transaction_number_tmp_2)), "]", NULL )); } else { /* it's a category : sub-category */ if ( !mother_transaction_category_written ) { fprintf ( fichier_qif, "L%s\n", gsb_data_category_get_name (gsb_data_transaction_get_category_number (transaction_number_tmp_2), gsb_data_transaction_get_sub_category_number (transaction_number_tmp_2), _("No category defined"))); mother_transaction_category_written = 1; } fprintf ( fichier_qif, "S%s\n", gsb_data_category_get_name (gsb_data_transaction_get_category_number (transaction_number_tmp_2), gsb_data_transaction_get_sub_category_number (transaction_number_tmp_2), _("No category defined"))); } /* set the notes of the split child */ if ( gsb_data_transaction_get_notes (transaction_number_tmp_2)) fprintf ( fichier_qif, "E%s\n", gsb_data_transaction_get_notes (transaction_number_tmp_2)); /* set the amount of the split child */ tmpstr = utils_real_get_string (gsb_data_transaction_get_adjusted_amount (transaction_number_tmp_2, floating_point)); fprintf ( fichier_qif, "$%s\n", tmpstr); g_free ( tmpstr ); } list_tmp_transactions_2 = list_tmp_transactions_2 -> next; } } else { /* if it's a transfer, the contra-account must exist, else we do * as for a normal category */ if ( gsb_data_transaction_get_contra_transaction_number (transaction_number_tmp) > 0 ) { /* it's a transfer */ fprintf ( fichier_qif, "L%s\n", g_strconcat ( "[", gsb_data_account_get_name (gsb_data_transaction_get_contra_transaction_account ( transaction_number_tmp)), "]", NULL )); } else { /* it's a normal category */ fprintf ( fichier_qif, "L%s\n", gsb_data_category_get_name (gsb_data_transaction_get_category_number (transaction_number_tmp), gsb_data_transaction_get_sub_category_number (transaction_number_tmp), FALSE )); } } fprintf ( fichier_qif, "^\n" ); } } list_tmp_transactions = list_tmp_transactions -> next; } if ( beginning ) { /* there is no transaction in the account, so do the opening of the account, bug no date */ /* met le solde initial */ gchar* tmpstr = utils_real_get_string (gsb_data_account_get_init_balance (account_nb, -1)); fprintf ( fichier_qif, "T%s\n", tmpstr); g_free ( tmpstr ); fprintf ( fichier_qif, "CX\nPOpening Balance\n" ); /* met le nom du imported_account */ fprintf ( fichier_qif, "L%s\n^\n", g_strconcat ( "[", gsb_data_account_get_name (account_nb), "]", NULL ) ); } fclose ( fichier_qif ); return TRUE; }
/** * export an archive given in param * it will create 1 file per account exported, containing * the transactions of the archive * the name exported will be "filename-name of the account.qif" * * \param filename a name without the extension * \param archive_number * * \return TRUE ok, FALSE pb * */ gboolean gsb_qif_export_archive ( const gchar *filename, gint archive_number ) { GSList *tmp_list; GSList *name_list = NULL; gint error_return = 0; if (!gsb_file_util_test_overwrite (filename)) return FALSE; /* the work (split between accounts) is already done with the archive_store, * so just use it */ tmp_list = gsb_data_archive_store_get_archives_list (); while (tmp_list) { gint archive_store_number; archive_store_number = gsb_data_archive_store_get_number (tmp_list -> data); if (gsb_data_archive_store_get_archive_number (archive_store_number) == archive_number) { gchar *new_filename; new_filename = g_strconcat ( filename, "-", gsb_data_account_get_name (gsb_data_archive_store_get_account_number(archive_store_number)), ".qif", NULL ); if (qif_export ( new_filename, gsb_data_archive_store_get_account_number(archive_store_number), archive_number )) name_list = g_slist_append ( name_list, new_filename ); else error_return = 1; } tmp_list = tmp_list -> next; } /* if there is more than 1 file created, we show what files we did */ if (g_slist_length (name_list) > 1) { gchar *string; string = g_strdup_printf ( _("There were many accounts to export in the archive,\nbut the QIF format only support one file per account,\nso Grisbi created %d files, one per account :\n"), g_slist_length (name_list)); /* add the name to the string */ tmp_list = name_list; while (tmp_list) { gchar *new_string; new_string = g_strconcat ( string, "\n", tmp_list -> data, NULL ); g_free (string); string = new_string; tmp_list = tmp_list -> next; } dialogue (string); g_free (string); } /* free the names */ tmp_list = name_list; while (tmp_list) { g_free (tmp_list -> data); tmp_list = tmp_list -> next; } g_slist_free (name_list); return !error_return; }
/** * export a transaction given in param in the file given in param * * \param transaction_number * \param csv_file * \param print_balance will set a balance for each transaction in the csv file * not set for archive export, set (but usefull ?) for account export * * \return TRUE ok, FALSE problem * */ static gboolean gsb_csv_export_transaction ( gint transaction_number, FILE *csv_file, gboolean print_balance ) { gsb_real amount; gint return_exponent; gint account_number; gchar* tmpstr; const GDate *value_date, *date; gint payment_method; account_number = gsb_data_transaction_get_account_number (transaction_number); /* Si c'est une ventilation d'opération (càd une opération fille), elle n'est pas traitée à la base du "if" mais plus loin, quand son opé ventilée sera exportée */ if ( gsb_data_transaction_get_mother_transaction_number (transaction_number) ) return TRUE; return_exponent = gsb_data_currency_get_floating_point ( gsb_data_account_get_currency (account_number)); /* met la date */ date = gsb_data_transaction_get_date ( transaction_number ); if ( date ) { CSV_CLEAR_FIELD (csv_field_date); csv_field_date = g_strdup_printf ("%d/%d/%d", g_date_get_day ( date ), g_date_get_month ( date ), g_date_get_year ( date ) ); } value_date = gsb_data_transaction_get_value_date ( transaction_number ); if ( value_date ) { CSV_CLEAR_FIELD (csv_field_date_val); csv_field_date_val = g_strdup_printf ("%d/%d/%d", g_date_get_day ( value_date ), g_date_get_month ( value_date ), g_date_get_year ( value_date ) ); } /* met le pointage */ CSV_CLEAR_FIELD (csv_field_pointage); switch ( gsb_data_transaction_get_marked_transaction ( transaction_number ) ) { case OPERATION_NORMALE: csv_field_pointage = my_strdup (""); break; case OPERATION_POINTEE: csv_field_pointage = my_strdup ("P"); break; case OPERATION_TELERAPPROCHEE: csv_field_pointage = my_strdup ("T"); break; case OPERATION_RAPPROCHEE: csv_field_pointage = my_strdup ("R"); break; } /* met les notes */ CSV_CLEAR_FIELD(csv_field_notes); if ( gsb_data_transaction_get_notes ( transaction_number ) ) csv_field_notes = my_strdup (gsb_data_transaction_get_notes ( transaction_number )); /* met le tiers */ CSV_CLEAR_FIELD(csv_field_tiers); csv_field_tiers = g_strdup ( gsb_data_payee_get_name ( gsb_data_transaction_get_party_number ( transaction_number ), FALSE ) ); /* met le numero du rapprochement */ if ( gsb_data_transaction_get_reconcile_number ( transaction_number ) ) { CSV_CLEAR_FIELD (csv_field_rappro); csv_field_rappro = my_strdup ( gsb_data_reconcile_get_name ( gsb_data_transaction_get_reconcile_number ( transaction_number ) ) ); } /* Met les informations bancaires de l'opération. Elles n'existent qu'au niveau de l'opération mère */ CSV_CLEAR_FIELD(csv_field_info_bank); if ( gsb_data_transaction_get_bank_references ( transaction_number ) ) { csv_field_info_bank = my_strdup ( gsb_data_transaction_get_bank_references ( transaction_number ) ); } /* met le montant, transforme la devise si necessaire */ amount = gsb_data_transaction_get_adjusted_amount ( transaction_number, return_exponent); CSV_CLEAR_FIELD (csv_field_credit); if (amount.mantissa >= 0 ) csv_field_credit = utils_real_get_string (amount); else csv_field_debit = utils_real_get_string (gsb_real_abs (amount)); /* met le cheque si c'est un type à numerotation automatique */ payment_method = gsb_data_transaction_get_method_of_payment_number ( transaction_number ); CSV_CLEAR_FIELD (csv_field_cheque); if (gsb_data_payment_get_automatic_numbering (payment_method)) csv_field_cheque = my_strdup ( gsb_data_transaction_get_method_of_payment_content ( transaction_number ) ); if ( gsb_data_transaction_get_budgetary_number ( transaction_number ) != -1 ) { CSV_CLEAR_FIELD (csv_field_imput); csv_field_imput = my_strdup ( gsb_data_budget_get_name ( gsb_data_transaction_get_budgetary_number ( transaction_number ), 0, "" ) ); if ( gsb_data_transaction_get_sub_budgetary_number ( transaction_number ) != -1 ) { CSV_CLEAR_FIELD (csv_field_sous_imput); csv_field_sous_imput = my_strdup ( gsb_data_budget_get_sub_budget_name ( gsb_data_transaction_get_budgetary_number ( transaction_number ), gsb_data_transaction_get_sub_budgetary_number ( transaction_number ), NULL ) ); } } /* Piece comptable */ CSV_CLEAR_FIELD (csv_field_piece); csv_field_piece = my_strdup ( gsb_data_transaction_get_voucher ( transaction_number ) ); /* Balance */ if (print_balance) { current_balance = gsb_real_add ( current_balance, amount ); CSV_CLEAR_FIELD (csv_field_solde); csv_field_solde = utils_real_get_string (current_balance); } /* Number */ CSV_CLEAR_FIELD (csv_field_operation); csv_field_operation = g_strdup_printf("%d", transaction_number ); /* Account name */ CSV_CLEAR_FIELD (csv_field_account); csv_field_account = my_strdup (gsb_data_account_get_name (account_number)); /* Financial Year */ if ( gsb_data_transaction_get_financial_year_number ( transaction_number ) != -1 ) { CSV_CLEAR_FIELD (csv_field_exercice ); csv_field_exercice = my_strdup (gsb_data_fyear_get_name(gsb_data_transaction_get_financial_year_number ( transaction_number ))); } /* on met soit un virement, soit une ventilation, soit les catégories */ /* Si c'est une opération ventilée, on recherche toutes les ventilations de cette opération et on les traite immédiatement. */ /* et les met à la suite */ /* la catégorie de l'opé sera celle de la première opé de ventilation */ if ( gsb_data_transaction_get_split_of_transaction ( transaction_number ) ) { GSList *pSplitTransactionList; CSV_CLEAR_FIELD (csv_field_categ); csv_field_categ = my_strdup (_("Split of transaction")); csv_add_record(csv_file,FALSE, print_balance); pSplitTransactionList = gsb_data_transaction_get_transactions_list (); while ( pSplitTransactionList ) { gint pSplitTransaction; pSplitTransaction = gsb_data_transaction_get_transaction_number ( pSplitTransactionList -> data ); if ( gsb_data_transaction_get_account_number ( pSplitTransaction ) == gsb_data_transaction_get_account_number (transaction_number) && gsb_data_transaction_get_mother_transaction_number ( pSplitTransaction ) == transaction_number ) { /* on commence par mettre la catég et sous categ de l'opé et de l'opé de ventilation */ CSV_CLEAR_FIELD (csv_field_ventil); csv_field_ventil = my_strdup (_("B")); /* -> mark */ CSV_CLEAR_FIELD (csv_field_operation); csv_field_operation = g_strdup_printf("%d", pSplitTransaction ); if ( gsb_data_transaction_get_contra_transaction_number ( pSplitTransaction ) > 0) { /* c'est un virement */ CSV_CLEAR_FIELD (csv_field_categ); csv_field_categ = my_strdup (_("Transfer")); tmpstr = g_strconcat ( "[", gsb_data_account_get_name ( gsb_data_transaction_get_contra_transaction_account ( pSplitTransaction ) ), "]", NULL ); /* TODO dOm : is it necessary to duplicate memory with my_strdup since it was already newly allocated memory ? */ CSV_CLEAR_FIELD (csv_field_sous_categ); csv_field_sous_categ = my_strdup (tmpstr); g_free ( tmpstr ); } else { if ( gsb_data_transaction_get_category_number ( pSplitTransaction ) != -1 ) { CSV_CLEAR_FIELD (csv_field_categ); csv_field_categ = my_strdup ( gsb_data_category_get_name ( gsb_data_transaction_get_category_number ( pSplitTransaction ), 0, "" ) ); if ( gsb_data_transaction_get_sub_category_number ( pSplitTransaction ) != -1 ) { CSV_CLEAR_FIELD (csv_field_sous_categ); csv_field_sous_categ = my_strdup ( gsb_data_category_get_sub_category_name ( gsb_data_transaction_get_category_number ( pSplitTransaction ), gsb_data_transaction_get_sub_category_number ( pSplitTransaction ), NULL ) ); } } } /* met les notes de la ventilation */ if ( gsb_data_transaction_get_notes ( pSplitTransaction ) ) { CSV_CLEAR_FIELD (csv_field_notes); csv_field_notes = my_strdup (gsb_data_transaction_get_notes ( pSplitTransaction )); } /* met le montant de la ventilation */ amount = gsb_data_transaction_get_adjusted_amount ( pSplitTransaction, return_exponent ); CSV_CLEAR_FIELD (csv_field_montant); csv_field_montant = utils_real_get_string (amount); /* met le rapprochement */ if ( gsb_data_transaction_get_reconcile_number ( pSplitTransaction ) ) { CSV_CLEAR_FIELD (csv_field_rappro); csv_field_rappro = my_strdup ( gsb_data_reconcile_get_name ( gsb_data_transaction_get_reconcile_number ( pSplitTransaction ) ) ); } /* met le chèque si c'est un type à numéotation automatique */ payment_method = gsb_data_transaction_get_method_of_payment_number ( pSplitTransaction ); if (gsb_data_payment_get_automatic_numbering (payment_method)) { CSV_CLEAR_FIELD (csv_field_cheque); csv_field_cheque = my_strdup ( gsb_data_transaction_get_method_of_payment_content ( pSplitTransaction ) ); } /* Budgetary lines */ if ( gsb_data_transaction_get_budgetary_number ( pSplitTransaction ) != -1 ) { CSV_CLEAR_FIELD (csv_field_imput); csv_field_imput = my_strdup ( gsb_data_budget_get_name ( gsb_data_transaction_get_budgetary_number ( pSplitTransaction ), 0, "" ) ); if ( gsb_data_transaction_get_sub_budgetary_number ( pSplitTransaction ) != -1 ) { CSV_CLEAR_FIELD (csv_field_sous_imput); csv_field_sous_imput = my_strdup ( gsb_data_budget_get_sub_budget_name ( gsb_data_transaction_get_budgetary_number ( pSplitTransaction ), gsb_data_transaction_get_sub_budgetary_number ( pSplitTransaction ), NULL ) ); } } /* Piece comptable */ CSV_CLEAR_FIELD (csv_field_piece); csv_field_piece = my_strdup ( gsb_data_transaction_get_voucher ( pSplitTransaction ) ); /* Financial Year */ if ( gsb_data_transaction_get_financial_year_number ( pSplitTransaction ) != -1 ) { CSV_CLEAR_FIELD (csv_field_exercice ); csv_field_exercice = my_strdup (gsb_data_fyear_get_name(gsb_data_transaction_get_financial_year_number ( pSplitTransaction ))); } csv_add_record(csv_file,FALSE, print_balance); } pSplitTransactionList = pSplitTransactionList -> next; } csv_clear_fields(TRUE); } else { gchar *tmpstr; gint contra_transaction_number = gsb_data_transaction_get_contra_transaction_number ( transaction_number ); switch (contra_transaction_number) { case 0: /* normal category */ if ( gsb_data_transaction_get_category_number ( transaction_number ) != -1 ) { CSV_CLEAR_FIELD (csv_field_categ); csv_field_categ = my_strdup ( gsb_data_category_get_name ( gsb_data_transaction_get_category_number ( transaction_number ), 0, "" ) ); if ( gsb_data_transaction_get_sub_category_number ( transaction_number ) != -1 ) { CSV_CLEAR_FIELD (csv_field_sous_categ); csv_field_sous_categ = my_strdup ( gsb_data_category_get_sub_category_name ( gsb_data_transaction_get_category_number ( transaction_number ), gsb_data_transaction_get_sub_category_number ( transaction_number ), NULL ) ); } } break; case -1: /* transfer to deleted account */ CSV_CLEAR_FIELD (csv_field_categ); csv_field_categ = my_strdup (_("Transfer")); tmpstr = g_strconcat ( "[", _("Deleted account"), "]", NULL ); /* TODO dOm : is it necessary to duplicate memory with my_strdup since it was already newly allocated memory ? */ CSV_CLEAR_FIELD (csv_field_sous_categ); csv_field_sous_categ = my_strdup (tmpstr); g_free ( tmpstr ); break; default: /* transfer */ CSV_CLEAR_FIELD (csv_field_categ); csv_field_categ = my_strdup (_("Transfer")); tmpstr = g_strconcat ( "[", gsb_data_account_get_name ( gsb_data_transaction_get_contra_transaction_account ( transaction_number ) ), "]", NULL ); /* TODO dOm : is it necessary to duplicate memory with my_strdup since it was already newly allocated memory ? */ CSV_CLEAR_FIELD (csv_field_sous_categ); csv_field_sous_categ = my_strdup (tmpstr); g_free ( tmpstr ); } csv_add_record(csv_file,TRUE, print_balance); } return TRUE; }
/** * export an account into a csv file * * \param filename * \param account_nb the account to export * * \return TRUE if ok, FALSE if problem * */ gboolean gsb_csv_export_account ( const gchar *filename, gint account_number ) { FILE *csv_file; GSList *pTransactionList; GSList *tmp_list; csv_file = gsb_csv_export_open_file ( filename ); if ( !csv_file ) return FALSE; if ( g_csv_with_title_line ) gsb_csv_export_title_line ( csv_file, TRUE ); /* set the initial balance */ if ( csv_field_tiers ) g_free ( csv_field_tiers ); csv_field_tiers = g_strconcat (_("Initial balance") , " [", gsb_data_account_get_name ( account_number ), "]", NULL ); /* set the initial current_balance, * as we will write all the non archived transactions, * we need to get the initial balance of the account, without the archived transactions */ current_balance = gsb_data_account_get_init_balance ( account_number, -1); tmp_list = gsb_data_archive_store_get_archives_list ( ); while ( tmp_list ) { gint archive_store_number; archive_store_number = gsb_data_archive_store_get_number ( tmp_list -> data ); if ( gsb_data_archive_store_get_account_number ( archive_store_number ) == account_number ) current_balance = gsb_real_add ( current_balance, gsb_data_archive_store_get_balance ( archive_store_number ) ); tmp_list = tmp_list -> next; } /* ok the balance is now good, can write it */ CSV_CLEAR_FIELD ( csv_field_solde ); csv_field_solde = utils_real_get_string ( current_balance ); if ( current_balance.mantissa >= 0 ) { CSV_CLEAR_FIELD ( csv_field_credit ); csv_field_credit = utils_real_get_string ( current_balance ); } else { CSV_CLEAR_FIELD ( csv_field_debit ); csv_field_debit = utils_real_get_string ( gsb_real_abs ( current_balance ) ); } csv_add_record ( csv_file, TRUE, TRUE ); /* export the transactions */ pTransactionList = gsb_data_transaction_get_transactions_list ( ); tmp_list = g_slist_sort ( g_slist_copy ( pTransactionList ), (GCompareFunc) gsb_csv_export_sort_by_value_date_or_date ); while ( tmp_list ) { gint pTransaction; pTransaction = gsb_data_transaction_get_transaction_number ( tmp_list -> data ); if ( gsb_data_transaction_get_account_number ( pTransaction ) == account_number ) { /* export the transaction */ /* for now, print the balance. is this usefull ? */ gsb_csv_export_transaction ( pTransaction, csv_file, TRUE); } tmp_list = tmp_list -> next; } fclose ( csv_file ); g_slist_free ( tmp_list ); /* return */ return TRUE; }
/** * Fill the `model' GtkTreeModel with all payment methods known. They * are organized by account and then my method_ptr of payment method: Debit, * Credit, Neutral. * * \param model * * \return */ void gsb_payment_method_config_fill_list ( GtkTreeModel *model) { GSList *list_tmp; gtk_tree_store_clear ( GTK_TREE_STORE (model) ); /* Fill tree, iter over with accounts */ list_tmp = gsb_data_account_get_list_accounts (); while ( list_tmp ) { gint account_number; GSList *payment_list; GtkTreeIter account_iter, debit_iter, credit_iter; account_number = gsb_data_account_get_no_account ( list_tmp -> data ); gtk_tree_store_append (GTK_TREE_STORE (model), &account_iter, NULL); gtk_tree_store_set (GTK_TREE_STORE (model), &account_iter, PAYMENT_METHODS_NAME_COLUMN, gsb_data_account_get_name (account_number), PAYMENT_METHODS_NUMBERING_COLUMN, NULL, PAYMENT_METHODS_TYPE_COLUMN, 0, PAYMENT_METHODS_DEFAULT_COLUMN, FALSE, PAYMENT_METHODS_ACTIVABLE_COLUMN, FALSE, PAYMENT_METHODS_VISIBLE_COLUMN, FALSE, PAYMENT_METHODS_NUMBER_COLUMN, NULL, PAYMENT_METHODS_ACCOUNT_COLUMN, account_number, -1 ); /* Create the "Debit" node */ gtk_tree_store_append (GTK_TREE_STORE (model), &debit_iter, &account_iter); gtk_tree_store_set (GTK_TREE_STORE (model), &debit_iter, PAYMENT_METHODS_NAME_COLUMN, _("Debit"), PAYMENT_METHODS_NUMBERING_COLUMN, NULL, PAYMENT_METHODS_TYPE_COLUMN, 0, PAYMENT_METHODS_DEFAULT_COLUMN, FALSE, PAYMENT_METHODS_ACTIVABLE_COLUMN, FALSE, PAYMENT_METHODS_VISIBLE_COLUMN, FALSE, PAYMENT_METHODS_NUMBER_COLUMN, NULL, PAYMENT_METHODS_ACCOUNT_COLUMN, account_number, -1 ); /* Create the "Credit" node */ gtk_tree_store_append (GTK_TREE_STORE (model), &credit_iter, &account_iter); gtk_tree_store_set (GTK_TREE_STORE (model), &credit_iter, PAYMENT_METHODS_NAME_COLUMN, _("Credit"), PAYMENT_METHODS_NUMBERING_COLUMN, NULL, /* This is a hack: account number is put in Debit/Credit nodes */ PAYMENT_METHODS_TYPE_COLUMN, 0, PAYMENT_METHODS_DEFAULT_COLUMN, FALSE, PAYMENT_METHODS_ACTIVABLE_COLUMN, FALSE, PAYMENT_METHODS_VISIBLE_COLUMN, FALSE, PAYMENT_METHODS_NUMBER_COLUMN, NULL, PAYMENT_METHODS_ACCOUNT_COLUMN, account_number, -1 ); /* Iter over account payment methods */ payment_list = gsb_data_payment_get_payments_list (); while (payment_list) { gint payment_number; GtkTreeIter *parent_iter = NULL; GtkTreeIter method_iter; gboolean isdefault; const gchar *number; payment_number = gsb_data_payment_get_number (payment_list -> data); /* check if we have to show this payment here */ if (gsb_data_payment_get_account_number (payment_number) != account_number) { payment_list = payment_list -> next; continue; } /* set if default value */ if ( payment_number == gsb_data_account_get_default_debit (account_number) || payment_number == gsb_data_account_get_default_credit (account_number) ) isdefault = 1; else isdefault = 0; /* look for the parent iter according to the sign */ switch (gsb_data_payment_get_sign (payment_number)) { case GSB_PAYMENT_NEUTRAL: parent_iter = &account_iter; break; case GSB_PAYMENT_DEBIT: parent_iter = &debit_iter; break; case GSB_PAYMENT_CREDIT: parent_iter = &credit_iter; break; } /* set the last number */ if ( gsb_data_payment_get_automatic_numbering (payment_number)) number = gsb_data_payment_get_last_number ( payment_number ); else number = g_strdup(""); /* Insert a child node */ gtk_tree_store_append (GTK_TREE_STORE (model), &method_iter, parent_iter); gtk_tree_store_set (GTK_TREE_STORE (model), &method_iter, PAYMENT_METHODS_NAME_COLUMN, gsb_data_payment_get_name (payment_number), PAYMENT_METHODS_NUMBERING_COLUMN, number, PAYMENT_METHODS_TYPE_COLUMN, gsb_data_payment_get_sign (payment_number), PAYMENT_METHODS_DEFAULT_COLUMN, isdefault, PAYMENT_METHODS_ACTIVABLE_COLUMN, gsb_data_payment_get_sign (payment_number) != 0, PAYMENT_METHODS_VISIBLE_COLUMN, gsb_data_payment_get_sign (payment_number) != 0, PAYMENT_METHODS_NUMBER_COLUMN, payment_number, PAYMENT_METHODS_ACCOUNT_COLUMN, account_number, -1 ); payment_list = payment_list -> next; } list_tmp = list_tmp -> next; } }
/** * clear and fill the reconciliation tree with the accounts, * and for each account, set the method of payments in the good order * * \param * * \return */ void gsb_reconcile_sort_config_fill ( void ) { GtkTreeIter account_iter, payment_method_iter; GSList *list_tmp; GtkTreeModel *model; model = gtk_tree_view_get_model (GTK_TREE_VIEW (reconcile_treeview)); gtk_tree_store_clear (GTK_TREE_STORE (model)); list_tmp = gsb_data_account_get_list_accounts (); while ( list_tmp ) { gint account_number; GSList *sorted_list; GSList *payment_list; gboolean visible; account_number = gsb_data_account_get_no_account ( list_tmp -> data ); /* when no method of payment, hide the checkbuttons because non sense */ payment_list = gsb_data_payment_get_list_for_account (account_number); if (payment_list) { visible = TRUE; g_slist_free (payment_list); } else visible = FALSE; gtk_tree_store_append (GTK_TREE_STORE (model), &account_iter, NULL); gtk_tree_store_set (GTK_TREE_STORE (model), &account_iter, RECONCILIATION_SORT_NAME_COLUMN, gsb_data_account_get_name (account_number), RECONCILIATION_SORT_VISIBLE_COLUMN, visible, RECONCILIATION_SORT_SORT_COLUMN, gsb_data_account_get_reconcile_sort_type(account_number), RECONCILIATION_SORT_SPLIT_NEUTRAL_COLUMN, gsb_data_account_get_split_neutral_payment (account_number), RECONCILIATION_SORT_ACCOUNT_COLUMN, account_number, RECONCILIATION_SORT_TYPE_COLUMN, 0, RECONCILIATION_SORT_SENSITIVE_COLUMN, visible, -1 ); /* the sorted list is a list of numbers of method of payment, in the good order */ sorted_list = gsb_data_account_get_sort_list (account_number); while ( sorted_list ) { gint payment_number; /* in the sorted list, a number can be negative, when split a neutral into 2 parts * so payment number here can be negative for neutral payments */ payment_number = GPOINTER_TO_INT (sorted_list -> data); if (payment_number) { gchar *name = NULL; gtk_tree_store_append (GTK_TREE_STORE (model), &payment_method_iter, &account_iter); /* if split the neutrals, show here with the name */ switch (gsb_data_payment_get_sign (abs (payment_number))) { case GSB_PAYMENT_DEBIT: case GSB_PAYMENT_CREDIT: name = my_strdup (gsb_data_payment_get_name (payment_number)); break; case GSB_PAYMENT_NEUTRAL: if (gsb_data_account_get_split_neutral_payment (account_number)) { /* the neutrals are splitted */ if (payment_number < 0) name = g_strconcat ( gsb_data_payment_get_name (-payment_number), " ( - )", NULL ); else name = g_strconcat ( gsb_data_payment_get_name (payment_number), " ( + )", NULL ); } else name = my_strdup (gsb_data_payment_get_name (payment_number)); break; } gtk_tree_store_set (GTK_TREE_STORE (model), &payment_method_iter, RECONCILIATION_SORT_NAME_COLUMN, name, RECONCILIATION_SORT_VISIBLE_COLUMN, FALSE, RECONCILIATION_SORT_SORT_COLUMN, FALSE, RECONCILIATION_SORT_SPLIT_NEUTRAL_COLUMN, FALSE, RECONCILIATION_SORT_ACCOUNT_COLUMN, account_number, RECONCILIATION_SORT_TYPE_COLUMN, payment_number, RECONCILIATION_SORT_SENSITIVE_COLUMN, TRUE, -1 ); if (name) g_free (name); } sorted_list = sorted_list -> next; } if ( gtk_tree_model_iter_has_child( GTK_TREE_MODEL(model), &account_iter) && gsb_data_account_get_reconcile_sort_type (account_number) ) { GtkTreePath * treepath; treepath = gtk_tree_model_get_path (GTK_TREE_MODEL(model), &account_iter); if ( treepath ) { gtk_tree_view_expand_row ( GTK_TREE_VIEW(reconcile_treeview), treepath, TRUE ); gtk_tree_path_free ( treepath ); } } list_tmp = list_tmp -> next; } }
/** * set Grisbi title * * * * */ gboolean gsb_main_set_grisbi_title ( gint account_number ) { gchar *titre_grisbi = NULL; gchar *titre = NULL; gint tmp_number; gboolean return_value; devel_debug_int ( account_number ); if ( nom_fichier_comptes == NULL ) { titre_grisbi = g_strdup ( _("Grisbi") ); return_value = TRUE; } else { switch ( conf.display_grisbi_title ) { case GSB_ACCOUNTS_TITLE: if ( titre_fichier && strlen ( titre_fichier ) ) titre = g_strdup ( titre_fichier ); break; case GSB_ACCOUNT_HOLDER: { if ( account_number == -1 ) tmp_number = gsb_data_account_first_number ( ); else tmp_number = account_number; if ( tmp_number == -1 ) { if ( titre_fichier && strlen ( titre_fichier ) ) titre = g_strdup ( titre_fichier ); } else { titre = g_strdup ( gsb_data_account_get_holder_name ( tmp_number ) ); if ( titre == NULL ) titre = g_strdup ( gsb_data_account_get_name ( tmp_number ) ); } break; } case GSB_ACCOUNTS_FILE: if ( nom_fichier_comptes && strlen ( nom_fichier_comptes ) ) titre = g_path_get_basename ( nom_fichier_comptes ); break; } if ( titre && strlen ( titre ) > 0 ) { titre_grisbi = g_strconcat ( titre, " - ", _("Grisbi"), NULL ); g_free ( titre ); return_value = TRUE; } else { titre_grisbi = g_strconcat ( "<", _("unnamed"), ">", NULL ); return_value = FALSE; } } gtk_window_set_title ( GTK_WINDOW ( run.window ), titre_grisbi ); gsb_main_page_update_homepage_title ( titre_grisbi ); if ( titre_grisbi && strlen ( titre_grisbi ) > 0 ) g_free ( titre_grisbi ); return return_value; }
/** * fill the reconcile list, * sort each reconcile in its account * * \param * * \return * */ void gsb_reconcile_config_fill ( void ) { GtkTreeModel *model; GSList *tmp_list; GrisbiWinEtat *w_etat; if (!reconcile_treeview) return; w_etat = (GrisbiWinEtat *) grisbi_win_get_w_etat (); model = gtk_tree_view_get_model ( GTK_TREE_VIEW (reconcile_treeview)); gtk_tree_store_clear (GTK_TREE_STORE(model)); /* we make a tree_model containing the accounts, * and for each account, all the reconciles */ tmp_list = gsb_data_account_get_list_accounts (); while (tmp_list) { gint account_number; GtkTreeIter account_iter; GList *reconcile_list; account_number = gsb_data_account_get_no_account (tmp_list -> data); gtk_tree_store_append ( GTK_TREE_STORE (model), &account_iter, NULL ); gtk_tree_store_set ( GTK_TREE_STORE (model), &account_iter, RECONCILIATION_NAME_COLUMN, gsb_data_account_get_name (account_number), RECONCILIATION_WEIGHT_COLUMN, 800, RECONCILIATION_ACCOUNT_COLUMN, account_number, -1 ); /* for each account, get the concerned reconciles */ reconcile_list = gsb_data_reconcile_get_sort_reconcile_list (account_number); if (w_etat->reconcile_sort) reconcile_list = g_list_reverse (reconcile_list); while (reconcile_list) { gint reconcile_number; reconcile_number = GPOINTER_TO_INT (reconcile_list->data); if (gsb_data_reconcile_get_account (reconcile_number) == account_number) { GtkTreeIter reconcile_iter; gchar *init_date, *final_date; gchar *init_balance, *final_balance; init_date = gsb_format_gdate (gsb_data_reconcile_get_init_date (reconcile_number)); final_date = gsb_format_gdate (gsb_data_reconcile_get_final_date (reconcile_number)); init_balance = utils_real_get_string (gsb_data_reconcile_get_init_balance (reconcile_number)); final_balance = utils_real_get_string (gsb_data_reconcile_get_final_balance (reconcile_number)); gtk_tree_store_append ( GTK_TREE_STORE (model), &reconcile_iter, &account_iter ); gtk_tree_store_set ( GTK_TREE_STORE (model), &reconcile_iter, RECONCILIATION_NAME_COLUMN, gsb_data_reconcile_get_name (reconcile_number), RECONCILIATION_WEIGHT_COLUMN, 400, RECONCILIATION_INIT_DATE_COLUMN, init_date, RECONCILIATION_FINAL_DATE_COLUMN, final_date, RECONCILIATION_INIT_BALANCE_COLUMN, init_balance, RECONCILIATION_FINAL_BALANCE_COLUMN, final_balance, RECONCILIATION_RECONCILE_COLUMN, reconcile_number, RECONCILIATION_ACCOUNT_COLUMN, account_number, -1 ); g_free (init_date); g_free (final_date); g_free (init_balance); g_free (final_balance); } reconcile_list = reconcile_list -> next; } tmp_list = tmp_list -> next; } }