/** * callback called when something change in the entries of the configuration of the reconcile * * \param tree_view * * \return FALSE * */ gboolean gsb_reconcile_config_update_line ( GtkWidget *entry, GtkWidget *tree_view ) { GtkTreeIter iter; GtkTreeModel *model; GtkTreeSelection *selection; gboolean good; selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)); good = gtk_tree_selection_get_selected (selection, &model, &iter); if (good) { gint reconcile_number; gtk_tree_model_get (model, &iter, RECONCILIATION_RECONCILE_COLUMN, &reconcile_number, -1 ); if (reconcile_number) { /* we are on a reconcile, change the line with the new values */ 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_set ( GTK_TREE_STORE (model), &iter, RECONCILIATION_NAME_COLUMN, gsb_data_reconcile_get_name (reconcile_number), RECONCILIATION_INIT_DATE_COLUMN, init_date, RECONCILIATION_FINAL_DATE_COLUMN, final_date, RECONCILIATION_INIT_BALANCE_COLUMN, init_balance, RECONCILIATION_FINAL_BALANCE_COLUMN, final_balance, -1 ); g_free (init_date); g_free (final_date); g_free (init_balance); g_free (final_balance); } } return FALSE; }
/** * 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; }
/** * append a new line to the tree_view and fill it with the * link given in param * * \param model * \param link_number * \param iter a pointer to an iter to fill it with the position of the new link, or NULL * * \return * */ void gsb_currency_link_config_append_line ( GtkTreeModel *model, gint link_number, GtkTreeIter *iter_to_fill ) { gchar *invalid; GtkTreeIter local_iter; GtkTreeIter *iter_ptr; gchar *tmpstr; gchar *strdate; if (iter_to_fill) iter_ptr = iter_to_fill; else iter_ptr = &local_iter; strdate = gsb_format_gdate ( gsb_data_currency_link_get_modified_date ( link_number ) ); if ( gsb_data_currency_link_get_invalid_link (link_number)) invalid = GTK_STOCK_DIALOG_WARNING; else invalid = NULL; tmpstr = utils_real_get_string (gsb_data_currency_link_get_change_rate (link_number)); gtk_list_store_append ( GTK_LIST_STORE ( model ), iter_ptr ); gtk_list_store_set ( GTK_LIST_STORE ( model ), iter_ptr, LINK_1_COLUMN, "1", LINK_CURRENCY1_COLUMN, gsb_data_currency_get_name (gsb_data_currency_link_get_first_currency(link_number)), LINK_EQUAL_COLUMN, "=", LINK_EXCHANGE_COLUMN, tmpstr, LINK_CURRENCY2_COLUMN, gsb_data_currency_get_name (gsb_data_currency_link_get_second_currency(link_number)), LINK_DATE_COLUMN, strdate, LINK_INVALID_COLUMN, invalid, LINK_NUMBER_COLUMN, link_number, -1 ); g_free ( tmpstr ); g_free ( strdate ); }
/** * 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; }
/** * called when something change for a link * * \param tree_view the tree_view * * \return FALSE * */ gboolean gsb_currency_link_config_modify_link ( GtkWidget *tree_view ) { GtkWidget *combobox_1; GtkWidget *combobox_2; GtkWidget *exchange_entry; GtkTreeModel *model; GtkTreeIter iter; gint link_number; gchar *invalid; GtkWidget *label; gchar* tmpstr; gchar *strdate; gsb_real number; if ( !gtk_tree_selection_get_selected ( gtk_tree_view_get_selection ( GTK_TREE_VIEW ( tree_view ) ), &model, &iter ) ) return FALSE; gtk_tree_model_get ( GTK_TREE_MODEL (model), &iter, LINK_NUMBER_COLUMN, &link_number, -1 ); /* normally should not happen */ if (!link_number) return FALSE; combobox_1 = g_object_get_data ( G_OBJECT (model), "combobox_1" ); combobox_2 = g_object_get_data ( G_OBJECT (model), "combobox_2" ); exchange_entry = g_object_get_data ( G_OBJECT (model), "exchange_entry" ); number = utils_real_get_from_string ( gtk_entry_get_text ( GTK_ENTRY (exchange_entry) ) ); if ( number.exponent > 8 ) gtk_entry_set_max_length (GTK_ENTRY (exchange_entry), strlen( gtk_entry_get_text ( GTK_ENTRY ( exchange_entry ) ) - 1) ); gsb_data_currency_link_set_first_currency ( link_number, gsb_currency_get_currency_from_combobox (combobox_1)); gsb_data_currency_link_set_second_currency ( link_number, gsb_currency_get_currency_from_combobox (combobox_2)); gsb_data_currency_link_set_change_rate ( link_number, number ); gsb_data_currency_link_set_modified_date ( link_number, gdate_today ( ) ); strdate = gsb_format_gdate ( gsb_data_currency_link_get_modified_date ( link_number ) ); if ( gsb_data_currency_link_get_invalid_link (link_number)) invalid = GTK_STOCK_DIALOG_WARNING; else invalid = NULL; tmpstr = utils_real_get_string ( gsb_data_currency_link_get_change_rate ( link_number ) ); gtk_list_store_set ( GTK_LIST_STORE (model), &iter, LINK_CURRENCY1_COLUMN, gsb_data_currency_get_name (gsb_data_currency_link_get_first_currency(link_number)), LINK_EXCHANGE_COLUMN, tmpstr, LINK_CURRENCY2_COLUMN, gsb_data_currency_get_name (gsb_data_currency_link_get_second_currency(link_number)), LINK_DATE_COLUMN, strdate, LINK_INVALID_COLUMN, invalid, -1 ); g_free ( tmpstr ); g_free ( strdate ); /* set or hide the warning label */ label = g_object_get_data (G_OBJECT (model), "warning_label"); if ( gsb_data_currency_link_get_invalid_link (link_number)) { gtk_label_set_markup ( GTK_LABEL (label), gsb_data_currency_link_get_invalid_message (link_number)); gtk_widget_show (label); } else gtk_widget_hide (label); gsb_file_set_modified ( TRUE ); gsb_gui_navigation_update_home_page ( ); return FALSE; }
/** * called when select a link * * \param tree_selection * \param null not used * * \return FALSE * */ gboolean gsb_currency_link_config_select_currency ( GtkTreeSelection *tree_selection, gpointer null ) { GtkTreeModel *model; GtkTreeIter iter; gint link_number; GtkWidget *combobox_1; GtkWidget *combobox_2; GtkWidget *exchange_entry; GtkWidget *tree_view; GtkWidget *label; GtkWidget *button; gchar* tmpstr; if (!gtk_tree_selection_get_selected ( GTK_TREE_SELECTION (tree_selection), &model, &iter )) return FALSE; gtk_tree_model_get ( GTK_TREE_MODEL (model), &iter, LINK_NUMBER_COLUMN, &link_number, -1 ); /* normally should not happen */ if (!link_number) return FALSE; gtk_widget_set_sensitive ( GTK_WIDGET ( g_object_get_data ( G_OBJECT ( model ), "hbox_line") ), TRUE ); combobox_1 = g_object_get_data ( G_OBJECT (model), "combobox_1" ); combobox_2 = g_object_get_data ( G_OBJECT (model), "combobox_2" ); exchange_entry = g_object_get_data ( G_OBJECT (model), "exchange_entry" ); button = g_object_get_data ( G_OBJECT (model), "fixed_button" ); gtk_widget_set_sensitive ( button, TRUE ); tree_view = GTK_WIDGET ( gtk_tree_selection_get_tree_view ( tree_selection ) ); g_signal_handlers_block_by_func ( G_OBJECT (combobox_1), G_CALLBACK (gsb_currency_link_config_modify_link), tree_view ); gsb_currency_set_combobox_history ( combobox_1, gsb_data_currency_link_get_first_currency (link_number)); g_signal_handlers_unblock_by_func ( G_OBJECT (combobox_1), G_CALLBACK (gsb_currency_link_config_modify_link), tree_view ); g_signal_handlers_block_by_func ( G_OBJECT (combobox_2), G_CALLBACK (gsb_currency_link_config_modify_link), tree_view ); gsb_currency_set_combobox_history ( combobox_2, gsb_data_currency_link_get_second_currency (link_number)); g_signal_handlers_unblock_by_func ( G_OBJECT (combobox_2), G_CALLBACK (gsb_currency_link_config_modify_link), tree_view ); g_signal_handlers_block_by_func ( G_OBJECT (exchange_entry), G_CALLBACK (gsb_currency_link_config_modify_link), tree_view ); tmpstr = utils_real_get_string (gsb_data_currency_link_get_change_rate (link_number)); gtk_entry_set_text ( GTK_ENTRY (exchange_entry), tmpstr); g_free ( tmpstr ); g_signal_handlers_unblock_by_func ( G_OBJECT (exchange_entry), G_CALLBACK (gsb_currency_link_config_modify_link), tree_view ); /* set the fixed_link flag */ g_signal_handlers_block_by_func ( G_OBJECT ( button ), G_CALLBACK ( gsb_currency_link_config_button_fixed_changed ), tree_view ); gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( button ), gsb_data_currency_link_get_fixed_link ( link_number ) ); g_signal_handlers_unblock_by_func ( G_OBJECT ( button ), G_CALLBACK ( gsb_currency_link_config_button_fixed_changed ), tree_view ); /* set or hide the warning label */ label = g_object_get_data (G_OBJECT (model), "warning_label"); if ( gsb_data_currency_link_get_invalid_link (link_number)) { gtk_label_set_markup ( GTK_LABEL (label), gsb_data_currency_link_get_invalid_message (link_number)); gtk_widget_show (label); } else gtk_widget_hide (label); 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 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 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; } }