noalyss-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Noalyss-commit] [noalyss] 02/17: restructure files and folders


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 02/17: restructure files and folders
Date: Fri, 02 Oct 2015 10:22:14 +0000

sparkyx pushed a commit to branch master
in repository noalyss.

commit 083ba483cc65184b69e83d0aef3b5d6e2bedabe5
Author: Dany De Bontridder <address@hidden>
Date:   Tue Sep 15 07:26:33 2015 +0200

    restructure files and folders
---
 html/admin/setup.php                               |    6 +-
 html/admin_repo.php                                |    8 +-
 html/ajax.php                                      |    8 +-
 html/ajax_card.php                                 |   22 +-
 html/ajax_history.php                              |   14 +-
 html/ajax_ledger.php                               |   20 +-
 html/ajax_misc.php                                 |  130 +-
 html/ajax_poste.php                                |   12 +-
 html/ajax_todo_list.php                            |    8 +-
 html/backup.php                                    |    6 +-
 html/compute.php                                   |   10 +-
 html/direct.php                                    |    4 +-
 html/do.php                                        |   12 +-
 html/export.php                                    |    6 +-
 html/extension.raw.php                             |   16 +-
 html/fid.php                                       |   10 +-
 html/fid_card.php                                  |    6 +-
 html/index.php                                     |    6 +-
 html/login.php                                     |    8 +-
 html/logout.php                                    |    4 +-
 html/not_implemented.php                           |    2 +-
 html/popup.php                                     |   14 +-
 html/recherche.php                                 |   10 +-
 html/show_document.php                             |   10 +-
 html/show_document_modele.php                      |    8 +-
 html/show_pj.php                                   |    8 +-
 html/test.php                                      |   12 +-
 html/user_login.php                                |   10 +-
 include/ac_common.php                              | 1254 -------
 include/action.inc.php                             |   10 +-
 include/adm.inc.php                                |   14 +-
 include/{ => ajax}/ajax_account_update.php         |    0
 include/ajax/ajax_action_remove_concerned.php      |   45 +
 include/ajax/ajax_action_save_concerned.php        |   47 +
 include/ajax/ajax_add_concerned_card.php           |   83 +
 include/{ => ajax}/ajax_add_menu.php               |    0
 include/{ => ajax}/ajax_admin.php                  |    0
 include/ajax/ajax_anc_key_choice.php               |   53 +
 include/ajax/ajax_anc_key_compute.php              |   61 +
 include/ajax/ajax_anc_search.php                   |   98 +
 include/ajax/ajax_auto_anc_card.php                |   31 +
 include/ajax/ajax_bank_saldo.php                   |   75 +
 include/{ => ajax}/ajax_bookmark.php               |    0
 include/{ => ajax}/ajax_boxcard_search.php         |    0
 include/ajax/ajax_calendar_zoom.php                |   46 +
 include/ajax/ajax_create_menu.php                  |   15 +
 include/ajax/ajax_display_submenu.php              |   98 +
 include/ajax/ajax_fiche_def_detail.php             |   47 +
 include/ajax/ajax_gestion.php                      |  129 +
 include/{ => ajax}/ajax_get_menu_detail.php        |    0
 include/ajax/ajax_get_profile.php                  |  137 +
 include/ajax/ajax_get_receipt.php                  |   65 +
 include/ajax/ajax_ledger_show.php                  |   35 +
 include/ajax/ajax_min_row.php                      |   48 +
 include/ajax/ajax_mod_document.php                 |   52 +
 include/ajax/ajax_mod_menu.php                     |   17 +
 include/ajax/ajax_mod_periode.php                  |  104 +
 include/ajax/ajax_mod_predf_op.php                 |   76 +
 include/ajax/ajax_mod_stock_repo.php               |   80 +
 include/{ => ajax}/ajax_navigator.php              |    0
 include/{ => ajax}/ajax_pcmn_update.php            |    0
 include/{ => ajax}/ajax_plugin_detail.php          |    0
 include/ajax/ajax_preference.php                   |  195 +
 include/{ => ajax}/ajax_remove_submenu.php         |    0
 include/{ => ajax}/ajax_save_predf_op.php          |    0
 include/ajax/ajax_search_action.php                |   34 +
 include/ajax/ajax_search_add_tag.php               |   45 +
 include/ajax/ajax_search_clear_tag.php             |   38 +
 include/ajax/ajax_search_display_tag.php           |   40 +
 include/{ => ajax}/ajax_tag_add_action.php         |    0
 include/ajax/ajax_tag_detail.php                   |   51 +
 include/ajax/ajax_tag_list.php                     |   45 +
 include/{ => ajax}/ajax_tag_remove_action.php      |    0
 include/ajax/ajax_tag_save.php                     |   11 +
 include/ajax/ajax_tag_select_search.php            |   40 +
 include/ajax/ajax_update_payment.php               |   32 +
 include/ajax/ajax_update_predef.php                |   69 +
 include/ajax/ajax_view_action.php                  |   75 +
 include/ajax/ajax_view_mod_stock.php               |   58 +
 include/ajax_action_remove_concerned.php           |   45 -
 include/ajax_action_save_concerned.php             |   47 -
 include/ajax_add_concerned_card.php                |   83 -
 include/ajax_anc_key_choice.php                    |   53 -
 include/ajax_anc_key_compute.php                   |   61 -
 include/ajax_anc_search.php                        |   98 -
 include/ajax_auto_anc_card.php                     |   31 -
 include/ajax_bank_saldo.php                        |   75 -
 include/ajax_calendar_zoom.php                     |   46 -
 include/ajax_create_menu.php                       |   15 -
 include/ajax_display_submenu.php                   |   98 -
 include/ajax_fiche_def_detail.php                  |   47 -
 include/ajax_gestion.php                           |  129 -
 include/ajax_get_profile.php                       |  137 -
 include/ajax_get_receipt.php                       |   65 -
 include/ajax_ledger_show.php                       |   35 -
 include/ajax_min_row.php                           |   48 -
 include/ajax_mod_document.php                      |   52 -
 include/ajax_mod_menu.php                          |   17 -
 include/ajax_mod_periode.php                       |  104 -
 include/ajax_mod_predf_op.php                      |   76 -
 include/ajax_mod_stock_repo.php                    |   80 -
 include/ajax_preference.php                        |  195 -
 include/ajax_search_action.php                     |   34 -
 include/ajax_search_add_tag.php                    |   45 -
 include/ajax_search_clear_tag.php                  |   38 -
 include/ajax_search_display_tag.php                |   40 -
 include/ajax_tag_detail.php                        |   51 -
 include/ajax_tag_list.php                          |   45 -
 include/ajax_tag_save.php                          |   11 -
 include/ajax_tag_select_search.php                 |   40 -
 include/ajax_update_payment.php                    |   32 -
 include/ajax_update_predef.php                     |   69 -
 include/ajax_view_action.php                       |   75 -
 include/ajax_view_mod_stock.php                    |   58 -
 include/anc_acc_balance.inc.php                    |    2 +-
 include/anc_acc_table.inc.php                      |    2 +-
 include/anc_balance_double.inc.php                 |    2 +-
 include/anc_balance_simple.inc.php                 |    2 +-
 include/anc_great_ledger.inc.php                   |    2 +-
 include/anc_group.inc.php                          |    6 +-
 include/anc_group_balance.inc.php                  |    2 +-
 include/anc_history.inc.php                        |    2 +-
 include/anc_key.inc.php                            |    2 +-
 include/anc_od.inc.php                             |   12 +-
 include/anc_pa.inc.php                             |    4 +-
 include/balance.inc.php                            |   18 +-
 include/balance_age.inc.php                        |    2 +-
 include/balance_card.inc.php                       |    2 +-
 include/balance_card_ageing.inc.php                |    4 +-
 include/bank.inc.php                               |    8 +-
 include/calendar.inc.php                           |    2 +-
 include/card_attr.inc.php                          |    2 +-
 include/cat_document.inc.php                       |    2 +-
 include/category_card.inc.php                      |    2 +-
 include/category_detail.inc.php                    |    2 +-
 include/category_followup.inc.php                  |    2 +-
 include/category_operation.inc.php                 |    2 +-
 include/cfgfiche.inc.php                           |   18 +-
 include/cfgledger.inc.php                          |   10 +-
 include/cfgplugin.inc.php                          |    2 +-
 include/cfgtags.inc.php                            |    4 +-
 include/class/class_acc_account.php                |  233 ++
 include/class/class_acc_account_ledger.php         |  657 ++++
 include/class/class_acc_balance.php                |  284 ++
 include/class/class_acc_bilan.php                  |  729 ++++
 include/{ => class}/class_acc_compute.php          |    0
 include/class/class_acc_ledger.php                 | 3958 ++++++++++++++++++++
 include/class/class_acc_ledger_fin.php             | 1143 ++++++
 include/class/class_acc_ledger_info.php            |  216 ++
 include/class/class_acc_ledger_purchase.php        | 1790 +++++++++
 include/class/class_acc_ledger_sold.php            | 1374 +++++++
 include/class/class_acc_operation.php              |  716 ++++
 include/class/class_acc_parm_code.php              |  182 +
 include/class/class_acc_payment.php                |  406 ++
 include/class/class_acc_reconciliation.php         |  532 +++
 include/class/class_acc_report.php                 |  456 +++
 include/{ => class}/class_acc_report_row.php       |    0
 include/class/class_acc_tva.php                    |  202 +
 include/class/class_admin.php                      |   58 +
 include/class/class_anc_acc_link.php               |   61 +
 include/class/class_anc_acc_list.php               |  545 +++
 include/class/class_anc_account.php                |  349 ++
 include/class/class_anc_balance_double.php         |  579 +++
 include/class/class_anc_balance_simple.php         |  311 ++
 include/class/class_anc_grandlivre.php             |  309 ++
 include/class/class_anc_group.php                  |  260 ++
 include/class/class_anc_group_operation.php        |  278 ++
 include/class/class_anc_key.php                    |  354 ++
 include/class/class_anc_listing.php                |  216 ++
 include/class/class_anc_operation.php              |  964 +++++
 include/class/class_anc_plan.php                   |  248 ++
 include/class/class_anc_print.php                  |  224 ++
 include/class/class_anc_table.php                  |  329 ++
 include/class/class_anticipation.php               |  452 +++
 include/class/class_balance_age.php                |  240 ++
 include/class/class_bank.php                       |   58 +
 include/{ => class}/class_calendar.php             |    0
 include/class/class_contact.php                    |  143 +
 include/class/class_customer.php                   |  187 +
 include/class/class_default_menu.php               |  153 +
 include/class/class_document.php                   | 1285 +++++++
 include/{ => class}/class_document_export.php      |    0
 include/class/class_document_modele.php            |  364 ++
 include/{ => class}/class_document_type.php        |    0
 include/class/class_dossier.php                    |  314 ++
 include/class/class_exercice.php                   |   77 +
 include/class/class_extension.php                  |  309 ++
 include/class/class_fiche.php                      | 1992 ++++++++++
 include/class/class_fiche_attr.php                 |  284 ++
 include/class/class_fiche_def.php                  |  816 ++++
 include/{ => class}/class_fiche_def_ref.php        |    0
 include/class/class_follow_up.php                  | 1840 +++++++++
 include/class/class_follow_up_detail.php           |  248 ++
 include/{ => class}/class_forecast.php             |    0
 include/{ => class}/class_forecast_cat.php         |    0
 include/{ => class}/class_forecast_item.php        |    0
 include/class/class_gestion_purchase.php           |  128 +
 include/class/class_gestion_sold.php               |  115 +
 include/{ => class}/class_gestion_table.php        |    0
 include/class/class_lettering.php                  |  760 ++++
 include/class/class_manager.php                    |   62 +
 include/class/class_menu_ref.php                   |   59 +
 include/{ => class}/class_own.php                  |    0
 include/class/class_periode.php                    |  575 +++
 include/class/class_pre_op_ach.php                 |  394 ++
 include/class/class_pre_op_advanced.php            |  289 ++
 include/class/class_pre_op_fin.php                 |  135 +
 include/class/class_pre_op_ods.php                 |  122 +
 include/class/class_pre_op_ven.php                 |  387 ++
 include/class/class_pre_operation.php              |  332 ++
 include/class/class_print_ledger.php               |  130 +
 include/class/class_print_ledger_detail.php        |  148 +
 include/class/class_print_ledger_detail_item.php   |  174 +
 include/class/class_print_ledger_fin.php           |  119 +
 include/class/class_print_ledger_misc.php          |   97 +
 include/class/class_print_ledger_simple.php        |  277 ++
 .../class_print_ledger_simple_without_vat.php      |  185 +
 include/class/class_profile_menu.php               |  280 ++
 include/class/class_stock.php                      |  342 ++
 include/class/class_stock_goods.php                |  272 ++
 include/class/class_supplier.php                   |   78 +
 include/class/class_tag.php                        |  115 +
 include/class/class_todo_list.php                  |  415 ++
 include/class/class_user.php                       | 1226 ++++++
 include/class_acc_account.php                      |  233 --
 include/class_acc_account_ledger.php               |  657 ----
 include/class_acc_balance.php                      |  284 --
 include/class_acc_bilan.php                        |  729 ----
 include/class_acc_ledger.php                       | 3958 --------------------
 include/class_acc_ledger_fin.php                   | 1143 ------
 include/class_acc_ledger_info.php                  |  216 --
 include/class_acc_ledger_purchase.php              | 1790 ---------
 include/class_acc_ledger_sold.php                  | 1374 -------
 include/class_acc_operation.php                    |  716 ----
 include/class_acc_parm_code.php                    |  182 -
 include/class_acc_payment.php                      |  406 --
 include/class_acc_reconciliation.php               |  532 ---
 include/class_acc_report.php                       |  456 ---
 include/class_acc_tva.php                          |  202 -
 include/class_admin.php                            |   58 -
 include/class_anc_acc_link.php                     |   61 -
 include/class_anc_acc_list.php                     |  545 ---
 include/class_anc_account.php                      |  349 --
 include/class_anc_balance_double.php               |  579 ---
 include/class_anc_balance_simple.php               |  311 --
 include/class_anc_grandlivre.php                   |  309 --
 include/class_anc_group.php                        |  260 --
 include/class_anc_group_operation.php              |  278 --
 include/class_anc_key.php                          |  354 --
 include/class_anc_key_sql.php                      |  159 -
 include/class_anc_listing.php                      |  216 --
 include/class_anc_operation.php                    |  964 -----
 include/class_anc_plan.php                         |  248 --
 include/class_anc_print.php                        |  224 --
 include/class_anc_table.php                        |  329 --
 include/class_anticipation.php                     |  452 ---
 include/class_balance_age.php                      |  240 --
 include/class_bank.php                             |   58 -
 include/class_contact.php                          |  143 -
 include/class_customer.php                         |  187 -
 include/class_database.php                         | 1051 ------
 include/class_default_menu.php                     |  153 -
 include/class_default_menu_sql.php                 |   57 -
 include/class_document.php                         | 1285 -------
 include/class_document_modele.php                  |  364 --
 include/class_dossier.php                          |  314 --
 include/class_exercice.php                         |   77 -
 include/class_extension.php                        |  309 --
 include/class_fiche.php                            | 1992 ----------
 include/class_fiche_attr.php                       |  284 --
 include/class_fiche_def.php                        |  816 ----
 include/class_follow_up.php                        | 1840 ---------
 include/class_follow_up_detail.php                 |  248 --
 include/class_gestion_purchase.php                 |  128 -
 include/class_gestion_sold.php                     |  115 -
 include/class_html_input.php                       |  929 -----
 include/class_iaction.php                          |   61 -
 include/class_ianccard.php                         |  200 -
 include/class_ibutton.php                          |  118 -
 include/class_icard.php                            |  394 --
 include/class_icheckbox.php                        |   74 -
 include/class_iconcerned.php                       |   80 -
 include/class_idate.php                            |   71 -
 include/class_ifile.php                            |   46 -
 include/class_ihidden.php                          |   42 -
 include/class_impress.php                          |  293 --
 include/class_inum.php                             |  111 -
 include/class_iperiod.php                          |  171 -
 include/class_ipopup.php                           |  191 -
 include/class_iposte.php                           |  203 -
 include/class_iradio.php                           |   73 -
 include/class_irelated_action.php                  |   73 -
 include/class_iselect.php                          |   76 -
 include/class_ispan.php                            |   53 -
 include/class_itext.php                            |   98 -
 include/class_itextarea.php                        |   61 -
 include/class_itva_popup.php                       |  177 -
 include/class_jrn_def_sql.php                      |  408 --
 include/class_lettering.php                        |  760 ----
 include/class_manager.php                          |   62 -
 include/class_menu_ref.php                         |   59 -
 include/class_menu_ref_sql.php                     |   66 -
 include/class_periode.php                          |  575 ---
 include/class_pre_op_ach.php                       |  394 --
 include/class_pre_op_advanced.php                  |  289 --
 include/class_pre_op_fin.php                       |  135 -
 include/class_pre_op_ods.php                       |  122 -
 include/class_pre_op_ven.php                       |  387 --
 include/class_pre_operation.php                    |  332 --
 include/class_print_ledger.php                     |  130 -
 include/class_print_ledger_detail.php              |  148 -
 include/class_print_ledger_detail_item.php         |  174 -
 include/class_print_ledger_fin.php                 |  119 -
 include/class_print_ledger_misc.php                |   97 -
 include/class_print_ledger_simple.php              |  277 --
 include/class_print_ledger_simple_without_vat.php  |  185 -
 include/class_profile_menu.php                     |  280 --
 include/class_profile_menu_sql.php                 |   76 -
 include/class_profile_sql.php                      |   72 -
 include/class_sendmail.php                         |  160 -
 include/class_stock.php                            |  342 --
 include/class_stock_goods.php                      |  272 --
 include/class_stock_goods_sql.php                  |  120 -
 include/class_stock_sql.php                        |   63 -
 include/class_supplier.php                         |   78 -
 include/class_tag.php                              |  115 -
 include/class_tag_sql.php                          |   54 -
 include/class_todo_list.php                        |  415 --
 include/class_tool_uos.php                         |  107 -
 include/class_user.php                             | 1226 ------
 include/company.inc.php                            |    2 +-
 include/compta_ach.inc.php                         |    8 +-
 include/compta_fin.inc.php                         |    4 +-
 include/compta_fin_rec.inc.php                     |    2 +-
 include/compta_fin_saldo.inc.php                   |    2 +-
 include/compta_ods.inc.php                         |   14 +-
 include/compta_ven.inc.php                         |   12 +-
 include/config_file.php                            |    6 +-
 include/contact.inc.php                            |   10 +-
 include/customer.inc.php                           |   10 +-
 include/dashboard.inc.php                          |   24 +-
 include/database/class_anc_key_sql.php             |  159 +
 include/database/class_default_menu_sql.php        |   57 +
 include/database/class_jrn_def_sql.php             |  408 ++
 include/database/class_menu_ref_sql.php            |   66 +
 include/{ => database}/class_noalyss_sql.php       |    0
 include/database/class_profile_menu_sql.php        |   76 +
 include/database/class_profile_sql.php             |   72 +
 include/database/class_stock_goods_sql.php         |  120 +
 include/database/class_stock_sql.php               |   63 +
 include/database/class_tag_sql.php                 |   54 +
 include/default_menu.inc.php                       |    2 +-
 include/document_modele.inc.php                    |    8 +-
 include/dossier.inc.php                            |   10 +-
 include/export/export_anc_acc_list_csv.php         |   36 +
 include/export/export_anc_balance_double_csv.php   |   40 +
 include/export/export_anc_balance_double_pdf.php   |   37 +
 include/export/export_anc_balance_group_csv.php    |   35 +
 include/export/export_anc_balance_simple_csv.php   |   36 +
 include/export/export_anc_balance_simple_pdf.php   |   35 +
 include/export/export_anc_grandlivre_csv.php       |   37 +
 include/export/export_anc_list_csv.php             |   37 +
 include/export/export_anc_receipt_pdf.php          |   40 +
 include/export/export_anc_table_csv.php            |   34 +
 include/export/export_balance_age_csv.php          |   88 +
 include/export/export_balance_csv.php              |  103 +
 include/export/export_balance_pdf.php              |  284 ++
 include/export/export_bilan_oth.php                |   61 +
 include/export/export_fiche_balance_csv.php        |  200 +
 include/export/export_fiche_balance_pdf.php        |  317 ++
 include/export/export_fiche_csv.php                |   89 +
 include/export/export_fiche_detail_csv.php         |  163 +
 include/export/export_fiche_detail_pdf.php         |  231 ++
 include/export/export_fiche_pdf.php                |  232 ++
 include/export/export_follow_up_csv.php            |   42 +
 include/export/export_form_csv.php                 |  105 +
 include/export/export_form_pdf.php                 |  130 +
 include/export/export_gl_csv.php                   |  214 ++
 include/export/export_gl_pdf.php                   |  239 ++
 include/{ => export}/export_histo_csv.php          |    0
 include/export/export_ledger_csv.php               |  284 ++
 include/export/export_ledger_pdf.php               |   79 +
 include/export/export_poste_detail_csv.php         |  194 +
 include/export/export_poste_detail_pdf.php         |  241 ++
 include/export/export_rec_csv.php                  |   39 +
 include/export/export_reportinit_csv.php           |   56 +
 include/export/export_security_pdf.php             |  178 +
 include/export/export_stock_histo_csv.php          |   63 +
 include/export/export_stock_resume_list.php        |   91 +
 include/export_anc_acc_list_csv.php                |   36 -
 include/export_anc_balance_double_csv.php          |   40 -
 include/export_anc_balance_double_pdf.php          |   37 -
 include/export_anc_balance_group_csv.php           |   35 -
 include/export_anc_balance_simple_csv.php          |   36 -
 include/export_anc_balance_simple_pdf.php          |   35 -
 include/export_anc_grandlivre_csv.php              |   37 -
 include/export_anc_list_csv.php                    |   37 -
 include/export_anc_receipt_pdf.php                 |   40 -
 include/export_anc_table_csv.php                   |   34 -
 include/export_balance_age_csv.php                 |   88 -
 include/export_balance_csv.php                     |  103 -
 include/export_balance_pdf.php                     |  284 --
 include/export_bilan_oth.php                       |   61 -
 include/export_fiche_balance_csv.php               |  200 -
 include/export_fiche_balance_pdf.php               |  317 --
 include/export_fiche_csv.php                       |   89 -
 include/export_fiche_detail_csv.php                |  163 -
 include/export_fiche_detail_pdf.php                |  231 --
 include/export_fiche_pdf.php                       |  232 --
 include/export_follow_up_csv.php                   |   42 -
 include/export_form_csv.php                        |  105 -
 include/export_form_pdf.php                        |  130 -
 include/export_gl_csv.php                          |  214 --
 include/export_gl_pdf.php                          |  239 --
 include/export_ledger_csv.php                      |  284 --
 include/export_ledger_pdf.php                      |   79 -
 include/export_poste_detail_csv.php                |  194 -
 include/export_poste_detail_pdf.php                |  241 --
 include/export_rec_csv.php                         |   39 -
 include/export_reportinit_csv.php                  |   56 -
 include/export_security_pdf.php                    |  178 -
 include/export_stock_histo_csv.php                 |   63 -
 include/export_stock_resume_list.php               |   91 -
 include/ext/dummy/dummy.php                        |   12 +-
 include/extension_choice.inc.php                   |   16 +-
 include/extension_get.inc.php                      |   16 +-
 include/fiche.inc.php                              |   10 +-
 include/fiche_def.inc.php                          |    4 +-
 include/forecast.inc.php                           |    2 +-
 include/header_print.php                           |    6 +-
 include/history_operation.inc.php                  |    8 +-
 include/impress_bilan.inc.php                      |    6 +-
 include/impress_gl_comptes.inc.php                 |   14 +-
 include/impress_jrn.inc.php                        |   14 +-
 include/impress_poste.inc.php                      |   18 +-
 include/impress_rapport.inc.php                    |   12 +-
 include/impress_rec.inc.php                        |    4 +-
 include/lettering.account.inc.php                  |    2 +-
 include/lettering.card.inc.php                     |    4 +-
 include/lettering.gestion.inc.php                  |    2 +-
 include/lib/ac_common.php                          | 1254 +++++++
 include/lib/class_database.php                     | 1051 ++++++
 include/{ => lib}/class_filetosend.php             |    0
 include/lib/class_html_input.php                   |  929 +++++
 include/{ => lib}/class_html_table.php             |    0
 include/lib/class_iaction.php                      |   61 +
 include/lib/class_ianccard.php                     |  200 +
 include/lib/class_ibutton.php                      |  118 +
 include/lib/class_icard.php                        |  394 ++
 include/lib/class_icheckbox.php                    |   74 +
 include/lib/class_iconcerned.php                   |   80 +
 include/lib/class_idate.php                        |   71 +
 include/lib/class_ifile.php                        |   46 +
 include/lib/class_ihidden.php                      |   42 +
 include/lib/class_impress.php                      |  293 ++
 include/lib/class_inum.php                         |  111 +
 include/lib/class_iperiod.php                      |  171 +
 include/lib/class_ipopup.php                       |  191 +
 include/lib/class_iposte.php                       |  203 +
 include/lib/class_iradio.php                       |   73 +
 include/lib/class_irelated_action.php              |   73 +
 include/lib/class_iselect.php                      |   76 +
 include/lib/class_ispan.php                        |   53 +
 include/lib/class_itext.php                        |   98 +
 include/lib/class_itextarea.php                    |   61 +
 include/lib/class_itva_popup.php                   |  177 +
 include/{ => lib}/class_pdf.php                    |    0
 include/lib/class_sendmail.php                     |  160 +
 include/{ => lib}/class_sort_table.php             |    0
 include/lib/class_tool_uos.php                     |  107 +
 include/{ => lib}/class_zip_extended.php           |    0
 include/{ => lib}/function_javascript.php          |    0
 include/lib/user_common.php                        |  248 ++
 include/manager.inc.php                            |   16 +-
 include/menu.inc.php                               |    6 +-
 include/modele.inc.php                             |    8 +-
 include/opening.inc.php                            |    4 +-
 include/operation_ods_new.inc.php                  |    4 +-
 include/param_pcmn.inc.php                         |   12 +-
 include/param_sec.inc.php                          |   12 +-
 include/payment_middle.inc.php                     |    4 +-
 include/periode.inc.php                            |    4 +-
 include/poste.inc.php                              |    4 +-
 include/preod.inc.php                              |   12 +-
 include/profile.inc.php                            |    4 +-
 include/recover.php                                |    8 +-
 include/report.inc.php                             |   16 +-
 include/restore.inc.php                            |    4 +-
 include/search.inc.php                             |   10 +-
 include/stock_cfg.inc.php                          |    4 +-
 include/stock_histo.inc.php                        |    4 +-
 include/stock_inv.inc.php                          |    4 +-
 include/stock_inv_histo.inc.php                    |    2 +-
 include/stock_state.inc.php                        |    2 +-
 include/supplier.inc.php                           |   18 +-
 include/template/action_show.php                   |    2 +-
 include/template/dashboard.php                     |    2 +-
 include/template/document_mod_change.php           |    2 +-
 include/template/ledger_detail_ach.php             |    2 +-
 include/template/ledger_detail_fin.php             |    6 +-
 include/template/ledger_detail_misc.php            |   10 +-
 include/template/ledger_detail_top.php             |    2 +-
 include/template/ledger_detail_ven.php             |    2 +-
 include/template/letter_all.php                    |    4 +-
 include/template/letter_prop.php                   |    4 +-
 include/template/menu_detail.php                   |    4 +-
 include/tva.inc.php                                |    8 +-
 include/user.inc.php                               |    2 +-
 include/user_common.php                            |  248 --
 include/user_detail.inc.php                        |    8 +-
 include/user_menu.php                              |    6 +-
 include/verif_bilan.inc.php                        |    4 +-
 512 files changed, 48210 insertions(+), 48210 deletions(-)

diff --git a/html/admin/setup.php b/html/admin/setup.php
index bfd9ca1..d2d9d12 100644
--- a/html/admin/setup.php
+++ b/html/admin/setup.php
@@ -213,7 +213,7 @@ if ( ! 
file_exists('..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'include'.D
 // magic_quotes_sybase = Off
 // include_path
 require_once NOALYSS_INCLUDE.'/config_file.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
 
 if ( defined ("MULTI") && MULTI==1) { create_htaccess();}
 
@@ -386,8 +386,8 @@ if ( $Res==0) { ?>
 
 <?php exit(); }
 
-include_once('ac_common.php');
-require_once('class_dossier.php');
+include_once('lib/ac_common.php');
+require_once('class/class_dossier.php');
 
 // Memory setting
 //--
diff --git a/html/admin_repo.php b/html/admin_repo.php
index e2fa577..84ea1c3 100644
--- a/html/admin_repo.php
+++ b/html/admin_repo.php
@@ -22,12 +22,12 @@
  *        templates... Accessible only by the administrator
  */
 require_once '../include/constant.php';
-require_once("user_common.php");
-include_once("ac_common.php");
-require_once('class_database.php');
+require_once("lib/user_common.php");
+include_once("lib/ac_common.php");
+require_once('lib/class_database.php');
 include_once("user_menu.php");
 $rep=new Database();
-include_once ("class_user.php");
+include_once ("class/class_user.php");
 $User=new User($rep);
 $User->Check();
 
diff --git a/html/ajax.php b/html/ajax.php
index cab34f0..9fa9e81 100644
--- a/html/ajax.php
+++ b/html/ajax.php
@@ -13,12 +13,12 @@
  */
 if ( ! defined ('ALLOWED') ) define ('ALLOWED',1);
 require_once '../include/constant.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_user.php';
-require_once NOALYSS_INCLUDE.'/class_extension.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/class/class_user.php';
+require_once NOALYSS_INCLUDE.'/class/class_extension.php';
 if ( !isset ($_REQUEST['gDossier'])) exit();
 
-require_once NOALYSS_INCLUDE.'/class_own.php';
+require_once NOALYSS_INCLUDE.'/class/class_own.php';
 mb_internal_encoding("UTF-8");
 
 global $g_user,$cn,$g_parameter;
diff --git a/html/ajax_card.php b/html/ajax_card.php
index c33f2a9..dab6056 100644
--- a/html/ajax_card.php
+++ b/html/ajax_card.php
@@ -56,13 +56,13 @@
 if ( ! defined('ALLOWED')) define ('ALLOWED',1);
 
 require_once '../include/constant.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_fiche.php';
-require_once NOALYSS_INCLUDE.'/class_iradio.php';
-require_once NOALYSS_INCLUDE.'/function_javascript.php';
-require_once NOALYSS_INCLUDE.'/ac_common.php';
-require_once NOALYSS_INCLUDE.'/class_user.php';
-require_once NOALYSS_INCLUDE.'/class_fiche_attr.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/class/class_fiche.php';
+require_once NOALYSS_INCLUDE.'/lib/class_iradio.php';
+require_once NOALYSS_INCLUDE.'/lib/function_javascript.php';
+require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
+require_once NOALYSS_INCLUDE.'/class/class_user.php';
+require_once NOALYSS_INCLUDE.'/class/class_fiche_attr.php';
 
 mb_internal_encoding("UTF-8");
 
@@ -356,7 +356,7 @@ case 'sc':
      *
      *----------------------------------------------------------------------*/
 case 'fs':
-    require_once NOALYSS_INCLUDE.'/class_acc_ledger.php';
+    require_once NOALYSS_INCLUDE.'/class/class_acc_ledger.php';
     $r=HtmlInput::title_box(_("Détail fiche"), 'search_card');
     $r.='<form method="GET" 
onsubmit="this.ctl=\'ipop_card\';search_get_card(this);return false;">';
     $q=new IText('query');
@@ -434,14 +434,14 @@ case 'fs':
     $html=$r;
     break;
     case 'action_add_concerned_card':
-        require_once NOALYSS_INCLUDE.'/ajax_add_concerned_card.php';
+        require_once NOALYSS_INCLUDE.'/ajax/ajax_add_concerned_card.php';
         return;
     break;
     case 'action_save_concerned':
-        require 'ajax_action_save_concerned.php';
+        require 'ajax/ajax_action_save_concerned.php';
         return;
     case 'action_remove_concerned':
-        require 'ajax_action_remove_concerned.php';
+        require 'ajax/ajax_action_remove_concerned.php';
         return;
 case 'ac':
     if ( $g_user->check_action(FICCAT)==1 )
diff --git a/html/ajax_history.php b/html/ajax_history.php
index 0e77920..0a84cdf 100644
--- a/html/ajax_history.php
+++ b/html/ajax_history.php
@@ -26,13 +26,13 @@
 if ( ! defined('ALLOWED')) define ('ALLOWED',1);
 
 require_once '../include/constant.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_user.php';
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-require_once NOALYSS_INCLUDE.'/class_periode.php';
-require_once NOALYSS_INCLUDE.'/class_html_input.php';
-require_once NOALYSS_INCLUDE.'/class_acc_account.php';
-require_once NOALYSS_INCLUDE.'/class_exercice.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/class/class_user.php';
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+require_once NOALYSS_INCLUDE.'/class/class_periode.php';
+require_once NOALYSS_INCLUDE.'/lib/class_html_input.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_account.php';
+require_once NOALYSS_INCLUDE.'/class/class_exercice.php';
 $div=$_REQUEST['div'];
 mb_internal_encoding("UTF-8");
 
diff --git a/html/ajax_ledger.php b/html/ajax_ledger.php
index 842b676..aaa5f31 100644
--- a/html/ajax_ledger.php
+++ b/html/ajax_ledger.php
@@ -31,16 +31,16 @@
 if ( ! defined('ALLOWED')) define ('ALLOWED',1);
 
 require_once '../include/constant.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_user.php';
-require_once NOALYSS_INCLUDE.'/class_acc_operation.php';
-require_once NOALYSS_INCLUDE.'/class_acc_ledger.php';
-require_once NOALYSS_INCLUDE.'/class_fiche.php';
-require_once NOALYSS_INCLUDE.'/class_acc_reconciliation.php';
-require_once NOALYSS_INCLUDE.'/class_anc_operation.php';
-require_once NOALYSS_INCLUDE.'/class_idate.php';
-require_once NOALYSS_INCLUDE.'/class_own.php';
-require_once NOALYSS_INCLUDE.'/class_iconcerned.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/class/class_user.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_operation.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_ledger.php';
+require_once NOALYSS_INCLUDE.'/class/class_fiche.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_reconciliation.php';
+require_once NOALYSS_INCLUDE.'/class/class_anc_operation.php';
+require_once NOALYSS_INCLUDE.'/lib/class_idate.php';
+require_once NOALYSS_INCLUDE.'/class/class_own.php';
+require_once NOALYSS_INCLUDE.'/lib/class_iconcerned.php';
 /**
  * Check if we receive the needed data (jr_id...)
  */
diff --git a/html/ajax_misc.php b/html/ajax_misc.php
index f30f470..69c578c 100644
--- a/html/ajax_misc.php
+++ b/html/ajax_misc.php
@@ -37,12 +37,12 @@
 if ( ! defined('ALLOWED')) define ('ALLOWED',1);
 
 require_once '../include/constant.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once  NOALYSS_INCLUDE.'/class_fiche.php';
-require_once NOALYSS_INCLUDE.'/class_iradio.php';
-require_once NOALYSS_INCLUDE.'/function_javascript.php';
-require_once NOALYSS_INCLUDE.'/ac_common.php';
-require_once  NOALYSS_INCLUDE.'/class_user.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once  NOALYSS_INCLUDE.'/class/class_fiche.php';
+require_once NOALYSS_INCLUDE.'/lib/class_iradio.php';
+require_once NOALYSS_INCLUDE.'/lib/function_javascript.php';
+require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
+require_once  NOALYSS_INCLUDE.'/class/class_user.php';
 mb_internal_encoding("UTF-8");
 
 $var = array('gDossier', 'op');
@@ -102,7 +102,7 @@ if ( LOGINPUT)
 switch ($op)
 {
         case 'pcmn_update':
-            require 'ajax_pcmn_update.php';
+            require 'ajax/ajax_pcmn_update.php';
             return;
        case "remove_anc":
                if ($g_user->check_module('ANCODS') == 0)
@@ -122,7 +122,7 @@ switch ($op)
        //--------------------------------------------------
        // get the last date of a ledger
        case 'lastdate':
-               require_once NOALYSS_INCLUDE.'/class_acc_ledger_fin.php';
+               require_once NOALYSS_INCLUDE.'/class/class_acc_ledger_fin.php';
                $ledger = new Acc_Ledger_Fin($cn, $_GET['p_jrn']);
                $html = $ledger->get_last_date();
                $html = escape_xml($html);
@@ -137,7 +137,7 @@ EOF;
 
                break;
        case 'bkname':
-               require_once NOALYSS_INCLUDE.'/class_acc_ledger_fin.php';
+               require_once NOALYSS_INCLUDE.'/class/class_acc_ledger_fin.php';
                $ledger = new Acc_Ledger_Fin($cn, $_GET['p_jrn']);
                $html = $ledger->get_bank_name();
                $html = escape_xml($html);
@@ -152,7 +152,7 @@ EOF;
                break;
        // display new calendar
        case 'cal':
-               require_once NOALYSS_INCLUDE.'/class_calendar.php';
+               require_once NOALYSS_INCLUDE.'/class/class_calendar.php';
                /* others report */
                $cal = new Calendar();
                $cal->set_periode($per);
@@ -170,7 +170,7 @@ EOF;
                break;
        /* rem a cat of document */
        case 'rem_cat_doc':
-               require_once NOALYSS_INCLUDE.'/class_document_type.php';
+               require_once NOALYSS_INCLUDE.'/class/class_document_type.php';
                // if user can not return error message
                 $message="";
                if ($g_user->check_action(PARCATDOC) == 0)
@@ -309,7 +309,7 @@ EOF;
         * display the lettering
         */
        case 'dl':
-               require_once NOALYSS_INCLUDE.'/class_lettering.php';
+               require_once NOALYSS_INCLUDE.'/class/class_lettering.php';
                $exercice = $g_user->get_exercice();
                if ($g_user->check_module("LETCARD") == 0 && 
$g_user->check_module("LETACC") == 0)
                        exit();
@@ -516,43 +516,43 @@ EOF;
 EOF;
                break;
        case 'mod_doc':
-               require_once NOALYSS_INCLUDE.'/ajax_mod_document.php';
+               require_once NOALYSS_INCLUDE.'/ajax/ajax_mod_document.php';
                break;
        case 'input_per':
-               require_once NOALYSS_INCLUDE.'/ajax_mod_periode.php';
+               require_once NOALYSS_INCLUDE.'/ajax/ajax_mod_periode.php';
                break;
        case 'save_per':
-               require_once NOALYSS_INCLUDE.'/ajax_mod_periode.php';
+               require_once NOALYSS_INCLUDE.'/ajax/ajax_mod_periode.php';
                break;
        case 'mod_predf':
-               require_once NOALYSS_INCLUDE.'/ajax_mod_predf_op.php';
+               require_once NOALYSS_INCLUDE.'/ajax/ajax_mod_predf_op.php';
                break;
        case 'save_predf':
-               require_once NOALYSS_INCLUDE.'/ajax_save_predf_op.php';
+               require_once NOALYSS_INCLUDE.'/ajax/ajax_save_predf_op.php';
                break;
        case 'search_op':
                require_once NOALYSS_INCLUDE.'/search.inc.php';
                break;
        case 'search_action':
-               require_once NOALYSS_INCLUDE.'/ajax_search_action.php';
+               require_once NOALYSS_INCLUDE.'/ajax/ajax_search_action.php';
                break;
        case 'display_profile':
-               require_once NOALYSS_INCLUDE.'/ajax_get_profile.php';
+               require_once NOALYSS_INCLUDE.'/ajax/ajax_get_profile.php';
                break;
        case 'det_menu':
-               require_once NOALYSS_INCLUDE.'/ajax_get_menu_detail.php';
+               require_once NOALYSS_INCLUDE.'/ajax/ajax_get_menu_detail.php';
                break;
        case 'add_menu':
-               require_once NOALYSS_INCLUDE.'/ajax_add_menu.php';
+               require_once NOALYSS_INCLUDE.'/ajax/ajax_add_menu.php';
                break;
         case 'display_submenu':
-                require_once NOALYSS_INCLUDE.'/ajax_display_submenu.php';
+                require_once NOALYSS_INCLUDE.'/ajax/ajax_display_submenu.php';
                 break;
         case 'remove_submenu':
-                require_once NOALYSS_INCLUDE.'/ajax_remove_submenu.php';
+                require_once NOALYSS_INCLUDE.'/ajax/ajax_remove_submenu.php';
                 break;
        case 'cardsearch':
-               require_once NOALYSS_INCLUDE.'/ajax_boxcard_search.php';
+               require_once NOALYSS_INCLUDE.'/ajax/ajax_boxcard_search.php';
                break;
        case 'add_plugin':
                $me_code = new IText('me_code');
@@ -561,7 +561,7 @@ EOF;
                $me_description = new IText("me_description");
                $me_parameter = new IText("me_parameter");
                $new = true;
-               require_once NOALYSS_INCLUDE.'/ajax_plugin_detail.php';
+               require_once NOALYSS_INCLUDE.'/ajax/ajax_plugin_detail.php';
                break;
        case 'mod_plugin':
                $m = $cn->get_array("select 
me_code,me_file,me_menu,me_description,me_parameter
@@ -578,71 +578,71 @@ EOF;
                $me_description = new IText("me_description", $m[0] 
['me_description']);
                $me_parameter = new IText("me_parameter", $m[0] 
['me_parameter']);
                $new = false;
-               require_once NOALYSS_INCLUDE.'/ajax_plugin_detail.php';
+               require_once NOALYSS_INCLUDE.'/ajax/ajax_plugin_detail.php';
                break;
        case 'saldo':
-               require_once NOALYSS_INCLUDE.'/ajax_bank_saldo.php';
+               require_once NOALYSS_INCLUDE.'/ajax/ajax_bank_saldo.php';
                break;
        case 'up_predef':
-               require_once NOALYSS_INCLUDE.'/ajax_update_predef.php';
+               require_once NOALYSS_INCLUDE.'/ajax/ajax_update_predef.php';
                break;
        case 'upd_receipt':
-               require_once NOALYSS_INCLUDE.'/ajax_get_receipt.php';
+               require_once NOALYSS_INCLUDE.'/ajax/ajax_get_receipt.php';
                break;
        case 'up_pay_method':
-               require_once NOALYSS_INCLUDE.'/ajax_update_payment.php';
+               require_once NOALYSS_INCLUDE.'/ajax/ajax_update_payment.php';
                break;
        case 'openancsearch':
        case 'resultancsearch':
-               require_once NOALYSS_INCLUDE.'/ajax_anc_search.php';
+               require_once NOALYSS_INCLUDE.'/ajax/ajax_anc_search.php';
                break;
        case 'autoanc':
-               require_once NOALYSS_INCLUDE.'/ajax_auto_anc_card.php';
+               require_once NOALYSS_INCLUDE.'/ajax/ajax_auto_anc_card.php';
                break;
        case 'create_menu';
-               require_once NOALYSS_INCLUDE.'/ajax_create_menu.php';
+               require_once NOALYSS_INCLUDE.'/ajax/ajax_create_menu.php';
                break;
        case 'modify_menu';
-               require_once NOALYSS_INCLUDE.'/ajax_mod_menu.php';
+               require_once NOALYSS_INCLUDE.'/ajax/ajax_mod_menu.php';
                break;
        case 'mod_stock_repo':
-               require_once NOALYSS_INCLUDE.'/ajax_mod_stock_repo.php';
+               require_once NOALYSS_INCLUDE.'/ajax/ajax_mod_stock_repo.php';
                break;
        case 'view_mod_stock':
-               require_once NOALYSS_INCLUDE.'/ajax_view_mod_stock.php';
+               require_once NOALYSS_INCLUDE.'/ajax/ajax_view_mod_stock.php';
                break;
        case 'fddetail':
-               require_once NOALYSS_INCLUDE.'/ajax_fiche_def_detail.php';
+               require_once NOALYSS_INCLUDE.'/ajax/ajax_fiche_def_detail.php';
                break;
        case 'vw_action':
-               require_once NOALYSS_INCLUDE.'/ajax_view_action.php';
+               require_once NOALYSS_INCLUDE.'/ajax/ajax_view_action.php';
                break;
        case 'minrow':
-               require_once NOALYSS_INCLUDE.'/ajax_min_row.php';
+               require_once NOALYSS_INCLUDE.'/ajax/ajax_min_row.php';
                break;
         case 'navigator':
-                require_once NOALYSS_INCLUDE.'/ajax_navigator.php';
+                require_once NOALYSS_INCLUDE.'/ajax/ajax_navigator.php';
                 break;
         case 'preference':
-                require_once NOALYSS_INCLUDE.'/ajax_preference.php';
+                require_once NOALYSS_INCLUDE.'/ajax/ajax_preference.php';
                 break;
         case 'bookmark':
-            require_once NOALYSS_INCLUDE.'/ajax_bookmark.php';
+            require_once NOALYSS_INCLUDE.'/ajax/ajax_bookmark.php';
             break;
         case 'tag_detail':
-            require_once NOALYSS_INCLUDE.'/ajax_tag_detail.php';
+            require_once NOALYSS_INCLUDE.'/ajax/ajax_tag_detail.php';
             break;
         case 'tag_save':
-            require_once NOALYSS_INCLUDE.'/ajax_tag_save.php';
+            require_once NOALYSS_INCLUDE.'/ajax/ajax_tag_save.php';
             break;
         case 'tag_list':
-            require_once NOALYSS_INCLUDE.'/ajax_tag_list.php';
+            require_once NOALYSS_INCLUDE.'/ajax/ajax_tag_list.php';
             break;
         case 'tag_add':
-            require_once NOALYSS_INCLUDE.'/ajax_tag_add_action.php';
+            require_once NOALYSS_INCLUDE.'/ajax/ajax_tag_add_action.php';
             break;
         case 'tag_remove':
-            require_once NOALYSS_INCLUDE.'/ajax_tag_remove_action.php';
+            require_once NOALYSS_INCLUDE.'/ajax/ajax_tag_remove_action.php';
             break;
         case 'tag_choose':
             require_once NOALYSS_INCLUDE.'/ajax_tag_choose.php';
@@ -651,19 +651,19 @@ EOF;
             require_once NOALYSS_INCLUDE.'/ajax_tag_choose.php';
             break;
        case 'search_display_tag':
-            require_once NOALYSS_INCLUDE.'/ajax_search_display_tag.php';
+            require_once NOALYSS_INCLUDE.'/ajax/ajax_search_display_tag.php';
             break;
         case 'search_add_tag':
-            require_once NOALYSS_INCLUDE.'/ajax_search_add_tag.php';
+            require_once NOALYSS_INCLUDE.'/ajax/ajax_search_add_tag.php';
             break;
         case 'search_clear_tag':
-            require_once NOALYSS_INCLUDE.'/ajax_search_clear_tag.php';
+            require_once NOALYSS_INCLUDE.'/ajax/ajax_search_clear_tag.php';
             break;
         case 'calendar_zoom':
-            require_once NOALYSS_INCLUDE.'/ajax_calendar_zoom.php';
+            require_once NOALYSS_INCLUDE.'/ajax/ajax_calendar_zoom.php';
             break;
         case 'ledger_show':
-            require_once NOALYSS_INCLUDE.'/ajax_ledger_show.php';
+            require_once NOALYSS_INCLUDE.'/ajax/ajax_ledger_show.php';
         case 'ledger_description':
             $ajrn=$cn->get_array('select jrn_def_name,jrn_def_description from 
jrn_def where jrn_def_id=$1',array($l));
             if ( count($ajrn)==1)
@@ -682,67 +682,67 @@ EOF;
             /*
              *  Show the available distribution keys for analytic 
              */
-            require_once NOALYSS_INCLUDE.'/ajax_anc_key_choice.php';
+            require_once NOALYSS_INCLUDE.'/ajax/ajax_anc_key_choice.php';
             break;
         case 'anc_key_compute':
             /* 
              * Show the activities computed with the selected distribution key 
              */
-            require_once NOALYSS_INCLUDE.'/ajax_anc_key_compute.php';
+            require_once NOALYSS_INCLUDE.'/ajax/ajax_anc_key_compute.php';
             break;
         case 'account_update':
             /**
              * update an accounting (from CFGPCMN)
              */
-            require_once NOALYSS_INCLUDE.'/ajax_account_update.php';
+            require_once NOALYSS_INCLUDE.'/ajax/ajax_account_update.php';
             break;
         // From admin, revoke the access to a folder from an
         // user
         case 'folder_remove':
-            require_once NOALYSS_INCLUDE.'/ajax_admin.php';
+            require_once NOALYSS_INCLUDE.'/ajax/ajax_admin.php';
             break;
         // From admin, display a list of folder to which the user has 
         // no access
         case 'folder_display':
-            require_once NOALYSS_INCLUDE.'/ajax_admin.php';
+            require_once NOALYSS_INCLUDE.'/ajax/ajax_admin.php';
             break;
         // From admin, grant the access to a folder to an
         // user
         case 'folder_add':
-            require_once NOALYSS_INCLUDE.'/ajax_admin.php';
+            require_once NOALYSS_INCLUDE.'/ajax/ajax_admin.php';
             break;
 
         // From admin, display info and propose to drop the folder
         case 'folder_drop':
-            require_once NOALYSS_INCLUDE.'/ajax_admin.php';
+            require_once NOALYSS_INCLUDE.'/ajax/ajax_admin.php';
             break;
 
         // From admin, display the information of a folder you can 
         // modify
         case 'folder_modify':
-            require_once NOALYSS_INCLUDE.'/ajax_admin.php';
+            require_once NOALYSS_INCLUDE.'/ajax/ajax_admin.php';
             break;
         // From admin, display info and propose to drop the template
         case 'modele_drop':
-            require_once NOALYSS_INCLUDE.'/ajax_admin.php';
+            require_once NOALYSS_INCLUDE.'/ajax/ajax_admin.php';
             break;
 
         // From admin, display the information of a template you can 
         // modify
         case 'modele_modify':
-            require_once NOALYSS_INCLUDE.'/ajax_admin.php';
+            require_once NOALYSS_INCLUDE.'/ajax/ajax_admin.php';
             break;
         // From dashboard, display detail about last operation 
         case 'action_show':
-            require_once NOALYSS_INCLUDE.'/ajax_gestion.php';
+            require_once NOALYSS_INCLUDE.'/ajax/ajax_gestion.php';
             break;
         // From dashboard, display form for a new event
         case 'action_add':
-            require_once NOALYSS_INCLUDE.'/ajax_gestion.php';
+            require_once NOALYSS_INCLUDE.'/ajax/ajax_gestion.php';
             break;
         // Save a event given in the short form
         case 'action_save':
-            require_once NOALYSS_INCLUDE.'/ajax_gestion.php';
+            require_once NOALYSS_INCLUDE.'/ajax/ajax_gestion.php';
             break;
        default:
                var_dump($_GET);
diff --git a/html/ajax_poste.php b/html/ajax_poste.php
index 13f0e1d..ea6f1b2 100644
--- a/html/ajax_poste.php
+++ b/html/ajax_poste.php
@@ -35,11 +35,11 @@
 if ( ! defined('ALLOWED')) define ('ALLOWED',1);
 
 require_once '../include/constant.php';
-require_once  NOALYSS_INCLUDE.'/ac_common.php';
-require_once NOALYSS_INCLUDE.'/class_acc_ledger.php';
-require_once  NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/function_javascript.php';
-require_once NOALYSS_INCLUDE.'/class_acc_account_ledger.php';
+require_once  NOALYSS_INCLUDE.'/lib/ac_common.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_ledger.php';
+require_once  NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/lib/function_javascript.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_account_ledger.php';
 mb_internal_encoding("UTF-8");
 
 extract($_REQUEST);
@@ -60,7 +60,7 @@ set_language();
 
 if ( $cont != 0 ) exit();
 $cn=new Database(dossier::id());
-require_once  NOALYSS_INCLUDE.'/class_user.php';
+require_once  NOALYSS_INCLUDE.'/class/class_user.php';
 global $g_user;
 $g_user=new User($cn);
 $g_user->Check();
diff --git a/html/ajax_todo_list.php b/html/ajax_todo_list.php
index e71f29d..2cc5027 100644
--- a/html/ajax_todo_list.php
+++ b/html/ajax_todo_list.php
@@ -35,10 +35,10 @@
  */
 define ('ALLOWED',1);
 require_once '../include/constant.php';
-require_once  NOALYSS_INCLUDE.'/class_dossier.php';
-require_once  NOALYSS_INCLUDE.'/class_todo_list.php';
-require_once  NOALYSS_INCLUDE.'/class_database.php';
-require_once  NOALYSS_INCLUDE.'/class_user.php';
+require_once  NOALYSS_INCLUDE.'/class/class_dossier.php';
+require_once  NOALYSS_INCLUDE.'/class/class_todo_list.php';
+require_once  NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once  NOALYSS_INCLUDE.'/class/class_user.php';
 mb_internal_encoding("UTF-8");
 
 $cn= Dossier::connect();
diff --git a/html/backup.php b/html/backup.php
index 127a5a0..6dc1e47 100644
--- a/html/backup.php
+++ b/html/backup.php
@@ -20,9 +20,9 @@
 // Copyright Author Dany De Bontridder address@hidden
 require_once '../include/constant.php';
 require_once("constant.php");
-require_once('class_database.php');
-require_once  ("class_user.php");
-require_once ('ac_common.php');
+require_once('lib/class_database.php');
+require_once  ("class/class_user.php");
+require_once ('lib/ac_common.php');
 
 $rep=new Database();
 $User=new User($rep);
diff --git a/html/compute.php b/html/compute.php
index 8e5d441..a98407f 100644
--- a/html/compute.php
+++ b/html/compute.php
@@ -31,11 +31,11 @@
  * Must return at least tva, htva and tvac
  */
 require_once '../include/constant.php';
-require_once  NOALYSS_INCLUDE.'/class_database.php';
-require_once  NOALYSS_INCLUDE.'/class_acc_compute.php';
-require_once  NOALYSS_INCLUDE.'/class_dossier.php';
-require_once  NOALYSS_INCLUDE.'/class_acc_tva.php';
-require_once  NOALYSS_INCLUDE.'/class_user.php';
+require_once  NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once  NOALYSS_INCLUDE.'/class/class_acc_compute.php';
+require_once  NOALYSS_INCLUDE.'/class/class_dossier.php';
+require_once  NOALYSS_INCLUDE.'/class/class_acc_tva.php';
+require_once  NOALYSS_INCLUDE.'/class/class_user.php';
 
 // Check if the needed field does exist
 extract ($_GET);
diff --git a/html/direct.php b/html/direct.php
index 12f0e80..36fed4b 100644
--- a/html/direct.php
+++ b/html/direct.php
@@ -19,8 +19,8 @@
  */
 
 require_once '../include/constant.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_user.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/class/class_user.php';
 
 $cn=new Database($_GET['gDossier']);
 global $g_user;
diff --git a/html/do.php b/html/do.php
index 6354d60..b305819 100644
--- a/html/do.php
+++ b/html/do.php
@@ -24,13 +24,13 @@ define('ALLOWED',1);
  * \brief Main file
  */
 require_once '../include/constant.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-require_once NOALYSS_INCLUDE.'/user_common.php';
-require_once NOALYSS_INCLUDE.'/ac_common.php';
-require_once NOALYSS_INCLUDE.'/function_javascript.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+require_once NOALYSS_INCLUDE.'/lib/user_common.php';
+require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
+require_once NOALYSS_INCLUDE.'/lib/function_javascript.php';
 require_once NOALYSS_INCLUDE.'/constant.security.php';
-require_once NOALYSS_INCLUDE.'/class_html_input.php';
+require_once NOALYSS_INCLUDE.'/lib/class_html_input.php';
 mb_internal_encoding("UTF-8");
 
 // if gDossier is not set redirect to form to choose a folder
diff --git a/html/export.php b/html/export.php
index 14038c3..1124fc3 100644
--- a/html/export.php
+++ b/html/export.php
@@ -27,8 +27,8 @@
 define ('ALLOWED',1);
 require_once '../include/constant.php';
 global $g_user,$cn,$g_parameter;
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_user.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/class/class_user.php';
 $gDossier=dossier::id();
 $cn=new Database($gDossier);
 mb_internal_encoding("UTF-8");
@@ -52,5 +52,5 @@ if ($action == null )
  if ( $prfile == "") {
      die (_('Export impossible'));
  }
- require_once $prfile;
+ require_once NOALYSS_INCLUDE."/export/$prfile";
  ?>
\ No newline at end of file
diff --git a/html/extension.raw.php b/html/extension.raw.php
index 7000f14..5ff4576 100644
--- a/html/extension.raw.php
+++ b/html/extension.raw.php
@@ -24,14 +24,14 @@
  * the security. Load several javascript files
  */
 require_once '../include/constant.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-require_once NOALYSS_INCLUDE.'/ac_common.php';
-require_once NOALYSS_INCLUDE.'/function_javascript.php';
-require_once NOALYSS_INCLUDE.'/class_extension.php';
-require_once  NOALYSS_INCLUDE.'/class_html_input.php';
-require_once NOALYSS_INCLUDE.'/class_iselect.php';
-require_once  NOALYSS_INCLUDE.'/class_user.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
+require_once NOALYSS_INCLUDE.'/lib/function_javascript.php';
+require_once NOALYSS_INCLUDE.'/class/class_extension.php';
+require_once  NOALYSS_INCLUDE.'/lib/class_html_input.php';
+require_once NOALYSS_INCLUDE.'/lib/class_iselect.php';
+require_once  NOALYSS_INCLUDE.'/class/class_user.php';
 
 global $g_user,$cn,$g_parameter;
 
diff --git a/html/fid.php b/html/fid.php
index 7284bb2..3e02cdf 100644
--- a/html/fid.php
+++ b/html/fid.php
@@ -33,13 +33,13 @@
    *\note if the j is -1 then all the card are shown
  */
 require_once '../include/constant.php';
-require_once NOALYSS_INCLUDE.'/class_own.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/user_common.php';
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
+require_once NOALYSS_INCLUDE.'/class/class_own.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/lib/user_common.php';
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
 $gDossier=dossier::id();
 
-require_once('class_user.php');
+require_once('class/class_user.php');
 
 $cn=new Database(dossier::id());
 global $g_user;
diff --git a/html/fid_card.php b/html/fid_card.php
index 8af3a64..d9842fc 100644
--- a/html/fid_card.php
+++ b/html/fid_card.php
@@ -26,8 +26,8 @@
  */
 
 require_once '../include/constant.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
 /*!\brief
  *  Received parameters are
  *   - j for the ledger
@@ -48,7 +48,7 @@ $cn=new Database(dossier::id());
 $d=$_REQUEST['e'];
 $filter_card='';
 
-require_once('class_user.php');
+require_once('class/class_user.php');
 global $g_user;
 $g_user=new User($cn);
 $g_user->check();
diff --git a/html/index.php b/html/index.php
index d651291..5eb72b2 100644
--- a/html/index.php
+++ b/html/index.php
@@ -45,7 +45,7 @@
  * <li>Dans le répertoire include: Les noms de fichier ajax* correspondent aux 
fichiers appelé par une fonction javascript en ajax, 
  * normalement le nom de fichier est basé sur le nom de la fonction javascript
  * exemple pour la fonction javascript anc_key_choice le fichier correspondant 
est
- * ajax_anc_key_choice.php
+ * ajax/ajax_anc_key_choice.php
  * <li>Dans le répertoire include/template: les fichiers de
  * présentation HTML </li>
  * <li>Utiliser sql/upgrade.sql comme fichier temporaire pour modifier la base 
de données, en général
@@ -96,7 +96,7 @@
  * class_*.php if it is related to a class.</li>
  * <li>In the folder include, files starting with ajax are executed by ajax 
call, usually, the file name is
  * based on the javascript function, example for the javascript function 
anc_key_choice the corresponding file is
- * ajax_anc_key_choice.php
+ * ajax/ajax_anc_key_choice.php
  * 
  * <li>In the folder include/template: files for the HTML presentation
  * </li>
@@ -208,7 +208,7 @@ background-repeat: repeat-x repeat-y;
 $my_domain="";
 require_once '../include/constant.php';
 require_once '../include/config.inc.php';
-require_once NOALYSS_INCLUDE.'/ac_common.php';
+require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
 
 if ( strlen(domaine) > 0 )
 {
diff --git a/html/login.php b/html/login.php
index 5b8725f..7f08154 100644
--- a/html/login.php
+++ b/html/login.php
@@ -19,13 +19,13 @@
 // Copyright Author Dany De Bontridder address@hidden
 require_once '../include/constant.php';
 
-include_once NOALYSS_INCLUDE.'/ac_common.php';
+include_once NOALYSS_INCLUDE.'/lib/ac_common.php';
 
 /*! \file
  * \brief Login page
  */
 
-require_once NOALYSS_INCLUDE.'/class_database.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
 // Verif if User and Pass match DB
     // if no, then redirect to the login page
 $rep=new Database();
@@ -53,7 +53,7 @@ if (  isset ($_POST["p_user"] ) )
                echo "<META HTTP-EQUIV=\"REFRESH\" 
content=\"0;url=admin/setup.php\">";
                exit();
        }
-    include_once NOALYSS_INCLUDE."/class_user.php";
+    include_once NOALYSS_INCLUDE."/class/class_user.php";
     $User=new User($rep);
     $User->Check(false,'LOGIN');
     if ($g_captcha == true)
@@ -92,7 +92,7 @@ else
 
       }
 
-    include_once ("class_user.php");
+    include_once ("class/class_user.php");
 
     $User=new User($rep);
     $User->Check();
diff --git a/html/logout.php b/html/logout.php
index de566e0..64db90d 100644
--- a/html/logout.php
+++ b/html/logout.php
@@ -21,8 +21,8 @@
  * \brief Logout
  */
 require_once '../include/constant.php';
-require_once ("ac_common.php");
-require_once('class_database.php');
+require_once ("lib/ac_common.php");
+require_once('lib/class_database.php');
 
 html_page_start("classic");
 
diff --git a/html/not_implemented.php b/html/not_implemented.php
index 9b7c1d1..0c2656c 100644
--- a/html/not_implemented.php
+++ b/html/not_implemented.php
@@ -17,7 +17,7 @@
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 // Copyright Author Dany De Bontridder address@hidden
-include_once("ac_common.php");
+include_once("lib/ac_common.php");
 html_page_start();
 echo '<H1 class="info"> Not Implemented</H1>';
 html_page_stop();
diff --git a/html/popup.php b/html/popup.php
index 727efb7..d756cd5 100644
--- a/html/popup.php
+++ b/html/popup.php
@@ -18,13 +18,13 @@
  */
 
 require_once '../include/constant.php';
-require_once NOALYSS_INCLUDE.'/ac_common.php';
-require_once NOALYSS_INCLUDE.'/function_javascript.php';
-require_once NOALYSS_INCLUDE.'/class_html_input.php';
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_user.php';
-require_once NOALYSS_INCLUDE.'/class_periode.php';
+require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
+require_once NOALYSS_INCLUDE.'/lib/function_javascript.php';
+require_once NOALYSS_INCLUDE.'/lib/class_html_input.php';
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/class/class_user.php';
+require_once NOALYSS_INCLUDE.'/class/class_periode.php';
 
 
 html_page_start($_SESSION['g_theme']);
diff --git a/html/recherche.php b/html/recherche.php
index cd59fa2..30f8490 100644
--- a/html/recherche.php
+++ b/html/recherche.php
@@ -21,9 +21,9 @@
  * \brief Search module
  */
 require_once '../include/constant.php';
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-include_once NOALYSS_INCLUDE.'/ac_common.php';
-require_once NOALYSS_INCLUDE.'/class_acc_ledger.php';
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+include_once NOALYSS_INCLUDE.'/lib/ac_common.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_ledger.php';
 
 html_page_start($_SESSION['g_theme']);
 
@@ -32,11 +32,11 @@ load_all_script();
 
 $gDossier=dossier::id();
 
-require_once NOALYSS_INCLUDE.'/class_database.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
 /* Admin. Dossier */
 
 $cn=new Database($gDossier);
-include_once NOALYSS_INCLUDE.'/class_user.php';
+include_once NOALYSS_INCLUDE.'/class/class_user.php';
 
 global $g_user;
 $g_user=new User($cn);
diff --git a/html/show_document.php b/html/show_document.php
index 67ac28b..728333d 100644
--- a/html/show_document.php
+++ b/html/show_document.php
@@ -23,15 +23,15 @@
  * \brief retrieve a document
  */
 require_once '../include/constant.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/ac_common.php';
-require_once NOALYSS_INCLUDE.'/class_document.php';
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
+require_once NOALYSS_INCLUDE.'/class/class_document.php';
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
 $gDossier = dossier::id();
 $cn = new Database($gDossier);
 $action = (isset($_REQUEST['a'])) ? $_REQUEST['a'] : 'sh';
 
-require_once  NOALYSS_INCLUDE.'/class_user.php';
+require_once  NOALYSS_INCLUDE.'/class/class_user.php';
 global $g_user;
 $g_user = new User($cn);
 $g_user->Check();
diff --git a/html/show_document_modele.php b/html/show_document_modele.php
index c641cb6..0c993d3 100644
--- a/html/show_document_modele.php
+++ b/html/show_document_modele.php
@@ -22,15 +22,15 @@
  * \brief send the document template
  */
 require_once '../include/constant.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/ac_common.php';
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
 
 $gDossier=dossier::id();
 $cn=new Database($gDossier);
 
 
-require_once NOALYSS_INCLUDE.'/class_user.php';
+require_once NOALYSS_INCLUDE.'/class/class_user.php';
 global $g_user;
 $g_user=new User($cn);
 $g_user->Check();
diff --git a/html/show_pj.php b/html/show_pj.php
index 7563e82..7811e3f 100644
--- a/html/show_pj.php
+++ b/html/show_pj.php
@@ -22,8 +22,8 @@
  * \brief show an attach of an operation
  */
 require_once '../include/constant.php';
-include_once NOALYSS_INCLUDE.'/ac_common.php';
-require_once  NOALYSS_INCLUDE.'/class_dossier.php';
+include_once NOALYSS_INCLUDE.'/lib/ac_common.php';
+require_once  NOALYSS_INCLUDE.'/class/class_dossier.php';
 $gDossier=dossier::id();
 
 if ( !isset ($_GET['jrn'] ) ||
@@ -32,7 +32,7 @@ if ( !isset ($_GET['jrn'] ) ||
     echo_error("Missing parameters");
 }
 
-require_once NOALYSS_INCLUDE.'/class_database.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
 set_language();
 
 $jr_grpt_id=$_GET['jr_grpt_id'];
@@ -40,7 +40,7 @@ $jr_grpt_id=$_GET['jr_grpt_id'];
 $cn=new Database($gDossier);
 
 
-require_once NOALYSS_INCLUDE.'/class_user.php';
+require_once NOALYSS_INCLUDE.'/class/class_user.php';
 global $g_user;
 $g_user=new User($cn);
 $g_user->Check();
diff --git a/html/test.php b/html/test.php
index 2dc2fb5..e0f99eb 100644
--- a/html/test.php
+++ b/html/test.php
@@ -30,12 +30,12 @@
 
 
 include_once("../include/constant.php");
-include_once("ac_common.php");
-require_once('class_database.php');
-require_once ('class_dossier.php');
-require_once('class_html_input.php');
-require_once ('function_javascript.php');
-require_once 'class_user.php';
+include_once("lib/ac_common.php");
+require_once('lib/class_database.php');
+require_once ('class/class_dossier.php');
+require_once('lib/class_html_input.php');
+require_once ('lib/function_javascript.php');
+require_once 'class/class_user.php';
 load_all_script();
 $gDossier=HtmlInput::default_value_get('gDossier', -1);
 if ($gDossier==-1)
diff --git a/html/user_login.php b/html/user_login.php
index af9808f..162f8cf 100644
--- a/html/user_login.php
+++ b/html/user_login.php
@@ -22,14 +22,14 @@
 
 // Copyright Author Dany De Bontridder address@hidden
 require_once '../include/constant.php';
-include_once NOALYSS_INCLUDE.'/ac_common.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_itext.php';
-require_once NOALYSS_INCLUDE.'/function_javascript.php';
+include_once NOALYSS_INCLUDE.'/lib/ac_common.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/lib/class_itext.php';
+require_once NOALYSS_INCLUDE.'/lib/function_javascript.php';
 
 @html_page_start($_SESSION['g_theme']);
 $rep=new Database();
-include_once NOALYSS_INCLUDE.'/class_user.php';
+include_once NOALYSS_INCLUDE.'/class/class_user.php';
 $User=new User($rep);
 
 $User->Check();
diff --git a/include/ac_common.php b/include/ac_common.php
deleted file mode 100644
index 3b46a62..0000000
--- a/include/ac_common.php
+++ /dev/null
@@ -1,1254 +0,0 @@
-<?php
-
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/**
- * @file
- * @brief common utilities for a lot of procedure, classe
- */
-
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_periode.php';
-require_once NOALYSS_INCLUDE.'/class_html_input.php';
-require_once NOALYSS_INCLUDE.'/function_javascript.php';
-
-/**
- * \brief to protect again bad characters which can lead to a cross scripting 
attack
-  the string to be diplayed must be protected
- */
-
-function h($p_string)
-{
-    return htmlspecialchars($p_string);
-}
-
-function span($p_string, $p_extra='')
-{
-    return '<span ' . $p_extra . '>' . $p_string . '</span>';
-}
-
-function hi($p_string)
-{
-    return '<i>' . htmlspecialchars($p_string) . '</i>';
-}
-
-function hb($p_string)
-{
-    return '<b>' . htmlspecialchars($p_string) . '</b>';
-}
-
-function th($p_string, $p_extra='',$raw='')
-{
-    return '<th  ' . $p_extra . '>' . htmlspecialchars($p_string).$raw . 
'</th>';
-}
-
-function h2info($p_string)
-{
-    return '<h2 class="info">' . htmlspecialchars($p_string) . '</h2>';
-}
-
-function h2($p_string, $p_class="",$raw="")
-{
-    return '<h2 ' . $p_class . '>' . $raw.htmlspecialchars($p_string) . 
'</h2>';
-}
-function h1($p_string, $p_class="")
-{
-    return '<h1 ' . $p_class . '>' . htmlspecialchars($p_string) . '</h1>';
-}
-/**
- * \brief surround the string with td
- * \param $p_string string to surround by TD
- * \param $p_extra extra info (class, style, javascript...)
- * \return string surrounded by td
- */
-
-function td($p_string='', $p_extra='')
-{
-    return '<td  ' . $p_extra . '>' . $p_string . '</td>';
-}
-
-function tr($p_string, $p_extra='')
-{
-    return '<tr  ' . $p_extra . '>' . $p_string . '</tr>';
-}
-
-/**
- * @brief escape correctly php string to javascript 
- */
-function j($p_string)
-{
-    $a = preg_replace("/\r?\n/", "\\n", addslashes($p_string));
-    $a = str_replace("'", '\'', $a);
-    return $a;
-}
-
-/**
- * format the number for the CSV export
- * @param $p_number number
- */
-function nb($p_number)
-{
-    $r = sprintf('%.2f', $p_number);
-    $r = str_replace('.', ',', $r);
-
-    return $r;
-}
-
-/**
- * format the number with a sep. for the thousand
- * @param $p_number number
- */
-function nbm($p_number)
-{
-
-    if (trim($p_number) == '')
-       return '';
-    if ($p_number == 0)
-       return "0,00";
-    
-    $a = doubleval($p_number);
-    $r = number_format($a, 2, ",", ".");
-    if (trim($r) == '')
-    {
-       var_dump($r);
-       var_dump($p_number);
-       var_dump($a);
-       exit();
-    }
-
-    return $r;
-}
-
-/**
- * \brief  log error into the /tmp/noalyss_error.log it doesn't work on windows
- *
- * \param p_log message
- * \param p_line line number
- * \param p_message is the message
- *
- * \return nothing
- *
- */
-
-function echo_error($p_log, $p_line="", $p_message="")
-{
-    echo "ERREUR :" . $p_log . " " . $p_line . " " . $p_message;
-    $fdebug = fopen($_ENV['TMP'] . DIRECTORY_SEPARATOR . "noalyss_error.log", 
"a+");
-    if ($fdebug != null)
-    {
-       fwrite($fdebug, date("Ymd H:i:s") . $p_log . " " . $p_line . " " . 
$p_message . "\n");
-       fclose($fdebug);
-    }
-}
-
-/**
- * \brief  Compare 2 dates
- * \param p_date
- * \param p_date_oth
- *
- * \return
- *      - == 0 les dates sont identiques
- *      - > 0 date1 > date2
- *      - < 0 date1 < date2
- */
-
-function cmpDate($p_date, $p_date_oth)
-{
-    date_default_timezone_set('Europe/Brussels');
-
-    $l_date = isDate($p_date);
-    $l2_date = isDate($p_date_oth);
-    if ($l_date == null || $l2_date == null)
-    {
-       throw new Exception("erreur date [$p_date] [$p_date_oth]");
-    }
-    $l_adate = explode(".", $l_date);
-    $l2_adate = explode(".", $l2_date);
-    $l_mkdate = mktime(0, 0, 0, $l_adate[1], $l_adate[0], $l_adate[2]);
-    $l2_mkdate = mktime(0, 0, 0, $l2_adate[1], $l2_adate[0], $l2_adate[2]);
-    // si $p_date > $p_date_oth return > 0
-    return $l_mkdate - $l2_mkdate;
-}
-
-/***!
- * @brief check if the argument is a number
- *
- * \param $p_int number to test
- *
- * \return
- *        - 1 it's a number
- *        - 0 it is not
- */
-function isNumber(&$p_int)
-{
-    if (strlen(trim($p_int)) == 0)
-       return 0;
-    if (is_numeric($p_int) === true)
-       return 1;
-    else
-       return 0;
-}
-
-/***
- * \brief Verifie qu'une date est bien formaté
- *           en d.m.y et est valable
- * \param $p_date
- *
- * \return
- *     - null si la date est invalide ou malformaté
- *      - $p_date si tout est bon
- *
- */
-
-function isDate($p_date)
-{
-    if (strlen(trim($p_date)) == 0)
-       return null;
-    if (preg_match("/^[0-9]{1,2}\.[0-9]{1,2}\.20[0-9]{2}$/", $p_date) == 0)
-    {
-
-       return null;
-    }
-    else
-    {
-       $l_date = explode(".", $p_date);
-
-       if (sizeof($l_date) != 3)
-           return null;
-
-       if ($l_date[2] > COMPTA_MAX_YEAR || $l_date[2] < COMPTA_MIN_YEAR)
-       {
-           return null;
-       }
-
-       if (checkdate($l_date[1], $l_date[0], $l_date[2]) == false)
-       {
-           return null;
-       }
-    }
-    return $p_date;
-}
-
-/**
- * \brief Default page header for each page
- *
- * \param p_theme default theme
- * \param $p_script
- * \param $p_script2  another js script
- * Must be called only once
- * \return none
- */
-
-function html_page_start($p_theme="", $p_script="", $p_script2="")
-{
-    // check not called twiced
-    static  $already_call=0;
-    if ( $already_call==1)return;
-    $already_call=1;
-
-    $cn = new Database();
-    if ($p_theme != "")
-    {
-       $Res = $cn->exec_sql("select the_filestyle from theme
-                           where the_name='" . $p_theme . "'");
-       if (Database::num_row($Res) == 0)
-           $style = "style-classic.css";
-       else
-       {
-           $s = Database::fetch_array($Res, 0);
-           $style = $s['the_filestyle'];
-       }
-    }
-    else
-    {
-       $style = "style-classic.css";
-    } // end if
-       $title="NOALYSS";
-
-       if ( isset ($_REQUEST['ac'])) {
-               if (strpos($_REQUEST['ac'],'/') <> 0)
-               {
-                       $m=  explode('/',$_REQUEST['ac']);
-                       $title=$m[count($m)-1]."  ".$title;
-               }
-               else
-                       $title=$_REQUEST['ac']."  ".$title;
-       }
-    $is_msie=is_msie();
-    
-    if ($is_msie == 0 ) 
-    {
-        echo '<!doctype html>';
-        printf("\n");
-        echo '<meta name="viewport" content="width=device-width, 
initial-scale=1.0">';
-        printf("\n");
-    }
-    else {
-        echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 FINAL//EN" >';
-        printf("\n");
-    }
-    echo "<HTML>";
-
-    if ($p_script2 != "")
-       $p_script2 = '<script src="' . $p_script2 . '?version='.SVNINFO.'" 
type="text/javascript"></script>';
-    $style=trim($style);
-    echo "<HEAD>";
-    if ( $is_msie == 1 )echo '      <meta http-equiv="x-ua-compatible" 
content="IE=edge"/>';
-    echo "
-    <TITLE>$title</TITLE>
-       <link rel=\"icon\" type=\"image/ico\" href=\"favicon.ico\" />
-    <META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
-    <LINK REL=\"stylesheet\" type=\"text/css\" 
href=\"".$style."?version=".SVNINFO."\" media=\"screen\"/>
-    <link rel=\"stylesheet\" type=\"text/css\" 
href=\"./style-print.css?version=".SVNINFO."\" media=\"print\"/>" .
-    $p_script2 . "
-    ";
-    echo '<script language="javascript" src="js/calendar.js"></script>
-    <script type="text/javascript" src="js/lang/calendar-en.js"></script>
-    <script language="javascript" src="js/calendar-setup.js"></script>
-    <LINK REL="stylesheet" type="text/css" href="./calendar-blue.css" 
media="screen">
-    ';
-    echo load_all_script();
-    echo '    </HEAD>    ';
-
-    echo "<BODY $p_script>";
-    echo '<div id="info_div"></div>';
-    echo '<div id="error_div">'.
-            HtmlInput::title_box(_("Erreur"), 'error_div','hide').
-            '<div id="error_content_div">'.
-            '</div>'.
-            '<p style="text-align:center">'.
-            
HtmlInput::button_action('Valider','$(\'error_div\').style.visibility=\'hidden\';$(\'error_content_div\').innerHTML=\'\';').
-            '</p>'.
-            '</div>';
-// language
-    if (isset($_SESSION['g_lang']))
-    {
-               set_language();
-    }
-
-}
-
-/**
- * \brief Minimal  page header for each page, used for small popup window
- *
- * \param p_theme default theme
- * \param $p_script
- * \param $p_script2  another js script
- *
- * \return none
- */
-
-function html_min_page_start($p_theme="", $p_script="", $p_script2="")
-{
-
-    $cn = new Database();
-    if ($p_theme != "")
-    {
-       $Res = $cn->exec_sql("select the_filestyle from theme
-                           where the_name='" . $p_theme . "'");
-       if (Database::num_row($Res) == 0)
-           $style = "style-classic.css";
-       else
-       {
-           $s = Database::fetch_array($Res, 0);
-           $style = $s['the_filestyle'];
-       }
-    }
-    else
-    {
-       $style = "style-classic.css";
-    } // end if
-    echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 FINAL//EN">';
-    echo "<HTML>";
-
-
-    if ($p_script2 != "")
-       $p_script2 = '<script src="' . $p_script2 . '" 
type="text/javascript"></script>';
-
-    echo "<HEAD>
-    <TITLE>NOALYSS</TITLE>
-    <META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF8\">
-    <LINK REL=\"stylesheet\" type=\"text/css\" href=\"$style\" 
media=\"screen\">
-    <link rel=\"stylesheet\" type=\"text/css\" href=\"style-print.css\" 
media=\"print\">" .
-    $p_script2 . "
-    <script src=\"js/scripts.js\" type=\"text/javascript\"></script>
-    <script src=\"js/acc_ledger.js\" type=\"text/javascript\"></script>
-    <script src=\"js/smoke.js\" type=\"text/javascript\"></script>";
-    echo '</HEAD>
-    ';
-
-    echo "<BODY $p_script>";
-    /* If we are on the user_login page */
-    if (basename($_SERVER['PHP_SELF']) == 'user_login.php')
-    {
-       return;
-    }
-}
-
-/**
- * \brief end tag
- *
- */
-
-function html_page_stop()
-{
-    echo "</BODY>";
-    echo "</HTML>";
-}
-
-/**
- * \brief Echo no access and stop
- *
- * \return nothing
- */
-
-function NoAccess($js=1)
-{
-    if ($js == 1)
-    {
-       echo "<script>";
-       echo "alert ('" . _('Cette action ne vous est pas autorisée Contactez 
votre responsable') . "');";
-       echo "</script>";
-    }
-    else
-    {
-       echo '<div class="redcontent">';
-       echo '<h2 class="error">' . _(' Cette action ne vous est pas autorisée 
Contactez votre responsable') . '</h2>';
-       echo '</div>';
-    }
-    exit - 1;
-}
-/**
- * replaced by sql_string
- * @deprecated
- */
-function FormatString($p_string)
-{
-    return sql_string($p_string);
-}
-/**
- * \brief Fix the problem with the quote char for the database
- *
- * \param $p_string
- * \return a string which won't let strange char for the database
- */
-
-function sql_string($p_string)
-{
-    $p_string = trim($p_string);
-    if (strlen($p_string) == 0)
-       return null;
-    $p_string = str_replace("'", "''", $p_string);
-    $p_string = str_replace('\\', '\\\\', $p_string);
-    return $p_string;
-}
-
-/**
-  /* \brief store the string which print
- *           the content of p_array in a table
- *           used to display the menu
- * \param  $p_array array like ( 0=>HREF reference, 1=>visible item 
(name),2=>Help(opt),
- * 3=>selected (opt) 4=>javascript (normally a onclick event) (opt)
- * \param $p_dir direction of the menu (H Horizontal  V vertical)
- * \param $class CSS for TD tag
- * \param $class_ref CSS for the A tag
- * \param $default selected item
- * \param $p_extra extra code for the table tag (CSS or javascript)
- *
-  /* \return : string */
-
-function ShowItem($p_array, $p_dir='V', $class="mtitle", $class_ref="mtitle", 
$default="", $p_extra="")
-{
-
-    $ret = "<TABLE $p_extra>";
-    // direction Vertical
-    if ($p_dir == 'V')
-    {
-       foreach ($p_array as $all => $href)
-       {
-           $javascript = (isset($href[4])) ? $href[4] : "";
-           $title = "";
-           $set = "XX";
-           if (isset($href[2]))
-               $title = $href[2];
-           if (isset($href[3]))
-               $set = $href[3];
-
-           if ($set == $default)
-               $ret.='<TR><TD CLASS="selectedcell"><A class="' . $class_ref . 
'" HREF="' . $href[0] . '" title="' . $title . '" ' . $javascript . '>' . 
$href[1] . '</A></TD></TR>';
-           else
-               $ret.='<TR><TD CLASS="' . $class . '"><A class="' . $class_ref 
. '" HREF="' . $href[0] . '" title="' . $title . '" ' . $javascript . '>' . 
$href[1] . '</A></TD></TR>';
-       }
-    }
-    //direction Horizontal
-    else if ($p_dir == 'H')
-    {
-
-       $ret.="<TR>";
-       foreach ($p_array as $all => $href)
-       {
-           $title = "";
-           $javascript = (isset($href[4])) ? $href[4] : "";
-
-           $set = "A";
-           if (isset($href[2]))
-               $title = $href[2];
-
-           if (isset($href[3]))
-               $set = $href[3];
-
-           if ($default === $href[0] || $set === $default)
-           {
-               $ret.='<TD CLASS="selectedcell"><A class="' . $class_ref . '" 
HREF="' . $href[0] . '" title="' . $title . '" ' . $javascript . '>' . $href[1] 
. '</A></TD>';
-           }
-           else
-           {
-               $ret.='<TD CLASS="' . $class . '"><A class="' . $class_ref . '" 
HREF="' . $href[0] . '" title="' . $title . '" ' . $javascript . '>' . $href[1] 
. '</A></TD>';
-           }
-       }
-       $ret.="</TR>";
-    }
-    $ret.="</TABLE>";
-    return $ret;
-}
-
-/**
- * \brief warns
- *
- * \param p_string error message
- * gen :
- *     - none
- * \return:
- *      - none
- */
-
-function echo_warning($p_string)
-{
-    echo '<H2 class="error">' . $p_string . "</H2>";
-}
-
-/**
- * \brief Show the periode which found thanks its id
- *
- *
- * \param  $p_cn database connection
- * \param p_id
- * \param pos Start or end
- *
- * \return: string
- */
-
-function getPeriodeName($p_cn, $p_id, $pos='p_start')
-{
-    if ($pos != 'p_start' and
-           $pos != 'p_end')
-       echo_error('ac_common.php' . "-" . __LINE__ . '  UNDEFINED PERIODE');
-    $ret = $p_cn->get_value("select to_char($pos,'Mon YYYY') as t from 
parm_periode where p_id=$p_id");
-    return $ret;
-}
-
-/**
- * \brief Return the period corresponding to the
- *           date
- *
- * \param p_cn database connection
- * \param p_date the month + year 'MM.YYYY'
- *
- * \return:
- *       parm_periode.p_id
- */
-
-function getPeriodeFromMonth($p_cn, $p_date)
-{
-    $R = $p_cn->get_value("select p_id from parm_periode where
-                        to_char(p_start,'DD.MM.YYYY') = '01.$p_date'");
-    if ($R == "")
-       return -1;
-    return $R;
-}
-
-/**\brief Decode the html for the widegt richtext and remove newline
- * \param $p_html string to decode
- * \return the html code without new line
- */
-
-function Decode($p_html)
-{
-    $p_html = str_replace('%0D', '', $p_html);
-    $p_html = str_replace('%0A', '', $p_html);
-    $p_html = urldecode($p_html);
-    return $p_html;
-}
-
-/**\brief Create the condition to filter on the j_tech_per
- *        thanks a from and to date.
- * \param $p_cn database conx
- * \param $p_from start date (date)
- * \param $p_to  end date (date)
- * \param $p_form if the p_from and p_to are date or p_id
- * \param $p_field column name
- * \return a string containg the query
- */
-
-function sql_filter_per($p_cn, $p_from, $p_to, $p_form='p_id', 
$p_field='jr_tech_per')
-{
-
-    if ($p_form != 'p_id' &&
-           $p_form != 'date')
-    {
-       echo_error(__FILE__, __LINE__, 'Mauvais parametres ');
-       exit(-1);
-    }
-    if ($p_form == 'p_id')
-    {
-       // retrieve the date
-       $pPeriode = new Periode($p_cn);
-       $a_start = $pPeriode->get_date_limit($p_from);
-       $a_end = $pPeriode->get_date_limit($p_to);
-       if ($a_start == null || $a_end == null)
-           throw new Exception(__FILE__ . __LINE__ . sprintf(_('Attention 
periode 
-                    non trouvee periode p_from= %s p_to_periode = %s'), 
$p_from ,
-                   $p_to));
-
-
-       $p_from = $a_start['p_start'];
-       $p_to = $a_end['p_end'];
-    }
-    if ($p_from == $p_to)
-       $periode = " $p_field = (select p_id from parm_periode " .
-               " where " .
-               " p_start = to_date('$p_from','DD.MM.YYYY')) ";
-    else
-       $periode = "$p_field in (select p_id from parm_periode " .
-               " where p_start >= to_date('$p_from','DD.MM.YYYY') and p_end <= 
to_date('$p_to','DD.MM.YYYY')) ";
-    return $periode;
-}
-
-/**\brief alert in javascript
- * \param $p_msg is the message
- * \param $buffer if false, echo directly and execute the javascript, if 
$buffer is true, the alert javascript
- * is in the return string
- * \return string with alert javascript if $buffer is true
- */
-
-function alert($p_msg, $buffer=false)
-{
-    $r = '<script>';
-    $r.= 'alert_box(\'' . j($p_msg) . '\')';
-    $r.= '</script>';
-
-    if ($buffer)
-       return $r;
-    echo $r;
-}
-
-/**
- * @brief set the lang thanks the _SESSION['g_lang'] var.
- */
-function set_language()
-{
-    // desactivate local check
-    if ( defined("LOCALE") && LOCALE==0 ) return;
-    if ( ! isset ($_SESSION['g_lang'])) return;
-    $dir = "";
-    // set differently the language depending of the operating system
-    if (what_os() == 1)
-    {
-       $dir = setlocale(LC_MESSAGES, $_SESSION['g_lang']);
-       if ($dir == "")
-       {
-           $g_lang = 'fr_FR.utf8';
-           $dir = setlocale(LC_MESSAGES, $g_lang);
-          // echo '<span class="notice">' . $_SESSION['g_lang'] . ' domaine 
non supporté</h2>';
-       }
-       bindtextdomain('messages', './lang');
-       textdomain('messages');
-       bind_textdomain_codeset('messages', 'UTF8');
-
-       return;
-    }
-    // for windows
-    putenv('LANG=' . $_SESSION['g_lang']);
-    $dir = setlocale(LC_ALL, $_SESSION['g_lang']);
-    bindtextdomain('messages', '.\\lang');
-    textdomain('messages');
-    bind_textdomain_codeset('messages', 'UTF8');
-}
-
-/**
- * @brief try to determine on what os you are running the pĥpcompte
- * server
- * @return
- *  0 it is a windows
- *  1 it is a Unix like
- */
-function what_os()
-{
-    $inc_path = get_include_path();
-
-    if (strpos($inc_path, ";") != 0)
-    {
-       $os = 0;   /* $os is 0 for windoz */
-    }
-    else
-    {
-       $os = 1;   /* $os is 1 for unix */
-    }
-    return $os;
-}
-
-/**
- * @brief shrink the date, make a date shorter for the printing
- * @param $p_date format DD.MM.YYYY
- * @return date in the format DDMMYY (size = 13 mm in arial 8)
- */
-function shrink_date($p_date)
-{
-    $date = str_replace('.', '', $p_date);
-    $str_date = substr($date, 0, 4) . substr($date, 6, 2);
-    return $str_date;
-}
-/**
- * @brief shrink the date, make a date shorter for the printing
- * @param $p_date format DD.MM.YYYY
- * @return date in the format DDMMYY (size = 13 mm in arial 8)
- */
-function smaller_date($p_date)
-{
-    $str_date = substr($p_date, 0, 6) . substr($p_date, 8, 2);
-    return $str_date;
-}
-
-/**
- * @brief format the date, when taken from the database the format
- * is MM-DD-YYYY
- * @param $p_date format
- * @param
- * @return date in the format DD.MM.YYYY
- */
-function format_date($p_date, $p_from_format = 
'YYYY-MM-DD',$p_to_format='DD.MM.YYYY')
-{
-    if ($p_from_format == 'YYYY-MM-DD')
-    {
-        $date = explode('-', $p_date);
-        if (count($date) != 3)
-            return $p_date;
-    }
-    if ($p_from_format == 'DD.MM.YYYY')
-    {
-        $temp_date = explode('.', $p_date);
-        if (count($temp_date) != 3)
-            return $p_date;
-        $date[0] = $temp_date[2]; // 0 is year
-        $date[1] = $temp_date[1]; // 1 for month
-        $date[2] = $temp_date[0]; // 2 for day
-    }
-
-    switch ($p_to_format)
-    {
-        case 'DD.MM.YYYY':
-            $str_date = $date[2] . '.' . $date[1] . '.' . $date[0];
-            break;
-        case 'YYYY-MM-DD':
-            $str_date = $date[0] . '-' . $date[1] . '-' . $date[2];
-            break;
-       case 'YYYYMMDD':
-            $str_date = $date[0] . $date[1] . $date[2];
-            break;
-                case 'YYYY/MM/DD':
-            $str_date = $date[0] . '/' . $date[1] . '/' . $date[2];
-            break;
-
-               }
-    return $str_date;
-}
-
-
-
-/**
- * Should a dialog box when you are disconnected from an ajax call
- * propose to reload or to connect in another tab
- */
-function ajax_disconnected($div)
-{
-    /**
-     * if $_SESSION['g_user'] is not set : echo a warning
-     */
-    if (!isset($_SESSION['g_user']))
-    {
-       $script = 'var a=$("' . $div . 
'");a.style.height="70%";a.style.width="60%";';
-       $script.='a.style.top=posY-20+offsetY;a.style.left=posX+offsetX;';
-       $script = create_script($script);
-       $html = $script;
-       $html.=HtmlInput::anchor_close($div);
-       $html.='<div>';
-       $html.=h2(_('Données non disponibles'), 'class="title" 
style="width:auto"');
-       $html.=h2(_('Veuillez vous reconnecter soit dans une autre fenêtre soit 
'
-                . ' en cliquant sur le lien'), 'class="error"');
-        // Reload button
-        $reload=new IButton("reload");
-        $reload->value=_("Se reconnecter pour revenir ici");
-        $reload->class="button";
-        $reload->javascript='window.location.reload()';
-        // Link to log in another tab
-        $html.='<p style="text-align:center">';
-        $html.='<a href="index.php" class="button" target="_blank">'.
-                _('Cliquez ici pour vous reconnecter dans une autre page').
-                '</a>';
-        $html.=$reload->input();
-        $html.='</p>';
-       $html = escape_xml($html);
-       header('Content-type: text/xml; charset=UTF-8');
-       echo <<<EOF
-<?xml version="1.0" encoding="UTF-8"?>
-<data>
-<ctl>$div</ctl>
-<code>$html</code>
-</data>
-EOF;
-       exit();
-    }
-}
-
-/**
- *Show the modules
- * @param int $selected module selected profile_menu.pm_id
- */
-function show_module($selected)
-{
-    global $g_user;
-    $cn = Dossier::connect();
-    $amodule = $cn->get_array("select
-       me_code,me_menu,me_url,me_javascript,p_order,me_type,me_description
-       from v_all_menu
-       where
-       p_id=$1
-       and p_type_display='M'
-       order by p_order", array($g_user->get_profile()));
-
-    if ($selected != -1)
-    {
-        $selected_module=$cn->get_value('select me_code from profile_menu 
where'
-                . ' pm_id = $1 ', array($selected));
-       require_once NOALYSS_INCLUDE.'/template/module.php';
-       $file = $cn->get_array("select 
me_file,me_parameter,me_javascript,me_type,me_description from v_all_menu
-           where pm_id=$1 and p_id=$2", 
array($selected,$g_user->get_profile()));
-       if ( count($file ) == 0 )
-       {
-               echo '</div>';
-               echo '</div>';
-               echo '<div class="content">';
-               echo_warning(_("Module inexistant")."[ $selected ] ");
-               echo '</div>';
-               exit();
-       }
-       if ($file[0]['me_file'] != '')
-       {
-           if ($file[0]['me_parameter'] != "")
-           {
-               // if there are paramter put them in superglobal
-               $array=compute_variable($file[0]['me_parameter']);
-               put_global($array);
-           }
-
-               // if file is not a plugin, include the file, otherwise
-               // include the plugin launcher
-               if ($file[0]['me_type'] != 'PL')
-                       {
-                               require_once $file[0]['me_file'];
-                       }
-                       else
-                       {
-                               // nothing  : direct call to plugin
-                       }
-       }
-       if ( $file[0]['me_javascript'] != '')
-       {
-               create_script($file[0]['me_javascript']);
-       }
-    }
-}
-/**
- * Find the default module or the first one
- * @global $g_user $g_user
- * @return default module (string)
- */
-function find_default_module()
-{
-    global $g_user;
-    $cn = Dossier::connect();
-
-    $default_module = $cn->get_array("select me_code
-           from profile_menu join profile_user using (p_id)
-           where
-           p_type_display='M' and
-           user_name=$1 and pm_default=1", array($g_user->login));
-
-       /*
-        * Try to find the smallest order for module
-        */
-    if (empty($default_module))
-    {
-               $default_module = $cn->get_array("select me_code
-           from profile_menu join profile_user using (p_id)
-           where
-           p_type_display='M' and
-           user_name=$1 order by p_order limit 1", array($g_user->login));
-
-               // if no default try to find the default menu
-               if ( empty ($default_module))
-               {
-                       $default_module = $cn->get_array("select me_code
-                        from profile_menu join profile_user using (p_id)
-                          where
-                          p_type_display='E' and
-                          user_name=$1 and pm_default=1 ", 
array($g_user->login));
-                       /*
-                        * Try to find a default menu by order
-                        */
-                       if (empty ($default_module))
-                       {
-                               $default_module = $cn->get_array("select me_code
-                               from profile_menu join profile_user using (p_id)
-                               where
-                               user_name=$1 and p_order=(select min(p_order) 
from profile_menu join profile_user using (p_id)
-                               where user_name=$2) limit 1", 
array($g_user->login, $g_user->login));
-                       }
-
-                       /*
-                       * if nothing found, there is no profile for this user 
=> exit
-                       */
-                       if (empty ($default_module))
-                       {
-                            /* 
-                             * If administrateur, then we insert a default 
profile (1)
-                             * for him
-                             */
-                            if ( $g_user->admin == 1 )
-                            {
-                                $cn->exec_sql('insert into 
profile_user(user_name,p_id) values ($1,1) ',array($g_user->login));
-                                return find_default_module();
-                            }
-                            echo_warning(_("Utilisateur n'a pas de profil, 
votre administrateur doit en configurer un dans CFGSEC"));
-                            exit();
-                       }
-               }
-               return $default_module[0]['me_code'];
-    }
-
-    if (count($default_module) > 1)
-    {
-               // return the first module found
-               return $default_module[0]['me_code'];
-    }
-    elseif (count($default_module) == 1)
-    {
-       return $default_module[0]['me_code'];
-    }
-}
-
-/**
- * show the module
- * @global $g_user
- * @param $module the $_REQUEST['ac'] exploded into an array
- * @param  $idx the index of the array : the AD code is splitted into an array 
thanks the slash
- */
-function show_menu($module)
-{
-    if ($module == 0)return;
-    static $level=0;
-    global $g_user;
-    
-    $cn = Dossier::connect();
-    /**
-     * Show the submenus
-     */
-    $amenu = $cn->get_array("
-        select 
-            pm_id,
-            me_code,
-            pm_id_dep,
-            me_file,
-            me_javascript,
-            me_url,
-            me_menu,
-            me_description,
-            me_description_etendue
-            from profile_menu 
-            join menu_ref using (me_code) 
-            where pm_id_dep=$1 and p_id=$2
-        order by p_order", array($module, $g_user->get_profile()));
-    
-    // There are submenuS, so show them
-    if (!empty($amenu) && count($amenu) > 1)
-    {
-        $a_style_menu=array('topmenu','menu2','menu3');
-        if ( $level > count($a_style_menu))
-            $style_menu='menu3';
-        else {
-            $style_menu=$a_style_menu[$level];
-        }
-               require 'template/menu.php';
-    } // there is only one submenu so we include the code or javascript 
-      // or we show the submenu
-    elseif (count($amenu) == 1)
-    {
-        if ( trim($amenu[0]['me_url']) != "" ||
-             trim ($amenu[0]['me_file']) != "" ||
-             trim ($amenu[0]['me_javascript']) != "" )
-        {
-               echo '<div class="topmenu">';
-               echo h2info(_($amenu[0]['me_menu']));
-               echo '</div>';
-               $module = $amenu[0]['pm_id'];
-        } else {
-           $url=$_REQUEST['ac'].'/'.$amenu[0]['me_code'];
-           echo '<a href="do.php?gDossier='.Dossier::id().'&ac='.$url.'">';
-           echo _($amenu[0]['me_menu']);
-           echo '</a>';
-           $level++;
-           return;
-        }
-    }
-    
-    // There is no submenu or only one
-    if (empty($amenu) || count($amenu) == 1)
-    {
-               $file = $cn->get_array("select 
me_file,me_parameter,me_javascript,me_type
-               from menu_ref
-               join profile_menu using (me_code)
-               join profile_user using (p_id)
-               where
-               pm_id=$1 and
-               user_name=$2 and
-               (me_file is not null or trim(me_file) <>'' or
-               me_javascript is not null or trim (me_javascript) <> '')", 
array($module,$g_user->login));
-
-               if (count($file)==0)
-               {
-                        return;
-               }
-
-               if ($file[0]['me_file'] != "")
-               {
-                       if ($file[0]['me_parameter'] !== "")
-                       {
-                               // if there are paramter put them in superglobal
-                               
$array=compute_variable($file[0]['me_parameter']);
-                               put_global($array);
-                       }
-                        if ( DEBUG ) echo  $file[0]['me_file']," param : 
",$file[0]['me_parameter'] ;
-                        /*
-                         * Log the file we input to put in the folder 
test-noalyss for replaying it
-                         */
-                        if (LOGINPUT) {
-                                
$file_loginput=fopen($_ENV['TMP'].'/scenario-'.$_SERVER['REQUEST_TIME'].'.php','a+');
-                                fwrite($file_loginput, "include 
'".$file[0]['me_file']."';");
-                                fwrite($file_loginput,"\n");
-                                fclose($file_loginput);
-                        }
-                       // if file is not a plugin, include the file, otherwise
-                       // include the plugin launcher
-                       if ( $file[0]['me_type'] != 'PL')
-                               require_once $file[0]['me_file'];
-                       else
-                               require 'extension_get.inc.php';
-
-                       exit();
-               }
-               if ( $file[0]['me_javascript'] != '')
-               {
-                    $js=  str_replace('<DOSSIER>', dossier::id(), 
$file[0]['me_javascript']);
-                    echo create_script($js);
-               }
-    }
-    $level++;
-}
-/**
- * Put in superglobal (get,post,request) the value contained in
- * the parameter field (me_parameter)
- * @param $array [key] [value]
- */
-function put_global($array)
-{
-    for ($i=0;$i<count($array);$i++)
-    {
-       $key=$array[$i]['key'];
-       $value=$array[$i]['value'];
-       $_GET[$key]=$value;
-       $_POST[$key]=$value;
-       $_REQUEST[$key]=$value;
-    }
-}
-/**
- * the string has the format a=b&c=d, it is parsed and an array[][key,value]
- * is returned
- * @param $p_string
- * @return $array usable in put_global
- */
-function compute_variable($p_string)
-{
-    $array=array();
-    if ($p_string == '') return $array;
-
-    $var=explode("&",$p_string);
-    if (empty ($var))  return $array;
-    for ($i=0;$i < count($var);$i++)
-    {
-       $var2=explode('=',$var[$i]);
-       $array[$i]['key']=$var2[0];
-       $array[$i]['value']=$var2[1];
-    }
-    return $array;
-}
-function ajax_xml_error($p_code,$p_string)
-{
-    $html = escape_xml($p_string);
-    header('Content-type: text/xml; charset=UTF-8');
-               echo <<<EOF
-<?xml version="1.0" encoding="UTF-8"?>
-<data>
-<code>$p_code</code>
-<value>$html</value>
-</data>
-EOF;
-}
-/**
- * @brief Display a box with the contains
- * @param type $p_array Data to display
- * @param type $p_title Title of the box
- * @param type $p_div id of the box
- */
-function display_dashboard_operation($p_array,$p_title,$p_div)
-{
-       ?>
-<div id="<?php echo $p_div;?>" class="inner_box" 
style="display:none;position:fixed;top:250px;left:12%;width: 
75%;min-height:50%;overflow:auto;">
-       <?php
-       echo HtmlInput::title_box($p_title, $p_div, "hide");
-       ?>
-       <?php if (count($p_array)>0) :?>
-       <table class="result">
-               <tr>
-                       <th><?php echo _('Date')?></th>
-                       <th><?php echo _('Code Interne')?></th>
-                       <th><?php echo _('Pièce')?></th>
-                       <th><?php echo _('Description')?></th>
-                       <th>
-                               <?php echo _('Montant')?>
-                       </th>
-
-               </tr>
-               <?php
-                       for ($i=0;$i<count($p_array);$i++):
-               ?>
-               <tr class="<?php echo (($i%2)==0)?'odd':'even';?>">
-                       <td>
-                               <?php echo 
smaller_date(format_date($p_array[$i]['jr_date']) );?>
-                       </td>
-                       <td>
-                               <?php echo 
HtmlInput::detail_op($p_array[$i]['jr_id'], $p_array[$i]['jr_internal']) ?>
-                       </td>
-                        <td>
-                            <?php echo h($p_array[$i]['jr_pj_number'])?>
-                        </td>
-                       <td>
-                               <?php echo h($p_array[$i]['jr_comment']) ?>
-                       </td>
-                       <td>
-                               <?php echo nbm($p_array[$i]['jr_montant']) ?>
-                       </td>
-               </tr>
-               <?php
-               endfor;
-               ?>
-       </table>
-       <?php else: ?>
-       <h2 class="notice"><?php echo _('Aucune donnée')?></h2>
-       <?php
-       endif;
-       ?>
-</div>
-<?php
-}
-function get_array_column($p_array,$key)
-{
-    $array=array();
-    for ($i=0;$i<count($p_array);$i++)
-    {
-        $r=$p_array[$i];
-        if ( isset($r[$key])) {
-            $array[]=$r[$key];
-        }
-    }
-    return $array;
-}
-
-/**
- * This function create a ledger object and return the right one.
- * It uses the factory pattern
- * @param Database $p_cn
- * @param type $ledger_id 
- * @return Acc_Ledger
- * @throws Exception
- */
-function factory_Ledger(Database &$p_cn, $ledger_id)
-{
-    include_once 'class_acc_ledger_sold.php';
-    include_once 'class_acc_ledger_purchase.php';
-    include_once 'class_acc_ledger_fin.php';
-    
-    $ledger=new Acc_Ledger($p_cn, $ledger_id);
-    $type=$ledger->get_type();
-
-    switch ($type)
-    {
-        case 'VEN':
-            $obj=new Acc_Ledger_Sold($p_cn, $ledger_id);
-            break;
-        case 'ACH':
-            $obj=new Acc_Ledger_Purchase($p_cn, $ledger_id);
-            break;
-        case 'FIN':
-            $obj= new Acc_Ledger_Fin($p_cn, $ledger_id);
-            break;
-        case 'ODS':
-            $obj=$ledger;
-            break;
-
-        default:
-            throw new Exception('Ledger type not found');
-    }
-    return $obj;
-}
-/**
- * Check if we use IE 8 or 9
- * @return int 1 for IE8-9;0 otherwise
- */
-function is_msie()
-{
-    if ( strpos ($_SERVER['HTTP_USER_AGENT'],'MSIE 8.0')  != 0 ||
-         strpos ($_SERVER['HTTP_USER_AGENT'],'MSIE 9.0')  != 0 )
-       $is_msie=1;
-    else
-        $is_msie=0;
-    return $is_msie;
-}
-?>
\ No newline at end of file
diff --git a/include/action.inc.php b/include/action.inc.php
index ff2ea68..d0d00f5 100644
--- a/include/action.inc.php
+++ b/include/action.inc.php
@@ -28,11 +28,11 @@ $retour=HtmlInput::button_anchor(_('Retour liste'),
 //-----------------------------------------------------
 // Follow_Up
 //-----------------------------------------------------
-require_once NOALYSS_INCLUDE.'/class_icard.php';
-require_once NOALYSS_INCLUDE.'/class_ispan.php';
-require_once NOALYSS_INCLUDE.'/class_ifile.php';
-require_once NOALYSS_INCLUDE.'/class_itext.php';
-require_once NOALYSS_INCLUDE.'/class_follow_up.php';
+require_once NOALYSS_INCLUDE.'/lib/class_icard.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ispan.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ifile.php';
+require_once NOALYSS_INCLUDE.'/lib/class_itext.php';
+require_once NOALYSS_INCLUDE.'/class/class_follow_up.php';
 /*!\brief Show the list of action, this code should be common
  *        to several webpage. But for the moment we keep like that
  *        because it is used only by this file.
diff --git a/include/adm.inc.php b/include/adm.inc.php
index 6e32b3b..3308253 100644
--- a/include/adm.inc.php
+++ b/include/adm.inc.php
@@ -21,13 +21,13 @@
  * the customer category
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_iselect.php';
-require_once NOALYSS_INCLUDE.'/class_ihidden.php';
-require_once NOALYSS_INCLUDE.'/class_customer.php';
-require_once NOALYSS_INCLUDE.'/class_ibutton.php';
-require_once NOALYSS_INCLUDE.'/class_fiche_def.php';
-require_once NOALYSS_INCLUDE.'/class_fiche_def.php';
-require_once NOALYSS_INCLUDE.'/class_admin.php';
+require_once NOALYSS_INCLUDE.'/lib/class_iselect.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ihidden.php';
+require_once NOALYSS_INCLUDE.'/class/class_customer.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ibutton.php';
+require_once NOALYSS_INCLUDE.'/class/class_fiche_def.php';
+require_once NOALYSS_INCLUDE.'/class/class_fiche_def.php';
+require_once NOALYSS_INCLUDE.'/class/class_admin.php';
 
 global $g_user;
 
diff --git a/include/ajax_account_update.php 
b/include/ajax/ajax_account_update.php
similarity index 100%
rename from include/ajax_account_update.php
rename to include/ajax/ajax_account_update.php
diff --git a/include/ajax/ajax_action_remove_concerned.php 
b/include/ajax/ajax_action_remove_concerned.php
new file mode 100644
index 0000000..7a0b47f
--- /dev/null
+++ b/include/ajax/ajax_action_remove_concerned.php
@@ -0,0 +1,45 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright 2014 Author Dany De Bontridder address@hidden
+
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+$ag_id=HtmlInput::default_value_get("ag_id", "0");
+$f_id=HtmlInput::default_value_get("f_id", "0");
+if ( $ag_id == 0 || $f_id == 0 ) throw new Exception ("Invalid values", 0);
+require_once 'class/class_follow_up.php';
+$follow=new Follow_Up($cn,$ag_id);
+
+ob_start();
+$follow->remove_linked_card($f_id);
+echo $follow->display_linked();
+HtmlInput::button_action_add_concerned_card( $follow->ag_id);
+
+$response = ob_get_clean();
+
+$html = escape_xml($response);
+header('Content-type: text/xml; charset=UTF-8');
+echo <<<EOF
+<?xml version="1.0" encoding="UTF-8"?>
+<data>
+<ctl>unused</ctl>
+<code>$html</code>
+</data>
+EOF;
+?>        
\ No newline at end of file
diff --git a/include/ajax/ajax_action_save_concerned.php 
b/include/ajax/ajax_action_save_concerned.php
new file mode 100644
index 0000000..e1600a9
--- /dev/null
+++ b/include/ajax/ajax_action_save_concerned.php
@@ -0,0 +1,47 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright 2014 Author Dany De Bontridder address@hidden
+
+// require_once '.php';
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+/**
+ * Insert into follow-up the card (f_id) for the action_gestion (ag_id)
+ */
+require_once 'class/class_follow_up.php';
+$follow=new Follow_Up($cn,$ag_id);
+$follow->insert_linked_card($f_id);
+/**
+ * Display all the linked card
+ */
+
+ob_start();
+$follow->display_linked();
+echo HtmlInput::button_action_add_concerned_card( $ag_id);
+$response = ob_get_clean();
+$html = escape_xml($response);
+header('Content-type: text/xml; charset=UTF-8');
+echo <<<EOF
+<?xml version="1.0" encoding="UTF-8"?>
+<data>
+<ctl>unused</ctl>
+<code>$html</code>
+</data>
+EOF;
+?>        
\ No newline at end of file
diff --git a/include/ajax/ajax_add_concerned_card.php 
b/include/ajax/ajax_add_concerned_card.php
new file mode 100644
index 0000000..7f6e22a
--- /dev/null
+++ b/include/ajax/ajax_add_concerned_card.php
@@ -0,0 +1,83 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+// Copyright 2014 Author Dany De Bontridder address@hidden
+// require_once '.php';
+if (!defined('ALLOWED'))
+    die('Appel direct ne sont pas permis');
+ob_start();
+
+$ag_id=HtmlInput::default_value_get("ag_id", "0");
+
+if ($ag_id == 0 )    throw new Exception('ag_id is null');
+
+require_once('class/class_acc_ledger.php');
+$r=HtmlInput::title_box(_("Détail fiche"), 'search_card');
+
+$r.='<form id="search_card1_frm" method="GET" 
onsubmit="action_add_concerned_card(this);return false;">';
+$q=new IText('query');
+$q->value=(isset($query))?$query:'';
+$r.='<span style="margin-left:50px">';
+$r.=_('Fiche contenant').HtmlInput::infobulle(19);
+$r.=$q->input();
+$r.=HtmlInput::submit('fs', _('Recherche'), "", "smallbutton");
+$r.='</span>';
+$r.=dossier::hidden().HtmlInput::hidden('op', 'add_concerned_card');
+$r.=HtmlInput::request_to_hidden(array('ag_id'));
+$r.='</form>';
+$query=HtmlInput::default_value_get("query", "");
+$sql_array['query']=$query;
+$sql_array['typecard']='all';
+
+$fiche=new Fiche($cn);
+/* Build the SQL and show result */
+$sql=$fiche->build_sql($sql_array);
+
+
+/* We limit the search to MAX_SEARCH_CARD records */
+$sql=$sql.' order by vw_name limit '.MAX_SEARCH_CARD;
+$a=$cn->get_array($sql);
+for ($i=0; $i<count($a); $i++)
+{
+    $array[$i]['quick_code']=$a[$i]['quick_code'];
+    $array[$i]['name']=h($a[$i]['vw_name']);
+    $array[$i]['accounting']=$a[$i]['accounting'];
+    $array[$i]['first_name']=h($a[$i]['vw_first_name']);
+    $array[$i]['description']=h($a[$i]['vw_description']);
+    
$array[$i]['javascript']=sprintf("action_save_concerned(%d,'%s','%s')",$gDossier,$a[$i]['f_id'],$ag_id);
+}//foreach
+
+
+echo $r;
+require_once('template/card_result.php');
+$response=ob_get_contents();
+ob_end_clean();
+
+
+$html=escape_xml($response);
+if ( !headers_sent() ) { header('Content-type: text/xml; charset=UTF-8');} 
else {echo $response;echo $html;}
+echo <<<EOF
+<?xml version="1.0" encoding="UTF-8"?>
+<data>
+<ctl>unused</ctl>
+<code>$html</code>
+</data>
+EOF;
+?>
\ No newline at end of file
diff --git a/include/ajax_add_menu.php b/include/ajax/ajax_add_menu.php
similarity index 100%
rename from include/ajax_add_menu.php
rename to include/ajax/ajax_add_menu.php
diff --git a/include/ajax_admin.php b/include/ajax/ajax_admin.php
similarity index 100%
rename from include/ajax_admin.php
rename to include/ajax/ajax_admin.php
diff --git a/include/ajax/ajax_anc_key_choice.php 
b/include/ajax/ajax_anc_key_choice.php
new file mode 100644
index 0000000..bf6cde7
--- /dev/null
+++ b/include/ajax/ajax_anc_key_choice.php
@@ -0,0 +1,53 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+/**
+ * @file
+ * @brief show the available distribution keys for analytic activities. 
Expected
+ * parameter are 
+ *  - t for the table id
+ *  - amount is the amount to distributed
+ *
+ */
+// Copyright (2014) Author Dany De Bontridder address@hidden
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+$amount=HtmlInput::default_value_get("amount", 0);
+$table_id=HtmlInput::default_value_get("t", "");
+$ledger=HtmlInput::default_value_get('led',0);
+
+if ($table_id == "" || isNumber($amount) == 0 || isNumber($ledger) == 0) die 
('Invalid Parameter');
+
+require_once 'class/class_anc_key.php';
+
+ob_start();
+echo HtmlInput::title_box(_("Choix d'une clef"), 'div_anc_key_choice');
+
+Anc_Key::display_choice($amount,$table_id,$ledger);
+
+echo HtmlInput::button_close('div_anc_key_choice');
+$response = ob_get_clean();
+$html = escape_xml($response);
+header('Content-type: text/xml; charset=UTF-8');
+echo <<<EOF
+<?xml version="1.0" encoding="UTF-8"?>
+<data>
+<ctl></ctl>
+<code>$html</code>
+</data>
+EOF;
+?>        
\ No newline at end of file
diff --git a/include/ajax/ajax_anc_key_compute.php 
b/include/ajax/ajax_anc_key_compute.php
new file mode 100644
index 0000000..58c5e37
--- /dev/null
+++ b/include/ajax/ajax_anc_key_compute.php
@@ -0,0 +1,61 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright 2014 Author Dany De Bontridder address@hidden
+// @brief Compute the amount. This file compute the amount and distribute it
+// following the given distribution key given in parameter.
+// Parameters are :
+//   - gDossier
+//   - t the element HTML to use as target
+//   - amount the amount to distribute
+//   - key the Distribution key to use
+// 
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+
+require_once NOALYSS_INCLUDE.'/class/class_anc_key.php';
+ob_start();
+/////
+$key=HtmlInput::default_value_get('key',0);
+$amount=HtmlInput::default_value_get('amount',0);
+$target=HtmlInput::default_value_get('t','');
+
+if (        isNumber($key)== 0
+        ||  isNumber($amount) ==0
+        || $target==''
+    ) 
+{
+    die ('Invalid parameter');
+}
+
+$compute_key=new Anc_Key($key);
+
+$compute_key->fill_table($target,$amount);
+
+////
+$response = ob_get_clean();
+$html = escape_xml($response);
+header('Content-type: text/xml; charset=UTF-8');
+echo <<<EOF
+<?xml version="1.0" encoding="UTF-8"?>
+<data>
+<ctl></ctl>
+<code>$html</code>
+</data>
+EOF;
+?>        
\ No newline at end of file
diff --git a/include/ajax/ajax_anc_search.php b/include/ajax/ajax_anc_search.php
new file mode 100644
index 0000000..db7321e
--- /dev/null
+++ b/include/ajax/ajax_anc_search.php
@@ -0,0 +1,98 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ *
+ * \brief show a screen to search a ca account
+ *
+ */
+
+// parameter are gDossier , c1 : the control id to update,
+// c2 the control id which contains the pa_id
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+require_once NOALYSS_INCLUDE.'/lib/class_itext.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ihidden.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ibutton.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+require_once NOALYSS_INCLUDE.'/class/class_anc_account.php';
+require_once NOALYSS_INCLUDE.'/class/class_anc_plan.php';
+require_once NOALYSS_INCLUDE.'/lib/function_javascript.php';
+
+echo HtmlInput::title_box(_("Recherche activité"), $ctl);
+
+//------------- FORM ----------------------------------
+echo '<FORM id="anc_search_form" METHOD="GET" 
onsubmit="search_anc_form(this);return false">';
+echo '<span>'._('Recherche').':';
+
+$texte=new IText('plabel');
+$texte->value=HtmlInput::default_value('plabel',"", $_GET);
+echo $texte->input();
+echo '</span>';
+echo dossier::hidden();
+$hid=new IHidden();
+echo $hid->input("c1",$_REQUEST['c1']);
+echo $hid->input("c2",$_REQUEST['c2']);
+echo $hid->input("go");
+echo HtmlInput::submit("go",_("Recherche"));
+echo '</form>';
+//------------- FORM ----------------------------------
+if ( isset($_REQUEST['go']))
+{
+    $cn=Dossier::connect();
+    $plan=new Anc_Plan($cn,$_REQUEST['c2']);
+    $plan->pa_id=$_REQUEST['c2'];
+    if ( $plan->exist()==false)
+        exit(_("Ce plan n'existe pas"));
+
+    $sql="select po_name , po_description from poste_analytique ".
+         "where pa_id=$1 and ".
+         " (po_name ~* $2 or po_description ~* $3) order by po_name";
+    
$array=$cn->get_array($sql,array($_REQUEST['c2'],$_REQUEST['plabel'],$_REQUEST['plabel']));
+
+    if (empty($array) == true)
+    {
+        echo _("Aucun poste trouvé");
+        return;
+    }
+    $button=new IButton();
+    $button->name=_("Choix");
+    $button->label=_("Choix");
+
+    echo '<table>';
+    foreach ($array as $line)
+    {
+        $button->javascript=sprintf("$('%s').value='%s';removeDiv('%s')",
+                                    $_REQUEST['c1'],
+                                    $line['po_name'],$ctl);
+        echo '<tr>'.
+        '<td>'.
+        $button->input().
+        '</td>'.
+        '<td>'.
+        h($line['po_name']).
+        '</td><td>'.
+        h($line['po_description']).
+        '</tr>';
+    }
+    echo '</table>';
+}
diff --git a/include/ajax/ajax_auto_anc_card.php 
b/include/ajax/ajax_auto_anc_card.php
new file mode 100644
index 0000000..912bd1f
--- /dev/null
+++ b/include/ajax/ajax_auto_anc_card.php
@@ -0,0 +1,31 @@
+<?php 
+//This file is part of NOALYSS and is under GPL 
+//see licence.txt
+
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/class/class_user.php';
+$cn=new Database($_GET['gDossier']);
+
+
+if ( isset($_REQUEST['pa_id']) )
+{   
+    $res=$cn->exec_sql("select po_name,po_description from  poste_analytique 
where pa_id=$1 ~* and (po_description ~* $2 or po_name ~* $3 order by po_id 
limit 12",
+        array($_REQUEST['pa_id'],$_POST['anccard'],$_POST['anccard']));
+}
+else
+{
+       $res=$cn->exec_sql("select po_name,po_description from  
poste_analytique where po_description ~* $1 or po_name ~* $2 order by po_id 
limit 12 ",
+        array($_POST['anccard'],$_POST['anccard']));
+}
+$nb=Database::num_row($res);
+       echo "<ul>";
+for ($i = 0;$i< $nb;$i++)
+{
+       $row=Database::fetch_array($res,$i);
+       echo "<li>";
+       echo $row['po_name'];
+       echo '<span class="informal"> '.$row['po_description'].'</span></li>';
+}
+       echo "</ul>";
+?>
\ No newline at end of file
diff --git a/include/ajax/ajax_bank_saldo.php b/include/ajax/ajax_bank_saldo.php
new file mode 100644
index 0000000..a74b5eb
--- /dev/null
+++ b/include/ajax/ajax_bank_saldo.php
@@ -0,0 +1,75 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief respond ajax request, the get contains
+ *  the value :
+ * - l for ledger
+ * - gDossier
+ * Must return at least tva, htva and tvac
+
+ */
+
+/*!\file
+ * \brief get the saldo of a account
+ * the get variable are :
+ *  - l the jrn id
+ *  - ctl the ctl where to get the quick_code
+ */
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+require_once NOALYSS_INCLUDE.'/class/class_user.php';
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+require_once NOALYSS_INCLUDE.'/class/class_fiche.php';
+extract($_GET);
+/* check the parameters */
+foreach ( array('j','ctl') as $a )
+{
+    if ( ! isset(${$a}) )
+    {
+        echo "missing $a";
+        return;
+    }
+}
+
+if ( $g_user->check_jrn($_GET['j'])=='X' ) return '{"saldo":"0"}';
+/*  make a filter on the exercice */
+
+$filter_year="  j_tech_per in (select p_id from parm_periode ".
+             "where p_exercice='".$g_user->get_exercice()."')";
+
+
+$id=$cn->get_value('select jrn_def_bank from jrn_def where 
jrn_def_id=$1',array($_GET['j']));
+$acc=new Fiche($cn,$id);
+
+$res=$acc->get_bk_balance($filter_year." and ( trim(jr_pj_number) != '' and 
jr_pj_number is not null)" );
+
+
+if ( empty($res) ) return '{"saldo":"0"}';
+$solde=$res['solde'];
+if ( $res['debit'] < $res['credit'] ) $solde=$solde*(-1);
+
+//header("Content-type: text/html; charset: utf8",true);
+echo '{"saldo":"'.$solde.'"}';
+
+
+
+?>
+
diff --git a/include/ajax_bookmark.php b/include/ajax/ajax_bookmark.php
similarity index 100%
rename from include/ajax_bookmark.php
rename to include/ajax/ajax_bookmark.php
diff --git a/include/ajax_boxcard_search.php 
b/include/ajax/ajax_boxcard_search.php
similarity index 100%
rename from include/ajax_boxcard_search.php
rename to include/ajax/ajax_boxcard_search.php
diff --git a/include/ajax/ajax_calendar_zoom.php 
b/include/ajax/ajax_calendar_zoom.php
new file mode 100644
index 0000000..f30e0f6
--- /dev/null
+++ b/include/ajax/ajax_calendar_zoom.php
@@ -0,0 +1,46 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+// Copyright Author Dany De Bontridder address@hidden
+if ( !defined ('ALLOWED') )  die('Appel direct ne sont pas permis');
+require_once NOALYSS_INCLUDE.'/class/class_calendar.php';
+ob_start();
+if ( $notitle== 0 ) echo HtmlInput::title_box(_("Calendrier"), 
"calendar_zoom_div");
+$cal=new Calendar();
+$in=HtmlInput::default_value_get('in',"");
+$notitle=HtmlInput::default_value_get('notitle',"0");
+if ( $in == "") {
+    $in=$cal->get_preference();
+}
+$cal->set_periode($in);
+echo $cal->zoom($distype,$notitle);
+$response=  ob_get_clean();
+
+$html=escape_xml($response);
+header('Content-type: text/xml; charset=UTF-8');
+echo <<<EOF
+<?xml version="1.0" encoding="UTF-8"?>
+<data>
+<ctl></ctl>
+<html>$html</html>
+</data>
+EOF;
+exit();
+
+
+?>
diff --git a/include/ajax/ajax_create_menu.php 
b/include/ajax/ajax_create_menu.php
new file mode 100644
index 0000000..856c1b3
--- /dev/null
+++ b/include/ajax/ajax_create_menu.php
@@ -0,0 +1,15 @@
+<?php
+//This file is part of NOALYSS and is under GPL 
+//see licence.txt
+
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+require_once NOALYSS_INCLUDE.'/class/class_menu_ref.php';
+$msg=_("Création");
+$m=new Menu_Ref($cn);
+echo '<form method="POST" id="ajax_create_menu_frm" onsubmit="return 
confirm_box(this,\''._('Vous confirmez ?').'\')">';
+echo HtmlInput::hidden('create_menu', 1);
+require_once 'template/menu_detail.php';
+echo HtmlInput::submit('create_menubt',_('Sauver'));
+echo HtmlInput::button_close('divmenu');
+echo '</form>';
+?>
diff --git a/include/ajax/ajax_display_submenu.php 
b/include/ajax/ajax_display_submenu.php
new file mode 100644
index 0000000..3d5908c
--- /dev/null
+++ b/include/ajax/ajax_display_submenu.php
@@ -0,0 +1,98 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright 2015 Author Dany De Bontridder address@hidden
+/** 
+ * @brief call from ajax : display submenu
+ * Security : only user with the menu CFGPRO
+ * display the submenu of a menu or a module
+ * It expects 2 parameters  = p_profile (profile.p_id) and the dep 
(menu_ref.me_code)
+ */
+// require_once '.php';
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+
+// Security 
+if ( $g_user->check_module('CFGPRO') == 0 ) die();
+
+// Check parameter
+$module=HtmlInput::default_value_get("dep", "");
+$p_level=HtmlInput::default_value_get("p_level", 0);
+$p_id=HtmlInput::default_value_get('p_profile',-1);
+
+if ($module == ""
+        || $p_id == -1 
+        || isNumber($p_id) == 0
+        || isNumber($p_level) == 0
+        )
+{
+    echo _('Paramètre invalide');
+    return;
+}
+
+require_once NOALYSS_INCLUDE.'/class/class_profile_menu.php';
+$p_level++;
+$profile=new Profile_Menu($cn);
+$profile->p_id=$p_id;
+$profile->display_module_menu($module,$p_level);
+
+////////////////////////////////////////////////////////////////////////////////
+// EXAMPLE
+////////////////////////////////////////////////////////////////////////////////
+/*
+if ($ac == 'save') // operation
+{
+    
+    $cn=new Database(dossier::id());
+    $todo=new Todo_List($cn);
+     $id=HtmlInput::default_value_get("id", 0); // get variable
+    $todo->set_parameter("id",$id);
+    if ($id <> 0 ) { $todo->load(); }
+    else
+    {
+        $todo->set_parameter("owner", $_SESSION['g_user']);
+    }
+    
+    $todo->set_parameter("date", HtmlInput::default_value_get("p_date_todo", 
""));
+    $todo->set_parameter("title", HtmlInput::default_value_get("p_title", ""));
+    $todo->set_parameter("desc", HtmlInput::default_value_get("p_desc", ""));
+    $todo->set_is_public(HtmlInput::default_value_get("p_public", "N"));
+    
+    if ( $todo->get_parameter('owner') == $_SESSION['g_user'] ) $todo->save();
+    $todo->load();
+ //----------------------------------------------------------------
+ // Answer in XML
+     header('Content-type: text/xml; charset=UTF-8');
+    $dom=new DOMDocument('1.0','UTF-8');
+    $tl_id=$dom->createElement('tl_id',$todo->get_parameter('id'));
+    
$tl_content=$dom->createElement('row',$todo->display_row('class="odd"','N'));
+     $root=$dom->createElement("root");
+     $todo_class=$todo->get_class();
+     $todo_class=($todo_class=="")?' odd ':$todo_class;
+     $class=$dom->createElement("style",$todo_class);
+    
+    $root->appendChild($tl_id);
+    $root->appendChild($tl_content);
+    $root->appendChild($class);
+    $dom->appendChild($root);
+   
+    echo $dom->saveXML();
+    exit();
+}
+  */
+?>        
\ No newline at end of file
diff --git a/include/ajax/ajax_fiche_def_detail.php 
b/include/ajax/ajax_fiche_def_detail.php
new file mode 100644
index 0000000..fbd5fc0
--- /dev/null
+++ b/include/ajax/ajax_fiche_def_detail.php
@@ -0,0 +1,47 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/**
+ * @file
+ * @brief show detail of a fiche_def (category of card) + Attribut
+ *
+ */
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+require_once NOALYSS_INCLUDE.'/class/class_fiche_def.php';
+require_once NOALYSS_INCLUDE.'/lib/class_tool_uos.php';
+global $g_user;
+
+$g_user->can_request(FICCAT,0);
+
+$fd=new Fiche_Def($cn,$_GET['id']);
+if ( $_GET['id'] > 0 )
+{
+
+       echo $fd->input_detail();
+       echo HtmlInput::button("retour_b", _("Retour à la liste"), 
"onclick=\"$('detail_category_div').hide();$('list_cat_div').show()\"");
+}
+else
+{
+       $fd->input_new();
+
+}
+?>
diff --git a/include/ajax/ajax_gestion.php b/include/ajax/ajax_gestion.php
new file mode 100644
index 0000000..a7f1e3a
--- /dev/null
+++ b/include/ajax/ajax_gestion.php
@@ -0,0 +1,129 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+// Copyright 2015 Author Dany De Bontridder address@hidden
+/**
+ * @file
+ * @brief display a box containing last actions
+ */
+if (!defined('ALLOWED'))
+    die('Appel direct ne sont pas permis');
+if ($op=='action_show')
+{
+    /**
+     * display action
+     */
+    require_once NOALYSS_INCLUDE.'/class/class_follow_up.php';
+    $gestion=new Follow_Up($cn);
+    $array=$gestion->get_last(25);
+    $len_array=count($array);
+    require_once NOALYSS_INCLUDE.'/template/action_show.php';
+    return;
+}
+if ($op=='action_add')
+{
+    require_once NOALYSS_INCLUDE.'/class/class_follow_up.php';
+    $gestion=new Follow_Up($cn);
+    $gestion->display_short();
+    return;
+}
+if ($op=='action_save')
+{
+    require_once NOALYSS_INCLUDE.'/class/class_follow_up.php';
+
+    /**
+     * save info from the get
+     */
+    $date_event=HtmlInput::default_value_get("date_event", -1);
+    $dest=HtmlInput::default_value_get("dest", "");
+    $event_group=HtmlInput::default_value_get("event_group", 0);
+    $event_priority=HtmlInput::default_value_get("event_priority", 0);
+    $title=HtmlInput::default_value_get("title_event", NULL);
+    $summary=HtmlInput::default_value_get("summary", "");
+    $type_event=HtmlInput::default_value_get('type_event', -1);
+    /*
+     * Check if data are valid
+     */
+    try
+    {
+        if ($date_event==-1||isDate($date_event)==0)
+            throw new Exception(_('Date invalide'));
+        if (trim($dest)=="")
+            $dest_id=NULL;
+        else
+        {
+            $fiche=new Fiche($cn);
+            $fiche->get_by_qcode($dest);
+            $dest_id=$fiche->id;
+            if ($dest_id==0)
+                throw new Exception(_('Destinataire invalide'));
+        }
+        if ($type_event==-1)
+            throw new Exception(_('Type invalide'));
+        if (trim($title)=="")
+            throw new Exception(_('Aucun titre'));
+    }
+    catch (Exception $ex)
+    {
+        header('Content-type: text/xml; charset=UTF-8');
+        $dom=new DOMDocument('1.0', 'UTF-8');
+        $xml_content=$dom->createElement('content', $ex->getMessage());
+        $xml_status=$dom->createElement('status', "NOK");
+        $root=$dom->createElement("root");
+        $root->appendChild($xml_content);
+        $root->appendChild($xml_status);
+        $dom->appendChild($root);
+        echo $dom->saveXML();
+        return;
+    }
+    /*
+     * Save data
+     */
+    $gestion=new Follow_Up($cn);
+    $gestion->ag_priority=$event_priority;
+    $gestion->ag_title=$title;
+    $gestion->ag_dest=$event_group;
+    $gestion->ag_type=$type_event;
+    $gestion->f_id_dest=$dest_id;
+    $gestion->ag_state=3;
+    $gestion->dt_id=$type_event;
+    $gestion->ag_comment=h($summary);
+    $gestion->ag_timestamp=$date_event;
+    $gestion->ag_remind_date=$date_event;
+    $content=_('Sauvé');
+    $status='OK';
+    try {
+        $gestion->save_short();
+    } catch (Exception $ex)
+    {
+        $content=$ex->getMessage();
+        $status='NOK';
+    }
+    header('Content-type: text/xml; charset=UTF-8');
+    $dom=new DOMDocument('1.0', 'UTF-8');
+    $xml_content=$dom->createElement('content', _("Sauvé"));
+    $xml_status=$dom->createElement('status', "OK");
+    $root=$dom->createElement("root");
+    $root->appendChild($xml_content);
+    $root->appendChild($xml_status);
+    $dom->appendChild($root);
+    echo $dom->saveXML();
+    return;
+}
\ No newline at end of file
diff --git a/include/ajax_get_menu_detail.php 
b/include/ajax/ajax_get_menu_detail.php
similarity index 100%
rename from include/ajax_get_menu_detail.php
rename to include/ajax/ajax_get_menu_detail.php
diff --git a/include/ajax/ajax_get_profile.php 
b/include/ajax/ajax_get_profile.php
new file mode 100644
index 0000000..18f82cd
--- /dev/null
+++ b/include/ajax/ajax_get_profile.php
@@ -0,0 +1,137 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/**
+ * @file
+ * @brief show the profile detail, included from ajax_misc.php
+ * @see ajax_misc.php scripts.js profile.inc.php
+ *
+ */
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+
+// Security 
+if ( $g_user->check_module('CFGPRO') == 0 ) die();
+
+require_once NOALYSS_INCLUDE.'/database/class_profile_sql.php';
+require_once NOALYSS_INCLUDE.'/class/class_profile_menu.php';
+require_once NOALYSS_INCLUDE.'/lib/class_html_input.php';
+$p_id=HtmlInput::default_value_request('p_id', -1);
+$profile=new Profile_sql($cn,$p_id);
+$gDossier=Dossier::id();
+$add_impression=HtmlInput::button("add", _("Ajout 
Menu"),"onclick=\"add_menu({dossier:$gDossier,p_id:$p_id,type:'pr'})\"");
+$call_tab=HtmlInput::default_value_post('tab', 'none');
+$a_tab=array('profile_gen_div'=>'tabs','profile_menu_div'=>'tabs','profile_print_div'=>'tabs','profile_gestion_div'=>'tabs','profile_repo_div'=>'tabs');
+$a_tab[$call_tab]='tabs_selected';
+?>
+<h1>Profil <?php echo $profile->p_name?></h1>
+<?php
+    echo HtmlInput::anchor(_('Retour'), "", " onclick = \" 
$('detail_profile').hide();$('list_profile').show(); \" ", 'class="line"');
+?>
+<?php if ($p_id > 0 ) : ?>
+<ul class="tabs">
+    
+    <li class="<?php echo $a_tab['profile_gen_div']?>"><a 
href="javascript:void(0)"  
onclick="unselect_other_tab(this.parentNode.parentNode);this.parentNode.className='tabs_selected';profile_show('profile_gen_div')"><?php
 echo _('Nom')?></a></li>
+    <li class="<?php echo $a_tab['profile_menu_div']?>"><a 
href="javascript:void(0)"  
onclick="unselect_other_tab(this.parentNode.parentNode);this.parentNode.className='tabs_selected';profile_show('profile_menu_div')"><?php
 echo _('Détail Menus')?></a></li>
+    <li class="<?php echo $a_tab['profile_print_div']?>"><a 
href="javascript:void(0)" 
onclick="unselect_other_tab(this.parentNode.parentNode);this.parentNode.className='tabs_selected';profile_show('profile_print_div')"><?php
 echo _('Détail Impressions')?></a></li>
+    <li class="<?php echo $a_tab['profile_gestion_div']?>"><a 
href="javascript:void(0)" style="" 
onclick="unselect_other_tab(this.parentNode.parentNode);this.parentNode.className='tabs_selected';profile_show('profile_gestion_div')"><?php
 echo _('Action Gestion')?> </a></li>
+    <li class="<?php echo $a_tab['profile_repo_div']?>"><a 
href="javascript:void(0)"  
onclick="unselect_other_tab(this.parentNode.parentNode);this.parentNode.className='tabs_selected';profile_show('profile_repo_div')"><?php
 echo _('Dépôts')?></a>&nbsp;
+</ul>
+<?php endif; ?>
+
+<?php 
+$id=HtmlInput::hidden('p_id',$profile->p_id);
+$name=new IText("p_name",$profile->p_name);
+$desc=new IText("p_desc",$profile->p_desc);
+$with_calc=new ICheckBox("with_calc","t");
+$with_calc->set_check($profile->with_calc);
+
+$with_direct_form=new ICheckBox("with_direct_form","t");
+$with_direct_form->set_check($profile->with_direct_form);
+
+// If $p_id == -1 it is a new profile
+if ( $p_id > 0 )
+{
+       echo '<div style="display:none" id="profile_gen_div">';
+}
+else
+{
+       echo '<div  class="myfieldset" id="profile_gen_div">';
+}
+echo '<form method="POST" id="profile_save_name_frm" onsubmit="return 
confirm_box(this,\'vous confirmez\')">';
+echo HtmlInput::hidden('tab','profile_gen_div');
+echo HtmlInput::hidden('p_id',$profile->p_id);
+echo HtmlInput::hidden('save_name',1);
+require_once("template/profile.php");
+echo HtmlInput::submit("save_namebt",_("Modifier"));
+echo '</form>';
+if ($profile->p_id > 0)
+{
+       echo '<form method="POST" id="profile_clone_frm" onsubmit="return 
confirm_box(this,\''._("vous confirmez").'\')">';
+
+       echo _('Vous pouvez aussi copier ce profil et puis le corriger');
+
+       echo HtmlInput::hidden('p_id', $profile->p_id);
+       echo HtmlInput::hidden('clone', 1);
+       echo HtmlInput::submit("clonebt", "Copier");
+       echo '</form>';
+
+       echo '<form method="POST" id="delete_profile_frm" onsubmit="return 
confirm_box(this,\''._("vous confirmez").'\')">';
+
+       echo _('Effacer ce profil');
+
+       echo HtmlInput::hidden('p_id', $profile->p_id);
+       echo HtmlInput::hidden('delete_profil', 1);
+       echo HtmlInput::submit("delete_profil", _("Effacer ce profil"));
+       echo '</form>';
+        echo '</div>';
+        echo '<div class="myfieldset"  style="display:none" 
id="profile_menu_div">';
+       //Menu / Module /plugin in this profile
+       echo "<h1 class=\"legend\">"._("Menu")."</h2>";
+       $profile_menu = new Profile_Menu($cn);
+        $profile_menu->p_id=$p_id;
+       $profile_menu->display_profile_menu_detail();
+        echo '</div>';
+        echo '<div class="myfieldset"  style="display:none" 
id="profile_print_div">';
+       echo "<h1 class=\"legend\">"._("Impression")."</h1>";
+       $profile_menu->printing();
+       echo $add_impression;
+        echo '</div>';
+        echo '<div class="myfieldset"  style="display:none" 
id="profile_gestion_div">';
+       echo "<h1 class=\"legend\">".('Groupe gestion')."</h1>";
+       $profile_menu->available_profile();
+        echo '</div>';
+        echo '<div class="myfieldset"  style="display:none" 
id="profile_repo_div">';
+       echo "<h1 class=\"legend\">"._("Dépôt de stock accessible")."</h1>";
+       $profile_menu->available_repository();
+        echo '</div>';
+        if ( isset ($_POST['tab']))
+        {
+            echo create_script("profile_show('".$_POST['tab']."');");
+        }
+}
+else
+{
+        echo '</div>';
+}
+?>
+
+
diff --git a/include/ajax/ajax_get_receipt.php 
b/include/ajax/ajax_get_receipt.php
new file mode 100644
index 0000000..1f6159b
--- /dev/null
+++ b/include/ajax/ajax_get_receipt.php
@@ -0,0 +1,65 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief respond ajax request, the get contains
+ *  the value :
+ * - l for ledger
+ * - gDossier
+ * Must return at least tva, htva and tvac
+
+ */
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+
+require_once NOALYSS_INCLUDE.'/constant.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_ledger.php';
+require_once NOALYSS_INCLUDE.'/class/class_user.php';
+
+// Check if the needed field does exist
+extract ($_GET);
+foreach (array('l','gDossier') as $a)
+{
+    if ( ! isset (${$a}) )
+    {
+        echo "error $a is not set ";
+        exit();
+    }
+
+}
+if ( is_numeric($l) == false  )
+{
+    exit();
+}
+
+
+$Ledger=new Acc_Ledger($cn,$l);
+$prop=$Ledger->get_propertie();
+$pj_seq=$Ledger->guess_pj();
+$string='{"pj":"'.$pj_seq.'"}';
+
+header("Content-type: text/json; charset: utf8",true);
+echo $string;
+
+
+?>
+
diff --git a/include/ajax/ajax_ledger_show.php 
b/include/ajax/ajax_ledger_show.php
new file mode 100644
index 0000000..6afa939
--- /dev/null
+++ b/include/ajax/ajax_ledger_show.php
@@ -0,0 +1,35 @@
+<?php
+//This file is part of NOALYSS and is under GPL 
+//see licence.txt
+
+/**
+ * @brief
+ * Show a div for selecting ledger
+ * return a html code for creating a window
+ * parameter 
+ *   - type 
+ *   - div
+ *   - nbjrn
+ *   - r_jrn[]
+ */
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+
+require_once NOALYSS_INCLUDE.'/class/class_acc_ledger.php';
+require_once NOALYSS_INCLUDE.'/lib/class_html_input.php';
+if ( ! isset ($r_jrn)) { $r_jrn=null;}
+$ctl='div_jrn'.$div;
+ob_start();
+echo HtmlInput::select_ledger($type,$r_jrn, $div);
+
+$response = ob_get_clean();
+$html = escape_xml($response);
+header('Content-type: text/xml; charset=UTF-8');
+echo <<<EOF
+<?xml version="1.0" encoding="UTF-8"?>
+<data>
+<ctl>$ctl</ctl>
+<code>$html</code>
+</data>
+EOF;
+exit();
+?>    
\ No newline at end of file
diff --git a/include/ajax/ajax_min_row.php b/include/ajax/ajax_min_row.php
new file mode 100644
index 0000000..05302cd
--- /dev/null
+++ b/include/ajax/ajax_min_row.php
@@ -0,0 +1,48 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/**
+ * @file
+ * @brief
+ *
+ */
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+require_once NOALYSS_INCLUDE.'/class/class_user.php';
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+extract($_GET);
+/* check the parameters */
+foreach ( array('j','ctl') as $a )
+{
+    if ( ! isset(${$a}) )
+    {
+        echo "missing $a";
+        return;
+    }
+}
+
+if ( $g_user->check_jrn($_GET['j'])=='X' ) { echo  '{"row":"0"}';exit();}
+
+$row=$cn->get_value('select jrn_deb_max_line from jrn_def where 
jrn_def_id=$1',array($_GET['j']));
+
+echo '{"row":"'.$row.'"}';
+
+?>
diff --git a/include/ajax/ajax_mod_document.php 
b/include/ajax/ajax_mod_document.php
new file mode 100644
index 0000000..eaf004e
--- /dev/null
+++ b/include/ajax/ajax_mod_document.php
@@ -0,0 +1,52 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief show the detail of a document and let you modify it
+ */
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+require_once NOALYSS_INCLUDE.'/class/class_document_modele.php';
+
+  /* 1. Check security */
+$cn=new Database(dossier::id());
+  /* 2. find the document */
+$doc=new Document_Modele($cn,$id);
+
+  /* 3. display it */
+$doc->load();
+ob_start();
+require(NOALYSS_INCLUDE.'/template/modele_document.php');
+
+$html=ob_get_contents();
+ob_end_clean();
+$html=escape_xml($html);
+header('Content-type: text/xml; charset=UTF-8');
+
+echo <<<EOF
+<?xml version="1.0" encoding="UTF-8"?>
+<data>
+<ctl>mod_doc</ctl>
+<code>$html</code>
+</data>
+EOF;
+exit();
diff --git a/include/ajax/ajax_mod_menu.php b/include/ajax/ajax_mod_menu.php
new file mode 100644
index 0000000..b3136d4
--- /dev/null
+++ b/include/ajax/ajax_mod_menu.php
@@ -0,0 +1,17 @@
+<?php
+//This file is part of NOALYSS and is under GPL 
+//see licence.txt
+
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+require_once NOALYSS_INCLUDE.'/class/class_menu_ref.php';
+$m=new Menu_Ref($cn,$me_code);
+$msg="Modification ".$m->me_code.' '.h($m->me_menu);
+echo '<form method="POST" id="ajax_mod_menu_frm" onsubmit="return 
confirm_box(this,\'Vous confirmez ?\')">';
+echo HtmlInput::hidden('modify_menu', 1);
+
+require_once NOALYSS_INCLUDE.'/template/menu_detail.php';
+
+echo HtmlInput::submit('modify_menutb',_('Sauver'));
+echo HtmlInput::button_close('divmenu');
+echo '</form>';
+?>
diff --git a/include/ajax/ajax_mod_periode.php 
b/include/ajax/ajax_mod_periode.php
new file mode 100644
index 0000000..b2d9f15
--- /dev/null
+++ b/include/ajax/ajax_mod_periode.php
@@ -0,0 +1,104 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+// Copyright Author Dany De Bontridder address@hidden
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+require_once NOALYSS_INCLUDE.'/class/class_periode.php';
+
+/**\file
+ * \brief display or save a periode
+ * variable received $op, $cn $g_user
+ */
+$err = 0;
+$html = '';
+/* we check the security */
+switch ($op)
+{
+    case 'input_per':
+        $per = new Periode($cn, $_GET['p_id']);
+        $per->load();
+        $limit = $per->get_date_limit($_GET['p_id']);
+
+        $p_start = new IDate('p_start');
+        $p_start->value = $limit['p_start'];
+        $p_end = new IDate('p_end');
+        $p_end->value = $limit['p_end'];
+        $p_exercice = new INum('p_exercice');
+        $p_exercice->value = $per->p_exercice;
+
+        $html = '';
+        $html.=HtmlInput::anchor_close('mod_periode');
+        $html.=h2info(_('Modification période'));
+        $html.='<p> '._('Modifier les dates de début et fin de 
période').'</p>';
+        $html.='<p class="notice">'._('Cela pourrait avoir un impact sur les 
opérations déjà existantes').'</p>';
+        $html.='<form method="post" onsubmit="return save_periode(this)">';
+        $html.=dossier::hidden();
+        $html.='<table>';
+
+        $html.=tr(td(_(' Début période : ')) . td($p_start->input()));
+        $html.=tr(td(_(' Fin période : ')) . td($p_end->input()));
+        $html.=tr(td(_(' Exercice : ')) . td($p_exercice->input()));
+        $html.='</table>';
+        $html.=HtmlInput::submit('sauver', _('sauver'));
+        $html.=HtmlInput::button('close', _('fermer'), 
'onclick="removeDiv(\'mod_periode\')"');
+        $html.=HtmlInput::hidden('p_id', $_GET['p_id']);
+        $html.='</form>';
+        break;
+    case 'save_per':
+        $per = new Periode($cn, $_POST['p_id']);
+        $per->load();
+        if (isDate($_POST['p_start']) == null ||
+                isDate($_POST['p_end'] == null) ||
+                isNumber($_POST['p_exercice']) == 0 ||
+                $_POST['p_exercice'] > 2099 ||
+                $_POST['p_exercice'] < 2000)
+        {
+            $html = '';
+            $html.=HtmlInput::anchor_close('mod_periode');
+            $html.='<h2 class="info">'._('Modifier les dates de début et fin 
de période').'</h2>';
+            $html.="<div class=\"error\">"._('Erreur date invalide')."</div>";
+
+            $html.=HtmlInput::button('close', _('fermer'), 
'onclick="removeDiv(\'mod_periode\')"');
+        }
+        else
+        {
+            $sql = "update parm_periode set 
p_start=to_date($1,'DD.MM.YYYY'),p_end=to_date($2,'DD.MM.YYYY'),p_exercice=$3 
where p_id=$4";
+            try
+            {
+                $cn->exec_sql($sql, array($_POST['p_start'], $_POST['p_end'], 
$_POST['p_exercice'], $_POST['p_id']));
+                $html = '<h2 class="info"> Modifier les dates de début et fin 
de période</h2>';
+                $html.='<h2 class="notice"> Sauvé </h2>';
+
+                $html.=HtmlInput::button('close', _('Fermer'), 'onclick="      
refresh_window();"');
+            }
+            catch (Exception $e)
+            {
+                $html = alert($e->getTrace(), true);
+            }
+        }
+        break;
+}
+
+$html = escape_xml($html);
+header('Content-type: text/xml; charset=UTF-8');
+echo '<?xml version="1.0" encoding="UTF-8"?>';
+echo '<xml>';
+echo '<data>' . $html . '</data>';
+echo '</xml>';
diff --git a/include/ajax/ajax_mod_predf_op.php 
b/include/ajax/ajax_mod_predf_op.php
new file mode 100644
index 0000000..9c47454
--- /dev/null
+++ b/include/ajax/ajax_mod_predf_op.php
@@ -0,0 +1,76 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/**\file
+ * \brief display a form to change the name of a predefined operation
+ */
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+ob_start();
+require_once NOALYSS_INCLUDE.'/class/class_pre_operation.php';
+$op=new Pre_Operation($cn,$_GET['id']);
+$array=$op->load();
+echo HtmlInput::anchor_close('mod_predf_op');
+echo h2(_('Modification du nom'),' class="title"');
+
+echo '
+    <form method="POST" onsubmit="save_predf_op(this);return false;">';
+$name = new IText('opd_name');
+$name->value = $op->od_name;
+$name->size = 60;
+echo "Nom =" . $name->input();
+$opd_description=new ITextarea('od_description');
+$opd_description->style=' class="itextarea" 
style="width:30em;height:4em;vertical-align:top"';
+$opd_description->value=$op->od_description;
+echo '<p>';
+echo _("Description (max 50 car.)");
+echo $opd_description->input();
+echo '</p>';
+echo dossier::hidden() . HtmlInput::hidden('od_id', $_GET['id']);
+echo "<hr>";
+//////////////////////////////////////////////////////////////////////////////
+// Detail operation 
+//////////////////////////////////////////////////////////////////////////////
+echo $op->display();
+
+
+echo HtmlInput::submit('save', _('Sauve'));
+echo HtmlInput::button('close', _('Annuler'), 
'onclick="removeDiv(\'mod_predf_op\')"');
+echo '</form>';
+
+
+$html1 = ob_get_contents();
+ob_end_clean();
+$html = escape_xml($html1);
+if (headers_sent() ) 
+    { 
+    echo $html1; 
+    }
+else {
+    header('Content-type: text/xml; charset=UTF-8');
+}
+echo <<<EOF
+<?xml version="1.0" encoding="UTF-8"?>
+<data>
+<ctl>mod_predf_op</ctl>
+<code>$html</code>
+</data>
+EOF;
diff --git a/include/ajax/ajax_mod_stock_repo.php 
b/include/ajax/ajax_mod_stock_repo.php
new file mode 100644
index 0000000..12a9ed5
--- /dev/null
+++ b/include/ajax/ajax_mod_stock_repo.php
@@ -0,0 +1,80 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/**
+ * @file
+ * @brief show a depot
+ *
+ */
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+require_once NOALYSS_INCLUDE.'/database/class_stock_sql.php';
+$st=new Stock_Sql($_GET['r_id']);
+
+?>
+<?php echo HtmlInput::title_box("Ajouter un 
dépôt","change_stock_repo_div","close")?>
+       <form method="post">
+               <?php echo HtmlInput::hidden("r_id",$_GET['r_id']);?>
+               <table>
+                       <tr>
+                               <td>
+                                       <?php echo _("Nom");?>
+                               </td>
+                               <td>
+                                       <?php $name=new 
IText("r_name",$st->r_name); echo $name->input();?>
+                               </td>
+                       </tr>
+                       <tr>
+                               <td>
+                                       <?php echo _("Adresse");?>
+                               </td>
+                               <td>
+                                       <?php $name=new 
IText("r_adress",$st->r_adress); echo $name->input();?>
+                               </td>
+                       </tr>
+                       <tr>
+                               <td>
+                                       <?php echo _("Ville");?>
+                               </td>
+                               <td>
+                                       <?php $name=new 
IText("r_city",$st->r_city); echo $name->input();?>
+                               </td>
+                       </tr>
+                       <tr>
+                               <td>
+                                       <?php echo _("Pays");?>
+                               </td>
+                               <td>
+                                       <?php $name=new 
IText("r_country",$st->r_country); echo $name->input();?>
+                               </td>
+                       </tr>
+                       <tr>
+                               <td>
+                                       <?php echo _("Téléphone");?>
+                               </td>
+                               <td>
+                                       <?php $name=new 
IText("r_phone",$st->r_phone); echo $name->input();?>
+                               </td>
+                       </tr>
+
+               </table>
+               <?php echo HtmlInput::submit("mod_stock",_("Sauver"))?>
+       </form>
\ No newline at end of file
diff --git a/include/ajax_navigator.php b/include/ajax/ajax_navigator.php
similarity index 100%
rename from include/ajax_navigator.php
rename to include/ajax/ajax_navigator.php
diff --git a/include/ajax_pcmn_update.php b/include/ajax/ajax_pcmn_update.php
similarity index 100%
rename from include/ajax_pcmn_update.php
rename to include/ajax/ajax_pcmn_update.php
diff --git a/include/ajax_plugin_detail.php 
b/include/ajax/ajax_plugin_detail.php
similarity index 100%
rename from include/ajax_plugin_detail.php
rename to include/ajax/ajax_plugin_detail.php
diff --git a/include/ajax/ajax_preference.php b/include/ajax/ajax_preference.php
new file mode 100644
index 0000000..42a7231
--- /dev/null
+++ b/include/ajax/ajax_preference.php
@@ -0,0 +1,195 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+// Copyright Author Dany De Bontridder address@hidden
+/**\file
+ * \brief this file is always included and then executed
+ *        it permits to change the user preferences
+ */
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+require_once NOALYSS_INCLUDE.'/class/class_user.php';
+require_once NOALYSS_INCLUDE.'/lib/class_iselect.php';
+require_once NOALYSS_INCLUDE.'/lib/class_iperiod.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_report.php';
+require_once NOALYSS_INCLUDE.'/class/class_periode.php';
+echo HtmlInput::title_box(_('Préférence'), 'preference_div');
+echo '<DIV class="content">';
+echo '<p class="notice">';
+echo _("Si vous validez, la page sera rechargée et vous pourriez perdre ce que 
vous faisiez");
+echo '</p>';
+//----------------------------------------------------------------------
+//
+global $g_user;
+
+$g_user=new User($cn);
+$inside_dossier = false;
+
+if (isset($_REQUEST['gDossier']) && $_REQUEST['gDossier']<>0)
+{
+    $g_user->load_global_pref();
+    $msg = "";
+    $cn = new Database($_REQUEST['gDossier']);
+    $g_user->cn = $cn;
+    $inside_dossier = true;
+    $local_pref=$g_user->get_preference();
+}
+//////////////////////////////////////////////////////////////////////////
+// Theme
+//////////////////////////////////////////////////////////////////////////
+
+    $repo = new Database();
+// charge tous les styles
+    $res = $repo->exec_sql("select the_name from theme
+                    order by the_name");
+    $style = new ISelect('style_user');
+    $style->value = $repo->make_array("select the_name,the_name
+       from theme
+       order by the_name");
+    $style->selected =$_SESSION['g_theme'];
+?>
+
+<div class="content" >
+
+    <FORM  METHOD="POST">
+       <fieldset style="margin: 1%"><legend><?php echo _('Options 
Générales')?></legend>
+           <table>
+                <tr>
+                    <td>
+                        <?php echo _('Email')?>
+                    </td>
+                    <td>
+                        <input type="text" name="p_email" value="<?php echo 
$g_user->email?>" class="input_text">
+                    </td>
+                </tr>
+               <tr><td>
+                       Mot de passe :
+                   </td>
+                   <td><input type="password" value="" class="input_text" 
name="pass_1" nohistory>
+                       <input type="password" value="" class="input_text" 
name="pass_2" nohistory>
+                   </td>
+               </tr>
+
+               <tr>
+                   <td>
+                       <?php echo _('Thème');?>
+                   </td>
+                   <td>
+                       <?php echo $style->input();?>
+                   </td>
+               </tr>
+
+               <?php
+               if ($inside_dossier)
+               {
+                   $l_user_per = $g_user->get_periode();
+                   if ($l_user_per == "")
+                       $l_user_per = $cn->get_value("select min(p_id) from 
parm_periode where p_closed='f'");
+
+// if periode is closed then warns the users
+                   $period = new Periode($cn, $l_user_per);
+
+                   $period->p_id = $l_user_per;
+                   $period->jrn_def_id = 0;
+                   if ($period->is_closed($l_user_per) == 1)
+                   {
+                       $msg = _('Attention cette période est fermée, vous ne 
pourrez rien modifier dans le module comptable');
+                       $msg = '<h2 class="notice">' . $msg . '</h2>';
+                   }
+
+                   $period = new IPeriod("period");
+                   $period->user = $g_user;
+                   $period->cn = $cn;
+                   $period->filter_year = false;
+                   $period->value = $l_user_per;
+                   $period->type = ALL;
+                   $l_form_per = $period->input();
+                   ?>
+               <tr><td><?php echo _('Période');?></td>
+                   <td>
+                           <?php printf(' %s ', $l_form_per);?>
+                   </td>
+                   <td>  <?php echo $msg;?></td>
+               <tr>
+                   <td><?php echo _('Taille des pages');?></td>
+                   <td>
+                       <SELECT NAME="p_size">
+                           <option value="15">15
+                           <option value="25">25
+                           <option value="50">50
+                           <option value="100">100
+                           <option value="150">150
+                           <option value="200">200
+                           <option value="-1"><?php echo _('Illimité');?>
+                                   <?php
+                                   $label = ($_SESSION['g_pagesize'] == -1) ? 
_('Illimité') : $_SESSION['g_pagesize'];
+                                   echo '<option value="' . 
$_SESSION['g_pagesize'] . '" selected>' . $label;
+                                   ?>
+                       </SELECT>
+
+                   </td>
+               </tr>
+                   <?php 
+               }
+               ?>
+           </table>
+       </fieldset>
+       <?php
+       if ($inside_dossier)
+       {
+           /* Pref for welcome page */
+           echo '<fieldset style="margin: 1%">';
+           echo '<legend>' . _('Options pour la page d\'accueil') . 
'</legend>';
+           echo _('Mini-Rapport : ');
+           $rapport = new Acc_Report($cn);
+           $aRapport = $rapport->make_array();
+           $aRapport[] = array("value" => 0, "label" => _('Aucun mini 
rapport'));
+           $wRapport = new ISelect();
+           $wRapport->name = "minirap";
+           $wRapport->selected = $g_user->get_mini_report();
+           $wRapport->value = $aRapport;
+           echo $wRapport->input();
+           echo '<span class="notice">' . _('Le mini rapport est un rapport 
qui s\'affiche  sur votre page d\'accueil') . '</span>';
+           echo '</fieldset>';
+       }
+
+       echo '<fieldset  style="margin: 1%">';
+       echo '<legend>' . _('Langue') . '</legend>';
+       echo _('Selectionnez votre langue');
+       $aLang = array(array(_('Français'), 'fr_FR.utf8'),
+           array(_('Anglais'), 'en_US.utf8'),
+           array(_('Néerlandais'), 'nl_NL.utf8'),
+       );
+       echo '<select name="lang" id="l">';
+       for ($i = 0; $i < count($aLang); $i++)
+       {
+           $sel = "";
+           if ($aLang[$i][1] == $_SESSION['g_lang'])
+               $sel = " selected ";
+           printf('<option value="%s" %s>%s</option>', $aLang[$i][1], $sel, 
$aLang[$i][0]);
+       }
+       echo '</select>';
+       echo '</fieldset>';
+        
+        echo '<p style="text-align:center">';
+       echo HtmlInput::button_close('preference_div');
+       echo HtmlInput::submit("set_preference", _("Valider"));
+        echo '</p>';
+       echo '</form>';
+
+       echo "</DIV>";
+       ?>
diff --git a/include/ajax_remove_submenu.php 
b/include/ajax/ajax_remove_submenu.php
similarity index 100%
rename from include/ajax_remove_submenu.php
rename to include/ajax/ajax_remove_submenu.php
diff --git a/include/ajax_save_predf_op.php 
b/include/ajax/ajax_save_predf_op.php
similarity index 100%
rename from include/ajax_save_predf_op.php
rename to include/ajax/ajax_save_predf_op.php
diff --git a/include/ajax/ajax_search_action.php 
b/include/ajax/ajax_search_action.php
new file mode 100755
index 0000000..684da33
--- /dev/null
+++ b/include/ajax/ajax_search_action.php
@@ -0,0 +1,34 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+// Copyright Author Dany De Bontridder address@hidden
+/*! \file
+ * \brief Search module
+ */
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+include_once NOALYSS_INCLUDE.'/lib/ac_common.php';
+require_once NOALYSS_INCLUDE.'/class/class_follow_up.php';
+
+$_REQUEST['ac']='FOLLOW';
+
+echo Follow_Up::display_search($cn,true);
+
+$sql=  "true ".Follow_Up::create_query($cn);
+echo Follow_Up::short_list($cn, $sql);
+?>
diff --git a/include/ajax/ajax_search_add_tag.php 
b/include/ajax/ajax_search_add_tag.php
new file mode 100644
index 0000000..a9c3e10
--- /dev/null
+++ b/include/ajax/ajax_search_add_tag.php
@@ -0,0 +1,45 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+// Copyright Author Dany De Bontridder address@hidden
+if ( !defined ('ALLOWED') )  die('Appel direct ne sont pas permis');
+
+require_once NOALYSS_INCLUDE.'/class/class_tag.php';
+ob_start();
+if ($_GET['clear']==1) {
+    /* Add a clear button */
+    echo Tag::add_clear_button($_GET['pref']);
+}
+$tag=new Tag($cn,$_GET['id']);
+$tag->update_search_cell($_GET['pref']);
+
+$response=  ob_get_clean();
+$html=escape_xml($response);
+header('Content-type: text/xml; charset=UTF-8');
+echo <<<EOF
+<?xml version="1.0" encoding="UTF-8"?>
+<data>
+<ctl></ctl>
+<html>$html</html>
+</data>
+EOF;
+exit();
+
+
+?>
+
diff --git a/include/ajax/ajax_search_clear_tag.php 
b/include/ajax/ajax_search_clear_tag.php
new file mode 100644
index 0000000..697543e
--- /dev/null
+++ b/include/ajax/ajax_search_clear_tag.php
@@ -0,0 +1,38 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+// Copyright Author Dany De Bontridder address@hidden
+if ( !defined ('ALLOWED') )  die('Appel direct ne sont pas permis');
+
+require_once NOALYSS_INCLUDE.'/class/class_tag.php';
+ob_start();
+echo Tag::button_search($_GET['pref']);
+$response=  ob_get_clean();
+$html=escape_xml($response);
+header('Content-type: text/xml; charset=UTF-8');
+echo <<<EOF
+<?xml version="1.0" encoding="UTF-8"?>
+<data>
+<ctl></ctl>
+<html>$html</html>
+</data>
+EOF;
+exit();
+
+
+?>
diff --git a/include/ajax/ajax_search_display_tag.php 
b/include/ajax/ajax_search_display_tag.php
new file mode 100644
index 0000000..592e1d4
--- /dev/null
+++ b/include/ajax/ajax_search_display_tag.php
@@ -0,0 +1,40 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+// Copyright Author Dany De Bontridder address@hidden
+if ( !defined ('ALLOWED') )  die('Appel direct ne sont pas permis');
+
+require_once NOALYSS_INCLUDE.'/class/class_tag.php';
+ob_start();
+$tag=new Tag($cn);
+$tag->select_search($_GET['pref']);
+
+$response=  ob_get_clean();
+$html=escape_xml($response);
+header('Content-type: text/xml; charset=UTF-8');
+echo <<<EOF
+<?xml version="1.0" encoding="UTF-8"?>
+<data>
+<ctl></ctl>
+<code>$html</code>
+</data>
+EOF;
+exit();
+
+
+?>
diff --git a/include/ajax_tag_add_action.php 
b/include/ajax/ajax_tag_add_action.php
similarity index 100%
rename from include/ajax_tag_add_action.php
rename to include/ajax/ajax_tag_add_action.php
diff --git a/include/ajax/ajax_tag_detail.php b/include/ajax/ajax_tag_detail.php
new file mode 100644
index 0000000..cd451fd
--- /dev/null
+++ b/include/ajax/ajax_tag_detail.php
@@ -0,0 +1,51 @@
+<?php
+/**
+ * @brief display a window with the content of a tag
+ */
+//This file is part of NOALYSS and is under GPL 
+//see licence.txt
+
+if ( !defined ('ALLOWED') )  die('Appel direct ne sont pas permis');
+require_once NOALYSS_INCLUDE.'/lib/class_tool_uos.php';
+require_once NOALYSS_INCLUDE.'/class/class_tag.php';
+ob_start();
+$tag=new Tag($cn);
+$tag->data->t_id=$_GET['tag'];
+$tag->data->load();
+echo HtmlInput::title_box(_("Détail du dossier ou tag"), "tag_div");
+
+?>
+<?php
+// save via POST and reload page 
+if ($_GET['form']=='p') :    ?>
+    <form id="tag_detail_frm" method="POST" >
+<?php 
+/*
+ * save via javascript and don't reload page
+ */
+else :
+    ?>
+    <form id="tag_detail_frm" method="POST" onsubmit="return save_tag();">
+<?php        endif; ?>        
+    <?php
+    echo dossier::hidden();
+    echo HtmlInput::hidden('t_id', $_GET['tag']);
+    echo HtmlInput::hidden('ac',$_GET['ac']);
+    $data=$tag->data;
+    require_once 'template/tag_detail.php';
+    echo HtmlInput::submit("save_tag_sb", "Valider");
+    ?>
+</form>
+<?php
+    $response=  ob_get_clean();
+    $html=escape_xml($response);
+    header('Content-type: text/xml; charset=UTF-8');
+    echo <<<EOF
+<?xml version="1.0" encoding="UTF-8"?>
+<data>
+<ctl></ctl>
+<code>$html</code>
+</data>
+EOF;
+    exit();
+    ?>
\ No newline at end of file
diff --git a/include/ajax/ajax_tag_list.php b/include/ajax/ajax_tag_list.php
new file mode 100644
index 0000000..983e877
--- /dev/null
+++ b/include/ajax/ajax_tag_list.php
@@ -0,0 +1,45 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+// Copyright Author Dany De Bontridder address@hidden
+if ( !defined ('ALLOWED') )  die('Appel direct ne sont pas permis');
+
+require_once NOALYSS_INCLUDE.'/class/class_tag.php';
+ob_start();
+$tag=new Tag($cn);
+$tag->select();
+
+//------------------- Propose to add a tag
+
+$js=sprintf("onclick=\"show_tag('%s','%s','%s','j')\"",Dossier::id(),'','-1');
+echo HtmlInput::button("tag_add", _("Ajout d'un tag"), $js);
+
+$response=  ob_get_clean();
+$html=escape_xml($response);
+header('Content-type: text/xml; charset=UTF-8');
+echo <<<EOF
+<?xml version="1.0" encoding="UTF-8"?>
+<data>
+<ctl></ctl>
+<code>$html</code>
+</data>
+EOF;
+exit();
+
+
+?>
diff --git a/include/ajax_tag_remove_action.php 
b/include/ajax/ajax_tag_remove_action.php
similarity index 100%
rename from include/ajax_tag_remove_action.php
rename to include/ajax/ajax_tag_remove_action.php
diff --git a/include/ajax/ajax_tag_save.php b/include/ajax/ajax_tag_save.php
new file mode 100644
index 0000000..d2dc070
--- /dev/null
+++ b/include/ajax/ajax_tag_save.php
@@ -0,0 +1,11 @@
+<?php
+//This file is part of NOALYSS and is under GPL 
+//see licence.txt
+
+if ( !defined ('ALLOWED') )  die('Appel direct ne sont pas permis');
+
+require_once NOALYSS_INCLUDE.'/class/class_tag.php';
+$tag=new Tag($cn);
+$tag->save($_GET);
+
+?>
diff --git a/include/ajax/ajax_tag_select_search.php 
b/include/ajax/ajax_tag_select_search.php
new file mode 100644
index 0000000..1652c1d
--- /dev/null
+++ b/include/ajax/ajax_tag_select_search.php
@@ -0,0 +1,40 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+// Copyright Author Dany De Bontridder address@hidden
+if ( !defined ('ALLOWED') )  die('Appel direct ne sont pas permis');
+
+require_once NOALYSS_INCLUDE.'/class/class_tag.php';
+ob_start();
+$tag=new Tag($cn);
+$tag->select_search();
+
+$response=  ob_get_clean();
+$html=escape_xml($response);
+header('Content-type: text/xml; charset=UTF-8');
+echo <<<EOF
+<?xml version="1.0" encoding="UTF-8"?>
+<data>
+<ctl></ctl>
+<code>$html</code>
+</data>
+EOF;
+exit();
+
+
+?>
diff --git a/include/ajax/ajax_update_payment.php 
b/include/ajax/ajax_update_payment.php
new file mode 100644
index 0000000..970a639
--- /dev/null
+++ b/include/ajax/ajax_update_payment.php
@@ -0,0 +1,32 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/**
+ * @file
+ * @brief refresh the area with payment method
+ * -l for the ledger
+ */
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+require_once NOALYSS_INCLUDE.'/class/class_acc_ledger.php';
+$ledger=new Acc_Ledger($cn,$l);
+echo $ledger->input_paid(1);
+?>
diff --git a/include/ajax/ajax_update_predef.php 
b/include/ajax/ajax_update_predef.php
new file mode 100644
index 0000000..6043f8f
--- /dev/null
+++ b/include/ajax/ajax_update_predef.php
@@ -0,0 +1,69 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief respond ajax request, the get contains
+ *  the value :
+ * - l for ledger 
+ * - gDossier
+ * Must return at least tva, htva and tvac
+ */
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+
+require_once NOALYSS_INCLUDE.'/constant.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+require_once NOALYSS_INCLUDE.'/class/class_pre_operation.php';
+
+// Check if the needed field does exist
+extract ($_GET);
+foreach (array('l','t','d','gDossier') as $a)
+{
+    if ( ! isset (${$a}) )
+    {
+        echo "error $a is not set ";
+        exit();
+    }
+
+}
+$cn=new Database(dossier::id());
+$op=new Pre_operation_detail($cn);
+$op->set('ledger',$l);
+$op->set('ledger_type',$t);
+$op->set('direct',$d);
+$url=http_build_query(array('action'=>'use_opd','p_jrn_predef'=>$l,'ac'=>$_GET['ac'],'gDossier'=>dossier::id()));
+$html="";
+
+$html.=HtmlInput::title_box(_("Modèle d'opérations"), 'modele_op_div', 'hide');
+$html.=$op->show_button('do.php?'.$url);
+
+$html=escape_xml($html);
+header('Content-type: text/xml; charset=UTF-8');
+echo <<<EOF
+<?xml version="1.0" encoding="UTF-8"?>
+<data>
+<code></code>
+<value>$html</value>
+</data>
+EOF;
+
+?>
+
diff --git a/include/ajax/ajax_view_action.php 
b/include/ajax/ajax_view_action.php
new file mode 100644
index 0000000..ea5e87d
--- /dev/null
+++ b/include/ajax/ajax_view_action.php
@@ -0,0 +1,75 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/**
+ * @file
+ * @brief show the detail of an action
+ *
+ */
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+ob_start();
+require_once NOALYSS_INCLUDE.'/class/class_follow_up.php';
+require_once NOALYSS_INCLUDE.'/class/class_default_menu.php';
+
+echo HtmlInput::title_box(_("Détail action"), $div);
+$act = new Follow_Up($cn);
+$act->ag_id = $ag_id;
+$act->get();
+$code='nok';
+if ($g_user->can_write_action($ag_id) == true || 
$g_user->can_read_action($ag_id) == true || $act->ag_dest == -1)
+{   
+        $menu=new Default_Menu();
+       echo $act->Display('READ', false, "ajax", "");
+       //$action=HtmlInput::array_to_string(array("gDossier","ag_id"), 
$_GET)."&ac=FOLLOW&sa=detail";
+        $action=  
"do.php?".http_build_query(array("gDossier"=>Dossier::id(),"ag_id"=>$ag_id,"ac"=>$menu->get('code_follow'),"sa"=>"detail"));
+        $code='ok';
+       if ( $_GET['mod']== 1) :
+            $forbidden=_("Accès interdit : vous n'avez pas accès à cette 
information, contactez votre responsable");
+       ?>
+<a href="<?php echo $action?>" target="_blank" class="smallbutton"><?php echo 
_("Modifier")?> </a>
+    <?php 
+        $code='nok';
+       endif;
+}
+else
+{
+       $forbidden = _("Ce document n'est pas accessible");
+       ?>
+       <div 
style="margin:0px;padding:0px;background-color:red;text-align:center;">
+        <h2 class="error"><?php echo $forbidden ?></h2>;
+</div>
+       <?php 
+}
+echo HtmlInput::button_close($div);
+$response =  ob_get_clean();
+$html=escape_xml($response);
+header('Content-type: text/xml; charset=UTF-8');
+echo <<<EOF
+<?xml version="1.0" encoding="UTF-8"?>
+<data>
+<ctl>$code</ctl>
+<code>$html</code>
+</data>
+EOF;
+exit();
+
+?>
\ No newline at end of file
diff --git a/include/ajax/ajax_view_mod_stock.php 
b/include/ajax/ajax_view_mod_stock.php
new file mode 100644
index 0000000..c079b93
--- /dev/null
+++ b/include/ajax/ajax_view_mod_stock.php
@@ -0,0 +1,58 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/**
+ * @file
+ * @brief show detail of inv.
+ *
+ */
+require_once NOALYSS_INCLUDE.'/class/class_stock_goods.php';
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+
+$st=new Stock_Goods($cn);
+$array=$cn->get_array("select * from stock_goods where 
c_id=$1",array($_GET['c_id']));
+echo HtmlInput::title_box(_("Détail changement"),$_GET['ctl']);
+$p_array=array();
+$p_array['p_date']=$cn->get_value("select to_char(c_date,'DD.MM.YYYY') from 
stock_change where c_id=$1",array($_GET['c_id']));
+$p_array['p_motif']=$cn->get_value("select c_comment from stock_change where 
c_id=$1",array($_GET['c_id']));
+$p_array['p_depot']=$cn->get_value("select r_id from stock_change where 
c_id=$1",array($_GET['c_id']));
+for ($i=0;$i<count($array);$i++)
+{
+       $p_array['f_id'.$i]=$array[$i]['f_id'];
+       $p_array['sg_code'.$i]=$array[$i]['sg_code'];
+       $p_array['sg_quantity'.$i]=$array[$i]['sg_quantity'];
+       $p_array['sg_type'.$i]=$array[$i]['sg_type'];
+        $p_array['row']=$i+1;
+}
+echo $st->input($p_array,true);
+?>
+<form method="POST">
+       <?php echo HtmlInput::hidden('c_id',$_GET['c_id']);?>
+       <p>
+       <?php $ck=new ICheckBox("ok"," 1");
+                       $ck->label= _("Cochez pour confirmer effacement");
+                       echo $ck->input();?>
+       </p>
+       <?php echo HtmlInput::submit("del",_("Effacer"));?>
+       <?php echo HtmlInput::button_close($_GET['ctl'])?>
+       <?php echo HtmlInput::hidden('r_id',$p_array['p_depot'])?>
+</form>
diff --git a/include/ajax_action_remove_concerned.php 
b/include/ajax_action_remove_concerned.php
deleted file mode 100644
index e6da625..0000000
--- a/include/ajax_action_remove_concerned.php
+++ /dev/null
@@ -1,45 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright 2014 Author Dany De Bontridder address@hidden
-
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-$ag_id=HtmlInput::default_value_get("ag_id", "0");
-$f_id=HtmlInput::default_value_get("f_id", "0");
-if ( $ag_id == 0 || $f_id == 0 ) throw new Exception ("Invalid values", 0);
-require_once 'class_follow_up.php';
-$follow=new Follow_Up($cn,$ag_id);
-
-ob_start();
-$follow->remove_linked_card($f_id);
-echo $follow->display_linked();
-HtmlInput::button_action_add_concerned_card( $follow->ag_id);
-
-$response = ob_get_clean();
-
-$html = escape_xml($response);
-header('Content-type: text/xml; charset=UTF-8');
-echo <<<EOF
-<?xml version="1.0" encoding="UTF-8"?>
-<data>
-<ctl>unused</ctl>
-<code>$html</code>
-</data>
-EOF;
-?>        
\ No newline at end of file
diff --git a/include/ajax_action_save_concerned.php 
b/include/ajax_action_save_concerned.php
deleted file mode 100644
index b8b780e..0000000
--- a/include/ajax_action_save_concerned.php
+++ /dev/null
@@ -1,47 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright 2014 Author Dany De Bontridder address@hidden
-
-// require_once '.php';
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-/**
- * Insert into follow-up the card (f_id) for the action_gestion (ag_id)
- */
-require_once 'class_follow_up.php';
-$follow=new Follow_Up($cn,$ag_id);
-$follow->insert_linked_card($f_id);
-/**
- * Display all the linked card
- */
-
-ob_start();
-$follow->display_linked();
-echo HtmlInput::button_action_add_concerned_card( $ag_id);
-$response = ob_get_clean();
-$html = escape_xml($response);
-header('Content-type: text/xml; charset=UTF-8');
-echo <<<EOF
-<?xml version="1.0" encoding="UTF-8"?>
-<data>
-<ctl>unused</ctl>
-<code>$html</code>
-</data>
-EOF;
-?>        
\ No newline at end of file
diff --git a/include/ajax_add_concerned_card.php 
b/include/ajax_add_concerned_card.php
deleted file mode 100644
index da09c71..0000000
--- a/include/ajax_add_concerned_card.php
+++ /dev/null
@@ -1,83 +0,0 @@
-<?php
-
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-// Copyright 2014 Author Dany De Bontridder address@hidden
-// require_once '.php';
-if (!defined('ALLOWED'))
-    die('Appel direct ne sont pas permis');
-ob_start();
-
-$ag_id=HtmlInput::default_value_get("ag_id", "0");
-
-if ($ag_id == 0 )    throw new Exception('ag_id is null');
-
-require_once('class_acc_ledger.php');
-$r=HtmlInput::title_box(_("Détail fiche"), 'search_card');
-
-$r.='<form id="search_card1_frm" method="GET" 
onsubmit="action_add_concerned_card(this);return false;">';
-$q=new IText('query');
-$q->value=(isset($query))?$query:'';
-$r.='<span style="margin-left:50px">';
-$r.=_('Fiche contenant').HtmlInput::infobulle(19);
-$r.=$q->input();
-$r.=HtmlInput::submit('fs', _('Recherche'), "", "smallbutton");
-$r.='</span>';
-$r.=dossier::hidden().HtmlInput::hidden('op', 'add_concerned_card');
-$r.=HtmlInput::request_to_hidden(array('ag_id'));
-$r.='</form>';
-$query=HtmlInput::default_value_get("query", "");
-$sql_array['query']=$query;
-$sql_array['typecard']='all';
-
-$fiche=new Fiche($cn);
-/* Build the SQL and show result */
-$sql=$fiche->build_sql($sql_array);
-
-
-/* We limit the search to MAX_SEARCH_CARD records */
-$sql=$sql.' order by vw_name limit '.MAX_SEARCH_CARD;
-$a=$cn->get_array($sql);
-for ($i=0; $i<count($a); $i++)
-{
-    $array[$i]['quick_code']=$a[$i]['quick_code'];
-    $array[$i]['name']=h($a[$i]['vw_name']);
-    $array[$i]['accounting']=$a[$i]['accounting'];
-    $array[$i]['first_name']=h($a[$i]['vw_first_name']);
-    $array[$i]['description']=h($a[$i]['vw_description']);
-    
$array[$i]['javascript']=sprintf("action_save_concerned(%d,'%s','%s')",$gDossier,$a[$i]['f_id'],$ag_id);
-}//foreach
-
-
-echo $r;
-require_once('template/card_result.php');
-$response=ob_get_contents();
-ob_end_clean();
-
-
-$html=escape_xml($response);
-if ( !headers_sent() ) { header('Content-type: text/xml; charset=UTF-8');} 
else {echo $response;echo $html;}
-echo <<<EOF
-<?xml version="1.0" encoding="UTF-8"?>
-<data>
-<ctl>unused</ctl>
-<code>$html</code>
-</data>
-EOF;
-?>
\ No newline at end of file
diff --git a/include/ajax_anc_key_choice.php b/include/ajax_anc_key_choice.php
deleted file mode 100644
index d2d38ee..0000000
--- a/include/ajax_anc_key_choice.php
+++ /dev/null
@@ -1,53 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-/**
- * @file
- * @brief show the available distribution keys for analytic activities. 
Expected
- * parameter are 
- *  - t for the table id
- *  - amount is the amount to distributed
- *
- */
-// Copyright (2014) Author Dany De Bontridder address@hidden
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-$amount=HtmlInput::default_value_get("amount", 0);
-$table_id=HtmlInput::default_value_get("t", "");
-$ledger=HtmlInput::default_value_get('led',0);
-
-if ($table_id == "" || isNumber($amount) == 0 || isNumber($ledger) == 0) die 
('Invalid Parameter');
-
-require_once 'class_anc_key.php';
-
-ob_start();
-echo HtmlInput::title_box(_("Choix d'une clef"), 'div_anc_key_choice');
-
-Anc_Key::display_choice($amount,$table_id,$ledger);
-
-echo HtmlInput::button_close('div_anc_key_choice');
-$response = ob_get_clean();
-$html = escape_xml($response);
-header('Content-type: text/xml; charset=UTF-8');
-echo <<<EOF
-<?xml version="1.0" encoding="UTF-8"?>
-<data>
-<ctl></ctl>
-<code>$html</code>
-</data>
-EOF;
-?>        
\ No newline at end of file
diff --git a/include/ajax_anc_key_compute.php b/include/ajax_anc_key_compute.php
deleted file mode 100644
index 499ad16..0000000
--- a/include/ajax_anc_key_compute.php
+++ /dev/null
@@ -1,61 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright 2014 Author Dany De Bontridder address@hidden
-// @brief Compute the amount. This file compute the amount and distribute it
-// following the given distribution key given in parameter.
-// Parameters are :
-//   - gDossier
-//   - t the element HTML to use as target
-//   - amount the amount to distribute
-//   - key the Distribution key to use
-// 
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-
-require_once NOALYSS_INCLUDE.'/class_anc_key.php';
-ob_start();
-/////
-$key=HtmlInput::default_value_get('key',0);
-$amount=HtmlInput::default_value_get('amount',0);
-$target=HtmlInput::default_value_get('t','');
-
-if (        isNumber($key)== 0
-        ||  isNumber($amount) ==0
-        || $target==''
-    ) 
-{
-    die ('Invalid parameter');
-}
-
-$compute_key=new Anc_Key($key);
-
-$compute_key->fill_table($target,$amount);
-
-////
-$response = ob_get_clean();
-$html = escape_xml($response);
-header('Content-type: text/xml; charset=UTF-8');
-echo <<<EOF
-<?xml version="1.0" encoding="UTF-8"?>
-<data>
-<ctl></ctl>
-<code>$html</code>
-</data>
-EOF;
-?>        
\ No newline at end of file
diff --git a/include/ajax_anc_search.php b/include/ajax_anc_search.php
deleted file mode 100644
index 7c313c0..0000000
--- a/include/ajax_anc_search.php
+++ /dev/null
@@ -1,98 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- *
- * \brief show a screen to search a ca account
- *
- */
-
-// parameter are gDossier , c1 : the control id to update,
-// c2 the control id which contains the pa_id
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_itext.php';
-require_once NOALYSS_INCLUDE.'/class_ihidden.php';
-require_once NOALYSS_INCLUDE.'/class_ibutton.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/ac_common.php';
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-require_once NOALYSS_INCLUDE.'/class_anc_account.php';
-require_once NOALYSS_INCLUDE.'/class_anc_plan.php';
-require_once NOALYSS_INCLUDE.'/function_javascript.php';
-
-echo HtmlInput::title_box(_("Recherche activité"), $ctl);
-
-//------------- FORM ----------------------------------
-echo '<FORM id="anc_search_form" METHOD="GET" 
onsubmit="search_anc_form(this);return false">';
-echo '<span>'._('Recherche').':';
-
-$texte=new IText('plabel');
-$texte->value=HtmlInput::default_value('plabel',"", $_GET);
-echo $texte->input();
-echo '</span>';
-echo dossier::hidden();
-$hid=new IHidden();
-echo $hid->input("c1",$_REQUEST['c1']);
-echo $hid->input("c2",$_REQUEST['c2']);
-echo $hid->input("go");
-echo HtmlInput::submit("go",_("Recherche"));
-echo '</form>';
-//------------- FORM ----------------------------------
-if ( isset($_REQUEST['go']))
-{
-    $cn=Dossier::connect();
-    $plan=new Anc_Plan($cn,$_REQUEST['c2']);
-    $plan->pa_id=$_REQUEST['c2'];
-    if ( $plan->exist()==false)
-        exit(_("Ce plan n'existe pas"));
-
-    $sql="select po_name , po_description from poste_analytique ".
-         "where pa_id=$1 and ".
-         " (po_name ~* $2 or po_description ~* $3) order by po_name";
-    
$array=$cn->get_array($sql,array($_REQUEST['c2'],$_REQUEST['plabel'],$_REQUEST['plabel']));
-
-    if (empty($array) == true)
-    {
-        echo _("Aucun poste trouvé");
-        return;
-    }
-    $button=new IButton();
-    $button->name=_("Choix");
-    $button->label=_("Choix");
-
-    echo '<table>';
-    foreach ($array as $line)
-    {
-        $button->javascript=sprintf("$('%s').value='%s';removeDiv('%s')",
-                                    $_REQUEST['c1'],
-                                    $line['po_name'],$ctl);
-        echo '<tr>'.
-        '<td>'.
-        $button->input().
-        '</td>'.
-        '<td>'.
-        h($line['po_name']).
-        '</td><td>'.
-        h($line['po_description']).
-        '</tr>';
-    }
-    echo '</table>';
-}
diff --git a/include/ajax_auto_anc_card.php b/include/ajax_auto_anc_card.php
deleted file mode 100644
index 4d17610..0000000
--- a/include/ajax_auto_anc_card.php
+++ /dev/null
@@ -1,31 +0,0 @@
-<?php 
-//This file is part of NOALYSS and is under GPL 
-//see licence.txt
-
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_user.php';
-$cn=new Database($_GET['gDossier']);
-
-
-if ( isset($_REQUEST['pa_id']) )
-{   
-    $res=$cn->exec_sql("select po_name,po_description from  poste_analytique 
where pa_id=$1 ~* and (po_description ~* $2 or po_name ~* $3 order by po_id 
limit 12",
-        array($_REQUEST['pa_id'],$_POST['anccard'],$_POST['anccard']));
-}
-else
-{
-       $res=$cn->exec_sql("select po_name,po_description from  
poste_analytique where po_description ~* $1 or po_name ~* $2 order by po_id 
limit 12 ",
-        array($_POST['anccard'],$_POST['anccard']));
-}
-$nb=Database::num_row($res);
-       echo "<ul>";
-for ($i = 0;$i< $nb;$i++)
-{
-       $row=Database::fetch_array($res,$i);
-       echo "<li>";
-       echo $row['po_name'];
-       echo '<span class="informal"> '.$row['po_description'].'</span></li>';
-}
-       echo "</ul>";
-?>
\ No newline at end of file
diff --git a/include/ajax_bank_saldo.php b/include/ajax_bank_saldo.php
deleted file mode 100644
index 56a3e84..0000000
--- a/include/ajax_bank_saldo.php
+++ /dev/null
@@ -1,75 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief respond ajax request, the get contains
- *  the value :
- * - l for ledger
- * - gDossier
- * Must return at least tva, htva and tvac
-
- */
-
-/*!\file
- * \brief get the saldo of a account
- * the get variable are :
- *  - l the jrn id
- *  - ctl the ctl where to get the quick_code
- */
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_user.php';
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-require_once NOALYSS_INCLUDE.'/class_fiche.php';
-extract($_GET);
-/* check the parameters */
-foreach ( array('j','ctl') as $a )
-{
-    if ( ! isset(${$a}) )
-    {
-        echo "missing $a";
-        return;
-    }
-}
-
-if ( $g_user->check_jrn($_GET['j'])=='X' ) return '{"saldo":"0"}';
-/*  make a filter on the exercice */
-
-$filter_year="  j_tech_per in (select p_id from parm_periode ".
-             "where p_exercice='".$g_user->get_exercice()."')";
-
-
-$id=$cn->get_value('select jrn_def_bank from jrn_def where 
jrn_def_id=$1',array($_GET['j']));
-$acc=new Fiche($cn,$id);
-
-$res=$acc->get_bk_balance($filter_year." and ( trim(jr_pj_number) != '' and 
jr_pj_number is not null)" );
-
-
-if ( empty($res) ) return '{"saldo":"0"}';
-$solde=$res['solde'];
-if ( $res['debit'] < $res['credit'] ) $solde=$solde*(-1);
-
-//header("Content-type: text/html; charset: utf8",true);
-echo '{"saldo":"'.$solde.'"}';
-
-
-
-?>
-
diff --git a/include/ajax_calendar_zoom.php b/include/ajax_calendar_zoom.php
deleted file mode 100644
index 5458235..0000000
--- a/include/ajax_calendar_zoom.php
+++ /dev/null
@@ -1,46 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-// Copyright Author Dany De Bontridder address@hidden
-if ( !defined ('ALLOWED') )  die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_calendar.php';
-ob_start();
-if ( $notitle== 0 ) echo HtmlInput::title_box(_("Calendrier"), 
"calendar_zoom_div");
-$cal=new Calendar();
-$in=HtmlInput::default_value_get('in',"");
-$notitle=HtmlInput::default_value_get('notitle',"0");
-if ( $in == "") {
-    $in=$cal->get_preference();
-}
-$cal->set_periode($in);
-echo $cal->zoom($distype,$notitle);
-$response=  ob_get_clean();
-
-$html=escape_xml($response);
-header('Content-type: text/xml; charset=UTF-8');
-echo <<<EOF
-<?xml version="1.0" encoding="UTF-8"?>
-<data>
-<ctl></ctl>
-<html>$html</html>
-</data>
-EOF;
-exit();
-
-
-?>
diff --git a/include/ajax_create_menu.php b/include/ajax_create_menu.php
deleted file mode 100644
index 6f5726d..0000000
--- a/include/ajax_create_menu.php
+++ /dev/null
@@ -1,15 +0,0 @@
-<?php
-//This file is part of NOALYSS and is under GPL 
-//see licence.txt
-
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_menu_ref.php';
-$msg=_("Création");
-$m=new Menu_Ref($cn);
-echo '<form method="POST" id="ajax_create_menu_frm" onsubmit="return 
confirm_box(this,\''._('Vous confirmez ?').'\')">';
-echo HtmlInput::hidden('create_menu', 1);
-require_once 'template/menu_detail.php';
-echo HtmlInput::submit('create_menubt',_('Sauver'));
-echo HtmlInput::button_close('divmenu');
-echo '</form>';
-?>
diff --git a/include/ajax_display_submenu.php b/include/ajax_display_submenu.php
deleted file mode 100644
index d8271f1..0000000
--- a/include/ajax_display_submenu.php
+++ /dev/null
@@ -1,98 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright 2015 Author Dany De Bontridder address@hidden
-/** 
- * @brief call from ajax : display submenu
- * Security : only user with the menu CFGPRO
- * display the submenu of a menu or a module
- * It expects 2 parameters  = p_profile (profile.p_id) and the dep 
(menu_ref.me_code)
- */
-// require_once '.php';
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-
-// Security 
-if ( $g_user->check_module('CFGPRO') == 0 ) die();
-
-// Check parameter
-$module=HtmlInput::default_value_get("dep", "");
-$p_level=HtmlInput::default_value_get("p_level", 0);
-$p_id=HtmlInput::default_value_get('p_profile',-1);
-
-if ($module == ""
-        || $p_id == -1 
-        || isNumber($p_id) == 0
-        || isNumber($p_level) == 0
-        )
-{
-    echo _('Paramètre invalide');
-    return;
-}
-
-require_once NOALYSS_INCLUDE.'/class_profile_menu.php';
-$p_level++;
-$profile=new Profile_Menu($cn);
-$profile->p_id=$p_id;
-$profile->display_module_menu($module,$p_level);
-
-////////////////////////////////////////////////////////////////////////////////
-// EXAMPLE
-////////////////////////////////////////////////////////////////////////////////
-/*
-if ($ac == 'save') // operation
-{
-    
-    $cn=new Database(dossier::id());
-    $todo=new Todo_List($cn);
-     $id=HtmlInput::default_value_get("id", 0); // get variable
-    $todo->set_parameter("id",$id);
-    if ($id <> 0 ) { $todo->load(); }
-    else
-    {
-        $todo->set_parameter("owner", $_SESSION['g_user']);
-    }
-    
-    $todo->set_parameter("date", HtmlInput::default_value_get("p_date_todo", 
""));
-    $todo->set_parameter("title", HtmlInput::default_value_get("p_title", ""));
-    $todo->set_parameter("desc", HtmlInput::default_value_get("p_desc", ""));
-    $todo->set_is_public(HtmlInput::default_value_get("p_public", "N"));
-    
-    if ( $todo->get_parameter('owner') == $_SESSION['g_user'] ) $todo->save();
-    $todo->load();
- //----------------------------------------------------------------
- // Answer in XML
-     header('Content-type: text/xml; charset=UTF-8');
-    $dom=new DOMDocument('1.0','UTF-8');
-    $tl_id=$dom->createElement('tl_id',$todo->get_parameter('id'));
-    
$tl_content=$dom->createElement('row',$todo->display_row('class="odd"','N'));
-     $root=$dom->createElement("root");
-     $todo_class=$todo->get_class();
-     $todo_class=($todo_class=="")?' odd ':$todo_class;
-     $class=$dom->createElement("style",$todo_class);
-    
-    $root->appendChild($tl_id);
-    $root->appendChild($tl_content);
-    $root->appendChild($class);
-    $dom->appendChild($root);
-   
-    echo $dom->saveXML();
-    exit();
-}
-  */
-?>        
\ No newline at end of file
diff --git a/include/ajax_fiche_def_detail.php 
b/include/ajax_fiche_def_detail.php
deleted file mode 100644
index effdb49..0000000
--- a/include/ajax_fiche_def_detail.php
+++ /dev/null
@@ -1,47 +0,0 @@
-<?php
-
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/**
- * @file
- * @brief show detail of a fiche_def (category of card) + Attribut
- *
- */
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_fiche_def.php';
-require_once NOALYSS_INCLUDE.'/class_tool_uos.php';
-global $g_user;
-
-$g_user->can_request(FICCAT,0);
-
-$fd=new Fiche_Def($cn,$_GET['id']);
-if ( $_GET['id'] > 0 )
-{
-
-       echo $fd->input_detail();
-       echo HtmlInput::button("retour_b", _("Retour à la liste"), 
"onclick=\"$('detail_category_div').hide();$('list_cat_div').show()\"");
-}
-else
-{
-       $fd->input_new();
-
-}
-?>
diff --git a/include/ajax_gestion.php b/include/ajax_gestion.php
deleted file mode 100644
index d59c681..0000000
--- a/include/ajax_gestion.php
+++ /dev/null
@@ -1,129 +0,0 @@
-<?php
-
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-// Copyright 2015 Author Dany De Bontridder address@hidden
-/**
- * @file
- * @brief display a box containing last actions
- */
-if (!defined('ALLOWED'))
-    die('Appel direct ne sont pas permis');
-if ($op=='action_show')
-{
-    /**
-     * display action
-     */
-    require_once NOALYSS_INCLUDE.'/class_follow_up.php';
-    $gestion=new Follow_Up($cn);
-    $array=$gestion->get_last(25);
-    $len_array=count($array);
-    require_once NOALYSS_INCLUDE.'/template/action_show.php';
-    return;
-}
-if ($op=='action_add')
-{
-    require_once NOALYSS_INCLUDE.'/class_follow_up.php';
-    $gestion=new Follow_Up($cn);
-    $gestion->display_short();
-    return;
-}
-if ($op=='action_save')
-{
-    require_once NOALYSS_INCLUDE.'/class_follow_up.php';
-
-    /**
-     * save info from the get
-     */
-    $date_event=HtmlInput::default_value_get("date_event", -1);
-    $dest=HtmlInput::default_value_get("dest", "");
-    $event_group=HtmlInput::default_value_get("event_group", 0);
-    $event_priority=HtmlInput::default_value_get("event_priority", 0);
-    $title=HtmlInput::default_value_get("title_event", NULL);
-    $summary=HtmlInput::default_value_get("summary", "");
-    $type_event=HtmlInput::default_value_get('type_event', -1);
-    /*
-     * Check if data are valid
-     */
-    try
-    {
-        if ($date_event==-1||isDate($date_event)==0)
-            throw new Exception(_('Date invalide'));
-        if (trim($dest)=="")
-            $dest_id=NULL;
-        else
-        {
-            $fiche=new Fiche($cn);
-            $fiche->get_by_qcode($dest);
-            $dest_id=$fiche->id;
-            if ($dest_id==0)
-                throw new Exception(_('Destinataire invalide'));
-        }
-        if ($type_event==-1)
-            throw new Exception(_('Type invalide'));
-        if (trim($title)=="")
-            throw new Exception(_('Aucun titre'));
-    }
-    catch (Exception $ex)
-    {
-        header('Content-type: text/xml; charset=UTF-8');
-        $dom=new DOMDocument('1.0', 'UTF-8');
-        $xml_content=$dom->createElement('content', $ex->getMessage());
-        $xml_status=$dom->createElement('status', "NOK");
-        $root=$dom->createElement("root");
-        $root->appendChild($xml_content);
-        $root->appendChild($xml_status);
-        $dom->appendChild($root);
-        echo $dom->saveXML();
-        return;
-    }
-    /*
-     * Save data
-     */
-    $gestion=new Follow_Up($cn);
-    $gestion->ag_priority=$event_priority;
-    $gestion->ag_title=$title;
-    $gestion->ag_dest=$event_group;
-    $gestion->ag_type=$type_event;
-    $gestion->f_id_dest=$dest_id;
-    $gestion->ag_state=3;
-    $gestion->dt_id=$type_event;
-    $gestion->ag_comment=h($summary);
-    $gestion->ag_timestamp=$date_event;
-    $gestion->ag_remind_date=$date_event;
-    $content=_('Sauvé');
-    $status='OK';
-    try {
-        $gestion->save_short();
-    } catch (Exception $ex)
-    {
-        $content=$ex->getMessage();
-        $status='NOK';
-    }
-    header('Content-type: text/xml; charset=UTF-8');
-    $dom=new DOMDocument('1.0', 'UTF-8');
-    $xml_content=$dom->createElement('content', _("Sauvé"));
-    $xml_status=$dom->createElement('status', "OK");
-    $root=$dom->createElement("root");
-    $root->appendChild($xml_content);
-    $root->appendChild($xml_status);
-    $dom->appendChild($root);
-    echo $dom->saveXML();
-    return;
-}
\ No newline at end of file
diff --git a/include/ajax_get_profile.php b/include/ajax_get_profile.php
deleted file mode 100644
index 8dcab3b..0000000
--- a/include/ajax_get_profile.php
+++ /dev/null
@@ -1,137 +0,0 @@
-<?php
-
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/**
- * @file
- * @brief show the profile detail, included from ajax_misc.php
- * @see ajax_misc.php scripts.js profile.inc.php
- *
- */
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-
-// Security 
-if ( $g_user->check_module('CFGPRO') == 0 ) die();
-
-require_once NOALYSS_INCLUDE.'/class_profile_sql.php';
-require_once NOALYSS_INCLUDE.'/class_profile_menu.php';
-require_once NOALYSS_INCLUDE.'/class_html_input.php';
-$p_id=HtmlInput::default_value_request('p_id', -1);
-$profile=new Profile_sql($cn,$p_id);
-$gDossier=Dossier::id();
-$add_impression=HtmlInput::button("add", _("Ajout 
Menu"),"onclick=\"add_menu({dossier:$gDossier,p_id:$p_id,type:'pr'})\"");
-$call_tab=HtmlInput::default_value_post('tab', 'none');
-$a_tab=array('profile_gen_div'=>'tabs','profile_menu_div'=>'tabs','profile_print_div'=>'tabs','profile_gestion_div'=>'tabs','profile_repo_div'=>'tabs');
-$a_tab[$call_tab]='tabs_selected';
-?>
-<h1>Profil <?php echo $profile->p_name?></h1>
-<?php
-    echo HtmlInput::anchor(_('Retour'), "", " onclick = \" 
$('detail_profile').hide();$('list_profile').show(); \" ", 'class="line"');
-?>
-<?php if ($p_id > 0 ) : ?>
-<ul class="tabs">
-    
-    <li class="<?php echo $a_tab['profile_gen_div']?>"><a 
href="javascript:void(0)"  
onclick="unselect_other_tab(this.parentNode.parentNode);this.parentNode.className='tabs_selected';profile_show('profile_gen_div')"><?php
 echo _('Nom')?></a></li>
-    <li class="<?php echo $a_tab['profile_menu_div']?>"><a 
href="javascript:void(0)"  
onclick="unselect_other_tab(this.parentNode.parentNode);this.parentNode.className='tabs_selected';profile_show('profile_menu_div')"><?php
 echo _('Détail Menus')?></a></li>
-    <li class="<?php echo $a_tab['profile_print_div']?>"><a 
href="javascript:void(0)" 
onclick="unselect_other_tab(this.parentNode.parentNode);this.parentNode.className='tabs_selected';profile_show('profile_print_div')"><?php
 echo _('Détail Impressions')?></a></li>
-    <li class="<?php echo $a_tab['profile_gestion_div']?>"><a 
href="javascript:void(0)" style="" 
onclick="unselect_other_tab(this.parentNode.parentNode);this.parentNode.className='tabs_selected';profile_show('profile_gestion_div')"><?php
 echo _('Action Gestion')?> </a></li>
-    <li class="<?php echo $a_tab['profile_repo_div']?>"><a 
href="javascript:void(0)"  
onclick="unselect_other_tab(this.parentNode.parentNode);this.parentNode.className='tabs_selected';profile_show('profile_repo_div')"><?php
 echo _('Dépôts')?></a>&nbsp;
-</ul>
-<?php endif; ?>
-
-<?php 
-$id=HtmlInput::hidden('p_id',$profile->p_id);
-$name=new IText("p_name",$profile->p_name);
-$desc=new IText("p_desc",$profile->p_desc);
-$with_calc=new ICheckBox("with_calc","t");
-$with_calc->set_check($profile->with_calc);
-
-$with_direct_form=new ICheckBox("with_direct_form","t");
-$with_direct_form->set_check($profile->with_direct_form);
-
-// If $p_id == -1 it is a new profile
-if ( $p_id > 0 )
-{
-       echo '<div style="display:none" id="profile_gen_div">';
-}
-else
-{
-       echo '<div  class="myfieldset" id="profile_gen_div">';
-}
-echo '<form method="POST" id="profile_save_name_frm" onsubmit="return 
confirm_box(this,\'vous confirmez\')">';
-echo HtmlInput::hidden('tab','profile_gen_div');
-echo HtmlInput::hidden('p_id',$profile->p_id);
-echo HtmlInput::hidden('save_name',1);
-require_once("template/profile.php");
-echo HtmlInput::submit("save_namebt",_("Modifier"));
-echo '</form>';
-if ($profile->p_id > 0)
-{
-       echo '<form method="POST" id="profile_clone_frm" onsubmit="return 
confirm_box(this,\''._("vous confirmez").'\')">';
-
-       echo _('Vous pouvez aussi copier ce profil et puis le corriger');
-
-       echo HtmlInput::hidden('p_id', $profile->p_id);
-       echo HtmlInput::hidden('clone', 1);
-       echo HtmlInput::submit("clonebt", "Copier");
-       echo '</form>';
-
-       echo '<form method="POST" id="delete_profile_frm" onsubmit="return 
confirm_box(this,\''._("vous confirmez").'\')">';
-
-       echo _('Effacer ce profil');
-
-       echo HtmlInput::hidden('p_id', $profile->p_id);
-       echo HtmlInput::hidden('delete_profil', 1);
-       echo HtmlInput::submit("delete_profil", _("Effacer ce profil"));
-       echo '</form>';
-        echo '</div>';
-        echo '<div class="myfieldset"  style="display:none" 
id="profile_menu_div">';
-       //Menu / Module /plugin in this profile
-       echo "<h1 class=\"legend\">"._("Menu")."</h2>";
-       $profile_menu = new Profile_Menu($cn);
-        $profile_menu->p_id=$p_id;
-       $profile_menu->display_profile_menu_detail();
-        echo '</div>';
-        echo '<div class="myfieldset"  style="display:none" 
id="profile_print_div">';
-       echo "<h1 class=\"legend\">"._("Impression")."</h1>";
-       $profile_menu->printing();
-       echo $add_impression;
-        echo '</div>';
-        echo '<div class="myfieldset"  style="display:none" 
id="profile_gestion_div">';
-       echo "<h1 class=\"legend\">".('Groupe gestion')."</h1>";
-       $profile_menu->available_profile();
-        echo '</div>';
-        echo '<div class="myfieldset"  style="display:none" 
id="profile_repo_div">';
-       echo "<h1 class=\"legend\">"._("Dépôt de stock accessible")."</h1>";
-       $profile_menu->available_repository();
-        echo '</div>';
-        if ( isset ($_POST['tab']))
-        {
-            echo create_script("profile_show('".$_POST['tab']."');");
-        }
-}
-else
-{
-        echo '</div>';
-}
-?>
-
-
diff --git a/include/ajax_get_receipt.php b/include/ajax_get_receipt.php
deleted file mode 100644
index 472c9fa..0000000
--- a/include/ajax_get_receipt.php
+++ /dev/null
@@ -1,65 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief respond ajax request, the get contains
- *  the value :
- * - l for ledger
- * - gDossier
- * Must return at least tva, htva and tvac
-
- */
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-
-require_once NOALYSS_INCLUDE.'/constant.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-require_once NOALYSS_INCLUDE.'/class_acc_ledger.php';
-require_once NOALYSS_INCLUDE.'/class_user.php';
-
-// Check if the needed field does exist
-extract ($_GET);
-foreach (array('l','gDossier') as $a)
-{
-    if ( ! isset (${$a}) )
-    {
-        echo "error $a is not set ";
-        exit();
-    }
-
-}
-if ( is_numeric($l) == false  )
-{
-    exit();
-}
-
-
-$Ledger=new Acc_Ledger($cn,$l);
-$prop=$Ledger->get_propertie();
-$pj_seq=$Ledger->guess_pj();
-$string='{"pj":"'.$pj_seq.'"}';
-
-header("Content-type: text/json; charset: utf8",true);
-echo $string;
-
-
-?>
-
diff --git a/include/ajax_ledger_show.php b/include/ajax_ledger_show.php
deleted file mode 100644
index db9534c..0000000
--- a/include/ajax_ledger_show.php
+++ /dev/null
@@ -1,35 +0,0 @@
-<?php
-//This file is part of NOALYSS and is under GPL 
-//see licence.txt
-
-/**
- * @brief
- * Show a div for selecting ledger
- * return a html code for creating a window
- * parameter 
- *   - type 
- *   - div
- *   - nbjrn
- *   - r_jrn[]
- */
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-
-require_once NOALYSS_INCLUDE.'/class_acc_ledger.php';
-require_once NOALYSS_INCLUDE.'/class_html_input.php';
-if ( ! isset ($r_jrn)) { $r_jrn=null;}
-$ctl='div_jrn'.$div;
-ob_start();
-echo HtmlInput::select_ledger($type,$r_jrn, $div);
-
-$response = ob_get_clean();
-$html = escape_xml($response);
-header('Content-type: text/xml; charset=UTF-8');
-echo <<<EOF
-<?xml version="1.0" encoding="UTF-8"?>
-<data>
-<ctl>$ctl</ctl>
-<code>$html</code>
-</data>
-EOF;
-exit();
-?>    
\ No newline at end of file
diff --git a/include/ajax_min_row.php b/include/ajax_min_row.php
deleted file mode 100644
index c454ccc..0000000
--- a/include/ajax_min_row.php
+++ /dev/null
@@ -1,48 +0,0 @@
-<?php
-
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/**
- * @file
- * @brief
- *
- */
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_user.php';
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-extract($_GET);
-/* check the parameters */
-foreach ( array('j','ctl') as $a )
-{
-    if ( ! isset(${$a}) )
-    {
-        echo "missing $a";
-        return;
-    }
-}
-
-if ( $g_user->check_jrn($_GET['j'])=='X' ) { echo  '{"row":"0"}';exit();}
-
-$row=$cn->get_value('select jrn_deb_max_line from jrn_def where 
jrn_def_id=$1',array($_GET['j']));
-
-echo '{"row":"'.$row.'"}';
-
-?>
diff --git a/include/ajax_mod_document.php b/include/ajax_mod_document.php
deleted file mode 100644
index 157d25b..0000000
--- a/include/ajax_mod_document.php
+++ /dev/null
@@ -1,52 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief show the detail of a document and let you modify it
- */
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-require_once NOALYSS_INCLUDE.'/class_document_modele.php';
-
-  /* 1. Check security */
-$cn=new Database(dossier::id());
-  /* 2. find the document */
-$doc=new Document_Modele($cn,$id);
-
-  /* 3. display it */
-$doc->load();
-ob_start();
-require(NOALYSS_INCLUDE.'/template/modele_document.php');
-
-$html=ob_get_contents();
-ob_end_clean();
-$html=escape_xml($html);
-header('Content-type: text/xml; charset=UTF-8');
-
-echo <<<EOF
-<?xml version="1.0" encoding="UTF-8"?>
-<data>
-<ctl>mod_doc</ctl>
-<code>$html</code>
-</data>
-EOF;
-exit();
diff --git a/include/ajax_mod_menu.php b/include/ajax_mod_menu.php
deleted file mode 100644
index 7d32b3f..0000000
--- a/include/ajax_mod_menu.php
+++ /dev/null
@@ -1,17 +0,0 @@
-<?php
-//This file is part of NOALYSS and is under GPL 
-//see licence.txt
-
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_menu_ref.php';
-$m=new Menu_Ref($cn,$me_code);
-$msg="Modification ".$m->me_code.' '.h($m->me_menu);
-echo '<form method="POST" id="ajax_mod_menu_frm" onsubmit="return 
confirm_box(this,\'Vous confirmez ?\')">';
-echo HtmlInput::hidden('modify_menu', 1);
-
-require_once NOALYSS_INCLUDE.'/template/menu_detail.php';
-
-echo HtmlInput::submit('modify_menutb',_('Sauver'));
-echo HtmlInput::button_close('divmenu');
-echo '</form>';
-?>
diff --git a/include/ajax_mod_periode.php b/include/ajax_mod_periode.php
deleted file mode 100644
index f28cd13..0000000
--- a/include/ajax_mod_periode.php
+++ /dev/null
@@ -1,104 +0,0 @@
-<?php
-
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-// Copyright Author Dany De Bontridder address@hidden
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_periode.php';
-
-/**\file
- * \brief display or save a periode
- * variable received $op, $cn $g_user
- */
-$err = 0;
-$html = '';
-/* we check the security */
-switch ($op)
-{
-    case 'input_per':
-        $per = new Periode($cn, $_GET['p_id']);
-        $per->load();
-        $limit = $per->get_date_limit($_GET['p_id']);
-
-        $p_start = new IDate('p_start');
-        $p_start->value = $limit['p_start'];
-        $p_end = new IDate('p_end');
-        $p_end->value = $limit['p_end'];
-        $p_exercice = new INum('p_exercice');
-        $p_exercice->value = $per->p_exercice;
-
-        $html = '';
-        $html.=HtmlInput::anchor_close('mod_periode');
-        $html.=h2info(_('Modification période'));
-        $html.='<p> '._('Modifier les dates de début et fin de 
période').'</p>';
-        $html.='<p class="notice">'._('Cela pourrait avoir un impact sur les 
opérations déjà existantes').'</p>';
-        $html.='<form method="post" onsubmit="return save_periode(this)">';
-        $html.=dossier::hidden();
-        $html.='<table>';
-
-        $html.=tr(td(_(' Début période : ')) . td($p_start->input()));
-        $html.=tr(td(_(' Fin période : ')) . td($p_end->input()));
-        $html.=tr(td(_(' Exercice : ')) . td($p_exercice->input()));
-        $html.='</table>';
-        $html.=HtmlInput::submit('sauver', _('sauver'));
-        $html.=HtmlInput::button('close', _('fermer'), 
'onclick="removeDiv(\'mod_periode\')"');
-        $html.=HtmlInput::hidden('p_id', $_GET['p_id']);
-        $html.='</form>';
-        break;
-    case 'save_per':
-        $per = new Periode($cn, $_POST['p_id']);
-        $per->load();
-        if (isDate($_POST['p_start']) == null ||
-                isDate($_POST['p_end'] == null) ||
-                isNumber($_POST['p_exercice']) == 0 ||
-                $_POST['p_exercice'] > 2099 ||
-                $_POST['p_exercice'] < 2000)
-        {
-            $html = '';
-            $html.=HtmlInput::anchor_close('mod_periode');
-            $html.='<h2 class="info">'._('Modifier les dates de début et fin 
de période').'</h2>';
-            $html.="<div class=\"error\">"._('Erreur date invalide')."</div>";
-
-            $html.=HtmlInput::button('close', _('fermer'), 
'onclick="removeDiv(\'mod_periode\')"');
-        }
-        else
-        {
-            $sql = "update parm_periode set 
p_start=to_date($1,'DD.MM.YYYY'),p_end=to_date($2,'DD.MM.YYYY'),p_exercice=$3 
where p_id=$4";
-            try
-            {
-                $cn->exec_sql($sql, array($_POST['p_start'], $_POST['p_end'], 
$_POST['p_exercice'], $_POST['p_id']));
-                $html = '<h2 class="info"> Modifier les dates de début et fin 
de période</h2>';
-                $html.='<h2 class="notice"> Sauvé </h2>';
-
-                $html.=HtmlInput::button('close', _('Fermer'), 'onclick="      
refresh_window();"');
-            }
-            catch (Exception $e)
-            {
-                $html = alert($e->getTrace(), true);
-            }
-        }
-        break;
-}
-
-$html = escape_xml($html);
-header('Content-type: text/xml; charset=UTF-8');
-echo '<?xml version="1.0" encoding="UTF-8"?>';
-echo '<xml>';
-echo '<data>' . $html . '</data>';
-echo '</xml>';
diff --git a/include/ajax_mod_predf_op.php b/include/ajax_mod_predf_op.php
deleted file mode 100644
index 1e5ea89..0000000
--- a/include/ajax_mod_predf_op.php
+++ /dev/null
@@ -1,76 +0,0 @@
-<?php
-
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/**\file
- * \brief display a form to change the name of a predefined operation
- */
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-ob_start();
-require_once NOALYSS_INCLUDE.'/class_pre_operation.php';
-$op=new Pre_Operation($cn,$_GET['id']);
-$array=$op->load();
-echo HtmlInput::anchor_close('mod_predf_op');
-echo h2(_('Modification du nom'),' class="title"');
-
-echo '
-    <form method="POST" onsubmit="save_predf_op(this);return false;">';
-$name = new IText('opd_name');
-$name->value = $op->od_name;
-$name->size = 60;
-echo "Nom =" . $name->input();
-$opd_description=new ITextarea('od_description');
-$opd_description->style=' class="itextarea" 
style="width:30em;height:4em;vertical-align:top"';
-$opd_description->value=$op->od_description;
-echo '<p>';
-echo _("Description (max 50 car.)");
-echo $opd_description->input();
-echo '</p>';
-echo dossier::hidden() . HtmlInput::hidden('od_id', $_GET['id']);
-echo "<hr>";
-//////////////////////////////////////////////////////////////////////////////
-// Detail operation 
-//////////////////////////////////////////////////////////////////////////////
-echo $op->display();
-
-
-echo HtmlInput::submit('save', _('Sauve'));
-echo HtmlInput::button('close', _('Annuler'), 
'onclick="removeDiv(\'mod_predf_op\')"');
-echo '</form>';
-
-
-$html1 = ob_get_contents();
-ob_end_clean();
-$html = escape_xml($html1);
-if (headers_sent() ) 
-    { 
-    echo $html1; 
-    }
-else {
-    header('Content-type: text/xml; charset=UTF-8');
-}
-echo <<<EOF
-<?xml version="1.0" encoding="UTF-8"?>
-<data>
-<ctl>mod_predf_op</ctl>
-<code>$html</code>
-</data>
-EOF;
diff --git a/include/ajax_mod_stock_repo.php b/include/ajax_mod_stock_repo.php
deleted file mode 100644
index e808e7d..0000000
--- a/include/ajax_mod_stock_repo.php
+++ /dev/null
@@ -1,80 +0,0 @@
-<?php
-
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/**
- * @file
- * @brief show a depot
- *
- */
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_stock_sql.php';
-$st=new Stock_Sql($_GET['r_id']);
-
-?>
-<?php echo HtmlInput::title_box("Ajouter un 
dépôt","change_stock_repo_div","close")?>
-       <form method="post">
-               <?php echo HtmlInput::hidden("r_id",$_GET['r_id']);?>
-               <table>
-                       <tr>
-                               <td>
-                                       <?php echo _("Nom");?>
-                               </td>
-                               <td>
-                                       <?php $name=new 
IText("r_name",$st->r_name); echo $name->input();?>
-                               </td>
-                       </tr>
-                       <tr>
-                               <td>
-                                       <?php echo _("Adresse");?>
-                               </td>
-                               <td>
-                                       <?php $name=new 
IText("r_adress",$st->r_adress); echo $name->input();?>
-                               </td>
-                       </tr>
-                       <tr>
-                               <td>
-                                       <?php echo _("Ville");?>
-                               </td>
-                               <td>
-                                       <?php $name=new 
IText("r_city",$st->r_city); echo $name->input();?>
-                               </td>
-                       </tr>
-                       <tr>
-                               <td>
-                                       <?php echo _("Pays");?>
-                               </td>
-                               <td>
-                                       <?php $name=new 
IText("r_country",$st->r_country); echo $name->input();?>
-                               </td>
-                       </tr>
-                       <tr>
-                               <td>
-                                       <?php echo _("Téléphone");?>
-                               </td>
-                               <td>
-                                       <?php $name=new 
IText("r_phone",$st->r_phone); echo $name->input();?>
-                               </td>
-                       </tr>
-
-               </table>
-               <?php echo HtmlInput::submit("mod_stock",_("Sauver"))?>
-       </form>
\ No newline at end of file
diff --git a/include/ajax_preference.php b/include/ajax_preference.php
deleted file mode 100644
index 0b4c894..0000000
--- a/include/ajax_preference.php
+++ /dev/null
@@ -1,195 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-// Copyright Author Dany De Bontridder address@hidden
-/**\file
- * \brief this file is always included and then executed
- *        it permits to change the user preferences
- */
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_user.php';
-require_once NOALYSS_INCLUDE.'/class_iselect.php';
-require_once NOALYSS_INCLUDE.'/class_iperiod.php';
-require_once NOALYSS_INCLUDE.'/class_acc_report.php';
-require_once NOALYSS_INCLUDE.'/class_periode.php';
-echo HtmlInput::title_box(_('Préférence'), 'preference_div');
-echo '<DIV class="content">';
-echo '<p class="notice">';
-echo _("Si vous validez, la page sera rechargée et vous pourriez perdre ce que 
vous faisiez");
-echo '</p>';
-//----------------------------------------------------------------------
-//
-global $g_user;
-
-$g_user=new User($cn);
-$inside_dossier = false;
-
-if (isset($_REQUEST['gDossier']) && $_REQUEST['gDossier']<>0)
-{
-    $g_user->load_global_pref();
-    $msg = "";
-    $cn = new Database($_REQUEST['gDossier']);
-    $g_user->cn = $cn;
-    $inside_dossier = true;
-    $local_pref=$g_user->get_preference();
-}
-//////////////////////////////////////////////////////////////////////////
-// Theme
-//////////////////////////////////////////////////////////////////////////
-
-    $repo = new Database();
-// charge tous les styles
-    $res = $repo->exec_sql("select the_name from theme
-                    order by the_name");
-    $style = new ISelect('style_user');
-    $style->value = $repo->make_array("select the_name,the_name
-       from theme
-       order by the_name");
-    $style->selected =$_SESSION['g_theme'];
-?>
-
-<div class="content" >
-
-    <FORM  METHOD="POST">
-       <fieldset style="margin: 1%"><legend><?php echo _('Options 
Générales')?></legend>
-           <table>
-                <tr>
-                    <td>
-                        <?php echo _('Email')?>
-                    </td>
-                    <td>
-                        <input type="text" name="p_email" value="<?php echo 
$g_user->email?>" class="input_text">
-                    </td>
-                </tr>
-               <tr><td>
-                       Mot de passe :
-                   </td>
-                   <td><input type="password" value="" class="input_text" 
name="pass_1" nohistory>
-                       <input type="password" value="" class="input_text" 
name="pass_2" nohistory>
-                   </td>
-               </tr>
-
-               <tr>
-                   <td>
-                       <?php echo _('Thème');?>
-                   </td>
-                   <td>
-                       <?php echo $style->input();?>
-                   </td>
-               </tr>
-
-               <?php
-               if ($inside_dossier)
-               {
-                   $l_user_per = $g_user->get_periode();
-                   if ($l_user_per == "")
-                       $l_user_per = $cn->get_value("select min(p_id) from 
parm_periode where p_closed='f'");
-
-// if periode is closed then warns the users
-                   $period = new Periode($cn, $l_user_per);
-
-                   $period->p_id = $l_user_per;
-                   $period->jrn_def_id = 0;
-                   if ($period->is_closed($l_user_per) == 1)
-                   {
-                       $msg = _('Attention cette période est fermée, vous ne 
pourrez rien modifier dans le module comptable');
-                       $msg = '<h2 class="notice">' . $msg . '</h2>';
-                   }
-
-                   $period = new IPeriod("period");
-                   $period->user = $g_user;
-                   $period->cn = $cn;
-                   $period->filter_year = false;
-                   $period->value = $l_user_per;
-                   $period->type = ALL;
-                   $l_form_per = $period->input();
-                   ?>
-               <tr><td><?php echo _('Période');?></td>
-                   <td>
-                           <?php printf(' %s ', $l_form_per);?>
-                   </td>
-                   <td>  <?php echo $msg;?></td>
-               <tr>
-                   <td><?php echo _('Taille des pages');?></td>
-                   <td>
-                       <SELECT NAME="p_size">
-                           <option value="15">15
-                           <option value="25">25
-                           <option value="50">50
-                           <option value="100">100
-                           <option value="150">150
-                           <option value="200">200
-                           <option value="-1"><?php echo _('Illimité');?>
-                                   <?php
-                                   $label = ($_SESSION['g_pagesize'] == -1) ? 
_('Illimité') : $_SESSION['g_pagesize'];
-                                   echo '<option value="' . 
$_SESSION['g_pagesize'] . '" selected>' . $label;
-                                   ?>
-                       </SELECT>
-
-                   </td>
-               </tr>
-                   <?php 
-               }
-               ?>
-           </table>
-       </fieldset>
-       <?php
-       if ($inside_dossier)
-       {
-           /* Pref for welcome page */
-           echo '<fieldset style="margin: 1%">';
-           echo '<legend>' . _('Options pour la page d\'accueil') . 
'</legend>';
-           echo _('Mini-Rapport : ');
-           $rapport = new Acc_Report($cn);
-           $aRapport = $rapport->make_array();
-           $aRapport[] = array("value" => 0, "label" => _('Aucun mini 
rapport'));
-           $wRapport = new ISelect();
-           $wRapport->name = "minirap";
-           $wRapport->selected = $g_user->get_mini_report();
-           $wRapport->value = $aRapport;
-           echo $wRapport->input();
-           echo '<span class="notice">' . _('Le mini rapport est un rapport 
qui s\'affiche  sur votre page d\'accueil') . '</span>';
-           echo '</fieldset>';
-       }
-
-       echo '<fieldset  style="margin: 1%">';
-       echo '<legend>' . _('Langue') . '</legend>';
-       echo _('Selectionnez votre langue');
-       $aLang = array(array(_('Français'), 'fr_FR.utf8'),
-           array(_('Anglais'), 'en_US.utf8'),
-           array(_('Néerlandais'), 'nl_NL.utf8'),
-       );
-       echo '<select name="lang" id="l">';
-       for ($i = 0; $i < count($aLang); $i++)
-       {
-           $sel = "";
-           if ($aLang[$i][1] == $_SESSION['g_lang'])
-               $sel = " selected ";
-           printf('<option value="%s" %s>%s</option>', $aLang[$i][1], $sel, 
$aLang[$i][0]);
-       }
-       echo '</select>';
-       echo '</fieldset>';
-        
-        echo '<p style="text-align:center">';
-       echo HtmlInput::button_close('preference_div');
-       echo HtmlInput::submit("set_preference", _("Valider"));
-        echo '</p>';
-       echo '</form>';
-
-       echo "</DIV>";
-       ?>
diff --git a/include/ajax_search_action.php b/include/ajax_search_action.php
deleted file mode 100755
index aae5edf..0000000
--- a/include/ajax_search_action.php
+++ /dev/null
@@ -1,34 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-// Copyright Author Dany De Bontridder address@hidden
-/*! \file
- * \brief Search module
- */
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-include_once NOALYSS_INCLUDE.'/ac_common.php';
-require_once NOALYSS_INCLUDE.'/class_follow_up.php';
-
-$_REQUEST['ac']='FOLLOW';
-
-echo Follow_Up::display_search($cn,true);
-
-$sql=  "true ".Follow_Up::create_query($cn);
-echo Follow_Up::short_list($cn, $sql);
-?>
diff --git a/include/ajax_search_add_tag.php b/include/ajax_search_add_tag.php
deleted file mode 100644
index f40c9e1..0000000
--- a/include/ajax_search_add_tag.php
+++ /dev/null
@@ -1,45 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-// Copyright Author Dany De Bontridder address@hidden
-if ( !defined ('ALLOWED') )  die('Appel direct ne sont pas permis');
-
-require_once NOALYSS_INCLUDE.'/class_tag.php';
-ob_start();
-if ($_GET['clear']==1) {
-    /* Add a clear button */
-    echo Tag::add_clear_button($_GET['pref']);
-}
-$tag=new Tag($cn,$_GET['id']);
-$tag->update_search_cell($_GET['pref']);
-
-$response=  ob_get_clean();
-$html=escape_xml($response);
-header('Content-type: text/xml; charset=UTF-8');
-echo <<<EOF
-<?xml version="1.0" encoding="UTF-8"?>
-<data>
-<ctl></ctl>
-<html>$html</html>
-</data>
-EOF;
-exit();
-
-
-?>
-
diff --git a/include/ajax_search_clear_tag.php 
b/include/ajax_search_clear_tag.php
deleted file mode 100644
index fb8508a..0000000
--- a/include/ajax_search_clear_tag.php
+++ /dev/null
@@ -1,38 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-// Copyright Author Dany De Bontridder address@hidden
-if ( !defined ('ALLOWED') )  die('Appel direct ne sont pas permis');
-
-require_once NOALYSS_INCLUDE.'/class_tag.php';
-ob_start();
-echo Tag::button_search($_GET['pref']);
-$response=  ob_get_clean();
-$html=escape_xml($response);
-header('Content-type: text/xml; charset=UTF-8');
-echo <<<EOF
-<?xml version="1.0" encoding="UTF-8"?>
-<data>
-<ctl></ctl>
-<html>$html</html>
-</data>
-EOF;
-exit();
-
-
-?>
diff --git a/include/ajax_search_display_tag.php 
b/include/ajax_search_display_tag.php
deleted file mode 100644
index 90270be..0000000
--- a/include/ajax_search_display_tag.php
+++ /dev/null
@@ -1,40 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-// Copyright Author Dany De Bontridder address@hidden
-if ( !defined ('ALLOWED') )  die('Appel direct ne sont pas permis');
-
-require_once NOALYSS_INCLUDE.'/class_tag.php';
-ob_start();
-$tag=new Tag($cn);
-$tag->select_search($_GET['pref']);
-
-$response=  ob_get_clean();
-$html=escape_xml($response);
-header('Content-type: text/xml; charset=UTF-8');
-echo <<<EOF
-<?xml version="1.0" encoding="UTF-8"?>
-<data>
-<ctl></ctl>
-<code>$html</code>
-</data>
-EOF;
-exit();
-
-
-?>
diff --git a/include/ajax_tag_detail.php b/include/ajax_tag_detail.php
deleted file mode 100644
index 1226260..0000000
--- a/include/ajax_tag_detail.php
+++ /dev/null
@@ -1,51 +0,0 @@
-<?php
-/**
- * @brief display a window with the content of a tag
- */
-//This file is part of NOALYSS and is under GPL 
-//see licence.txt
-
-if ( !defined ('ALLOWED') )  die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_tool_uos.php';
-require_once NOALYSS_INCLUDE.'/class_tag.php';
-ob_start();
-$tag=new Tag($cn);
-$tag->data->t_id=$_GET['tag'];
-$tag->data->load();
-echo HtmlInput::title_box(_("Détail du dossier ou tag"), "tag_div");
-
-?>
-<?php
-// save via POST and reload page 
-if ($_GET['form']=='p') :    ?>
-    <form id="tag_detail_frm" method="POST" >
-<?php 
-/*
- * save via javascript and don't reload page
- */
-else :
-    ?>
-    <form id="tag_detail_frm" method="POST" onsubmit="return save_tag();">
-<?php        endif; ?>        
-    <?php
-    echo dossier::hidden();
-    echo HtmlInput::hidden('t_id', $_GET['tag']);
-    echo HtmlInput::hidden('ac',$_GET['ac']);
-    $data=$tag->data;
-    require_once 'template/tag_detail.php';
-    echo HtmlInput::submit("save_tag_sb", "Valider");
-    ?>
-</form>
-<?php
-    $response=  ob_get_clean();
-    $html=escape_xml($response);
-    header('Content-type: text/xml; charset=UTF-8');
-    echo <<<EOF
-<?xml version="1.0" encoding="UTF-8"?>
-<data>
-<ctl></ctl>
-<code>$html</code>
-</data>
-EOF;
-    exit();
-    ?>
\ No newline at end of file
diff --git a/include/ajax_tag_list.php b/include/ajax_tag_list.php
deleted file mode 100644
index f8dc506..0000000
--- a/include/ajax_tag_list.php
+++ /dev/null
@@ -1,45 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-// Copyright Author Dany De Bontridder address@hidden
-if ( !defined ('ALLOWED') )  die('Appel direct ne sont pas permis');
-
-require_once NOALYSS_INCLUDE.'/class_tag.php';
-ob_start();
-$tag=new Tag($cn);
-$tag->select();
-
-//------------------- Propose to add a tag
-
-$js=sprintf("onclick=\"show_tag('%s','%s','%s','j')\"",Dossier::id(),'','-1');
-echo HtmlInput::button("tag_add", _("Ajout d'un tag"), $js);
-
-$response=  ob_get_clean();
-$html=escape_xml($response);
-header('Content-type: text/xml; charset=UTF-8');
-echo <<<EOF
-<?xml version="1.0" encoding="UTF-8"?>
-<data>
-<ctl></ctl>
-<code>$html</code>
-</data>
-EOF;
-exit();
-
-
-?>
diff --git a/include/ajax_tag_save.php b/include/ajax_tag_save.php
deleted file mode 100644
index 9194a18..0000000
--- a/include/ajax_tag_save.php
+++ /dev/null
@@ -1,11 +0,0 @@
-<?php
-//This file is part of NOALYSS and is under GPL 
-//see licence.txt
-
-if ( !defined ('ALLOWED') )  die('Appel direct ne sont pas permis');
-
-require_once NOALYSS_INCLUDE.'/class_tag.php';
-$tag=new Tag($cn);
-$tag->save($_GET);
-
-?>
diff --git a/include/ajax_tag_select_search.php 
b/include/ajax_tag_select_search.php
deleted file mode 100644
index d364ec0..0000000
--- a/include/ajax_tag_select_search.php
+++ /dev/null
@@ -1,40 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-// Copyright Author Dany De Bontridder address@hidden
-if ( !defined ('ALLOWED') )  die('Appel direct ne sont pas permis');
-
-require_once NOALYSS_INCLUDE.'/class_tag.php';
-ob_start();
-$tag=new Tag($cn);
-$tag->select_search();
-
-$response=  ob_get_clean();
-$html=escape_xml($response);
-header('Content-type: text/xml; charset=UTF-8');
-echo <<<EOF
-<?xml version="1.0" encoding="UTF-8"?>
-<data>
-<ctl></ctl>
-<code>$html</code>
-</data>
-EOF;
-exit();
-
-
-?>
diff --git a/include/ajax_update_payment.php b/include/ajax_update_payment.php
deleted file mode 100644
index f12a61a..0000000
--- a/include/ajax_update_payment.php
+++ /dev/null
@@ -1,32 +0,0 @@
-<?php
-
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/**
- * @file
- * @brief refresh the area with payment method
- * -l for the ledger
- */
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_acc_ledger.php';
-$ledger=new Acc_Ledger($cn,$l);
-echo $ledger->input_paid(1);
-?>
diff --git a/include/ajax_update_predef.php b/include/ajax_update_predef.php
deleted file mode 100644
index 80eaf20..0000000
--- a/include/ajax_update_predef.php
+++ /dev/null
@@ -1,69 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief respond ajax request, the get contains
- *  the value :
- * - l for ledger 
- * - gDossier
- * Must return at least tva, htva and tvac
- */
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-
-require_once NOALYSS_INCLUDE.'/constant.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-require_once NOALYSS_INCLUDE.'/class_pre_operation.php';
-
-// Check if the needed field does exist
-extract ($_GET);
-foreach (array('l','t','d','gDossier') as $a)
-{
-    if ( ! isset (${$a}) )
-    {
-        echo "error $a is not set ";
-        exit();
-    }
-
-}
-$cn=new Database(dossier::id());
-$op=new Pre_operation_detail($cn);
-$op->set('ledger',$l);
-$op->set('ledger_type',$t);
-$op->set('direct',$d);
-$url=http_build_query(array('action'=>'use_opd','p_jrn_predef'=>$l,'ac'=>$_GET['ac'],'gDossier'=>dossier::id()));
-$html="";
-
-$html.=HtmlInput::title_box(_("Modèle d'opérations"), 'modele_op_div', 'hide');
-$html.=$op->show_button('do.php?'.$url);
-
-$html=escape_xml($html);
-header('Content-type: text/xml; charset=UTF-8');
-echo <<<EOF
-<?xml version="1.0" encoding="UTF-8"?>
-<data>
-<code></code>
-<value>$html</value>
-</data>
-EOF;
-
-?>
-
diff --git a/include/ajax_view_action.php b/include/ajax_view_action.php
deleted file mode 100644
index 38a1f79..0000000
--- a/include/ajax_view_action.php
+++ /dev/null
@@ -1,75 +0,0 @@
-<?php
-
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/**
- * @file
- * @brief show the detail of an action
- *
- */
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-ob_start();
-require_once NOALYSS_INCLUDE.'/class_follow_up.php';
-require_once NOALYSS_INCLUDE.'/class_default_menu.php';
-
-echo HtmlInput::title_box(_("Détail action"), $div);
-$act = new Follow_Up($cn);
-$act->ag_id = $ag_id;
-$act->get();
-$code='nok';
-if ($g_user->can_write_action($ag_id) == true || 
$g_user->can_read_action($ag_id) == true || $act->ag_dest == -1)
-{   
-        $menu=new Default_Menu();
-       echo $act->Display('READ', false, "ajax", "");
-       //$action=HtmlInput::array_to_string(array("gDossier","ag_id"), 
$_GET)."&ac=FOLLOW&sa=detail";
-        $action=  
"do.php?".http_build_query(array("gDossier"=>Dossier::id(),"ag_id"=>$ag_id,"ac"=>$menu->get('code_follow'),"sa"=>"detail"));
-        $code='ok';
-       if ( $_GET['mod']== 1) :
-            $forbidden=_("Accès interdit : vous n'avez pas accès à cette 
information, contactez votre responsable");
-       ?>
-<a href="<?php echo $action?>" target="_blank" class="smallbutton"><?php echo 
_("Modifier")?> </a>
-    <?php 
-        $code='nok';
-       endif;
-}
-else
-{
-       $forbidden = _("Ce document n'est pas accessible");
-       ?>
-       <div 
style="margin:0px;padding:0px;background-color:red;text-align:center;">
-        <h2 class="error"><?php echo $forbidden ?></h2>;
-</div>
-       <?php 
-}
-echo HtmlInput::button_close($div);
-$response =  ob_get_clean();
-$html=escape_xml($response);
-header('Content-type: text/xml; charset=UTF-8');
-echo <<<EOF
-<?xml version="1.0" encoding="UTF-8"?>
-<data>
-<ctl>$code</ctl>
-<code>$html</code>
-</data>
-EOF;
-exit();
-
-?>
\ No newline at end of file
diff --git a/include/ajax_view_mod_stock.php b/include/ajax_view_mod_stock.php
deleted file mode 100644
index d6426c7..0000000
--- a/include/ajax_view_mod_stock.php
+++ /dev/null
@@ -1,58 +0,0 @@
-<?php
-
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/**
- * @file
- * @brief show detail of inv.
- *
- */
-require_once NOALYSS_INCLUDE.'/class_stock_goods.php';
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-
-$st=new Stock_Goods($cn);
-$array=$cn->get_array("select * from stock_goods where 
c_id=$1",array($_GET['c_id']));
-echo HtmlInput::title_box(_("Détail changement"),$_GET['ctl']);
-$p_array=array();
-$p_array['p_date']=$cn->get_value("select to_char(c_date,'DD.MM.YYYY') from 
stock_change where c_id=$1",array($_GET['c_id']));
-$p_array['p_motif']=$cn->get_value("select c_comment from stock_change where 
c_id=$1",array($_GET['c_id']));
-$p_array['p_depot']=$cn->get_value("select r_id from stock_change where 
c_id=$1",array($_GET['c_id']));
-for ($i=0;$i<count($array);$i++)
-{
-       $p_array['f_id'.$i]=$array[$i]['f_id'];
-       $p_array['sg_code'.$i]=$array[$i]['sg_code'];
-       $p_array['sg_quantity'.$i]=$array[$i]['sg_quantity'];
-       $p_array['sg_type'.$i]=$array[$i]['sg_type'];
-        $p_array['row']=$i+1;
-}
-echo $st->input($p_array,true);
-?>
-<form method="POST">
-       <?php echo HtmlInput::hidden('c_id',$_GET['c_id']);?>
-       <p>
-       <?php $ck=new ICheckBox("ok"," 1");
-                       $ck->label= _("Cochez pour confirmer effacement");
-                       echo $ck->input();?>
-       </p>
-       <?php echo HtmlInput::submit("del",_("Effacer"));?>
-       <?php echo HtmlInput::button_close($_GET['ctl'])?>
-       <?php echo HtmlInput::hidden('r_id',$p_array['p_depot'])?>
-</form>
diff --git a/include/anc_acc_balance.inc.php b/include/anc_acc_balance.inc.php
index efa03f8..e58a909 100644
--- a/include/anc_acc_balance.inc.php
+++ b/include/anc_acc_balance.inc.php
@@ -3,7 +3,7 @@
 //see licence.txt
 
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_anc_acc_list.php';
+require_once NOALYSS_INCLUDE.'/class/class_anc_acc_list.php';
 echo '<div class="content">';
 $tab = new Anc_Acc_List($cn);
 $tab->get_request();
diff --git a/include/anc_acc_table.inc.php b/include/anc_acc_table.inc.php
index 357c2dd..d1ce3a9 100644
--- a/include/anc_acc_table.inc.php
+++ b/include/anc_acc_table.inc.php
@@ -3,7 +3,7 @@
 //see licence.txt
 
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_anc_table.php';
+require_once NOALYSS_INCLUDE.'/class/class_anc_table.php';
 $tab = new Anc_Table($cn);
 $tab->get_request();
 echo '<form method="get">';
diff --git a/include/anc_balance_double.inc.php 
b/include/anc_balance_double.inc.php
index b8baab3..fd450aa 100644
--- a/include/anc_balance_double.inc.php
+++ b/include/anc_balance_double.inc.php
@@ -3,7 +3,7 @@
 //see licence.txt
 
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_anc_balance_double.php';
+require_once NOALYSS_INCLUDE.'/class/class_anc_balance_double.php';
 $bc = new Anc_Balance_Double($cn);
 $bc->get_request();
 echo '<form method="get">';
diff --git a/include/anc_balance_simple.inc.php 
b/include/anc_balance_simple.inc.php
index fdab93c..aa28ad8 100644
--- a/include/anc_balance_simple.inc.php
+++ b/include/anc_balance_simple.inc.php
@@ -3,7 +3,7 @@
 //see licence.txt
 
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_anc_balance_simple.php';
+require_once NOALYSS_INCLUDE.'/class/class_anc_balance_simple.php';
 $bs = new Anc_Balance_Simple($cn);
 $bs->get_request();
 echo '<form method="get">';
diff --git a/include/anc_great_ledger.inc.php b/include/anc_great_ledger.inc.php
index fc7c51a..40bbe3b 100644
--- a/include/anc_great_ledger.inc.php
+++ b/include/anc_great_ledger.inc.php
@@ -5,7 +5,7 @@
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
 echo '<div style="content">';
 
-require_once NOALYSS_INCLUDE.'/class_anc_grandlivre.php';
+require_once NOALYSS_INCLUDE.'/class/class_anc_grandlivre.php';
 
 $grandLivre=new Anc_Grandlivre($cn);
 
diff --git a/include/anc_group.inc.php b/include/anc_group.inc.php
index fdda9f3..97651f2 100644
--- a/include/anc_group.inc.php
+++ b/include/anc_group.inc.php
@@ -24,9 +24,9 @@
  *
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_itext.php';
-require_once NOALYSS_INCLUDE.'/class_iselect.php';
-require_once NOALYSS_INCLUDE.'/class_anc_group.php';
+require_once NOALYSS_INCLUDE.'/lib/class_itext.php';
+require_once NOALYSS_INCLUDE.'/lib/class_iselect.php';
+require_once NOALYSS_INCLUDE.'/class/class_anc_group.php';
 $r=new Anc_Group($cn);
 
 
diff --git a/include/anc_group_balance.inc.php 
b/include/anc_group_balance.inc.php
index 532c897..91ba047 100644
--- a/include/anc_group_balance.inc.php
+++ b/include/anc_group_balance.inc.php
@@ -3,7 +3,7 @@
 //see licence.txt
 
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_anc_group.php';
+require_once NOALYSS_INCLUDE.'/class/class_anc_group.php';
 
 $gr = new Anc_Group($cn);
 $gr->get_request();
diff --git a/include/anc_history.inc.php b/include/anc_history.inc.php
index 7efb2a6..0bc5312 100644
--- a/include/anc_history.inc.php
+++ b/include/anc_history.inc.php
@@ -5,7 +5,7 @@
 
 
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_anc_listing.php';
+require_once NOALYSS_INCLUDE.'/class/class_anc_listing.php';
 $list = new Anc_Listing($cn);
 $list->get_request();
 
diff --git a/include/anc_key.inc.php b/include/anc_key.inc.php
index b9d5a22..097c083 100644
--- a/include/anc_key.inc.php
+++ b/include/anc_key.inc.php
@@ -29,7 +29,7 @@
 if (!defined('ALLOWED'))
     die('Appel direct ne sont pas permis');
 global $cn, $g_user;
-require_once NOALYSS_INCLUDE.'/class_anc_key.php';
+require_once NOALYSS_INCLUDE.'/class/class_anc_key.php';
 $op=HtmlInput::default_value_request("op", "list");
 
 switch ($op)
diff --git a/include/anc_od.inc.php b/include/anc_od.inc.php
index 54d3339..17600d7 100644
--- a/include/anc_od.inc.php
+++ b/include/anc_od.inc.php
@@ -26,12 +26,12 @@
  *
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_ihidden.php';
-require_once NOALYSS_INCLUDE.'/class_iselect.php';
-require_once NOALYSS_INCLUDE.'/class_anc_account.php';
-require_once  NOALYSS_INCLUDE.'/class_anc_operation.php';
-require_once  NOALYSS_INCLUDE.'/class_anc_plan.php';
-require_once  NOALYSS_INCLUDE.'/class_anc_group_operation.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ihidden.php';
+require_once NOALYSS_INCLUDE.'/lib/class_iselect.php';
+require_once NOALYSS_INCLUDE.'/class/class_anc_account.php';
+require_once  NOALYSS_INCLUDE.'/class/class_anc_operation.php';
+require_once  NOALYSS_INCLUDE.'/class/class_anc_plan.php';
+require_once  NOALYSS_INCLUDE.'/class/class_anc_group_operation.php';
 
 global $g_user;
 
diff --git a/include/anc_pa.inc.php b/include/anc_pa.inc.php
index 23e6798..a5477b2 100644
--- a/include/anc_pa.inc.php
+++ b/include/anc_pa.inc.php
@@ -25,8 +25,8 @@
  *
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_anc_plan.php';
-require_once NOALYSS_INCLUDE.'/class_anc_account.php';
+require_once NOALYSS_INCLUDE.'/class/class_anc_plan.php';
+require_once NOALYSS_INCLUDE.'/class/class_anc_account.php';
 $ret="";
 $str_dossier=Dossier::get();
 //---------------------------------------------------------------------------
diff --git a/include/balance.inc.php b/include/balance.inc.php
index 0480987..202bb8e 100644
--- a/include/balance.inc.php
+++ b/include/balance.inc.php
@@ -24,15 +24,15 @@
  * some variable are already defined ($cn, $g_user ...)
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-include_once  NOALYSS_INCLUDE.'/ac_common.php';
-include_once NOALYSS_INCLUDE.'/class_acc_balance.php';
-require_once NOALYSS_INCLUDE.'/class_iselect.php';
-require_once NOALYSS_INCLUDE.'/class_ispan.php';
-require_once NOALYSS_INCLUDE.'/class_icheckbox.php';
-require_once NOALYSS_INCLUDE.'/class_ihidden.php';
-require_once NOALYSS_INCLUDE.'/class_acc_ledger.php';
-require_once NOALYSS_INCLUDE.'/class_periode.php';
-require_once NOALYSS_INCLUDE.'/class_exercice.php';
+include_once  NOALYSS_INCLUDE.'/lib/ac_common.php';
+include_once NOALYSS_INCLUDE.'/class/class_acc_balance.php';
+require_once NOALYSS_INCLUDE.'/lib/class_iselect.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ispan.php';
+require_once NOALYSS_INCLUDE.'/lib/class_icheckbox.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ihidden.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_ledger.php';
+require_once NOALYSS_INCLUDE.'/class/class_periode.php';
+require_once NOALYSS_INCLUDE.'/class/class_exercice.php';
 global $g_user;
 $gDossier=dossier::id();
 $exercice=(isset($_GET['exercice']))?$_GET['exercice']:$g_user->get_exercice();
diff --git a/include/balance_age.inc.php b/include/balance_age.inc.php
index ba5a4da..ca4aa49 100644
--- a/include/balance_age.inc.php
+++ b/include/balance_age.inc.php
@@ -65,7 +65,7 @@ 
$w_lettre->selected=HtmlInput::default_value_get('p_let','unlet');
 ?>
 </form>
 <?php
-    require_once 'class_balance_age.php';
+    require_once 'class/class_balance_age.php';
     $balance=new Balance_Age($cn);
     $type=HtmlInput::default_value_get('p_type', 'C');
     $let=HtmlInput::default_value_get('p_let', 'unlet');
diff --git a/include/balance_card.inc.php b/include/balance_card.inc.php
index 9cf7642..abdd029 100644
--- a/include/balance_card.inc.php
+++ b/include/balance_card.inc.php
@@ -23,7 +23,7 @@
  * \brief show the status of a card
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_exercice.php';
+require_once NOALYSS_INCLUDE.'/class/class_exercice.php';
 
 global $g_user;
 echo '<div class="content" style="width:90%;margin-left:5%">';
diff --git a/include/balance_card_ageing.inc.php 
b/include/balance_card_ageing.inc.php
index 60fe728..25599cb 100644
--- a/include/balance_card_ageing.inc.php
+++ b/include/balance_card_ageing.inc.php
@@ -25,8 +25,8 @@ if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas 
permis');
  * @brief 
  * @param type $name Descriptionara
  */
-require_once NOALYSS_INCLUDE.'/class_exercice.php';
-require_once NOALYSS_INCLUDE.'/class_balance_age.php';
+require_once NOALYSS_INCLUDE.'/class/class_exercice.php';
+require_once NOALYSS_INCLUDE.'/class/class_balance_age.php';
 $let=( isset ($_GET['p_let']))?'let':'unlet';
 
 $export_csv = '<FORM METHOD="get" ACTION="export.php" style="display:inline">';
diff --git a/include/bank.inc.php b/include/bank.inc.php
index 6d7ff1c..d0b0a15 100644
--- a/include/bank.inc.php
+++ b/include/bank.inc.php
@@ -21,10 +21,10 @@
  * the supplier category
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_iselect.php';
-require_once NOALYSS_INCLUDE.'/class_ihidden.php';
-require_once NOALYSS_INCLUDE.'/class_bank.php';
-require_once NOALYSS_INCLUDE.'/class_ibutton.php';
+require_once NOALYSS_INCLUDE.'/lib/class_iselect.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ihidden.php';
+require_once NOALYSS_INCLUDE.'/class/class_bank.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ibutton.php';
 global $g_user;
 
 $low_action=(isset($_REQUEST['sb']))?$_REQUEST['sb']:'list';
diff --git a/include/calendar.inc.php b/include/calendar.inc.php
index 74db9a8..4f665c1 100644
--- a/include/calendar.inc.php
+++ b/include/calendar.inc.php
@@ -8,7 +8,7 @@
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
 
-require_once NOALYSS_INCLUDE.'/class_calendar.php';
+require_once NOALYSS_INCLUDE.'/class/class_calendar.php';
 $cal=new Calendar();
 $cal->default_periode=(isset ($_GET['in']))?$_GET['in']:$g_user->get_periode();
 
diff --git a/include/card_attr.inc.php b/include/card_attr.inc.php
index 151150f..6c182c1 100644
--- a/include/card_attr.inc.php
+++ b/include/card_attr.inc.php
@@ -23,7 +23,7 @@
  * \brief Manage the attributs
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_fiche_attr.php';
+require_once NOALYSS_INCLUDE.'/class/class_fiche_attr.php';
 
 
 
diff --git a/include/cat_document.inc.php b/include/cat_document.inc.php
index 43d2cf2..a0b458f 100644
--- a/include/cat_document.inc.php
+++ b/include/cat_document.inc.php
@@ -26,7 +26,7 @@
 
 // show list of document
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_document_type.php';
+require_once NOALYSS_INCLUDE.'/class/class_document_type.php';
 
 if ( isset($_POST['add']) )
 {
diff --git a/include/category_card.inc.php b/include/category_card.inc.php
index 845d3c6..5e5ad00 100644
--- a/include/category_card.inc.php
+++ b/include/category_card.inc.php
@@ -26,7 +26,7 @@
  * the customer category
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_contact.php';
+require_once NOALYSS_INCLUDE.'/class/class_contact.php';
 
 $str_dossier=Dossier::get();
 /* $sub_action = sb = detail */
diff --git a/include/category_detail.inc.php b/include/category_detail.inc.php
index 95e68b9..bd08122 100644
--- a/include/category_detail.inc.php
+++ b/include/category_detail.inc.php
@@ -32,7 +32,7 @@
 // Save modification
 //---------------------------------------------------------------------------
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_customer.php';
+require_once NOALYSS_INCLUDE.'/class/class_customer.php';
 if ( isset ($_POST['mod']))
 {
 
diff --git a/include/category_followup.inc.php 
b/include/category_followup.inc.php
index d4b0a7f..1e011c8 100644
--- a/include/category_followup.inc.php
+++ b/include/category_followup.inc.php
@@ -27,7 +27,7 @@
  *  - $cn = database connection
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_follow_up.php';
+require_once NOALYSS_INCLUDE.'/class/class_follow_up.php';
 
 /**
  *\note problem with ShowActionList, this function is local
diff --git a/include/category_operation.inc.php 
b/include/category_operation.inc.php
index 1fb5b06..34b8fac 100644
--- a/include/category_operation.inc.php
+++ b/include/category_operation.inc.php
@@ -29,7 +29,7 @@
  * - $ss_action
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_acc_ledger.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_ledger.php';
 $f=new Fiche($cn,$_REQUEST['f_id']);
 $qcode=$f->get_quick_code();
 $_GET['qcode']=$qcode;
diff --git a/include/cfgfiche.inc.php b/include/cfgfiche.inc.php
index 17620fa..cbca11e 100644
--- a/include/cfgfiche.inc.php
+++ b/include/cfgfiche.inc.php
@@ -21,16 +21,16 @@
  * \brief module to manage the card (removing, listing, creating, modify 
attribut)
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/ac_common.php';
-require_once NOALYSS_INCLUDE.'/class_itext.php';
-require_once NOALYSS_INCLUDE.'/class_ihidden.php';
-require_once NOALYSS_INCLUDE.'/class_fiche.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
+require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
+require_once NOALYSS_INCLUDE.'/lib/class_itext.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ihidden.php';
+require_once NOALYSS_INCLUDE.'/class/class_fiche.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
 require_once NOALYSS_INCLUDE.'/user_menu.php';
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-require_once NOALYSS_INCLUDE.'/class_sort_table.php';
-require_once NOALYSS_INCLUDE.'/class_fiche_def.php';
-require_once NOALYSS_INCLUDE.'/class_tool_uos.php';
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+require_once NOALYSS_INCLUDE.'/lib/class_sort_table.php';
+require_once NOALYSS_INCLUDE.'/class/class_fiche_def.php';
+require_once NOALYSS_INCLUDE.'/lib/class_tool_uos.php';
 
 $retour=HtmlInput::button_anchor("Retour à la liste", 
HtmlInput::get_to_string(array("gDossier","ac")));
 $action=HtmlInput::default_value_post('action', '');
diff --git a/include/cfgledger.inc.php b/include/cfgledger.inc.php
index b0b1bea..90f0d1f 100644
--- a/include/cfgledger.inc.php
+++ b/include/cfgledger.inc.php
@@ -27,12 +27,12 @@
  *
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-require_once NOALYSS_INCLUDE.'/ac_common.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_user.php';
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/class/class_user.php';
 require_once NOALYSS_INCLUDE.'/user_menu.php';
-require_once NOALYSS_INCLUDE.'/class_acc_ledger.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_ledger.php';
 
 $gDossier=dossier::id();
 global $cn;
diff --git a/include/cfgplugin.inc.php b/include/cfgplugin.inc.php
index b440dd3..afa0e99 100644
--- a/include/cfgplugin.inc.php
+++ b/include/cfgplugin.inc.php
@@ -19,7 +19,7 @@
 // Copyright (2014) Author Dany De Bontridder <address@hidden>
 
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_extension.php';
+require_once NOALYSS_INCLUDE.'/class/class_extension.php';
 
 /**
  * @file
diff --git a/include/cfgtags.inc.php b/include/cfgtags.inc.php
index 2a4743e..3f4c192 100644
--- a/include/cfgtags.inc.php
+++ b/include/cfgtags.inc.php
@@ -24,8 +24,8 @@ if ( !defined ('ALLOWED') )  die('Appel direct ne sont pas 
permis');
  * @brief Manage the tags
  *
  */
-require_once NOALYSS_INCLUDE.'/class_tag.php';
-require_once NOALYSS_INCLUDE.'/class_tool_uos.php';
+require_once NOALYSS_INCLUDE.'/class/class_tag.php';
+require_once NOALYSS_INCLUDE.'/lib/class_tool_uos.php';
 
 $tag=new Tag($cn);
 $uos=new Tool_Uos('tag');
diff --git a/include/class/class_acc_account.php 
b/include/class/class_acc_account.php
new file mode 100644
index 0000000..1e69f37
--- /dev/null
+++ b/include/class/class_acc_account.php
@@ -0,0 +1,233 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+// Copyright Author Dany De Bontridder address@hidden
+/*! \file
+ * \brief Manage the account
+ */
+/*!
+ * \brief Manage the account from the table tmp_pcmn
+ */
+require_once NOALYSS_INCLUDE.'/lib/class_iselect.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+
+class Acc_Account
+{
+    var $db;          /*!< $db database connection */
+    static private $variable = array("value"=>'pcm_val',
+                                     'type'=>'pcm_type',
+                                     'parent'=>'pcm_val_parent',
+                                     'libelle'=>'pcm_lib');
+    private  $pcm_val;
+    private  $pcm_type;
+    private  $pcm_parent;
+    private  $pcm_lib;
+    static public $type=array(
+                            array('label'=>'Actif','value'=>'ACT'),
+                            array('label'=>'Passif','value'=>'PAS'),
+                            array('label'=>'Actif c. 
inverse','value'=>'ACTINV'),
+                            array('label'=>'Passif 
c.inverse','value'=>'PASINV'),
+                            array('label'=>'Produit','value'=>'PRO'),
+                            array('label'=>'Produit 
Inverse','value'=>'PROINV'),
+                            array('label'=>'Charge','value'=>'CHA'),
+                            array('label'=>'Charge Inverse','value'=>'CHAINV'),
+                            array('label'=>'Non defini','value'=>'CON')
+                        );
+
+    function __construct ($p_cn,$p_id=0)
+    {
+        $this->db=$p_cn;
+        $this->pcm_val=$p_id;
+    }
+    public function get_parameter($p_string)
+    {
+        if ( array_key_exists($p_string,self::$variable) )
+        {
+            $idx=self::$variable[$p_string];
+            return $this->$idx;
+        }
+        else
+            throw new Exception (__FILE__.":".__LINE__._('Erreur attribut 
inexistant'));
+    }
+
+    function set_parameter($p_string,$p_value)
+    {
+        if ( array_key_exists($p_string,self::$variable) )
+        {
+            $idx=self::$variable[$p_string];
+            if ($this->check($idx,$p_value) == true )      
$this->$idx=$p_value;
+        }
+        else
+            throw new Exception (__FILE__.":".__LINE__._('Erreur attribut 
inexistant'));
+
+
+    }
+    /*!\brief Return the name of a account
+     *        it doesn't change any data member
+     * \return string with the pcm_lib
+     */
+    function get_lib()
+    {
+        $ret=$this->db->exec_sql(
+                 "select pcm_lib from tmp_pcmn where
+                 pcm_val=$1",array($this->pcm_val));
+        if ( Database::num_row($ret) != 0)
+        {
+            $r=Database::fetch_array($ret);
+            $this->pcm_lib=$r['pcm_lib'];
+        }
+        else
+        {
+            $this->pcm_lib=_("Poste inconnu");
+        }
+        return $this->pcm_lib;
+    }
+    /*!\brief Check that the value are valid
+     *\return true if all value are valid otherwise false
+     */
+    function check ($p_member='',$p_value='')
+    {
+        // if there is no argument we check all the member
+        if ($p_member == '' && $p_value== '' )
+        {
+            foreach (self::$variable as $l=>$k)
+            {
+                $this->check($k,$this->$k);
+            }
+        }
+        else
+        {
+            // otherwise we check only the value
+            if ( strcmp ($p_member,'pcm_val') == 0 )
+            {
+                    return true;
+            }
+            else if ( strcmp ($p_member,'pcm_val_parent') == 0 )
+            {
+                    return true;
+            }
+            else if ( strcmp ($p_member,'pcm_lib') == 0 )
+            {
+                return true;
+            }
+            else if ( strcmp ($p_member,'pcm_type') == 0 )
+            {
+                foreach (self::$type as $l=>$k)
+                {
+                    if ( strcmp ($k['value'],$p_value) == 0 ) return true;
+
+                }
+                throw new Exception(_('type de compte incorrect ').$p_value);
+            }
+            throw new Exception (_('Donnee member inconnue ').$p_member);
+        }
+
+    }
+    /*!\brief Get all the value for this object from the database
+     *        the data member are set
+     * \return false if this account doesn't exist otherwise true
+     */
+    function load()
+    {
+        $ret=$this->db->exec_sql("select pcm_lib,pcm_val_parent,pcm_type from
+                                 tmp_pcmn where 
pcm_val=$1",array($this->pcm_val));
+        $r=Database::fetch_all($ret);
+
+        if ( ! $r ) return false;
+        $this->pcm_lib=$r[0]['pcm_lib'];
+        $this->pcm_val_parent=$r[0]['pcm_val_parent'];
+        $this->pcm_type=$r[0]['pcm_type'];
+        return true;
+
+    }
+    function form($p_table=true)
+    {
+        $wType=new ISelect();
+        $wType->name='p_type';
+        $wType->value=self::$type;
+
+        if ( ! $p_table )
+        {
+            $ret='    <TR>
+                 <TD>
+                 <INPUT TYPE="TEXT" NAME="p_val" SIZE=7>
+                 </TD>
+                 <TD>
+                 <INPUT TYPE="TEXT" NAME="p_lib" size=50>
+                 </TD>
+                 <TD>
+                 <INPUT TYPE="TEXT" NAME="p_parent" size=5>
+                 </TD>
+                 <TD>';
+
+            $ret.=$wType->input().'</TD>';
+            return $ret;
+        }
+        else
+        {
+            $ret='<TABLE><TR>';
+            $ret.=sprintf ('<TD>'._('Numéro de classe').' </TD><TD><INPUT 
TYPE="TEXT" name="p_val" value="%s"></TD>',$this->pcm_val);
+            $ret.="</TR><TR>";
+            $ret.=sprintf('<TD>'._('Libellé').' </TD><TD><INPUT TYPE="TEXT" 
size="70" NAME="p_lib" value="%s"></TD>',h($this->pcm_lib));
+            $ret.= "</TR><TR>";
+            $ret.=sprintf ('<TD>'._('Classe Parent').'</TD><TD><INPUT 
TYPE="TEXT" name="p_parent" value="%s"></TD>',$this->pcm_val_parent);
+            $ret.='</tr><tr>';
+            $wType->selected=$this->pcm_type;
+            $ret.="<td> Type de poste </td>";
+            $ret.= '<td>'.$wType->input().'</td>';
+            $ret.="</TR> </TABLE>";
+            $ret.=dossier::hidden();
+
+            return $ret;
+        }
+    }
+    function count($p_value)
+    {
+        $sql="select count(*) from tmp_pcmn where pcm_val=$1";
+        return $this->db->get_value($sql,array($p_value));
+    }
+    /*!\brief for developper only during test */
+    static function test_me()
+    {
+        $cn=new Database(dossier::id());
+
+    }
+    /**
+     address@hidden update an accounting, but you can update pcm_val only if
+     * this accounting has never been used before  */
+    function update($p_old)
+    {
+        if (strcmp(trim($p_old), trim($this->pcm_val)) !=0 )
+        {
+            $count=$this->db->get_value('select count(*) from jrnx where 
j_poste=$1',
+                                        array($p_old)
+                                       );
+            if ($count != 0)
+                throw new Exception(_('Impossible de changer la valeur: poste 
déjà utilisé'));
+        }
+        $this->pcm_lib=mb_substr($this->pcm_lib,0,150);
+        $this->check();
+        $sql="update tmp_pcmn set pcm_val=$1, 
pcm_lib=$2,pcm_val_parent=$3,pcm_type=$4 where pcm_val=$5";
+        $Ret=$this->db->exec_sql($sql,array($this->pcm_val,
+                                            $this->pcm_lib,
+                                            $this->pcm_val_parent,
+                                            $this->pcm_type,
+                                            $p_old));
+    }
+}
diff --git a/include/class/class_acc_account_ledger.php 
b/include/class/class_acc_account_ledger.php
new file mode 100644
index 0000000..0d5afa6
--- /dev/null
+++ b/include/class/class_acc_account_ledger.php
@@ -0,0 +1,657 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+// Copyright Author Dany De Bontridder address@hidden
+/*! \file
+ * \brief Manage the account
+ */
+/*!
+ * \brief Manage the account from the table jrn, jrnx or tmp_pcmn
+ */
+require_once NOALYSS_INCLUDE.'/lib/class_ihidden.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+
+class Acc_Account_Ledger
+{
+    var $db;          /*!< $db database connection */
+    var $id;          /*!< $id poste_id (pcm_val)*/
+    var $label;       /*!< $label label of the poste */
+    var $parent;      /*!< $parent parent account */
+    var $row;         /*!< $row double array see get_row */
+    var $tot_deb;    /*!< value set by  get_row */
+    var $tot_cred;    /*!< value by  get_row */
+    function __construct ($p_cn,$p_id)
+    {
+        $this->db=$p_cn;
+        $this->id=$p_id;
+    }
+    /**
+     address@hidden get the row thanks the resource
+     address@hidden double array 
(j_date,deb_montant,cred_montant,description,jrn_name,j_debit,jr_internal)
+     *         (tot_deb,tot_credit)
+     */
+    private function get_row_sql($Res)
+    {
+        $array=array();
+        $tot_cred=0.0;
+        $tot_deb=0.0;
+        $Max=Database::num_row($Res);
+        if ( $Max == 0 ) return null;
+        for ($i=0;$i<$Max;$i++)
+        {
+            $array[]=Database::fetch_array($Res,$i);
+            if ($array[$i]['j_debit']=='t')
+            {
+                $tot_deb+=$array[$i]['deb_montant'] ;
+            }
+            else
+            {
+                $tot_cred+=$array[$i]['cred_montant'] ;
+            }
+        }
+        $this->row=$array;
+        $this->tot_deb=$tot_deb;
+        $this->tot_cred=$tot_cred;
+        return array($array,$tot_deb,$tot_cred);
+
+    }
+    /*!
+     * \brief  Get data for accounting entry between 2 periode
+     *
+     * \param  $p_from periode from
+     * \param  $p_to   end periode
+     * \return double array 
(j_date,deb_montant,cred_montant,description,jrn_name,j_debit,jr_internal)
+     *         (tot_deb,tot_credit
+     *
+     */
+    function get_row($p_from,$p_to)
+    {
+        $periode=sql_filter_per($this->db,$p_from,$p_to,'p_id','jr_tech_per');
+
+        $Res=$this->db->exec_sql("select distinct 
j_id,jr_id,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,j_date,".
+                                 "case when j_debit='t' then j_montant else 0 
end as deb_montant,".
+                                 "case when j_debit='f' then j_montant else 0 
end as cred_montant,".
+                                 " jr_comment as description,jrn_def_name as 
jrn_name,".
+                                 "j_debit, jr_internal,jr_pj_number ".
+                                 " from jrnx left join jrn_def on 
jrn_def_id=j_jrn_def ".
+                                 " left join jrn on jr_grpt_id=j_grpt".
+                                 " where j_poste=".$this->id." and ".$periode.
+                                 " order by j_date");
+        return $this->get_row_sql($Res);
+    }
+    /*!
+     * \brief  Get data for accounting entry between 2 date
+     *
+     * \param  $p_from date from
+     * \param  $p_to   end date
+     *\param $let 0 means all rows, 1 only lettered, 2 only unlettered
+        * \param $solded 0 means all account, 1 means only accounts with a 
saldo <> 0
+     *\note the data are filtered by the access of the current user
+     * \return double array 
(j_date,deb_montant,cred_montant,description,jrn_name,j_debit,jr_internal)
+     *         (tot_deb,tot_credit
+     *
+     */
+    function get_row_date($p_from,$p_to,$let=0,$solded=0)
+    {
+        global $g_user;
+        $filter_sql=$g_user->get_ledger_sql('ALL',3);
+        $sql_let='';
+        switch ($let)
+        {
+        case 0:
+                break;
+        case 1:
+            $sql_let=' and j_id in (select j_id from letter_cred union select 
j_id from letter_deb)';
+            break;
+        case '2':
+            $sql_let=' and j_id not in (select j_id from letter_cred union 
select j_id from letter_deb) ';
+            break;
+        }
+       if ( $solded == 1)
+         {
+           $filter=str_replace('jrn_def_id','jr_def_id',$filter_sql);
+           $bal_sql="select sum(amount_deb) as s_deb,sum(amount_cred) as 
s_cred, j_poste
+                               from                                            
(select case when j_debit='t' then j_montant else 0 end as amount_deb,
+                                                               case when 
j_debit='f' then j_montant else 0 end as amount_cred,
+                                                               j_poste
+                                                               from jrnx join 
jrn on (j_grpt = jr_grpt_id)
+                                                               where
+                                                               j_poste=$1 and
+                                                               $filter and
+                                                               ( 
to_date($2,'DD.MM.YYYY') <= j_date and
+                                  to_date($3,'DD.MM.YYYY') >= j_date  )) as 
signed_amount
+                                               group by j_poste
+                                               ";
+           $r=$this->db->get_array($bal_sql,array($this->id,$p_from,$p_to));
+           if ( $this->db->count() == 0 ) return array();
+           if ($r[0]['s_deb']==$r[0]['s_cred']) return array();
+         }
+        $Res=$this->db->exec_sql("select  jr_id,to_char(j_date,'DD.MM.YYYY') 
as j_date_fmt,j_date,".
+                                 "case when j_debit='t' then j_montant else 0 
end as deb_montant,".
+                                 "case when j_debit='f' then j_montant else 0 
end as cred_montant,".
+                                 " case when j_text is null or j_text = '' 
then jr_comment 
+                                   else jr_comment||' '||j_text  end
+                as description,jrn_def_name as jrn_name,".
+                                 "j_debit, jr_internal,jr_pj_number,
+                                                                
coalesce(comptaproc.get_letter_jnt(j_id),-1) as letter ".
+                                 ",pcm_lib ".
+                                
",jr_tech_per,p_exercice,jrn_def_name,jrn_def_code".
+                                 " from jrnx left join jrn_def on 
(jrn_def_id=j_jrn_def )".
+                                 " left join jrn on (jr_grpt_id=j_grpt)".
+                                 " left join tmp_pcmn on (j_poste=pcm_val)".
+                                " left join parm_periode on (p_id=jr_tech_per) 
".
+                                 " where j_poste=$1 and ".
+                                 " ( to_date($2,'DD.MM.YYYY') <= j_date and ".
+                                 "   to_date($3,'DD.MM.YYYY') >= j_date )".
+                                 " and $filter_sql  $sql_let ".
+                                 " order by 
j_date,substring(jr_pj_number,'[0-9]+$') asc",array($this->id,$p_from,$p_to));
+        return $this->get_row_sql($Res);
+    }
+
+
+    /*!\brief Return the name of a account
+     *        it doesn't change any data member
+     * \return string with the pcm_lib
+     */
+    function get_name()
+    {
+        $ret=$this->db->exec_sql(
+                 "select pcm_lib from tmp_pcmn where
+                 pcm_val=$1",array($this->id));
+        if ( Database::num_row($ret) != 0)
+        {
+            $r=Database::fetch_array($ret);
+            $this->name=$r['pcm_lib'];
+        }
+        else
+        {
+            $this->name="Poste inconnu";
+        }
+        return $this->name;
+    }
+    /*!\brief check if the poste exist in the tmp_pcmn
+     *\return the number of line (normally 1 or 0)
+     */
+    function do_exist()
+    {
+        $sql="select pcm_val from tmp_pcmn where pcm_val= $1";
+        $ret=$this->db->exec_sql($sql,array($this->id));
+        return Database::num_row($ret) ;
+    }
+    /*!\brief Get all the value for this object from the database
+     *        the data member are set
+     * \return false if this account doesn't exist otherwise true
+     */
+    function load()
+    {
+        $ret=$this->db->exec_sql("select pcm_lib,pcm_val_parent from
+                                 tmp_pcmn where pcm_val=$1",array($this->id));
+        $r=Database::fetch_all($ret);
+
+        if ( ! $r ) return false;
+        $this->label=$r[0]['pcm_lib'];
+        $this->parent=$r[0]['pcm_val_parent'];
+        return true;
+
+    }
+    /*!\brief Get all the value for this object from the database
+     *        the data member are set
+     * \return false if this account doesn't exist otherwise true
+     */
+    function get()
+    {
+        echo "OBSOLETE Acc_Account_Ledger->get(), a remplacer par 
Acc_Account_Ledger->load()";
+        return $this->load();
+    }
+
+    /*!
+     * \brief  give the balance of an account
+     *
+     * \return
+     *      balance of the account
+     *
+     */
+    function get_solde($p_cond=" true ")
+    {
+        $Res=$this->db->exec_sql("select sum(deb) as sum_deb, sum(cred) as 
sum_cred from
+                                 ( select j_poste,
+                                 case when j_debit='t' then j_montant else 0 
end as deb,
+                                 case when j_debit='f' then j_montant else 0 
end as cred
+                                 from jrnx join tmp_pcmn on j_poste=pcm_val
+                                 where
+                                 j_poste::text like ('$this->id'::text) and
+                                 $p_cond
+                                 ) as m  ");
+        $Max=Database::num_row($Res);
+        if ($Max==0) return 0;
+        $r=Database::fetch_array($Res,0);
+
+        return abs($r['sum_deb']-$r['sum_cred']);
+    }
+    /*!
+     * \brief   give the balance of an account
+     * \return
+     *      balance of the account
+     *
+     */
+    function get_solde_detail($p_cond="")
+    {
+
+        if ( $p_cond != "") $p_cond=" and ".$p_cond;
+        $sql="select sum(deb) as sum_deb, sum(cred) as sum_cred from
+             ( select j_poste,
+             case when j_debit='t' then j_montant else 0 end as deb,
+             case when j_debit='f' then j_montant else 0 end as cred
+             from jrnx
+             where
+             j_poste::text like ('$this->id'::text)
+             $p_cond
+             ) as m  ";
+
+        $Res=$this->db->exec_sql($sql);
+        $Max=Database::num_row($Res);
+
+        if ($Max==0)
+        {
+            return array('debit'=>0,
+                         'credit'=>0,
+                         'solde'=>0)     ;
+        }
+        $r=Database::fetch_array($Res,0);
+// if p_start is < p_end the query returns null to avoid any problem
+// we set it to 0
+        if ($r['sum_deb']=='')
+            $r['sum_deb']=0.0;
+        if ($r['sum_cred']=='')
+            $r['sum_cred']=0.0;
+
+        return array('debit'=>$r['sum_deb'],
+                     'credit'=>$r['sum_cred'],
+                     'solde'=>abs(bcsub($r['sum_deb'],$r['sum_cred'])));
+    }
+    /*!
+     * \brief isTva tell is a poste is used for VAT
+     * \param none
+     *
+     *
+     * \return 1 is Yes otherwise 0
+     */
+    function isTVA()
+    {
+        // Load TVA array
+        $a_TVA=$this->db->get_array('select tva_poste
+                                    from tva_rate');
+        foreach ( $a_TVA as $line_tva)
+        {
+            if ( $line_tva['tva_poste']  == '' )
+                continue;
+            list($tva_deb,$tva_cred)=explode(',',$line_tva['tva_poste']);
+            if ( $this->id == $tva_deb ||
+                    $this->id == $tva_cred )
+            {
+                return 1;
+            }
+        }
+        return 0;
+
+    }
+    /*!
+     * \brief HtmlTable, display a HTML of a poste for the asked period
+     * \param $p_array array for filter
+     * \param $let lettering of operation 0
+     * \return -1 if nothing is found otherwise 0
+     */
+    function HtmlTable($p_array=null,$let=0 , $from_div=0)
+    {
+        if ( $p_array==null)$p_array=$_REQUEST;
+        $this->get_name();
+        list($array,$tot_deb,$tot_cred)=$this->get_row_date( 
$p_array['from_periode'],
+                                                            
$p_array['to_periode'],$let
+                                                           );
+
+        if ( count($this->row ) == 0 )
+            return -1;
+
+        $rep="";
+
+        echo '<h2 class="title">'.$this->id." ".$this->name.'</h2>';
+        if ( $from_div == 0)
+                       echo "<TABLE class=\"resultfooter\" 
style=\"border-collapse:separate;margin:1%;width:98%;;border-spacing:0px 
5px\">";
+               else
+                       echo "<TABLE class=\"resultfooter\" 
style=\"border-collapse:separate;margin:1%;width:98%;;border-spacing:0px 
2px\">";
+        echo '<tbody>';
+        echo "<TR>".
+        "<TH style=\"text-align:left\"> Date</TH>".
+        "<TH style=\"text-align:left\"> n° de pièce </TH>".
+        "<TH style=\"text-align:left\"> Code interne </TH>".
+        "<TH style=\"text-align:left\"> Description </TH>".
+        "<TH style=\"text-align:right\"> D&eacute;bit  </TH>".
+        "<TH style=\"text-align:right\"> Cr&eacute;dit </TH>".
+        th('Prog.','style="text-align:right"').
+        th('Let.','style="text-align:right"');
+        "</TR>"
+        ;
+        $progress=0;$sum_deb=0;$sum_cred=0;
+       bcscale(2);
+       $old_exercice="";
+       $idx=0;
+        foreach ( $this->row as $op )
+        {
+            $vw_operation = sprintf('<A class="detail" 
style="text-decoration:underline;color:red" 
HREF="javascript:modifyOperation(\'%s\',\'%s\')" >%s</A>', $op['jr_id'], 
dossier::id(), $op['jr_internal']);
+            $let = '';
+                       $html_let = "";
+                       if ($op['letter'] != -1)
+                       {
+                               $let = strtoupper(base_convert($op['letter'], 
10, 36));
+                               $html_let = 
HtmlInput::show_reconcile($from_div, $let);
+                       }
+                       $tmp_diff=bcsub($op['deb_montant'],$op['cred_montant']);
+
+           /*
+            * reset prog. balance to zero if we change of exercice
+            */
+           if ( $old_exercice != $op['p_exercice'])
+             {
+               if ( $old_exercice != '')
+                 {
+                   $progress=bcsub($sum_deb,$sum_cred);
+                       $side="&nbsp;".$this->get_amount_side($progress);
+                   echo "<TR class=\"highlight\">".
+                     "<TD>$old_exercice</TD>".
+                     td('').
+                     "<TD></TD>".
+                     "<TD>Totaux</TD>".
+                     "<TD style=\"text-align:right\">".nbm($sum_deb)."</TD>".
+                     "<TD style=\"text-align:right\">".nbm($sum_cred)."</TD>".
+                     td(nbm(abs($progress)).$side,'style="text-align:right"').
+                     td('').
+                     "</TR>";
+                   $sum_cred=0;
+                   $sum_deb=0;
+                   $progress=0;
+
+                 }
+             }
+           $progress=bcadd($progress,$tmp_diff);
+               $side="&nbsp;".$this->get_amount_side($progress);
+           $sum_cred=bcadd($sum_cred,$op['cred_montant']);
+           $sum_deb=bcadd($sum_deb,$op['deb_montant']);
+               if ($idx%2 == 0) $class='class="odd"'; else $class=' 
class="even"';
+               $idx++;
+
+           echo "<TR $class name=\"tr_" . $let . "_" . $from_div . "\">" .
+                       "<TD>".smaller_date(format_date($op['j_date']))."</TD>".
+             td(h($op['jr_pj_number'])).
+             "<TD>".$vw_operation."</TD>".
+             "<TD>".h($op['description'])."</TD>".
+             "<TD style=\"text-align:right\">".nbm($op['deb_montant'])."</TD>".
+             "<TD 
style=\"text-align:right\">".nbm($op['cred_montant'])."</TD>".
+             td(nbm(abs($progress)).$side,'style="text-align:right"').
+
+             td($html_let, ' style="color:red;text-align:right"') .
+                       "</TR>";
+           $old_exercice=$op['p_exercice'];
+        }
+        echo '<tfoot>';
+        $solde_type=($sum_deb>$sum_cred)?"solde débiteur":"solde créditeur";
+        $diff=bcsub($sum_deb,$sum_cred);
+               $side="&nbsp;".$this->get_amount_side($diff);
+        echo "<TR class=\"highlight\">".
+        "<TD >Totaux</TD><td></td>".
+        "<TD ></TD>".
+        "<TD></TD>".
+         "<TD  style=\"text-align:right\">".nbm($sum_deb)."</TD>".
+         "<TD  style=\"text-align:right\">".nbm($sum_cred)."</TD>".
+         "<TD style=\"text-align:right\">".nbm(abs($diff)).$side."</TD>".
+
+        "</TR>";
+       echo   "<tr><TD>$solde_type</TD><td></td>".
+         "<TD style=\"text-align:right\">".nbm(abs($diff))."</TD>".
+        "</TR>";
+        echo '</tfoot>';
+        echo '</tbody>';
+
+        echo "</table>";
+
+        return;
+    }
+       /**
+        * return the letter C if amount is > 0, D if < 0 or =
+        * @param type $p_amount
+        * @return string
+        */
+       function get_amount_side($p_amount)
+               {
+                       if ($p_amount == 0)
+                               return "=";
+                       if ($p_amount < 0)
+                               return "C";
+                       if ($p_amount > 0)
+                               return "D";
+               }
+    /*!
+     * \brief Display HTML Table Header (button)
+     *
+     * \return none
+     */
+    static function HtmlTableHeader($actiontarget="poste")
+    {
+      switch($actiontarget)
+       {
+       case 'poste':
+         $action_csv='CSV:postedetail';
+         $action_pdf='PDF:postedetail';
+         break;
+       case 'gl_comptes':
+         $action_csv='CSV:glcompte';
+         $action_pdf='PDF:glcompte';
+         break;
+       default:
+         throw new Exception(" Fonction HtmlTableHeader argument actiontarget 
invalid");
+       }
+        $hid=new IHidden();
+
+        echo "<table  >";
+        echo '<TR>';
+        
$str_ople=(isset($_REQUEST['ople']))?HtmlInput::hidden('ople',$_REQUEST['ople']):'';
+       if ($actiontarget=='poste')
+         {
+           echo '<TD><form method="GET" ACTION="">'.
+             dossier::hidden().
+             HtmlInput::submit('bt_other',"Autre poste").
+             
$hid->input("type","poste").$hid->input('ac',$_REQUEST['ac'])."</form></TD>";
+         }
+
+
+        echo '<TD><form method="GET" ACTION="export.php">'.
+        dossier::hidden().
+        HtmlInput::submit('bt_pdf',"Export PDF").
+        HtmlInput::hidden('act',$action_pdf).
+        $hid->input("type","poste").$str_ople.
+        $hid->input('p_action','impress').
+        $hid->input("from_periode",$_REQUEST['from_periode']).
+        $hid->input("to_periode",$_REQUEST['to_periode'])
+         ;
+
+       if ( isset($_REQUEST['letter'] )) echo HtmlInput::hidden('letter','2');
+       if ( isset($_REQUEST['solded'] )) echo HtmlInput::hidden('solded','1');
+
+       if (isset($_REQUEST['from_poste']))
+         echo HtmlInput::hidden('from_poste',$_REQUEST['from_poste']);
+
+       if (isset($_REQUEST['to_poste']))
+         echo HtmlInput::hidden('to_poste',$_REQUEST['to_poste']);
+
+        if (isset($_REQUEST['poste_id']))
+         echo HtmlInput::hidden("poste_id",$_REQUEST['poste_id']);
+
+        if (isset($_REQUEST['poste_fille']))
+            echo $hid->input('poste_fille','on');
+        if (isset($_REQUEST['oper_detail']))
+            echo $hid->input('oper_detail','on');
+
+        echo "</form></TD>";
+
+        echo '<TD><form method="GET" ACTION="export.php">'.
+        dossier::hidden().
+        HtmlInput::submit('bt_csv',"Export CSV").
+       HtmlInput::hidden('act',$action_csv).
+        $hid->input("type","poste").$str_ople.
+        $hid->input('p_action','impress').
+        $hid->input("from_periode",$_REQUEST['from_periode']).
+         $hid->input("to_periode",$_REQUEST['to_periode']);
+
+       if (isset($_REQUEST['from_poste']))
+         echo HtmlInput::hidden('from_poste',$_REQUEST['from_poste']);
+
+       if (isset($_REQUEST['to_poste']))
+         echo HtmlInput::hidden('to_poste',$_REQUEST['to_poste']);
+
+        if (isset($_REQUEST['poste_id']))
+         echo HtmlInput::hidden("poste_id",$_REQUEST['poste_id']);
+
+       if ( isset($_REQUEST['letter'] )) echo HtmlInput::hidden('letter','2');
+       if ( isset($_REQUEST['solded'] )) echo HtmlInput::hidden('solded','1');
+
+        if (isset($_REQUEST['poste_fille']))
+            echo $hid->input('poste_fille','on');
+        if (isset($_REQUEST['oper_detail']))
+            echo $hid->input('oper_detail','on');
+        if (isset($_REQUEST['poste_id'])) echo 
$hid->input("poste_id",$_REQUEST['poste_id']);
+
+        echo "</form></TD>";
+       echo "</form></TD>";
+       echo '<td style="vertical-align:top">';
+       echo HtmlInput::print_window();
+       echo '</td>';
+       echo '</tr>';
+        echo "</table>";
+
+
+    }
+    /*!
+     * \brief verify that the poste belong to a ledger
+     *
+     * \return 0 ok,  -1 no
+     */
+    function belong_ledger($p_jrn)
+    {
+        $filter=$this->db->get_value("select jrn_def_class_cred from jrn_def 
where jrn_def_id=$p_jrn");
+        if ( trim ($filter) == '')
+            return 0;
+
+        $valid_cred=explode(" ",$filter);
+        $sql="select count(*) as poste from tmp_pcmn where ";
+        // Creation query
+        $or="";
+        $SqlFilter="";
+        foreach ( $valid_cred as $item_cred)
+        {
+            if ( strlen (trim($item_cred)))
+            {
+                if ( strstr($item_cred,"*") == true )
+                {
+                    $item_cred=strtr($item_cred,"*","%");
+                    $SqlItem="$or pcm_val::text like 
'".sql_string($item_cred)."'";
+                    $or="  or ";
+                }
+                else
+                {
+                    $SqlItem="$or pcm_val::text = '".sql_string($item_cred)."' 
";
+                    $or="  or ";
+                }
+                $SqlFilter=$SqlFilter.$SqlItem;
+            }
+        }//foreach
+        $sql.=$SqlFilter." and pcm_val::text='".sql_string($this->id)."'";
+        $max=$this->db->get_value($sql);
+        if ($max > 0 )
+            return 0;
+        else
+            return -1;
+    }
+    /*!\brief With the id of the ledger, get the col jrn_def_class_deb
+     *\param $p_jrn jrn_id
+     *\return array of value, or an empty array if nothing is found
+     *\note
+     *\see
+     */
+    function get_account_ledger($p_jrn)
+    {
+        $l=new Acc_Ledger($this->db,$p_jrn);
+        $row=$l->get_propertie();
+        if ( strlen(trim($row['jrn_def_class_deb'])) == 0 ) return array();
+        $valid_account=explode(" ",$row['jrn_def_class_deb']);
+        return $valid_account;
+    }
+    /*!\brief build a sql statement thanks a array found with 
get_account_ledger
+     *
+     *\param $p_jrn jrn_id
+     *\return an emty string if nothing is found or a valid SQL statement like
+    \code
+    pcm_val like ... or pcm_val like ...
+    \endcode
+     *\note
+     *\see get_account_ledger
+     */
+    function build_sql_account($p_jrn)
+    {
+        $array=$this->get_account_ledger($p_jrn);
+        if ( empty($array) ) return "";
+        $sql="";
+        foreach ( $array as $item_cred)
+        {
+            if ( strlen (trim($item_cred))>0 )
+            {
+                if ( strstr($item_cred,"*") == true )
+                {
+                    $item_cred=strtr($item_cred,"*","%");
+                    $sql_tmp=" pcm_val::text like '$item_cred' or";
+                }
+                else
+                {
+                    $sql_tmp=" pcm_val::text = '$item_cred' or";
+                }
+                $sql.=$sql_tmp;
+            }
+        }//foreach
+        /* remove the last or */
+        $sql=substr($sql,0,strlen($sql)-2);
+        return $sql;
+    }
+       /**
+        * Find the id of the cards which are using the current account
+         * 
+        * @return an array of f_id
+        */
+       function find_card()
+       {
+               $sql="select f_id from fiche_detail where ad_id=$1 and 
ad_value=$2";
+               
$account=$this->db->get_array($sql,array(ATTR_DEF_ACCOUNT,$this->id));
+               return $account;
+       }
+    static function test_me()
+    {
+        $cn=new Database(dossier::id());
+        $a=new Acc_Account_Ledger($cn,550);
+        echo ' Journal 4 '.$a->belong_ledger(4);
+        return $a->belong_ledger(4);;
+
+    }
+}
diff --git a/include/class/class_acc_balance.php 
b/include/class/class_acc_balance.php
new file mode 100644
index 0000000..119c9cf
--- /dev/null
+++ b/include/class/class_acc_balance.php
@@ -0,0 +1,284 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+// Copyright Author Dany De Bontridder address@hidden
+/*! \file
+ * \brief Class for manipulating data to print the balance of account
+ */
+/*!
+ * \brief Class for manipulating data to print the balance of account
+ */
+require_once NOALYSS_INCLUDE.'/class/class_acc_account.php';
+
+class Acc_Balance
+{
+    var $db;       /*! < database connection */
+    var $row;     /*! < row for ledger*/
+    var $jrn;                                          /*!< idx of a table of 
ledger create by user->get_ledger */
+    var $from_poste;                           /*!< from_poste  filter on the 
post */
+    var $to_poste;                             /*!< to_poste filter on the 
post*/
+    var $unsold;                               /**= 0) */
+    function Acc_Balance($p_cn)
+    {
+        $this->db=$p_cn;
+        $this->jrn=null;
+        $from_poste="";
+        $to_poste="";
+       $unsold=false;
+    }
+
+
+    /*!
+     * \brief retrieve all the row from the ledger in the range of a periode
+     * \param $p_from_periode start periode (p_id)
+     * \param $p_to_periode end periode (p_id)
+     * \param $p_previous_exc previous exercice 1= yes default =0
+     *
+     * \return a double array
+     *     array of
+     *         - $a['poste']
+     *         - $a['label']
+     *         - $a['sum_deb']
+     *         - $a['sum_cred']
+     *         - $a['solde_deb']
+     *         - $a['solde_cred']
+     */
+    function get_row($p_from_periode,$p_to_periode,$p_previous_exc=0)
+    {
+        global $g_user;
+        // filter on requested periode
+        
$per_sql=sql_filter_per($this->db,$p_from_periode,$p_to_periode,'p_id','j_tech_per');
+
+
+        $and="";
+        $jrn="";
+        $from_poste="";
+        $to_poste="";
+        /* if several ledgers are asked then we filter here  */
+        if ($this->jrn!== null)
+        {
+            /**
+             address@hidden
+             address@hidden the get_ledger here is not valid and useless we 
just need a list of the 
+             * asked ledgers
+             */
+
+            $jrn="  j_jrn_def in (";
+            $comma='';
+            for ($e=0;$e<count($this->jrn);$e++)
+            {
+                $jrn.=$comma.$this->jrn[$e];
+                $comma=',';
+            }
+            $jrn.=')';
+            $and=" and ";
+        }
+
+        if ( strlen(trim($this->from_poste)) != 0 && $this->from_poste!=-1  )
+        {
+            $from_poste=" $and j_poste::text >= '".$this->from_poste."'";
+            $and=" and ";
+        }
+        if ( strlen(trim($this->to_poste)) != 0   && $this->to_poste!=-1 )
+        {
+            $to_poste=" $and j_poste::text <= '".$this->to_poste."'";
+            $and=" and ";
+        }
+        $filter_sql=$g_user->get_ledger_sql('ALL',3);
+        
+        switch ($p_previous_exc)
+        {
+            case 0:
+                // build query
+                $sql="select j_poste as poste,sum(deb) as sum_deb, sum(cred) 
as sum_cred from
+                     ( select j_poste,
+                     case when j_debit='t' then j_montant else 0 end as deb,
+                     case when j_debit='f' then j_montant else 0 end as cred
+                     from jrnx join tmp_pcmn on (j_poste=pcm_val)
+                     left join parm_periode on (j_tech_per = p_id)
+                     join jrn_def on (j_jrn_def=jrn_def_id)
+                     where
+                     $jrn $from_poste $to_poste
+                     $and $filter_sql
+                     and
+                     $per_sql ) as m group by 1 order by 1";
+                break;
+            case 1:
+                /*
+                 * retrieve balance previous exercice
+                 */
+                $periode=new Periode($this->db);
+                $previous_exc=$periode->get_exercice($p_from_periode)-1;
+                try {
+                    
list($previous_start,$previous_end)=$periode->get_limit($previous_exc);
+               
+                        
$per_sql_previous=sql_filter_per($this->db,$previous_start->p_id,$previous_end->p_id,'p_id','j_tech_per');
+                        $sql="
+                            with m as 
+                                ( select j_poste,sum(deb) as sdeb,sum(cred) as 
scred
+                                from 
+                                (select j_poste, 
+                                    case when j_debit='t' then j_montant else 
0 end as deb, 
+                                    case when j_debit='f' then j_montant else 
0 end as cred 
+                                    from jrnx 
+                                    join tmp_pcmn on (j_poste=pcm_val) 
+                                    left join parm_periode on (j_tech_per = 
p_id) 
+                                    join jrn_def on (j_jrn_def=jrn_def_id) 
+                                    where
+                                                             $jrn $from_poste 
$to_poste
+                                    $and $filter_sql and $per_sql
+                                    ) as sub_m group by j_poste order by 
j_poste ) , 
+                            p as ( select j_poste,sum(deb) as sdeb,sum(cred) 
as scred 
+                                from 
+                                    (select j_poste, 
+                                        case when j_debit='t' then j_montant 
else 0 end as deb, 
+                                        case when j_debit='f' then j_montant 
else 0 end as cred 
+                                        from jrnx join tmp_pcmn on 
(j_poste=pcm_val) 
+                                        left join parm_periode on (j_tech_per 
= p_id) 
+                                        join jrn_def on (j_jrn_def=jrn_def_id) 
+                                        where 
+                                       $jrn $from_poste $to_poste
+                                    $and $filter_sql and $per_sql_previous)  
as sub_p group by j_poste order by j_poste)
+                            select coalesce(m.j_poste,p.j_poste) as poste
+                                                                
,coalesce(m.sdeb,0) as sum_deb
+                                                                , 
coalesce(m.scred,0) as sum_cred 
+                                                                
,coalesce(p.sdeb,0) as sum_deb_previous
+                                                                , 
coalesce(p.scred,0) as sum_cred_previous from m full join p on 
(p.j_poste=m.j_poste)
+                                             order by poste";
+                       
+                 } catch (Exception $exc) {
+                    $p_previous_exc=0;
+                    /*
+                     * no previous exercice
+                     */
+                     $sql="select upper(j_poste::text) as poste,sum(deb) as 
sum_deb, sum(cred) as sum_cred from
+                     ( select j_poste,
+                     case when j_debit='t' then j_montant else 0 end as deb,
+                     case when j_debit='f' then j_montant else 0 end as cred
+                     from jrnx join tmp_pcmn on (j_poste=pcm_val)
+                     left join parm_periode on (j_tech_per = p_id)
+                     join jrn_def on (j_jrn_def=jrn_def_id)
+                     where
+                     $jrn $from_poste $to_poste
+                     $and $filter_sql
+                     and
+                     $per_sql ) as m group by poste order by poste";
+                }
+                break;
+                           
+        }
+        $cn=clone $this->db;
+        $Res=$this->db->exec_sql($sql);
+        $tot_cred=  0.0;
+        $tot_deb=  0.0;
+        $tot_deb_saldo=0.0;
+        $tot_cred_saldo=0.0;
+        $tot_cred_previous=  0.0;
+        $tot_deb_previous=  0.0;
+        $tot_deb_saldo_previous=0.0;
+        $tot_cred_saldo_previous=0.0;
+        $M=$this->db->size();
+
+        // Load the array
+        for ($i=0; $i <$M;$i++)
+        {
+            $r=$this->db->fetch($i);
+            $poste=new Acc_Account($cn,$r['poste']);
+
+            $a['poste']=$r['poste'];
+            $a['label']=mb_substr($poste->get_lib(),0,40);
+            $a['sum_deb']=round($r['sum_deb'],2);
+            $a['sum_cred']=round($r['sum_cred'],2);
+            $a['solde_deb']=round(( $a['sum_deb']  >=  $a['sum_cred'] )? 
$a['sum_deb']- $a['sum_cred']:0,2);
+            $a['solde_cred']=round(( $a['sum_deb'] <=  $a['sum_cred'] 
)?$a['sum_cred']-$a['sum_deb']:0,2);
+            if ($p_previous_exc==1)
+            {
+                $a['sum_deb_previous']=round($r['sum_deb_previous'],2);
+                $a['sum_cred_previous']=round($r['sum_cred_previous'],2);
+                $a['solde_deb_previous']=round(( $a['sum_deb_previous']  >=  
$a['sum_cred_previous'] )? $a['sum_deb_previous']- $a['sum_cred_previous']:0,2);
+                $a['solde_cred_previous']=round(( $a['sum_deb_previous'] <=  
$a['sum_cred_previous'] )?$a['sum_cred_previous']-$a['sum_deb_previous']:0,2);
+                $tot_cred_previous+=  $a['sum_cred_previous'];
+                $tot_deb_previous+= $a['sum_deb_previous'];
+                $tot_deb_saldo_previous+= $a['solde_deb_previous'];
+                $tot_cred_saldo_previous+= $a['solde_cred_previous'];
+            }
+           if ($p_previous_exc==0 && $this->unsold==true && 
$a['solde_cred']==0 && $a['solde_deb']==0) continue;
+           if ($p_previous_exc==1 && $this->unsold==true && 
$a['solde_cred']==0 && $a['solde_deb']==0 && $a['solde_cred_previous']==0 && 
$a['solde_deb_previous']==0) continue;
+            $array[$i]=$a;
+            $tot_cred+=  $a['sum_cred'];
+            $tot_deb+= $a['sum_deb'];
+            $tot_deb_saldo+= $a['solde_deb'];
+            $tot_cred_saldo+= $a['solde_cred'];
+
+
+        }//for i
+        // Add the saldo
+        $i+=1;
+        $a['poste']="";
+        $a['label']="Totaux ";
+        $a['sum_deb']=$tot_deb;
+        $a['sum_cred']=$tot_cred;
+        $a['solde_deb']=$tot_deb_saldo;
+        $a['solde_cred']=$tot_cred_saldo;
+        if ($p_previous_exc==1) {
+            $a['sum_deb_previous']=$tot_deb_previous;
+            $a['sum_cred_previous']=$tot_cred_previous;
+            $a['solde_deb_previous']=$tot_deb_saldo_previous;
+            $a['solde_cred_previous']=$tot_cred_saldo_previous;
+        }
+        $array[$i]=$a;
+        $this->row=$array;
+        return $array;
+
+    }
+    /**
+     * set the $this->jrn to the cat
+     * @todo Cette function semble ne pas fonctionner correctement
+     */
+    function filter_cat($p_array)
+    {
+        if ( empty($p_array) )
+        {
+            $this->jrn=null;
+            return;
+        }
+        /* get the list of jrn of the cat. */
+
+        $array=Acc_Ledger::array_cat();
+        $jrn=array();
+        for ($e=0;$e<count($array);$e++)
+        {
+            if ( isset($p_array[$e]))
+            {
+                $t_a=$this->db->get_array('select jrn_def_id from jrn_def 
where jrn_def_type=$1',array($array[$e]['cat']));
+                for ( $f=0;$f < count($t_a);$f++) 
$this->jrn[]=$t_a[$f]['jrn_def_id'];
+            }
+        }
+
+    }
+    static function test_me ()
+    {
+        require 'class/class_user.php';
+        global $g_user;
+        $cn=new Database(dossier::id());
+        $g_user=new User($cn);
+        $a=new Acc_Balance($cn);
+        $a->get_row(163, 175, 1);
+        var_dump($a);
+    }
+}
diff --git a/include/class/class_acc_bilan.php 
b/include/class/class_acc_bilan.php
new file mode 100644
index 0000000..049071e
--- /dev/null
+++ b/include/class/class_acc_bilan.php
@@ -0,0 +1,729 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief this class handle the different bilan, from the table bilan
+ *
+ */
+require_once NOALYSS_INCLUDE.'/lib/class_iselect.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+require_once NOALYSS_INCLUDE.'/lib/class_impress.php';
+require_once NOALYSS_INCLUDE.'/header_print.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_account_ledger.php';
+
+/*!
+ * \brief this class handle the different bilan, from the table bilan, parse 
the form and replace
+ * in the template
+ */
+class Acc_Bilan
+{
+    var $db;                                           /*!< database 
connection */
+    var $b_id;                                 /*!< id of the bilan 
(bilan.b_id) */
+    var $from;                                 /*!< from periode */
+    var $to;                                   /*!< end periode */
+
+    function Acc_Bilan($p_cn)
+    {
+        $this->db=$p_cn;
+    }
+    /*!
+     * \brief return a string with the form for selecting the periode and
+     * the type of bilan
+     * \param $p_filter_year filter on a year
+     *
+     * \return a string
+     */
+    function display_form($p_filter_year="")
+    {
+        $r="";
+        $r.=dossier::hidden();
+        $r.= '<TABLE>';
+
+        $r.='<TR>';
+// filter on the current year
+        $w=new ISelect();
+        $w->table=1;
+
+        $periode_start=$this->db->make_array("select 
p_id,to_char(p_start,'DD-MM-YYYY') from parm_periode $p_filter_year order by 
p_start,p_end");
+
+        $periode_end=$this->db->make_array("select 
p_id,to_char(p_end,'DD-MM-YYYY') from parm_periode $p_filter_year order by 
p_end,p_start");
+
+        $w->label=_("Depuis");
+        $w->value=$this->from;
+        $w->selected=$this->from;
+        $r.= td($w->input('from_periode',$periode_start));
+        $w->label=_(" jusque ");
+        $w->value=$this->to;
+        $w->selected=$this->to;
+        $r.= td($w->input('to_periode',$periode_end));
+        $r.= "</TR>";
+        $r.="<tr>";
+        $mod=new ISelect();
+        $mod->table=1;
+        $mod->value=$this->db->make_array("select b_id, b_name from bilan 
order by b_name");
+        $mod->label=_("Choix du bilan");
+        $r.=td($mod->input('b_id'));
+        $r.="</tr>";
+        $r.= '</TABLE>';
+        return $r;
+    }
+    /**
+     * @brief check and warn if an accound has the wrong saldo
+     * @param $p_message legend of the fieldset
+     * @param $p_type type of the Acccount ACT actif, ACTINV...
+     * @param $p_type the saldo must debit or credit
+     */
+    private function warning($p_message,$p_type,$p_deb)
+    {
+        $sql="select pcm_val,pcm_lib from tmp_pcmn where pcm_type='$p_type'";
+        $res=$this->db->exec_sql($sql);
+        if ( Database::num_row($res) ==0 )
+            return;
+        $count=0;
+        $nRow=Database::num_row($res);
+
+        $ret="";
+        $obj=new Acc_Account_Ledger($this->db,0);
+        for ($i=0;$i<$nRow;$i++)
+        {
+
+            $line=Database::fetch_array($res,$i);
+            /* set the periode filter */
+            
$sql=sql_filter_per($this->db,$this->from,$this->to,'p_id','j_tech_per');
+            $obj->id=$line['pcm_val'];
+
+            $solde=$obj->get_solde_detail($sql);
+            $solde_signed=bcsub($solde['debit'],$solde['credit']);
+
+            if (
+                ($solde_signed < 0 && $p_deb == 'D' ) ||
+                ($solde_signed > 0 && $p_deb == 'C' )
+            )
+            {
+                $ret.= '<li> 
'.HtmlInput::history_account($line['pcm_val'],'Anomalie pour le compte 
'.$line['pcm_val'].' '.h($line['pcm_lib']).
+                       "  D: ".$solde['debit'].
+                       "  C: ".$solde['credit']." diff ".$solde['solde']);
+                $count++;
+            }
+
+        }
+
+        echo '<fieldset>';
+        echo '<legend>'.$p_message.'</legend>';
+        if ( $count <> 0 )
+        {
+            echo '<ol>'.$ret.'</ol>';
+            echo '<span class="error">'._("Nbres anomalies").' : 
'.$count.'</span>';
+        }
+        else
+            echo _("Pas d'anomalie détectée");
+        echo '</fieldset>';
+
+
+    }
+    /*!\brief verify that the saldo is good for the type of account */
+    function verify()
+    {
+               bcscale(2);
+        echo '<h3>'._("Comptes normaux").'</h3>';
+        $this->warning(_('Actif avec un solde crediteur'),'ACT','D');
+        $this->warning(_('Passif avec un solde debiteur'),'PAS','C');
+        $this->warning(_('Compte de resultat : Charge avec un solde 
crediteur'),'CHA','D');
+        $this->warning(_('Compte de resultat : produit avec un solde 
debiteur'),'PRO','C');
+        echo '<hr>';
+        echo '<h3>'._("Comptes inverses").' </h3>';
+        $this->warning(_('Compte inverse : actif avec un solde 
debiteur'),'ACTINV','C');
+        $this->warning(_('Compte inverse : passif avec un solde 
crediteur'),'PASINV','D');
+        $this->warning(_('Compte inverse : Charge avec un solde 
debiteur'),'CHAINV','C');
+        $this->warning(_('Compte inverse : produit avec un solde 
crediteur'),'PROINV','D');
+        echo '<h3'._("Solde").' </h3>';
+        /* set the periode filter */
+        
$sql_periode=sql_filter_per($this->db,$this->from,$this->to,'p_id','j_tech_per');
+        /* debit Actif */
+        $sql="select sum(j_montant) from jrnx join tmp_pcmn on 
(j_poste=pcm_val)".
+             " where j_debit='t' and (pcm_type='ACT' or pcm_type='ACTINV')";
+        $sql.="and $sql_periode";
+        $debit_actif=$this->db->get_value($sql);
+
+        /* Credit Actif */
+        $sql="select sum(j_montant) from jrnx join tmp_pcmn on 
(j_poste=pcm_val)".
+             " where j_debit='f' and (pcm_type='ACT' or pcm_type='ACTINV')";
+
+        $sql.="and $sql_periode";
+
+        $credit_actif=$this->db->get_value($sql);
+        $total_actif=abs(bcsub($debit_actif,$credit_actif));
+        echo '<table >';
+        echo tr(td(_('Total 
actif')).td($total_actif,'style="text-align:right"'));
+
+        /* debit passif */
+        $sql="select sum(j_montant) from jrnx join tmp_pcmn on 
(j_poste=pcm_val)".
+             " where j_debit='t' and (pcm_type='PAS' or pcm_type='PASINV') ";
+        $sql.="and $sql_periode";
+
+        $debit_passif=$this->db->get_value($sql);
+
+        /* Credit Actif */
+        $sql="select sum(j_montant) from jrnx join tmp_pcmn on 
(j_poste=pcm_val)".
+             " where j_debit='f' and (pcm_type='PAS' or pcm_type='PASINV') ";
+        $sql.="and $sql_periode";
+        $credit_passif=$this->db->get_value($sql);
+        $total_passif=abs(bcsub($debit_passif,$credit_passif));
+
+        /* diff actif / passif */
+        echo tr(td(_('Total 
passif')).td($total_passif,'style="text-align:right"'));
+        if ( $total_actif != $total_passif )
+        {
+            $diff=bcsub($total_actif,$total_passif);
+            echo tr(td(' Difference Actif - Passif 
').td($diff,'style="text-align:right"'),'style="font-weight:bolder"');
+        }
+
+        /* debit charge */
+        $sql="select sum(j_montant) from jrnx join tmp_pcmn on 
(j_poste=pcm_val)".
+             " where j_debit='t' and (pcm_type='CHA' or pcm_type='CHAINV')";
+        $sql.="and $sql_periode";
+        $debit_charge=$this->db->get_value($sql);
+
+        /* Credit charge */
+        $sql="select sum(j_montant) from jrnx join tmp_pcmn on 
(j_poste=pcm_val)".
+             " where j_debit='f' and (pcm_type='CHA' or pcm_type='CHAINV')";
+        $sql.="and $sql_periode";
+        $credit_charge=$this->db->get_value($sql);
+        $total_charge=abs(bcsub($debit_charge,$credit_charge));
+        echo tr(td(_('Total charge 
')).td($total_charge,'style="text-align:right"'));
+
+
+        /* debit prod */
+        $sql="select sum(j_montant) from jrnx join tmp_pcmn on 
(j_poste=pcm_val)".
+             " where j_debit='t' and (pcm_type='PRO' or pcm_type='PROINV')";
+        $sql.="and $sql_periode";
+        $debit_pro=$this->db->get_value($sql);
+
+        /* Credit prod */
+        $sql="select sum(j_montant) from jrnx join tmp_pcmn on 
(j_poste=pcm_val)".
+             " where j_debit='f' and (pcm_type='PRO' or pcm_type='PROINV')";
+        $sql.="and $sql_periode";
+        $credit_pro=$this->db->get_value($sql);
+        $total_pro=abs(bcsub($debit_pro,$credit_pro));
+        echo tr(td(_('Total 
produit')).td($total_pro,'style="text-align:right"'));
+
+        $diff=bcsub($total_pro,$total_charge);
+
+        echo tr( td(_("Difference Produit - 
Charge"),'style="padding-right:20px"').td($diff,'style="text-align:right"'),'style="font-weight:bolder"');
+        echo '</table>';
+    }
+    /*!
+     * \brief get data from the $_GET
+     *
+     */
+    function get_request_get()
+    {
+        $this->b_id=(isset($_GET['b_id']))?$_GET['b_id']:"";
+        $this->from=( isset ($_GET['from_periode']))?$_GET['from_periode']:-1;
+        $this->to=( isset ($_GET['to_periode']))?$_GET['to_periode']:-1;
+    }
+    /*!\brief load from the database the document data  */
+    function load()
+    {
+        try
+        {
+            if ( $this->b_id=="")
+                throw new Exception(_("le formulaire id n'est pas donnee"));
+
+            $sql="select b_name,b_file_template,b_file_form,lower(b_type) as 
b_type from bilan where".
+                 " b_id = ".$this->b_id;
+            $res=$this->db->exec_sql($sql);
+
+            if ( Database::num_row($res)==0)
+                throw new Exception (_('Aucun enregistrement trouve'));
+            $array=Database::fetch_array($res,0);
+            foreach ($array as $name=>$value)
+            $this->$name=$value;
+
+        }
+        catch(Exception $Ex)
+        {
+            echo $Ex->getMessage();
+            throw $Ex;
+        }
+    }
+    /*!\brief open the file of the form */
+    /*\return an handle to this file */
+    function file_open_form()
+    {
+        $form=fopen($this->b_file_form,'r');
+        if ( $form == false)
+        {
+            echo 'Cannot Open';
+           throw new Exception(_('Echec ouverture fichier 
'.$this->b_file_form));
+        }
+        return $form;
+    }
+    /*!\brief open the file with the template */
+    /*\return an handle to this file */
+    function file_open_template()
+    {
+        $templ=fopen($this->b_file_template,'r');
+        if ( $templ == false)
+        {
+            echo 'Cannot Open';
+              throw new Exception(_('Echec ouverture fichier 
'.$this->b_file_template));
+        }
+        return $templ;
+
+    }
+    /*!
+     * \brief Compute all the formula
+     * \param $p_handle the handle to the file
+     * \param
+     * \param
+     *
+     *
+     * \return
+     */
+    function compute_formula($p_handle)
+    {
+        while (! feof ($p_handle))
+        {
+            $buffer=trim(fgets($p_handle));
+            // $a=(Impress::check_formula($buffer)  == true)?"$buffer 
ok<br>":'<font color="red">'.'Pas ok '.$buffer."</font><br>";
+            // echo $a;
+            // blank line are skipped
+            if (strlen(trim($buffer))==0)
+                continue;
+            // skip comment
+            if ( strpos($buffer,'#') === true )
+                continue;
+            // buffer contains a formula A$=....
+            // We need to eval it
+            
$a=Impress::parse_formula($this->db,"$buffer",$buffer,$this->from,$this->to,false);
+            $b=str_replace("$","\$this->",$a);
+            if ( eval("$b;") === false )
+                echo_debug(__FILE__,__LINE__,"Code failed with $b");
+
+
+        }// end read form line per line
+    }
+    /*!\brief generate the ods document
+    * \param the handle to the template file
+    * \return the xml
+    address@hidden
+    * Sur une seule ligne il y a plusieurs données, donc il y a plusieurs 
boucles, pour les autres documents
+    * cela devrait être fait aussi, actuellement ces documents, n'acceptent 
qu'une formule par ligne.
+    address@hidden
+    * Pas de header dans les entêtes car n'est pas compris dans le document 
qu'on utilise
+    */
+    function generate_odt()
+    {
+        // create a temp directory in /tmp to unpack file and to parse it
+        $dirname=tempnam($_ENV['TMP'],'bilan_');
+
+
+        unlink($dirname);
+        mkdir ($dirname);
+        chdir($dirname);
+
+        
$file_base=dirname($_SERVER['SCRIPT_FILENAME']).DIRECTORY_SEPARATOR.$this->b_file_template;
+        $work_file=basename($file_base);
+        if ( copy ($file_base,$work_file) == false )
+        {
+            echo _("erreur Ouverture fichier");
+              throw new Exception(_('Echec ouverture fichier '.$file_base));
+        }
+        ob_start();
+       /* unzip the document */
+       $zip = new Zip_Extended;
+       if ($zip->open($work_file) === TRUE)
+         {
+           $zip->extractTo($dirname.DIRECTORY_SEPARATOR);
+           $zip->close();
+         } else
+         {
+           echo __FILE__.":".__LINE__."cannot unzip model ".$filename;
+         }
+
+       ob_end_clean();
+        unlink($work_file);
+        // remove the zip file
+        $p_file=fopen('content.xml','r');
+
+        if ( $p_file == false)
+        {
+             throw new Exception(_('Echec ouverture fichier '.$p_file));
+        }
+
+        $r="";
+        $regex="/&lt;&lt;\\$[A-Z]*[0-9]*&gt;&gt;/";
+        $lt="&lt;";
+        $gt="&gt;";
+       $header_txt=header_txt($this->db);
+
+        while ( !feof($p_file) )
+        {
+            $line_rtf=fgets($p_file);
+
+            /*
+            * replace the header tag, doesn't work if inside header
+            */
+            
$line_rtf=preg_replace('/&lt;&lt;header&gt;&gt;/',$header_txt,$line_rtf);
+
+
+            // the line contains the magic <<
+            $tmp="";
+
+
+           while (preg_match_all($regex,$line_rtf,$f2) > 0 )
+             {
+                // the f2 array contains all the magic << in the line
+                foreach ($f2 as $f2_array)
+                 {
+                   foreach ($f2_array as $f2_str)
+                     {
+                       $to_remove=$f2_str;
+                       $f2_value=str_replace("&lt;","",$f2_str);
+                       $f2_value=str_replace("&gt;","",$f2_value);
+                       $f2_value=str_replace("$","",$f2_value);
+
+
+
+                       // check for missing variables and labels (N vars)
+                       if( ! isset($this->$f2_value))
+                         {
+
+                           $a = "!!".$f2_value."!!";
+                           if( substr($f2_value, 0, 1) == "N" )
+                             {
+                               $ret = $this->db->get_array("SELECT pcm_lib AS 
acct_name FROM tmp_pcmn WHERE pcm_val::text LIKE ".
+                                                           " substr($1, 
2)||'%' ORDER BY pcm_val ASC LIMIT 1",array($f2_value));
+                               if($ret[0]['acct_name'])
+                                 {
+                                   $a = $ret[0]['acct_name'];
+                                   $a=str_replace('<','&lt;',$a);
+                                   $a=str_replace('>','&gt;',$a);
+                                 }
+                             }
+                         }
+                       else
+                         {
+                           $a=$this->$f2_value;
+                         }
+                       if ( $a=='-0' ) $a=0;
+
+                       /*  allow numeric cel in ODT for the formatting and 
formula */
+                       if ( is_numeric($a) )
+                         {
+                           
$searched='office:value-type="string"><text:p>'.$f2_str;
+                           $replaced='office:value-type="float" 
office:value="'.$a.'"><text:p>'.$f2_str;
+                           $line_rtf=str_replace($searched, $replaced, 
$line_rtf);
+                         }
+
+
+                       $line_rtf=str_replace($f2_str,$a,$line_rtf);
+
+                     }// foreach end
+                 } // foreach
+             } // preg_match_all
+            $r.=$line_rtf;
+
+        }// odt file is read
+
+        return $r;
+
+    }
+
+    /*!
+     * \brief generate the plain  file (rtf,txt, or html)
+     * \param the handle to the template file
+     */
+    function generate_plain($p_file)
+    {
+        $r="";
+        if ( $this->b_type=='html')
+        {
+            $lt='&lt;';
+            $gt='&gt;';
+           $pattern='/&lt;&lt;header&gt;&gt;/';
+        }
+        else
+        {
+            $lt='<';
+            $gt='>';
+           $pattern='/<<header>>/';
+        }
+
+       $header_txt=header_txt($this->db);
+
+        while ( !feof($p_file) )
+        {
+            $line_rtf=fgets($p_file);
+
+            $line_rtf=preg_replace($pattern,$header_txt,$line_rtf);
+
+
+            // the line contains the magic <<
+            if 
(preg_match_all("/".$lt.$lt."\\$[a-zA-Z]*[0-9]*".$gt.$gt."/",$line_rtf,$f2) > 0)
+            {
+                // DEBUG
+                //    echo $r.'<br>';
+                // the f2 array contains all the magic << in the line
+                foreach ($f2 as $f2_str)
+                {
+                    // DEBUG
+                    // echo "single_f2 = $f2_str <br>";
+                    // replace single_f2 by its value
+                    $f2_value=str_replace($lt,"",$f2_str);
+                    $f2_value=str_replace($gt,"",$f2_value);
+                    $f2_value=str_replace("$","",$f2_value);
+                   $f2_value=$f2_value[0];
+
+                    // check for missing variables and labels (N vars)
+                    if( ! isset($this->$f2_value))
+                    {
+                        $a = "!!".$f2_value."!!";
+                        if( substr($f2_value, 0, 1) == "N" )
+                        {
+                            $ret = $this->db->get_array("SELECT pcm_lib AS 
acct_name FROM tmp_pcmn WHERE ".
+                                                        " pcm_val::text LIKE 
substr($1, 2)||'%' ORDER BY pcm_val ASC LIMIT 1",
+                                                        array($f2_value));
+                            if($ret[0]['acct_name'])
+                            {
+                                /* for rtf we have the string to put it in 
latin1 */
+                                $a = utf8_decode($ret[0]['acct_name']);
+                            }
+                        }
+                    }
+                    else
+                    {
+                        // DEBUG
+                        //echo "f2_value=$f2_value";
+                        //               $a=${"$f2_value"};
+                        $a=$this->$f2_value;
+                    }
+                    // DEBUG      echo " a = $a";
+                    if ( $a=='-0' ) $a=0;
+                    $line_rtf=str_replace($f2_str,$a,$line_rtf);
+
+                }// foreach end
+            }
+            $r.=$line_rtf;
+
+        }// rtf file is read
+        // DEBUG
+        //  fwrite($out,$r);
+
+        return $r;
+
+
+
+
+    }
+    /*!\brief generate the document and send it to the browser
+     */
+    function generate()
+    {
+        // Load the data
+        $this->load();
+        // Open the files
+        $form=$this->file_open_form();
+
+        // Compute all the formula and add the value to this
+        $this->compute_formula($form);
+        fclose($form);
+        // open the form
+        $templ=$this->file_open_template();
+        switch ($this->b_type)
+        {
+        case 'rtf':
+            $result=$this->generate_plain($templ);
+            $this->send($result);
+            break;
+        case 'txt':
+            $result=$this->generate_plain($templ);
+            $this->send($result);
+        case 'html':
+            $result=$this->generate_plain($templ);
+            $this->send($result);
+
+            break;
+        case 'odt':
+        case 'ods':
+            $result=$this->generate_odt($templ);
+            $this->send($result);
+            break;
+
+        }
+        fclose($templ);
+    }
+    /*!\brief send the result of generate plain to the browser
+     * \param $p_result is the string returned by generate_...
+     */
+    function send($p_result)
+    {
+        switch ($this->b_type)
+        {
+        case 'rtf':
+            // A rtf file is generated
+            header('Content-type: application/rtf');
+            header('Content-Disposition: attachment; 
filename="'.$this->b_name.'.rtf"');
+            echo $p_result;
+            break;
+
+        case 'txt':
+            // A txt file is generated
+            header('Content-type: application/txt');
+            header('Content-Disposition: attachment; 
filename="'.$this->b_name.'.txt"');
+
+            echo $p_result;
+            break;
+        case 'html':
+            // A txt file is generated
+            header('Content-type: application/html');
+            header('Content-Disposition: attachment; 
filename="'.$this->b_name.'.html"');
+
+            echo $p_result;
+            break;
+        case 'odt':
+        case 'ods':
+            header("Pragma: public");
+            header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
+            header("Cache-Control: must-revalidate");
+            if ( $this->b_type == 'odt' )
+            {
+                header('Content-type: 
application/vnd.oasis.opendocument.text');
+                header('Content-Disposition: 
attachment;filename="'.$this->b_name.'.odt"',FALSE);
+            }
+            if ( $this->b_type == 'ods' )
+            {
+                header('Content-type: 
application/vnd.oasis.opendocument.spreadsheet');
+                header('Content-Disposition: 
attachment;filename="'.$this->b_name.'.ods"',FALSE);
+            }
+            
+            header("Accept-Ranges: bytes");
+            ob_start();
+            // save the file in a temp folder
+            // create a temp directory in /tmp to unpack file and to parse it
+            
$dirname=tempnam($_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.'tmp','bilan_');
+
+
+            unlink($dirname);
+            mkdir ($dirname);
+            chdir($dirname);
+            // create a temp directory in /tmp to unpack file and to parse it
+            
$file_base=dirname($_SERVER['SCRIPT_FILENAME']).DIRECTORY_SEPARATOR.$this->b_file_template;
+            $work_file=basename($file_base);
+            if ( copy ($file_base,$work_file) == false )
+            {
+                throw new Exception ( _("Ouverture fichier impossible"));
+            }
+           /*
+            * unzip the document
+            */
+            ob_start();
+           $zip = new Zip_Extended;
+           if ($zip->open($work_file) === TRUE)
+             {
+               $zip->extractTo($dirname.DIRECTORY_SEPARATOR);
+               $zip->close();
+             }
+           else
+             {
+               echo __FILE__.":".__LINE__."cannot unzip model ".$filename;
+             }
+
+            // Remove the file we do  not need anymore
+            unlink ($work_file);
+
+
+            // replace the file
+            $p_file=fopen($dirname.DIRECTORY_SEPARATOR.'content.xml','wb');
+            if ( $p_file == false )
+            {
+                  throw new Exception ( _("erreur Ouverture fichier").' 
content.xml');
+
+            }
+            $a=fwrite($p_file,$p_result);
+            if ( $a==false)
+            {
+                throw new Exception ( _("erreur écriture fichier").' 
content.xml');
+            }
+            // repack
+           $zip = new Zip_Extended;
+            $res = $zip->open($this->b_name.".".$this->b_type, 
ZipArchive::CREATE);
+            if($res !== TRUE)
+             {
+               throw new Exception (__FILE__.":".__LINE__."cannot recreate 
zip");
+             }
+           $zip->add_recurse_folder($dirname.DIRECTORY_SEPARATOR);
+           $zip->close();
+
+            ob_end_clean();
+            fclose($p_file);
+            
$fdoc=fopen($dirname.DIRECTORY_SEPARATOR.$this->b_name.'.'.$this->b_type,'r');
+            if ( $fdoc == false )
+            {
+                  throw new Exception   (_("erreur Ouverture fichier"));
+            }
+            $buffer=fread 
($fdoc,filesize($dirname.DIRECTORY_SEPARATOR.$this->b_name.'.'.$this->b_type));
+            echo $buffer;
+
+            break;
+            // and send
+        }
+
+    }
+    static function test_me()
+    {
+
+        if ( isset($_GET['result']))
+        {
+            ob_start();
+            $cn=new Database(dossier::id());
+            $a=new Acc_Bilan($cn);
+            $a->get_request_get();
+
+            $a->load();
+            $form=$a->file_open_form();
+            $a->compute_formula($form);
+            fclose($form);
+            // open the form
+            $templ=$a->file_open_template();
+            $r=$a->generate_odt($templ);
+            fclose($templ);
+            ob_end_clean();
+
+            $a->send($r);
+        }
+        else
+        {
+            $cn=new Database(dossier::id());
+            $a=new Acc_Bilan($cn);
+            $a->get_request_get();
+
+            echo '<form method="get">';
+            echo $a->display_form();
+           echo 
HtmlInput::hidden('test_select',$_GET['test_select']).dossier::hidden();
+           echo HtmlInput::submit('result','Sauve');
+            echo '</form>';
+        }
+    }
+}
+
diff --git a/include/class_acc_compute.php b/include/class/class_acc_compute.php
similarity index 100%
rename from include/class_acc_compute.php
rename to include/class/class_acc_compute.php
diff --git a/include/class/class_acc_ledger.php 
b/include/class/class_acc_ledger.php
new file mode 100644
index 0000000..45300e2
--- /dev/null
+++ b/include/class/class_acc_ledger.php
@@ -0,0 +1,3958 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+// Copyright Author Dany De Bontridder address@hidden
+require_once NOALYSS_INCLUDE.'/lib/class_iselect.php';
+require_once NOALYSS_INCLUDE.'/lib/class_icard.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ispan.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ihidden.php';
+require_once NOALYSS_INCLUDE.'/lib/class_idate.php';
+require_once NOALYSS_INCLUDE.'/lib/class_itext.php';
+require_once NOALYSS_INCLUDE.'/lib/class_icheckbox.php';
+require_once NOALYSS_INCLUDE.'/lib/class_iperiod.php';
+require_once NOALYSS_INCLUDE.'/class/class_fiche.php';
+require_once NOALYSS_INCLUDE.'/class/class_user.php';
+require_once  NOALYSS_INCLUDE.'/class/class_dossier.php';
+require_once  NOALYSS_INCLUDE.'/class/class_anc_operation.php';
+require_once  NOALYSS_INCLUDE.'/class/class_acc_operation.php';
+require_once  NOALYSS_INCLUDE.'/class/class_acc_account_ledger.php';
+require_once  NOALYSS_INCLUDE.'/class/class_pre_op_advanced.php';
+require_once  NOALYSS_INCLUDE.'/class/class_acc_reconciliation.php';
+require_once  NOALYSS_INCLUDE.'/class/class_periode.php';
+require_once  NOALYSS_INCLUDE.'/class/class_gestion_purchase.php';
+require_once  NOALYSS_INCLUDE.'/class/class_gestion_sold.php';
+require_once  NOALYSS_INCLUDE.'/class/class_acc_account.php';
+require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
+require_once NOALYSS_INCLUDE.'/lib/class_inum.php';
+require_once NOALYSS_INCLUDE.'/class/class_lettering.php';
+require_once NOALYSS_INCLUDE.'/lib/class_sort_table.php';
+require_once NOALYSS_INCLUDE.'/database/class_jrn_def_sql.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_payment.php';
+/** \file
+ * @brief Class for jrn,  class acc_ledger for manipulating the ledger
+ */
+
+/** @brief Class for jrn,  class acc_ledger for manipulating the ledger
+ *
+ */
+
+class Acc_Ledger extends jrn_def_sql
+{
+
+       var $id;   /**< jrn_def.jrn_def_id */
+       var $name;   /**< jrn_def.jrn_def_name */
+       var $db;   /**< database connextion */
+       var $row;   /**< row of the ledger */
+       var $type;   /**< type of the ledger ACH ODS FIN
+         VEN or GL */
+       var $nb;   /**< default number of rows by
+         default 10 */
+
+       /**
+        * @param $p_cn database connexion
+        * @param $p_id jrn.jrn_def_id
+        */
+       function __construct($p_cn, $p_id)
+       {
+               $this->id = $p_id;
+               $this->name = &$this->jrn_def_name;
+               $this->jrn_def_id = &$this->id;
+               $this->db = $p_cn;
+               $this->row = null;
+               $this->nb = MAX_ARTICLE;
+       }
+
+       function get_last_pj()
+       {
+               if ($this->db->exist_sequence("s_jrn_pj" . $this->id))
+               {
+                       $ret = $this->db->get_array("select 
last_value,is_called from s_jrn_pj" . $this->id);
+                       $last = $ret[0]['last_value'];
+                       /**
+                        * \note  With PSQL sequence , the last_value column is 
1 when before   AND after the first call, to make the difference between them
+                        * I have to check whether the sequence has been 
already called or not */
+                       if ($ret[0]['is_called'] == 'f')
+                               $last--;
+                       return $last;
+               }
+               else
+                       $this->db->create_sequence("s_jrn_pj" . $this->id);
+               return 0;
+       }
+
+       /**
+        * @brief Return the type of a ledger (ACH,VEN,ODS or FIN) or GL
+        *
+        */
+
+       function get_type()
+       {
+               if ($this->id == 0)
+               {
+                       $this->name = _(" Tous les journaux");
+                       $this->type = "GL";
+                       return "GL";
+               }
+
+               $Res = $this->db->exec_sql("select jrn_def_type from " .
+                               " jrn_def where jrn_def_id=" .
+                               $this->id);
+               $Max = Database::num_row($Res);
+               if ($Max == 0)
+                       return null;
+               $ret = Database::fetch_array($Res, 0);
+               $this->type = $ret['jrn_def_type'];
+               return $ret['jrn_def_type'];
+       }
+
+       /**
+        * let you delete a operation
+        * @note by cascade it will delete also in
+        * - jrnx
+        * - stock
+        * - quant_purchase
+        * - quant_fin
+        * - quant_sold
+        * - operation_analytique
+        * - letter
+        * - reconciliation
+        * @bug the attached document is not deleted
+         * @bug Normally it should be named delete_operation, cause the id is 
the ledger_id
+         * (jrn_def_id) and not the operation id
+        */
+       function delete()
+       {
+               if ($this->id == 0)
+                       return;
+               $grpt_id = $this->db->get_value('select jr_grpt_id from jrn 
where jr_id=$1', array($this->jr_id));
+               if ($this->db->count() == 0)
+                       return;
+               $this->db->exec_sql('delete from jrnx where j_grpt=$1', 
array($grpt_id));
+               $this->db->exec_sql('delete from jrn where jr_id=$1', 
array($this->jr_id));
+       }
+
+       /**
+        * Display warning contained in an array
+        * @return string with error message
+        */
+       function display_warning($pa_msg, $p_warning)
+       {
+               $str = '<p class="notice"> ' . $p_warning;
+               $str.="<ol class=\"notice\">";
+               for ($i = 0; $i < count($pa_msg); $i++)
+               {
+                       $str.="<li>" . $pa_msg[$i] . "</li>";
+               }
+               $str.='</ol>';
+               $str.='</p>';
+               return $str;
+       }
+
+       /**
+        * reverse the operation by creating the opposite one,
+        * the result is to avoid it
+        * it must be done in
+        * - jrn
+        * - jrnx
+        * - quant_fin
+        * - quant_sold
+        * - quant_purchase
+        * - stock
+        * - ANC
+        * @param $p_date is the date of the reversed op
+        * @exception if date is invalid or other prob
+        * @note automatically create a reconciliation between operation
+        * You must set the ledger_id $this->jrn_def_id
+         * This function should be in operation or call an acc_operation object
+         * 
+        */
+       function reverse($p_date)
+       {
+               global $g_user;
+               try
+               {
+                       $this->db->start();
+                       if (!isset($this->jr_id) || $this->jr_id == '')
+                               throw new Exception(_("this->jr_id is not set 
ou opération inconnue"));
+
+                       /* check if the date is valid */
+                       if (isDate($p_date) == null)
+                               throw new Exception(_('Date invalide') . 
$p_date);
+
+                       // if the operation is in a closed or centralized period
+                       // the operation is voided thanks the opposite operation
+                       $grp_new = $this->db->get_next_seq('s_grpt');
+                       $seq = $this->db->get_next_seq("s_jrn");
+                       $p_internal = $this->compute_internal_code($seq);
+                       $this->jr_grpt_id = $this->db->get_value('select 
jr_grpt_id from jrn where jr_id=$1', array($this->jr_id));
+                       if ($this->db->count() == 0)
+                               throw new Exception(_("Cette opération n'existe 
pas"));
+                       $this->jr_internal = $this->db->get_value('select 
jr_internal from jrn where jr_id=$1', array($this->jr_id));
+                       if ($this->db->count() == 0 || trim($this->jr_internal) 
== '')
+                               throw new Exception(_("Cette opération n'existe 
pas"));
+
+                       /* find the periode thanks the date */
+                       $per = new Periode($this->db);
+                       $per->jrn_def_id = $this->id;
+                       $per->find_periode($p_date);
+
+                       if ($per->is_open() == 0)
+                               throw new Exception(_('PERIODE FERMEE'));
+
+
+
+
+
+                       // Mark the operation invalid into the ledger
+                       // to avoid to nullify twice the same op.
+                       $sql = "update jrn set jr_comment='extourne : 
'||jr_comment where jr_id=$1";
+                       $Res = $this->db->exec_sql($sql, array($this->jr_id));
+
+                       // Check return code
+                       if ($Res == false)
+                               throw new Exception(__FILE__ . __LINE__ . "sql 
a echoue [ $sql ]");
+
+                       //////////////////////////////////////////////////
+                       // Reverse in jrnx* tables
+                       //////////////////////////////////////////////////
+                       $a_jid = $this->db->get_array("select j_id,j_debit from 
jrnx where j_grpt=$1", array($this->jr_grpt_id));
+                       for ($l = 0; $l < count($a_jid); $l++)
+                       {
+                               $row = $a_jid[$l]['j_id'];
+                               // Make also the change into jrnx
+                               $sql = "insert into jrnx (
+                  j_date,j_montant,j_poste,j_grpt,
+                  
j_jrn_def,j_debit,j_text,j_internal,j_tech_user,j_tech_per,j_qcode
+                  ) select to_date($1,'DD.MM.YYYY'),j_montant,j_poste,$2,
+                  j_jrn_def,not (j_debit),j_text,$3,$4,$5,
+                  j_qcode
+                  from
+                  jrnx
+                  where   j_id=$6 returning j_id";
+                               $Res = $this->db->exec_sql($sql, array($p_date, 
$grp_new, $p_internal, $g_user->id, $per->p_id, $row));
+                               // Check return code
+                               if ($Res == false)
+                                       throw (new Exception(__FILE__ . 
__LINE__ . "SQL ERROR [ $sql ]"));
+                               $aj_id = $this->db->fetch(0);
+                               $j_id = $aj_id['j_id'];
+
+                               /* automatic lettering */
+                               $let = new Lettering($this->db);
+                               $let->insert_couple($j_id, $row);
+
+                               // reverse in QUANT_SOLD
+                               $Res = $this->db->exec_sql("INSERT INTO 
quant_sold(
+                                     qs_internal, qs_fiche, qs_quantite, 
qs_price, qs_vat,
+                                     qs_vat_code, qs_client, qs_valid, j_id)
+                                     SELECT $1, qs_fiche, qs_quantite*(-1), 
qs_price*(-1), qs_vat*(-1),
+                                     qs_vat_code, qs_client, qs_valid, $2
+                                     FROM quant_sold where j_id=$3", 
array($p_internal, $j_id, $row));
+
+                               if ($Res == false)
+                                       throw new Exception(__FILE__ . __LINE__ 
. "sql a echoue [ $sql ]");
+                               $Res = $this->db->exec_sql("INSERT INTO 
quant_purchase(
+                                     qp_internal, j_id, qp_fiche, qp_quantite, 
qp_price, qp_vat,
+                                     qp_vat_code, qp_nd_amount, qp_nd_tva, 
qp_nd_tva_recup, qp_supplier,
+                                     qp_valid, qp_dep_priv)
+                                     SELECT  $1, $2, qp_fiche, 
qp_quantite*(-1), qp_price*(-1), qp_vat*(-1),
+                                     qp_vat_code, qp_nd_amount*(-1), 
qp_nd_tva*(-1), qp_nd_tva_recup*(-1), qp_supplier,
+                                     qp_valid, qp_dep_priv*(-1)
+                                     FROM quant_purchase where j_id=$3", 
array($p_internal, $j_id, $row));
+
+                               if ($Res == false)
+                                       throw new Exception(__FILE__ . __LINE__ 
. "SQL ERROR [ $sql ]");
+                       }
+                       $sql = "insert into jrn (
+              jr_id,
+              jr_def_id,
+              jr_montant,
+              jr_comment,
+              jr_date,
+              jr_grpt_id,
+              jr_internal
+              ,jr_tech_per, jr_valid
+              )
+              select $1,jr_def_id,jr_montant,jr_comment,
+              to_date($2,'DD.MM.YYYY'),$3,$4,
+              $5, true
+              from
+              jrn
+              where   jr_id=$6";
+                               $Res = $this->db->exec_sql($sql, array($seq, 
$p_date, $grp_new, $p_internal, $per->p_id, $this->jr_id));
+                               // Check return code
+                               if ($Res == false)
+                                       throw (new Exception(__FILE__ . 
__LINE__ . "SQL ERROR [ $sql ]"));
+                       // reverse in QUANT_FIN table
+                       $Res = $this->db->exec_sql("  INSERT INTO quant_fin(
+                                 qf_bank,  qf_other, qf_amount,jr_id)
+                                 SELECT  qf_bank,  qf_other, qf_amount*(-1),$1
+                                 FROM quant_fin where jr_id=$2", array($seq, 
$this->jr_id));
+                       if ($Res == false)
+                               throw (new Exception(__FILE__ . __LINE__ . "SQL 
ERROR[ $sql ]"));
+
+                       // Add a "concerned operation to bound these op.together
+                       //
+        $rec = new Acc_Reconciliation($this->db);
+                       $rec->set_jr_id($seq);
+                       $rec->insert($this->jr_id);
+
+                       // Check return code
+                       if ($Res == false)
+                       {
+                               throw (new Exception(__FILE__ . __LINE__ . "SQL 
ERROR [ $sql ]"));
+                       }
+
+
+
+                       // the table stock must updated
+                       // also in the stock table
+                       $sql = "delete from stock_goods where sg_id = any ( 
select sg_id
+             from stock_goods natural join jrnx  where j_grpt=" . 
$this->jr_grpt_id . ")";
+                       $Res = $this->db->exec_sql($sql);
+                       if ($Res == false)
+                               throw (new Exception(__FILE__ . __LINE__ . "SQL 
ERROR [ $sql ]"));
+                        $this->db->commit();
+               }
+               catch (Exception $e)
+               {
+                       $this->db->rollback();
+                       throw $e;
+               }
+       }
+
+       /**
+        * @brief Return the name of a ledger
+        *
+        */
+
+       function get_name()
+       {
+               if ($this->id == 0)
+               {
+                       $this->name = _("Grand Livre");
+                       return $this->name;
+               }
+
+               $Res = $this->db->exec_sql("select jrn_def_name from " .
+                               " jrn_def where jrn_def_id=$1", 
array($this->id));
+               $Max = Database::num_row($Res);
+               if ($Max == 0)
+                       return null;
+               $ret = Database::fetch_array($Res, 0);
+               $this->name = $ret['jrn_def_name'];
+               return $ret['jrn_def_name'];
+       }
+
+       /** \function  get_row
+        * @brief  Get The data
+        *
+        *
+        * @paramp_from from periode
+        * @paramp_to to periode
+        * @paramp_limit starting line
+        * @paramp_offset number of lines
+        * \return Array with the asked data
+        *
+        */
+
+       function get_row($p_from, $p_to, $p_limit = -1, $p_offset = -1)
+       {
+               global $g_user;
+               $periode = sql_filter_per($this->db, $p_from, $p_to, 'p_id', 
'jr_tech_per');
+
+               $cond_limite = ($p_limit != -1) ? " limit " . $p_limit . " 
offset " . $p_offset : "";
+               // retrieve the type
+               $this->get_type();
+               // Grand livre == 0
+               if ($this->id != 0)
+               {
+                       $Res = $this->db->exec_sql("select jr_id,j_id,j_id as 
int_j_id,to_char(j_date,'DD.MM.YYYY') as j_date,
+                                     jr_internal,
+                                     case j_debit when 't' then 
j_montant::text else '   ' end as deb_montant,
+                                     case j_debit when 'f' then 
j_montant::text else '   ' end as cred_montant,
+                                     j_debit as debit,j_poste as 
poste,jr_montant , " .
+                                       "case when j_text='' or j_text is null 
then pcm_lib else j_text end as description,j_grpt as grp,
+                                     jr_comment||' ('||jr_internal||')'  as 
jr_comment,
+                                    jr_pj_number,
+                                     j_qcode,
+                                     jr_rapt as oc, j_tech_per as periode
+                                     from jrnx left join jrn on " .
+                                       "jr_grpt_id=j_grpt " .
+                                       " left join tmp_pcmn on pcm_val=j_poste 
" .
+                                       " where j_jrn_def=" . $this->id .
+                                       " and " . $periode . " order by 
j_date::date asc,substring(jr_pj_number,'[0-9]+$')::numeric asc,j_grpt,j_debit 
desc " .
+                                       $cond_limite);
+               }
+               else
+               {
+                       $Res = $this->db->exec_sql("select jr_id,j_id,j_id as 
int_j_id,to_char(j_date,'DD.MM.YYYY') as j_date,
+                                     jr_internal,
+                                     case j_debit when 't' then 
j_montant::text else '   ' end as deb_montant,
+                                     case j_debit when 'f' then 
j_montant::text else '   ' end as cred_montant,
+                                     j_debit as debit,j_poste as poste," .
+                                       "case when j_text='' or j_text is null 
then pcm_lib else j_text end as description,j_grpt as grp,
+                                     jr_comment||' ('||jr_internal||')' as 
jr_comment,
+                                    jr_pj_number,
+                                     jr_montant,
+                                     j_qcode,
+                                     jr_rapt as oc, j_tech_per as periode from 
jrnx left join jrn on " .
+                                       "jr_grpt_id=j_grpt left join tmp_pcmn 
on pcm_val=j_poste
+                                                                               
 join jrn_def on (jr_def_id=jrn_def_id)
+                                                                               
 where " .
+                                       $g_user->get_ledger_sql() . " and " .
+                                       "  " . $periode . " order by 
j_date::date,substring(jr_pj_number,'[0-9]+$') asc,j_grpt,j_debit desc   " .
+                                       $cond_limite);
+               }
+
+
+               $array = array();
+               $Max = Database::num_row($Res);
+               if ($Max == 0)
+                       return null;
+               $case = "";
+               $tot_deb = 0;
+               $tot_cred = 0;
+               $row = Database::fetch_all($Res);
+               for ($i = 0; $i < $Max; $i++)
+               {
+                       $fiche = new Fiche($this->db);
+                       $line = $row[$i];
+                       $mont_deb = ($line['deb_montant'] != 0) ? sprintf("% 
8.2f", $line['deb_montant']) : "";
+                       $mont_cred = ($line['cred_montant'] != 0) ? sprintf("% 
8.2f", $line['cred_montant']) : "";
+                       $jr_montant = ($line['jr_montant'] != 0) ? sprintf("% 
8.2f", $line['jr_montant']) : "";
+                       $tot_deb+=$line['deb_montant'];
+                       $tot_cred+=$line['cred_montant'];
+                       $tot_op = $line['jr_montant'];
+
+                       /* Check first if there is a quickcode */
+                       if (strlen(trim($line['description'])) == 0 && 
strlen(trim($line['j_qcode'])) != 0)
+                       {
+                               if ($fiche->get_by_qcode($line['j_qcode'], 
false) == 0)
+                               {
+                                       $line['description'] = 
$fiche->strAttribut(ATTR_DEF_NAME);
+                               }
+                       }
+                       if ($case != $line['grp'])
+                       {
+                               $case = $line['grp'];
+                               // for financial, we show if the amount is or 
not in negative
+                               if ($this->type == 'FIN')
+                               {
+                                       $amount = $this->db->get_value('select 
qf_amount from quant_fin where jr_id=$1', array($line['jr_id']));
+                                       /*  if nothing is found */
+                                       if ($this->db->count() == 0)
+                                               $tot_op = $jr_montant;
+                                       else if ($amount < 0)
+                                       {
+                                               $tot_op = $amount;
+                                       }
+                               }
+                               $array[] = array(
+                                       'jr_id' => $line['jr_id'],
+                                       'int_j_id' => $line['int_j_id'],
+                                       'j_id' => $line['j_id'],
+                                       'j_date' => $line['j_date'],
+                                       'internal' => $line['jr_internal'],
+                                       'deb_montant' => '',
+                                       'cred_montant' => ' ',
+                                       'description' => '<b><i>' . 
h($line['jr_comment']) . ' [' . $tot_op . '] </i></b>',
+                                       'poste' => $line['oc'],
+                                       'qcode' => $line['j_qcode'],
+                                       'periode' => $line['periode'],
+                                       'jr_pj_number' => $line 
['jr_pj_number']);
+
+                               $array[] = array(
+                                       'jr_id' => '',
+                                       'int_j_id' => $line['int_j_id'],
+                                       'j_id' => '',
+                                       'j_date' => '',
+                                       'internal' => '',
+                                       'deb_montant' => $mont_deb,
+                                       'cred_montant' => $mont_cred,
+                                       'description' => $line['description'],
+                                       'poste' => $line['poste'],
+                                       'qcode' => $line['j_qcode'],
+                                       'periode' => $line['periode'],
+                                       'jr_pj_number' => ''
+                               );
+                       }
+                       else
+                       {
+                               $array[] = array(
+                                       'jr_id' => $line['jr_id'],
+                                       'int_j_id' => $line['int_j_id'],
+                                       'j_id' => '',
+                                       'j_date' => '',
+                                       'internal' => '',
+                                       'deb_montant' => $mont_deb,
+                                       'cred_montant' => $mont_cred,
+                                       'description' => $line['description'],
+                                       'poste' => $line['poste'],
+                                       'qcode' => $line['j_qcode'],
+                                       'periode' => $line['periode'],
+                                       'jr_pj_number' => '');
+                       }
+               }
+               $this->row = $array;
+               $a = array($array, $tot_deb, $tot_cred);
+               return $a;
+       }
+
+       /** @brief  Get simplified row from ledger
+        *
+        * @param p_from periode
+        * @param p_to periode
+        * @param p_limit starting line
+        * @param p_offset number of lines
+        * @param trunc if data must be truncated (pdf export)
+        *
+        * \return an Array with the asked data
+        */
+
+       function get_rowSimple($p_from, $p_to, $trunc = 0, $p_limit = -1, 
$p_offset = -1)
+       {
+               global $g_user;
+               // Grand-livre : id= 0
+               //---
+               $jrn = ($this->id == 0 ) ? "and " . $g_user->get_ledger_sql() : 
"and jrn_def_id = " . $this->id;
+
+               $periode = sql_filter_per($this->db, $p_from, $p_to, 'p_id', 
'jr_tech_per');
+
+               $cond_limite = ($p_limit != -1) ? " limit " . $p_limit . " 
offset " . $p_offset : "";
+               //---
+               $sql = "
+             SELECT jrn.jr_id as jr_id ,
+             jrn.jr_id as num ,
+             jrn.jr_def_id as jr_def_id,
+             jrn.jr_montant as montant,
+             substr(jrn.jr_comment,1,35) as comment,
+             to_char(jrn.jr_date,'DD-MM-YYYY') as date,
+             to_char(jrn.jr_date_paid,'DD-MM-YYYY') as date_paid,
+             jr_pj_number,
+             jr_internal,
+             jrn.jr_grpt_id as grpt_id,
+             jrn.jr_pj_name as pj,
+             jrn_def_type,
+             jrn.jr_tech_per
+             FROM jrn join jrn_def on (jrn_def_id=jr_def_id)
+             WHERE $periode $jrn order by 
jr_date,substring(jrn.jr_pj_number,'[0-9]+$')::numeric asc  $cond_limite";
+
+               $Res = $this->db->exec_sql($sql);
+               $Max = Database::num_row($Res);
+               if ($Max == 0)
+               {
+                       return null;
+               }
+               $type = $this->get_type();
+               // for type ACH and Ven we take more info
+               if ($type == 'ACH' || $type == 'VEN')
+               {
+                       $a_ParmCode = $this->db->get_array('select 
p_code,p_value from parm_code');
+                       $a_TVA = $this->db->get_array('select 
tva_id,tva_label,tva_poste
+                                        from tva_rate where tva_rate != 0 
order by tva_rate,tva_label,tva_id ');
+                       for ($i = 0; $i < $Max; $i++)
+                       {
+                               $array[$i] = Database::fetch_array($Res, $i);
+                               $p = $this->get_detail($array[$i], $type, 
$trunc, $a_TVA, $a_ParmCode);
+                               if ($array[$i]['dep_priv'] != 0.0)
+                               {
+                                       $array[$i]['comment'].="(priv. " . 
$array[$i]['dep_priv'] . ")";
+                               }
+                       }
+               }
+               else
+               {
+                       $array = Database::fetch_all($Res);
+               }
+
+               return $array;
+       }
+
+// end function get_rowSimple
+
+       /**
+        * @brief guess what  the next pj should be
+        */
+
+       function guess_pj()
+       {
+               $prop = $this->get_propertie();
+               $pj_pref = $prop["jrn_def_pj_pref"];
+               $pj_seq = $this->get_last_pj() + 1;
+               return $pj_pref . $pj_seq;
+       }
+
+       /**
+        * @brief Show all the operation
+        * @param$sql is the sql stmt, normally created by build_search_sql
+        * @param$offset the offset
+        * @param$p_paid if we want to see info about payment
+         @code
+         // Example
+         // Build the sql
+         list($sql,$where)=$Ledger->build_search_sql($_GET);
+         // Count nb of line
+         $max_line=$this->db->count_sql($sql);
+
+         $step=$_SESSION['g_pagesize'];
+         $page=(isset($_GET['offset']))?$_GET['page']:1;
+         $offset=(isset($_GET['offset']))?$_GET['offset']:0;
+         // create the nav. bar
+         $bar=navigation_bar($offset,$max_line,$step,$page);
+         // show a part
+         list($count,$html)= $Ledger->list_operation($sql,$offset,0);
+         echo $html;
+         // show nav bar
+         echo $bar;
+
+         @endcode
+        * @see build_search_sql
+        * @see display_search_form
+        * @see search_form
+
+        * @return HTML string
+        */
+
+       public function list_operation_to_reconcile($sql,$p_target)
+       {
+               global $g_parameter, $g_user;
+               $gDossier = dossier::id();
+               $limit = " LIMIT ".MAX_RECONCILE;
+               // Sort
+               // Count
+               $count = $this->db->count_sql($sql);
+               // Add the limit
+               $sql.=" order by jr_date asc " . $limit;
+
+               // Execute SQL stmt
+               $Res = $this->db->exec_sql($sql);
+
+               //starting from here we can refactor, so that instead of 
returning the generated HTML,
+               //this function returns a tree structure.
+
+               $r = "";
+
+
+               $Max = Database::num_row($Res);
+
+               if ($Max == 0)
+                       return array(0, _("Aucun enregistrement trouvé"));
+                $r.=HtmlInput::hidden("target", $p_target);
+               $r.='<table class="result">';
+
+
+               $r.="<tr >";
+               $r.="<th>"._("Selection")."</th>";
+               $r.="<th>"._("Internal")."</th>";
+
+               if ($this->type == 'ALL')
+               {
+                       $r.=th(_('Journal'));
+               }
+
+               $r.='<th>'._("Date").'</th>';
+               $r.='<th>'._("Pièce").'</td>';
+               $r.=th(_('tiers'));
+               $r.='<th>'._("Description").'</th>';
+               $r.=th(_('Notes'), ' ');
+               $r.='<th>'._("Montant").'</th>';
+               $r.="<th>" . _('Concerne') . "</th>";
+               $r.="</tr>";
+               // Total Amount
+               $tot = 0.0;
+               $gDossier = dossier::id();
+               $str_dossier = Dossier::id();
+               for ($i = 0; $i < $Max; $i++)
+               {
+
+
+                       $row = Database::fetch_array($Res, $i);
+
+                       if ($i % 2 == 0)
+                               $tr = '<TR class="odd">';
+                       else
+                               $tr = '<TR class="even">';
+                       $r.=$tr;
+                       // Radiobox
+                       //
+
+                       $r.='<td><INPUT TYPE="CHECKBOX" name="jr_concerned' . 
$row['jr_id'] . '" ID="jr_concerned' . $row['jr_id'] . '" 
value="'.$row['quick_code'].'"> </td>';
+                       //internal code
+                       // button  modify
+                       $r.="<TD>";
+                       // If url contains
+                       //
+
+            $href = basename($_SERVER['PHP_SELF']);
+
+
+                       $r.=sprintf('<A class="detail" 
style="text-decoration:underline" 
HREF="javascript:modifyOperation(\'%s\',\'%s\')" >%s </A>', $row['jr_id'], 
$gDossier, $row['jr_internal']);
+                       $r.="</TD>";
+                       if ($this->type == 'ALL')
+                               $r.=td($row['jrn_def_name']);
+                       // date
+                       $r.="<TD>";
+                       $r.=$row['str_jr_date'];
+                       $r.="</TD>";
+
+                       // pj
+                       $r.="<TD>";
+                       $r.=$row['jr_pj_number'];
+                       $r.="</TD>";
+
+                       // Tiers
+                       $other = ($row['quick_code'] != '') ? '[' . 
$row['quick_code'] . '] ' . $row['name'] . ' ' . $row['first_name'] : '';
+                       $r.=td($other);
+                       // comment
+                       $r.="<TD>";
+                       $tmp_jr_comment = h($row['jr_comment']);
+                       $r.=$tmp_jr_comment;
+                       $r.="</TD>";
+                       $r.=td(h($row['n_text']), ' style="font-size:0.87em"');
+                       // Amount
+                       // If the ledger is financial :
+                       // the credit must be negative and written in red
+                       $positive = 0;
+
+                       // Check ledger type :
+                       if ($row['jrn_def_type'] == 'FIN')
+                       {
+                               $positive = $this->db->get_value("select 
qf_amount from quant_fin where jr_id=$1", array($row['jr_id']));
+                               if ($this->db->count() != 0)
+                                       $positive = ($positive < 0) ? 1 : 0;
+                       }
+                       $r.="<TD align=\"right\">";
+
+                       $r.=( $positive != 0 ) ? "<font color=\"red\">  - " . 
nbm($row['jr_montant']) . "</font>" : nbm($row['jr_montant']);
+                       $r.="</TD>";
+
+
+
+                       // Rapprochement
+                       $rec = new Acc_Reconciliation($this->db);
+                       $rec->set_jr_id($row['jr_id']);
+                       $a = $rec->get();
+                       $r.="<TD>";
+                       if ($a != null)
+                       {
+
+                               foreach ($a as $key => $element)
+                               {
+                                       $operation = new 
Acc_Operation($this->db);
+                                       $operation->jr_id = $element;
+                                       $l_amount = 
$this->db->get_value("select jr_montant from jrn " .
+                                                       " where 
jr_id=$element");
+                                       $r.= "<A class=\"detail\" 
HREF=\"javascript:modifyOperation('" . $element . "'," . $gDossier . ")\" > " . 
$operation->get_internal() . "[" . nbm($l_amount) . "]</A>";
+                               }//for
+                       }// if ( $a != null ) {
+                       $r.="</TD>";
+
+                       if ($row['jr_valid'] == 'f')
+                       {
+                               $r.="<TD>"._("Opération annulée")."</TD>";
+                       }
+                       // end row
+                       $r.="</tr>";
+               }
+               $r.='</table>';
+               return array($count, $r);
+       }
+
+       /**
+        * @brief Show all the operation
+        * @param$sql is the sql stmt, normally created by build_search_sql
+        * @param$offset the offset
+        * @param$p_paid if we want to see info about payment
+         \code
+         // Example
+         // Build the sql
+         list($sql,$where)=$Ledger->build_search_sql($_GET);
+         // Count nb of line
+         $max_line=$cn->count_sql($sql);
+
+         $step=$_SESSION['g_pagesize'];
+         $page=(isset($_GET['offset']))?$_GET['page']:1;
+         $offset=(isset($_GET['offset']))?$_GET['offset']:0;
+         // create the nav. bar
+         $bar=navigation_bar($offset,$max_line,$step,$page);
+         // show a part
+         list($count,$html)= $Ledger->list_operation($sql,$offset,0);
+         echo $html;
+         // show nav bar
+         echo $bar;
+
+         \endcode
+        * \see build_search_sql
+        * \see display_search_form
+        * \see search_form
+
+        * \return HTML string
+        */
+
+       public function list_operation($sql, $offset, $p_paid = 0)
+       {
+               global $g_parameter, $g_user;
+               bcscale(2);
+               $table = new Sort_Table();
+               $gDossier = dossier::id();
+               $amount_paid = 0.0;
+               $amount_unpaid = 0.0;
+               $limit = ($_SESSION['g_pagesize'] != -1) ? " LIMIT " . 
$_SESSION['g_pagesize'] : "";
+               $offset = ($_SESSION['g_pagesize'] != -1) ? " OFFSET " . 
Database::escape_string($offset) : "";
+               $order = "  order by jr_date_order asc,jr_internal asc";
+               // Sort
+               $url = "?" . CleanUrl();
+               $str_dossier = dossier::get();
+               $table->add(_("Date"), $url, 'order by jr_date 
asc,substring(jr_pj_number,\'[0-9]+$\')::numeric asc', 'order by  jr_date 
desc,substring(jr_pj_number,\'[0-9]+$\')::numeric desc', "da", "dd");
+               $table->add(_('Echeance'), $url, " order by  jr_ech asc", " 
order by  jr_ech desc", 'ea', 'ed');
+               $table->add(_('Paiement'), $url, " order by  jr_date_paid asc", 
" order by  jr_date_paid desc", 'eap', 'edp');
+               $table->add(_('Pièce'), $url, ' order by  
substring(jr_pj_number,\'[0-9]+$\')::numeric asc ', ' order by  
substring(jr_pj_number,\'[0-9]+$\')::numeric desc ', "pja", "pjd");
+               $table->add(_('Tiers'), $url, " order by  name asc", " order by 
 name desc", 'na', 'nd');
+               $table->add(_('Montant'), $url, " order by jr_montant asc", " 
order by jr_montant desc", "ma", "md");
+               $table->add(_("Description"), $url, "order by jr_comment asc", 
"order by jr_comment desc", "ca", "cd");
+
+               $ord = (!isset($_GET['ord'])) ? 'da' : $_GET['ord'];
+               $order = $table->get_sql_order($ord);
+
+               // Count
+               $count = $this->db->count_sql($sql);
+               // Add the limit
+               $sql.=$order . $limit . $offset;
+               // Execute SQL stmt
+               $Res = $this->db->exec_sql($sql);
+
+               //starting from here we can refactor, so that instead of 
returning the generated HTML,
+               //this function returns a tree structure.
+
+               $r = "";
+
+
+               $Max = Database::num_row($Res);
+
+               if ($Max == 0)
+                       return array(0, _("Aucun enregistrement trouvé"));
+
+               $r.='<table class="result">';
+
+
+               $r.="<tr >";
+               $r.="<th>"._("n° interne")."</th>";
+               if ($this->type == 'ALL')
+               {
+                       $r.=th('Journal');
+               }
+               $r.='<th>' . $table->get_header(0) . '</th>';
+               if ($p_paid != 0 ) $r.='<th>' . $table->get_header(1) . '</td>';
+               if ($p_paid != 0 ) $r.='<th>' . $table->get_header(2) . '</th>';
+               $r.='<th>' . $table->get_header(3) . '</th>';
+               $r.='<th>' . $table->get_header(4) . '</th>';
+               $r.='<th>' . $table->get_header(6) . '</th>';
+               $r.=th('Notes', ' style="width:15%"');
+               $r.='<th>' . $table->get_header(5) . '</th>';
+               // if $p_paid is not equal to 0 then we have a paid column
+               if ($p_paid != 0)
+               {
+                       $r.="<th> " . _('Payé') . "</th>";
+               }
+               $r.="<th>" . _('Concerne') . "</th>";
+               $r.="<th>" . _('Document') . "</th>";
+               $r.="</tr>";
+               // Total Amount
+               $tot = 0.0;
+               $gDossier = dossier::id();
+               for ($i = 0; $i < $Max; $i++)
+               {
+
+
+                       $row = Database::fetch_array($Res, $i);
+
+                       if ($i % 2 == 0)
+                               $tr = '<TR class="odd">';
+                       else
+                               $tr = '<TR class="even">';
+                       $r.=$tr;
+                       //internal code
+                       // button  modify
+                       $r.="<TD>";
+                       // If url contains
+                       //
+
+            $href = basename($_SERVER['PHP_SELF']);
+
+
+                       $r.=sprintf('<A class="detail" 
style="text-decoration:underline" 
HREF="javascript:modifyOperation(\'%s\',\'%s\')" >%s </A>', $row['jr_id'], 
$gDossier, $row['jr_internal']);
+                       $r.="</TD>";
+                       if ($this->type == 'ALL')
+                               $r.=td($row['jrn_def_name']);
+                       // date
+                       $r.="<TD>";
+                       $r.=$row['str_jr_date'];
+                       $r.="</TD>";
+                       // echeance
+                       if ($p_paid != 0 )
+                        {
+                            $r.="<TD>";
+                            $r.=$row['str_jr_ech'];
+                            $r.="</TD>";
+                            $r.="<TD>";
+                            $r.=$row['str_jr_date_paid'];
+                            $r.="</TD>";
+                        }
+
+                       // pj
+                       $r.="<TD>";
+                       $r.=$row['jr_pj_number'];
+                       $r.="</TD>";
+
+                       // Tiers
+                       $other = ($row['quick_code'] != '') ? '[' . 
$row['quick_code'] . '] ' . $row['name'] . ' ' . $row['first_name'] : '';
+                       $r.=td($other);
+                       // comment
+                       $r.="<TD>";
+                       $tmp_jr_comment = h($row['jr_comment']);
+                       $r.=$tmp_jr_comment;
+                       $r.="</TD>";
+                       $r.=td(h($row['n_text']), ' style="font-size:0.87em%"');
+                       // Amount
+                       // If the ledger is financial :
+                       // the credit must be negative and written in red
+                       $positive = 0;
+
+                       // Check ledger type :
+                       if ($row['jrn_def_type'] == 'FIN')
+                       {
+                               $positive = $this->db->get_value("select 
qf_amount from quant_fin where jr_id=$1", array($row['jr_id']));
+                               if ($this->db->count() != 0)
+                                       $positive = ($positive < 0) ? 1 : 0;
+                       }
+                       $r.="<TD align=\"right\">";
+                       $t_amount=$row['jr_montant'];
+                       if ($row['total_invoice'] != null && 
$row['total_invoice'] != $row['jr_montant'])
+                               $t_amount=$row['total_invoice'];
+                       $tot = ($positive != 0) ? bcsub($tot , $t_amount ): 
bcadd($tot , $t_amount);
+                       //STAN $positive always == 0
+                       if ($row [ 'jrn_def_type']=='FIN')
+                       {
+                               $r.=( $positive != 0 ) ? "<font color=\"red\">  
- " . nbm($t_amount) . "</font>" : nbm($t_amount);
+                       }
+                       else
+                       {
+                               $r.=( $t_amount <  0 ) ? "<font color=\"red\">  
" . nbm($t_amount) . "</font>" : nbm($t_amount);
+                       }
+                       $r.="</TD>";
+
+
+                       // Show the paid column if p_paid is not null
+                       if ($p_paid != 0)
+                       {
+                               $w = new ICheckBox();
+                               $w->name = "rd_paid" . $row['jr_id'];
+                               $w->selected = ($row['jr_rapt'] == 'paid') ? 
true : false;
+                               // if p_paid == 2 then readonly
+                               $w->readonly = ( $p_paid == 2) ? true : false;
+                               $h = new IHidden();
+                               $h->name = "set_jr_id" . $row['jr_id'];
+                               $r.='<TD>' . $w->input() . $h->input() . 
'</TD>';
+                               if ($row['jr_rapt'] == 'paid')
+                                       
$amount_paid=bcadd($amount_paid,$t_amount);
+                               else
+                                       
$amount_unpaid=bcadd($amount_unpaid,$t_amount);
+                       }
+
+                       // Rapprochement
+                       $rec = new Acc_Reconciliation($this->db);
+                       $rec->set_jr_id($row['jr_id']);
+                       $a = $rec->get();
+                       $r.="<TD>";
+                       if ($a != null)
+                       {
+
+                               foreach ($a as $key => $element)
+                               {
+                                       $operation = new 
Acc_Operation($this->db);
+                                       $operation->jr_id = $element;
+                                       $l_amount = 
$this->db->get_value("select jr_montant from jrn " .
+                                                       " where 
jr_id=$element");
+                                       $r.= "<A class=\"detail\" 
HREF=\"javascript:modifyOperation('" . $element . "'," . $gDossier . ")\" > " . 
$operation->get_internal() . "[" . nbm($l_amount) . "]</A>";
+                               }//for
+                       }// if ( $a != null ) {
+                       $r.="</TD>";
+
+                       if ($row['jr_valid'] == 'f')
+                       {
+                               $r.="<TD>"._("Opération annulée")."</TD>";
+                       }
+                       else
+                       {
+
+                       } // else
+                       //document
+                       if ($row['jr_pj_name'] != "")
+                       {
+                            
$r.='<td>'.HtmlInput::show_receipt_document($row['jr_id']).'</td>';
+                       }
+                       else
+                               $r.="<TD></TD>";
+
+                       // end row
+                       $r.="</tr>";
+               }
+               $amount_paid = round($amount_paid, 4);
+               $amount_unpaid = round($amount_unpaid, 4);
+               $tot = round($tot, 4);
+               $r.="<TR>";
+               $r.='<TD COLSPAN="5">Total</TD>';
+               $r.='<TD ALIGN="RIGHT">' . nbm($tot) . "</TD>";
+               $r.="</tr>";
+               if ($p_paid != 0)
+               {
+                       $r.="<TR>";
+                       $r.='<TD COLSPAN="5">'._("Payé").'</TD>';
+                       $r.='<TD ALIGN="RIGHT">' . nbm($amount_paid) . "</TD>";
+                       $r.="</tr>";
+                       $r.="<TR>";
+                       $r.='<TD COLSPAN="5">'._("Non payé").'</TD>';
+                       $r.='<TD ALIGN="RIGHT">' . nbm($amount_unpaid) . 
"</TD>";
+                       $r.="</tr>";
+               }
+               $r.="</table>";
+
+               return array($count, $r);
+       }
+
+       /**
+        * @brief get_detail gives the detail of row
+        * this array must contains at least the field
+        *       <ul>
+        *       <li> montant</li>
+        *       <li> grpt_id
+        *       </ul>
+        * the following field will be added
+        *       <ul>
+        *       <li> HTVA
+        *       <li> TVAC
+        *       <li> TVA array with
+        *          <ul>
+        *          <li> field 0 idx
+        *          <li> array containing tva_id,tva_label and tva_amount
+        *          </ul>
+        *       </ul>
+        *
+        * @paramp_array the structure is set in get_rowSimple, this array is
+        *        modified,
+        * @param $trunc if the data must be truncated, usefull for pdf export
+        * @paramp_jrn_type is the type of the ledger (ACH or VEN)
+        * @param $a_TVA TVA Array (default null)
+        * @param $a_ParmCode Array (default null)
+        * \return p_array
+        */
+
+       function get_detail(&$p_array, $p_jrn_type, $trunc = 0, $a_TVA = null, 
$a_ParmCode = null)
+       {
+            bcscale(2);
+            
+               if ($a_TVA == null)
+               {
+                       //Load TVA array
+                       $a_TVA = $this->db->get_array('select 
tva_id,tva_label,tva_poste
+                                        from tva_rate where tva_rate != 0 
order by tva_rate,tva_label,tva_id');
+               }
+               if ($a_ParmCode == null)
+               {
+                       //Load Parm_code
+                       $a_ParmCode = $this->db->get_array('select 
p_code,p_value from parm_code');
+               }
+               // init
+               $p_array['client'] = "";
+               $p_array['TVAC'] = 0;
+               $p_array['TVA'] = array();
+               $p_array['AMOUNT_TVA'] = 0.0;
+               $p_array['dep_priv'] = 0;
+               $p_array['dna'] = 0;
+               $p_array['tva_dna'] = 0;
+               $p_array['tva_np'] = 0;
+               $dep_priv = 0.0;
+                
+               //
+               // Retrieve data from jrnx
+               $sql = "select j_id,j_poste,j_montant, j_debit,j_qcode from 
jrnx where " .
+                               " j_grpt=" . $p_array['grpt_id'];
+               $Res2 = $this->db->exec_sql($sql);
+               $data_jrnx = Database::fetch_all($Res2);
+               $c = 0;
+
+               // Parse data from jrnx and fill diff. field
+               foreach ($data_jrnx as $code)
+               {
+                       $idx_tva = 0;
+                       $poste = new Acc_Account_Ledger($this->db, 
$code['j_poste']);
+
+                       // if card retrieve name if the account is not a VAT 
account
+                       if (strlen(trim($code['j_qcode'])) != 0 && 
$poste->isTva() == 0)
+                       {
+                               $fiche = new Fiche($this->db);
+                               $fiche->get_by_qcode(trim($code['j_qcode']), 
false);
+                               $fiche_def_id = $fiche->get_fiche_def_ref_id();
+                               // Customer or supplier
+                               if ($fiche_def_id == FICHE_TYPE_CLIENT ||
+                                               $fiche_def_id == 
FICHE_TYPE_FOURNISSEUR
+                                        ||$fiche_def_id == FICHE_TYPE_ADM_TAX)
+                               {
+                                       $p_array['TVAC'] = $code['j_montant'];
+
+                                       $p_array['client'] = ($trunc == 0) ? 
$fiche->getName() : mb_substr($fiche->getName(), 0, 20);
+                                       $p_array['reversed'] = false;
+                                       if ($fiche_def_id == FICHE_TYPE_CLIENT 
&& $code['j_debit'] == 'f')
+                                       {
+                                               $p_array['reversed'] = true;
+                                               $p_array['TVAC']*=-1;
+                                       }
+                                       if ($fiche_def_id == FICHE_TYPE_ADM_TAX 
&& $code['j_debit'] == 'f')
+                                       {
+                                               $p_array['reversed'] = true;
+                                               $p_array['TVAC']*=-1;
+                                       }
+                                       if ($fiche_def_id == 
FICHE_TYPE_FOURNISSEUR && $code['j_debit'] == 't')
+                                       {
+                                               $p_array['reversed'] = true;
+                                               $p_array['TVAC']*=-1;
+                                       }
+                               }
+                               else
+                               {
+                                       // if we use the ledger ven / ach for 
others card than supplier and customer
+                                       if ($fiche_def_id != FICHE_TYPE_VENTE &&
+                                                       $fiche_def_id != 
FICHE_TYPE_ACH_MAR &&
+                                                       $fiche_def_id != 
FICHE_TYPE_ACH_SER  &&
+                                                       $fiche_def_id != 
FICHE_TYPE_ACH_MAT
+                                           )                                   
             
+                                       {
+                                               $p_array['TVAC'] = 
$code['j_montant'];
+
+                                               $p_array['client'] = ($trunc == 
0) ? $fiche->getName() : mb_substr($fiche->getName(), 0, 20);
+                                               $p_array['reversed'] = false;
+                                               if ($p_jrn_type == 'ACH' && 
$code['j_debit'] == 't')
+                                               {
+                                                       $p_array['reversed'] = 
true;
+                                                       $p_array['TVAC']*=-1;
+                                               }
+                                               if ($p_jrn_type == 'VEN' && 
$code['j_debit'] == 'f')
+                                               {
+                                                       $p_array['reversed'] = 
true;
+                                                       $p_array['TVAC']*=-1;
+                                               }
+                                       }
+                               }
+                       }
+                       // if TVA, load amount, tva id and rate in array
+                       foreach ($a_TVA as $line_tva)
+                       {
+                               list($tva_deb, $tva_cred) = explode(',', 
$line_tva['tva_poste']);
+                               if ($code['j_poste'] == $tva_deb ||
+                                               $code['j_poste'] == $tva_cred)
+                               {
+
+                                       // For the reversed operation
+                                       if ($p_jrn_type == 'ACH' && 
$code['j_debit'] == 'f')
+                                       {
+                                               $code['j_montant'] = -1 * 
$code['j_montant'];
+                                       }
+                                       if ($p_jrn_type == 'VEN' && 
$code['j_debit'] == 't')
+                                       {
+                                               $code['j_montant'] = -1 * 
$code['j_montant'];
+                                       }
+
+                                       
$p_array['AMOUNT_TVA']+=$code['j_montant'];
+
+                                       $p_array['TVA'][$c] = array($idx_tva, 
array($line_tva['tva_id'], $line_tva['tva_label'], $code['j_montant']));
+                                       $c++;
+
+                                       $idx_tva++;
+                               }
+                       }
+
+                       // isDNA
+                       // If operation is reversed then  amount are negatif
+                       /* if ND */
+                       if ($p_array['jrn_def_type'] == 'ACH')
+                       {
+                               $purchase = new Gestion_Purchase($this->db);
+                               $purchase->search_by_jid($code['j_id']);
+                               $purchase->load();
+                               $dep_priv+=$purchase->qp_dep_priv;
+                               $p_array['dep_priv'] = $dep_priv;
+                                
$p_array['dna']=bcadd($p_array['dna'],$purchase->qp_nd_amount);
+                                
$p_array['tva_dna']=bcadd($p_array['tva_dna'],bcadd($purchase->qp_nd_tva,$purchase->qp_nd_tva_recup));
+                                
$p_array['tva_np']=bcadd($purchase->qp_vat_sided,$p_array['tva_np']);
+                       }
+                       if ($p_array['jrn_def_type'] == 'VEN') {
+                            $sold=new gestion_sold($this->db);
+                            $sold->search_by_jid($code['j_id']);
+                            $sold->load();
+                            
$p_array['tva_np']=bcadd($sold->qs_vat_sided,$p_array['tva_np']);
+                        }
+                        
+                        
+               }
+               $p_array['TVAC'] = sprintf('% 10.2f', $p_array['TVAC'] );
+               $p_array['HTVA'] = sprintf('% 10.2f', $p_array['TVAC'] - 
$p_array['AMOUNT_TVA']-$p_array['tva_dna']);
+               $r = "";
+               $a_tva_amount = array();
+               // inline TVA (used for the PDF)
+               foreach ($p_array['TVA'] as $linetva)
+               {
+                       foreach ($a_TVA as $tva)
+                       {
+                               if ($tva['tva_id'] == $linetva[1][0])
+                               {
+                                       $a = $tva['tva_id'];
+                                       $a_tva_amount[$a] = $linetva[1][2];
+                               }
+                       }
+               }
+               foreach ($a_TVA as $line_tva)
+               {
+                       $a = $line_tva['tva_id'];
+                       if (isset($a_tva_amount[$a]))
+                       {
+                               $tmp = sprintf("% 10.2f", $a_tva_amount[$a]);
+                               $r.="$tmp";
+                       }
+                       else
+                               $r.=sprintf("% 10.2f", 0);
+               }
+               $p_array['TVA_INLINE'] = $r;
+
+               return $p_array;
+       }
+
+// retrieve data from jrnx
+       /**
+        * @brief  Get the properties of a journal
+        *
+        * \return an array containing properties
+        *
+        */
+
+       function get_propertie()
+       {
+               if ($this->id == 0)
+                       return;
+
+               $Res = $this->db->exec_sql("select 
jrn_Def_id,jrn_def_name,jrn_def_class_deb,jrn_def_class_cred,jrn_def_type,
+                                 
jrn_deb_max_line,jrn_cred_max_line,jrn_def_ech,jrn_def_ech_lib,jrn_def_code,
+                                 
jrn_def_fiche_deb,jrn_def_fiche_cred,jrn_def_pj_pref
+                                 from jrn_Def
+                                 where jrn_def_id=$1", array($this->id));
+               $Count = Database::num_row($Res);
+               if ($Count == 0)
+               {
+                       echo '<DIV="redcontent"><H2 class="error">' . 
_('Parametres journaux non trouves') . '</H2> </DIV>';
+                       return null;
+               }
+               return Database::fetch_array($Res, 0);
+       }
+
+       /** \function GetDefLine
+        * @brief Get the number of lines of a journal
+        * @param$p_cred deb or cred
+        *
+        * \return an integer
+        */
+
+       function GetDefLine()
+       {
+               $sql_cred = 'jrn_deb_max_line';
+               $sql = "select jrn_deb_max_line as value from jrn_def where 
jrn_def_id=$1";
+               $r = $this->db->exec_sql($sql, array($this->id));
+               $Res = Database::fetch_all($r);
+               if (sizeof($Res) == 0)
+                       return 1;
+               return $Res[0]['value'];
+       }
+
+       /**
+        * @brief get the saldo of a ledger for a specific period
+        * @param$p_from start period
+        * @param$p_to end period
+        */
+
+       function get_solde($p_from, $p_to)
+       {
+               $ledger = "";
+               if ($this->id != 0)
+               {
+                       $ledger = " and j_jrn_def = " . $this->id;
+               }
+
+               $periode = sql_filter_per($this->db, $p_from, $p_to, 'p_id', 
'j_tech_per');
+               $sql = 'select j_montant as montant,j_debit as deb from jrnx 
where '
+                               . $periode . $ledger;
+
+               $ret = $this->db->exec_sql($sql);
+               $array = Database::fetch_all($ret);
+               $deb = 0.0;
+               $cred = 0.0;
+               foreach ($array as $line)
+               {
+
+                       if ($line['deb'] == 't')
+                               $deb+=$line['montant'];
+                       else
+                               $cred+=$line['montant'];
+               }
+               $response = array($deb, $cred);
+               return $response;
+       }
+
+       /**
+        * @brief Show a select list   of the ledgers you can access in
+        * writing, reading or simply accessing.
+        * @param$p_type = ALL or the type of the ledger (ACH,VEN,FIN,ODS)
+        * @param$p_access =3 for READ and WRITE, 2 for write and 1 for readonly
+        * \return     object HtmlInput select
+        */
+
+       function select_ledger($p_type = "ALL", $p_access = 3)
+       {
+               global $g_user;
+               $array = $g_user->get_ledger($p_type, $p_access);
+
+               if ($array == null)
+                       return null;
+               $idx = 0;
+               $ret = array();
+
+               foreach ($array as $value)
+               {
+                       $ret[$idx]['value'] = $value['jrn_def_id'];
+                       $ret[$idx]['label'] = h($value['jrn_def_name']);
+                       $idx++;
+               }
+
+               $select = new ISelect();
+               $select->name = 'p_jrn';
+               $select->value = $ret;
+               $select->selected = $this->id;
+               return $select;
+       }
+
+       /**
+        * @brief retrieve the jrn_def_fiche and return them into a array
+        *        index deb, cred
+        * \param
+        * \param
+        * \param
+        *
+        *
+        * \return return an array ('deb'=> ,'cred'=>)
+        */
+
+       function get_fiche_def()
+       {
+               $sql = "select jrn_def_fiche_deb as deb,jrn_def_fiche_cred as 
cred " .
+                               " from jrn_def where " .
+                               " jrn_def_id = $1 ";
+
+               $r = $this->db->exec_sql($sql, array($this->id));
+
+               $res = Database::fetch_all($r);
+               if (empty($res))
+                       return null;
+
+               return $res[0];
+       }
+
+       /**
+        * @brief retrieve the jrn_def_class_deb and return it
+        *
+        *
+        * \return return an string
+        */
+
+       function get_class_def()
+       {
+               $sql = "select jrn_def_class_deb  " .
+                               " from jrn_def where " .
+                               " jrn_def_id = $1";
+
+               $r = $this->db->exec_sql($sql, array($this->id));
+
+               $res = Database::fetch_all($r);
+
+               if (empty($res))
+                       return null;
+
+               return $res[0];
+       }
+
+       /**
+        * @brief show the result of the array to confirm
+        * before inserting
+        * @param$p_array array from the form
+        * \return string
+        */
+
+       function confirm($p_array, $p_readonly = false)
+       {
+               global $g_parameter;
+               $msg = array();
+               if (!$p_readonly)
+                       $msg = $this->verify($p_array);
+               $this->id = $p_array['p_jrn'];
+               if (empty($p_array))
+                       return 'Aucun r&eacute;sultat';
+               $anc = null;
+               extract($p_array);
+               $lPeriode = new Periode($this->db);
+               if ($this->check_periode() == true)
+               {
+                       $lPeriode->p_id = $period;
+               }
+               else
+               {
+                       $lPeriode->find_periode($e_date);
+               }
+               $total_deb = 0;
+               $total_cred = 0;
+               bcscale(2);
+
+               $ret = "";
+               if (!empty($msg))
+               {
+                       $ret.=$this->display_warning($msg, _("Attention : il 
vaut mieux utiliser les fiches que les postes comptables"));
+               }
+               $ret.="<table >";
+               $ret.="<tr><td>" . _('Date') . " : </td><td>$e_date</td></tr>";
+               /* display periode */
+               $date_limit = $lPeriode->get_date_limit();
+               $ret.='<tr> ' . td(_('Période Comptable')) . 
td($date_limit['p_start'] . '-' . $date_limit['p_end']) . '</tr>';
+               $ret.="<tr><td>" . _('Libellé') . " </td><td>" . h($desc) . 
"</td></tr>";
+               $ret.="<tr><td>" . _('PJ Num') . " </td><td>" . h($e_pj) . 
"</td></tr>";
+               $ret.='</table>';
+               $ret.="<table class=\"result\">";
+               $ret.="<tr>";
+               $ret.="<th>" . _('Quick Code ou ');
+               $ret.=_("Poste") . " </th>";
+               $ret.="<th style=\"text-align:left\"> " . _("Libellé") . " 
</th>";
+               $ret.="<th style=\"text-align:right\">" . _("Débit") . "</th>";
+               $ret.="<th style=\"text-align:right\">" . _("Crédit") . "</th>";
+               /* if we use the AC */
+               if ($g_parameter->MY_ANALYTIC != 'nu')
+               {
+                       $anc = new Anc_Plan($this->db);
+                       $a_anc = $anc->get_list();
+                       $x = count($a_anc);
+                       /* set the width of the col */
+                       $ret.='<th colspan="' . $x . '" 
style="width:auto;text-align:center" >' . _('Compt. Analytique') . '</th>';
+
+                       /* add hidden variables pa[] to hold the value of pa_id 
*/
+                       $ret.=Anc_Plan::hidden($a_anc);
+               }
+               $ret.="</tr>";
+
+               $ret.=HtmlInput::hidden('e_date', $e_date);
+               $ret.=HtmlInput::hidden('desc', $desc);
+               $ret.=HtmlInput::hidden('period', $lPeriode->p_id);
+               $ret.=HtmlInput::hidden('e_pj', $e_pj);
+               $ret.=HtmlInput::hidden('e_pj_suggest', $e_pj_suggest);
+               $mt = microtime(true);
+               $ret.=HtmlInput::hidden('mt', $mt);
+               // For predefined operation
+               $ret.=HtmlInput::hidden('e_comm', $desc);
+               $ret.=HtmlInput::hidden('jrn_type', $this->get_type());
+               $ret.=HtmlInput::hidden('p_jrn', $this->id);
+               $ret.=HtmlInput::hidden('nb_item', $nb_item);
+               if ($this->with_concerned == true)
+               {
+                       $ret.=HtmlInput::hidden('jrn_concerned', 
$jrn_concerned);
+               }
+               $ret.=dossier::hidden();
+               $count = 0;
+               for ($i = 0; $i < $nb_item; $i++)
+               {
+                       if ($p_readonly == true)
+                       {
+                               if (!isset(${'qc_' . $i}))
+                                       ${'qc_' . $i} = '';
+                               if (!isset(${'poste' . $i}))
+                                       ${'poste' . $i} = '';
+                               if (!isset(${'amount' . $i}))
+                                       ${'amount' . $i} = '';
+                       }
+                        $class=($i%2==0)?' class="even" ':' class="odd" ';
+                       $ret.="<tr $class> ";
+                       if (trim(${'qc_' . $i}) != "")
+                       {
+                               $oqc = new Fiche($this->db);
+                               $oqc->get_by_qcode(${'qc_' . $i}, false);
+                               $strPoste = $oqc->strAttribut(ATTR_DEF_ACCOUNT);
+                               $ret.="<td>" .
+                                               ${'qc_' . $i} . ' - ' .
+                                               
$oqc->strAttribut(ATTR_DEF_NAME) . HtmlInput::hidden('qc_' . $i, ${'qc_' . $i}) 
.
+                                               '</td>';
+                       }
+
+                       if (trim(${'qc_' . $i}) == "" && trim(${'poste' . $i}) 
!= "")
+                       {
+                               $oposte = new Acc_Account_Ledger($this->db, 
${'poste' . $i});
+                               $strPoste = $oposte->id;
+                               $ret.="<td>" . h(${"poste" . $i} . " - " .
+                                                               
$oposte->get_name()) . HtmlInput::hidden('poste' . $i, ${'poste' . $i}) .
+                                               '</td>';
+                       }
+
+                       if (trim(${'qc_' . $i}) == "" && trim(${'poste' . $i}) 
== "")
+                               continue;
+                       $ret.="<td>" . h(${"ld" . $i}) . HtmlInput::hidden('ld' 
. $i, ${'ld' . $i}) ; 
+                        $ret .=(isset(${"ck$i"})) ? HtmlInput::hidden('ck' . 
$i, ${'ck' . $i}) : "";
+                        $ret .=        "</td>";
+                       if (isset(${"ck$i"}))
+                       {
+                               $ret.="<td class=\"num\">" . nbm(${"amount" . 
$i}) . HtmlInput::hidden('amount' . $i, ${'amount' . $i}) . "</td>" . td("");
+                               $total_deb = bcadd($total_deb, ${'amount' . 
$i});
+                       }
+                       else
+                       {
+                               $ret.=td("") . "<td class=\"num\">" . 
nbm(${"amount" . $i}) . HtmlInput::hidden('amount' . $i, ${'amount' . $i}) . 
"</td>";
+                               $total_cred = bcadd($total_cred, ${"amount" . 
$i});
+                       }
+                       /*$ret.="<td>";
+                       $ret.=(isset(${"ck$i"})) ? HtmlInput::hidden('ck' . $i, 
${'ck' . $i}) : "";
+                       $ret.="</td>";*/
+                       // CA
+
+                       if ($g_parameter->MY_ANALYTIC != 'nu') // use of AA
+                       {
+                               if (preg_match("/^[6,7]+/", $strPoste) == 1)
+                               {
+                                       // show form
+                                       $op = new Anc_Operation($this->db);
+                                       $null = ($g_parameter->MY_ANALYTIC == 
'op') ? 1 : 0;
+                                       $p_array['pa_id'] = $a_anc;
+                                       /* op is the operation it contains 
either a sequence or a jrnx.j_id */
+                                       $ret.=HtmlInput::hidden('op[]=', $i);
+
+                                       $ret.='<td style="text-align:center">';
+                                       $read = ($p_readonly == true) ? 0 : 1;
+                                       $ret.=$op->display_form_plan($p_array, 
$null, $read, $count, round(${'amount' . $i}, 2));
+                                       $ret.='</td>';
+                                       $count++;
+                               }
+                       }
+
+
+
+                       $ret.="</tr>";
+               }
+               $ret.=tr(td('') . td(_('Totaux')) . td($total_deb, 
'class="num"') . td($total_cred, 'class="num"'), 'class="highlight"');
+               $ret.="</table>";
+               if ($g_parameter->MY_ANALYTIC != 'nu' && $p_readonly == false)
+                       $ret.='<input type="button" class="button" value="' . 
_('verifie Imputation Analytique') . '" onClick="verify_ca(\'\');">';
+               return $ret;
+       }
+       function get_min_row()
+       {
+               $row=$this->db->get_value("select jrn_deb_max_line from jrn_def 
where jrn_def_id=$1",array($this->id));
+               return $row;
+       }
+       /**
+        * @brief Show the form to encode your operation
+        * @param$p_array if you correct or use a predef operation (default = 
null)
+        * @param$p_readonly 1 for readonly 0 for writable (default 0)
+        address@hidden if ledger not found
+        * \return a string containing the form
+        */
+
+       function input($p_array = null, $p_readonly = 0)
+       {
+               global $g_parameter, $g_user;
+               $this->nb=$this->get_min_row();
+               if ($p_readonly == 1)
+                       return $this->confirm($p_array);
+
+               if ($p_array != null)
+                       extract($p_array);
+               $add_js = "";
+               if ($g_parameter->MY_PJ_SUGGEST == 'Y')
+               {
+                       $add_js = "update_pj();";
+               }
+               if ($g_parameter->MY_DATE_SUGGEST=='Y')
+               {
+                       $add_js.='get_last_date();';
+               }
+               $add_js.='update_row("quick_item");';
+               $ret = "";
+               if ($g_user->check_action(FICADD) == 1)
+               {
+                       /* Add button */
+                       $f_add_button = new IButton('add_card');
+                       $f_add_button->label = _('Créer une nouvelle fiche');
+                       $f_add_button->set_attribute('ipopup', 'ipop_newcard');
+                       $f_add_button->set_attribute('jrn', $this->id);
+                       $f_add_button->javascript = " 
this.jrn=\$('p_jrn').value;select_card_type(this);";
+                       $f_add_button->input();
+               }
+               $wLedger = $this->select_ledger('ODS', 2);
+               if ($wLedger == null)
+                       throw new Exception(_('Pas de journal disponible'));
+               $wLedger->javascript = 
"onChange='update_name();update_predef(\"ods\",\"t\",\"".$_REQUEST['ac']."\");$add_js'";
+               $label = " Journal " . HtmlInput::infobulle(2);
+
+               $ret.=$label . $wLedger->input();
+
+
+               // Load the javascript
+               //
+        $ret.="<table>";
+               $ret.= '<tr ><td colspan="2" style="width:auto">';
+               $wDate = new IDate('e_date');
+               $wDate->readonly = $p_readonly;
+               $e_date = (isset($e_date) && trim($e_date) != '') ? $e_date : 
'';
+               $wDate->value = $e_date;
+
+               $ret.=_("Date") . ' : ' . $wDate->input();
+               $ret.= '</td>';
+               /* insert periode if needed */
+               // Periode
+               //--
+               if ($this->check_periode() == true)
+               {
+                       $l_user_per = $g_user->get_periode();
+                       $def = (isset($periode)) ? $periode : $l_user_per;
+
+                       $period = new IPeriod("period");
+                       $period->user = $g_user;
+                       $period->cn = $this->db;
+                       $period->value = $def;
+                       $period->type = OPEN;
+                       try
+                       {
+                               $l_form_per = $period->input();
+                       }
+                       catch (Exception $e)
+                       {
+                               if ($e->getCode() == 1)
+                               {
+                                       echo _("Aucune période ouverte");
+                                       exit();
+                               }
+                       }
+                       $label = HtmlInput::infobulle(3);
+                       $f_periode = _("Période comptable") . " $label " . 
$l_form_per;
+                       $ret.=td($f_periode);
+               }
+               $wPJ = new IText('e_pj');
+               $wPJ->readonly = false;
+               $wPJ->size = 10;
+
+               /* suggest PJ ? */
+               $default_pj = '';
+               if ($g_parameter->MY_PJ_SUGGEST == 'Y')
+               {
+                       $default_pj = $this->guess_pj();
+               }
+               $wPJ->value = (isset($e_pj)) ? $e_pj : $default_pj;
+               $ret.= '</tr>';
+               $ret.='<tr >';
+               $ret.='<td colspan="2" style="width:auto"> ' . _('Pièce') . ' : 
' . $wPJ->input();
+               $ret.=HtmlInput::hidden('e_pj_suggest', $default_pj);
+               $ret.= '</tr>';
+               $ret.= '</td>';
+
+               $ret.= '<tr>';
+               $ret.='<td colspan="2" style="width:auto">';
+               $ret.=_('Libellé');
+               $wDescription = new IText('desc');
+               $wDescription->readonly = $p_readonly;
+               $wDescription->size = "50";
+               $wDescription->value = (isset($desc)) ? $desc : '';
+
+               $ret.=$wDescription->input();
+               $ret.= '</td>';
+               $ret.='</tr>';
+
+               $ret.= '</table>';
+               $nb_row = (isset($nb_item) ) ? $nb_item : $this->nb;
+
+               $ret.=HtmlInput::hidden('nb_item', $nb_row);
+               $ret.=dossier::hidden();
+
+               $ret.=dossier::hidden();
+
+               $ret.=HtmlInput::hidden('jrn_type', $this->get_type());
+               $info = HtmlInput::infobulle(0);
+               $info_poste = HtmlInput::infobulle(9);
+               if ($g_user->check_action(FICADD) == 1)
+                       $ret.=$f_add_button->input();
+               $ret.='<table id="quick_item" 
style="position:float;width:100%">';
+               $ret.='<tr>' .
+                               '<th style="text-align:left">Quickcode' . $info 
. '</th>' .
+                               '<th style="text-align:left">' . _('Poste') . 
$info_poste . '</th>' .
+                               '<th style="text-align:left">' . _('Libellé') . 
'</th>' .
+                               '<th style="text-align:left">' . _('Montant') . 
'</th>' .
+                               '<th style="text-align:left">' . _('Débit') . 
'</th>' .
+                               '</tr>';
+
+
+               for ($i = 0; $i < $nb_row; $i++)
+               {
+                       // Quick Code
+                       $quick_code = new ICard('qc_' . $i);
+                       $quick_code->set_dblclick("fill_ipopcard(this);");
+                       $quick_code->set_attribute('ipopup', 'ipopcard');
+
+                       // name of the field to update with the name of the card
+                       $quick_code->set_attribute('label', "ld" . $i);
+
+                       // name of the field to update with the name of the card
+                       $quick_code->set_attribute('typecard', 'filter');
+
+                       // Add the callback function to filter the card on the 
jrn
+                       $quick_code->set_callback('filter_card');
+                       $quick_code->set_function('fill_data');
+                       $quick_code->javascript = sprintf(' 
onchange="fill_data_onchange(\'%s\');" ', $quick_code->name);
+
+                       $quick_code->value = (isset(${'qc_' . $i})) ? ${'qc_' . 
$i} : "";
+                       $quick_code->readonly = $p_readonly;
+                        
+                       $label = '';
+                       if ($quick_code->value != '')
+                       {
+                               $Fiche = new Fiche($this->db);
+                               $Fiche->get_by_qcode($quick_code->value);
+                               $label = $Fiche->strAttribut(ATTR_DEF_NAME);
+                       }
+
+
+                       // Account
+                       $poste = new IPoste();
+                       $poste->name = 'poste' . $i;
+                       $poste->set_attribute('jrn', $this->id);
+                       $poste->set_attribute('ipopup', 'ipop_account');
+                       $poste->set_attribute('label', 'ld' . $i);
+                       $poste->set_attribute('account', 'poste' . $i);
+                       $poste->set_attribute('dossier', Dossier::id());
+
+                       $poste->value = (isset(${'poste' . $i})) ? ${"poste" . 
$i} : ''
+                       ;
+                       $poste->dbl_click_history();
+
+                       $poste->readonly = $p_readonly;
+
+                       if ($poste->value != '')
+                       {
+                               $Poste = new Acc_Account($this->db);
+                               $Poste->set_parameter('value', $poste->value);
+                               $label = $Poste->get_lib();
+                       }
+
+                       // Description of the line
+                       $line_desc = new IText();
+                       $line_desc->name = 'ld' . $i;
+                       $line_desc->size = 30;
+                       $line_desc->value = (isset(${"ld" . $i})) ? ${"ld" . 
$i} :
+                                       $label;
+
+                       // Amount
+                       $amount = new INum();
+                       $amount->size = 10;
+                       $amount->name = 'amount' . $i;
+                       $amount->value = (isset(${'amount' . $i})) ? ${"amount" 
. $i} : ''
+                       ;
+                       $amount->readonly = $p_readonly;
+                       $amount->javascript = ' 
onChange="format_number(this);checkTotalDirect()"';
+                       // D/C
+                       $deb = new ICheckBox();
+                       $deb->name = 'ck' . $i;
+                       $deb->selected = (isset(${'ck' . $i})) ? true : false;
+                       $deb->readonly = $p_readonly;
+                       $deb->javascript = ' onChange="checkTotalDirect()"';
+
+                       $ret.='<tr>';
+                       $ret.='<td>' . $quick_code->input() . 
$quick_code->search() . '</td>';
+                       $ret.='<td>' . $poste->input() .
+                                       '<script> 
document.getElementById(\'poste' . $i . '\').onblur=function(){ if 
(trim(this.value) !=\'\') {document.getElementById(\'qc_' . $i . 
'\').value="";}}</script>' .
+                                       '</td>';
+                       $ret.='<td>' . $line_desc->input() . '</td>';
+                       $ret.='<td>' . $amount->input() . '</td>';
+                       $ret.='<td>' . $deb->input() . '</td>';
+                       $ret.='</tr>';
+                       // If readonly == 1 then show CA
+               }
+               $ret.='</table>';
+               if (isset($this->with_concerned) && $this->with_concerned == 
true)
+               {
+                       $oRapt = new Acc_Reconciliation($this->db);
+                       $w = $oRapt->widget();
+                       $w->name = 'jrn_concerned';
+                       $w->value = (isset($jrn_concerned)) ? $jrn_concerned : 
"";
+                       $ret.="R&eacute;conciliation/rapprochements : " . 
$w->input();
+               }
+               $ret.= create_script("$('".$wDate->id."').focus()");
+               return $ret;
+       }
+
+       /**
+        * @brief
+        * check if the current ledger is closed
+        * \return 1 for yes, otherwise 0
+        * \see Periode::is_closed
+        */
+
+       function is_closed($p_periode)
+       {
+               $per = new Periode($this->db);
+               $per->set_jrn($this->id);
+               $per->set_periode($p_periode);
+               $ret = $per->is_closed();
+               return $ret;
+       }
+
+       /**
+        * @brief verify that the operation can be saved
+        * @param$p_array array of data same layout that the $_POST from 
show_form
+        *
+        *
+        * \throw  the getcode  value is 1 incorrect balance,  2 date
+        * invalid, 3 invalid amount,  4 the card is not in the range of
+        * permitted card, 5 not in the user's period, 6 closed period
+        *
+        */
+
+       function verify($p_array)
+       {
+            if (is_array($p_array ) == false || empty($p_array))
+                    throw new Exception ("Array empty");
+        /*
+         * Check needed value
+         */
+        check_parameter($p_array,'p_jrn,e_date');
+        
+               extract($p_array);
+               global $g_user;
+               $tot_cred = 0;
+               $tot_deb = 0;
+               $msg = array();
+
+               /* check if we can write into this ledger */
+               if ($g_user->check_jrn($p_jrn) != 'W')
+                       throw new Exception(_('Accès interdit'), 20);
+
+               /* check for a double reload */
+               if (isset($mt) && $this->db->count_sql('select jr_mt from jrn 
where jr_mt=$1', array($mt)) != 0)
+                       throw new Exception('Double Encodage', 5);
+
+               // Check the periode and the date
+               if (isDate($e_date) == null)
+               {
+                       throw new Exception('Date invalide', 2);
+               }
+               $periode = new Periode($this->db);
+               /* find the periode  if we have enabled the check_periode */
+               if ($this->check_periode() == false)
+               {
+                       $periode->find_periode($e_date);
+               }
+               else
+               {
+                       $periode->p_id = $period;
+                       list ($min, $max) = $periode->get_date_limit();
+                       if (cmpDate($e_date, $min) < 0 ||
+                                       cmpDate($e_date, $max) > 0)
+                               throw new Exception(_('Date et periode ne 
correspondent pas'), 6);
+               }
+
+
+
+               // Periode ferme
+               if ($this->is_closed($periode->p_id) == 1)
+               {
+                       throw new Exception('Periode fermee', 6);
+               }
+               /* check if we are using the strict mode */
+               if ($this->check_strict() == true)
+               {
+                       /* if we use the strict mode, we get the date of the 
last
+                         operation */
+                       $last_date = $this->get_last_date();
+                       if ($last_date != null && cmpDate($e_date, $last_date) 
< 0)
+                               throw new Exception(_('Vous utilisez le mode 
strict la dernière operation est la date du ')
+                                               . $last_date . ' ' . _('vous ne 
pouvez pas encoder à une date antérieure'), 15);
+               }
+
+               for ($i = 0; $i < $nb_item; $i++)
+               {
+                       $err = 0;
+
+                       // Check the balance
+                       if (!isset(${'amount' . $i}))
+                               continue;
+
+                       $amount = round(${'amount' . $i}, 2);
+                       $tot_deb+=(isset(${'ck' . $i})) ? $amount : 0;
+                       $tot_cred+=(!isset(${'ck' . $i})) ? $amount : 0;
+
+                       // Check if the card is permitted
+                       if (isset(${'qc_' . $i}) && trim(${'qc_' . $i}) != "")
+                       {
+                               $f = new Fiche($this->db);
+                               $f->quick_code = ${'qc_' . $i};
+                               if ($f->belong_ledger($p_jrn) < 0)
+                                       throw new Exception("La fiche 
quick_code = " .
+                                                       $f->quick_code . " 
n'est pas dans ce journal", 4);
+                               if (strlen(trim(${'qc_' . $i})) != 0 && 
isNumber(${'amount' . $i}) == 0)
+                                       throw new Exception('Montant invalide', 
3);
+
+                               $strPoste = $f->strAttribut(ATTR_DEF_ACCOUNT);
+                               if ($strPoste == '')
+                                       throw new Exception(sprintf(_("La fiche 
%s n'a pas de poste comptable"), ${"qc_" . $i}));
+
+                               $p = new Acc_Account_Ledger($this->db, 
$strPoste);
+                               if ($p->do_exist() == 0)
+                                       throw new Exception(_('Poste Inexistant 
pour la fiche [' . ${'qc_' . $i} . ']'), 4);
+                       }
+
+                       // Check if the account is permitted
+                       if (isset(${'poste' . $i}) && strlen(trim(${'poste' . 
$i})) != 0)
+                       {
+                               $p = new Acc_Account_Ledger($this->db, 
${'poste' . $i});
+                               if ($p->belong_ledger($p_jrn) < 0)
+                                       throw new Exception(_("Le poste") . " " 
. $p->id . " " . _("n'est pas dans ce journal"), 5);
+                               if (strlen(trim(${'poste' . $i})) != 0 && 
isNumber(${'amount' . $i}) == 0)
+                                       throw new Exception(_('Poste invalide 
[' . ${'poste' . $i} . ']'), 3);
+                               if ($p->do_exist() == 0)
+                                       throw new Exception(_('Poste Inexistant 
[' . ${'poste' . $i} . ']'), 4);
+                               $card_id = $p->find_card();
+                               if (!empty($card_id))
+                               {
+                                       $str_msg = " Le poste " . $p->id . " 
appartient à " . count($card_id) . " fiche(s) dont :";
+                                       $max = (count($card_id) > 
MAX_COMPTE_CARD) ? MAX_COMPTE_CARD : count($card_id);
+                                       for ($x = 0; $x < $max; $x++)
+                                       {
+                                               $card = new Fiche($this->db, 
$card_id[$x]['f_id']);
+                                               
$str_msg.=HtmlInput::card_detail($card->strAttribut(ATTR_DEF_QUICKCODE), 
$card->strAttribut(ATTR_DEF_NAME), 
'style="color:red;display:inline;text-decoration:underline"');
+                                               $str_msg.=" ";
+                                       }
+                                       $msg[] = $str_msg;
+                               }
+                       }
+               }
+               $tot_deb = round($tot_deb, 4);
+               $tot_cred = round($tot_cred, 4);
+               if ($tot_deb != $tot_cred)
+               {
+                       throw new Exception(_("Balance incorrecte ") . " debit 
= $tot_deb credit=$tot_cred ", 1);
+               }
+
+               return $msg;
+       }
+
+       /**
+        * @brief compute the internal code of the saved operation and set the 
$this->jr_internal to
+        *  the computed value
+        *
+        * @param$p_grpt id in jr_grpt_
+        *
+        * \return string internal_code
+        *      -
+        *
+        */
+
+       function compute_internal_code($p_grpt)
+       {
+               if ($this->id == 0)
+                       return;
+               $num = $this->db->get_next_seq('s_internal');
+               $atype = $this->get_propertie();
+               $type = substr($atype['jrn_def_code'], 0, 1);
+               $internal_code = sprintf("%s%06X", $type, $num);
+               $this->jr_internal = $internal_code;
+               return $internal_code;
+       }
+
+       /**
+        * @brief save the operation into the jrnx,jrn, ,
+        *  CA and pre_def
+        * @param$p_array
+        *
+        * \return array with [0] = false if failed otherwise true, [1] error
+        * code
+        */
+
+       function save($p_array = null)
+       {
+               if ($p_array == null)
+                       throw new Exception('save cannot use a empty array');
+               global $g_parameter;
+               extract($p_array);
+               try
+               {
+                       $msg = $this->verify($p_array);
+                       if (!empty($msg))
+                       {
+                               echo $this->display_warning($msg, _("Attention 
: il vaut mieux utiliser les fiches que les postes comptables "));
+                       }
+                       $this->db->start();
+
+                       $seq = $this->db->get_next_seq('s_grpt');
+                       $internal = $this->compute_internal_code($seq);
+
+                       $group = $this->db->get_next_seq("s_oa_group");
+                       $tot_amount = 0;
+                       $tot_deb = 0;
+                       $tot_cred = 0;
+                       $oPeriode = new Periode($this->db);
+                       $check_periode = $this->check_periode();
+                       if ($check_periode == false)
+                       {
+                               $oPeriode->find_periode($e_date);
+                       }
+                       else
+                       {
+                               $oPeriode->id = $period;
+                       }
+
+                       $count = 0;
+                       for ($i = 0; $i < $nb_item; $i++)
+                       {
+                               if (!isset(${'qc_' . $i}) && !isset(${'poste' . 
$i}))
+                                       continue;
+                               $acc_op = new Acc_Operation($this->db);
+                               $quick_code = "";
+                               // First we save the jrnx
+                               if (isset(${'qc_' . $i}))
+                               {
+                                       $qc = new Fiche($this->db);
+                                       $qc->get_by_qcode(${'qc_' . $i}, false);
+                                       $sposte = 
$qc->strAttribut(ATTR_DEF_ACCOUNT);
+                                       /*  if there are 2 accounts take 
following the deb or cred */
+                                       if (strpos($sposte, ',') != 0)
+                                       {
+                                               $array = explode(",", $sposte);
+                                               $poste = (isset(${'ck' . $i})) 
? $array[0] : $array[1];
+                                       }
+                                       else
+                                       {
+                                               $poste = $sposte;
+                                               if ($poste == '')
+                                                       throw new 
Exception(sprintf(_("La fiche %s n'a pas de poste comptable"), ${"qc_" . $i}));
+                                       }
+                                       $quick_code = ${'qc_' . $i};
+                               }
+                               else
+                               {
+                                       $poste = ${'poste' . $i};
+                               }
+
+                               $acc_op->date = $e_date;
+                               // compute the periode is do not check it
+                               if ($check_periode == false)
+                                       $acc_op->periode = $oPeriode->p_id;
+                               $acc_op->desc = null;
+                               if (strlen(trim(${'ld' . $i})) != 0)
+                                       $acc_op->desc = ${'ld' . $i};
+                               $acc_op->amount = round(${'amount' . $i}, 2);
+                               $acc_op->grpt = $seq;
+                               $acc_op->poste = $poste;
+                               $acc_op->jrn = $this->id;
+                               $acc_op->type = (isset(${'ck' . $i})) ? 'd' : 
'c';
+                               $acc_op->qcode = $quick_code;
+                               $j_id = $acc_op->insert_jrnx();
+                               $tot_amount+=round($acc_op->amount, 2);
+                               $tot_deb+=($acc_op->type == 'd') ? 
$acc_op->amount : 0;
+                               $tot_cred+=($acc_op->type == 'c') ? 
$acc_op->amount : 0;
+                               if ($g_parameter->MY_ANALYTIC != "nu")
+                               {
+                                       if (preg_match("/^[6,7]+/", $poste) == 
1)
+                                       {
+
+                                               // for each item, insert into 
operation_analytique */
+                                               $op = new 
Anc_Operation($this->db);
+                                               $op->oa_group = $group;
+                                               $op->j_id = $j_id;
+                                               $op->oa_date = $e_date;
+                                               $op->oa_debit = ($acc_op->type 
== 'd' ) ? 't' : 'f';
+                                               $op->oa_description = $desc;
+                                               $op->save_form_plan($p_array, 
$count, $j_id);
+                                               $count++;
+                                       }
+                               }
+                       }// loop for each item
+                       $acc_end = new Acc_Operation($this->db);
+                       $acc_end->amount = $tot_deb;
+                       if ($check_periode == false)
+                               $acc_end->periode = $oPeriode->p_id;
+                       $acc_end->date = $e_date;
+                       $acc_end->desc = $desc;
+                       $acc_end->grpt = $seq;
+                       $acc_end->jrn = $this->id;
+                       $acc_end->mt = $mt;
+                       $jr_id = $acc_end->insert_jrn();
+                       $this->jr_id = $jr_id;
+                       if ($jr_id == false)
+                               throw new Exception(_('Balance incorrecte'));
+                       $acc_end->pj = $e_pj;
+
+                       /* if e_suggest != e_pj then do not increment sequence 
*/
+                       if (strcmp($e_pj, $e_pj_suggest) == 0 && 
strlen(trim($e_pj)) != 0)
+                       {
+                               $this->inc_seq_pj();
+                       }
+
+                       $this->pj = $acc_end->set_pj();
+
+                       $this->db->exec_sql("update jrn set jr_internal='" . 
$internal . "' where " .
+                                       " jr_grpt_id = " . $seq);
+                       $this->internal = $internal;
+                       // Save now the predef op
+                       //------------------------
+                        if (isset ($opd_name) && trim($opd_name) != "" ){
+                               $opd = new Pre_Op_Advanced($this->db);
+                               $opd->get_post();
+                               $opd->save();
+                       }
+
+                       if (isset($this->with_concerned) && 
$this->with_concerned == true)
+                       {
+                               $orap = new acc_reconciliation($this->db);
+                               $orap->jr_id = $jr_id;
+
+                               $orap->insert($jrn_concerned);
+                       }
+                        /**
+                         * Save the file is any
+                         */
+                        if (isset($_FILES["pj"]))
+                        {
+                            $this->db->save_upload_document($seq);
+                        }
+                       
+               }
+               catch (Exception $a)
+               {
+                       throw $a;
+               }
+               catch (Exception $e)
+               {
+                       $this->db->rollback();
+                       echo _('OPERATION ANNULEE ');
+                       echo '<hr>';
+                       echo __FILE__ . __LINE__ . $e->getMessage();
+                       exit();
+               }
+               $this->db->commit();
+               return true;
+       }
+
+       /**
+        * @brief get all the data from request and build the object
+        */
+
+       function get_request()
+       {
+               $this->id = $_REQUEST['p_jrn'];
+       }
+
+       /**
+        * @brief retrieve the next number for this type of ledger
+        * @paramp_cn connx
+        * @paramp_type ledger type
+        *
+        * \return the number
+        *
+        *
+        */
+
+       static function next_number($p_cn, $p_type)
+       {
+
+               $Ret = $p_cn->count_sql("select * from jrn_def where 
jrn_def_type='" . $p_type . "'");
+               return $Ret + 1;
+       }
+
+       /**
+        * @brief get the first ledger
+        * @paramthe type
+        * \return the j_id
+        */
+
+       public function get_first($p_type, $p_access = 3)
+       {
+               global $g_user;
+               $all = $g_user->get_ledger($p_type, $p_access);
+               return $all[0];
+       }
+
+       /**
+        * @brief Update the paiment  in the list of operation
+        * @param$p_array is normally $_GET
+        */
+
+       function update_paid($p_array)
+       {
+               // reset all the paid flag because the checkbox is post only
+               // when checked
+               foreach ($p_array as $name => $paid)
+               {
+                       list($ad) = sscanf($name, "set_jr_id%d");
+                       if ($ad == null)
+                               continue;
+                       $sql = "update jrn set jr_rapt='' where jr_id=$ad";
+                       $Res = $this->db->exec_sql($sql);
+               }
+               // set a paid flag for the checked box
+               foreach ($p_array as $name => $paid)
+               {
+                       list ($id) = sscanf($name, "rd_paid%d");
+                       if ($id == null)
+                               continue;
+
+                       $sql = "update jrn set jr_rapt='paid' where jr_id=$id";
+                       $Res = $this->db->exec_sql($sql);
+               }
+       }
+
+       function update_internal_code($p_internal)
+       {
+               if (!isset($this->grpt_id))
+                       throw new Exception(('ERREUR ' . __FILE__ . ":" . 
__LINE__));
+               $Res = $this->db->exec_sql("update jrn set jr_internal='" . 
$p_internal . "' where " .
+                               " jr_grpt_id = " . $this->grpt_id);
+       }
+        /**
+         * Return an array of default card for the ledger type given 
+         * 
+         * @param $p_ledger_type VEN ACH ODS or FIN
+         * @param $p_side   D for Debit or C for credit or NA No Applicable
+         */
+        function get_default_card($p_ledger_type,$p_side)
+        {
+            $array=array();
+            $fiche_def_ref=new Fiche_Def_Ref($this->db);
+            // ----- for FINANCIAL  ----
+            if ($p_ledger_type =='FIN')
+            {
+                $array=$fiche_def_ref->get_by_modele(FICHE_TYPE_CLIENT);
+                $array=array_merge ( $array , 
$fiche_def_ref->get_by_modele(FICHE_TYPE_FOURNISSEUR));
+                $array=array_merge ( $array , 
$fiche_def_ref->get_by_modele(FICHE_TYPE_FIN));
+                $array=array_merge ( $array , 
$fiche_def_ref->get_by_modele(FICHE_TYPE_ADM_TAX));
+                $array=array_merge ( $array , 
$fiche_def_ref->get_by_modele(FICHE_TYPE_EMPL));
+                
+            }
+            // --- for miscellaneous ----
+            if ($p_ledger_type == 'ODS')
+            {
+                $result=$this->db->get_array('select fd_id from fiche_def');
+                for ($i = 0;$i<count($result);$i++ )
+                {
+                    $array[$i]=$result[$i]['fd_id'];
+                }
+            }
+            if ($p_side == 'D')
+            {
+                switch($p_ledger_type) 
+                {
+                    case 'VEN':
+                        
$array=$fiche_def_ref->get_by_modele(FICHE_TYPE_CLIENT);
+                        break;
+                    case 'ACH':
+                        
$array=$fiche_def_ref->get_by_modele(FICHE_TYPE_ACH_SER);
+                        $array=array_merge ($array, 
$fiche_def_ref->get_by_modele(FICHE_TYPE_ACH_MAR));
+                        $array=array_merge 
($array,$fiche_def_ref->get_by_modele(FICHE_TYPE_ACH_MAT));
+                        break;
+                    default :
+                        throw new Exception(_('get_default_card p_ledger_side 
is invalide ['.$p_ledger_type.']'));
+                    
+                }
+            } elseif ($p_side == 'C')
+            {
+                 switch($p_ledger_type) 
+                {
+                    case 'VEN':
+                        $array=$fiche_def_ref->get_by_modele(FICHE_TYPE_VENTE);
+                        break;
+                    case 'ACH':
+                        $array=  array_merge($array, 
$fiche_def_ref->get_by_modele(FICHE_TYPE_ADM_TAX));
+                        $array=  array_merge($array, 
$fiche_def_ref->get_by_modele(FICHE_TYPE_FOURNISSEUR));
+                        break;
+                    default :
+                        throw new Exception(_('get_default_card p_ledger_side 
is invalide ['.$p_ledger_type.']'));
+                    
+                }
+            }
+            return $array;
+            /*
+            $return=array();
+            $return = array_values($array);
+            for ($i = 0;$i<count($array);$i++ )
+            {
+                $return[$i]=$array[$i]['fd_id'];
+            }
+            return $return;
+             * 
+             */
+        }
+       /**
+        * @brief retrieve all the card for this type of ledger, make them
+        * into a string separated by comma
+        * @paramnone
+        * \return all the card or null is nothing is found
+        */
+
+       function get_all_fiche_def()
+       {
+               $sql = "select jrn_def_fiche_deb as deb,jrn_def_fiche_cred as 
cred " .
+                               " from jrn_def where " .
+                               " jrn_def_id = $1 ";
+
+               $r = $this->db->exec_sql($sql, array($this->id));
+
+               $res = Database::fetch_all($r);
+               if (empty($res))
+                       return null;
+               $card = "";
+               $comma = '';
+               foreach ($res as $item)
+               {
+                       if (strlen(trim($item['deb'])) != 0)
+                       {
+                               $card.=$comma . $item['deb'];
+                               $comma = ',';
+                       }
+                       if (strlen(trim($item['cred'])) != '')
+                       {
+                               $card.=$comma . $item['cred'];
+                               $comma = ',';
+                       }
+               }
+
+               return $card;
+       }
+
+       /**
+        * @brief get the saldo of an exercice, used for the opening of a folder
+        * @param$p_exercice is the exercice we want
+        * \return an array
+        * index =
+        * - solde (debit > 0 ; credit < 0)
+        * - j_poste
+        * - j_qcode
+        */
+
+       function get_saldo_exercice($p_exercice)
+       {
+               $sql = "select sum(a.montant) as solde, j_poste, j_qcode
+             from
+             (select j_id, case when j_debit='t' then j_montant
+             else j_montant * (-1) end  as montant
+             from jrnx) as a
+             join jrnx using (j_id)
+             join parm_periode on (j_tech_per = p_id )
+             where
+             p_exercice=$1
+             and j_poste::text not like '7%'
+             and j_poste::text not like '6%'
+             group by j_poste,j_qcode
+             having (sum(a.montant) != 0 )";
+               $res = $this->db->get_array($sql, array($p_exercice));
+               return $res;
+       }
+
+       /**
+        * @brief Check if a Dossier is using the strict mode or not
+        * \return true if we are using the strict_mode
+        */
+
+       function check_strict()
+       {
+               global $g_parameter;
+               if ($g_parameter->MY_STRICT == 'Y')
+                       return true;
+               if ($g_parameter->MY_STRICT == 'N')
+                       return false;
+               throw  new Exception("Valeur invalid " . __FILE__ . ':' . 
__LINE__);
+       }
+
+       /**
+        * @brief Check if a Dossier is using the check on the periode, if true 
than the user has to enter the date
+        * and the periode, it is a security check
+        * \return true if we are using the double encoding (date+periode)
+        */
+
+       function check_periode()
+       {
+               global $g_parameter;
+               if ($g_parameter->MY_CHECK_PERIODE == 'Y')
+                       return true;
+               if ($g_parameter->MY_CHECK_PERIODE == 'N')
+                       return false;
+               throw  new Exception("Valeur invalid " . __FILE__ . ':' . 
__LINE__);
+       }
+
+       /**
+        * @brief get the date of the last operation
+        */
+
+       function get_last_date()
+       {
+               if ($this->id == 0)
+                       throw new Exception(__FILE__ . ":" . __LINE__ . 
"Journal incorrect ");
+               $sql = "select to_char(max(jr_date),'DD.MM.YYYY') from jrn 
where jr_def_id=$1";
+               $date = $this->db->get_value($sql, array($this->id));
+               return $date;
+       }
+
+       /**
+        * @brief retrieve the jr_id thanks the internal code, do not change
+        * anything to the current object
+        * @paramthe internal code
+        * \return the jr_id or 0 if not found
+        */
+
+       function get_id($p_internal)
+       {
+               $sql = 'select jr_id from jrn where jr_internal=$1';
+               $value = $this->db->get_value($sql, array($p_internal));
+               if ($value == '')
+                       $value = 0;
+               return $value;
+       }
+
+       /**
+        * @brief create the invoice and saved it as attachment to the
+        * operation,
+        * @param$internal is the internal code
+        * @param$p_array is normally the $_POST
+        * \return a string
+        */
+
+       function create_document($internal, $p_array)
+       {
+               extract($p_array);
+               $doc = new Document($this->db);
+               $doc->f_id = $e_client;
+               $doc->md_id = $gen_doc;
+               $doc->ag_id = 0;
+                $p_array['e_pj']=$this->pj;
+               $filename="";
+               $doc->Generate($p_array,$p_array['e_pj']);
+               // Move the document to the jrn
+               $doc->MoveDocumentPj($internal);
+               // Update the comment with invoice number, if the comment is 
empty
+               if (!isset($e_comm) || strlen(trim($e_comm)) == 0)
+               {
+                       $sql = "update jrn set jr_comment=' document " . 
$doc->d_number . "' where jr_internal='$internal'";
+                       $this->db->exec_sql($sql);
+               }
+               return h($doc->d_name . ' (' . $doc->d_filename . ')');
+       }
+
+       /**
+        * @brief check if the payment method is valid
+        * @param$e_mp is the value and $e_mp_qcode is the quickcode
+        * \return nothing throw an Exception
+        */
+
+       public function check_payment($e_mp, $e_mp_qcode)
+       {
+               /*   Check if the "paid by" is empty, */
+               if ($e_mp != 0)
+               {
+                       /* the paid by is not empty then check if valid */
+                       $empl = new Fiche($this->db);
+                       $empl->get_by_qcode($e_mp_qcode);
+                       if ($empl->empty_attribute(ATTR_DEF_ACCOUNT) == true)
+                       {
+                               throw new Exception(_("Celui qui paie n' a pas 
de poste comptable"), 20);
+                       }
+                       /* get the account and explode if necessary */
+                       $sposte = $empl->strAttribut(ATTR_DEF_ACCOUNT);
+                       // if 2 accounts, take only the debit one for customer
+                       if (strpos($sposte, ',') != 0)
+                       {
+                               $array = explode(',', $sposte);
+                               $poste_val = $array[0];
+                       }
+                       else
+                       {
+                               $poste_val = $sposte;
+                       }
+                       $poste = new Acc_Account_Ledger($this->db, $poste_val);
+                       if ($poste->load() == false)
+                       {
+                               throw new Exception(sprintf(_("Pour la fiche %s 
le poste comptable [%s] n'existe pas"),$empl->quick_code,$poste->id  ), 9);
+                       }
+               }
+       }
+
+       /**
+        * @brief increment the sequence for the pj */
+
+       function inc_seq_pj()
+       {
+               $sql = "select nextval('s_jrn_pj" . $this->id . "')";
+               $this->db->exec_sql($sql);
+       }
+
+       /**
+        * @brief return a HTML string with the form for the search
+        * @param $p_type if the type of ledger possible 
values=ALL,VEN,ACH,ODS,FIN
+        * @param $all_type_ledger
+        *       values :
+        *         - 1 means all the ledger of this type
+        *         - 0 No have the "Tous les journaux" availables
+        * @param $div is the div (for reconciliation)
+        * @return a HTML String without the tag FORM or DIV
+        *
+        * @see build_search_sql
+        * @see display_search_form
+        * @see list_operation
+        */
+
+       function search_form($p_type, $all_type_ledger = 1, $div = "")
+       {
+            global $g_user;
+            $r="";
+                $bledger_param=  json_encode(array(
+                    'dossier'=>$_REQUEST['gDossier'],
+                    'type'=>$p_type,
+                    'all_type'=>$all_type_ledger,
+                    'div'=>$div
+                    ));
+                
+                $bledger_param=  str_replace('"', "'", $bledger_param);
+                $bledger=new ISmallButton('l');
+                $bledger->label=_("choix des journaux");
+                $bledger->javascript=" show_ledger_choice($bledger_param)";
+                $f_ledger=$bledger->input();
+                $hid_jrn="";
+                if ( isset ($_REQUEST[$div.'nb_jrn']) ){
+                    for ($i=0;$i < $_REQUEST[$div.'nb_jrn'];$i++) {
+                        if ( isset ($_REQUEST[$div."r_jrn"][$i]))
+                            
$hid_jrn.=HtmlInput::hidden($div.'r_jrn['.$i.']',$_REQUEST[$div."r_jrn"][$i]);
+                    }
+                    
$hid_jrn.=HtmlInput::hidden($div.'nb_jrn',$_REQUEST[$div.'nb_jrn']);
+                } else {
+                    $hid_jrn=HtmlInput::hidden($div.'nb_jrn',0);
+                }
+                /* Compute date for exercice */
+                $period = $g_user->get_periode();
+                $per = new Periode($this->db, $period);
+               $exercice = $per->get_exercice();
+               list($per_start, $per_end) = $per->get_limit($exercice);
+               $date_end = $per_end->last_day();
+                $date_start=$per_start->first_day();
+                        
+               /* widget for date_start */
+               $f_date_start = new IDate('date_start');
+               /* all periode or only the selected one */
+               if (isset($_REQUEST['date_start']))
+               {
+                       $f_date_start->value = $_REQUEST['date_start'];
+               }
+               else
+               {
+                        $f_date_start->value=$date_start;
+               }
+
+               /* widget for date_end */
+               $f_date_end = new IDate('date_end');
+               /* all date or only the selected one */
+               if (isset($_REQUEST['date_end']))
+               {
+                       $f_date_end->value = $_REQUEST['date_end'];
+               }
+               else
+               {
+                       $f_date_end->value = $date_end;
+               }
+                /* widget for date term */
+                $f_date_paid_start=new IDate('date_paid_start');
+                $f_date_paid_end=new IDate('date_paid_end');
+                
+                
$f_date_paid_start->value=(isset($_REQUEST['date_paid_start']))?$_REQUEST['date_paid_start']:'';
+                
$f_date_paid_end->value=(isset($_REQUEST['date_paid_end']))?$_REQUEST['date_paid_end']:'';
+                
+               /* widget for desc */
+               $f_descript = new IText('desc');
+               $f_descript->size = 40;
+               if (isset($_REQUEST['desc']))
+               {
+                       $f_descript->value = $_REQUEST['desc'];
+               }
+
+               /* widget for amount */
+               $f_amount_min = new INum('amount_min');
+               $f_amount_min->value = (isset($_REQUEST['amount_min'])) ? 
abs($_REQUEST['amount_min']) : 0;
+               $f_amount_max = new INum('amount_max');
+               $f_amount_max->value = (isset($_REQUEST['amount_max'])) ? 
abs($_REQUEST['amount_max']) : 0;
+
+               /* input quick code */
+               $f_qcode = new ICard('qcode' . $div);
+
+               $f_qcode->set_attribute('typecard', 'all');
+               /*        $f_qcode->set_attribute('p_jrn','0');
+
+                 $f_qcode->set_callback('filter_card');
+                */
+               $f_qcode->set_dblclick("fill_ipopcard(this);");
+               // Add the callback function to filter the card on the jrn
+               //$f_qcode->set_callback('filter_card');
+               $f_qcode->set_function('fill_data');
+               $f_qcode->javascript = sprintf(' 
onchange="fill_data_onchange(%s);" ', $f_qcode->name);
+               $f_qcode->value = (isset($_REQUEST['qcode' . $div])) ? 
$_REQUEST['qcode' . $div] : '';
+
+               /*        $f_txt_qcode=new IText('qcode');
+                 
$f_txt_qcode->value=(isset($_REQUEST['qcode']))?$_REQUEST['qcode']:'';
+                */
+
+               /* input poste comptable */
+               $f_accounting = new IPoste('accounting');
+               $f_accounting->value = (isset($_REQUEST['accounting'])) ? 
$_REQUEST['accounting'] : '';
+               if ($this->id == -1)
+                       $jrn = 0;
+               else
+                       $jrn = $this->id;
+               $f_accounting->set_attribute('jrn', $jrn);
+               $f_accounting->set_attribute('ipopup', 'ipop_account');
+               $f_accounting->set_attribute('label', 'ld');
+               $f_accounting->set_attribute('account', 'accounting');
+               $info = HtmlInput::infobulle(13);
+
+               $f_paid = new ICheckbox('unpaid');
+               $f_paid->selected = (isset($_REQUEST['unpaid'])) ? true : false;
+
+               $r.=dossier::hidden();
+               $r.=HtmlInput::hidden('ledger_type', $this->type);
+               $r.=HtmlInput::hidden('ac', $_REQUEST['ac']);
+               ob_start();
+               require_once NOALYSS_INCLUDE.'/template/ledger_search.php';
+               $r.=ob_get_contents();
+               ob_end_clean();
+               return $r;
+       }
+
+       /**
+        * @brief this function will create a sql stmt to use to create the 
list for
+        * the ledger,
+        * @param$p_array is usually the $_GET,
+        * @param$p_order the order of the row
+        * @param$p_where is the sql condition if not null then the $p_array 
will not be used
+        * \note the p_action will be used to filter the ledger but gl means ALL
+        * struct array $p_array
+         \verbatim
+         (
+         [gDossier] => 13
+         [p_jrn] => -1
+         [date_start] =>
+         [date_end] =>
+         [amount_min] => 0
+         [amount_max] => 0
+         [desc] =>
+         [search] => Rechercher
+         [p_action] => ven
+         [sa] => l
+         )
+         \endverbatim
+        * \return an array with a valid sql statement, an the where clause => 
array[sql] array[where]
+        * \see list_operation
+        * \see display_search_form
+        * \see search_form
+        */
+
+       public function build_search_sql($p_array, $p_order = "", $p_where = "")
+       {
+               $sql = "select jr_id    ,
+             jr_montant,
+             substr(jr_comment,1,60) as jr_comment,
+             to_char(jr_ech,'DD.MM.YY') as str_jr_ech,
+             to_char(jr_date,'DD.MM.YY') as str_jr_date,
+             jr_date as jr_date_order,
+             jr_grpt_id,
+             jr_rapt,
+             jr_internal,
+             jrn_def_id,
+             jrn_def_name,
+             jrn_def_ech,
+             jrn_def_type,
+             jr_valid,
+             jr_tech_per,
+             jr_pj_name,
+             p_closed,
+             jr_pj_number,
+             n_text,
+            case
+            when jrn_def_type='VEN' then
+                (select ad_value from fiche_detail where ad_id=1
+                and f_id=(select max(qs_client) from quant_sold join jrnx 
using (j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))
+           when jrn_def_type = 'ACH' then
+               (select ad_value from fiche_detail where ad_id=1
+               and f_id=(select max(qp_supplier) from quant_purchase join jrnx 
using (j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))
+           when jrn_def_type = 'FIN' then
+               (select ad_value from fiche_detail where ad_id=1
+               and f_id=(select qf_other from quant_fin where 
quant_fin.jr_id=x.jr_id))
+           end as name,
+          case
+            when jrn_def_type='VEN' then (select ad_value from fiche_detail 
where ad_id=32 and f_id=(select max(qs_client) from quant_sold join jrnx using 
(j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))
+           when jrn_def_type = 'ACH' then (select ad_value from fiche_detail 
where ad_id=32 and f_id=(select max(qp_supplier) from quant_purchase join jrnx 
using (j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))
+           when jrn_def_type = 'FIN' then (select ad_value from fiche_detail 
where ad_id=32 and f_id=(select qf_other from quant_fin where 
quant_fin.jr_id=x.jr_id))
+           end as first_name,
+           case
+            when jrn_def_type='VEN' then (select ad_value from fiche_detail 
where ad_id=23 and f_id=(select max(qs_client) from quant_sold join jrnx using 
(j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))
+           when jrn_def_type = 'ACH' then (select ad_value from fiche_detail 
where ad_id=23 and f_id=(select max(qp_supplier) from quant_purchase join jrnx 
using (j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))
+           when jrn_def_type = 'FIN' then (select ad_value from fiche_detail 
where ad_id=23 and f_id=(select qf_other from quant_fin where 
quant_fin.jr_id=x.jr_id))
+           end as quick_code,
+           case
+            when jrn_def_type='VEN' then
+                    (select sum(qs_price)+sum(vat) from
+                               (select qs_internal,qs_price,case when 
qs_vat_sided<>0 then 0 else qs_vat end as vat from quant_sold where 
qs_internal=X.jr_internal) as ven_invoice
+                         )
+           when jrn_def_type = 'ACH' then
+                       (
+                               select 
sum(qp_price)+sum(vat)+sum(qp_nd_tva)+sum(qp_nd_tva_recup)
+                               from
+                                (select 
qp_internal,qp_price,qp_nd_tva,qp_nd_tva_recup,qp_vat-qp_vat_sided as vat from 
quant_purchase where qp_internal=X.jr_internal) as invoice_purchase
+                       )
+               else null
+               end as total_invoice,
+            jr_date_paid,
+            to_char(jr_date_paid,'DD.MM.YY') as str_jr_date_paid
+             from
+             jrn as X left join jrn_note using(jr_id)
+             join jrn_def on jrn_def_id=jr_def_id
+             join parm_periode on p_id=jr_tech_per";
+
+               if (!empty($p_array))
+                       extract($p_array);
+
+                if (isset($op) ) 
+                    $r_jrn = (isset(${$op."r_jrn"})) ? ${$op."r_jrn"} : -1;
+                else
+                {
+                    $r_jrn = (isset($r_jrn)) ? $r_jrn : -1;
+                    
+                }
+
+               /* if no variable are set then give them a default
+                * value */
+               if ($p_array == null || empty($p_array) || !isset($amount_min))
+               {
+                       $amount_min = 0;
+                       $amount_max = 0;
+
+                       $desc = '';
+                       $qcode = (isset($qcode)) ? $qcode : "";
+                       if (isset($qcodesearch_op))
+                               $qcode = $qcodesearch_op;
+                       $accounting = (isset($accounting)) ? $accounting : "";
+                       $periode = new Periode($this->db);
+                       $g_user = new User($this->db);
+                       $p_id = $g_user->get_periode();
+                       if ($p_id != null)
+                       {
+                               list($date_start, $date_end) = 
$periode->get_date_limit($p_id);
+                       }
+               }
+
+               /* if p_jrn : 0 if means all ledgers, if -1 means all ledger of 
this
+                *  type otherwise only one ledger */
+               $fil_ledger = '';
+               $fil_amount = '';
+               $fil_date = '';
+               $fil_desc = '';
+               $fil_sec = '';
+               $fil_qcode = '';
+               $fil_account = '';
+               $fil_paid = '';
+                $fil_date_paid='';
+
+               $and = '';
+               $g_user = new User($this->db);
+               $p_action = $ledger_type;
+               if ($p_action == '')
+                       $p_action = 'ALL';
+               if ($r_jrn == -1)
+               {
+
+                       /* from compta.php the p_action is quick_writing 
instead of ODS  */
+                       if ($p_action == 'quick_writing')
+                               $p_action = 'ODS';
+
+
+                       $fil_ledger = $g_user->get_ledger_sql($p_action, 3);
+                       $and = ' and ';
+               }
+               else
+               {
+
+                       if ($p_action == 'quick_writing')
+                               $p_action = 'ODS';
+
+                       $aLedger = $g_user->get_ledger($p_action, 3);
+                       $fil_ledger = '';
+                       $sp = '';
+                       for ($i = 0; $i < count($r_jrn); $i++)
+                       {
+                                if (isset($r_jrn[$i]) )
+                               {
+                                    $a=$r_jrn[$i];
+                                   $fil_ledger.=$sp . $a;
+                                    $sp = ',';
+                               }
+                       }
+                       $fil_ledger = ' jrn_def_id in (' . $fil_ledger . ')';
+                       $and = ' and ';
+
+                       /* no ledger selected */
+                       if ($sp == '')
+                       {
+                               $fil_ledger = '';
+                               $and = '';
+                       }
+               }
+
+               /* format the number */
+               $amount_min = abs(toNumber($amount_min));
+               $amount_max = abs(toNumber($amount_max));
+               if ($amount_min > 0 && isNumber($amount_min))
+               {
+                       $fil_amount = $and . ' jr_montant >=' . $amount_min;
+                       $and = ' and ';
+               }
+               if ($amount_max > 0 && isNumber($amount_max))
+               {
+                       $fil_amount.=$and . ' jr_montant <=' . $amount_max;
+                       $and = ' and ';
+               }
+               /* 
-------------------------------------------------------------------------- *
+                * if both amount are the same then we need to search into the 
detail
+                * and we reset the fil_amount
+                * 
-------------------------------------------------------------------------- */
+               if (isNumber($amount_min) &&
+                               isNumber($amount_max) &&
+                               $amount_min > 0 &&
+                               bccomp($amount_min, $amount_max, 2) == 0)
+               {
+                        $fil_amount = $and . ' ( ';
+ 
+                        // Look in detail
+                       $fil_amount .= 'jr_grpt_id in ( select distinct j_grpt 
from jrnx where j_montant = ' . $amount_min . ') ';
+
+                       //and the total operation
+                       $fil_amount .= ' or ';
+                       $fil_amount .= ' jr_montant = '.$amount_min;
+
+                      $fil_amount .= ')';
+                      $and = " and ";
+               }
+               // date
+               if (isset($date_start) && isDate($date_start) != null)
+               {
+                       $fil_date = $and . " jr_date >= to_date('" . 
$date_start . "','DD.MM.YYYY')";
+                       $and = " and ";
+               }
+               if (isset($date_end) && isDate($date_end) != null)
+               {
+                       $fil_date.=$and . " jr_date <= to_date('" . $date_end . 
"','DD.MM.YYYY')";
+                       $and = " and ";
+               }
+               // date paiement
+               if (isset($date_paid_start) && isDate($date_paid_start) != null)
+               {
+                       $fil_date_paid = $and . " jr_date_paid >= to_date('" . 
$date_paid_start . "','DD.MM.YYYY')";
+                       $and = " and ";
+               }
+               if (isset($date_paid_end) && isDate($date_paid_end) != null)
+               {
+                       $fil_date_paid.=$and . " jr_date_paid <= to_date('" . 
$date_paid_end . "','DD.MM.YYYY')";
+                       $and = " and ";
+               }
+               // comment
+               if (isset($desc) && $desc != null)
+               {
+                       $desc = sql_string($desc);
+                       $fil_desc = $and . " ( upper(jr_comment) like upper('%" 
. $desc . "%') or upper(jr_pj_number) like upper('%" . $desc . "%') " .
+                                       " or upper(jr_internal)  like upper('%" 
. $desc . "%')
+                          or jr_grpt_id in (select j_grpt from jrnx where 
j_text ~* '" . $desc . "')
+                          or jr_id in (select jr_id from jrn_info where 
ji_value is not null and ji_value ~* '$desc')
+                          )";
+                       $and = " and ";
+               }
+               //    Poste
+               if (isset($accounting) && $accounting != null)
+               {
+                       $fil_account = $and . "  jr_grpt_id in (select j_grpt
+                         from jrnx where j_poste::text like '" . 
sql_string($accounting) . "%' )  ";
+                       $and = " and ";
+               }
+               // Quick Code
+               if (isset($qcodesearch_op))
+                       $qcode = $qcodesearch_op;
+               if (isset($qcode) && $qcode != null)
+               {
+                       $fil_qcode = $and . "  jr_grpt_id in ( select j_grpt 
from
+                       jrnx where trim(j_qcode) = upper(trim('" . 
sql_string($qcode) . "')))";
+                       $and = " and ";
+               }
+
+               // Only the unpaid
+               if (isset($unpaid))
+               {
+                       $fil_paid = $and . SQL_LIST_UNPAID_INVOICE;
+                       $and = " and ";
+               }
+
+               $g_user = new User(new Database());
+               $g_user->Check();
+               $g_user->check_dossier(dossier::id());
+
+               if ($g_user->admin == 0 && $g_user->is_local_admin() == 0)
+               {
+                       $fil_sec = $and . " jr_def_id in ( select uj_jrn_id " .
+                                       " from user_sec_jrn where " .
+                                       " uj_login='" . $_SESSION['g_user'] . 
"'" .
+                                       " and uj_priv in ('R','W'))";
+               }
+               $where = $fil_ledger . $fil_amount . $fil_date . $fil_desc . 
$fil_sec . $fil_amount . $fil_qcode . $fil_paid . $fil_account.$fil_date_paid;
+               $sql.=" where " . $where;
+               return array($sql, $where);
+       }
+
+       /**
+        * @brief return a html string with the search_form
+        * \return a HTML string with the FORM
+        * \see build_search_sql
+        * \see search_form
+        * \see list_operation
+        */
+
+       function display_search_form()
+       {
+               $r = '';
+               $type = $this->type;
+
+               if ($type == "")
+                       $type = 'ALL';
+               $r.='<div id="search_form" style="display:none">';
+               $r.=HtmlInput::anchor_hide('&#10761;', 
'$(\'search_form\').style.display=\'none\';');
+               $r.=h2('Recherche','class="title"');
+               $r.='<FORM METHOD="GET">';
+               $r.=$this->search_form($type);
+               $r.=HtmlInput::submit('search', _('Rechercher'));
+               $r.=HtmlInput::hidden('ac', $_REQUEST['ac']);
+
+               /*  when called from commercial.php some hidden values are 
needed */
+               if (isset($_REQUEST['sa']))
+                       $r.= HtmlInput::hidden("sa", $_REQUEST['sa']);
+               if (isset($_REQUEST['sb']))
+                       $r.= HtmlInput::hidden("sb", $_REQUEST['sb']);
+               if (isset($_REQUEST['sc']))
+                       $r.= HtmlInput::hidden("sc", $_REQUEST['sc']);
+               if (isset($_REQUEST['f_id']))
+                       $r.=HtmlInput::hidden("f_id", $_REQUEST['f_id']);
+
+               $r.='</FORM>';
+
+               $r.='</div>';
+               $button = new IButton('tfs');
+               $button->label = _("Filtrer");
+               $button->javascript = "toggleHideShow('search_form','tfs');";
+
+               $r.=$button->input();
+               return $r;
+       }
+
+       /**
+        * @brief return the last p_limit operation into an array
+        * @param$p_limit is the max of operation to return
+        * \return $p_array of Follow_Up object
+        */
+
+       function get_last($p_limit)
+       {
+               global $g_user;
+               $filter_ledger = $g_user->get_ledger_sql('ALL', 3);
+               $filter_ledger = str_replace('jrn_def_id', 'jr_def_id', 
$filter_ledger);
+               $sql = "
+                       select 
jr_id,jr_pj_number,jr_date,to_char(jr_date,'DD.MM.YYYY') as 
jr_date_fmt,jr_montant, jr_comment,jr_internal,jrn_def_code
+                       from jrn
+                       join jrn_def on (jrn_def_id=jr_def_id)
+                        where $filter_ledger
+                       order by jr_date desc , 
substring(jr_pj_number,'[0-9]+$')::numeric desc limit $p_limit";
+               $array = $this->db->get_array($sql);
+               return $array;
+       }
+
+       /**
+        * @brief retreive the jr_grpt_id from a ledger
+        * @param $p_what the column to seek
+        *    possible values are
+        *   - internal
+        * @param $p_value the value of the col.
+        */
+       function search_group($p_what, $p_value)
+       {
+               switch ($p_what)
+               {
+                       case 'internal':
+                               return $this->db->get_value('select jr_grpt_id 
from jrn where jr_internal=$1', array($p_value));
+               }
+       }
+
+       /**
+        * @brief retrieve operation from  jrn
+        * @param $p_from periode (id)
+        * @param $p_to periode (id)
+        * @return an array
+        */
+       function get_operation($p_from, $p_to)
+       {
+               global $g_user;
+               $jrn = ($this->id == 0) ? 'and ' . $g_user->get_ledger_sql() : 
' and jr_def_id = ' . $this->id;
+               $sql = "select jr_id as id ,jr_internal as internal, " .
+                               "jr_pj_number as pj,jr_grpt_id," .
+                               " to_char(jr_date,'DDMMYY') as date_fmt, " .
+                               " jr_comment as comment, jr_montant as montant 
," .
+                               " jr_grpt_id,jr_def_id" .
+                               " from jrn join jrn_def on 
(jr_def_id=jrn_def_id) where  " .
+                               " jr_date >= (select p_start from parm_periode 
where p_id = $1)
+                                and  jr_date <= (select p_end from 
parm_periode where p_id  = $2)" .
+                               '  ' . $jrn . ' order by 
jr_date,substring(jr_pj_number,\'[0-9]+$\')::numeric asc';
+               $ret = $this->db->get_array($sql, array($p_from, $p_to));
+               return $ret;
+       }
+
+       /**
+        * @brief return the used VAT code with a rate > 0
+        * @return an array of tva_id,tva_label,tva_poste
+        */
+       public function existing_vat()
+       {
+               if ($this->type == 'ACH')
+               {
+                       $array = $this->db->get_array("select 
tva_id,tva_label,tva_poste from tva_rate where tva_rate != 0.0000 " .
+                                       " and  exists (select qp_vat_code from 
quant_purchase
+                                        where  qp_vat_code=tva_id and  exists 
(select j_id from jrnx where j_jrn_def = $1)) order by tva_id", 
array($this->id));
+               }
+               if ($this->type == 'VEN')
+               {
+                       $array = $this->db->get_array("select 
tva_id,tva_label,tva_poste from tva_rate where tva_rate != 0.0000 " .
+                                       " and  exists (select qs_vat_code from 
quant_sold
+                                        where  qs_vat_code=tva_id and  exists 
(select j_id from jrnx where j_jrn_def = $1)) order by tva_id", 
array($this->id));
+               }
+               return $array;
+       }
+
+       /**
+        * @brief get the amount of vat for a given jr_grpt_id from the table
+        * quant_purchase
+        * @param the jr_grpt_id
+        * @return array price=htva, [1] =  vat,
+        * @note
+        * @see
+         @code
+         array
+         'price' => string '91.3500' (length=7)
+         'vat' => string '0.0000' (length=6)
+         'priv' => string '0.0000' (length=6)
+         'tva_nd_recup' => string '0.0000' (length=6)
+
+         @endcode
+        */
+       function get_other_amount($p_jr_id)
+       {
+               if ($this->type == 'ACH')
+               {
+                       $array = $this->db->get_array('select sum(qp_price) as 
price,sum(qp_vat) as vat ' .
+                                       
',sum(coalesce(qp_nd_amount,0)+coalesce(qp_dep_priv,0)) as priv' .
+                                       
',sum(coalesce(qp_nd_tva_recup,0)+coalesce(qp_nd_tva,0)) as tva_nd' .
+                                       ',sum(qp_vat_sided)  as tva_np' .
+                                       '  from quant_purchase join jrnx 
using(j_id)
+                                        where  j_grpt=$1 ', array($p_jr_id));
+                       $ret = $array[0];
+               }
+               if ($this->type == 'VEN')
+               {
+                       $array = $this->db->get_array('select sum(qs_price) as 
price,sum(qs_vat) as vat ' .
+                                       ',0 as priv' .
+                                       ',0 as tva_nd' .
+                                        ',sum(qs_vat_sided)  as tva_np' .
+                                       '  from quant_sold join jrnx using(j_id)
+                                        where  j_grpt=$1 ', array($p_jr_id));
+                       $ret = $array[0];
+               }
+               return $ret;
+       }
+
+       /**
+        * @brief get the amount of vat for a given jr_grpt_id from the table
+        * quant_purchase
+        * @param the jr_grpt_id
+        * @return array of sum_vat, tva_label
+        * @note
+        * @see
+         @code
+
+         @endcode
+        */
+       function vat_operation($p_jr_id)
+       {
+               if ($this->type == 'ACH')
+               {
+                       $array = $this->db->get_array('select 
coalesce(sum(qp_vat),0) as sum_vat,tva_id
+                                        from quant_purchase as p right join 
tva_rate on (qp_vat_code=tva_id)  join jrnx using(j_id)
+                                        where tva_rate !=0.0 and j_grpt=$1 
group by tva_id', array($p_jr_id));
+               }
+               if ($this->type == 'VEN')
+               {
+                       $array = $this->db->get_array('select 
coalesce(sum(qs_vat),0) as sum_vat,tva_id
+                                        from quant_sold as p right join 
tva_rate on (qs_vat_code=tva_id)  join jrnx using(j_id)
+                                        where tva_rate !=0.0 and j_grpt=$1 
group by tva_id', array($p_jr_id));
+               }
+               return $array;
+       }
+
+       /**
+        * @brief retrieve amount of previous periode
+        * @param $p_to frmo the start of the exercise until $p_to
+        * @return $array with vat, price,other_amount
+        * @note
+        * @see
+         @code
+         array
+         'price' => string '446.1900' (length=8)
+         'vat' => string '21.7600' (length=7)
+         'priv' => string '0.0000' (length=6)
+         'tva_nd_recup' => string '0.0000' (length=6)
+         'tva' =>
+         array
+         0 =>
+         array
+         'sum_vat' => string '13.7200' (length=7)
+         'tva_id' => string '1' (length=1)
+         1 =>
+         array
+         'sum_vat' => string '8.0400' (length=6)
+         'tva_id' => string '3' (length=1)
+         2 =>
+         array
+         'sum_vat' => string '0.0000' (length=6)
+         'tva_id' => string '4' (length=1)
+
+         @endcode
+        */
+       function previous_amount($p_to)
+       {
+               /* get the first periode of exercise */
+               $periode = new Periode($this->db, $p_to);
+               $exercise = $periode->get_exercice();
+               list ($min, $max) = $periode->get_limit($exercise);
+                // transform min into date
+                $min_date=$min->first_day();
+                // transform $p_to  into date
+                $periode_max=new Periode($this->db,$p_to);
+                $max_date=$periode_max->first_day();
+                bcscale(2);
+               // min periode
+               if ($this->type == 'ACH')
+               {
+                       /*  get all amount exclude vat */
+                       $sql = "select coalesce(sum(qp_price),0) as price" .
+                                       " ,coalesce(sum(qp_vat),0) as vat " .
+                                       ',coalesce(sum(qp_dep_priv),0) as priv' 
.
+                                       ',coalesce(sum(qp_vat_sided),0) as 
reversed' .
+                                       
',coalesce(sum(qp_nd_tva_recup),0)+coalesce(sum(qp_nd_tva),0) as tva_nd' .
+                                       ',coalesce(sum(qp_vat_sided),0) as 
tva_np' .
+                                       '  from quant_purchase join jrnx 
using(j_id) ' .
+                                       " where j_date >= 
to_date($1,'DD.MM.YYYY') and j_date < to_date($2,'DD.MM.YYYY') ".
+                                ' and j_jrn_def = $3';
+                       $array = $this->db->get_array($sql, array($min_date, 
$max_date,$this->id));
+
+                       $ret = $array[0];
+                       /* retrieve all vat code */
+                       $array = $this->db->get_array("select 
coalesce(sum(qp_vat),0) as sum_vat,tva_id
+                                        from quant_purchase as p right join 
tva_rate on (qp_vat_code=tva_id)  join jrnx using(j_id)
+                                        where tva_rate !=0 and  j_date >= 
to_date($1,'DD.MM.YYYY') and j_date < to_date($2,'DD.MM.YYYY') 
+                                        and j_jrn_def = $3
+                                        group by tva_id", 
+                                array($min_date, $max_date,$this->id));
+                       $ret['tva'] = $array;
+               }
+               if ($this->type == 'VEN')
+               {
+                       /*  get all amount exclude vat */
+                       $sql = "select coalesce(sum(qs_price),0) as price" .
+                                       " ,coalesce(sum(qs_vat),0) as vat " .
+                                       ',0 as priv' .
+                                       ',0 as tva_nd' .
+                                        ',coalesce(sum(qs_vat_sided),0) as 
tva_np' .
+                                       '  from quant_sold join jrnx 
using(j_id) ' .
+                                       " where j_date >= 
to_date($1,'DD.MM.YYYY') and j_date < to_date($2,'DD.MM.YYYY') ".
+                                ' and j_jrn_def = $3';
+                       $array = $this->db->get_array($sql, array($min_date, 
$max_date,$this->id));
+                       $ret = $array[0];
+                       /* retrieve all vat code */
+                       $array = $this->db->get_array("select 
coalesce(sum(qs_vat),0) as sum_vat,tva_id
+                                        from quant_sold as p right join 
tva_rate on (qs_vat_code=tva_id)  join jrnx using(j_id)
+                                        where tva_rate !=0 and
+                                        j_date >= to_date($1,'DD.MM.YYYY') and 
j_date < to_date($2,'DD.MM.YYYY') 
+                                        and j_jrn_def = $3
+                                        group by tva_id", array($min_date, 
$max_date,$this->id));
+                       $ret['tva'] = $array;
+               }
+                if ($this->type=="FIN") 
+                {
+                        
+                    /* find the quick code of this ledger */
+                    $ledger=new Acc_Ledger_Fin($this->db,$this->id);
+                    $qcode=$ledger->get_bank();
+                    $bank_card=new Fiche($this->db,$qcode);
+                    
+                    /*add the amount from Opening Writing                  */
+                    $cond=sprintf(" j_jrn_def <> %d  and j_date >= 
to_date('%s','DD.MM.YYYY') and j_date < to_date('%s','DD.MM.YYYY') 
",$this->id,$min_date,$max_date);
+                    $saldo = $bank_card->get_bk_balance ($cond);
+                    $ret['amount']=bcsub($saldo['debit'],$saldo['credit']);
+                }
+               return $ret;
+       }
+
+       
////////////////////////////////////////////////////////////////////////////////
+       // TEST MODULE
+       
////////////////////////////////////////////////////////////////////////////////
+       /**
+        * @brief this function is intended to test this class
+        */
+       static function test_me($pCase = '')
+       {
+               if ($pCase == '')
+               {
+                       echo Acc_Reconciliation::$javascript;
+                       html_page_start();
+                       $cn = new Database(dossier::id());
+                       $_SESSION['g_user'] = 'phpcompta';
+                       $_SESSION['g_pass'] = 'phpcompta';
+
+                       $id = (isset($_REQUEST['p_jrn'])) ? $_REQUEST['p_jrn'] 
: -1;
+                       $a = new Acc_Ledger($cn, $id);
+                       $a->with_concerned = true;
+                       // Vide
+                       echo '<FORM method="post">';
+                       echo $a->select_ledger()->input();
+                       echo HtmlInput::submit('go', 'Test it');
+                       echo '</form>';
+                       if (isset($_POST['go']))
+                       {
+                               echo "Ok ";
+                               echo '<form method="post">';
+                               echo $a->show_form();
+                               echo HtmlInput::submit('post_id', 'Try me');
+                               echo '</form>';
+                               // Show the predef operation
+                               // Don't forget the p_jrn
+                               echo '<form>';
+                               echo dossier::hidden();
+                               echo '<input type="hidden" value="' . $id . '" 
name="p_jrn">';
+                               $op = new Pre_operation($cn);
+                               $op->p_jrn = $id;
+                               $op->od_direct = 't';
+                               if ($op->count() != 0)
+                               {
+                                       echo HtmlInput::submit('use_opd', 
'Utilisez une opération pr&eacute;d&eacute;finie',"","smallbutton");
+                                       echo $op->show_button();
+                               }
+                               echo '</form>';
+                               exit('test_me');
+                       }
+
+                       if (isset($_POST['post_id']))
+                       {
+
+                               echo '<form method="post">';
+                               echo $a->show_form($_POST, 1);
+                               echo HtmlInput::button('add', 'Ajout d\'une 
ligne', 'onClick="quick_writing_add_row()"');
+                               echo HtmlInput::submit('save_it', _("Sauver"));
+                               echo '</form>';
+                               exit('test_me');
+                       }
+                       if (isset($_POST['save_it']))
+                       {
+                               print 'saving';
+                               $array = $_POST;
+                               $array['save_opd'] = 1;
+                               try
+                               {
+                                       $a->save($array);
+                               }
+                               catch (Exception $e)
+                               {
+                                       alert($e->getMessage());
+                                       echo '<form method="post">';
+
+                                       echo $a->show_form($_POST);
+                                       echo HtmlInput::submit('post_id', 'Try 
me');
+                                       echo '</form>';
+                               }
+                               return;
+                       }
+                       // The GET at the end because automatically repost when 
you don't
+                       // specify the url in the METHOD field
+                       if (isset($_GET['use_opd']))
+                       {
+                               $op = new Pre_op_advanced($cn);
+                               $op->set_od_id($_REQUEST['pre_def']);
+                               //$op->p_jrn=$id;
+
+                               $p_post = $op->compute_array();
+
+                               echo '<FORM method="post">';
+
+                               echo $a->show_form($p_post);
+                               echo HtmlInput::submit('post_id', 'Use 
predefined operation');
+                               echo '</form>';
+                               return;
+                       }
+               }// if case = ''
+               
///////////////////////////////////////////////////////////////////////////
+               // search
+               if ($pCase == 'search')
+               {
+                       html_page_start();
+                       $cn = new Database(dossier::id());
+                       $ledger = new Acc_Ledger($cn, 0);
+                       $_SESSION['g_user'] = 'phpcompta';
+                       $_SESSION['g_pass'] = 'phpcompta';
+                       echo $ledger->search_form('ALL');
+               }
+               
///////////////////////////////////////////////////////////////////////////
+               // reverse
+               // Give yourself the var and check in your tables
+               
///////////////////////////////////////////////////////////////////////////
+               if ($pCase == 'reverse')
+               {
+                       $cn = new Database(dossier::id());
+                       $jr_internal = 'OD-01-272';
+                       try
+                       {
+                               $cn->start();
+                               $jrn_def_id = $cn->get_value('select jr_def_id 
from jrn where jr_internal=$1', array($jr_internal));
+                               $ledger = new Acc_Ledger($cn, $jrn_def_id);
+                               $ledger->jr_id = $cn->get_value('select jr_id 
from jrn where jr_internal=$1', array($jr_internal));
+
+                               echo "Ouvrez le fichier " . __FILE__ . " à la 
ligne " . __LINE__ . " pour changer jr_internal et vérifier le résultat de 
l'extourne";
+
+                               $ledger->reverse('01.07.2010');
+                       }
+                       catch (Exception $e)
+                       {
+                               $cn->rollback();
+                               var_dump($e);
+                       }
+                       $cn->commit();
+               }
+       }
+
+       /**
+        * create an array of the existing cat, to be used in a checkbox form
+        *
+        */
+       static function array_cat()
+       {
+               $r = array(
+                       array('cat' => 'VEN', 'name' => _("Journaux de vente")),
+                       array('cat' => 'ACH', 'name' => _("Journaux d'achat")),
+                       array('cat' => 'FIN', 'name' => _("Journaux 
Financier")),
+                       array('cat' => 'ODS', 'name' => _("Journaux 
d'Opérations diverses"))
+               );
+               return $r;
+       }
+
+       /**
+        * Retrieve the third : supplier for purchase, customer for sale, bank 
for fin,
+        * @param $p_jrn_type type of the ledger FIN, VEN ACH or ODS
+        */
+       function get_tiers($p_jrn_type, $jr_id)
+       {
+               if ($p_jrn_type == 'ODS')
+                       return ' ';
+               $tiers = '';
+               switch ($p_jrn_type)
+               {
+                       case 'VEN':
+                               $tiers = $this->db->get_value('select 
max(qs_client) from quant_sold join jrnx using (j_id) join jrn on 
(jr_grpt_id=j_grpt) where jrn.jr_id=$1', array($jr_id));
+                               break;
+                       case 'ACH':
+                               $tiers = $this->db->get_value('select 
max(qp_supplier) from quant_purchase join jrnx using (j_id) join jrn on 
(jr_grpt_id=j_grpt) where jrn.jr_id=$1', array($jr_id));
+
+                               break;
+                       case 'FIN':
+                               $tiers = $this->db->get_value('select qf_other 
from quant_fin where jr_id=$1', array($jr_id));
+                               break;
+               }
+               if ($this->db->count() == 0)
+                       return '';
+               $name = $this->db->get_value('select ad_value from fiche_detail 
where ad_id=1 and f_id=$1', array($tiers));
+               $first_name = $this->db->get_value('select ad_value from 
fiche_detail where ad_id=32 and f_id=$1', array($tiers));
+               return $name . ' ' . $first_name;
+       }
+
+       /**
+        * @brief listing of all ledgers
+        * @return HTML string
+        */
+       function listing()
+       {
+               $str_dossier = dossier::get();
+               $base_url = "?" . dossier::get() . "&ac=" . $_REQUEST['ac'];
+
+               $r = "";
+                $r.=_('Filtre')." 
".HtmlInput::filter_table("cfgledger_table_id", "0", "1");
+               $r.='<TABLE id="cfgledger_table_id" class="vert_mtitle">';
+               $r.='<TR><TD class="first"><A HREF="' . $base_url . '&sa=add">' 
. _('Ajout journal') . ' </A></TD></TR>';
+               $ret = $this->db->exec_sql("select distinct 
jrn_def_id,jrn_def_name,
+                       jrn_def_class_deb,jrn_def_class_cred,jrn_def_type
+                       from jrn_def order by jrn_def_name");
+               $Max = Database::num_row($ret);
+
+
+               for ($i = 0; $i < $Max; $i++)
+               {
+                       $l_line = Database::fetch_array($ret, $i);
+                       $url = $base_url . "&sa=detail&p_jrn=" . 
$l_line['jrn_def_id'];
+                       $r.=sprintf('<TR><TD><A HREF="%s">%s</A></TD></TR>', 
$url, h($l_line['jrn_def_name']).' ('.$l_line['jrn_def_type'].')');
+               }
+               $r.= "</TABLE>";
+               return $r;
+       }
+
+       /**
+        * display detail of a ledger
+        *
+        */
+       function display_ledger()
+       {
+               if ($this->load() == -1)
+               {
+                       throw new Exception(_("Journal n'existe pas"), -1);
+               }
+               $type = $this->jrn_def_type;
+               $name = $this->jrn_def_name;
+               $code = $this->jrn_def_code;
+                $str_add_button="";
+               /* widget for searching an account */
+               $wSearch = new IPoste();
+               $wSearch->set_attribute('ipopup', 'ipop_account');
+               $wSearch->set_attribute('account', 'p_jrn_class_deb');
+               $wSearch->set_attribute('no_overwrite', '1');
+               $wSearch->set_attribute('noquery', '1');
+               $wSearch->table = 3;
+               $wSearch->name = "p_jrn_class_deb";
+               $wSearch->size = 20;
+               $wSearch->value = $this->jrn_def_class_deb;
+               $search = $wSearch->input();
+
+               $wPjPref = new IText();
+               $wPjPref->name = 'jrn_def_pj_pref';
+               $wPjPref->value = $this->jrn_def_pj_pref;
+               $pj_pref = $wPjPref->input();
+
+               $wPjSeq = new INum();
+               $wPjSeq->value = 0;
+               $wPjSeq->name = 'jrn_def_pj_seq';
+               $pj_seq = $wPjSeq->input();
+               $last_seq = $this->get_last_pj();
+               $name = $this->jrn_def_name;
+
+               $hidden = HtmlInput::hidden('p_jrn', $this->id);
+               $hidden.= HtmlInput::hidden('sa', 'detail');
+               $hidden.= dossier::hidden();
+               $hidden.=HtmlInput::hidden('p_jrn_deb_max_line', 10);
+               $hidden.=HtmlInput::hidden('p_ech_lib', 'echeance');
+               $hidden.=HtmlInput::hidden('p_jrn_type', $type);
+
+               $min_row = new INum("min_row",$this->jrn_deb_max_line);
+               $min_row->prec=0;
+                
+                $description=new ITextarea('p_description');
+                $description->style='class="itextarea" style="margin:0px;"';
+                $description->value=$this->jrn_def_description;
+                $str_description=$description->input();
+
+               /* Load the card */
+               $card = $this->get_fiche_def();
+               $rdeb = explode(',', $card['deb']);
+               $rcred = explode(',', $card['cred']);
+               /* Numbering (only FIN) */
+               $num_op = new ICheckBox('numb_operation');
+               if ($this->jrn_def_num_op == 1)
+                       $num_op->selected = true;
+               /* bank card */
+               $qcode_bank = '';
+               if ($type == 'FIN')
+               {
+                       $f_id = $this->jrn_def_bank;
+                       if (isNumber($f_id) == 1)
+                       {
+                               $fBank = new Fiche($this->db, $f_id);
+                               $qcode_bank = $fBank->get_quick_code();
+                       }
+               }
+               $new = 0;
+               $cn = $this->db;
+               echo $hidden;
+               require_once NOALYSS_INCLUDE.'/template/param_jrn.php';
+       }
+
+       /**
+        * Verify before update
+        *
+        * @param type $array
+        *   'p_jrn' => string '3' (length=1)
+         'sa' => string 'detail' (length=6)
+         'gDossier' => string '82' (length=2)
+         'p_jrn_deb_max_line' => string '10' (length=2)
+         'p_ech_lib' => string 'echeance' (length=8)
+         'p_jrn_type' => string 'ACH' (length=3)
+         'p_jrn_name' => string 'Achat' (length=5)
+         'jrn_def_pj_pref' => string 'ACH' (length=3)
+         'jrn_def_pj_seq' => string '0' (length=1)
+         'FICHECRED' =>
+         array
+         0 => string '4' (length=1)
+         'FICHEDEB' =>
+         array
+         0 => string '7' (length=1)
+         1 => string '5' (length=1)
+         2 => string '13' (length=2)
+         'update' => string 'Sauve' (length=5
+        * @exception is throw is test are not valid
+        */
+       function verify_ledger($array)
+       {
+               extract($array);
+               try
+               {
+                       if (isNumber($p_jrn) == 0)
+                               throw new Exception("Id invalide");
+                       if (isNumber($p_jrn_deb_max_line) == 0)
+                               throw new Exception(_("Nombre de ligne 
incorrect"));
+                       if (trim($p_jrn_name) == "")
+                               throw new Exception("Nom de journal invalide");
+                       if ($this->db->get_value("select count(*) from jrn_def 
where jrn_def_name=$1 and jrn_Def_id<>$2", array($p_jrn_name, $p_jrn)) > 0)
+                               throw new Exception(_("Un journal avec ce nom 
existe déjà"));
+                       if ($p_jrn_type == 'FIN')
+                       {
+                               $a = new Fiche($this->db);
+                               $result = 
$a->get_by_qcode(trim(strtoupper($_POST['bank'])), false);
+                               if ($result == 1)
+                                       throw new Exception(_("Aucun compte en 
banque n'est donné"));
+                       }
+                        if ($p_jrn_type == "-1") {
+                            throw new Exception(_('Choix du type de journal 
est obligatoire'));
+                        }
+               }
+               catch (Exception $e)
+               {
+                       throw $e;
+               }
+       }
+
+       /**
+        * update a ledger
+        * @param type $array  normally post
+        * @see verify_ledger
+        */
+       function update($array = '')
+       {
+               if ($array == null)
+                       throw new Exception('save cannot use a empty array');
+
+               extract($array);
+               $this->jrn_def_id = $p_jrn;
+               $this->jrn_def_name = $p_jrn_name;
+               $this->jrn_def_ech_lib = $p_ech_lib;
+               $this->jrn_def_max_line_deb = 
($p_jrn_deb_max_line<1)?1:$p_jrn_deb_max_line;
+               $this->jrn_def_type = $p_jrn_type;
+               $this->jrn_def_pj_pref = $jrn_def_pj_pref;
+               $this->jrn_def_fiche_deb = (isset($FICHEDEB)) ? join($FICHEDEB, 
',') : "";
+               $this->jrn_deb_max_line=($min_row<1)?1:$min_row;
+               $this->jrn_def_description=$p_description;
+               switch ($this->jrn_def_type)
+               {
+                       case 'ACH':
+                       case 'VEN':
+                               $this->jrn_def_fiche_cred = (isset($FICHECRED)) 
? join($FICHECRED, ',') : '';
+                               break;
+                       case 'ODS':
+                               $this->jrn_def_class_deb = $p_jrn_class_deb;
+                               $this->jrn_def_fiche_cred=null;
+                               break;
+                       case 'FIN':
+                               $a = new Fiche($this->db);
+                               $result = 
$a->get_by_qcode(trim(strtoupper($_POST['bank'])), false);
+                               $bank = $a->id;
+                               $this->jrn_def_bank = $bank;
+                               if ($result == -1)
+                                       throw new Exception(_("Aucun compte en 
banque n'est donné"));
+                               $this->jrn_def_num_op = 
(isset($numb_operation)) ? 1 : 0;
+                               break;
+               }
+
+               parent::update();
+               //Reset sequence if needed
+               if ($jrn_def_pj_seq != 0)
+               {
+                       $Res = $this->db->alter_seq("s_jrn_pj" . $p_jrn, 
$jrn_def_pj_seq);
+               }
+       }
+
+       function input_paid()
+       {
+               $r = '';
+               $r.='<div id="payment"> ';
+               $r.='<h2> ' . _('Payé par') . ' </h2>';
+               $mp = new Acc_Payment($this->db);
+               $mp->set_parameter('ledger_source', $this->id);
+               $r.=$mp->select();
+               $r.='</div>';
+               return $r;
+       }
+
+       /**
+        * display screen to enter a new ledger
+        */
+       function input_new()
+       {
+            $retry=HtmlInput::default_value_post("sa", "");
+//            if ( $retry == "add") {
+                $default_type=HtmlInput::default_value_post("p_jrn_type", -1);
+                
$previous_jrn_def_pj_pref=HtmlInput::default_value_post("jrn_def_pj_pref","");
+                
$previous_p_description=HtmlInput::default_value_post("p_description","");
+                
$previous_p_jrn_name=HtmlInput::default_value_post('p_jrn_name','');
+                $previous_p_jrn_type = 
HtmlInput::default_value_post("p_jrn_type","");
+//            }
+                global $g_user;
+                $f_add_button=new ISmallButton('add_card');
+                $f_add_button->label=_('Créer une nouvelle fiche');
+                $f_add_button->tabindex=-1;
+                $f_add_button->set_attribute('jrn',-1);
+                $f_add_button->javascript=" 
this.jrn=-1;select_card_type({type_cat:4});";
+
+                $str_add_button="";
+                if ($g_user->check_action(FICADD)==1)
+                {
+                        $str_add_button=$f_add_button->input();
+                }
+               $wSearch = new IPoste();
+               $wSearch->table = 3;
+               $wSearch->set_attribute('ipopup', 'ipop_account');
+               $wSearch->set_attribute('account', 'p_jrn_class_deb');
+               $wSearch->set_attribute('no_overwrite', '1');
+               $wSearch->set_attribute('noquery', '1');
+
+               $wSearch->name = "p_jrn_class_deb";
+               $wSearch->size = 20;
+
+               $search = $wSearch->input();
+                // default for ACH
+                $default_deb_purchase = $this->get_default_card('ACH', 'D');
+                $default_cred_purchase = $this->get_default_card('ACH', 'C');
+                
+                // default for VEN
+                $default_deb_sale      = $this->get_default_card('VEN', 'D');
+                $default_cred_sale     = $this->get_default_card('VEN', 'C');
+                
+                // default for FIN
+                $default_fin           = $this->get_default_card("FIN", "");
+                
+                //default ods
+                $default_ods          = $this->get_default_card("ODS", "");
+                
+               /* construct all the hidden */
+               $hidden = HtmlInput::hidden('p_jrn', -1);
+               $hidden.= HtmlInput::hidden('p_action', 'jrn');
+               $hidden.= HtmlInput::hidden('sa', 'add');
+               $hidden.= dossier::hidden();
+               $hidden.=HtmlInput::hidden('p_jrn_deb_max_line', 10);
+               $hidden.=HtmlInput::hidden('p_ech_lib', 'echeance');
+
+               /* properties of the ledger */
+               $name = $previous_p_jrn_name;
+               $code = "";
+               $wType = new ISelect();
+                $a_jrn= $this->db->make_array("select '-1',' -- "._("choix du 
type de journal")." -- ' union select jrn_type_id,jrn_desc from jrn_type");
+                $wType->selected='-1';
+               $wType->value =$a_jrn;
+               $wType->name = "p_jrn_type";
+               $wType->id= "p_jrn_type_select_id";
+                $wType->javascript=' onchange="show_ledger_div()"';
+                $wType->selected=$default_type;
+               $type = $wType->input();
+               $rcred = $rdeb = array();
+                $wPjPref = new IText();
+               $wPjPref->name = 'jrn_def_pj_pref';
+                $wPjPref->value=$previous_jrn_def_pj_pref;
+               $pj_pref = $wPjPref->input();
+               $pj_seq = '';
+               $last_seq = 0;
+               $new = 1;
+                $description=new ITextarea('p_description');
+                $description->style='class="itextarea" style="margin:0px;"';
+                $description->value=$previous_p_description;
+                $str_description=$description->input();
+               /* bank card */
+               $qcode_bank = '';
+               /* Numbering (only FIN) */
+               $num_op = new ICheckBox('numb_operation');
+               echo dossier::hidden();
+               echo HtmlInput::hidden('ac', $_REQUEST['ac']);
+                echo $hidden;
+                
+               $cn = $this->db;
+               $min_row = new INum("min_row",MAX_ARTICLE);
+               $min_row->prec=0;
+               require_once NOALYSS_INCLUDE.'/template/param_jrn.php';
+       }
+
+       /**
+        * Insert a new ledger
+        * @param type $array normally $_POST
+        * @see verify_ledger
+        */
+       function save_new($array)
+       {
+               $this->load();
+               extract($array);
+               $this->jrn_def_id = -1;
+               $this->jrn_def_name = $p_jrn_name;
+               $this->jrn_def_ech_lib = $p_ech_lib;
+               $this->jrn_def_max_line_deb = $p_jrn_deb_max_line;
+               $this->jrn_def_type = $p_jrn_type;
+               $this->jrn_def_pj_pref = $jrn_def_pj_pref;
+               $this->jrn_def_fiche_deb = (isset($FICHEDEB)) ? join($FICHEDEB, 
',') : "";
+               $this->jrn_deb_max_line=$min_row;
+               $this->jrn_def_code = sprintf("%s%02d", 
trim(substr($this->jrn_def_type, 0, 1)), Acc_Ledger::next_number($this->db, 
$this->jrn_def_type));
+                $this->jrn_def_description=$p_description;
+               switch ($this->jrn_def_type)
+               {
+                       case 'ACH':
+                       case 'VEN':
+                               $this->jrn_def_fiche_cred = (isset($FICHECRED)) 
? join($FICHECRED, ',') : '';
+
+                               break;
+                       case 'ODS':
+                               $this->jrn_def_class_deb = $p_jrn_class_deb;
+                               $this->jrn_def_fiche_cred = null;
+                               break;
+                       case 'FIN':
+                               $a = new Fiche($this->db);
+                               $result = 
$a->get_by_qcode(trim(strtoupper($_POST['bank'])), false);
+                               $bank = $a->id;
+                               $this->jrn_def_bank = $bank;
+                               if ($result == -1)
+                                       throw new Exception(_("Aucun compte en 
banque n'est donné"));
+                               $this->jrn_def_num_op = 
(isset($numb_operation)) ? 1 : 0;
+                               break;
+               }
+
+               parent::insert();
+       }
+
+       /**
+        * delete a ledger IF is not already used
+        * @exeption : cannot delete
+        */
+       function delete_ledger()
+       {
+               try
+               {
+                       if ($this->db->get_value("select count(jr_id) from jrn 
where jr_def_id=$1", array($this->jrn_def_id)) > 0)
+                               throw new Exception(_("Impossible d'effacer un 
journal qui contient des opérations"));
+                       parent::delete();
+               }
+               catch (Exception $e)
+               {
+                       throw $e;
+               }
+       }
+        /**
+         * Get operation from the ledger type before, after or with the 
+         * given date . The array is filtered by the ledgers granted to the 
+         * user
+         * @global type $g_user
+         * @param $p_date Date (d.m.Y)
+         * @param $p_ledger_type VEN ACH 
+         * @param type $sql_op < > or =
+         * @return array from jrn (jr_id, jr_internal, jr_date, 
jr_comment,jr_pj_number,jr_montant)
+         * @throws Exception
+         */
+       function get_operation_date($p_date,$p_ledger_type,$sql_op)
+       {
+               global $g_user;
+               switch ($p_ledger_type)
+               {
+                       case 'ACH':
+                               $filter=$g_user->get_ledger_sql('ACH',3);
+                               break;
+                       case 'VEN':
+                               $filter=$g_user->get_ledger_sql('VEN',3);
+                               break;
+                       default:
+                               throw new Exception ('Ledger_type invalid : 
'.$p_ledger_type);
+               }
+
+
+               $sql = "select jr_id, jr_internal, jr_date, 
jr_comment,jr_pj_number,jr_montant
+                               from jrn
+                               join jrn_def on (jrn_def_id=jr_def_id)
+                               where
+                               jr_ech is not null
+                               and jr_ech $sql_op to_date($1,'DD.MM.YYYY')
+                               and coalesce (jr_rapt,'xx') <> 'paid'
+                               and $filter
+                               ";
+               $array=$this->db->get_array($sql,array($p_date));
+               return $array;
+       }
+       /**
+        * @brief get info from supplier to pay today
+        */
+       function get_supplier_now()
+       {
+               $array=$this->get_operation_date(Date('d.m.Y'), 'ACH', '=');
+               return $array;
+       }
+       /**
+        * @brief get info from supplier not yet paid
+        */
+       function get_supplier_late()
+       {
+               $array=$this->get_operation_date(Date('d.m.Y'), 'ACH', '<');
+               return $array;
+       }
+       /**
+        * @brief get info from customer to pay today
+        */
+       function get_customer_now()
+       {
+               $array=$this->get_operation_date(Date('d.m.Y'), 'VEN', '=');
+               return $array;
+       }
+       /**
+        * @brief get info from customer not yet paid
+        */
+       function get_customer_late()
+       {
+               $array=$this->get_operation_date(Date('d.m.Y'), 'VEN', '<');
+               return $array;
+       }
+        function convert_from_follow($p_ag_id)
+        {
+            global $g_user;
+            if (isNumber($p_ag_id)==0) return null;
+            if (! $g_user->can_read_action($p_ag_id)) die (_('Action non 
accessible'));
+            $array=array();
+            
+            // retrieve info from action_gestion
+            $tiers_id=$this->db->get_value('select f_id_dest from 
action_gestion where ag_id=$1',array($p_ag_id));
+            if ( $this->db->size() !=0 )
+                $qcode=$this->db->get_value('select j_qcode from 
vw_poste_qcode where f_id=$1',array($tiers_id));
+            else
+                $qcode="";
+            
+            $comment=$this->db->get_value('select ag_title from action_gestion 
where ag_id=$1',array($p_ag_id));
+            $array['e_client']=$qcode;
+            $array['e_comm']=$comment;
+            
+            // retrieve info from action_detail
+            $a_item=$this->db->get_array('select 
f_id,ad_text,ad_pu,ad_quant,ad_tva_id,ad_tva_amount,j_qcode 
+                    from 
+                  action_detail 
+                  left join vw_poste_qcode using(f_id)
+                  where
+                    ag_id=$1',array($p_ag_id));
+            
+            $array['nb_item']=($this->nb > 
count($a_item))?$this->nb:count($a_item);
+            for ($i=0;$i<count($a_item);$i++)
+            {
+                $array['e_march'.$i]=$a_item[$i]['j_qcode'];
+                $array['e_march'.$i.'_label']=$a_item[$i]['ad_text'];
+                $array['e_march'.$i.'_price']=$a_item[$i]['ad_pu'];
+                $array['e_march'.$i.'_tva_id']=$a_item[$i]['ad_tva_id'];
+                
$array['e_march'.$i.'_tva_amount']=$a_item[$i]['ad_tva_amount'];
+                $array['e_quant'.$i]=$a_item[$i]['ad_quant'];
+                
+            }
+            return $array;
+                       
+        }
+        /**
+         * Retrieve the label of an accounting
+         * @param $p_value tmp_pcmn.pcm_val
+         * @return string
+         */
+        protected function find_label($p_value)
+        {
+            $lib=$this->db->get_value('select pcm_lib from tmp_pcmn where 
pcm_val=$1',array($p_value));
+            return $lib;
+        }
+        /**
+         * Let you select the repository before confirming a sale or a 
purchase.
+         * Returns an empty string if the company doesn't use stock
+         * @brief Let you select the repository before confirming a sale or a 
purchase.
+         * @global type $g_parameter check if company is using stock
+         * @param type $p_readonly 
+         * @param type $p_repo
+         * @return string
+         */
+        public function select_depot($p_readonly, $p_repo)
+        {
+            global $g_parameter;
+            $r=($p_readonly==false)?'<div id="repo_div_id" 
style="height:185px;height:10rem;">':'<div id="repo_div_id" >';
+            // Show the available repository
+            if ($g_parameter->MY_STOCK=='Y')
+            {
+                $sel=HtmlInput::select_stock($this->db, 'repo', 'W');
+                $sel->readOnly=$p_readonly;
+                if ($p_readonly==true)
+                    $sel->selected=$p_repo;
+                $r.="<p class=\"decale\">"._('Dans le dépôt')." : ";
+                $r.=$sel->input();
+                $r.='</p>';
+            } else
+            {
+                $r.='<span class="notice">'.'Stock non utilisé'.'</span>';
+            }
+            $r.='</div>';
+            return $r;
+            
+        }
+        /**
+         * Create a button to encode a new operation into the same ledger
+         * @return string
+         */
+        function button_new_operation()
+        {
+            
$url=http_build_query(array('ac'=>$_REQUEST['ac'],'gDossier'=>$_REQUEST['gDossier'],'p_jrn'=>$_REQUEST['p_jrn']));
+            $button = HtmlInput::button_anchor(_("Nouvelle opération"), 
'do.php?'.$url);
+            return '<p>'.$button.'</p>';
+        }
+
+}
+?>
\ No newline at end of file
diff --git a/include/class/class_acc_ledger_fin.php 
b/include/class/class_acc_ledger_fin.php
new file mode 100644
index 0000000..3d441f9
--- /dev/null
+++ b/include/class/class_acc_ledger_fin.php
@@ -0,0 +1,1143 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/**\file
+ * \brief the class Acc_Ledger_Fin inherits from Acc_Ledger, this
+ * object permit to manage the financial ledger
+ */
+require_once NOALYSS_INCLUDE.'/lib/class_idate.php';
+require_once NOALYSS_INCLUDE.'/lib/class_icard.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ispan.php';
+require_once NOALYSS_INCLUDE.'/lib/class_itext.php';
+require_once NOALYSS_INCLUDE.'/lib/class_iconcerned.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ifile.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ihidden.php';
+require_once NOALYSS_INCLUDE.'/lib/class_iselect.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_ledger.php';
+require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_reconciliation.php';
+
+class Acc_Ledger_Fin extends Acc_Ledger
+{
+
+       function __construct($p_cn, $p_init)
+       {
+               parent::__construct($p_cn, $p_init);
+               $this->type = 'FIN';
+       }
+
+       /**
+         * Verify that the data are correct before inserting or confirming
+         * @brief verify the data 
+        * @param an array (usually $_POST)
+        * @return String
+        * @throw Exception on error occurs
+        */
+
+       public function verify($p_array)
+       {
+               global $g_user;
+                if (is_array($p_array ) == false || empty($p_array))
+                    throw new Exception ("Array empty");
+               /*
+                * Check needed value
+                */
+                check_parameter($p_array,'p_jrn');
+
+                
+               extract($p_array);
+               /* check for a double reload */
+               if (isset($mt) && $this->db->count_sql('select jr_mt from jrn 
where jr_mt=$1', array($mt)) != 0)
+                       throw new Exception(_('Double Encodage'), 5);
+
+               /* check if we can write into this ledger */
+               if ($g_user->check_jrn($p_jrn) != 'W')
+                       throw new Exception(_('Accès interdit'), 20);
+
+               /* check if there is a bank account linked to the ledger */
+               $bank_id = $this->get_bank();
+
+               if ($this->db->count() == 0)
+                       throw new Exception("Ce journal n'a pas de compte en 
banque, allez dans paramètre->journal pour régler cela");
+               /* check if the accounting of the bank is correct */
+               $fBank = new Fiche($this->db, $bank_id);
+               $bank_accounting = $fBank->strAttribut(ATTR_DEF_ACCOUNT);
+               if (trim($bank_accounting) == '')
+                       throw new Exception('Le poste comptable du compte en 
banque de ce journal est invalide');
+
+               /* check if the account exists */
+               $poste = new Acc_Account_Ledger($this->db, $bank_accounting);
+               if ($poste->load() == false)
+                       throw new Exception('Le poste comptable du compte en 
banque de ce journal est invalide');
+               if ($chdate != 1 && $chdate != 2) throw new Exception ('Le 
choix de date est invalide');
+               if ( $chdate == 1 )
+               {
+                       /*  check if the date is valid */
+                       if (isDate($e_date) == null)
+                       {
+                               throw new Exception('Date invalide', 2);
+                       }
+                       $oPeriode = new Periode($this->db);
+                       if ($this->check_periode() == false)
+                       {
+                               $periode = $oPeriode->find_periode($e_date);
+                       }
+                       else
+                       {
+                               $oPeriode->p_id = $periode;
+                               list ($min, $max) = $oPeriode->get_date_limit();
+                               if (cmpDate($e_date, $min) < 0 ||
+                                               cmpDate($e_date, $max) > 0)
+                                       throw new Exception(_('Date et periode 
ne correspondent pas'), 6);
+                       }
+
+                       /* check if the periode is closed */
+                       if ($this->is_closed($periode) == 1)
+                       {
+                               throw new Exception(_('Periode fermee'), 6);
+                       }
+
+                       /* check if we are using the strict mode */
+                       if ($this->check_strict() == true)
+                       {
+                               /* if we use the strict mode, we get the date 
of the last
+                               operation */
+                               $last_date = $this->get_last_date();
+                               if ($last_date != null && cmpDate($e_date, 
$last_date) < 0)
+                                       throw new Exception(_('Vous utilisez le 
mode strict la dernière operation est à la date du ')
+                                                       . $last_date . _(' vous 
ne pouvez pas encoder à une date antérieure'), 15);
+                       }
+               }
+
+               $acc_pay = new Acc_Operation($this->db);
+
+               $nb = 0;
+               $tot_amount = 0;
+               //----------------------------------------
+               // foreach item
+               //----------------------------------------
+               for ($i = 0; $i < $nb_item; $i++)
+               {
+                       if (strlen(trim(${'e_other' . $i})) == 0)
+                               continue;
+                       /* check if amount are numeric and */
+                       if (isNumber(${'e_other' . $i . '_amount'}) == 0)
+                               throw new Exception('La fiche ' . ${'e_other' . 
$i} . 'a un montant invalide [' . ${'e_other' . $i . '_amount'} . ']', 6);
+
+                       /* compute the total */
+                       $tot_amount+=round(${'e_other' . $i . '_amount'}, 2);
+                       /* check if all card has a ATTR_DEF_ACCOUNT */
+                       $fiche = new Fiche($this->db);
+                       $fiche->get_by_qcode(${'e_other' . $i});
+                       if ($fiche->empty_attribute(ATTR_DEF_ACCOUNT) == true)
+                               throw new Exception('La fiche ' . ${'e_other' . 
$i} . 'n\'a pas de poste comptable', 8);
+
+                       $sposte = $fiche->strAttribut(ATTR_DEF_ACCOUNT);
+                       // if 2 accounts, take only the debit one for customer
+                       if (strpos($sposte, ',') != 0)
+                       {
+                               $array = explode(',', $sposte);
+                               $poste_val = $array[1];
+                       }
+                       else
+                       {
+                               $poste_val = $sposte;
+                       }
+                       /* The account exists */
+                       $poste = new Acc_Account_Ledger($this->db, $poste_val);
+                       if ($poste->load() == false)
+                       {
+                               throw new Exception('Pour la fiche ' . 
${'e_other' . $i} . ' le poste comptable [' . $poste->id . 'n\'existe pas', 9);
+                       }
+                       /* Check if the card belong to the ledger */
+                       $fiche = new Fiche($this->db);
+                       $fiche->get_by_qcode(${'e_other' . $i});
+                       if ($fiche->belong_ledger($p_jrn, 'deb') != 1)
+                               throw new Exception('La fiche ' . ${'e_other' . 
$i} . 'n\'est pas accessible à ce journal', 10);
+                       if ($chdate == 2)
+                       {
+                               {/*  check if the date is valid */
+                                       if (isDate(${'dateop' . $i}) == null)
+                                       {
+                                               throw new Exception('Date 
invalide', 2);
+                                       }
+                                       $oPeriode = new Periode($this->db);
+                                       if ($this->check_periode() == false)
+                                       {
+                                               $periode = 
$oPeriode->find_periode(${'dateop' . $i});
+                                       }
+                                       else
+                                       {
+                                               $oPeriode->p_id = $periode;
+                                               list ($min, $max) = 
$oPeriode->get_date_limit();
+                                               if (cmpDate(${'dateop' . $i}, 
$min) < 0 ||
+                                                               
cmpDate(${'dateop' . $i}, $max) > 0)
+                                                       throw new 
Exception(_('Date et periode ne correspondent pas'), 6);
+                                       }
+
+                                       /* check if the periode is closed */
+                                       if ($this->is_closed($periode) == 1)
+                                       {
+                                               throw new Exception(_('Periode 
fermee'), 6);
+                                       }
+
+                                       /* check if we are using the strict 
mode */
+                                       if ($this->check_strict() == true)
+                                       {
+                                               /* if we use the strict mode, 
we get the date of the last
+                                                 operation */
+                                               $last_date = 
$this->get_last_date();
+                                               if ($last_date != null && 
cmpDate(${'dateop' . $i}, $last_date) < 0)
+                                                       throw new 
Exception(_('Vous utilisez le mode strict la dernière operation est à la date 
du ')
+                                                                       . 
$last_date . _(' vous ne pouvez pas encoder à une date antérieure'), 15);
+                                       }
+                               }
+                       }
+                       $nb++;
+               }
+               if ($nb == 0)
+                       throw new Exception('Il n\'y a aucune opération', 12);
+
+               /* Check if the last_saldo and first_saldo are correct */
+               if (strlen(trim($last_sold)) != 0 && isNumber($last_sold) &&
+                               strlen(trim($first_sold)) != 0 && 
isNumber($first_sold))
+               {
+                       $diff = $last_sold - $first_sold;
+                       $diff = round($diff, 2) - round($tot_amount, 2);
+                       if ($first_sold != 0 && $last_sold != 0)
+                       {
+                               if ($diff != 0)
+                                       throw new Exception('Le montant de 
l\'extrait est incorrect' .
+                                                       $tot_amount . ' extrait 
' . $diff, 13);
+                       }
+               }
+       }
+
+       /**\brief
+        * \param $p_array contains the value usually it is $_POST
+        * \return string with html code
+        * \note the form tag are not  set here
+        */
+
+       function input($p_array = null, $notused = 0)
+       {
+               global $g_parameter, $g_user;
+               if ($p_array != null)
+                       extract($p_array);
+
+               $pview_only = false;
+
+               $min_article=$this->get_min_row();
+
+               $f_add_button = new IButton('add_card');
+               $f_add_button->label = _('Créer une nouvelle fiche');
+               $f_add_button->set_attribute('ipopup', 'ipop_newcard');
+               $f_add_button->set_attribute('jrn', $this->id);
+               $f_add_button->javascript = " 
this.jrn=\$('p_jrn').value;select_card_type(this);";
+               $str_add_button = ($g_user->check_action(FICADD) == 1) ? 
$f_add_button->input() : "";
+
+               // The first day of the periode
+               $pPeriode = new Periode($this->db);
+               list ($l_date_start, $l_date_end) = 
$pPeriode->get_date_limit($g_user->get_periode());
+               if ($g_parameter->MY_DATE_SUGGEST == 'Y')
+                       $op_date = (!isset($e_date) ) ? $l_date_start : $e_date;
+               else
+                       $op_date = (!isset($e_date) ) ? '' : $e_date;
+
+               $r = "";
+
+               $r.=dossier::hidden();
+               $f_legend = 'Banque, caisse';
+               //  Date
+               //--
+               $Date = new IDate("e_date", $op_date);
+               $Date->setReadOnly($pview_only);
+               $f_date = $Date->input();
+               $f_period = '';
+               if ($this->check_periode() == true)
+               {
+                       // Periode
+                       //--
+                       $l_user_per = (isset($periode)) ? $periode : 
$g_user->get_periode();
+                       $period = new IPeriod();
+                       $period->cn = $this->db;
+                       $period->type = OPEN;
+                       $period->value = $l_user_per;
+                       $period->user = $g_user;
+                       $period->name = 'periode';
+                       try
+                       {
+                               $l_form_per = $period->input();
+                       }
+                       catch (Exception $e)
+                       {
+                               if ($e->getCode() == 1)
+                               {
+                                       throw  new Exception(_("Aucune période 
ouverte"));
+                                       
+                               }
+                       }
+                       $label = HtmlInput::infobulle(3);
+                       $f_period = "Période comptable $label" . $l_form_per;
+               }
+
+               // Ledger (p_jrn)
+               //--
+               
$onchange="update_bank();ajax_saldo('first_sold');update_name();update_row('fin_item');";
+
+               if ($g_parameter->MY_DATE_SUGGEST == 'Y')
+                       $onchange .= 'get_last_date();';
+               if ($g_parameter->MY_PJ_SUGGEST=='Y')
+                       $onchange .= 'update_pj();';
+
+               $add_js = 'onchange="'.$onchange.'"';
+               $wLedger = $this->select_ledger('FIN', 2);
+               if ($wLedger == null)
+                       throw  new Exception(_('Pas de journal disponible'));
+
+               $wLedger->javascript = $add_js;
+
+               $label = " Journal " . HtmlInput::infobulle(2);
+               $f_jrn = $label . $wLedger->input();
+
+
+               // retrieve bank name, code and account from the 
jrn_def.jrn_def_bank
+
+               $f_bank = '<span id="bkname">' . $this->get_bank_name() . 
'</span>';
+               if ($this->bank_id == "")
+               {
+                       echo h2("Journal de banque non configuré " . 
$this->get_name(), ' class="error"');
+                       echo '<span class="error"> vous devez donner à ce 
journal un compte en banque (fiche), modifiez dans CFGLED</span>';
+                       alert("Journal de banque non configuré " . 
$this->get_name());
+               }
+
+               $f_legend_detail = 'Opérations financières';
+               //--------------------------------------------------
+               // Saldo begin end
+               //-------------------------------------------------
+               // Extrait
+               $default_pj = '';
+               if ($g_parameter->MY_PJ_SUGGEST == 'Y')
+               {
+                       $default_pj = $this->guess_pj();
+               }
+               $wPJ = new IText('e_pj');
+               $wPJ->readonly = false;
+               $wPJ->size = 10;
+               $wPJ->value = (isset($e_pj)) ? $e_pj : $default_pj;
+
+               $f_extrait = $wPJ->input() . HtmlInput::hidden('e_pj_suggest', 
$default_pj);
+               $label = HtmlInput::infobulle(7);
+
+               $first_sold = (isset($first_sold)) ? $first_sold : "";
+               $wFirst = new INum('first_sold', $first_sold);
+
+               $last_sold = isset($last_sold) ? $last_sold : "";
+               $wLast = new INum('last_sold', $last_sold);
+
+
+               $max = (isset($nb_item)) ? $nb_item : $min_article;
+
+               $r.= HtmlInput::hidden('nb_item', $max);
+               //--------------------------------------------------
+               // financial operation
+               //-------------------------------------------------
+
+               $array = array();
+               // Parse each " tiers"
+               for ($i = 0; $i < $max; $i++)
+               {
+                       $tiers = (isset(${"e_other" . $i})) ? ${"e_other" . $i} 
: "";
+
+                       $tiers_amount = (isset(${"e_other$i" . "_amount"})) ? 
round(${"e_other$i" . "_amount"}, 2) : 0;
+
+                       $tiers_comment = (isset(${"e_other$i" . "_comment"})) ? 
${"e_other$i" . "_comment"} : "";
+
+                       $operation_date=new IDate("dateop".$i);
+                       
$operation_date->value=(isset(${'dateop'.$i}))?${'dateop'.$i}:"";
+                       $array[$i]['dateop']=$operation_date->input();
+                       ${"e_other$i" . "_amount"} = (isset(${"e_other$i" . 
"_amount"})) ? ${"e_other$i" . "_amount"} : 0;
+
+                       $W1 = new ICard();
+                       $W1->label = "";
+                       $W1->name = "e_other" . $i;
+                       $W1->id = "e_other" . $i;
+                       $W1->value = $tiers;
+                       $W1->extra = 'deb';  // credits
+                       $W1->typecard = 'deb';
+                        $W1->style=' style = "vertical-align:65%"';
+                       $W1->set_dblclick("fill_ipopcard(this);");
+                       $W1->set_attribute('ipopup', 'ipopcard');
+
+                       // name of the field to update with the name of the card
+                       $W1->set_attribute('label', 'e_other_name' . $i);
+                       // name of the field to update with the name of the card
+                       $W1->set_attribute('typecard', 'filter');
+                       // Add the callback function to filter the card on the 
jrn
+                       $W1->set_callback('filter_card');
+                       $W1->set_function('fill_data');
+                       $W1->javascript = sprintf(' 
onchange="fill_data_onchange(\'%s\');" ', $W1->name);
+                       $W1->readonly = $pview_only;
+                       $array[$i]['qcode'] = $W1->input();
+                       $array[$i]['search'] = $W1->search();
+
+                       // Card name
+                       //
+                        $card_name = "";
+                       if ($tiers != "")
+                       {
+                               $fiche = new Fiche($this->db);
+                               $fiche->get_by_qcode($tiers);
+                               $card_name = $this->db->get_value("Select 
ad_value from fiche_detail where ad_id=$1 and f_id=$2", array(ATTR_DEF_NAME, 
$fiche->id));
+                       }
+
+                       $wcard_name = new IText("e_other_name" . $i, 
$card_name);
+                       $wcard_name->id=$wcard_name->name;
+                       $wcard_name->readOnly = true;
+                       $array[$i]['cname'] = $wcard_name->input();
+
+                       // Comment
+                       $wComment = new IText("e_other$i" . "_comment", 
$tiers_comment);
+
+                       $wComment->size = 35;
+                       $wComment->setReadOnly($pview_only);
+                       $array[$i]['comment'] = $wComment->input();
+                       // amount
+                       $wAmount = new INum("e_other$i" . "_amount", 
$tiers_amount);
+
+                       $wAmount->size = 7;
+                       $wAmount->setReadOnly($pview_only);
+                       $array[$i]['amount'] = $wAmount->input();
+                       // concerned
+                       ${"e_concerned" . $i} = (isset(${"e_concerned" . $i})) 
? ${"e_concerned" . $i} : ""
+                       ;
+                       $wConcerned = new IConcerned("e_concerned" . $i, 
${"e_concerned" . $i});
+                        $wConcerned->tiers="e_other" . $i;
+                       $wConcerned->setReadOnly($pview_only);
+                       $wConcerned->amount_id = "e_other" . $i . "_amount";
+
+                       $wConcerned->paid = 'paid';
+                       $array[$i]['concerned'] = $wConcerned->input();
+               }
+
+               ob_start();
+               require_once NOALYSS_INCLUDE.'/template/form_ledger_fin.php';
+               $r.=ob_get_contents();
+               ob_end_clean();
+               $r.= create_script("$('".$Date->id."').focus()");
+
+               return $r;
+       }
+
+       /**\brief show the summary before inserting into the database, it
+        * calls the function for adding a attachment. The function verify
+        * should be called before
+        * \param $p_array an array usually is $_POST
+        * \return string with code html
+        */
+
+       public function confirm($p_array, $p_nothing = 0)
+       {
+               global $g_parameter,$g_user;
+               $r = "";
+               bcscale(2);
+               extract($p_array);
+               $pPeriode = new Periode($this->db);
+               if ($this->check_periode() == true)
+               {
+                       $pPeriode->p_id = $periode;
+               }
+               else
+               {
+                       if (isDate($e_date) != null) {
+                               $pPeriode->find_periode($e_date);
+                       } else {
+                               $pPeriode->p_id=$g_user->get_periode();
+                       }
+               }
+
+               list ($l_date_start, $l_date_end) = $pPeriode->get_date_limit();
+               $exercice = $pPeriode->get_exercice();
+               $r.='';
+               $r.='<fieldset><legend>Banque, caisse </legend>';
+               $r.= '<div id="jrn_name_div">';
+               $r.='<h2 id="jrn_name" style="display:inline">' . 
$this->get_name() . '</h2>';
+               $r.= '</div>';
+               $r.='<TABLE  width="100%">';
+               //  Date
+               //--
+               $r.="<tr>";
+               if ( $chdate == 1 ) $r.='<td> Date : </td><td>' . $e_date;
+               // Periode
+               //--
+               $r.="<td>";
+               $r.="Période comptable </td><td>";
+               $r.=$l_date_start . ' - ' . $l_date_end;
+               $r.="</td>";
+               $r.="</tr>";
+               // Ledger (p_jrn)
+               //--
+               $r.='<tr>';
+               $r.='<td> Journal </td>';
+               $this->id = $p_jrn;
+               $r.='<td>';
+               $r.=h($this->get_name());
+               $r.='</td>';
+               $r.='</tr>';
+
+               //retrieve bank name
+               $bk_id = $this->get_bank();
+
+               $fBank = new Fiche($this->db, $bk_id);
+               $e_bank_account_label = $this->get_bank_name();
+
+               $filter_year = "  j_tech_per in (select p_id from parm_periode 
where  p_exercice='" . $exercice . "')";
+
+               $acc_account = new Acc_Account_Ledger($this->db, 
$fBank->strAttribut(ATTR_DEF_ACCOUNT));
+               $asolde= $acc_account->get_solde_detail($filter_year);
+               $deb=$asolde['debit'];
+               $cred=$asolde['credit'];
+               $solde=  bcsub($deb, $cred);
+               $new_solde=$solde;
+
+               $r.="<TR><td colspan=\"4\"> Banque ";
+               $r.=$e_bank_account_label;
+
+               $r.="</TABLE>";
+
+               $r.='</fieldset>';
+
+               $r.='<div class="myfieldset"><h1 class="legend">Extrait de 
compte</h1>';
+               //--------------------------------------------------
+               // Saldo begin end
+               //-------------------------------------------------
+               $r.='<table>';
+               $r.='<tr>';
+               // Extrait
+               //--
+               $r.=tr('<td> Numéro d\'extrait</td>' . td(h($e_pj)));
+               $r.='<tr><td >Solde début extrait </td>';
+               $r.='<td style="num">' . nbm($first_sold) . '</td></tr>';
+               $r.='<tr><td>Solde fin extrait </td>';
+               $r.='<td style="num">' . nbm($last_sold) . '</td></tr>';
+               $r.='</table>';
+
+               $r.='<h1 class="legend">Opérations financières</h1>';
+               //--------------------------------------------------
+               // financial operation
+               //-------------------------------------------------
+               $r.='<TABLE style="width:100%" id="fin_item">';
+               $r.="<TR>";
+               if ($chdate==2) $r.='<th>Date</th>';
+               $r.="<th style=\"width:auto;text-align:left\" 
colspan=\"2\">Nom</TH>";
+               $r.="<th style=\"text-align:left\" >Commentaire</TH>";
+               $r.="<th style=\"text-align:right\">Montant</TH>";
+               $r.='<th colspan="2"> Op. Concern&eacute;e(s)</th>';
+
+               /* if we use the AC */
+               if ($g_parameter->MY_ANALYTIC != 'nu')
+               {
+                       $anc = new Anc_Plan($this->db);
+                       $a_anc = $anc->get_list();
+                       $x = count($a_anc);
+                       /* set the width of the col */
+                       $r.='<th colspan="' . $x . '">' . _('Compt. 
Analytique') . '</th>';
+
+                       /* add hidden variables pa[] to hold the value of pa_id 
*/
+                       $r.=Anc_Plan::hidden($a_anc);
+               }
+               $r.="</TR>";
+               // Parse each " tiers"
+               $tot_amount = 0;
+               //--------------------------------------------------
+               // For each items
+               //--------------------------------------------------
+               for ($i = 0; $i < $nb_item; $i++)
+               {
+
+                       $tiers = (isset(${"e_other" . $i})) ? ${"e_other" . $i} 
: ""
+                       ;
+
+                       if (strlen(trim($tiers)) == 0)
+                               continue;
+                       $tiers_label = "";
+                       $tiers_amount = round(${"e_other$i" . "_amount"}, 2);
+                       $tot_amount = bcadd($tot_amount, $tiers_amount);
+                       $tiers_comment = h(${"e_other$i" . "_comment"});
+                       // If $tiers has a value
+                       $fTiers = new Fiche($this->db);
+                       $fTiers->get_by_qcode($tiers);
+
+                       $tiers_label = $fTiers->strAttribut(ATTR_DEF_NAME);
+
+                       $r.="<TR>";
+                       if ($chdate==2) $r.=td(${"dateop".$i});
+                       $r.="<td>" . ${'e_other' . $i} . "</TD>";
+                       // label
+                       $r.='<TD style="width:25%;border-bottom:1px dotted 
grey;">';
+                       $r.=$fTiers->strAttribut(ATTR_DEF_NAME);
+                       $r.='</td>';
+                       // Comment
+                       $r.='<td style="width:40%">' . $tiers_comment . '</td>';
+                       // amount
+                       $r.='<td class="num">' . nbm($tiers_amount) . '</td>';
+                       // concerned
+                       $r.='<td style="text-align:center">';
+                       if (${"e_concerned" . $i} != '')
+                       {
+                               $jr_internal = $this->db->get_array("select 
jr_internal from jrn where jr_id in (" . ${"e_concerned" . $i} . ")");
+                               $comma="";
+                               for ($x = 0; $x < count($jr_internal); $x++)
+                               {
+                                       
$r.=$comma.HtmlInput::detail_op(${"e_concerned" . $i}, 
$jr_internal[$x]['jr_internal']);
+                                       $comma=" , ";
+                               }
+                       }
+                       $r.='</td>';
+                       // encode the pa
+                       if ($g_parameter->MY_ANALYTIC != 'nu' && 
preg_match("/^[6,7]/", $fTiers->strAttribut(ATTR_DEF_ACCOUNT)) == 1) // use of 
AA
+                       {
+                               // show form
+                               $anc_op = new Anc_Operation($this->db);
+                               $null = ($g_parameter->MY_ANALYTIC == 'op') ? 1 
: 0;
+                               $r.='<td>';
+                               $p_mode = 1;
+                               $p_array['pa_id'] = $a_anc;
+                               /* op is the operation it contains either a 
sequence or a jrnx.j_id */
+                               $r.=HtmlInput::hidden('op[]=', $i);
+                               $r.=$anc_op->display_form_plan($p_array, $null, 
$p_mode, $i, $tiers_amount);
+                               $r.='</td>';
+                       }
+
+                       $r.='</TR>';
+               }
+               $r.="</TABLE>";
+
+               // saldo
+               $r.='<br>Ancien solde = ' . $solde;
+               $new_solde+=$tot_amount;
+               $r.='<br>Nouveau solde = ' . $new_solde;
+               $r.='<br>Difference =' . $tot_amount;
+               // check for upload piece
+               $file = new IFile();
+
+               $r.="<br>Ajoutez une pi&egrave;ce justificative ";
+               $r.=$file->input("pj", "");
+
+               $r.='</div>';
+               //--------------------------------------------------
+               // Hidden variables
+               //--------------------------------------------------
+               $r.=dossier::hidden();
+               $r.=HtmlInput::hidden('p_jrn', $this->id);
+               $r.=HtmlInput::hidden('nb_item', $nb_item);
+               $r.=HtmlInput::hidden('last_sold', $last_sold);
+               $r.=HtmlInput::hidden('first_sold', $first_sold);
+               $r.=HtmlInput::hidden('e_pj', $e_pj);
+               $r.=HtmlInput::hidden('e_pj_suggest', $e_pj_suggest);
+               $r.=HtmlInput::hidden('e_date', $e_date);
+               $mt = microtime(true);
+               $r.=HtmlInput::hidden('mt', $mt);
+
+               if (isset($periode))
+                       $r.=HtmlInput::hidden('periode', $periode);
+               $r.=dossier::hidden();
+               $r.=HtmlInput::hidden('sa', 'n','chdate');
+               for ($i = 0; $i < $nb_item; $i++)
+               {
+                       $tiers = (isset(${"e_other" . $i})) ? ${"e_other" . $i} 
: ""                    ;
+                       $r.=HtmlInput::hidden('e_other' . $i, $tiers);
+                       $r.=HtmlInput::hidden('e_other' . $i, $tiers);
+                       $r.=HtmlInput::hidden('e_other' . $i . '_comment', 
${'e_other' . $i . '_comment'});
+                       $r.=HtmlInput::hidden('e_other' . $i . '_amount', 
${'e_other' . $i . '_amount'});
+                       $r.=HtmlInput::hidden('e_concerned' . $i, 
${'e_concerned' . $i});
+                       $r.=HtmlInput::hidden('dateop' . $i, ${'dateop' . $i});
+                       $r.=HtmlInput::hidden('chdate' , $chdate);
+               }
+
+               return $r;
+       }
+
+       /**\brief save the data into the database, included the attachment,
+        * and the reconciliations
+        * \param $p_array usually $_POST
+        * \return string with HTML code
+        */
+
+       public function insert($p_array = null)
+       {
+               global $g_parameter;
+               bcscale(2);
+               $internal_code = "";
+               $oid = 0;
+               extract($p_array);
+               $ret = '';
+               // Debit = banque
+               $bank_id = $this->get_bank();
+               $fBank = new Fiche($this->db, $bank_id);
+               $e_bank_account = $fBank->strAttribut(ATTR_DEF_QUICKCODE);
+               // Get the saldo
+               $pPeriode = new Periode($this->db);
+               $sposte = $fBank->strAttribut(ATTR_DEF_ACCOUNT);
+               // if 2 accounts, take only the debit one for customer
+               if (strpos($sposte, ',') != 0)
+               {
+                       $array = explode(',', $sposte);
+                       $poste_val = $array[0];
+               }
+               else
+               {
+                       $poste_val = $sposte;
+               }
+
+               $acc_account = new Acc_Account_Ledger($this->db, $poste_val);
+
+               // If date = deposit date
+               if ($chdate == 1 )
+               {
+                       if ($this->check_periode() == true)
+                       {
+                               $pPeriode->p_id = $periode;
+                       }
+                       else
+                       {
+                               $pPeriode->find_periode($e_date);
+                       }
+                       $exercice = $pPeriode->get_exercice();
+                       $filter_year = "  j_tech_per in (select p_id from 
parm_periode where  p_exercice='" . $exercice . "')";
+                       $asolde= $acc_account->get_solde_detail($filter_year);
+                       $deb=$asolde['debit'];
+                       $cred=$asolde['credit'];
+                       $solde=  bcsub($deb, $cred);
+                       $new_solde=$solde;
+               }
+
+
+
+
+
+               try
+               {
+                       $this->db->start();
+                       $amount = 0.0;
+                       $idx_operation = 0;
+                       $ret = '<table class="result" >';
+                       $ret.=tr(th('Date').th('n° interne') . th('Quick Code') 
. th('Nom') . th('Libellé') . th('Montant', ' style="text-align:right"'));
+                       // Credit = goods
+                       $get_solde=true;
+                       for ($i = 0; $i < $nb_item; $i++)
+                       {
+                               // insert it into the database
+                               // and quit the loop ?
+                               if (strlen(trim(${"e_other$i"})) == 0)
+                                       continue;
+
+                               if ( $chdate == 2 ) $e_date=${'dateop'.$i};
+                               // if date is date of operation
+                               if ($chdate == 2 && $get_solde )
+                               {
+                                       $get_solde=false;
+                                       if ($this->check_periode() == true)
+                                       {
+                                               $pPeriode->p_id = $periode;
+                                       }
+                                       else
+                                       {
+                                               
$pPeriode->find_periode($e_date);
+                                       }
+                                       $exercice = $pPeriode->get_exercice();
+                                       $filter_year = "  j_tech_per in (select 
p_id from parm_periode where  p_exercice='" . $exercice . "')";
+                                       $solde = 
$acc_account->get_solde($filter_year);
+                                       $new_solde = $solde;
+                               }
+                               $fPoste = new Fiche($this->db);
+                               $fPoste->get_by_qcode(${"e_other$i"});
+
+                               // round it
+                               ${"e_other$i" . "_amount"} = 
round(${"e_other$i" . "_amount"}, 2);
+
+
+
+                               $amount+=${"e_other$i" . "_amount"};
+                               // Record a line for the bank
+                               // Compute the j_grpt
+                               $seq = $this->db->get_next_seq('s_grpt');
+
+                               $acc_operation = new Acc_Operation($this->db);
+                               $acc_operation->date = $e_date;
+                               $sposte = 
$fPoste->strAttribut(ATTR_DEF_ACCOUNT);
+                               // if 2 accounts
+                               if (strpos($sposte, ',') != 0)
+                               {
+                                       $array = explode(',', $sposte);
+                                       if (${"e_other$i" . "_amount"} < 0)
+                                               $poste_val = $array[1];
+                                       else
+                                               $poste_val = $array[0];
+                               }
+                               else
+                               {
+                                       $poste_val = $sposte;
+                               }
+
+
+                               $acc_operation->poste = $poste_val;
+                               $acc_operation->amount = ${"e_other$i" . 
"_amount"} * (-1);
+                               $acc_operation->grpt = $seq;
+                               $acc_operation->jrn = $p_jrn;
+                               $acc_operation->type = 'd';
+
+                               if (isset($periode))
+                                       $tperiode = $periode;
+                               else
+                               {
+                                       $per = new Periode($this->db);
+                                       $tperiode = $per->find_periode($e_date);
+                               }
+                               $acc_operation->periode = $tperiode;
+                               $acc_operation->qcode = ${"e_other" . $i};
+                               $j_id = $acc_operation->insert_jrnx();
+
+                               $acc_operation = new Acc_Operation($this->db);
+                               $acc_operation->date = $e_date;
+                               $sposte = $fBank->strAttribut(ATTR_DEF_ACCOUNT);
+
+                               // if 2 accounts
+                               if (strpos($sposte, ',') != 0)
+                               {
+                                       $array = explode(',', $sposte);
+                                       if (${"e_other$i" . "_amount"} < 0)
+                                               $poste_val = $array[1];
+                                       else
+                                               $poste_val = $array[0];
+                               }
+                               else
+                               {
+                                       $poste_val = $sposte;
+                               }
+
+                               $acc_operation->poste = $poste_val;
+                               $acc_operation->amount = ${"e_other$i" . 
"_amount"};
+                               $acc_operation->grpt = $seq;
+                               $acc_operation->jrn = $p_jrn;
+                               $acc_operation->type = 'd';
+                               $acc_operation->periode = $tperiode;
+                               $acc_operation->qcode = $e_bank_account;
+                               $acc_operation->insert_jrnx();
+
+
+                               if (sql_string(${"e_other$i" . "_comment"}) == 
null)
+                               {
+                                       // if comment is blank set a default one
+                                       $comment = "  compte : " . 
$fBank->strAttribut(ATTR_DEF_NAME) . ' a ' .
+                                                       
$fPoste->strAttribut(ATTR_DEF_NAME);
+                               }
+                               else
+                               {
+                                       $comment = ${'e_other' . $i . 
'_comment'};
+                               }
+
+
+                               $acc_operation = new Acc_Operation($this->db);
+                               $acc_operation->jrn = $p_jrn;
+                               $acc_operation->amount = abs(${"e_other$i" . 
"_amount"});
+                               $acc_operation->date = $e_date;
+                               $acc_operation->desc = $comment;
+                               $acc_operation->grpt = $seq;
+                               $acc_operation->periode = $tperiode;
+                               $acc_operation->mt = $mt;
+                               $idx_operation++;
+                               $acc_operation->pj = '';
+
+                               if (trim($e_pj) != '' && 
$this->numb_operation() == true)
+                                       $acc_operation->pj = $e_pj . 
str_pad($idx_operation, 3, 0, STR_PAD_LEFT);
+
+                               if (trim($e_pj) != '' && 
$this->numb_operation() == false)
+                                       $acc_operation->pj = $e_pj;
+
+                               $jr_id = $acc_operation->insert_jrn();
+                               //        $acc_operation->set_pj();
+                               $this->db->exec_sql('update jrn set 
jr_pj_number=$1 where jr_id=$2', array($acc_operation->pj, $jr_id));
+                               $internal = $this->compute_internal_code($seq);
+
+
+                               if (trim(${"e_concerned" . $i}) != "")
+                               {
+                                       if (strpos(${"e_concerned" . $i}, ',') 
!= 0)
+                                       {
+                                               $aRapt = explode(',', 
${"e_concerned" . $i});
+                                               foreach ($aRapt as $rRapt)
+                                               {
+                                                       // Add a "concerned 
operation to bound these op.together
+                                                       //
+                                                        $rec = new 
Acc_Reconciliation($this->db);
+                                                       $rec->set_jr_id($jr_id);
+
+                                                       if (isNumber($rRapt) == 
1)
+                                                       {
+                                                               
$rec->insert($rRapt);
+                                                       }
+                                               }
+                                       }
+                                       else
+                                       if (isNumber(${"e_concerned" . $i}) == 
1)
+                                       {
+                                               $rec = new 
Acc_Reconciliation($this->db);
+                                               $rec->set_jr_id($jr_id);
+                                               
$rec->insert(${"e_concerned$i"});
+                                       }
+                               }
+
+                               // Set Internal code
+                               $this->grpt_id = $seq;
+                               /**
+                                * save also into quant_fin
+                                */
+                               $this->insert_quant_fin($fBank->id, $jr_id, 
$fPoste->id, ${"e_other$i" . "_amount"});
+
+                               if ($g_parameter->MY_ANALYTIC != "nu")
+                               {
+                                       // for each item, insert into 
operation_analytique */
+                                       $op = new Anc_Operation($this->db);
+                                       $op->oa_group = 
$this->db->get_next_seq("s_oa_group"); /* for analytic */
+                                       $op->j_id = $j_id;
+                                       $op->oa_date = $e_date;
+                                       $op->oa_debit = 'f';
+                                       $op->oa_description = 
sql_string($comment);
+                                       $op->save_form_plan($_POST, $i, $j_id);
+                               }
+
+
+                               $this->update_internal_code($internal);
+
+                               $js_detail = HtmlInput::detail_op($jr_id, 
$internal);
+                               // Compute display
+                               $row = td($e_date).td($js_detail) . 
td(${"e_other$i"}) . td($fPoste->strAttribut(ATTR_DEF_NAME)) . td(${"e_other" . 
$i . "_comment"}) . td(nbm(${"e_other$i" . "_amount"}), 'class="num"');
+                                $class=($i%2==0)?' class="even" ':' 
class="odd" ';
+                               $ret.=tr($row,$class);
+
+
+                               if ($i == 0)
+                               {
+                                       // first record we upload the files and
+                                       // keep variable to update other row of 
jrn
+                                       if (isset($_FILES))
+                                               $oid = 
$this->db->save_upload_document($seq);
+                               }
+                               else
+                               {
+                                       if ($oid != 0)
+                                       {
+                                            $this->db->exec_sql("update jrn 
set jr_pj=$1 , jr_pj_name=$2,
+                                            jr_pj_type=$3  where 
jr_grpt_id=$4",
+                                                
array($oid,$_FILES['pj']['name'] ,$_FILES['pj']['type'],$seq));
+                                       }
+                               }
+                       } // for nbitem
+                       // increment pj
+                       if (strlen(trim($e_pj)) != 0)
+                       {
+                               $this->inc_seq_pj();
+                       }
+                       $ret.='</table>';
+               }
+               catch (Exception $e)
+               {
+                       $r = '<span class="error">' .
+                       'Erreur dans l\'enregistrement ' .
+                       __FILE__ . ':' . __LINE__ . ' ' .
+                       $e->getMessage();
+                       $this->db->rollback();
+                       throw new Exception($r);
+               }
+               $this->db->commit();
+               $r = "";
+               $r.="<br>Ancien solde " . nbm($solde);
+               $new_solde = bcadd($new_solde, $amount);
+               $r.="<br>Nouveau solde " . nbm($new_solde);
+               $ret.=$r;
+               return $ret;
+       }
+
+       /**\brief display operation of a FIN ledger
+        * \return html code into a string
+        */
+
+       function show_ledger()
+       {
+               global $g_user;
+               echo dossier::hidden();
+               $hid = new IHidden();
+
+               $hid->name = "p_action";
+               $hid->value = "bank";
+               echo $hid->input();
+
+
+               $hid->name = "sa";
+               $hid->value = "l";
+               echo $hid->input();
+
+
+               $w = new ISelect();
+               // filter on the current year
+               $filter_year = " where p_exercice='" . $g_user->get_exercice() 
. "'";
+
+               $periode_start = $this->db->make_array("select 
p_id,to_char(p_start,'DD-MM-YYYY') from parm_periode $filter_year order by 
p_start,p_end", 1);
+               // User is already set User=new User($this->db);
+               $current = (isset($_GET['p_periode'])) ? $_GET['p_periode'] : 
-1;
+               $w->selected = $current;
+
+               echo '<form>';
+               echo 'Période  ' . $w->input("p_periode", $periode_start);
+               $wLedger = $this->select_ledger('fin', 3);
+
+               if ($wLedger == null)
+                       throw  new Exception(_('Pas de journal disponible'));
+
+               if (count($wLedger->value) > 1)
+               {
+                       $aValue = $wLedger->value;
+                       $wLedger->value[0] = array('value' => -1, 'label' => 
_('Tous les journaux financiers'));
+                       $idx = 1;
+                       foreach ($aValue as $a)
+                       {
+                               $wLedger->value[$idx] = $a;
+                               $idx++;
+                       }
+               }
+
+
+
+               echo 'Journal ' . $wLedger->input();
+               $w = new ICard();
+               $w->noadd = 'no';
+               $w->jrn = $this->id;
+               $qcode = (isset($_GET['qcode'])) ? $_GET['qcode'] : "";
+               echo dossier::hidden();
+               echo HtmlInput::hidden('p_action', 'bank');
+               echo HtmlInput::hidden('sa', 'l');
+               $w->name = 'qcode';
+               $w->value = $qcode;
+               $w->label = '';
+               $this->type = 'FIN';
+               $all = $this->get_all_fiche_def();
+               $w->extra = $all;
+               $w->extra2 = 'QuickCode';
+               $sp = new ISpan();
+               echo $sp->input("qcode_label", "", $qcode);
+               echo $w->input();
+
+               echo HtmlInput::submit('gl_submit', _('Rechercher'));
+               echo '</form>';
+
+               // Show list of sell
+               // Date - date of payment - Customer - amount
+               if ($current != -1)
+               {
+                       $filter_per = " and jr_tech_per=" . $current;
+               }
+               else
+               {
+                       $filter_per = " and jr_tech_per in (select p_id from 
parm_periode where p_exercice::integer=" .
+                                       $g_user->get_exercice() . ")";
+               }
+               /* security  */
+               if ($this->id != -1)
+                       $available_ledger = " and jr_def_id= " . $this->id . " 
and " . $g_user->get_ledger_sql();
+               else
+                       $available_ledger = " and " . $g_user->get_ledger_sql();
+               // Show list of sell
+               // Date - date of payment - Customer - amount
+               $sql = SQL_LIST_ALL_INVOICE . $filter_per . " and 
jr_def_type='FIN'" .
+                               " $available_ledger";
+               $step = $_SESSION['g_pagesize'];
+               $page = (isset($_GET['offset'])) ? $_GET['page'] : 1;
+               $offset = (isset($_GET['offset'])) ? $_GET['offset'] : 0;
+
+               $l = "";
+
+               // check if qcode contains something
+               if ($qcode != "")
+               {
+                       // add a condition to filter on the quick code
+                       $l = " and jr_grpt_id in (select j_grpt from jrnx where 
j_qcode=upper('$qcode')) ";
+               }
+
+               list($max_line, $list) = ListJrn($this->db, "where 
jrn_def_type='FIN' $filter_per $l $available_ledger "
+                               , null, $offset, 0);
+               $bar = navigation_bar($offset, $max_line, $step, $page);
+
+               echo "<hr> $bar";
+               echo $list;
+               echo "$bar <hr>";
+       }
+
+       /**
+        * return a string with the bank account, name and quick_code
+        */
+       function get_bank_name()
+       {
+               $this->bank_id = $this->db->get_value('select jrn_def_bank from 
jrn_def where jrn_def_id=$1', array($this->id));
+               $fBank = new Fiche($this->db, $this->bank_id);
+               $e_bank_account = " : " . $fBank->strAttribut(ATTR_DEF_BQ_NO);
+               $e_bank_name = " : " . $fBank->strAttribut(ATTR_DEF_NAME);
+               $e_bank_qcode = ": " . $fBank->strAttribut(ATTR_DEF_QUICKCODE);
+               return $e_bank_qcode . $e_bank_name . $e_bank_account;
+       }
+
+       /**
+        * return the fiche_id of the bank
+        */
+       function get_bank()
+       {
+               $bank_id = $this->db->get_value('select jrn_def_bank from 
jrn_def where jrn_def_id=$1', array($this->id));
+               return $bank_id;
+       }
+
+       /**
+        * return true is we numbere each operation
+        */
+       function numb_operation()
+       {
+               $a = $this->db->get_value('select jrn_def_num_op from jrn_def 
where jrn_def_id=$1', array($this->id));
+               if ($a == 1)
+                       return true;
+               return false;
+       }
+
+       /**
+        * insert into the quant_fin table
+        * @param $bank_id is the f_id of the bank
+        * @param $jr_id is the jrn.jr_id of the operation
+        * @param $other is the f_id of the benefit
+        * @param $amount is the amount
+        */
+       function insert_quant_fin($p_bankid, $p_jrid, $p_otherid, $p_amount)
+       {
+               $sql = "INSERT INTO quant_fin(qf_bank, jr_id, qf_other, 
qf_amount)
+                   VALUES ($1, $2, $3, $4);";
+
+               $this->db->exec_sql($sql, array($p_bankid, $p_jrid, $p_otherid, 
round($p_amount, 2)));
+       }
+
+}
diff --git a/include/class/class_acc_ledger_info.php 
b/include/class/class_acc_ledger_info.php
new file mode 100644
index 0000000..1d44e56
--- /dev/null
+++ b/include/class/class_acc_ledger_info.php
@@ -0,0 +1,216 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+// Copyright Author Dany De Bontridder address@hidden
+require_once  NOALYSS_INCLUDE.'/class/class_dossier.php';
+require_once  NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
+
+/*!\file
+ * \brief Manage additional info for Accountancy
+ */
+
+/*!
+ * \brief Manage the additionnal info for operation (from jrn), when an 
invoice is generated, 
+ * the order or other info are going to be stored and used in the detail.
+ * this class maps the table jrn_info
+ */
+class Acc_Ledger_Info
+{
+    var $cn;    /*!< connection */
+    var $ji_id;    /*!< primary key */
+    var $id_type;    /*!< type id */
+    var $jr_id;    /*!< primary key of the table jrn */
+    var $ji_value;     /*!< value for this */
+    function __construct($p_cn,$p_ji_id=0)
+    {
+        $this->cn=$p_cn;
+        $this->ji_id=$p_ji_id;
+    }
+    function insert()
+    {
+        if ( ! isset ($this->jr_id) ||
+                ! isset ($this->ji_value) ||
+                ! isset ($this->id_type ) )
+        {
+            echo 'Appel incorrecte '.__FILE__.__LINE__;
+            var_dump($this);
+            throw new Exception(_('appel incorrect'));
+        }
+        try
+        {
+            $sql=$this->cn->exec_sql('insert into 
jrn_info(jr_id,id_type,ji_value) values ($1,$2,$3)'.
+                                     ' returning ji_id ',
+                                     array 
($this->jr_id,$this->id_type,$this->ji_value)
+                                    );
+            $this->ji_id=Database::fetch_result($sql,0,0);
+        }
+        catch (Exception $e)
+        {
+            echo "Echec sauvegarde info additionnelles";
+            throw $e;
+        }
+    }
+    function update()
+    {
+        if ( ! isset ($this->jr_id) ||
+                ! isset ($this->ji_value) ||
+                ! isset ($this->jr_id ) )
+        {
+            echo 'Appel incorrecte '.__FILE__.__LINE__;
+            var_dump($this);
+            throw  new Exception('appel incorrect');
+        }
+        try
+        {
+            $sql=$this->exec_sql('update jrn_info set jr_id=$1 
,id_type=$2,ji_value=$3 where ji_id=$4)'.
+                                 array 
($this->jr_id,$this->id_type,$this->ji_value,$this->ji_id)
+                                );
+        }
+        catch (Exception $e)
+        {
+            $this->cn->rollback();
+            echo "Echec sauvegarde info additionnelles";
+            throw $e;
+        }
+    }
+    function load()
+    {
+        $sql="select jr_id,id_type,ji_value from jrn_info where 
ji_id=".$this->ji_id;
+        $r=$this->cn->exec_sql($sql);
+        if (Database::num_row ($r) > 0 )
+        {
+            $this->from_array(Database::fetch_array($r,0));
+            return 0;
+        }
+        else
+        {
+            return 1;
+        }
+
+    }
+    function from_array($p_array)
+    {
+        foreach ($p_array as $col=>$value)
+        {
+            $this->$col=$value;
+        }
+    }
+    function set_id($p_ji_id)
+    {
+        $this->$ji_id=$p_ji_id;
+    }
+    function set_jrn_id($p_id)
+    {
+        $this->jr_id=$p_id;
+    }
+    function set_type($p_id)
+    {
+        $this->id_type=$p_id;
+    }
+    function set_value($p_id)
+    {
+        $this->ji_value=$p_id;
+    }
+    /*!\brief load all the jrn_info thanks the jr_id
+     * \return an array of object
+     */
+    function load_all()
+    {
+        if ( ! isset ($this->jr_id) )
+        {
+            echo "jr_id is not set ".__FILE__.__LINE__;
+            throw new Exception('Error : jr_id not set');
+        }
+
+        $sql="select ji_id from jrn_info where jr_id=".$this->jr_id;
+        $r=$this->cn->exec_sql($sql);
+        if (Database::num_row($r) == 0 )
+            return array();
+        $array=Database::fetch_all($r);
+        $ret=array();
+        foreach ($array as $row)
+        {
+            $o=new Acc_Ledger_Info($this->cn,$row['ji_id']);
+            $o->load();
+            $ret[]=clone $o;
+        }
+        return $ret;
+
+    }
+    function count()
+    {
+        $sql="select ji_id from jrn_info where jr_id=".$this->jr_id;
+        return $this->cn->count_sql($sql);
+    }
+    function search_id_internal($p_internal)
+    {
+        $sql="select jr_id from jrn where jr_internal='$p_internal'";
+        $r=$this->cn->exec_sql($sql);
+        if (Database::num_row($r) > 0 )
+        {
+            $this->jr_id=Database::fetch_result($r,0,0);
+            return $this->jr_id;
+        }
+        else
+        {
+            $this->jr_id=-1;
+            return $this->jr_id;
+        }
+    }
+    /**
+     address@hidden save all extra information in once, called by compta_ven 
and compta_ach
+     address@hidden $p_jr_id is the jrn.jr_id concerned, 
+     address@hidden $p_array is the array with the data usually it is $_POST
+     address@hidden will change this->jr_id
+     address@hidden compta_ven.inc.php compta_ach.inc.php
+     */
+    function save_extra($p_jr_id,$p_array)
+    {
+        $this->jr_id=$p_jr_id;
+        if (strlen(trim($p_array['bon_comm'] )) != 0 )
+        {
+            $this->set_type('BON_COMMANDE');
+            $this->set_value($p_array['bon_comm']);
+            $this->insert();
+        }
+        if (strlen(trim($p_array['other_info'] )) != 0 )
+        {
+            $this->set_type('OTHER');
+            $this->set_value($p_array['other_info']);
+            $this->insert();
+        }
+    }
+    static function test_me()
+    {
+        echo "Dossier = ".Dossier::id();
+        $cn=new Database(Dossier::id());
+        $a=new Acc_Ledger_Info($cn);
+        $a->jr_id=3;
+        $a->id_type='BON_COMMANDE';
+        $a->ji_value='BON';
+        var_dump($a);
+        $a->insert();
+
+        $a->set_jrn_id(7);
+        $a->set_type('OTHER');
+        $a->set_value('Autre test');
+        $a->insert();
+    }
+}
diff --git a/include/class/class_acc_ledger_purchase.php 
b/include/class/class_acc_ledger_purchase.php
new file mode 100644
index 0000000..7100611
--- /dev/null
+++ b/include/class/class_acc_ledger_purchase.php
@@ -0,0 +1,1790 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief class for the purchase, herits from acc_ledger
+ */
+require_once NOALYSS_INCLUDE.'/lib/class_iselect.php';
+require_once NOALYSS_INCLUDE.'/lib/class_icard.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ispan.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ihidden.php';
+require_once NOALYSS_INCLUDE.'/lib/class_iperiod.php';
+require_once NOALYSS_INCLUDE.'/lib/class_idate.php';
+require_once NOALYSS_INCLUDE.'/lib/class_itext.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ifile.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_ledger.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_compute.php';
+require_once NOALYSS_INCLUDE.'/class/class_anc_operation.php';
+require_once NOALYSS_INCLUDE.'/lib/user_common.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_parm_code.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_payment.php';
+require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
+require_once NOALYSS_INCLUDE.'/lib/class_itva_popup.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_ledger_info.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_ledger_fin.php';
+require_once NOALYSS_INCLUDE.'/class/class_stock_goods.php';
+
+/*!\brief Handle the ledger of purchase,
+ *
+ *
+ */
+class  Acc_Ledger_Purchase extends Acc_Ledger
+{
+    function __construct ($p_cn,$p_init)
+    {
+        $this->type='ACH';
+        parent::__construct($p_cn,$p_init);
+    }
+    /*!\brief verify that the data are correct before inserting or confirming
+     *\param an array (usually $_POST)
+     *\return String
+     *\throw Exception if an error occurs
+     */
+    public function verify($p_array)
+    {
+        global $g_parameter,$g_user;
+        
+        if (is_array($p_array ) == false || empty($p_array))
+                    throw new Exception ("Array empty");
+        /*
+         * Check needed value
+         */
+        check_parameter($p_array,'p_jrn,e_date,e_client');
+
+        extract ($p_array);
+        /* check if we can write into this ledger */
+        if ( $g_user->check_jrn($p_jrn) != 'W' )
+            throw new Exception (_('Accès interdit'),20);
+
+
+        /* check for a double reload */
+        if (  isset($mt) && $this->db->count_sql('select jr_mt from jrn where 
jr_mt=$1',array($mt)) != 0 )
+            throw new Exception (_('Double Encodage'),5);
+
+        /* check if there is a customer */
+        if ( strlen(trim($e_client)) == 0 )
+            throw new Exception(_('Vous n\'avez pas donné de fournisseur'),11);
+
+        /*  check if the date is valid */
+        if ( isDate($e_date) == null )
+        {
+            throw new Exception(_('Date invalide'), 2);
+        }
+        $oPeriode=new Periode($this->db);
+        if ( $this->check_periode() == false)
+        {
+            $tperiode=$oPeriode->find_periode($e_date);
+        }
+        else
+        {
+            $tperiode=$period;
+            $oPeriode->p_id=$tperiode;
+            /* check that the datum is in the choosen periode */
+            list ($min,$max)=$oPeriode->get_date_limit($tperiode);
+            if ( cmpDate($e_date,$min) < 0 ||
+                    cmpDate($e_date,$max) > 0)
+                throw new Exception(_('Date et periode ne correspondent 
pas'),6);
+        }
+        /* check if the periode is closed */
+        if ( $this->is_closed($tperiode)==1 )
+        {
+            throw new Exception(_('Periode fermee'),6);
+        }
+
+        /* check if we are using the strict mode */
+        if( $this->check_strict() == true)
+        {
+            /* if we use the strict mode, we get the date of the last
+            operation */
+            $last_date=$this->get_last_date();
+            if ( $last_date != null  && cmpDate($e_date,$last_date) < 0 )
+                throw new Exception(_('Vous utilisez le mode strict la 
dernière operation est à la date du ')
+                                    .$last_date._(' vous ne pouvez pas encoder 
à une '.
+                                                  ' date antérieure dans ce 
journal'),13);
+
+        }
+
+        /* check the account */
+        $fiche=new Fiche($this->db);
+        $fiche->get_by_qcode($e_client);
+
+        if ( $fiche->empty_attribute(ATTR_DEF_ACCOUNT) == true)
+            throw new Exception(_('La fiche ').$e_client._('n\'a pas de poste 
comptable'),8);
+
+        /* get the account and explode if necessary */
+        $sposte=$fiche->strAttribut(ATTR_DEF_ACCOUNT);
+        // if 2 accounts, take only the credit one for supplier
+        if ( strpos($sposte,',') != 0 )
+        {
+            $array=explode(',',$sposte);
+            $poste_val=$array[1];
+        }
+        else
+        {
+            $poste_val=$sposte;
+        }
+
+        /* The account exists */
+        $poste=new Acc_Account_Ledger($this->db,$poste_val);
+        if ( $poste->load() == false )
+        {
+            throw new Exception(_('Pour la fiche ').$e_client._(' le poste 
comptable [').$poste->id.'] '._('n\'existe pas'),9);
+        }
+        /* Check if the card belong to the ledger */
+        $fiche=new Fiche ($this->db);
+        $fiche->get_by_qcode($e_client,'cred');
+        if ( $fiche->belong_ledger($p_jrn) !=1 )
+            throw new Exception(_('La fiche ').$e_client._('n\'est pas 
accessible à ce journal'),10);
+
+        $nb=0;
+        //------------------------------------------------------
+        // The "Paid By"  check
+        //------------------------------------------------------
+        if ($e_mp != 0 ) $this->check_payment($e_mp,${"e_mp_qcode_".$e_mp});
+
+
+        //----------------------------------------
+        // foreach item
+        //----------------------------------------
+        for ($i=0;$i< $nb_item;$i++)
+        {
+            if ( strlen(trim(${'e_march'.$i}))== 0) continue;
+            /* check if amount are numeric and */
+            if ( isNumber(${'e_march'.$i.'_price'}) == 0 )
+                throw new Exception(_('La fiche ').${'e_march'.$i}._('a un 
montant invalide').' ['.${'e_march'.$i}.']',6);
+            if ( isNumber(${'e_quant'.$i}) == 0 )
+                throw new Exception(_('La fiche ').${'e_march'.$i}._('a une 
quantité invalide').' ['.${'e_quant'.$i}.']',7);
+
+            // Check if the given tva id is valid
+            if ( $g_parameter->MY_TVA_USE=='Y')
+            {
+                if (${'e_march'.$i.'_tva_id'} == 0 )
+                    throw new Exception(_('La fiche ').${'e_march'.$i}._('a un 
code tva invalide').' ['.${'e_march'.$i.'_tva_id'}.']',13);
+                $tva_rate=new Acc_Tva($this->db);
+                $tva_rate->set_parameter('id',${'e_march'.$i.'_tva_id'});
+
+                if ( $tva_rate->load() != 0 )
+                    throw new Exception(_('La fiche ').${'e_march'.$i}._('a un 
code tva invalide').' ['.${'e_march'.$i.'_tva_id'}.']',13);
+               /*
+                * check if the accounting for VAT are valid
+                */
+               $a_poste=explode(',',$tva_rate->tva_poste);
+
+               if (
+                   $this->db->get_value('select count(*) from tmp_pcmn where 
pcm_val=$1',array($a_poste[0])) == 0 ||
+                   $this->db->get_value('select count(*) from tmp_pcmn where 
pcm_val=$1',array($a_poste[1])) == 0 )
+                 throw new Exception(_(" La TVA ".$tva_rate->tva_label." 
utilise des postes comptables inexistants"));
+
+            }
+            /* check if all card has a ATTR_DEF_ACCOUNT*/
+            $fiche=new Fiche($this->db);
+            $fiche->get_by_qcode(${'e_march'.$i});
+            if ( $fiche->empty_attribute(ATTR_DEF_ACCOUNT) == true)
+                throw new Exception(_('La fiche ').${'e_march'.$i}._('n\'a pas 
de poste comptable'),8);
+
+            /* get the account and explode if necessary */
+            $sposte=$fiche->strAttribut(ATTR_DEF_ACCOUNT);
+            // if 2 accounts, take only the  debit
+            if ( strpos($sposte,',') != 0 )
+            {
+                $array=explode(',',$sposte);
+                $poste_val=$array[0];
+            }
+            else
+            {
+                $poste_val=$sposte;
+            }
+
+            /* The account exists */
+            $poste=new Acc_Account_Ledger($this->db,$poste_val);
+            if ( $poste->load() == false )
+            {
+                throw new Exception(_('Pour la fiche ').${'e_march'.$i}._(' le 
poste comptable').' ['.$poste->id._('n\'existe pas'),9);
+            }
+            /* Check if the card belong to the ledger */
+            $fiche=new Fiche ($this->db);
+            $fiche->get_by_qcode(${'e_march'.$i});
+            if ( $fiche->belong_ledger($p_jrn,'deb') !=1 )
+                throw new Exception(_('La fiche ').${'e_march'.$i}._('n\'est 
pas accessible à ce journal'),10);
+            /**
+             * we have to check also if the different accountings exist
+             "ATTR_DEF_DEP_PRIV"
+             "ATTR_DEF_DEPENSE_NON_DEDUCTIBLE"
+             "ATTR_DEF_TVA_NON_DEDUCTIBLE"
+             "ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP"
+            */
+            foreach (array(
+                          
array(ATTR_DEF_DEPENSE_NON_DEDUCTIBLE,'DNA',ATTR_DEF_ACCOUNT_ND),
+                          
array(ATTR_DEF_DEP_PRIV,'DEP_PRIV',ATTR_DEF_ACCOUNT_ND_PERSO),
+                          
array(ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP,'TVA_DED_IMPOT',ATTR_DEF_ACCOUNT_ND_TVA),
+                          
array(ATTR_DEF_TVA_NON_DEDUCTIBLE,'TVA_DNA',ATTR_DEF_ACCOUNT_ND_TVA_ND)) as 
$key)
+             {
+                if ( ! $fiche->empty_attribute($key[0]) &&  
$fiche->empty_attribute($key[2]))
+                 {
+                    $a=new Acc_Parm_Code($this->db,$key[1]);
+                    if ( $this->db->count_sql('select pcm_val from tmp_pcmn 
where pcm_val=$1',array($a->p_value))==0)
+                     throw new Exception ($key[1]._("ce code n'a pas de poste 
comptable, créez ce poste : [".$a->p_value."]"));
+                 }
+               if ( ! $fiche->empty_attribute($key[0]) &&  ! 
$fiche->empty_attribute($key[2]))
+                 {
+                   $nd_str=$fiche->strAttribut($key[2]);
+                   if ( $nd_str != '')
+                     {
+                       $poste_nd=new Acc_Account_Ledger($this->db,$nd_str);
+                       if ( $poste_nd->load() == false)
+                         {
+                           $nd_msg=sprintf(_("Pour la fiche %s, le compte 
contrepartie %s n'existe pas"),
+                                           $fiche->getName(),$poste_nd->id);
+                           $nd_msg=h($nd_msg);
+                           throw new Exception ($nd_msg);
+                         }
+                     }
+                 }
+             }
+           $nb++;
+        }
+
+        if ( $nb == 0 )
+            throw new Exception(_('Il n\'y a aucune marchandise'),12);
+
+    }
+    /**
+     * Compute the ND amount thanks the attribute of the concerned card. The 
object 
+     * $p_nd_amount will changed
+     * 
+     * @param Acc_Compute $p_nd_amount object with ND amount
+     * @param Fiche $p_fiche Concerned Card (purchase items)
+     * @param type $p_tva_bot 0 TVA on one side, 1 TVA on both side
+     */
+    private function compute_no_deductible(Acc_Compute $p_nd_amount, Fiche 
$p_fiche)
+    {
+        if (!$p_fiche->empty_attribute(ATTR_DEF_DEPENSE_NON_DEDUCTIBLE))
+        {
+            $p_nd_amount->amount_nd_rate = 
$p_fiche->strAttribut(ATTR_DEF_DEPENSE_NON_DEDUCTIBLE);
+            $p_nd_amount->compute_nd();
+        }
+        if (!$p_fiche->empty_attribute(ATTR_DEF_TVA_NON_DEDUCTIBLE) )
+        {
+            $p_nd_amount->nd_vat_rate = 
$p_fiche->strAttribut(ATTR_DEF_TVA_NON_DEDUCTIBLE);
+            $p_nd_amount->compute_nd_vat();
+        }
+        if (!$p_fiche->empty_attribute(ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP) )
+        {
+            $p_nd_amount->nd_ded_vat_rate = 
$p_fiche->strAttribut(ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP);
+            $p_nd_amount->compute_ndded_vat();
+        }
+
+        if (!$p_fiche->empty_attribute(ATTR_DEF_DEP_PRIV))
+        {
+            $p_nd_amount->amount_perso_rate = 
$p_fiche->strAttribut(ATTR_DEF_DEP_PRIV);
+            $p_nd_amount->compute_perso();
+        }
+
+    }
+
+    /**
+     * Insert into JRNX the No Deductible amount and into Analytic Accountancy 
for the ND VAT
+     * @param Acc_Compute $p_nd_amount content ND amount
+     * @param Fiche $p_fiche Card of the Service
+     * @param type $p_tva_both  0 if TVA is normal or 1 if on both side
+     * @param type $p_tot_debit total debit
+     * @param $p_acc_operation Acc_Operation for inserting into jrnx
+     * @param $p_group group for AC
+     * @param $idx row number
+     * 
+     * @see Acc_Ledger_Purchase::insert
+     */
+    private function insert_no_deductible(Acc_Compute $p_nd_amount, Fiche 
$p_fiche, $p_tva_both,&$p_tot_debit,Acc_Operation 
$p_acc_operation,$p_group,$idx)
+    {
+        global $g_parameter;
+        if ($p_acc_operation->jrnx_id == 0) {
+            throw new Exception(__FILE__.__LINE__.'invalid 
acc_operation.j_id');
+        }
+        $source_j_id=$p_acc_operation->jrnx_id ;
+        /*
+         * Save all the no deductible
+         *     
ATTR_DEF_ACCOUNT_ND_TVA,ATTR_DEF_ACCOUNT_ND_TVA_ND,ATTR_DEF_ACCOUNT_ND_PERSO,ATTR_DEF_ACCOUNT_ND
+         */
+        if ($p_nd_amount->amount_nd_rate != 0)
+        {
+            $dna_default = new Acc_Parm_Code($this->db, 'DNA');
+
+            /* save op. */
+            if (!$p_fiche->empty_attribute(ATTR_DEF_ACCOUNT_ND))
+            {
+                $dna = $p_fiche->strAttribut(ATTR_DEF_ACCOUNT_ND);
+            } else
+            {
+                $dna = $dna_default->p_value;
+            }
+            $dna = ($dna == '') ? $dna_default->p_value : $dna;
+
+            $p_acc_operation->type = 'd';
+            $p_acc_operation->amount = $p_nd_amount->amount_nd;
+            $p_acc_operation->poste = $dna;
+            $p_acc_operation->qcode = '';
+            $p_acc_operation->desc=$this->find_label($dna)." ND 
".$p_fiche->strAttribut(ATTR_DEF_QUICKCODE);
+            if ($p_nd_amount->amount_nd > 0)
+                $p_tot_debit = bcadd($p_tot_debit, $p_nd_amount->amount_nd );
+            $j_id = $p_acc_operation->insert_jrnx();
+        }
+        /*
+         * ATTR_DEF_ACCOUNT_ND_PERSO
+         */
+        if ($p_nd_amount->amount_perso != 0)
+        {
+            $dna_default = new Acc_Parm_Code($this->db, 'DEP_PRIV');
+
+            /* save op. */
+            $p_acc_operation->type = 'd';
+            if (!$p_fiche->empty_attribute(ATTR_DEF_ACCOUNT_ND_PERSO))
+            {
+                $dna = $p_fiche->strAttribut(ATTR_DEF_ACCOUNT_ND_PERSO);
+            } else
+            {
+                $dna = $dna_default->p_value;
+            }
+            $dna = ($dna == '') ? $dna_default->p_value : $dna;
+
+            $p_acc_operation->amount = $p_nd_amount->amount_perso ;
+            $p_acc_operation->poste = $dna;
+            $p_acc_operation->qcode = '';
+            $p_acc_operation->desc=$this->find_label($dna)." ND_PRIV 
".$p_fiche->strAttribut(ATTR_DEF_QUICKCODE);
+            if ($p_nd_amount->amount_perso> 0)
+                $p_tot_debit = bcadd($p_tot_debit, $p_nd_amount->amount_perso);
+            $j_id = $p_acc_operation->insert_jrnx();
+        }
+        if ($p_nd_amount->nd_vat != 0)
+        {
+            $dna_default = new Acc_Parm_Code($this->db, 'TVA_DNA');
+
+            /* save op. */
+            $p_acc_operation->type = 'd';
+            $p_acc_operation->qcode = '';
+            if (!$p_fiche->empty_attribute(ATTR_DEF_ACCOUNT_ND_TVA_ND) )
+            {
+                $dna = $p_fiche->strAttribut(ATTR_DEF_ACCOUNT_ND_TVA_ND);
+            } else
+            {
+                $dna = $dna_default->p_value;
+            }
+            $dna = ($dna == '') ? $dna_default->p_value : $dna;
+
+            $p_acc_operation->amount = $p_nd_amount->nd_vat;
+            $p_acc_operation->poste = $dna;
+            $p_acc_operation->desc=$this->find_label($dna)." ND_TVA 
".$p_fiche->strAttribut(ATTR_DEF_QUICKCODE);
+            $j_id = $p_acc_operation->insert_jrnx();
+            if ( $g_parameter->MY_ANALYTIC != "nu" )
+            {
+                $op=new Anc_Operation($this->db);
+                $op->oa_group=$p_group;
+                $op->j_id=$j_id;
+                $op->oa_date=$p_acc_operation->date;
+
+                $op->oa_debit='t';
+                $op->oa_description=sql_string('ND_TVA');
+                $op->oa_jrnx_id_source=$source_j_id;
+                
$op->save_form_plan_vat_nd($_POST,$idx,$j_id,$p_nd_amount->nd_vat,$p_acc_operation->jrnx_id);
+            }
+            if ($p_nd_amount->nd_vat> 0)
+                $p_tot_debit = bcadd($p_tot_debit, $p_nd_amount->nd_vat);
+            
+        }
+        if ($p_nd_amount->nd_ded_vat != 0)
+        {
+            $dna_default = new Acc_Parm_Code($this->db, 'TVA_DED_IMPOT');
+            /* save op. */
+            if (!$p_fiche->empty_attribute(ATTR_DEF_ACCOUNT_ND_TVA) )
+            {
+                $dna = $p_fiche->strAttribut(ATTR_DEF_ACCOUNT_ND_TVA);
+            } else
+            {
+                $dna = $dna_default->p_value;
+            }
+            $dna = ($dna == '') ? $dna_default->value : $dna;
+
+
+
+            $p_acc_operation->type = 'd';
+            $p_acc_operation->qcode = '';
+            $p_acc_operation->amount = $p_nd_amount->nd_ded_vat;
+            $p_acc_operation->poste = $dna;
+            $p_acc_operation->desc=$this->find_label($dna)." DED_TVA 
".$p_fiche->strAttribut(ATTR_DEF_QUICKCODE);
+            if ($p_nd_amount->nd_ded_vat > 0)
+                $p_tot_debit = bcadd($p_tot_debit, $p_nd_amount->nd_ded_vat);
+            $j_id = $p_acc_operation->insert_jrnx();
+           if ( $g_parameter->MY_ANALYTIC != "nu" )
+            {
+                $op=new Anc_Operation($this->db);
+                $op->oa_group=$p_group;
+                $op->j_id=$j_id;
+                $op->oa_date=$p_acc_operation->date;
+
+                $op->oa_debit='t';
+                $op->oa_description=sql_string('DED_TVA ');
+                $op->oa_jrnx_id_source=$source_j_id;
+                
$op->save_form_plan_vat_nd($_POST,$idx,$j_id,$p_nd_amount->nd_ded_vat);
+            }
+        }
+    }
+
+    /*!\brief insert into the database, it calls first the verify function
+     * change the value of this->jr_id and this->jr_internal.
+     * It generates the document and save the middle of payment, if 
'gen_invoice is set
+     * and e_mp
+     *\param $p_array is usually $_POST or a predefined operation
+    \code
+     Array
+    (
+
+      [e_client] =>BELGACOM
+      [nb_item] =>9
+      [p_jrn] =>3
+      [period] =>117
+      [e_comm] =>Frais de téléphone
+      [e_date] =>01.09.2009
+      [e_ech] =>
+      [jrn_type] =>ACH
+      [e_pj] =>ACH53
+      [e_pj_suggest] =>ACH53
+      [mt] =>1265318941.39
+      [e_mp] =>0
+      [e_march0] =>TEL
+      [e_march0_price] =>63.6700
+      [e_march0_tva_id] =>1
+      [e_march0_tva_amount] =>13.3700
+      [e_quant0] =>1.000
+      ...
+      [bon_comm] =>
+      [other_info] =>
+      [record] =>Enregistrement
+    )
+    \endcode
+     *\return string
+     *\note throw an Exception
+     */
+    public function insert($p_array=null)
+    {
+        global $g_parameter;
+        extract ($p_array);
+        $this->verify($p_array) ;
+
+        $group=$this->db->get_next_seq("s_oa_group"); /* for analytic */
+        $seq=$this->db->get_next_seq('s_grpt');
+        $this->id=$p_jrn;
+
+        $internal=$this->compute_internal_code($seq);
+        $this->internal=$internal;
+
+        $cust=new Fiche($this->db);
+        $cust->get_by_qcode($e_client);
+        $sposte=$cust->strAttribut(ATTR_DEF_ACCOUNT);
+        // if 2 accounts, take only the credit Supplier
+        if ( strpos($sposte,',') != 0 )
+        {
+            $array=explode(',',$sposte);
+            $poste=$array[1];
+        }
+        else
+        {
+            $poste=$sposte;
+        }
+
+        $oPeriode=new Periode($this->db);
+        $check_periode=$this->check_periode();
+
+        if ( $check_periode == true )
+            $tperiode=$period;
+        else
+            $tperiode=$oPeriode->find_periode($e_date);
+
+        bcscale(4);
+        try
+        {
+            $tot_amount=0;
+            $tot_tva=0;
+            $tot_debit=0;
+            $this->db->start();
+            $tot_nd=0;
+            $tot_perso=0;
+            $tot_tva_nd=0;
+            $tot_tva_ndded=0;
+            $tot_tva_reversed=0;
+                       $tva=array();
+            /* Save all the items without vat and no deductible vat and 
expense*/
+            for ($i=0;$i< $nb_item;$i++)
+            {
+               $n_both=0;
+                if ( strlen(trim(${'e_march'.$i})) == 0 ) continue;
+
+                /* First we save all the items without vat */
+                $fiche=new Fiche($this->db);
+                $fiche->get_by_qcode(${"e_march".$i});
+               $tva_both=0;
+                /* tva */
+                if ($g_parameter->MY_TVA_USE=='Y')
+                {
+                    $idx_tva=${'e_march'.$i.'_tva_id'};
+                    $oTva=new Acc_Tva($this->db);
+                    $oTva->set_parameter('id',$idx_tva);
+                    $oTva->load();
+                    $tva_both=$oTva->get_parameter("both_side");
+                }
+                /* -- Create acc_operation -- */
+                $acc_operation=new Acc_Operation($this->db);
+                $acc_operation->date=$e_date;
+                $acc_operation->grpt=$seq;
+                $acc_operation->jrn=$p_jrn;
+                $acc_operation->type='d';
+                $acc_operation->periode=$tperiode;
+                $acc_operation->qcode="";
+                
+                
+                /* We have to compute all the amount thanks Acc_Compute */
+                
$amount=round(bcmul(${'e_march'.$i.'_price'},${'e_quant'.$i}),2);
+                
+                $acc_amount=new Acc_Compute();
+                $acc_amount->check=false;
+                $acc_amount->set_parameter('amount',$amount);
+                
+                // Compute VAT or take the given one
+                if ( $g_parameter->MY_TVA_USE=='Y')
+                {
+                    
$acc_amount->set_parameter('amount_vat_rate',$oTva->get_parameter('rate'));
+                    if ( strlen(trim(${'e_march'.$i.'_tva_amount'})) ==0 || 
${'e_march'.$i.'_tva_amount'} == 0)
+                    {
+                        $acc_amount->compute_vat();
+
+                    }
+                    else
+                    {
+                        $acc_amount->amount_vat= ${'e_march'.$i.'_tva_amount'};
+
+                    }
+                   $tot_tva=bcadd($tot_tva,$acc_amount->amount_vat);
+                }
+
+               
+                /* compute ND */
+                $save_amount_vat=$acc_amount->amount_vat;
+                $this->compute_no_deductible($acc_amount, $fiche);
+                $acc_amount->correct();
+                // TVA which avoid 
+                $acc_amount->amount_unpaid=($tva_both == 1 ) ? 
$save_amount_vat :0 ;
+                
$tot_tva_reversed=bcadd($tot_tva_reversed,$acc_amount->amount_unpaid);
+                
+
+              
+                $tot_amount=round(bcadd($tot_amount,$amount),2);
+
+                /* get the account and explode if necessary */
+                $sposte=$fiche->strAttribut(ATTR_DEF_ACCOUNT);
+                // if 2 accounts, take only the debit one for customer
+                if ( strpos($sposte,',') != 0 )
+                {
+                    $array=explode(',',$sposte);
+                    $poste_val=$array[0];
+                }
+                else
+                {
+                    $poste_val=$sposte;
+                }
+                if ( $g_parameter->MY_UPDLAB=='Y')
+                    $acc_operation->desc=strip_tags(${"e_march".$i."_label"});
+                else
+                    $acc_operation->desc=null;
+                $acc_operation->poste=$poste_val;
+                $acc_operation->amount=$acc_amount->amount;
+                $acc_operation->qcode=${"e_march".$i};
+                if( $acc_amount->amount > 0 ) 
$tot_debit=bcadd($tot_debit,$acc_amount->amount);
+                $j_id=$acc_operation->insert_jrnx();
+                
+                /* insert ND */
+                $this->insert_no_deductible($acc_amount, $fiche, $tva_both, 
$tot_debit,$acc_operation,$group,$i);
+
+                
+                /* Compute sum vat */
+                if ( $g_parameter->MY_TVA_USE=='Y')
+                {
+                    $tva_item=$acc_amount->amount_vat;
+
+                    if (isset($tva[$idx_tva] ) )
+                        $tva[$idx_tva]=bcadd($tva[$idx_tva],$tva_item);
+                    else
+                        $tva[$idx_tva]=$tva_item;
+
+                }
+                /* Save the stock */
+                /* if the quantity is < 0 then the stock increase (return of
+                 *  material)
+                 */
+                $nNeg=(${"e_quant" . $i}< 0) ? -1 : 1;
+
+                // always save quantity but in withStock we can find
+                // what card need a stock management
+                if ( $g_parameter->MY_STOCK='Y'&& isset ($repo))
+                {
+                    $dir=(${'e_quant'.$i} < 0 ) ? 'c':'d';
+                    
Stock_Goods::insert_goods($this->db,array('j_id'=>$j_id,'goods'=>${'e_march'.$i},'quant'=>$nNeg*${'e_quant'.$i},'dir'=>$dir,'repo'=>$repo))
 ;
+                }
+
+                if ( $g_parameter->MY_ANALYTIC != "nu" )
+                {
+                    // for each item, insert into operation_analytique */
+                    $op=new Anc_Operation($this->db);
+                    $op->oa_group=$group;
+                    $op->j_id=$j_id;
+                    $op->oa_date=$e_date;
+                    $op->oa_debit='t';
+                    $op->oa_description=sql_string($e_comm);
+                    $op->save_form_plan($_POST,$i,$j_id);
+                }
+                // insert into quant_purchase
+                //-----
+                if ( $g_parameter->MY_TVA_USE=='Y')
+                {
+
+                    $r=$this->db->exec_sql("select insert_quant_purchase ".
+                                           "(null".
+                                           ",".$j_id.           /* 2 */
+                                           ",'".${"e_march".$i}."'". /* 3 */
+                                           ",".${"e_quant".$i}.",".  /* 4 */
+                                           round($amount,2).          /* 5 */
+                                           ",".$acc_amount->amount_vat. /* 6 */
+                                           ",".$oTva->get_parameter('id'). /* 
7 */
+                                           ",".$acc_amount->amount_nd.     /* 
8 */
+                                           ",".$acc_amount->nd_vat.         /* 
9 */
+                                           ",".$acc_amount->nd_ded_vat.    /* 
10 */
+                                           ",".$acc_amount->amount_perso.  /* 
11 */ 
+                                           ",'".$e_client."',". 
$acc_amount->amount_unpaid.")");            /* 12 */
+
+                }
+                else
+                {
+                    $r=$this->db->exec_sql("select insert_quant_purchase ".
+                                           "(null".
+                                           ",".$j_id.
+                                           ",'".${"e_march".$i}."'".
+                                           ",".${"e_quant".$i}.",".
+                                           round($amount,2).
+                                           ",0".
+                                           ",null".
+                                           ",".$acc_amount->amount_nd.
+                                           ",0".
+                                           ",".$acc_amount->nd_ded_vat.
+                                           ",".$acc_amount->amount_perso.
+                                           
",'".$e_client."',".$acc_amount->amount_unpaid.")");
+
+
+                }
+
+            }       // end loop : save all items
+            /*  save total customer */
+            $cust_amount=round(bcadd($tot_amount,$tot_tva),2);
+            $acc_operation=new Acc_Operation($this->db);
+            $acc_operation->date=$e_date;
+            $acc_operation->poste=$poste;
+            $acc_operation->amount=$cust_amount-$tot_tva_reversed;
+            $acc_operation->grpt=$seq;
+            $acc_operation->jrn=$p_jrn;
+            $acc_operation->type='c';
+            $acc_operation->periode=$tperiode;
+            $acc_operation->qcode=${"e_client"};
+            if ( $cust_amount < 0 )
+                               $tot_debit=bcadd($tot_debit,abs($cust_amount));
+            $let_client=$acc_operation->insert_jrnx();
+            
+
+            if ( $g_parameter->MY_TVA_USE=='Y')
+            {
+                /* save all vat
+                 * $i contains the tva_id and value contains the vat amount
+                 */
+                foreach ($tva as $i => $value)
+                {
+                    $oTva=new Acc_Tva($this->db);
+                    $oTva->set_parameter('id',$i);
+                    $oTva->load();
+
+                    $poste_vat=$oTva->get_side('d');
+
+                    $cust_amount=bcadd($tot_amount,$tot_tva);
+                    $acc_operation=new Acc_Operation($this->db);
+                    $acc_operation->date=$e_date;
+                    $acc_operation->poste=$poste_vat;
+                    $acc_operation->amount=$value;
+                    $acc_operation->grpt=$seq;
+                    $acc_operation->jrn=$p_jrn;
+                    $acc_operation->type='d';
+                    $acc_operation->periode=$tperiode;
+                    if ( $value > 0 ) $tot_debit=bcadd($tot_debit,abs($value));
+                    $acc_operation->insert_jrnx();
+                    // if TVA is on both side, we deduce it immediately
+                    if ( $oTva->get_parameter("both_side")==1)
+                    {
+                        $poste_vat=$oTva->get_side('c');
+                        $cust_amount=bcadd($tot_amount,$tot_tva);
+                        $cust_amount=bcsub($tot_amount,$tot_tva_reversed);
+                        $acc_operation=new Acc_Operation($this->db);
+                        $acc_operation->date=$e_date;
+                        $acc_operation->poste=$poste_vat;
+                        $acc_operation->amount=$tot_tva_reversed;
+                        $acc_operation->grpt=$seq;
+                        $acc_operation->jrn=$p_jrn;
+                        $acc_operation->type='c';
+                        $acc_operation->periode=$tperiode;
+                        $acc_operation->insert_jrnx();
+                       if ( $value < 0 ) 
$tot_debit=bcadd($tot_debit,abs($value));
+                    }
+
+                }
+            }
+            /* insert into jrn */
+            $acc_operation=new Acc_Operation($this->db);
+            $acc_operation->date=$e_date;
+            $acc_operation->echeance=$e_ech;
+            $acc_operation->amount=abs(round($tot_debit,2));
+            $acc_operation->desc=$e_comm;
+            $acc_operation->grpt=$seq;
+            $acc_operation->jrn=$p_jrn;
+            $acc_operation->periode=$tperiode;
+            $acc_operation->pj=$e_pj;
+            $acc_operation->mt=$mt;
+            $this->jr_id=$acc_operation->insert_jrn();
+            $this->pj=$acc_operation->set_pj();
+
+            // Set Internal code
+            $this->grpt_id=$seq;
+            $this->update_internal_code($internal);
+            /* update quant_purchase */
+            $this->db->exec_sql('update quant_purchase set qp_internal = $1 
where j_id in (select j_id from jrnx where j_grpt=$2)',
+                                array($internal,$seq));
+
+            /**= e_pj then do not increment sequence */
+            if ( strcmp($e_pj,$e_pj_suggest) == 0 && strlen(trim($e_pj)) != 0 )
+            {
+                $this->inc_seq_pj();
+            }
+
+            /* Save the attachment */
+            if ( isset ($_FILES))
+            {
+                if ( sizeof($_FILES) != 0 )
+                    $this->db->save_upload_document($seq);
+            }
+            $str_file="";
+            /* Generate an document  and save it into the database (Note de 
frais only)
+             */
+            if ( isset($_POST['gen_invoice']) )
+            {
+                $ref_doc= $this->create_document($internal,$p_array);
+                $this->doc='<A class="line" 
HREF="show_pj.php?'.dossier::get().'&jr_grpt_id='.$seq.'&jrn='.$this->id.'">'.$ref_doc.'</A>';
+            }
+
+            //----------------------------------------
+            // Save the payer
+            //----------------------------------------
+            if ( $e_mp != 0 )
+            {
+                /* mp */
+                $mp=new Acc_Payment($this->db,$e_mp);
+                $mp->load();
+
+                /* fiche */
+                if ($mp->get_parameter('qcode') == '')
+                    $fqcode=${'e_mp_qcode_'.$e_mp};
+                else
+                    $fqcode=$mp->get_parameter('qcode');
+
+                $acfiche = new Fiche($this->db);
+                $acfiche->get_by_qcode($fqcode);
+
+                /* jrnx */
+                $acseq=$this->db->get_next_seq('s_grpt');
+                $acjrn=new 
Acc_Ledger($this->db,$mp->get_parameter('ledger_target'));
+                $acinternal=$acjrn->compute_internal_code($acseq);
+
+                /* Insert paid by  */
+                $acc_pay=new Acc_Operation($this->db);
+                $acc_pay->date=$e_date;
+
+                /* get the account and explode if necessary */
+                $sposte=$acfiche->strAttribut(ATTR_DEF_ACCOUNT);
+                // if 2 accounts, take only the debit one for customer
+                if ( strpos($sposte,',') != 0 )
+                {
+                    $array=explode(',',$sposte);
+                    $poste_val=$array[1];
+                }
+                else
+                {
+                    $poste_val=$sposte;
+                }
+
+                $famount=bcsub($cust_amount,$acompte);
+                $acc_pay->poste=$poste_val;
+                $acc_pay->qcode=$fqcode;
+                $acc_pay->amount=abs(round($famount,2));
+                $acc_pay->desc='';
+                $acc_pay->grpt=$acseq;
+                $acc_pay->jrn=$mp->get_parameter('ledger_target');
+                $acc_pay->periode=$tperiode;
+               $acc_pay->type=($famount>=0)?'c':'d';
+                $acc_pay->insert_jrnx();
+
+                /* Insert supplier  */
+                $acc_pay=new Acc_Operation($this->db);
+                $acc_pay->date=$e_date;
+                $acc_pay->poste=$poste;
+                $acc_pay->qcode=$e_client;
+                $acc_pay->amount=abs(round($famount,2));
+                $acc_pay->desc='';
+                $acc_pay->grpt=$acseq;
+                $acc_pay->jrn=$mp->get_parameter('ledger_target');
+                $acc_pay->periode=$tperiode;
+                               $acc_pay->type=($famount>=0)?'d':'c';
+                $let_other=$acc_pay->insert_jrnx();
+
+                /* insert into jrn */
+                $acc_pay->mt=$mt;
+                               $acc_pay->desc=(!isset($e_comm_paiement) || 
strlen(trim($e_comm_paiement)) == 0) ?$e_comm:$e_comm_paiement;
+                $mp_jr_id=$acc_pay->insert_jrn();
+                $acjrn->grpt_id=$acseq;
+                $acjrn->update_internal_code($acinternal);
+
+                $r1=$this->get_id($internal);
+                $r2=$this->get_id($acinternal);
+
+               /*
+                * add lettering
+                */
+               $oletter=new Lettering($this->db);
+               $oletter->insert_couple($let_client,$let_other);
+
+                /* set the flag paid */
+                $Res=$this->db->exec_sql("update jrn set jr_rapt='paid' where 
jr_id=$1",array($r1));
+
+                /* Reconcialiation */
+                $rec=new Acc_Reconciliation($this->db);
+                $rec->set_jr_id($r1);
+                $rec->insert($r2);
+               /*
+                * save also into quant_fin
+                */
+
+               /* get ledger property */
+               $ledger=new Acc_Ledger_Fin($this->db,$acc_pay->jrn);
+               $prop=$ledger->get_propertie();
+
+               /* if ledger is FIN then insert into quant_fin */
+               if ( $prop['jrn_def_type'] == 'FIN' )
+                 {
+                   
$ledger->insert_quant_fin($acfiche->id,$mp_jr_id,$cust->id,bcmul($famount,-1));
+                 }
+
+
+            }
+        }//end try
+        catch (Exception $e)
+        {
+            echo '<span class="error">'.
+            'Erreur dans l\'enregistrement '.
+            __FILE__.':'.__LINE__.' '.
+            $e->getMessage().$e->getTraceAsString();
+
+            $this->db->rollback();
+            throw  new Exception($e);
+        }
+        $this->db->commit();
+        return $internal;
+    }
+
+    /*!\brief display the form for entering data for invoice
+     *\param $p_array is null or you can put the predef operation or the $_POST
+    \code
+    array
+    'sa' => string 'n' (length=1)
+    'p_action' => string 'ach' (length=3)
+    'gDossier' => string '28' (length=2)
+    'e_client' => string 'ASEKURA' (length=7)
+    'nb_item' => string '9' (length=1)
+    'p_jrn' => string '3' (length=1)
+    'period' => string '126' (length=3)
+    'e_comm' => string 'descriptio' (length=10)
+    'e_date' => string '01.05.2010' (length=10)
+    'e_ech' => string '' (length=0)
+    'jrn_type' => string 'ACH' (length=3)
+    'e_pj' => string 'ACH37' (length=5)
+    'e_pj_suggest' => string 'ACH37' (length=5)
+    'mt' => string '1273759434.5701' (length=15)
+    'e_mp' => string '0' (length=1)
+    'e_march0' => string 'DOC' (length=3)
+    'e_march0_price' => string '2000' (length=4)
+    'e_march0_tva_id' => string '3' (length=1)
+    'e_march0_tva_amount' => string '120' (length=3)
+    'e_quant0' => string '1' (length=1)
+    'gen_invoice' => string 'on' (length=2)
+    'gen_doc' => string '7' (length=1)
+    'bon_comm' => string '' (length=0)
+    'other_info' => string '' (length=0)
+    'correct' => string 'Corriger' (length=8)
+    \endcode
+     *\return HTML string
+     */
+    public function input($p_array=null,$p_readonly=0)
+    {
+        global $g_parameter,$g_user;
+        if ( $p_array != null ) extract($p_array);
+
+        $flag_tva=$g_parameter->MY_TVA_USE;
+        /* Add button */
+        $f_add_button=new IButton('add_card');
+        $f_add_button->label=_('Créer une nouvelle fiche');
+               $f_add_button->tabindex=-1;
+        $f_add_button->set_attribute('jrn',$this->id);
+        $f_add_button->javascript=" 
this.jrn=\$('p_jrn').value;select_card_type(this);";
+
+        $str_add_button="";
+        if ($g_user->check_action(FICADD)==1)
+        {
+                $str_add_button=$f_add_button->input();
+        }
+        // The first day of the periode
+        $oPeriode=new Periode($this->db);
+        list 
($l_date_start,$l_date_end)=$oPeriode->get_date_limit($g_user->get_periode());
+        if (  $g_parameter->MY_DATE_SUGGEST=='Y' )
+            $op_date=( ! isset($e_date) ) ?$l_date_start:$e_date;
+        else
+            $op_date=( ! isset($e_date) ) ?'':$e_date;
+
+        $e_ech=(isset($e_ech))?$e_ech:"";
+        $e_comm=(isset($e_comm))?$e_comm:"";
+
+        $r="";
+        $r.=dossier::hidden();
+        $f_legend_detail=_("Détail articles achetés");
+
+        //  Date
+        //--
+        $Date=new IDate();
+        $Date->setReadOnly(false);
+        $Date->table=1;
+        $Date->tabindex=1;
+        $f_date=$Date->input("e_date",$op_date);
+        // Payment limit
+        //--
+        $Echeance=new IDate();
+        $Echeance->setReadOnly(false);
+        $Echeance->tabindex=2;
+        $label=HtmlInput::infobulle(4);
+        $f_echeance=$Echeance->input('e_ech',$e_ech,'Echéance'.$label);
+        $f_periode="";
+        if ($this->check_periode() == true)
+        {
+            // Periode
+            //--
+            $l_user_per=$g_user->get_periode();
+            $def=(isset($periode))?$periode:$l_user_per;
+
+            $period=new IPeriod("period");
+            $period->user=$g_user;
+            $period->cn=$this->db;
+            $period->value=$def;
+            $period->type=OPEN;
+            try
+            {
+                $l_form_per=$period->input();
+            }
+            catch (Exception $e)
+            {
+                if ($e->getCode() == 1 )
+                {
+                    throw new Exception( _("Aucune période ouverte"));
+                }
+            }
+
+            $r.="<td>";
+            $label=HtmlInput::infobulle(3);
+            $f_periode=_("Période comptable")." $label ".$l_form_per;
+        }
+        // Ledger (p_jrn)
+        //--
+        /* if we suggest the next pj, then we need a javascript */
+        $add_js="";
+        if ( $g_parameter->MY_PJ_SUGGEST=='Y')
+        {
+            $add_js="update_pj();";
+        }
+               if ($g_parameter->MY_DATE_SUGGEST == 'Y')
+               {
+                       $add_js.='get_last_date();';
+               }
+               $add_js.='update_name();';
+               $add_js.='update_pay_method();';
+               $add_js.='update_row("sold_item");';
+
+               $wLedger=$this->select_ledger('ACH',2);
+        if ($wLedger == null) throw  new Exception(_('Pas de journal 
disponible'));
+        
$wLedger->javascript="onChange='update_predef(\"ach\",\"f\",\"".$_REQUEST['ac']."\");$add_js'";
+        $wLedger->table=1;
+        $f_jrn=$wLedger->input();
+
+        // Comment
+        //--
+        $Commentaire=new IText();
+        $Commentaire->table=0;
+        $Commentaire->setReadOnly(false);
+        $Commentaire->size=60;
+        $Commentaire->tabindex=3;
+        $label=HtmlInput::infobulle(1) ;
+        $f_desc=$Commentaire->input("e_comm",h($e_comm));
+
+        // PJ
+        //--
+        /* suggest PJ ? */
+        $default_pj='';
+        if ( $g_parameter->MY_PJ_SUGGEST=='Y')
+        {
+            $default_pj=$this->guess_pj();
+        }
+
+        $pj=new IText();
+        $pj->value=(isset($e_pj))?$e_pj:$default_pj;
+
+
+        $pj->table=0;
+        $pj->name="e_pj";
+        $pj->size=10;
+        $pj->readonly=false;
+
+        $f_pj=$pj->input().HtmlInput::hidden('e_pj_suggest',$default_pj);
+
+        // Display the customer
+        //--
+        $fiche='cred';
+
+        // Save old value and set a new one
+        //--
+        $e_client=( isset ($e_client) )?$e_client:"";
+        $e_client_label="&nbsp;";//str_pad("",100,".");
+
+
+        // retrieve e_client_label
+        //--
+
+        if ( strlen(trim($e_client)) !=  0)
+        {
+            $fClient=new Fiche($this->db);
+            $fClient->get_by_qcode($e_client);
+            $e_client_label=$fClient->strAttribut(ATTR_DEF_NAME).' '.
+                            ' Adresse : 
'.$fClient->strAttribut(ATTR_DEF_ADRESS).' '.
+                            $fClient->strAttribut(ATTR_DEF_CP).' '.
+                            $fClient->strAttribut(ATTR_DEF_CITY).' ';
+
+
+        }
+
+        $W1=new ICard();
+        $W1->label=_("Fournisseur ").HtmlInput::infobulle(0) ;
+        $W1->name="e_client";
+        $W1->tabindex=3;
+        $W1->value=$e_client;
+        $W1->table=0;
+        $W1->set_dblclick("fill_ipopcard(this);");
+        $W1->set_attribute('ipopup','ipopcard');
+
+        // name of the field to update with the name of the card
+        $W1->set_attribute('label','e_client_label');
+        // name of the field to update with the name of the card
+        $W1->set_attribute('typecard','cred');
+
+        // Add the callback function to filter the card on the jrn
+        $W1->set_callback('filter_card');
+        $W1->set_function('fill_data');
+        $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
+                                $W1->name);
+        $f_client_qcode=$W1->input();
+        $client_label=new ISpan();
+        $client_label->table=0;
+        $f_client=$client_label->input("e_client_label",$e_client_label);
+        $f_client_bt=$W1->search();
+
+
+        // Record the current number of article
+
+        $e_comment=(isset($e_comment))?$e_comment:"";
+               $p_article= ( isset ($nb_item))?$nb_item:$this->get_min_row();
+        $max=($p_article < 
$this->get_min_row())?$this->get_min_row():$p_article;
+
+        $Hid=new IHidden();
+               $r.=$Hid->input("nb_item",$p_article);
+
+        // For each article
+        //--
+        for ($i=0;$i< $max ;$i++)
+        {
+            // Code id, price & vat code
+            //--
+            $march=(isset(${"e_march$i"}))?${"e_march$i"}:""                   
;
+            
$march_price=(isset(${"e_march".$i."_price"}))?${"e_march".$i."_price"}:""
+                         ;
+            /* use vat */
+            if ( $g_parameter->MY_TVA_USE=='Y')
+            {
+                
$march_tva_id=(isset(${"e_march$i"."_tva_id"}))?${"e_march$i"."_tva_id"}:"";
+                
$march_tva_amount=(isset(${"e_march$i"."_tva_amount"}))?${"e_march$i"."_tva_amount"}:"";
+            }
+
+
+
+            
$march_label=(isset(${"e_march".$i."_label"}))?${"e_march".$i."_label"}:"";
+            // retrieve the tva label and name
+            //--
+            if ( strlen(trim($march))!=0  && strlen(trim($march_label))==0 )
+            {
+                $fMarch=new Fiche($this->db);
+                $fMarch->get_by_qcode($march);
+                $march_label=$fMarch->strAttribut(ATTR_DEF_NAME);
+                /* vat use */
+                if ( ! isset($march_tva_id) && $g_parameter->MY_TVA_USE=='Y' )
+                    $march_tva_id=$fMarch->strAttribut(ATTR_DEF_TVA);
+            }
+            // Show input
+            //--
+            $W1=new ICard();
+            $W1->label="";
+            $W1->name="e_march".$i;
+            $W1->value=$march;
+            $W1->table=1;
+            $W1->set_dblclick("fill_ipopcard(this);");
+            $W1->set_attribute('ipopup','ipopcard');
+
+            $W1->set_attribute('typecard','deb');
+
+            // name of the field to update with the name of the card
+            $W1->set_attribute('label','e_march'.$i.'_label');
+            // name of the field with the price
+            $W1->set_attribute('purchase','e_march'.$i.'_price'); /* 
autocomplete */
+            $W1->set_attribute('price','e_march'.$i.'_price');    /* via 
search */
+
+            // name of the field with the TVA_ID
+            $W1->set_attribute('tvaid','e_march'.$i.'_tva_id');
+            // Add the callback function to filter the card on the jrn
+            $W1->set_callback('filter_card');
+            $W1->set_function('fill_data');
+            $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
+                                    $W1->name);
+            $W1->readonly=false;
+            $array[$i]['quick_code']=$W1->input();
+            $array[$i]['bt']=$W1->search();
+
+            $array[$i]['hidden']='';
+            // For computing we need some hidden field for holding the value
+            if ( $g_parameter->MY_TVA_USE=='Y')
+            {
+                $array[$i]['hidden'].=HtmlInput::hidden('tva_march'.$i,0);
+            }
+
+            if ( $g_parameter->MY_TVA_USE=='Y')
+                $tvac=new INum('tvac_march'.$i);
+            else
+                $tvac=new IHidden('tvac_march'.$i);
+
+            $tvac->readOnly=1;
+            $tvac->value=0;
+            $array[$i]['tvac']=$tvac->input();
+
+            $htva=new INum('htva_march'.$i);
+            $htva->readOnly=1;
+
+            $htva->value=0;
+            $array[$i]['htva']=$htva->input();
+
+            if ( $g_parameter->MY_UPDLAB == 'Y')
+            {
+                $Span=new IText("e_march".$i."_label");
+                $Span->css_size="100%";
+            } else
+            {
+                $Span=new ISpan("e_march".$i."_label");
+            }
+            $Span->value=$march_label;
+            $Span->setReadOnly(false);
+            // card's name, price
+            //--
+            
$array[$i]['denom']=$Span->input("e_march".$i."_label",$march_label);
+            // price
+            $Price=new INum();
+            $Price->setReadOnly(false);
+            $Price->size=9;
+            
$Price->javascript="onBlur='format_number(this);clean_tva($i);compute_ledger($i)'";
+            $array[$i]['pu']=$Price->input("e_march".$i."_price",$march_price);
+            if ( $g_parameter->MY_TVA_USE=='Y')
+            {
+
+                // vat label
+                //--
+                $Tva=new ITva_Popup($this->db);
+                
$Tva->js="onblur=\"format_number(this);onChange=clean_tva($i);compute_ledger($i)\"";
+                $Tva->in_table=true;
+                $Tva->set_attribute('compute',$i);
+                $Tva->value=$march_tva_id;
+                $array[$i]['tva']=$Tva->input("e_march$i"."_tva_id");
+
+                // Tva_amount
+
+                // price
+                $Tva_amount=new INum();
+                $Tva_amount->setReadOnly(false);
+                $Tva_amount->size=9;
+                
$Tva_amount->javascript="onBlur='format_number(this);compute_ledger($i)'";
+                
$array[$i]['amount_tva']=$Tva_amount->input("e_march".$i."_tva_amount",$march_tva_amount);
+            }
+            // quantity
+            //--
+            $quant=(isset(${"e_quant$i"}))?${"e_quant$i"}:"1"
+                   ;
+            $Quantity=new INum();
+            $Quantity->setReadOnly(false);
+            $Quantity->size=9;
+            
$Quantity->javascript="onChange=format_number(this);clean_tva($i);compute_ledger($i)";
+            $array[$i]['quantity']=$Quantity->input("e_quant".$i,$quant);
+
+        }
+        $f_type=_('Fournisseur');
+
+        ob_start();
+        require_once NOALYSS_INCLUDE.'/template/form_ledger_detail.php';
+        $r.=ob_get_contents();
+        ob_end_clean();
+
+        // Set correctly the REQUEST param for jrn_type
+        $r.= HtmlInput::hidden('jrn_type','ACH');
+        $r.= HtmlInput::button('add_item',_('Ajout article'),      ' 
onClick="ledger_add_row()"');
+
+
+
+        /* if we suggest the pj n# the run the script */
+        if ( $g_parameter->MY_PJ_SUGGEST=='Y')
+        {
+            $r.='<script> update_pj();</script>';
+        }
+               // set focus on date
+               $r.= create_script("$('".$Date->id."').focus()");
+        return $r;
+    }
+
+    /address@hidden show the summary of the operation and propose to save it
+     address@hidden array contains normally $_POST. It proposes also to save
+     * the Analytic accountancy
+        * @param $p_summary true to confirm false, show only the result in RO
+     address@hidden string
+     */
+    function confirm($p_array,$p_summary=false)
+    {
+        global $g_parameter;
+        extract ($p_array);
+
+               // we don't need to verify if we need only a feedback
+        if ( ! $p_summary )
+                       $this->verify($p_array) ;
+
+               $anc=null;
+        // to show a select list for the analytic
+        // if analytic is op (optionnel) there is a blank line
+
+        bcscale(4);
+        $client=new Fiche($this->db);
+        $client->get_by_qcode($e_client,true);
+
+        $client_name=h($client->getName().
+                       ' '.$client->strAttribut(ATTR_DEF_ADRESS).' '.
+                       $client->strAttribut(ATTR_DEF_CP).' '.
+                       $client->strAttribut(ATTR_DEF_CITY));
+        $lPeriode=new Periode($this->db);
+        if ($this->check_periode() == true)
+        {
+            $lPeriode->p_id=$period;
+        }
+        else
+        {
+            $lPeriode->find_periode($e_date);
+        }
+        $date_limit=$lPeriode->get_date_limit();
+        $r="";
+        $r.='<TABLE>';
+        if ( $p_summary ) {
+            $jr_id=$this->db->get_value('select jr_id from jrn where 
jr_internal=$1',array($this->internal));
+            $r.="<tr>";
+            $r.='<td>';
+            $r.=_('Détail opération ');
+            $r.='</td>';
+            $r.='<td>';
+            $r.=sprintf ('<a class="line" style="display:inline" 
href="javascript:modifyOperation(%d,%d)">%s</a>',
+                    $jr_id,dossier::id(),$this->internal);
+            $r.='</td>';
+            $r.="</tr>";
+        }
+        $r.='<tr>';
+         if ( ! $p_summary) {
+            $r.='<td>' . _('Numéro Pièce') .'</td><td>'. hb($e_pj) . '</td>';
+        } else {
+            
+             if ( strcmp($this->pj,$e_pj) != 0 )
+            {
+                $r.='<td>' . _('Numéro Pièce') .'</td><td>'. hb($this->pj) . 
+                        '<span class="notice"> '._('Attention numéro pièce 
existante, elle a du être adaptée').'</span></td>';
+            } else {
+                $r.='<td>' . _('Numéro Pièce') .'</td><td>'. hb($this->pj) . 
'</td>';
+            }
+        }
+        $r.='</tr>';
+        $r.='<td> ' . _('Date') . '</td><td> ' . hb($e_date) . '</td>';
+        $r.='</tr>';
+        $r.='<tr>';
+        $r.='<td>' . _('Echeance') . '</td><td> ' . hb($e_ech) . '</td>';
+        $r.='</tr>';
+       
+     
+        $r.='<tr>';
+        $r.='<td> ' . _('Période Comptable') . '</td><td> ' .hb( 
$date_limit['p_start'] . '-' . $date_limit['p_end']) . '</td>';
+        $r.='</tr>';
+        $r.='<tr>';
+        $r.='<td> ' . _('Journal') . '</td><td> ' . hb($this->get_name()) . 
'</td>';
+        $r.='</tr>';
+        $r.='<tr>';
+        $r.='<td> ' . _('Libellé') . '</td><td> ' . hb($e_comm) . '</td>';
+        $r.='</tr>';
+        $r.='<tr>';
+        
+        $r.='<tr>';
+        $r.='<td> ' . _('Fournisseur') . '</td><td> ' . hb($e_client . ':' . 
$client_name) . '</td>';
+        $r.='</tr>';
+        $r.='</table>';
+        $r.='<h2>' . _('Détail articles achetés') . '</h2>';
+        $r.='<p class="decale">';
+        $r.='<table class="result" >';
+        $r.='<TR>';
+        $r.="<th>" . _('Code') . "</th>";
+        $r.="<th>" . _('Dénomination') . "</th>";
+        $r.="<th style=\"text-align:right\">" . _('prix') . "</th>";
+        $r.="<th style=\"text-align:right\">" . _('quantité') . "</th>";
+
+
+        if ($g_parameter->MY_TVA_USE == 'Y') {
+            $r.="<th style=\"text-align:right\">" . _('tva') . "</th>";
+            $r.='<th style="text-align:right"> ' . _('Montant TVA') . '</th>';
+            $r.='<th style="text-align:right">' . _('Montant HTVA') . '</th>';
+            $r.='<th style="text-align:right">' . _('Montant TVAC') . '</th>';
+        } else {
+            $r.='<th style="text-align:right">' . _('Montant') . '</th>';
+        }
+
+        /* if we use the AC */
+        if ($g_parameter->MY_ANALYTIC!='nu')
+        {
+            $anc=new Anc_Plan($this->db);
+            $a_anc=$anc->get_list();
+            $x=count($a_anc);
+            /* set the width of the col */
+            $r.='<th colspan="'.$x.'">'._('Compt. Analytique').'</th>';
+
+            /* add hidden variables pa[] to hold the value of pa_id */
+            $r.=Anc_Plan::hidden($a_anc);
+        }
+
+        $r.='</tr>';
+        $tot_amount=0.0;
+        $tot_tva=0.0;
+        //--
+        // For each item
+        //--
+        for ($i = 0; $i < $nb_item;$i++)
+        {
+                       $tot_row=0;
+            if ( strlen(trim(${"e_march".$i})) == 0 ) continue;
+
+            /* retrieve information for card */
+            $fiche=new Fiche($this->db);
+            $fiche->get_by_qcode(${"e_march".$i});
+            if ( $g_parameter->MY_UPDLAB=='Y')
+                $fiche_name=h(${"e_march".$i."_label"});
+            else
+                $fiche_name=$fiche->strAttribut (ATTR_DEF_NAME);
+            $amount=bcmul(${"e_march".$i."_price"},${'e_quant'.$i});
+            if ( $g_parameter->MY_TVA_USE=='Y')
+            {
+                $idx_tva=${"e_march".$i."_tva_id"};
+                $oTva=new Acc_Tva($this->db);
+                $oTva->set_parameter('id',$idx_tva);
+                $oTva->load();
+                $op=new Acc_Compute();
+
+                $op->set_parameter("amount",$amount);
+                
$op->set_parameter('amount_vat_rate',$oTva->get_parameter('rate'));
+                $op->compute_vat();
+                $tva_computed=$op->get_parameter('amount_vat');
+                //----- if tva_amount is not given we compute the vat ----
+                if ( strlen (trim (${'e_march'.$i.'_tva_amount'})) == 0)
+                {
+                    $tva_item=$op->get_parameter('amount_vat');
+                }
+                else
+                    $tva_item=round(${'e_march'.$i.'_tva_amount'},2);
+
+                if (isset($tva[$idx_tva] ) )
+                    $tva[$idx_tva]=bcadd($tva_item,$tva[$idx_tva]);
+                else
+                    $tva[$idx_tva]=$tva_item;
+               
+               
+                
+            }
+            $tot_amount=round(bcadd($tot_amount,$amount),2);
+            $tot_row=round(bcadd($tot_row,$amount),2);
+            $r.='<tr>';
+            $r.='<td>';
+            $r.=${"e_march".$i};
+            $r.='</td>';
+            $r.='<TD style="border-bottom:1px dotted grey;">';
+            $r.=$fiche_name;
+            $r.='</td>';
+            $r.='<td class="num">';
+            $r.=nbm(${"e_march".$i."_price"});
+            $r.='</td>';
+            $r.='<td class="num">';
+            $r.=nbm(${"e_quant".$i});
+            $r.='</td>';
+            $both_side=0;
+            if ($g_parameter->MY_TVA_USE == 'Y')
+            {
+                $r.='<td class="num">';
+                $r.=$oTva->get_parameter('label');
+                $both_side=$oTva->get_parameter("both_side");
+                if ( $both_side == 0) {
+                    $tot_row=bcadd($tot_row,$tva_item);
+                    $tot_tva=round(bcadd($tva_item,$tot_tva),2);
+                }
+                $r.='</td>';
+                /* warning if tva_computed and given are not the
+                   same */
+                $css_void_tva=($both_side == 
1)?'style="text-decoration:line-through"':'';
+                if ( bcsub($tva_item,$tva_computed) != 0 && ! ($tva_item == 0 
&& $both_side == 1))
+                {
+
+                                        $r.='<td style="background-color:red" 
class="num" '.$css_void_tva.'>';
+                                        $r.=HtmlInput::infobulle(28);
+                                         $r.='<a href="#" class="error" 
style="display:inline" title="'. _("Attention Différence entre TVA calculée et 
donnée").'">'
+                                                       .nbm($tva_item).'<a>';
+                }
+                else{
+                        $r.='<td  class="num" '.$css_void_tva.'>';
+                        $r.=nbm($tva_item);
+                }
+                $r.='</td>';
+                $r.='<td class="num"> ';
+                $r.=nbm(round($amount,2));
+                $r.='</td>';
+            }
+            $r.='<td class="num">';
+            $r.=nbm(round($tot_row,2));
+            $r.='</td>';
+            // encode the pa
+            if ( $g_parameter->MY_ANALYTIC!='nu') // use of AA
+            {
+                // show form
+                $anc_op=new Anc_Operation($this->db);
+                $null=($g_parameter->MY_ANALYTIC=='op')?1:0;
+                $r.='<td>';
+                $p_mode=($p_summary==false)?1:0;
+                $p_array['pa_id']=$a_anc;
+                /* op is the operation it contains either a sequence or a 
jrnx.j_id */
+                $r.=HtmlInput::hidden('op[]=',$i);
+                
$r.=$anc_op->display_form_plan($p_array,$null,$p_mode,$i,$amount);
+                $r.='</td>';
+            }
+
+
+            $r.='</tr>';
+
+        }
+        // Add the sum
+        $decalage=($g_parameter->MY_TVA_USE == 
'Y')?'<td></td><td></td><td></td><td></td>':'<td></td>';
+         $tot = round(bcadd($tot_amount, $tot_tva), 2);
+        $tot_tva=nbm($tot_tva);
+        $tot=nbm($tot);
+        $str_tot=_('Totaux');
+        $tot_amount=nbm($tot_amount);
+        $r.=<<<EOF
+<tr class="highlight">
+    {$decalage}            
+     <td>
+                {$str_tot}
+     </td>
+    <td class="num">
+        {$tot_tva}
+    </td>
+    <td class="num">
+        {$tot_amount}
+    </td>
+    <td class="num">
+        {$tot}
+    </td>
+EOF;
+
+        $r.='</table>';
+        $r.='</p>';
+        if ( $g_parameter->MY_ANALYTIC!='nu' && !$p_summary) // use of AA
+            $r.='<input type="button" class="button" value="'._('Vérifiez 
imputation analytique').'" onClick="verify_ca(\'\');">';
+        
+        $r.=(! $p_summary )?'<div id="total_div_id" >':'<div>';
+        $r.='<h2>Totaux</h2>';
+        /* use VAT */
+        if ($g_parameter->MY_TVA_USE == 'Y') {
+            $r.='<table>';
+            $r.='<tr><td>Total HTVA</td>';
+            $r.=td(hb($tot_amount ),'class="num"');
+            foreach ($tva as $i => $value) {
+                $oTva->set_parameter('id', $i);
+                $oTva->load();
+
+                $r.='<tr><td>  TVA ' . $oTva->get_parameter('label').'</td>';
+                $r.=td(hb(nbm($tva[$i])),'class="num"');
+            }
+            $r.='<tr>'.td(_('Total TVA')).td(hb($tot_tva),'class="num"');
+            $r.='<tr>'.td(_('Total TVAC')).td(hb($tot),'class="num"');
+            $r.='</table>';
+        } else {
+            $r.='<br>Total '.hb($tot);
+        }
+        $r.='</div>';
+        /*  Add hidden */
+        $r.=HtmlInput::hidden('e_client',$e_client);
+        $r.=HtmlInput::hidden('nb_item',$nb_item);
+        $r.=HtmlInput::hidden('p_jrn',$p_jrn);
+        if ( isset($period))
+            $r.=HtmlInput::hidden('period',$period);
+        $r.=HtmlInput::hidden('e_comm',$e_comm);
+        $r.=HtmlInput::hidden('e_date',$e_date);
+        $r.=HtmlInput::hidden('e_ech',$e_ech);
+        $r.=HtmlInput::hidden('jrn_type',$jrn_type);
+        $r.=HtmlInput::hidden('e_pj',$e_pj);
+        $r.=HtmlInput::hidden('e_pj_suggest',$e_pj_suggest);
+        $mt=microtime(true);
+        $r.=HtmlInput::hidden('mt',$mt);
+
+        $e_mp=(isset($e_mp))?$e_mp:0;
+        $r.=HtmlInput::hidden('e_mp',$e_mp);
+        /* Paid by */
+        /* if the paymethod is not 0 and if a quick code is given */
+
+
+        for ($i=0;$i < $nb_item;$i++)
+        {
+            $r.=HtmlInput::hidden("e_march".$i,${"e_march".$i});
+            if (isset (${"e_march".$i."_label"})) 
$r.=HtmlInput::hidden("e_march".$i."_label",${"e_march".$i."_label"});
+            
$r.=HtmlInput::hidden("e_march".$i."_price",${"e_march".$i."_price"});
+            if ( $g_parameter->MY_TVA_USE=='Y' )
+            {
+                
$r.=HtmlInput::hidden("e_march".$i."_tva_id",${"e_march".$i."_tva_id"});
+                $r.=HtmlInput::hidden('e_march'.$i.'_tva_amount', 
${'e_march'.$i.'_tva_amount'});
+            }
+            $r.=HtmlInput::hidden("e_quant".$i,${"e_quant".$i});
+
+        }
+
+        /**
+         * 
+         */
+        if ( $e_mp!=0 && strlen (trim (${'e_mp_qcode_'.$e_mp})) != 0 )
+        {
+            $r.=HtmlInput::hidden('e_mp_qcode_'.$e_mp,${'e_mp_qcode_'.$e_mp});
+            $r.=HtmlInput::hidden('acompte',$acompte);
+                       
$r.=HtmlInput::hidden('e_comm_paiement',$e_comm_paiement);
+            /* needed for generating a invoice */
+           $r.=HtmlInput::hidden('qcode_benef', ${'e_mp_qcode_' . $e_mp});
+                       $fname = new Fiche($this->db);
+                       $fname->get_by_qcode(${'e_mp_qcode_' . $e_mp});
+            $r.='<h2>' . _("Payé par")." " . ${'e_mp_qcode_' . $e_mp} .
+                    " " . $fname->getName() . '</h2> ' . '<p class="decale">' 
. _('Déduction acompte ') . h($acompte) . '</p>' .
+                    _('Libellé :') . h($e_comm_paiement) ;
+            $r.='<br>';
+            $r.='<br>';
+        }
+        // check for upload piece
+
+        return $r;
+    }
+
+    /*!\brief the function extra info allows to
+     * - add a attachment
+     * - generate an invoice
+     * - insert extra info
+     *\return html string
+     */
+    public function extra_info()
+    {
+        $r="";
+        $r = '<div id="facturation_div_id" style="height:185px;height:10rem">';
+        $r.='<p class="decale">';
+        // check for upload piece
+        $file=new IFile();
+        $file->table=0;
+        $r.=_("Ajoutez une pièce justificative ");
+        $r.=$file->input("pj","");
+
+        if ( $this->db->count_sql("select md_id,md_name from document_modele 
where md_affect='ACH'") > 0 )
+        {
+
+            $r.=_('ou générer un document').' <input type="checkbox" 
name="gen_invoice" >';
+            // We propose to generate  the fee note
+            $doc_gen=new ISelect();
+            $doc_gen->name="gen_doc";
+            $doc_gen->value=$this->db->make_array(
+                                "select md_id,md_name ".
+                                " from document_modele where md_affect='ACH'");
+            $r.=$doc_gen->input().'<br>';
+        }
+        $r.='<br>';
+        $obj=new IText();
+        $r.=_('Numero de bon de commande : ').$obj->input('bon_comm').'<br>';
+        $r.=_('Autre information : ').$obj->input('other_info').'<br>';
+        $r.='</p>';
+        $r.='</div>';
+        return $r;
+    }
+
+
+    /**
+     * @brief update the payment
+     * @todo to remove, obsolete
+     * @deprecated
+     */
+    function show_unpaid_deprecated()
+    {
+        // Show list of unpaid sell
+        // Date - date of payment - Customer - amount
+        // Nav. bar
+        $step=$_SESSION['g_pagesize'];
+        $page=(isset($_GET['offset']))?$_GET['page']:1;
+        $offset=(isset($_GET['offset']))?$_GET['offset']:0;
+
+
+        $sql=SQL_LIST_UNPAID_INVOICE_DATE_LIMIT." and jr_def_id=".$this->id ;
+        list($max_line,$list)=$this->list_operation($sql,null,$offset,1);
+        $sql=SQL_LIST_UNPAID_INVOICE." and jr_def_id=".$this->id ;
+        list($max_line2,$list2)=$this->list_operation($sql,null,$offset,1);
+
+        // Get the max line
+        $m=($max_line2>$max_line)?$max_line2:$max_line;
+        $bar2=navigation_bar($offset,$m,$step,$page);
+
+        echo $bar2;
+        echo '<h2 class="info"> '._('Echeance dépassée').' </h2>';
+        echo $list;
+        echo  '<h2 class="info"> '._('Non Payée').' </h2>';
+        echo $list2;
+        echo $bar2;
+        // Add hidden parameter
+        $hid=new IHidden();
+
+        echo '<hr>';
+
+        if ( $m != 0 )
+            echo HtmlInput::submit('paid',_('Mise à jour paiement'));
+
+
+    }
+    /**
+     * Retrieve data from the view v_detail_purchase
+     * @global  $g_user connected user
+     * @param $p_from jrn.jr_tech_per from 
+     * @param type $p_end jrn.jr_tech_per to
+     * @return type
+     */
+    function get_detail_purchase($p_from,$p_end)
+    {
+        global $g_user;
+        // Journal valide
+        if ( $this->id == 0 ) die (__FILE__.":".__LINE__." Journal invalide");
+        
+        // Securite
+        if ( $g_user->get_ledger_access($this->id) == 'X' ) return null;
+        
+        // get the data from the view
+        $sql = "select * 
+                from v_detail_purchase
+                 where 
+                jr_def_id = $1 
+                and  jr_date >= (select p_start from parm_periode where p_id = 
$2) 
+               and  jr_date <= (select p_end from parm_periode where p_id  = 
$3) "
+                .' order by 
jr_date,substring(jr_pj_number,\'[0-9]+$\')::numeric asc ';
+        $ret = $this->db->exec_sql($sql, array($this->id,$p_from, $p_end));
+        return $ret;
+    }
+    /**
+     * @brief compute an array with the heading cells for the
+     * details, used for the export in CSV
+     * @return array
+     */
+    static function heading_detail_purchase()
+    {
+        $array['jr_id'] = _('Numéro opération');
+        $array['jr_date'] = _('Date');
+        $array['jr_date_paid'] = _('Date paiement');
+        $array['jr_ech'] = _('Date échéance');
+        $array['jr_tech_per'] = _('Période');
+        $array['jr_comment'] = _('Libellé');
+        $array['jr_pj_number'] = _('Pièce');
+        $array['jr_internal'] = _('Interne');
+        $array['jr_def_id'] = _('Code journal');
+        $array['j_poste'] = _('Poste');
+        $array['j_text'] = _('Commentaire');
+        $array['j_qcode'] = _('Code Item');
+        $array['item_card'] = _('N° fiche');
+        $array['item_name'] = _('Nom fiche');
+        $array['qp_supplier'] = _('N° fiche fournisseur');
+        $array['tiers_name'] = _('Nom fournisseur');
+        $array['quick_code'] = _('Code fournisseur');
+        $array['tva_label'] = _('Nom TVA');
+        $array['tva_comment'] = _('Commentaire TVA');
+        $array['tva_both_side'] = _('TVA annulée');
+        $array['vat_sided'] = _('TVA Non Payé');
+        $array['vat_code'] = _('Code TVA');
+        $array['vat'] = _('Montant TVA');
+        $array['price'] = _('Total HTVA');
+        $array['quantity'] = _('quantité');
+        $array['price_per_unit'] = _('PU');
+        $array['non_ded_amount'] = _('Montant ND');
+        $array['non_ded_tva'] = _('Montant TVA ND');
+        $array['non_ded_tva_recup'] = _('TVA récup.');
+        $array['htva'] = _('HTVA Opération');
+        $array['tot_vat'] = _('TVA Opération');
+        $array['tot_tva_np'] = _('TVA NP opération');
+        return $array;
+    }
+
+}
+
+
+
+
+
diff --git a/include/class/class_acc_ledger_sold.php 
b/include/class/class_acc_ledger_sold.php
new file mode 100644
index 0000000..3aefc8d
--- /dev/null
+++ b/include/class/class_acc_ledger_sold.php
@@ -0,0 +1,1374 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/* !\file
+ * \brief class for the sold, herits from acc_ledger
+ */
+require_once NOALYSS_INCLUDE.'/lib/class_iselect.php';
+require_once NOALYSS_INCLUDE.'/lib/class_icard.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ispan.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ihidden.php';
+require_once NOALYSS_INCLUDE.'/lib/class_idate.php';
+require_once NOALYSS_INCLUDE.'/lib/class_itext.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ifile.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_ledger.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_compute.php';
+require_once NOALYSS_INCLUDE.'/class/class_anc_operation.php';
+require_once NOALYSS_INCLUDE.'/lib/user_common.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_payment.php';
+require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
+require_once NOALYSS_INCLUDE.'/class/class_own.php';
+require_once NOALYSS_INCLUDE.'/lib/class_itva_popup.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_ledger_fin.php';
+require_once NOALYSS_INCLUDE.'/class/class_stock_goods.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_ledger.php';
+
+/* !\brief Handle the ledger of sold,
+ *
+ * @exception throw an exception is something is wrong
+ */
+
+class Acc_Ledger_Sold extends Acc_Ledger {
+
+    function __construct($p_cn, $p_init) {
+        parent::__construct($p_cn, $p_init);
+        $this->type = 'VEN';
+    }
+
+    /* !\brief verify that the data are correct before inserting or confirming
+     * \param an array (usually $_POST)
+     * \return String
+     * \throw Exception if an error occurs
+     */
+
+    public function verify($p_array) {
+        global $g_parameter, $g_user;
+        
+        if (is_array($p_array ) == false || empty($p_array))
+                    throw new Exception ("Array empty");
+        
+        extract($p_array);
+        
+        /*
+         * Check needed value
+         */
+        check_parameter($p_array,'p_jrn,e_date,e_client');
+
+        /* check for a double reload */
+        if (isset($mt) && $this->db->count_sql('select jr_mt from jrn where 
jr_mt=$1', array($mt)) != 0)
+            throw new Exception(_('Double Encodage'), 5);
+
+        /* check if we can write into this ledger */
+        if ($g_user->check_jrn($p_jrn) != 'W')
+            throw new Exception(_('Accès interdit'), 20);
+
+        /* check if there is a customer */
+        if (strlen(trim($e_client)) == 0)
+            throw new Exception(_('Vous n\'avez pas donné de client'), 11);
+
+        /*  check if the date is valid */
+        if (isDate($e_date) == null) {
+            throw new Exception(_('Date invalide'), 2);
+        }
+
+        $oPeriode = new Periode($this->db);
+        if ($this->check_periode() == true) {
+            $tperiode = $period;
+            /* check that the datum is in the choosen periode */
+            $oPeriode->p_id = $period;
+            list ($min, $max) = $oPeriode->get_date_limit();
+
+            if (cmpDate($e_date, $min) < 0 ||
+                    cmpDate($e_date, $max) > 0)
+                throw new Exception(_('Date et periode ne correspondent pas'), 
6);
+        }
+        else {
+            $per = new Periode($this->db);
+            $tperiode = $per->find_periode($e_date);
+        }
+
+        /* check if the periode is closed */
+        if ($this->is_closed($tperiode) == 1) {
+            throw new Exception(_('Periode fermee'), 6);
+        }
+        /* check if we are using the strict mode */
+        if ($this->check_strict() == true) {
+            /* if we use the strict mode, we get the date of the last
+              operation */
+            $last_date = $this->get_last_date();
+            if ($last_date != null && cmpDate($e_date, $last_date) < 0)
+                throw new Exception(_('Vous utilisez le mode strict la 
dernière operation est date du ')
+                . $last_date . _(' vous ne pouvez pas encoder à une date 
antérieure'), 13);
+        }
+
+
+        $fiche = new Fiche($this->db);
+        $fiche->get_by_qcode($e_client);
+        if ($fiche->empty_attribute(ATTR_DEF_ACCOUNT) == true)
+            throw new Exception(_('La fiche ') . $e_client . _('n\'a pas de 
poste comptable'), 8);
+
+        /* get the account and explode if necessary */
+        $sposte = $fiche->strAttribut(ATTR_DEF_ACCOUNT);
+        // if 2 accounts, take only the debit one for customer
+        if (strpos($sposte, ',') != 0) {
+            $array = explode(',', $sposte);
+            $poste_val = $array[0];
+        } else {
+            $poste_val = $sposte;
+        }
+        /* The account exists */
+
+        $poste = new Acc_Account_Ledger($this->db, $poste_val);
+
+        if ($poste->load() == false) {
+            throw new Exception(_('Pour la fiche ') . $e_client . _(' le poste 
comptable [') . $poste->id . _('] n\'existe pas'), 9);
+        }
+
+        /* Check if the card belong to the ledger */
+        $fiche = new Fiche($this->db);
+        $fiche->get_by_qcode($e_client, 'deb');
+        if ($fiche->belong_ledger($p_jrn) != 1)
+            throw new Exception(_('La fiche ') . $e_client . _('n\'est pas 
accessible à ce journal'), 10);
+
+        $nb = 0;
+
+        //----------------------------------------
+        // foreach item
+        //----------------------------------------
+        for ($i = 0; $i < $nb_item; $i++) {
+            if (strlen(trim(${'e_march' . $i})) == 0)
+                continue;
+            /* check if amount are numeric and */
+            if (isNumber(${'e_march' . $i . '_price'}) == 0)
+                throw new Exception(_('La fiche ') . ${'e_march' . $i} . _('a 
un montant invalide [') . ${'e_march' . $i} . ']', 6);
+            if (isNumber(${'e_quant' . $i}) == 0)
+                throw new Exception(_('La fiche ') . ${'e_march' . $i} . _('a 
une quantité invalide [') . ${'e_quant' . $i} . ']', 7);
+            /* check if all card has a ATTR_DEF_ACCOUNT */
+            $fiche = new Fiche($this->db);
+            $fiche->get_by_qcode(${'e_march' . $i});
+            if ($fiche->empty_attribute(ATTR_DEF_ACCOUNT) == true)
+                throw new Exception(_('La fiche ') . ${'e_march' . $i} . 
_('n\'a pas de poste comptable'), 8);
+
+            // Check if the given tva id is valid
+            if ($g_parameter->MY_TVA_USE == 'Y') {
+                if (isNumber(${'e_march' . $i . '_tva_id'}) == 0)
+                    throw new Exception(_('La fiche ') . ${'e_march' . $i} . 
_('a un code tva invalide') . ' [' . ${'e_march' . $i . '_tva_id'} . ']', 13);
+                $tva_rate = new Acc_Tva($this->db);
+                $tva_rate->set_parameter('id', ${'e_march' . $i . '_tva_id'});
+                if ($tva_rate->load() != 0)
+                    throw new Exception(_('La fiche ') . ${'e_march' . $i} . 
_('a un code tva invalide') . ' [' . ${'e_march' . $i . '_tva_id'} . ']', 13);
+
+                /*
+                 * check if the accounting for VAT are valid
+                 */
+                $a_poste = explode(',', $tva_rate->tva_poste);
+
+                if (
+                        $this->db->get_value('select count(*) from tmp_pcmn 
where pcm_val=$1', array($a_poste[0])) == 0 ||
+                        $this->db->get_value('select count(*) from tmp_pcmn 
where pcm_val=$1', array($a_poste[1])) == 0)
+                    throw new Exception(_(" La TVA " . $tva_rate->tva_label . 
" utilise des postes comptables inexistants"));
+            }
+            // if 2 accounts, take only the credit one
+            /* The account exists */
+            $sposte = $fiche->strAttribut(ATTR_DEF_ACCOUNT);
+
+            if (strpos($sposte, ',') != 0) {
+                $array = explode(',', $sposte);
+                $poste_val = $array[1];
+            } else {
+                $poste_val = $sposte;
+            }
+            $poste = new Acc_Account_Ledger($this->db, $poste_val);
+            if ($poste->load() == false) {
+                throw new Exception(_('Pour la fiche ') . ${'e_march' . $i} . 
_(' le poste comptable [') . $poste->id . _('n\'existe pas'), 9);
+            }
+            /* Check if the card belong to the ledger */
+            $fiche = new Fiche($this->db);
+            $fiche->get_by_qcode(${'e_march' . $i});
+            if ($fiche->belong_ledger($p_jrn, 'cred') != 1)
+                throw new Exception(_('La fiche ') . ${'e_march' . $i} . 
_('n\'est pas accessible à ce journal'), 10);
+            $nb++;
+        }
+        if ($nb == 0)
+            throw new Exception(_('Il n\'y a aucune marchandise'), 12);
+        //------------------------------------------------------
+        // The "Paid By"  check
+        //------------------------------------------------------
+
+        if ($e_mp != 0) {
+            $this->check_payment($e_mp, ${"e_mp_qcode_" . $e_mp});
+        }
+    }
+
+    /* !\brief insert into the database, it calls first the verify function,
+     * change the value of this->jr_id and this->jr_internal
+     * * It generates the document if gen_invoice is set and save the middle 
of payment if any ($e_mp)
+     *
+     * \param $p_array is usually $_POST or a predefined operation
+     * \return string
+     * \note throw an Exception
+     */
+
+    public function insert($p_array = null) {
+        global $g_parameter;
+        extract($p_array);
+        $this->verify($p_array);
+
+        $group = $this->db->get_next_seq("s_oa_group"); /* for analytic */
+        $seq = $this->db->get_next_seq('s_grpt');
+        $this->id = $p_jrn;
+        $internal = $this->compute_internal_code($seq);
+        $this->internal = $internal;
+
+        $oPeriode = new Periode($this->db);
+        $check_periode = $this->check_periode();
+
+        if ($check_periode == true)
+            $tperiode = $period;
+        else
+            $tperiode = $oPeriode->find_periode($e_date);
+
+        $cust = new Fiche($this->db);
+        $cust->get_by_qcode($e_client);
+        $sposte = $cust->strAttribut(ATTR_DEF_ACCOUNT);
+
+        // if 2 accounts, take only the debit one for the customer
+        //
+        if (strpos($sposte, ',') != 0) {
+            $array = explode(',', $sposte);
+            $poste = $array[0];
+        } else {
+            $poste = $sposte;
+        }
+
+        bcscale(4);
+        try {
+            $tot_amount = 0;
+            $tot_tva = 0;
+            $tot_debit = 0;
+            $this->db->start();
+            $tva = array();
+            /* Save all the items without vat */
+            for ($i = 0; $i < $nb_item; $i++) {
+                $n_both = 0;
+                if (strlen(trim(${'e_march' . $i})) == 0)
+                    continue;
+
+                /* First we save all the items without vat */
+                $fiche = new Fiche($this->db);
+                $fiche->get_by_qcode(${"e_march" . $i});
+                $amount = bcmul(${'e_march' . $i . '_price'}, ${'e_quant' . 
$i});
+                $tot_amount = round(bcadd($tot_amount, $amount),2);
+                $acc_operation = new Acc_Operation($this->db);
+                $acc_operation->date = $e_date;
+                $sposte = $fiche->strAttribut(ATTR_DEF_ACCOUNT);
+
+                // if 2 accounts, take only the credit one
+                if (strpos($sposte, ',') != 0) {
+                    $array = explode(',', $sposte);
+                    $poste_val = $array[1];
+                } else {
+                    $poste_val = $sposte;
+                }
+
+                $acc_operation->poste = $poste_val;
+                $acc_operation->amount = $amount;
+                $acc_operation->grpt = $seq;
+                $acc_operation->jrn = $p_jrn;
+                $acc_operation->type = 'c';
+                $acc_operation->periode = $tperiode;
+                if ($g_parameter->MY_UPDLAB == 'Y')
+                    $acc_operation->desc = strip_tags(${"e_march" . $i . 
"_label"});
+                else
+                    $acc_operation->desc = null;
+
+                $acc_operation->qcode = ${"e_march" . $i};
+                if ($amount < 0)
+                    $tot_debit = bcadd($tot_debit, abs($amount));
+
+                $j_id = $acc_operation->insert_jrnx();
+
+                if ($g_parameter->MY_TVA_USE == 'Y') {
+                    /* Compute sum vat */
+                    $oTva = new Acc_Tva($this->db);
+                    $idx_tva = ${'e_march' . $i . '_tva_id'};
+                    $tva_item = ${'e_march' . $i . '_tva_amount'};
+                    $oTva->set_parameter("id", $idx_tva);
+                    $oTva->load();
+                    /* if empty then we need to compute it */
+                    if (trim($tva_item) == '' || ${'e_march'.$i.'_tva_amount'} 
== 0) {
+                        /* retrieve tva */
+                        $l = new Acc_Tva($this->db, $idx_tva);
+                        $l->load();
+                        $tva_item = bcmul($amount, $l->get_parameter('rate'));
+                    }
+                    if (isset($tva[$idx_tva]))
+                        $tva[$idx_tva]+=$tva_item;
+                    else
+                        $tva[$idx_tva] = $tva_item;
+                    if ($oTva->get_parameter("both_side") == 0) {
+                        $tot_tva = round(bcadd($tva_item, $tot_tva), 2);
+                    } else {
+                        $n_both = $tva_item;
+                        if ($n_both < 0)
+                            $tot_debit = bcadd($tot_debit, abs($n_both));
+                    }
+                }
+
+                /* Save the stock */
+                /* if the quantity is < 0 then the stock increase (return of
+                 *  material)
+                 */
+                $nNeg = (${"e_quant" . $i} < 0) ? -1 : 1;
+
+                // always save quantity but in withStock we can find
+                // what card need a stock management
+                if ($g_parameter->MY_STOCK = 'Y' && isset($repo))
+                {
+                    $dir=(${'e_quant'.$i} < 0 ) ? 'd':'c';
+                    Stock_Goods::insert_goods($this->db, array('j_id' => 
$j_id, 'goods' => ${'e_march' . $i}, 'quant' => $nNeg * ${'e_quant' . $i}, 
'dir' => $dir, 'repo' => $repo));
+                }
+
+
+                if ($g_parameter->MY_ANALYTIC != "nu") {
+                    // for each item, insert into operation_analytique */
+                    $op = new Anc_Operation($this->db);
+                    $op->oa_group = $group;
+                    $op->j_id = $j_id;
+                    $op->oa_date = $e_date;
+                    $op->oa_debit = 'f';
+                    $op->oa_description = sql_string($e_comm);
+                    $op->save_form_plan($_POST, $i, $j_id);
+                }
+                if ($g_parameter->MY_TVA_USE == 'Y') {
+                    /* save into quant_sold */
+                    $r = $this->db->exec_sql("select insert_quant_sold 
($1,$2,$3,$4,$5,$6,$7,$8,$9)", array(null, /* 1 */
+                        $j_id, /* 2 */
+                        ${'e_march' . $i}, /* 3 */
+                        ${'e_quant' . $i}, /* 4 */
+                        round($amount, 2), /* 5 */
+                        $tva_item, /* 6 */
+                        $idx_tva, /* 7 */
+                        $e_client, /* 8 */
+                        $n_both));
+                } else {
+                    $r = $this->db->exec_sql("select insert_quant_sold 
($1,$2,$3,$4,$5,$6,$7,$8,$9) ", array(null, /* 1 */
+                        $j_id, /* 2 */
+                        ${'e_march' . $i}, /* 3 */
+                        ${'e_quant' . $i}, /* 4 */
+                        $amount, // 5
+                        0,
+                        null,
+                        $e_client,
+                        0));
+                }  // if ( $g_parameter->MY_TVA_USE=='Y') {
+            }// end loop : save all items
+
+            /*  save total customer */
+            $cust_amount = bcadd($tot_amount, $tot_tva);
+            $acc_operation = new Acc_Operation($this->db);
+            $acc_operation->date = $e_date;
+            $acc_operation->poste = $poste;
+            $acc_operation->amount = $cust_amount;
+            $acc_operation->grpt = $seq;
+            $acc_operation->jrn = $p_jrn;
+            $acc_operation->type = 'd';
+            $acc_operation->periode = $tperiode;
+            $acc_operation->qcode = ${"e_client"};
+            if ($cust_amount > 0)
+                $tot_debit = bcadd($tot_debit, $cust_amount);
+            $let_tiers = $acc_operation->insert_jrnx();
+
+
+            /** save all vat
+             * $i contains the tva_id and value contains the vat amount
+             * if if ($g_parameter->MY_TVA_USE == 'Y' )
+             */
+            if ($g_parameter->MY_TVA_USE == 'Y') {
+                foreach ($tva as $i => $value) {
+                    $oTva = new Acc_Tva($this->db);
+                    $oTva->set_parameter('id', $i);
+                    $oTva->load();
+
+                    $poste_vat = $oTva->get_side('c');
+
+                    $cust_amount = bcadd($tot_amount, $tot_tva);
+                    $acc_operation = new Acc_Operation($this->db);
+                    $acc_operation->date = $e_date;
+                    $acc_operation->poste = $poste_vat;
+                    $acc_operation->amount = $value;
+                    $acc_operation->grpt = $seq;
+                    $acc_operation->jrn = $p_jrn;
+                    $acc_operation->type = 'c';
+                    $acc_operation->periode = $tperiode;
+                    if ($value < 0)
+                        $tot_debit = bcadd($tot_debit, abs($value));
+                    $acc_operation->insert_jrnx();
+
+                    // if TVA is on both side, we deduce it immediately
+                    if ($oTva->get_parameter("both_side") == 1) {
+                        $poste_vat = $oTva->get_side('d');
+                        $cust_amount = bcadd($tot_amount, $tot_tva);
+                        $acc_operation = new Acc_Operation($this->db);
+                        $acc_operation->date = $e_date;
+                        $acc_operation->poste = $poste_vat;
+                        $acc_operation->amount = $value;
+                        $acc_operation->grpt = $seq;
+                        $acc_operation->jrn = $p_jrn;
+                        $acc_operation->type = 'd';
+                        $acc_operation->periode = $tperiode;
+                        $acc_operation->insert_jrnx();
+                        $tot_debit = bcadd($tot_debit, $value);
+                        $n_both = $value;
+                    }
+                }
+            } // if ($g_parameter->MY_TVA_USE=='Y')
+            /* insert into jrn */
+            $acc_operation = new Acc_Operation($this->db);
+            $acc_operation->date = $e_date;
+            $acc_operation->echeance = $e_ech;
+            $acc_operation->amount = abs(round($tot_debit, 2));
+            $acc_operation->desc = $e_comm;
+            $acc_operation->grpt = $seq;
+            $acc_operation->jrn = $p_jrn;
+            $acc_operation->periode = $tperiode;
+            $acc_operation->pj = $e_pj;
+            $acc_operation->mt = $mt;
+
+            $this->jr_id = $acc_operation->insert_jrn();
+
+            $this->pj = $acc_operation->set_pj();
+
+            /*             * = e_pj then do not increment sequence */
+            /* and e_pj is not null */
+            if (strcmp($e_pj, $e_pj_suggest) == 0 && strlen(trim($e_pj)) != 0) 
{
+                $this->inc_seq_pj();
+            }
+
+            $this->db->exec_sql("update jrn set jr_internal='" . $internal . 
"' where " .
+                    " jr_grpt_id = " . $seq);
+
+            /* update quant_sold */
+            $this->db->exec_sql('update quant_sold set qs_internal = $1 where 
j_id in (select j_id from jrnx where j_grpt=$2)', array($internal, $seq));
+
+            /* Save the attachment or generate doc */
+            if (isset($_FILES['pj'])) {
+                if (strlen(trim($_FILES['pj']['name'])) != 0)
+                    $this->db->save_upload_document($seq);
+                else
+                /* Generate an invoice and save it into the database */
+                if (isset($_POST['gen_invoice'])) {
+                    $file = $this->create_document($internal, $p_array);
+                    $this->doc='<A class="line" HREF="show_pj.php?' . 
dossier::get() . '&jr_grpt_id=' . $seq . '&jrn=' . $this->id . '">' . $file . 
'</A>';
+                }
+            }
+            //----------------------------------------
+            // Save the payer
+            //----------------------------------------
+            if ($e_mp != 0) {
+                /* mp */
+                $mp = new Acc_Payment($this->db, $e_mp);
+                $mp->load();
+
+                /* fiche */
+                $fqcode = ${'e_mp_qcode_' . $e_mp};
+                $acfiche = new Fiche($this->db);
+                $acfiche->get_by_qcode($fqcode);
+
+                /* jrnx */
+                $acseq = $this->db->get_next_seq('s_grpt');
+                $acjrn = new Acc_Ledger($this->db, 
$mp->get_parameter('ledger_target'));
+                $acinternal = $acjrn->compute_internal_code($acseq);
+
+                /* Insert paid by  */
+                $acc_pay = new Acc_Operation($this->db);
+                $acc_pay->date = $e_date;
+                /* get the account and explode if necessary */
+                $sposte = $acfiche->strAttribut(ATTR_DEF_ACCOUNT);
+                // if 2 accounts, take only the debit one for customer
+                if (strpos($sposte, ',') != 0) {
+                    $array = explode(',', $sposte);
+                    $poste_val = $array[0];
+                } else {
+                    $poste_val = $sposte;
+                }
+                $famount = bcsub($cust_amount, $acompte);
+                $acc_pay->poste = $poste_val;
+                $acc_pay->qcode = $fqcode;
+                $acc_pay->amount = abs(round($famount, 2));
+                $acc_pay->desc = null;
+
+                $acc_pay->grpt = $acseq;
+                $acc_pay->jrn = $mp->get_parameter('ledger_target');
+                $acc_pay->periode = $tperiode;
+                $acc_pay->type = ($famount >= 0) ? 'd' : 'c';
+                $acc_pay->insert_jrnx();
+
+                /* Insert supplier  */
+                $acc_pay = new Acc_Operation($this->db);
+                $acc_pay->date = $e_date;
+                $acc_pay->poste = $poste;
+                $acc_pay->qcode = $e_client;
+                $acc_pay->amount = abs(round($famount, 2));
+                $acc_pay->desc = null;
+                $acc_pay->grpt = $acseq;
+                $acc_pay->jrn = $mp->get_parameter('ledger_target');
+                $acc_pay->periode = $tperiode;
+                $acc_pay->type = ($famount >= 0) ? 'c' : 'd';
+                $let_other = $acc_pay->insert_jrnx();
+
+                /* insert into jrn */
+                $acc_pay->mt = $mt;
+                $acjrn->grpt_id = $acseq;
+                $acc_pay->desc = (!isset($e_comm_paiement) || 
strlen(trim($e_comm_paiement)) == 0) ? $e_comm : $e_comm_paiement;
+                $mp_jr_id = $acc_pay->insert_jrn();
+                $acjrn->update_internal_code($acinternal);
+
+                $r1 = $this->get_id($internal);
+                $r2 = $this->get_id($acinternal);
+
+                /*
+                 * add lettering
+                 */
+                $oletter = new Lettering($this->db);
+                $oletter->insert_couple($let_tiers, $let_other);
+
+
+                /* set the flag paid */
+                $Res = $this->db->exec_sql("update jrn set jr_rapt='paid' 
where jr_id=$1", array($r1));
+
+                /* Reconcialiation */
+                $rec = new Acc_Reconciliation($this->db);
+                $rec->set_jr_id($r1);
+                $rec->insert($r2);
+
+
+                /*
+                 * save also into quant_fin
+                 */
+
+                /* get ledger property */
+                $ledger = new Acc_Ledger_Fin($this->db, $acc_pay->jrn);
+                $prop = $ledger->get_propertie();
+
+                /* if ledger is FIN then insert into quant_fin */
+                if ($prop['jrn_def_type'] == 'FIN') {
+                    $ledger->insert_quant_fin($acfiche->id, $mp_jr_id, 
$cust->id, bcmul($famount, 1));
+                }
+            }
+        } catch (Exception $e) {
+            echo '<span class="error">' .
+            'Erreur dans l\'enregistrement ' .
+            __FILE__ . ':' . __LINE__ . ' ' .
+            $e->getMessage();
+            echo $e->getTrace();
+
+            $this->db->rollback();
+            throw new Exception ($e);
+        }
+        $this->db->commit();
+
+        return $internal;
+    }
+
+    /* !
+     * @brief show the summary of the operation and propose to save it
+     * @param array contains normally $_POST. It proposes also to save
+     * the Analytic accountancy
+     * @param $p_summary false for the feedback, true to show the summary
+     * @return string
+     *
+     */
+
+    function confirm($p_array, $p_summary = false) {
+        global $g_parameter;
+        extract($p_array);
+
+        // don't need to verify for a summary
+        if (!$p_summary)
+            $this->verify($p_array);
+        $anc = null;
+        // to show a select list for the analytic & VAT USE
+        // if analytic is op (optionnel) there is a blank line
+
+        bcscale(4);
+        $client = new Fiche($this->db);
+        $client->get_by_qcode($e_client, true);
+
+        $client_name = $client->getName() .
+                ' ' . $client->strAttribut(ATTR_DEF_ADRESS) . ' ' .
+                $client->strAttribut(ATTR_DEF_CP) . ' ' .
+                $client->strAttribut(ATTR_DEF_CITY);
+        $lPeriode = new Periode($this->db);
+        if ($this->check_periode() == true) {
+            $lPeriode->p_id = $period;
+        } else {
+            $lPeriode->find_periode($e_date);
+        }
+        $date_limit = $lPeriode->get_date_limit();
+        $r = "";
+        
+        $r.='<TABLE>';
+        if ( $p_summary ) {
+            $jr_id=$this->db->get_value('select jr_id from jrn where 
jr_internal=$1',array($this->internal));
+            $r.="<tr>";
+            $r.='<td>';
+            $r.=_('Détail opération ');
+            $r.='</td>';
+            $r.='<td>';
+            $r.=sprintf ('<a class="line" style="display:inline" 
href="javascript:modifyOperation(%d,%d)">%s</a>',
+                    $jr_id,dossier::id(),$this->internal);
+            $r.='</td>';
+            $r.="</tr>";
+        }
+        $r.='<tr>';
+        if ( ! $p_summary) {
+            $r.='<td>' . _('Numéro Pièce') .'</td><td>'. hb($e_pj) . '</td>';
+        } else {
+            
+             if ( strcmp($this->pj,$e_pj) != 0 )
+            {
+                $r.='<td>' . _('Numéro Pièce') .'</td><td>'. hb($this->pj) . 
+                        '<span class="notice"> '._('Attention numéro pièce 
existante, elle a du être adaptée').'</span></td>';
+            } else {
+                $r.='<td>' . _('Numéro Pièce') .'</td><td>'. hb($this->pj) . 
'</td>';
+            }
+        }
+        $r.='</tr>';
+        $r.='<tr>';
+        $r.='<td> ' . _('Date') . '</td><td> ' . hb($e_date) . '</td>';
+        $r.='</tr>';
+        $r.='<tr>';
+        $r.='<td>' . _('Echeance') . '</td><td> ' . hb($e_ech) . '</td>';
+        $r.='</tr>';
+        $r.='<tr>';
+        $r.='<td> ' . _('Période Comptable') . '</td><td> ' .hb( 
$date_limit['p_start'] . '-' . $date_limit['p_end']) . '</td>';
+        $r.='</tr>';
+        $r.='<tr>';
+        $r.='<td> ' . _('Journal') . '</td><td> ' . hb($this->get_name()) . 
'</td>';
+        $r.='</tr>';
+        $r.='<tr>';
+        $r.='<td> ' . _('Libellé') . '</td><td> ' . hb($e_comm) . '</td>';
+        $r.='</tr>';
+        
+        $r.='<tr>';
+        $r.='<td> ' . _('Client') . '</td><td> ' . hb($e_client . ':' . 
$client_name) . '</td>';
+        $r.='</tr>';
+        $r.='</table>';
+        $r.='<h2>' . _('Détail articles vendus') . '</h2>';
+        $r.='<p class="decale">';
+        $r.='<table class="result" >';
+        $r.='<TR>';
+        $r.="<th>" . _('Code') . "</th>";
+        $r.="<th>" . _('Dénomination') . "</th>";
+        $r.="<th style=\"text-align:right\">" . _('prix') . "</th>";
+        $r.="<th style=\"text-align:right\">" . _('quantité') . "</th>";
+
+
+        if ($g_parameter->MY_TVA_USE == 'Y') {
+            $r.="<th style=\"text-align:right\">" . _('tva') . "</th>";
+            $r.='<th style="text-align:right"> ' . _('Montant TVA') . '</th>';
+            $r.='<th style="text-align:right">' . _('Montant HTVA') . '</th>';
+            $r.='<th style="text-align:right">' . _('Montant TVAC') . '</th>';
+        } else {
+            $r.='<th style="text-align:right">' . _('Montant') . '</th>';
+        }
+        /* if we use the AC */
+        if ($g_parameter->MY_ANALYTIC != 'nu') {
+            $anc = new Anc_Plan($this->db);
+            $a_anc = $anc->get_list();
+            $x = count($a_anc);
+            /* set the width of the col */
+            $r.='<th colspan="' . $x . '">' . _('Compt. Analytique') . '</th>';
+
+            /* add hidden variables pa[] to hold the value of pa_id */
+            $r.=Anc_Plan::hidden($a_anc);
+        }
+        $r.='</tr>';
+        $tot_amount = 0.0;
+        $tot_tva = 0.0;
+        for ($i = 0; $i < $nb_item; $i++) {
+            if (strlen(trim(${"e_march" . $i})) == 0)
+                continue;
+
+            /* retrieve information for card */
+            $fiche = new Fiche($this->db);
+            $fiche->get_by_qcode(${"e_march" . $i});
+            if ($g_parameter->MY_UPDLAB == 'Y')
+                $fiche_name = h(${"e_march" . $i . "_label"});
+            else
+                $fiche_name = $fiche->strAttribut(ATTR_DEF_NAME);
+            if ($g_parameter->MY_TVA_USE == 'Y') {
+                $oTva = new Acc_Tva($this->db);
+                $idx_tva = ${"e_march" . $i . "_tva_id"};
+
+                $oTva->set_parameter('id', $idx_tva);
+                $oTva->load();
+            }
+            $op = new Acc_Compute();
+            $amount = bcmul(${"e_march" . $i . "_price"}, ${'e_quant' . $i});
+            $op->set_parameter("amount", $amount);
+            if ($g_parameter->MY_TVA_USE == 'Y') {
+                $op->set_parameter('amount_vat_rate', 
$oTva->get_parameter('rate'));
+                $op->compute_vat();
+                $tva_computed = $op->get_parameter('amount_vat');
+                $tva_item = ${"e_march" . $i . "_tva_amount"};
+                if (isset($tva[$idx_tva]))
+                    $tva[$idx_tva]+=$tva_item;
+                else
+                    $tva[$idx_tva] = $tva_item;
+                $tot_tva = round(bcadd($tva_item, $tot_tva), 2);
+            }
+            $tot_amount = round(bcadd($tot_amount, $amount), 2);
+
+            $r.='<tr>';
+            $r.='<td>';
+            $r.=${"e_march" . $i};
+            $r.='</td>';
+            $r.='<TD style="border-bottom:1px dotted grey;">';
+            $r.=$fiche_name;
+            $r.='</td>';
+            $r.='<td class="num">';
+            $r.=nbm(${"e_march" . $i . "_price"});
+            $r.='</td>';
+            $r.='<td class="num">';
+            $r.=nbm(${"e_quant" . $i});
+            $r.='</td>';
+            $both_side=0;
+            if ($g_parameter->MY_TVA_USE == 'Y') {
+                $r.='<td class="num">';
+                $r.=$oTva->get_parameter('label');
+                $r.='</td>';
+                $both_side=$oTva->get_parameter("both_side");
+                /* warning if tva_computed and given are not the
+                  same */
+                if (bcsub($tva_item, $tva_computed) != 0 && ! ($tva_item == 0 
&& $both_side == 1)) {
+                    $r.='<td style="background-color:red" class="num">';
+                    $r.=HtmlInput::infobulle(28);
+                    $r.='<a href="#" class="error" style="display:inline" 
title="' . _("Attention Différence entre TVA calculée et donnée") . '">'
+                            . nbm($tva_item) . '<a>';
+                } else {
+                    $r.='<td  class="num">';
+                    $r.=nbm($tva_item);
+                }
+                $r.='</td>';
+                $r.='<td class="num">';
+                $r.=nbm($amount);
+                $r.='</td>';
+                $tot_row = bcadd($tva_item, $amount);
+                $r.=td(nbm($tot_row), 'class="num"');
+            } else {
+                $r.='<td class="num">';
+                $r.=nbm($amount);
+                $r.='</td>';
+            }
+            // encode the pa
+            if ($g_parameter->MY_ANALYTIC != 'nu') { // use of AA
+                // show form
+                $anc_op = new Anc_Operation($this->db);
+                $null = ($g_parameter->MY_ANALYTIC == 'op') ? 1 : 0;
+                $r.='<td>';
+                $p_mode = ($p_summary == false) ? 1 : 0;
+                $p_array['pa_id'] = $a_anc;
+                /* op is the operation it contains either a sequence or a 
jrnx.j_id */
+                $r.=HtmlInput::hidden('op[]=', $i);
+                $r.=$anc_op->display_form_plan($p_array, $null, $p_mode, $i, 
$amount);
+                $r.='</td>';
+            }
+
+
+            $r.='</tr>';
+        } // end loop item
+        //
+        // Add the sum
+        $decalage=($g_parameter->MY_TVA_USE == 
'Y')?'<td></td><td></td><td></td><td></td>':'<td></td>';
+         $tot = round(bcadd($tot_amount, $tot_tva), 2);
+        $tot_tva=nbm($tot_tva);
+        $tot=nbm($tot);
+        $str_tot=_('Totaux');
+        $tot_amount=nbm($tot_amount);
+        $r.=<<<EOF
+<tr class="highlight">
+    {$decalage}            
+     <td>
+                {$str_tot}
+     </td>
+    <td class="num">
+        {$tot_tva}
+    </td>
+    <td class="num">
+        {$tot_amount}
+    </td>
+    <td class="num">
+        {$tot}
+    </td>
+EOF;
+
+        $r.='</table>';
+        $r.='</p>';
+        if ($g_parameter->MY_ANALYTIC != 'nu' && ! $p_summary) // use of AA
+            $r.='<input type="button" class="button" value="' . _('Vérifiez 
Imputation Analytique') . '" onClick="verify_ca(\'\');">';
+        $r.=(! $p_summary )?'<div id="total_div_id" >':'<div>';
+        $r.='<h2>Totaux</h2>';
+       
+        /* use VAT */
+        if ($g_parameter->MY_TVA_USE == 'Y') {
+            $r.='<table>';
+            $r.='<tr><td>Total HTVA</td>';
+            $r.=td(hb($tot_amount ),'class="num"');
+            foreach ($tva as $i => $value) {
+                $oTva->set_parameter('id', $i);
+                $oTva->load();
+
+                $r.='<tr><td>  TVA ' . $oTva->get_parameter('label').'</td>';
+                $r.=td(hb(nbm($tva[$i])),'class="num"');
+            }
+            $r.='<tr>'.td(_('Total TVA')).td(hb($tot_tva),'class="num"');
+            $r.='<tr>'.td(_('Total TVAC')).td(hb($tot),'class="num"');
+            $r.='</table>';
+        } else {
+            $r.='<br>Total '.hb($tot);
+        }
+        $r.='</div>';
+        /*  Add hidden */
+        $r.=HtmlInput::hidden('e_client', $e_client);
+        $r.=HtmlInput::hidden('nb_item', $nb_item);
+        $r.=HtmlInput::hidden('p_jrn', $p_jrn);
+        $mt = microtime(true);
+        $r.=HtmlInput::hidden('mt', $mt);
+
+        if (isset($period))
+            $r.=HtmlInput::hidden('period', $period);
+        /* \todo comment les types hidden gérent ils des contenus avec des 
quotes, double quote ou < > ??? */
+        $r.=HtmlInput::hidden('e_comm', $e_comm);
+        $r.=HtmlInput::hidden('e_date', $e_date);
+        $r.=HtmlInput::hidden('e_ech', $e_ech);
+        $r.=HtmlInput::hidden('e_pj', $e_pj);
+        $r.=HtmlInput::hidden('e_pj_suggest', $e_pj_suggest);
+
+        $e_mp = (isset($e_mp)) ? $e_mp : 0;
+        $r.=HtmlInput::hidden('e_mp', $e_mp);
+        
+        if ( isset($repo) )  {
+            // Show the available repository
+            $r.= $this->select_depot($p_summary,$repo);
+        }
+
+        /* if the paymethod is not 0 and if a quick code is given */
+        if ($e_mp != 0 && strlen(trim(${'e_mp_qcode_' . $e_mp})) != 0) {
+            $r.=HtmlInput::hidden('e_mp_qcode_' . $e_mp, ${'e_mp_qcode_' . 
$e_mp});
+            $r.=HtmlInput::hidden('acompte', $acompte);
+            $r.=HtmlInput::hidden('e_comm_paiement', $e_comm_paiement);
+            /* needed for generating a invoice */
+            $r.=HtmlInput::hidden('qcode_benef', ${'e_mp_qcode_' . $e_mp});
+
+            $fname = new Fiche($this->db);
+            $fname->get_by_qcode(${'e_mp_qcode_' . $e_mp});
+            $r.='<h2>' . "Payé par " . ${'e_mp_qcode_' . $e_mp} .
+                    " " . $fname->getName() . '</h2> ' . '<p class="decale">' 
. _('Déduction acompte ') . h($acompte) . '</p>' .
+                    _('Libellé :') . h($e_comm_paiement) ;
+            $r.='<br>';
+        }
+
+        $r.=HtmlInput::hidden('jrn_type', $jrn_type);
+        for ($i = 0; $i < $nb_item; $i++) {
+            $r.=HtmlInput::hidden("e_march" . $i, ${"e_march" . $i});
+            if (isset(${"e_march" . $i . "_label"}))
+                $r.=HtmlInput::hidden("e_march" . $i . "_label", ${"e_march" . 
$i . "_label"});
+            $r.=HtmlInput::hidden("e_march" . $i . "_price", ${"e_march" . $i 
. "_price"});
+            if ($g_parameter->MY_TVA_USE == 'Y') {
+                $r.=HtmlInput::hidden("e_march" . $i . "_tva_id", ${"e_march" 
. $i . "_tva_id"});
+                $r.=HtmlInput::hidden("e_march" . $i . "_tva_amount", 
${"e_march" . $i . "_tva_amount"});
+            }
+            $r.=HtmlInput::hidden("e_quant" . $i, ${"e_quant" . $i});
+        }
+        return $r;
+    }
+
+    /* !\brief the function extra info allows to
+     * - add a attachment
+     * - generate an invoice
+     * - insert extra info
+     * \return string
+     */
+
+    public function extra_info() {
+        $r = '<div id="facturation_div_id" style="height:185px;height:10rem">';
+        // check for upload piece
+        $file = new IFile();
+        $file->table = 0;
+        $r.='<p class="decale">';
+        $r.=_("Ajoutez une pièce justificative ");
+        $r.=$file->input("pj", "");
+
+        if ($this->db->count_sql("select md_id,md_name from document_modele 
where md_affect='VEN'") > 0) {
+
+
+            $r.=_('ou générer une facture') . ' <input type="checkbox" 
name="gen_invoice" CHECKED>';
+            // We propose to generate  the invoice and some template
+            $doc_gen = new ISelect();
+            $doc_gen->name = "gen_doc";
+            $doc_gen->value = $this->db->make_array(
+                    "select md_id,md_name " .
+                    " from document_modele where md_affect='VEN'");
+            $r.=$doc_gen->input() . '<br>';
+        }
+        $r.='<br>';
+        $obj = new IText();
+        $r.=_('Numero de bon de commande : ') . $obj->input('bon_comm') . 
'<br>';
+        $r.=_('Autre information : ') . $obj->input('other_info') . '<br>';
+        $r.='</p>';
+        $r.='</div>';
+        return $r;
+    }
+
+    /**
+     * @brief update the payment
+     * @deprecated
+     * 
+     */
+
+    function show_unpaid() {
+        // Show list of unpaid sell
+        // Date - date of payment - Customer - amount
+        // Nav. bar
+        $step = $_SESSION['g_pagesize'];
+        $page = (isset($_GET['offset'])) ? $_GET['page'] : 1;
+        $offset = (isset($_GET['offset'])) ? $_GET['offset'] : 0;
+
+
+        $sql = SQL_LIST_UNPAID_INVOICE_DATE_LIMIT . " and jr_def_id=" . 
$this->id;
+        list($max_line, $list) = ListJrn($this->db, $sql, null, $offset, 1);
+        $sql = SQL_LIST_UNPAID_INVOICE . " and jr_def_id=" . $this->id;
+        list($max_line2, $list2) = ListJrn($this->db, $sql, null, $offset, 1);
+
+        // Get the max line
+        $m = ($max_line2 > $max_line) ? $max_line2 : $max_line;
+        $bar2 = navigation_bar($offset, $m, $step, $page);
+
+        echo $bar2;
+        echo '<h2 class="info"> ' . _('Echeance dépassée') . ' </h2>';
+        echo $list;
+        echo '<h2 class="info"> ' . _('Non Payée') . ' </h2>';
+        echo $list2;
+        echo $bar2;
+        // Add hidden parameter
+        $hid = new IHidden();
+
+        echo '<hr>';
+
+        if ($m != 0)
+            echo HtmlInput::submit('paid', _('Mise à jour paiement'));
+    }
+
+    /* !\brief display the form for entering data for invoice,
+     * \param $p_array is null or you can put the predef operation or the 
$_POST
+     *
+     * \return HTML string
+     */
+
+    function input($p_array = null, $p_readonly = 0) {
+        global $g_parameter, $g_user;
+        if ($p_array != null)
+            extract($p_array);
+
+        $flag_tva = $g_parameter->MY_TVA_USE;
+        /* Add button */
+        $f_add_button = new IButton('add_card');
+        $f_add_button->tabindex = -1;
+        $f_add_button->label = _('Créer une nouvelle fiche');
+        $f_add_button->set_attribute('ipopup', 'ipop_newcard');
+        $f_add_button->set_attribute('jrn', $this->id);
+        $f_add_button->javascript = "this.jrn=\$('p_jrn').value; 
select_card_type(this);";
+
+        $f_add_button2 = new IButton('add_card2');
+        $f_add_button2->tabindex = -1;
+        $f_add_button2->label = _('Créer une nouvelle fiche');
+        $f_add_button2->set_attribute('ipopup', 'ipop_newcard');
+        $f_add_button2->set_attribute('filter', $this->get_all_fiche_def());
+        //    $f_add_button2->set_attribute('jrn',$this->id);
+        $f_add_button2->javascript = " 
this.jrn=\$('p_jrn').value;select_card_type(this);";
+
+        $str_add_button = "";
+        $str_add_button2 = "";
+        if ($g_user->check_action(FICADD) == 1) {
+            $str_add_button = $f_add_button->input();
+            $str_add_button2 = $f_add_button2->input();
+        }
+        // The first day of the periode
+        $oPeriode = new Periode($this->db);
+        list ($l_date_start, $l_date_end) = 
$oPeriode->get_date_limit($g_user->get_periode());
+        if ($g_parameter->MY_DATE_SUGGEST == 'Y')
+            $op_date = (!isset($e_date) ) ? $l_date_start : $e_date;
+        else
+            $op_date = (!isset($e_date) ) ? '' : $e_date;
+
+
+        $e_ech = (isset($e_ech)) ? $e_ech : "";
+        $e_comm = (isset($e_comm)) ? $e_comm : "";
+
+        $r = '';
+        $r.=dossier::hidden();
+        $f_legend = _('Client');
+
+        $Echeance = new IDate();
+        $Echeance->setReadOnly(false);
+
+        $Echeance->tabindex = 2;
+        $label = HtmlInput::infobulle(4);
+        $f_echeance = $Echeance->input('e_ech', $e_ech, _('Echéance') . 
$label);
+        $Date = new IDate();
+        $Date->setReadOnly(false);
+
+        $f_date = $Date->input("e_date", $op_date);
+
+        $f_periode = '';
+        // Periode
+        //--
+        if ($this->check_periode() == true) {
+            $l_user_per = $g_user->get_periode();
+            $def = (isset($periode)) ? $periode : $l_user_per;
+
+            $period = new IPeriod("period");
+            $period->user = $g_user;
+            $period->cn = $this->db;
+            $period->value = $def;
+            $period->type = OPEN;
+            try {
+                $l_form_per = $period->input();
+            } catch (Exception $e) {
+                if ($e->getCode() == 1) {
+                    throw new Exception( _("Aucune période ouverte") );
+                }
+            }
+            $label = HtmlInput::infobulle(3);
+            $f_periode = '<td>' . _("Période comptable") . "</td> <td> $label 
" . $l_form_per . '</td>';
+        }
+        /* if we suggest the next pj, then we need a javascript */
+        $add_js = "";
+        if ($g_parameter->MY_PJ_SUGGEST == 'Y') {
+            $add_js = "update_pj();";
+        }
+        if ($g_parameter->MY_DATE_SUGGEST == 'Y') {
+            $add_js.='get_last_date();';
+        }
+        $add_js.='update_name();';
+        $add_js.='update_pay_method();';
+        $add_js.='update_row("sold_item");';
+
+        $wLedger = $this->select_ledger('VEN', 2);
+        if ($wLedger == null)
+            throw new Exception(_('Pas de journal disponible'));
+        $wLedger->table = 1;
+        $wLedger->javascript = 
"onChange='update_predef(\"ven\",\"f\",\"".$_REQUEST['ac']."\");$add_js'";
+        $wLedger->label = " Journal " . HtmlInput::infobulle(2);
+
+        $f_jrn = $wLedger->input();
+
+        $Commentaire = new IText();
+        $Commentaire->table = 0;
+        $Commentaire->setReadOnly(false);
+        $Commentaire->size = 60;
+        $Commentaire->tabindex = 3;
+
+        $label = HtmlInput::infobulle(1);
+
+        $f_desc = $Commentaire->input("e_comm", h($e_comm)) ;
+        // PJ
+        //--
+        /* suggest PJ ? */
+        $default_pj = '';
+        if ($g_parameter->MY_PJ_SUGGEST == 'Y') {
+            $default_pj = $this->guess_pj();
+        }
+
+        $pj = new IText();
+
+        $pj->table = 0;
+        $pj->name = "e_pj";
+        $pj->size = 10;
+        $pj->value = (isset($e_pj)) ? $e_pj : $default_pj;
+        $f_pj = $pj->input() . HtmlInput::hidden('e_pj_suggest', $default_pj);
+        // Display the customer
+        //--
+        $fiche = 'deb';
+
+        // Save old value and set a new one
+        //--
+        $e_client = ( isset($e_client) ) ? $e_client : "";
+        $e_client_label = "&nbsp;"; //str_pad("",100,".");
+        // retrieve e_client_label
+        //--
+
+        if (strlen(trim($e_client)) != 0) {
+            $fClient = new Fiche($this->db);
+            $fClient->get_by_qcode($e_client);
+            $e_client_label = $fClient->strAttribut(ATTR_DEF_NAME) . ' ' .
+                    ' Adresse : ' . $fClient->strAttribut(ATTR_DEF_ADRESS) . ' 
' .
+                    $fClient->strAttribut(ATTR_DEF_CP) . ' ' .
+                    $fClient->strAttribut(ATTR_DEF_CITY) . ' ';
+        }
+
+        $W1 = new ICard();
+        $W1->label = "Client " . HtmlInput::infobulle(0);
+        $W1->name = "e_client";
+        $W1->tabindex = 3;
+        $W1->value = $e_client;
+        $W1->table = 0;
+        $W1->set_dblclick("fill_ipopcard(this);");
+        $W1->set_attribute('ipopup', 'ipopcard');
+
+        // name of the field to update with the name of the card
+        $W1->set_attribute('label', 'e_client_label');
+        // name of the field to update with the name of the card
+        $W1->set_attribute('typecard', 'deb');
+
+        // Add the callback function to filter the card on the jrn
+        $W1->set_callback('filter_card');
+        $W1->set_function('fill_data');
+        $W1->javascript = sprintf(' onchange="fill_data_onchange(\'%s\');" ', 
$W1->name);
+        $f_client_qcode = $W1->input();
+        $client_label = new ISpan();
+        $client_label->table = 0;
+        $f_client = $client_label->input("e_client_label", $e_client_label);
+        $f_client_bt = $W1->search();
+
+
+        // Record the current number of article
+        $Hid = new IHidden();
+        $p_article = ( isset($nb_item)) ? $nb_item : $this->get_min_row();
+        $r.=$Hid->input("nb_item", $p_article);
+        $max = ($p_article < $this->get_min_row()) ? $this->get_min_row() : 
$p_article;
+
+
+        $f_legend_detail = _("Détail articles vendus");
+
+        // For each article
+        //--
+        for ($i = 0; $i < $max; $i++) {
+            // Code id, price & vat code
+            //--
+            $march = (isset(${"e_march$i"})) ? ${"e_march$i"} : "";
+            $march_price = (isset(${"e_march" . $i . "_price"})) ? ${"e_march" 
. $i . "_price"} : ""  ;
+            if ($flag_tva == 'Y') {
+                $march_tva_id = (isset(${"e_march$i" . "_tva_id"})) ? 
${"e_march$i" . "_tva_id"} : "";
+                $march_tva_amount = (isset(${"e_march$i" . "_tva_amount"})) ? 
${"e_march$i" . "_tva_amount"} : "";
+            }
+            $march_label = (isset(${"e_march" . $i . "_label"})) ? ${"e_march" 
. $i . "_label"} : "";
+
+            // retrieve the tva label and name
+            //--
+            if (strlen(trim($march)) != 0 && strlen(trim($march_label)) == 0) {
+                $fMarch = new Fiche($this->db);
+                $fMarch->get_by_qcode($march);
+                $march_label = $fMarch->strAttribut(ATTR_DEF_NAME);
+                if ($flag_tva == 'Y') {
+                    if (!(isset(${"e_march$i" . "_tva_id"})))
+                        $march_tva_id = $fMarch->strAttribut(ATTR_DEF_TVA);
+                }
+            }
+            // Show input
+            //--
+            $W1 = new ICard();
+            $W1->label = "";
+            $W1->name = "e_march" . $i;
+            $W1->value = $march;
+            $W1->table = 1;
+            $W1->set_attribute('typecard', 'cred');
+            $W1->set_dblclick("fill_ipopcard(this);");
+            $W1->set_attribute('ipopup', 'ipopcard');
+
+            // name of the field to update with the name of the card
+            $W1->set_attribute('label', 'e_march' . $i . '_label');
+            // name of the field with the price
+            $W1->set_attribute('price', 'e_march' . $i . '_price');
+            // name of the field with the TVA_ID
+            $W1->set_attribute('tvaid', 'e_march' . $i . '_tva_id');
+            // Add the callback function to filter the card on the jrn
+            $W1->set_callback('filter_card');
+            $W1->set_function('fill_data');
+            $W1->javascript = sprintf(' onchange="fill_data_onchange(\'%s\');" 
', $W1->name);
+
+            $W1->readonly = false;
+
+            $array[$i]['quick_code'] = $W1->input();
+            $array[$i]['bt'] = $W1->search();
+            // For computing we need some hidden field for holding the value
+            $array[$i]['hidden'] = '';
+            if ($flag_tva == 'Y')
+                $array[$i]['hidden'].=HtmlInput::hidden('tva_march' . $i, 0);
+
+            $htva = new INum('htva_march' . $i);
+            $htva->readOnly = 1;
+            $htva->value = 0;
+            $array[$i]['htva'] = $htva->input();
+
+            if ($g_parameter->MY_TVA_USE == 'Y')
+                $tvac = new INum('tvac_march' . $i);
+            else
+                $tvac = new IHidden('tvac_march' . $i);
+
+            $tvac->readOnly = 1;
+            $tvac->value = 0;
+            $array[$i]['tvac'] = $tvac->input();
+
+            if ($g_parameter->MY_UPDLAB == 'Y') {
+                $Span = new IText("e_march" . $i . "_label");
+
+                $Span->css_size = "100%";
+            } else {
+                $Span = new ISpan("e_march" . $i . "_label");
+            }
+            $Span->value = $march_label;
+            $Span->setReadOnly(false);
+            // card's name, price
+            //--
+            $array[$i]['denom'] = $Span->input("e_march" . $i . "_label", 
$march_label);
+            // price
+            $Price = new INum();
+            $Price->setReadOnly(false);
+            $Price->size = 9;
+            $Price->javascript = 
"onBlur='format_number(this);clean_tva($i);compute_ledger($i)'";
+            $array[$i]['pu'] = $Price->input("e_march" . $i . "_price", 
$march_price);
+            $array[$i]['tva'] = '';
+            $array[$i]['amount_tva'] = '';
+            // if tva is not needed then no tva field
+            if ($flag_tva == 'Y') {
+                // vat label
+                //--
+                $Tva = new ITva_Popup($this->db);
+                $Tva->in_table = true;
+                $Tva->set_attribute('compute', $i);
+
+                $Tva->js = 'onblur="format_number(this);clean_tva(' . $i . 
');compute_ledger(' . $i . ')"';
+                $Tva->value = $march_tva_id;
+                $array[$i]['tva'] = $Tva->input("e_march$i" . "_tva_id");
+                // vat amount
+                //--
+                $wTva_amount = new INum();
+                $wTva_amount->readOnly = false;
+                $wTva_amount->size = 6;
+                $wTva_amount->javascript = 
"onBlur='format_number(this);compute_ledger($i)'";
+                $array[$i]['amount_tva'] = $wTva_amount->input("e_march" . $i 
. "_tva_amount", $march_tva_amount);
+            }
+            // quantity
+            //--
+            $quant = (isset(${"e_quant$i"})) ? ${"e_quant$i"} : "1"
+            ;
+            $Quantity = new INum();
+            $Quantity->setReadOnly(false);
+            $Quantity->size = 8;
+            $Quantity->javascript = 
"onChange='format_number(this);clean_tva($i);compute_ledger($i)'";
+            $array[$i]['quantity'] = $Quantity->input("e_quant" . $i, $quant);
+        }// foreach article
+        $f_type = _('Client');
+
+
+        ob_start();
+        require_once NOALYSS_INCLUDE.'/template/form_ledger_detail.php';
+        $r.=ob_get_contents();
+        ob_end_clean();
+
+
+
+        // Set correctly the REQUEST param for jrn_type
+        $r.=HtmlInput::hidden('jrn_type', 'VEN');
+
+        $r.=HtmlInput::button('add_item', _('Ajout article'), ' 
onClick="ledger_add_row()"');
+        $r.= create_script("$('" . $Date->id . "').focus()");
+        return $r;
+    }
+    /**
+     * Retrieve data from the view v_detail_sale
+     * @global  $g_user connected user
+     * @param $p_from jrn.jr_tech_per from 
+     * @param type $p_end jrn.jr_tech_per to
+     * @return type
+     */
+    function get_detail_sale($p_from,$p_end)
+    {
+        global $g_user;
+        // Journal valide
+        if ( $this->id == 0 ) die (__FILE__.":".__LINE__." Journal invalide");
+        
+        // Securite
+        if ( $g_user->get_ledger_access($this->id) == 'X' ) return null;
+        
+        // get the data from the view
+        $sql = "select * 
+                from v_detail_sale
+                 where 
+                jr_def_id = $1 
+                and  jr_date >= (select p_start from parm_periode where p_id = 
$2) 
+               and  jr_date <= (select p_end from parm_periode where p_id  = 
$3) "
+                .' order by 
jr_date,substring(jr_pj_number,\'[0-9]+$\')::numeric asc ';
+        $ret = $this->db->exec_sql($sql, array($this->id,$p_from, $p_end));
+        return $ret;
+    }
+    /**
+     * @brief compute an array with the heading cells for the
+     * details, used for the export in CSV
+     * @return array
+     */
+    static function heading_detail_sale()
+    {
+        $array['jr_id'] = _('Numéro opération');
+        $array['jr_date'] = _('Date');
+        $array['jr_date_paid'] = _('Date paiement');
+        $array['jr_ech'] = _('Date échéance');
+        $array['jr_tech_per'] = _('Période');
+        $array['jr_comment'] = _('Libellé');
+        $array['jr_pj_number'] = _('Pièce');
+        $array['jr_internal'] = _('Interne');
+        $array['jr_def_id'] = _('Code journal');
+        $array['j_poste'] = _('Poste');
+        $array['j_text'] = _('Commentaire');
+        $array['j_qcode'] = _('Code Item');
+        $array['item_card'] = _('N° fiche');
+        $array['item_name'] = _('Nom fiche');
+        $array['qs_client'] = _('N° fiche fournisseur');
+        $array['tiers_name'] = _('Nom fournisseur');
+        $array['quick_code'] = _('Code fournisseur');
+        $array['tva_label'] = _('Nom TVA');
+        $array['tva_comment'] = _('Commentaire TVA');
+        $array['tva_both_side'] = _('TVA annulée');
+        $array['vat_sided'] = _('TVA Non Payé');
+        $array['vat_code'] = _('Code TVA');
+        $array['vat'] = _('Montant TVA');
+        $array['price'] = _('Total HTVA');
+        $array['quantity'] = _('quantité');
+        $array['price_per_unit'] = _('PU');
+        $array['htva'] = _('HTVA Opération');
+        $array['tot_vat'] = _('TVA Opération');
+        return $array;
+    }
+    /* !\brief test function
+     */
+
+    static function test_me($p_string = '') {
+        $cn = new Database(dossier::id());
+        $a = new Acc_Ledger_Sold($cn, 2);
+        echo $a->input();
+    }
+    
+        }
+
diff --git a/include/class/class_acc_operation.php 
b/include/class/class_acc_operation.php
new file mode 100644
index 0000000..f992d4f
--- /dev/null
+++ b/include/class/class_acc_operation.php
@@ -0,0 +1,716 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief  this file match the tables jrn & jrnx the purpose is to
+ *   remove or save accountant writing to these table.
+ */
+require_once NOALYSS_INCLUDE.'/class/class_user.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_ledger.php';
+
+/*! \brief  this file match the tables jrn & jrnx the purpose is to
+ *   remove or save accountant writing to these table.
+ *
+ */
+class Acc_Operation
+{
+    var $db;                           /*!< database connx */
+    var $jr_id;        /*!< pk of jrn */
+    var $jrn_id;                       /*!< jrn_def_id */
+    var $debit;                        /*!< debit or credit */
+    var $user;                 /*!< current user */
+    var $jrn;                  /*!< the ledger to use */
+    var $poste;                        /*!< account  */
+    var $date;                 /*!< the date */
+    var $periode;                      /*!< periode to use */
+    var $amount;                       /*!< amount of the operatoin */
+    var $grpt;                 /*!< the group id */
+    var $date_paid;
+    /*!
+     * \brief constructor set automatically the attributes user and periode
+     * \param $p_cn the databse connection
+     */
+    function __construct($p_cn)
+    {
+        global $g_user;
+        $this->db=$p_cn;
+        $this->qcode="";
+        $this->user=$_SESSION['g_user'];
+        $this->periode=$g_user->get_periode();
+        $this->jr_id=0;
+    }
+    /**
+     address@hidden retrieve the grpt_id from jrn for a jr_id
+     address@hidden jrn.jr_grpt_id or an empty string if not found
+     */
+    function seek_group()
+    {
+        $ret=$this->db->get_value('select jr_grpt_id from jrn where jr_id=$1',
+                                  array($this->jr_id));
+        return $ret;
+    }
+    /**
+     address@hidden  Insert into the table Jrn
+     *The needed data are :
+     * - this->date
+     * - this->amount
+     * - this->poste
+     * - this->grpt
+     * - this->jrn
+     * - this->type ( debit or credit)
+     * - this->user
+     * - this->periode
+     * - this->qcode
+     * - this->desc optional
+     address@hidden if the amount is less than 0 then side changes, for 
example debit becomes
+     *a credit and vice versa
+     address@hidden jrnx.j_id
+     */
+
+    function insert_jrnx()
+    {
+      if ( $this->poste == "") { return false; throw new  Exception 
(__FILE__.':'.__LINE__.' Poste comptable vide');}
+        /* for negative amount the operation is reversed */
+        if ( $this->amount < 0 )
+        {
+            $this->type=($this->type=='d')?'c':'d';
+        }
+        $this->amount=abs($this->amount);
+        $debit=($this->type=='c')?'false':'true';
+        $this->desc=(isset($this->desc))?$this->desc:'';
+        $Res=$this->db->exec_sql("select insert_jrnx
+                                 
($1::text,abs($2)::numeric,$3::account_type,$4::integer,$5::integer,$6::bool,$7::text,$8::integer,upper($9),$10::text)",
+                                 array(
+                                     $this->date, //$1
+                                     round($this->amount,2), //$2
+                                     $this->poste, //$3
+                                     $this->grpt, //$4
+                                     $this->jrn, //$5
+                                     $debit, //$6
+                                     $this->user, //$7
+                                     $this->periode, //$8
+                                     $this->qcode, // $9
+                                     $this->desc)); //$10
+        if ( $Res===false) return $Res;
+        $this->jrnx_id=$this->db->get_current_seq('s_jrn_op');
+        return $this->jrnx_id;
+
+    }
+    /*!\brief set the pj of a operation in jrn. the jr_id must be set
+     *\note if the jr_id it fails
+     */
+    function set_pj()
+    {
+        if ( strlen(trim($this->pj)) == 0 )
+        {
+            $sql="update jrn set jr_pj_number=$1 where jr_id=$2";
+            $this->db->exec_sql($sql,array(null,$this->jr_id));
+            return '';
+        }
+        /* is pj uniq ? */
+        if ( $this->db->count_sql("select jr_id from jrn where jr_pj_number=$1 
and jr_def_id=$2",
+                                  array($this->pj,$this->jrn)
+                                 ) == 0 )
+        {
+            $sql="update jrn set jr_pj_number=$1 where jr_id=$2";
+            $this->db->exec_sql($sql,array($this->pj,$this->jr_id));
+        }
+        else
+        {
+            /* get pref */
+            $pref=$this->db->get_value("select jrn_def_pj_pref from jrn_def 
where jrn_def_id=$1",
+                                       array($this->jrn));
+            /*  try another seq */
+            $flag=0;
+            $limit=100;
+            while ( $flag == 0 )
+            {
+                /*  limit the search to $limit */
+                if ( $limit < 1 )
+                {
+                    $this->pj='';
+                    $flag=2;
+                    break;
+                }
+
+                $seq=$this->db->get_next_seq('s_jrn_pj'.$this->jrn);
+                $this->pj=$pref.$seq;
+
+                /* check if the new pj numb exist */
+                $c=$this->db->count_sql("select jr_id from jrn where 
jr_pj_number=$1 and jr_def_id=$2",
+                                        array($this->pj,$this->jrn)
+                                       );
+                if ( $c == 0 )
+                {
+                    $flag=1;
+                    break;
+                }
+                $limit--;
+            }
+            /* a pj numb is found */
+            if ( $flag == 1 )
+            {
+                $sql="update jrn set jr_pj_number=$1 where jr_id=$2";
+                $this->db->exec_sql($sql,array($this->pj,$this->jr_id));
+            }
+        }
+        return $this->pj;
+    }
+
+    /*!
+     *\brief  Insert into the table Jrn, the amount is computed from jrnx 
thanks the
+     *        group id ($p_grpt)
+     *
+     * \return  sequence of jr_id
+     *
+     */
+
+    function insert_jrn()
+    {
+        $p_comment=$this->desc;
+
+        $diff=$this->db->get_value("select check_balance 
($1)",array($this->grpt));
+        if ( $diff != 0 )
+        {
+
+            echo "Erreur : balance incorrecte :diff = $diff";
+            return false;
+        }
+
+        $echeance=( isset( $this->echeance) && strlen(trim($this->echeance)) 
!= 0)?$this->echeance:null;
+        if ( ! isset($this->mt) )
+        {
+            $this->mt=microtime(true);
+        }
+        // if amount == -1then the triggers will throw an error
+        //
+        $Res=$this->db->exec_sql("insert into jrn 
(jr_def_id,jr_montant,jr_comment,".
+                                 "jr_date,jr_ech,jr_grpt_id,jr_tech_per,jr_mt) 
  values (".
+                                 "$1,$2,$3,".
+                                 
"to_date($4,'DD.MM.YYYY'),to_date($5,'DD.MM.YYYY'),$6,$7,$8)",
+                                 array ($this->jrn, $this->amount,$p_comment,
+                                        
$this->date,$echeance,$this->grpt,$this->periode,$this->mt)
+                                );
+        if ( $Res == false)  return false;
+        $this->jr_id=$this->db->get_current_seq('s_jrn');
+        return $this->jr_id;
+    }
+    /*!
+     * \brief  Return the internal value, the property jr_id must be set before
+     *
+     * \return  null si aucune valeur de trouv
+     *
+     */
+    function get_internal()
+    {
+        if ( ! isset($this->jr_id) )
+            throw new Exception('jr_id is not set',1);
+        $Res=$this->db->exec_sql("select jr_internal from jrn where 
jr_id=".$this->jr_id);
+        if ( Database::num_row($Res) == 0 ) return null;
+        $l_line=Database::fetch_array($Res);
+        $this->jr_internal= $l_line['jr_internal'];
+        return $this->jr_internal;
+    }
+    /*!\brief search an operation thankx it internal code
+     * \param internal code
+     * \return 0 ok -1 nok
+     */
+    function seek_internal($p_internal)
+    {
+        $res=$this->db->exec_sql('select jr_id from jrn where jr_internal=$1',
+                                 array($p_internal));
+        if ( Database::num_row($Res) == 0 ) return -1;
+        $this->jr_id=Database::fetch_result($Res,0,0);
+        return 0;
+    }
+    /*!\brief retrieve data from jrnx
+      *\note the data are filtered by the access of the current user
+     * \return an array
+     */
+    function get_jrnx_detail()
+    {
+        global $g_user;
+        $filter_sql=$g_user->get_ledger_sql('ALL',3);
+        $filter_sql=str_replace('jrn_def_id','jr_def_id',$filter_sql);
+        if ( $this->jr_id==0 ) return;
+        $sql=" select  jr_date,j_qcode,j_poste,j_montant,jr_internal,case when 
j_debit = 'f' then 'C' else 'D' end as debit,jr_comment as description,
+             
vw_name,pcm_lib,j_debit,coalesce(comptaproc.get_letter_jnt(j_id),-1) as 
letter,jr_def_id ".
+             " from jrnx join jrn on (jr_grpt_id=j_grpt)
+             join tmp_pcmn on (j_poste=pcm_val)
+             left join vw_fiche_attr on (j_qcode=quick_code)
+             where
+             jr_id=$1 and $filter_sql order by j_debit desc";
+        $res=$this->db->exec_sql($sql,array($this->jr_id));
+        if ( Database::num_row ($res) == 0 ) return array();
+        $all=Database::fetch_all($res);
+        return $all;
+    }
+    /*!\brief add a comment to the line (jrnx.j_text) */
+    function update_comment($p_text)
+    {
+        $sql="update jrnx set j_text=$1 where j_id=$2";
+        $this->db->exec_sql($sql,array($p_text,$this->jrnx_id));
+    }
+    /*!\brief add a comment to the operation (jrn.jr_text) */
+    function operation_update_comment($p_text)
+    {
+        $sql="update jrn set jr_comment=$1 where jr_id=$2";
+        $this->db->exec_sql($sql,array($p_text,$this->jr_id));
+    }
+    /*!\brief add a limit of payment to the operation (jrn.jr_ech) */
+    function operation_update_date_limit($p_text)
+    {
+        if ( isDate($p_text) == null )
+        {
+            $p_text=null;
+        }
+        $sql="update jrn set jr_ech=to_date($1,'DD.MM.YYYY') where jr_id=$2";
+        $this->db->exec_sql($sql,array($p_text,$this->jr_id));
+    }
+    /*!\brief return the jrn_def_id from jrn */
+    function get_ledger()
+    {
+        $sql="select jr_def_id from jrn where jr_id=$1";
+        $row=$this->db->get_value($sql,array($this->jr_id));
+        return $row;
+    }
+    /*!\brief display_jrnx_detail : get the data from get_jrnx_data and
+       return a string with HTML code
+     * \param table(=0 no code for table,1 code for table,2 code for CSV)
+
+    */
+    function display_jrnx_detail($p_table)
+    {
+        $show=$this->get_jrnx_detail();
+
+        $r='';
+        $r_notable='';
+        $csv="";
+        foreach ($show as $l)
+        {
+            $border="";
+            if ( $l['j_poste'] == $this->poste || ($l['j_qcode']==$this->qcode 
&& trim($this->qcode) != ''))
+                $border=' class="highlight"';
+            $r.='<tr '.$border.'>';
+            $r.='<td>';
+            $a=$l['j_qcode'];
+            
+            $r_notable.=$a;
+            $r.=$a;
+            $csv.='"'.$a.'";';
+            $r.='</td>';
+
+            $r.='<td  '.$border.'>';
+            $a=$l['j_poste'];
+            $r_notable.=$a;
+            $r.=$a;
+            $csv.='"'.$a.'";';
+            $r.='</td>';
+
+            $r.='<td  '.$border.'>';
+            //       $a=($l['vw_name']=="")?$l['j_qcode']:$l['pcm_lib'];
+            $a=(strlen(trim($l['j_qcode']))==0)?$l['pcm_lib']:$l['vw_name'];
+            $r_notable.=$a;
+            $r.=h($a);
+            $csv.='"'.$a.'";';
+            $r.='</td>';
+
+            $r.='<td  '.$border.'>';
+            $a=$l['j_montant'];
+            $r_notable.=$a;
+            $r.=$a;
+            $csv.=$a.';';
+            $r.='</td>';
+
+            $r.='<td  '.$border.'>';
+            $a=$l['debit'];
+            $r_notable.=$a;
+            $r.=$a;
+            $csv.='"'.$a.'"';
+
+            $csv.="\r\n";
+            $r.='</td>';
+            $r.='<td  '.$border.'>';
+            $a=($l['letter']!=-1)?$l['letter']:'';
+            $r_notable.=$a;
+            $r.=$a;
+            $csv.='"'.$a.'"';
+
+            $csv.="\r\n";
+            $r.='</td>';
+
+
+            $r.='</tr>';
+        }
+        switch ($p_table)
+        {
+        case 1:
+            return $r;
+            break;
+        case 0:
+            return $r_notable;
+            break;
+        case 2:
+            return $csv;
+        }
+        return "ERROR PARAMETRE";
+    }
+    /*!
+     * @brief  Get data from jrnx where p_grpt=jrnx(j_grpt)
+     *
+     * @param connection
+     * @return array of 3 elements
+     *  - First Element is an array
+    @verbatim
+    Array
+    (
+        [op_date] => 01.12.2009
+        [class_cred0] => 7000008
+        [mont_cred0] => 8880.0000
+        [op_cred0] => 754
+        [text_cred0] =>
+        [jr_internal] => 23VEN-01-302
+        [comment] =>
+        [ech] =>
+        [jr_id] => 302
+        [jr_def_id] => 2
+        [class_deb0] => 4000005
+        [mont_deb0] => 10744.8000
+        [text_deb0] =>
+        [op_deb0] => 755
+        [class_cred1] => 4511
+        [mont_cred1] => 1864.8000
+        [op_cred1] => 756
+        [text_cred1] =>
+    )
+    @endverbatim
+     *  - Second  : number of line with debit
+     *  - Third  : number of line with credit
+     */
+    function get_data ($p_grpt)
+    {
+        $Res=$this->db->exec_sql("select
+                                 to_char(j_date,'DD.MM.YYYY') as j_date,
+                                 j_text,
+                                 j_debit,
+                                 j_poste,
+                                 coalesce(j_qcode,'-') as qcode,
+                                 j_montant,
+                                 j_id,
+                                 jr_comment,
+                                 to_char(jr_ech,'DD.MM.YYYY') as jr_ech,
+                                 to_char(jr_date,'DD.MM.YYYY') as jr_date,
+                                 jr_id,jr_internal,jr_def_id,jr_pj
+                                 from jrnx inner join jrn on j_grpt=jr_grpt_id 
where j_grpt=$1",array($p_grpt));
+        $MaxLine=Database::num_row($Res);
+        if ( $MaxLine == 0 ) return null;
+        $deb=0;
+        $cred=0;
+        for ( $i=0; $i < $MaxLine; $i++)
+        {
+
+            $l_line=Database::fetch_array($Res,$i);
+            $l_array['op_date']=$l_line['j_date'];
+            if ( $l_line['j_debit'] == 't' )
+            {
+                $l_class=sprintf("class_deb%d",$deb);
+                $l_montant=sprintf("mont_deb%d",$deb);
+                $l_text=sprintf("text_deb%d",$deb);
+                $l_qcode=sprintf("qcode_deb%d",$deb);
+                $l_array[$l_class]=$l_line['j_poste'];
+                $l_array[$l_montant]=$l_line['j_montant'];
+                $l_array[$l_text]=$l_line['j_text'];
+                $l_array[$l_qcode]=$l_line['qcode'];
+                $l_id=sprintf("op_deb%d",$deb);
+                $l_array[$l_id]=$l_line['j_id'];
+                $deb++;
+            }
+            if ( $l_line['j_debit'] == 'f' )
+            {
+                $l_class=sprintf("class_cred%d",$cred);
+                $l_montant=sprintf("mont_cred%d",$cred);
+                $l_array[$l_class]=$l_line['j_poste'];
+                $l_array[$l_montant]=$l_line['j_montant'];
+                $l_id=sprintf("op_cred%d",$cred);
+                $l_array[$l_id]=$l_line['j_id'];
+                $l_text=sprintf("text_cred%d",$cred);
+                $l_array[$l_text]=$l_line['j_text'];
+                $l_qcode=sprintf("qcode_cred%d",$cred);
+                $l_array[$l_qcode]=$l_line['qcode'];
+                $cred++;
+            }
+            $l_array['jr_internal']=$l_line['jr_internal'];
+            $l_array['comment']=$l_line['jr_comment'];
+            $l_array['ech']=$l_line['jr_ech'];
+            $l_array['jr_id']=$l_line['jr_id'];
+            $l_array['jr_def_id']=$l_line['jr_def_id'];
+        }
+        return array($l_array,$deb,$cred);
+    }
+    /**
+    address@hidden retrieve data from jrnx and jrn
+    address@hidden return an object
+    address@hidden
+    address@hidden
+    @code
+
+    @endcode
+    */
+    function get()
+    {
+        $ret=new Acc_Misc($this->db,$this->jr_id);
+        $ret->get();
+        return $ret;
+    }
+    /**
+     address@hidden retrieve data from the table QUANT_*
+     address@hidden return an object or null if there is no
+     * data from the QUANT table
+     address@hidden Acc_Sold Acc_Purchase Acc_Fin Acc_Detail Acc_Misc
+     */
+    function get_quant()
+    {
+        $ledger_id=$this->get_ledger();
+        if ( $ledger_id=='') throw new Exception(_('Journal non trouvé'));
+        $oledger=new Acc_Ledger($this->db,$ledger_id);
+
+        // retrieve info from jrn_info
+
+
+        switch($oledger->get_type())
+        {
+        case 'VEN':
+            $ret=new Acc_Sold($this->db,$this->jr_id);
+            break;
+        case 'ACH':
+            $ret=new Acc_Purchase($this->db,$this->jr_id);
+            break;
+        case 'FIN':
+            $ret=new Acc_Fin($this->db,$this->jr_id);
+            break;
+        default:
+                       $ret=new Acc_Misc($this->db,$this->jr_id);
+                       break;
+        }
+        $ret->get();
+        if ( empty($ret->det->array))
+        {
+            $ret=new Acc_Misc($this->db,$this->jr_id);
+            $ret->get();
+        }
+        $ret->get_info();
+        return $ret;
+    }
+    /**
+     * @brief retrieve info from the jrn_info, create 2 new arrays
+     * obj->info->command and obj->info->other
+     * the columns are the idx
+     */
+    function get_info()
+    {
+        $this->info=new stdClass();
+        // other info
+        $array=$this->db->get_value("select ji_value from jrn_info where
+            jr_id=$1 and id_type=$2",array($this->jr_id,'OTHER'));
+        $this->info->other= $array;
+
+        // Bon de commande
+        $array=$this->db->get_value("select ji_value from jrn_info where
+            jr_id=$1 and id_type=$2",array($this->jr_id,'BON_COMMANDE'));
+        $this->info->command=  $array;
+
+    }
+    /**
+     * Save into jrn_info
+     * @param $p_info msg to save
+     * @param $p_type is OTHER or BON_COMMAND
+     */
+    function save_info($p_info,$p_type)
+    {
+        if ( ! in_array($p_type,array('OTHER','BON_COMMANDE'))) return;
+        if (trim($p_info)=="") {
+            $this->db->exec_sql('delete from jrn_info where jr_id=$1 and 
id_type=$2',array($this->jr_id,$p_type));
+            return;
+        }
+        $exist=$this->db->get_value('select count(ji_id) from jrn_info where 
jr_id=$1 and id_type=$2',array($this->jr_id,$p_type));
+        if ( $exist == "0" ) {
+            //insert into jrn_info
+            $this->db->exec_sql('insert into jrn_info(jr_id,id_type,ji_value) 
values ($1,$2,$3)',
+                    array($this->jr_id,$p_type,$p_info));
+        } elseif ( $exist == 1) {
+            //update
+            $this->db->exec_sql('update jrn_info set ji_value=$3 where 
jr_id=$1 and id_type=$2',
+                    array($this->jr_id,$p_type,$p_info));
+        }
+    }
+    
+    function insert_related_action($p_string)
+    {
+        if ($p_string == "") return;
+        $a_action=explode(',',$p_string);
+        for ($i=0;$i<count($a_action);$i++)
+        {
+            $action = new Follow_Up($this->db,$a_action[$i]);
+            $action->operation=$this->jr_id;
+            $action->insert_operation();
+        }
+    }
+    static function test_me()
+    {
+        $_SESSION['g_user']='phpcompta';
+        $_SESSION['g_pass']='dany';
+        global $g_user;
+        $cn=new Database(dossier::id());
+        $g_user=new User($cn);
+        $a=new Acc_Operation($cn);
+        $a->jr_id=1444;
+        $b=$a->get_quant();
+        var_dump($b);
+    }
+}
+/////////////////////////////////////////////////////////////////////////////
+class Acc_Detail extends Acc_Operation
+{
+    function __construct($p_cn,$p_jrid=0)
+    {
+        parent::__construct($p_cn);
+        $this->jr_id=$p_jrid;
+        $this->det=new stdClass();
+    }
+    /**
+     address@hidden retrieve some common data from jrn as
+     * the datum, the comment,payment limit...
+     */
+    function get()
+    {
+        $sql="SELECT jr_id, jr_def_id, jr_montant, jr_comment, jr_date, 
jr_grpt_id,
+             jr_internal, jr_tech_date, jr_tech_per, jrn_ech, jr_ech, 
jr_rapt,jr_ech,
+             jr_valid, jr_opid, jr_c_opid, jr_pj, jr_pj_name, jr_pj_type,
+             jr_pj_number, jr_mt,jr_rapt,jr_date_paid
+             FROM jrn where jr_id=$1";
+        $array=$this->db->get_array($sql,array($this->jr_id));
+        if ( count($array) == 0 ) throw new Exception('Aucune ligne trouvée');
+        foreach ($array[0] as $key=>$val)
+        {
+            $this->det->$key=$val;
+        }
+       $sql="select n_text from jrn_note where jr_id=$1";
+       $this->det->note=$this->db->get_value($sql,array($this->jr_id));
+       $this->det->note=strip_tags($this->det->note);
+    }
+}
+/////////////////////////////////////////////////////////////////////////////
+/**
+ address@hidden this class manage data from the JRNX and JRN
+ * table
+ address@hidden Data member are the column of the table
+ */
+class Acc_Misc extends Acc_Detail
+{
+    var $signature;            /*!< signature of the obj ODS */
+    var $array;                /*!< an array containing the data from JRNX */
+    function __construct($p_cn,$p_jrid=0)
+    {
+        parent::__construct($p_cn,$p_jrid);
+        $this->signature='ODS';
+        $this->det=new stdClass();
+    }
+    function get()
+    {
+        parent::get();
+        $sql="SELECT j_id, j_date, j_montant, j_poste, j_grpt, j_rapt, 
j_jrn_def,
+             j_debit, j_text, j_centralized, j_internal, j_tech_user, 
j_tech_date,
+             j_tech_per, j_qcode
+             FROM jrnx where j_grpt = $1 order by j_debit desc,j_poste";
+        
$this->det->array=$this->db->get_array($sql,array($this->det->jr_grpt_id));
+    }
+}
+/////////////////////////////////////////////////////////////////////////////
+/**
+ address@hidden this class manage data from the QUANT_SOLD
+ * table
+ address@hidden Data member are the column of the table
+ */
+class Acc_Sold extends Acc_Detail
+{
+    function __construct($p_cn,$p_jrid=0)
+    {
+        parent::__construct($p_cn,$p_jrid);
+        $this->signature='VEN';
+        $this->det=new stdClass();
+    }
+    function get()
+    {
+        parent::get();
+        $sql="SELECT qs_id, qs_internal, qs_fiche, qs_quantite, qs_price, 
qs_vat,
+             qs_vat_code, qs_client, qs_valid, j_id,j_text,qs_vat_sided
+             FROM quant_sold  join jrnx using(j_id) where j_grpt=$1";
+        
$this->det->array=$this->db->get_array($sql,array($this->det->jr_grpt_id));
+    }
+    
+}
+/////////////////////////////////////////////////////////////////////////////
+/**
+ address@hidden this class manage data from the QUANT_PURCHASE
+ * table
+ address@hidden Data member are the column of the table
+
+ */
+class Acc_Purchase extends Acc_Detail
+{
+    function __construct($p_cn,$p_jrid=0)
+    {
+        parent::__construct($p_cn,$p_jrid);
+        $this->signature='ACH';
+    }
+
+    function get()
+    {
+        parent::get();
+        $sql="SELECT qp_id, qp_internal, j_id, qp_fiche, qp_quantite, 
qp_price, qp_vat,
+             qp_vat_code, qp_nd_amount, qp_nd_tva, qp_nd_tva_recup, 
qp_supplier,
+             qp_valid, qp_dep_priv,j_text,qp_vat_sided
+             FROM quant_purchase  join jrnx using(j_id) where j_grpt=$1";
+        
$this->det->array=$this->db->get_array($sql,array($this->det->jr_grpt_id));
+    }
+}
+/////////////////////////////////////////////////////////////////////////////
+/**
+ address@hidden this class manage data from the QUANT_FIN
+ * table
+ address@hidden Data member are the column of the table
+ */
+class Acc_Fin extends Acc_Detail
+{
+    function __construct($p_cn,$p_jrid=0)
+    {
+        parent::__construct($p_cn,$p_jrid);
+        $this->signature='FIN';
+    }
+
+    function get()
+    {
+        parent::get();
+        $sql="SELECT qf_id, qf_bank, jr_id, qf_other, qf_amount
+             FROM quant_fin where jr_id = $1";
+        $this->det->array=$this->db->get_array($sql,array($this->jr_id));
+    }
+}
diff --git a/include/class/class_acc_parm_code.php 
b/include/class/class_acc_parm_code.php
new file mode 100644
index 0000000..e178e0d
--- /dev/null
+++ b/include/class/class_acc_parm_code.php
@@ -0,0 +1,182 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+// Copyright Author Dany De Bontridder address@hidden
+/*! \file
+ * \brief Manage the table parm_code which contains the custom parameter
+ * for the module accountancy
+ */
+/*!
+ * \brief Manage the table parm_code which contains the custom parameter
+ * for the module accountancy
+ */
+require_once NOALYSS_INCLUDE.'/lib/class_itext.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_account_ledger.php';
+
+class Acc_Parm_Code
+{
+    var $db;        /*!< $db  database connection */
+    var $p_code;    /*!< $p_code  parm_code.p_code primary key */
+    var $p_value;   /*!< $p_value  parm_code.p_value  */
+    var $p_comment; /*!< $p_comment parm_code.p_comment */
+// constructor
+    function Acc_Parm_Code($p_cn,$p_id=-1)
+    {
+        $this->db=$p_cn;
+        $this->p_code=$p_id;
+        if ( $p_id != -1 )
+            $this->load();
+    }
+    /*!
+     **************************************************
+     * \brief  
+     *  Load all parmCode
+     *  return an array of Acc_Parm_Code object
+     *
+     * \return array
+     */
+
+    function load_all()
+    {
+        $sql="select * from parm_code order by p_code";
+        $Res=$this->db->exec_sql($sql);
+        $r= Database::fetch_all($Res);
+        $idx=0;
+        $array=array();
+
+        if ( $r === false ) return null;
+        foreach ($r as $row )
+        {
+            $o=new Acc_Parm_Code($this->db,$row['p_code']);
+            $array[$idx]=$o;
+            $idx++;
+        }
+
+        return $array;
+    }
+    /*!
+    **************************************************
+    * \brief  update a parm_object into the database
+    *        p_code is _not_ updatable
+    * \return
+    *     nothing
+    */
+    function save()
+    {
+        // if p_code=="" nothing to save
+        if ( $this->p_code== -1) return;
+        // check if the account exists
+        $acc=new Acc_Account_Ledger($this->db,$this->p_value);
+        if ( $acc->load() == false )
+        {
+            alert(_("Ce compte n'existe pas"));
+        }
+        else
+        {
+            $this->p_comment=sql_string($this->p_comment);
+            $this->p_value=sql_string($this->p_value);
+            $this->p_code=sql_string($this->p_code);
+            $sql="update parm_code set ".
+                 "p_comment='".$this->p_comment."'  ".
+                 ",p_value='".$this->p_value."'  ".
+                 "where p_code='".$this->p_code."'";
+            $Res=$this->db->exec_sql($sql);
+        }
+    }
+    /*!
+     **************************************************
+     * \brief  Display an object, with the <TD> tag
+     *        
+     * \return
+     *     string
+     */
+    function display()
+    {
+        $r="";
+        $r.= '<TD>'.$this->p_code.'</TD>';
+        $r.= '<TD>'.h($this->p_comment).'</TD>';
+        $r.= '<TD>'.$this->p_value.'</TD>';
+
+        return $r;
+    }
+    /*!
+     **************************************************
+     * \brief  Display a form to enter info about
+     *        a parm_code object with the <TD> tag
+     *    
+     * \return string
+     */
+    function form()
+    {
+        $comment=new IText();
+        $comment->name='p_comment';
+        $comment->value=$this->p_comment;
+        $comment->size=45;
+        $value=new IPoste();
+        $value->name='p_value';
+        $value->value=$this->p_value;
+        $value->size=7;
+        $value->set_attribute('ipopup','ipop_account');
+        $value->set_attribute('account','p_value');
+        $poste=new IText();
+        $poste->setReadOnly(true);
+        $poste->size=strlen($this->p_code)+1;
+        $poste->name='p_code';
+        $poste->value=$this->p_code;
+        $r="";
+        $r.='<tr>';
+        $r.='<td align="right"> Code </td>';
+        $r.= '<TD>'.$poste->input().'</TD>';
+        $r.='</tr>';
+        $r.='<tr>';
+        $r.='<td align="right"> Commentaire </td>';
+        $r.= '<TD>'.$comment->input().'</TD>';
+        $r.='</tr>';
+        $r.='<tr>';
+        $r.='<td align="right"> Poste comptable </td>';
+        $r.= '<TD>'.$value->input();
+        $r.='<span id="p_value_label"></span></td>';
+        $r.='</tr>';
+        $r.=Dossier::hidden();
+        return $r;
+
+    }
+
+    /*!
+     **************************************************
+     * \brief  
+     * Complete a parm_code object thanks the p_code 
+     *        
+     * \return array
+     */
+
+    function load()
+    {
+        if ( $this->p_code == -1 ) return "p_code non initialisé";
+        $sql='select * from parm_code where p_code=$1 ';
+
+        $Res=$this->db->exec_sql($sql,array($this->p_code));
+
+        if ( Database::num_row($Res) == 0 ) return 'INCONNU';
+        $row= Database::fetch_array($Res,0);
+        $this->p_value=$row['p_value'];
+        $this->p_comment=$row['p_comment'];
+
+    }
+
+}
diff --git a/include/class/class_acc_payment.php 
b/include/class/class_acc_payment.php
new file mode 100644
index 0000000..3bc5543
--- /dev/null
+++ b/include/class/class_acc_payment.php
@@ -0,0 +1,406 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief Handle the table mod_payment
+ */
+require_once NOALYSS_INCLUDE.'/lib/class_iselect.php';
+require_once NOALYSS_INCLUDE.'/lib/class_icard.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ispan.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_ledger.php';
+require_once NOALYSS_INCLUDE.'/class/class_fiche.php';
+require_once NOALYSS_INCLUDE.'/class/class_fiche_def.php';
+require_once NOALYSS_INCLUDE.'/constant.php';
+/*!\brief Handle the table mod_payment
+ *\note the private data member are accessed via
+  - mp_id  ==> id ( Primary key )
+  - mp_lib ==> lib (label)
+  - mp_jrn_def_id ==> ledger (Number of the ledger where to save)
+  - mp_fd_id ==> fiche_def (fiche class to use)
+  - mp_qcode ==> qcode (quick_code of the card)
+ *
+ */
+class Acc_Payment
+{
+
+    private static $variable=array("id"=>"mp_id",
+                                   "lib"=>"mp_lib",
+                                   "qcode"=>"mp_qcode",
+                                   "ledger_target"=>"mp_jrn_def_id",
+                                   "ledger_source"=>"jrn_def_id",
+                                   "fiche_def"=>"mp_fd_id");
+
+
+    private  $mp_lib;
+    private  $mp_qcode;
+    private  $mp_jrn_def_if;
+    private  $jrn_def_id;
+    private  $mp_fd_id;
+
+    function __construct ($p_cn,$p_init=0)
+    {
+        $this->cn=$p_cn;
+        $this->mp_id=$p_init;
+    }
+    public function get_parameter($p_string)
+    {
+        if ( array_key_exists($p_string,self::$variable) )
+        {
+            $idx=self::$variable[$p_string];
+            return $this->$idx;
+        }
+        else
+               {
+                       throw new Exception("Attribut inexistant $p_string");
+               }
+    }
+    public function set_parameter($p_string,$p_value)
+    {
+        if ( array_key_exists($p_string,self::$variable) )
+        {
+            $idx=self::$variable[$p_string];
+            $this->$idx=$p_value;
+        }
+        else
+            throw new Exception("Attribut inexistant $p_string");
+
+
+    }
+    public function get_info()
+    {
+        return var_export(self::$variable,true);
+    }
+    public function verify()
+    {
+        // Verify that the elt we want to add is correct
+    }
+    public function save()
+    {
+        /* please adapt */
+        if (  $this->get_parameter("id") == 0 )
+            $this->insert();
+        else
+            $this->update();
+    }
+
+    public function insert()
+    {
+        if ( $this->verify() != 0 ) return;
+        $sql='INSERT INTO mod_payment(
+             mp_lib, mp_jrn_def_id, mp_fd_id, mp_qcode,jrn_def_id)
+             VALUES ($1, $2, $3, upper($4),$5) returning mp_id';
+        $this->mp_id=$this->cn->exec_sql($sql,array(
+                                             $this->mp_lib,
+                                             $this->mp_jrn_def_id,
+                                             $this->mp_fd_id,
+                                             $this->mp_qcode,
+                                             $this->jrn_def_id));
+    }
+
+    public function update()
+    {
+        if ( $this->verify() != 0 ) return;
+
+        $sql="update mod_payment set 
mp_lib=$1,mp_qcode=$2,mp_jrn_def_id=$3,mp_fd_id=$4,jrn_def_id=$5 ".
+             " where mp_id = $6";
+        $res=$this->cn->exec_sql(
+                 $sql,
+                 array($this->mp_lib,
+                       $this->mp_qcode,
+                       $this->mp_jrn_def_id,
+                       $this->mp_fd_id,
+                       $this->jrn_def_id,
+                       $this->mp_id)
+             );
+        if ( strlen (trim($this->mp_jrn_def_id))==0)
+            $this->cn->exec_sql(
+                'update mod_payment '.
+                'set mp_jrn_def_id = null where mp_id=$1',
+                array($this->mp_id));
+        if ( strlen (trim($this->jrn_def_id))==0)
+            $this->cn->exec_sql(
+                'update mod_payment '.
+                'set mp_jrn_def_id = null where mp_id=$1',
+                array($this->mp_id));
+        if ( strlen (trim($this->mp_qcode))==0)
+            $this->cn->exec_sql(
+                'update mod_payment '.
+                'set mp_qcode = null where mp_id=$1',
+                array($this->mp_id));
+        if ( strlen (trim($this->mp_fd_id))==0)
+            $this->cn->exec_sql(
+                'update mod_payment '.
+                'set mp_fd_id = null where mp_id=$1',
+                array($this->mp_id));
+
+    }
+
+    public function load()
+    {
+        $sql='select mp_id,mp_lib,mp_fd_id,mp_jrn_def_id,mp_qcode,jrn_def_id 
from mod_payment '.
+             ' where mp_id = $1';
+        $res=$this->cn->exec_sql(
+                 $sql,
+                 array($this->mp_id)
+             );
+
+        if ( Database::num_row($res) == 0 ) return;
+        $row=Database::fetch_array($res,0);
+        foreach ($row as $idx=>$value)
+        {
+            $this->$idx=$value;
+        }
+
+    }
+    /**
+     address@hidden remove a middle of payment
+     */
+    public function delete()
+    {
+        $sql="delete from mod_payment where mp_id=$1";
+        $this->cn->exec_sql($sql,array($this->mp_id));
+    }
+    /*!\brief retrieve all the data for all ledgers
+     *\param non
+     *\return an array of row
+     */
+    public function get_all()
+    {
+        $sql='select mp_id,mp_lib '.
+             ' from mod_payment order by mp_lib';
+        $array=$this->cn->get_array($sql);
+        $ret=array();
+        if ( !empty($array) )
+        {
+            foreach ($array as $row)
+            {
+                $t=new Acc_Payment($this->cn,$row['mp_id']);
+                $t->load();
+                $ret[]=$t;
+            }
+        }
+        return $ret;
+    }
+    /*!\brief retrieve all the data for a ledger but filter on the
+     *valid record (jrn and fd not null
+     *\param non
+     *\return an array of row
+     */
+    public function get_valide()
+    {
+        $sql='select mp_id '.
+             ' from mod_payment '.
+             ' where jrn_def_id=$1 and mp_jrn_def_id is not null and '.
+             ' (mp_fd_id is not null or mp_qcode is not null)';
+        $array=$this->cn->get_array($sql,array($this->jrn_def_id));
+        $ret=array();
+        if ( !empty($array) )
+        {
+            foreach ($array as $row)
+            {
+                $t=new Acc_Payment($this->cn,$row['mp_id']);
+                $t->load();
+                $ret[]=$t;
+            }
+        }
+        return $ret;
+    }
+    /*!\brief return a string with a form (into a table)
+     *\param none
+     *\return a html string
+     */
+    public function form()
+    {
+       //label
+        $lib=new IText('mp_lib');
+        $lib->value=$this->mp_lib;
+               $f_lib=$lib->input();
+
+
+        $ledger_source=new ISelect('jrn_def_id');
+        $ledger_source->value=$this->cn->make_array("select 
jrn_def_id,jrn_Def_name from
+                              jrn_def where jrn_def_type  in ('ACH','VEN') 
order by jrn_def_name");
+               $ledger_source->selected=$this->jrn_def_id;
+        $f_source=$ledger_source->input();
+
+        // type of card
+        $tcard=new ISelect('mp_fd_id');
+        $tcard->value=$this->cn->make_array('select fd_id,fd_label from 
fiche_def join fiche_def_ref '.
+                                            ' using (frd_id) where frd_id in 
(25,4) order by fd_label');
+               $tcard->selected=$this->mp_fd_id;
+
+        $f_type_fiche=$tcard->input();
+        $ledger_record=new ISelect('mp_jrn_def_id');
+        $ledger_record->value=$this->cn->make_array("select 
jrn_def_id,jrn_Def_name from
+                              jrn_def where jrn_def_type  in ('ODS','FIN')");
+               $ledger_record->selected=$this->mp_jrn_def_id;
+        $f_ledger_record=$ledger_record->input();
+
+        // the card
+        $qcode=new ICard();
+        $qcode->noadd=true;
+        $qcode->name='mp_qcode';
+        $list=$this->cn->make_list('select fd_id from fiche_def where frd_id 
in (25,4)');
+        $qcode->typecard=$list;
+               $qcode->dblclick='fill_ipopcard(this);';
+               $qcode->value=$this->mp_qcode;
+
+        $f_qcode=$qcode->input();
+
+               $msg="Modification de ".$this->mp_lib;
+        ob_start();
+        require_once NOALYSS_INCLUDE.'/template/new_mod_payment.php';
+        $r=ob_get_contents();
+        ob_end_clean();
+        return $r;
+
+    }
+    /*!\brief show several lines with radio button to select the payment
+     *method we want to use, the $_POST['e_mp'] will be set
+     *\param none
+     *\return html string
+     */
+    public function select()
+    {
+        $r='';
+        $array=$this->get_valide();
+        $r.=HtmlInput::hidden('gDossier',dossier::id());
+
+        if ( empty($array)==false ) {
+            $acompte=new INum('acompte');
+            $acompte->value=0;
+            $r.=_(" Acompte à déduire");
+            $r.=$acompte->input();
+                       $r.='<p>';
+                       $e_comm_paiement=new IText('e_comm_paiement');
+                       $e_comm_paiement->table = 0;
+                       $e_comm_paiement->setReadOnly(false);
+                       $e_comm_paiement->size = 60;
+                       $e_comm_paiement->tabindex = 3;
+                       $r.=_(" Libellé du paiement");
+                       $r.=$e_comm_paiement->input();
+                       $r.='</p>';
+               }
+
+        $r.='<ol>';
+        $r.='<li ><input type="radio" name="e_mp" value="0" 
checked>'._('Paiement encodé plus tard');
+        if ( empty($array ) == false )
+        {
+            foreach ($array as $row)
+            {
+                $f='';
+                /* if the qcode is  null the propose a search button to select
+                   the card */
+                if ( $row->mp_qcode==NULL)
+                {
+                    $a=new ICard();
+                    $a->jrn=$row->mp_jrn_def_id;
+                                       
$a->set_attribute('typecard',$row->mp_fd_id);
+                    $a->name='e_mp_qcode_'.$row->mp_id;
+                    $a->set_dblclick("fill_ipopcard(this);");
+                    $a->set_callback('filter_card');
+                    $a->set_function('fill_data');
+                    $a->set_attribute('ipopup','ipopcard');
+                    $a->set_attribute('label',$a->name.'_label');
+
+                    $s=new ISpan();
+                    $s->name=$a->name.'_label';
+                    $f=_(" paiement par ").$a->input().$s->input();
+                }
+                else
+                {
+                    /* if the qcode is not null then add a hidden variable with
+                       the qcode */
+
+                    $fiche=new Fiche($this->cn);
+                    $fiche->get_by_qcode($row->mp_qcode);
+                    
$f=HtmlInput::hidden('e_mp_qcode_'.$row->mp_id,$row->mp_qcode);
+
+                    //   $f.=$fiche->strAttribut(ATTR_DEF_NAME);
+                }
+                $r.='<li><input type="radio" name="e_mp" 
value="'.$row->mp_id.'">';
+                $r.=$row->mp_lib.'  '.$f;
+
+            }
+        }
+        $r.='</ol>';
+        return $r;
+    }
+
+    /*!\brief convert an array into an Acc_Payment object
+     *\param array to convert
+     */
+    public function from_array($p_array)
+    {
+        
$idx=array('mp_id','mp_lib','mp_fd_id','mp_jrn_def_id','mp_qcode','jrn_def_id');
+        foreach ($idx as $l)
+        if (isset($p_array[$l])) $this->$l=$p_array[$l];
+    }
+    /**
+     address@hidden return an html with a form to add a new middle of payment
+     */
+    public function blank()
+    {
+        //label
+        $lib=new IText('mp_lib');
+        $f_lib=$lib->input();
+
+        $ledger_source=new ISelect('jrn_def_id');
+        $ledger_source->value=$this->cn->make_array("select 
jrn_def_id,jrn_Def_name from
+                              jrn_def where jrn_def_type  in ('ACH','VEN') 
order by jrn_def_name");
+        $f_source=$ledger_source->input();
+
+        // type of card
+        $tcard=new ISelect('mp_fd_id');
+        $tcard->value=$this->cn->make_array('select fd_id,fd_label from 
fiche_def join fiche_def_ref '.
+                                            ' using (frd_id) where frd_id in 
(25,4) order by fd_label');
+        $f_type_fiche=$tcard->input();
+        $ledger_record=new ISelect('mp_jrn_def_id');
+        $ledger_record->value=$this->cn->make_array("select 
jrn_def_id,jrn_Def_name from
+                              jrn_def where jrn_def_type  in ('ODS','FIN')");
+        $f_ledger_record=$ledger_record->input();
+
+        // the card
+        $qcode=new ICard();
+        $qcode->noadd=true;
+        $qcode->name='mp_qcode';
+        $list=$this->cn->make_list('select fd_id from fiche_def where frd_id 
in (25,4)');
+        $qcode->typecard=$list;
+               $qcode->dblclick='fill_ipopcard(this);';
+
+        $f_qcode=$qcode->input();
+               $msg="Ajout d'un nouveau moyen de paiement";
+        ob_start();
+        require_once NOALYSS_INCLUDE.'/template/new_mod_payment.php';
+        $r=ob_get_contents();
+        ob_end_clean();
+        return $r;
+    }
+    /*!\brief test function
+     */
+    static function test_me()
+    {
+
+    }
+
+}
+
+
diff --git a/include/class/class_acc_reconciliation.php 
b/include/class/class_acc_reconciliation.php
new file mode 100644
index 0000000..412bde1
--- /dev/null
+++ b/include/class/class_acc_reconciliation.php
@@ -0,0 +1,532 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ *   \brief class acc_reconciliation, this class is new and the code
+ *   must use it
+ *
+ */
+require_once NOALYSS_INCLUDE.'/lib/class_iconcerned.php';
+require_once  NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once  NOALYSS_INCLUDE.'/class/class_dossier.php';
+require_once NOALYSS_INCLUDE.'/class/class_lettering.php';
+
+/*! \brief new class for managing the reconciliation it must be used
+ * instead of the function InsertRapt, ...
+ *
+ */
+class Acc_Reconciliation
+{
+    var $db;                   /*!< database connection */
+    var $jr_id;                        /*!< jr_id */
+
+    function   __construct($cn)
+    {
+        $this->db=$cn;
+        $this->jr_id=0;
+    }
+
+    function set_jr_id($jr_id)
+    {
+        $this->jr_id=$jr_id;
+    }
+    /*! \brief return a widget of type js_concerned
+     */
+    function widget()
+    {
+        $wConcerned=new IConcerned();
+        $wConcerned->extra=0; // with 0 javascript search from e_amount... 
field (see javascript)
+
+        return $wConcerned;
+
+    }
+    /*!
+     *\brief   Insert into jrn_rapt the concerned operations
+     *
+     * \param $jr_id2 (jrn.jr_id) => jrn_rapt.jra_concerned or a string
+     * like "jr_id2,jr_id3,jr_id4..."
+     *
+     * \return none
+     *
+     */
+    function insert($jr_id2)
+    {
+        if ( trim($jr_id2) == "" )
+            return;
+        if ( strpos($jr_id2,',') !== 0 )
+        {
+            $aRapt=explode(',',$jr_id2);
+            foreach ($aRapt as $rRapt)
+            {
+                if ( isNumber($rRapt) == 1 )
+                {
+                    $this->insert_rapt($rRapt);
+                }
+            }
+        }
+        else
+            if ( isNumber($jr_id2) == 1 )
+            {
+                $this->insert_rapt($jr_id2);
+            }
+    }
+
+    /*!
+     *\brief   Insert into jrn_rapt the concerned operations
+     * should not  be called directly, use insert instead
+     *
+     * \param $jr_id2 (jrn.jr_id) => jrn_rapt.jra_concerned
+     *
+     * \return none
+     *
+     */
+    function insert_rapt($jr_id2)
+    {
+        if ( isNumber($this->jr_id)  == 0 ||  isNumber($jr_id2) == 0 )
+        {
+            return false;
+        }
+        if ( $this->jr_id==$jr_id2)
+            return true;
+
+               if ( $this->db->count_sql("select jr_id from jrn where 
jr_id=".$this->jr_id)==0 )
+                               return false;
+               if ( $this->db->count_sql("select jr_id from jrn where 
jr_id=".$jr_id2)==0 )
+                               return false;
+
+        // verify if exists
+        if ( $this->db->count_sql(
+                    "select jra_id from jrn_rapt where 
jra_concerned=".$this->jr_id.
+                    " and jr_id=$jr_id2
+                    union
+                    select jra_id from jrn_rapt where jr_id=".$this->jr_id.
+                    " and jra_concerned=$jr_id2 ")
+                ==0)
+        {
+            // Ok we can insert
+            $Res=$this->db->exec_sql("insert into 
jrn_rapt(jr_id,jra_concerned) values ".
+                                    "(".$this->jr_id.",$jr_id2)");
+            // try to letter automatically same account from both operation
+            $this->auto_letter($jr_id2);
+            
+            // update date of paiement 
-----------------------------------------------------------------------
+            $source_type=$this->db->get_value("select substr(jr_internal,1,1) 
from jrn where jr_id=$1",array($this->jr_id));
+            $dest_type=$this->db->get_value("select substr(jr_internal,1,1) 
from jrn where jr_id=$1",array($jr_id2));
+            if (($source_type =='A' || $source_type=='V') && ($dest_type != 
'A' && $dest_type != 'V'))
+            {
+                // set the date on source
+                $date=$this->db->get_value('select jr_date from jrn where 
jr_id=$1',array($jr_id2));
+                if ( trim ($date) == '') $date=null;
+                $this->db->exec_sql('update jrn set jr_date_paid=$1 where 
jr_id=$2 and jr_date_paid is null ',array($date,$this->jr_id));
+            }
+            if (($source_type !='A' && $source_type !='V') && ($dest_type == 
'A' || $dest_type == 'V'))
+            {
+                // set the date on dest
+                $date=$this->db->get_value('select jr_date from jrn where 
jr_id=$1',array($this->jr_id));
+                if (trim($date) == '') $date=null;
+                $this->db->exec_sql('update jrn set jr_date_paid=$1 where 
jr_id=$2 and jr_date_paid is null ',array($date,$jr_id2));
+            }
+        }
+        return true;
+    }
+       /**
+        * @brief try to letter same card between $p_jrid and $this->jr_id
+        * @param jrn.jr_id $p_jrid  the operation to reconcile
+        */
+       function auto_letter($p_jrid)
+       {
+               // Try to find same card from both operation
+               $sql="select j1.f_id as fiche ,coalesce(j1.j_id,-1) as 
jrnx_id1,coalesce(j2.j_id,-1) as jrnx_id2,
+j1.j_poste as poste
+                               from jrnx as j1
+                                       join jrn as jr1 on 
(j1.j_grpt=jr1.jr_grpt_id)
+                                       join jrnx as j2 on 
(coalesce(j1.f_id,-1)=coalesce(j2.f_id,-1) and j1.j_poste=j2.j_poste)
+                                       join jrn as jr2 on 
(j2.j_grpt=jr2.jr_grpt_id)
+                               where
+                                       jr1.jr_id=$1
+                                       and
+                                       jr2.jr_id= $2";
+               $result=$this->db->get_array($sql,array($this->jr_id,$p_jrid));
+               if ( count($result) == 0)
+               {
+                       return;
+               }
+               for ($i=0;$i<count($result);$i++)
+               {
+                       if ( $result[$i]['fiche'] != -1)
+                       {
+                               $letter = new Lettering_Card($this->db);
+                               
$letter->insert_couple($result[$i]['jrnx_id1'],$result[$i]['jrnx_id2']);
+                       }
+                       else
+                       {
+                               $letter = new Lettering_Account($this->db);
+                               
$letter->insert_couple($result[$i]['jrnx_id1'],$result[$i]['jrnx_id2']);
+                       }
+               }
+
+       }
+
+       /*!
+     *\brief   Insert into jrn_rapt the concerned operations
+     *
+     * \param $this->jr_id (jrn.jr_id) => jrn_rapt.jr_id
+     * \param $jr_id2 (jrn.jr_id) => jrn_rapt.jra_concerned
+     *
+     * \return none
+     */
+    function remove($jr_id2)
+    {
+        if ( isNumber($this->jr_id)  == 0 or
+                isNumber($jr_id2) == 0 )
+        {
+            return;
+        }
+        // verify if exists
+        if ( $this->db->count_sql("select jra_id from jrn_rapt where ".
+                                  " jra_concerned=".$this->jr_id."  and 
jr_id=$jr_id2
+                                  union
+                                  select jra_id from jrn_rapt where 
jra_concerned=$jr_id2 ".
+                                  " and jr_id=".$this->jr_id) !=0)
+        {
+                       /**
+                        * remove also lettering between both operation
+                        */
+                       $sql = " delete from
+                                       jnt_letter
+                                       where jl_id in ( select jl_id from 
jnt_letter
+                                                                               
join letter_cred as lc using(jl_id)
+                                                                               
join letter_deb as ld using (jl_id)
+                                                                       where
+                                                                               
lc.j_id in (select j_id
+                                                                               
                        from jrnx join jrn on (j_grpt=jr_grpt_id)
+                                                                               
                        where jr_id in ($1,$2))
+                                                                               
or
+                                                                               
ld.j_id in (select j_id
+                                                                               
                        from jrnx join jrn on (j_grpt=jr_grpt_id)
+                                                                               
                        where jr_id in ($1,$2))
+
+
+
+                                                       )";
+                       $this->db->exec_sql($sql, array($jr_id2, $this->jr_id));
+                       // Ok we can delete
+                       $Res=$this->db->exec_sql("delete from jrn_rapt where ".
+                                     "(jra_concerned=$jr_id2 and 
jr_id=".$this->jr_id.") or
+                                     (jra_concerned=".$this->jr_id." and 
jr_id=$jr_id2) ");
+        }
+    }
+
+    /*!
+     *\brief   Return an array of the concerned operation
+     *
+     *
+     *\param database connection
+     * \return array if something is found or null
+     */
+    function get ( )
+    {
+        $sql=" select jr_id as cn from jrn_rapt where 
jra_concerned=".$this->jr_id.
+             " union ".
+             " select jra_concerned as cn from jrn_rapt where 
jr_id=".$this->jr_id;
+        $Res=$this->db->exec_sql($sql);
+
+        // If nothing is found return null
+        $n=Database::num_row($Res);
+
+        if ($n ==0 ) return null;
+
+        // put everything in an array
+        for ($i=0;$i<$n;$i++)
+        {
+            $l=Database::fetch_array($Res,$i);
+            $r[$i]=$l['cn'];
+        }
+        return $r;
+    }
+    function fill_info()
+    {
+        $sql="select 
jr_id,jr_date,jr_comment,jr_internal,jr_montant,jr_pj_number,jr_def_id,jrn_def_name,jrn_def_type
+             from jrn join jrn_def on (jrn_def_id=jr_def_id)
+             where jr_id=$1";
+        $a=$this->db->get_array($sql,array($this->jr_id));
+        return $a[0];
+    }
+    /**
+     address@hidden return array of not-reconciled operation
+    * Prepare and put in memory the SQL detail_quant
+    */
+    function get_not_reconciled()
+    {
+      $filter_date=$this->filter_date();
+      /* create ledger filter */
+      $sql_jrn=$this->ledger_filter();
+
+        $array=$this->db->get_array("select distinct jr_id,jr_date from jrn 
where $filter_date and $sql_jrn and jr_id not in (select jr_id from jrn_rapt 
union select jra_concerned from jrn_rapt) order by jr_date");
+        $ret=array();
+        for ($i=0;$i<count($array);$i++)
+        {
+            $this->jr_id=$array[$i]['jr_id'];
+            $ret[$i]['first']=$this->fill_info();
+        }
+        $this->db->prepare('detail_quant','select * from v_quant_detail where 
jr_id=$1');
+        return $ret;
+    }
+    /**
+     *Create a sql condition to filter by security and by asked ledger
+     * based on $this->a_jrn
+     address@hidden a valid sql stmt to include
+     address@hidden get_not_reconciled get_reconciled
+     */
+    function ledger_filter ()
+    {
+        global $g_user;
+        /* get the available ledgers for current user */
+        $sql=$g_user->get_ledger_sql('ALL',3);
+        $sql=str_replace('jrn_def_id','jr_def_id',$sql);
+        $r='';
+        /* filter by this->r_jrn */
+        if ($this->a_jrn != null )
+        {
+            $sep='';
+            $r='and jr_def_id in (';
+            foreach( $this->a_jrn as $key=>$value)
+            {
+                $r.=$sep.$value;
+                $sep=',';
+            }
+            $r.=')';
+        }
+        return $sql.'  '.$r;
+    }
+    /**
+     address@hidden return array of reconciled operation
+     * Prepare and put in memory the SQL detail_quant
+     address@hidden
+     address@hidden
+     address@hidden
+     @code
+
+     @endcode
+    */
+    function get_reconciled()
+    {
+      $filter_date=$this->filter_date();
+
+
+        /* create ledger filter */
+        $sql_jrn=$this->ledger_filter();
+
+        $array=$this->db->get_array("select distinct jr_id,jr_date from jrn 
where $filter_date and $sql_jrn and jr_id  in (select jr_id from jrn_rapt union 
select jra_concerned from jrn_rapt) order by jr_date");
+        $ret=array();
+        for ($i=0;$i<count($array);$i++)
+        {
+            $this->jr_id=$array[$i]['jr_id'];
+            $ret[$i]['first']=$this->fill_info();
+            $atmp=$this->get();
+            for ( $e=0;$e<count($atmp);$e++)
+            {
+                $this->jr_id=$atmp[$e];
+                $ret[$i]['depend'][$e]=$this->fill_info();
+            }
+        }
+        $this->db->prepare('detail_quant','select * from v_quant_detail where 
jr_id=$1');
+        return $ret;
+    }
+    /**
+     address@hidden
+     * Prepare and put in memory the SQL detail_quant
+     address@hidden
+     address@hidden
+     address@hidden
+     address@hidden
+    @code
+
+    @endcode
+     */
+    function get_reconciled_amount($p_equal=false)
+    {
+        $array=$this->get_reconciled();
+        $ret=array();
+        bcscale(2);
+        for ($i=0;$i<count($array);$i++)
+        {
+            $first_amount=$array[$i]['first']['jr_montant'];
+            $second_amount=0;
+            for ($e=0;$e<count($array[$i]['depend']);$e++)
+            {
+                
$second_amount=bcadd($second_amount,$array[$i]['depend'][$e]['jr_montant']);
+            }
+            if ( $p_equal &&  $first_amount==$second_amount)
+            {
+                $ret[]=$array[$i];
+            }
+            if ( ! $p_equal &&  $first_amount != $second_amount)
+            {
+                $ret[]=$array[$i];
+            }
+        }
+        return $ret;
+    }
+  /**
+   address@hidden create a string to filter thanks the date
+   address@hidden a sql string like jr_date > ... and jr_date < ....
+   address@hidden use the data member start_day and end_day
+   address@hidden get_reconciled get_not_reconciled
+   */
+    function filter_date()
+    {
+      global $g_user;
+      list($start,$end)=$g_user->get_limit_current_exercice();
+
+      if (isDate($this->start_day) ==null)
+       {
+         $this->start_day=$start;
+       }
+      if ( isDate($this->end_day) == null)
+       {
+         $this->end_day=$end;
+       }
+      $sql=" (jr_date >= to_date('".$this->start_day."','DD.MM.YYYY')
+               and jr_date <= to_date('".$this->end_day."','DD.MM.YYYY'))";
+      return $sql;
+
+    }
+    function show_detail($p_ret)
+    {
+        if (Database::num_row($p_ret)> 0)
+        {
+            echo '<tr class="odd">';
+            echo '<td></td>';
+            echo '<td colspan="5" style="border:1px solid black;width:auto">';
+            include 'template/impress_reconciliation_detail.php';
+            echo '</td>';
+            echo '</tr>';
+        }
+    }
+    /**
+     * Export to CSV
+     * @param type $p_choice 
+     * 
+     * @note must be set before calling
+     *    - $this->a_jrn       array of ledger
+     *    - $this->start_day start date
+     *    - $this->end_day end date
+     * @see Acc_Reconciliation::get_data
+     */
+    function export_csv($p_choice)
+    {
+        $array = $this->get_data($p_choice);
+        for ($i = 0; $i < count($array); $i++)
+        {
+            // ---------------------------------------
+            // first index has 2 arrays : first & depend[]
+            // ---------------------------------------
+
+            $first = $array[$i]['first'];
+            $a_depend = array();
+            if (isset($array[$i]['depend']))
+            {
+                $a_depend = $array[$i]['depend'];
+                //----- HEADER ----
+                if ($i == 0)
+                {
+                    printf('"n°";"Date";"internal";"libellé";"n° pièce";"nom 
journal";"type journal";"montant"');
+                    printf(';"<->";"Date";"internal";"libellé";"n° pièce";"nom 
journal";"type journal";"montant"' . "\n\r");
+                }
+            }
+            else
+            {
+                //----- HEADER ----
+                if ($i == 0)
+                {
+                    printf('"n°";"Date";"internal";"libellé";"n° pièce";"nom 
journal";"type journal";"montant"' . "\n\r");
+                }
+            }
+            // --------------------------
+            // Print First
+            // --------------------------
+            printf('%d;"%s";"%s";"%s";"%s";"%s";"%s";%f',$i, 
$first['jr_date'], $first['jr_internal'], $first['jr_comment'], 
$first['jr_pj_number'], $first['jrn_def_name'], $first['jrn_def_type'], 
$first['jr_montant']);
+            if (count($a_depend) > 0)
+            {
+                // --------------------------------------
+                // Print first depending operation
+                // --------------------------------------
+                $depend = $a_depend[0];
+                printf(';"<->";"%s";"%s";"%s";"%s";"%s";"%s";%f' . "\n\r", 
$depend['jr_date'], $depend['jr_internal'], $depend['jr_comment'], 
$depend['jr_pj_number'], $depend['jrn_def_name'], $depend['jrn_def_type'], 
$depend['jr_montant']);
+
+                // --------------------------------------
+                // print other depending operation if any
+                // --------------------------------------
+                for ($e = 1; $e < count($a_depend); $e++)
+                {
+                    $depend = $a_depend[$e];
+                    printf(';;;;;;;"<->";');
+                    printf('"%s";"%s";"%s";"%s";"%s";"%s";%f' . "\n\r", 
$depend['jr_date'], $depend['jr_internal'], $depend['jr_comment'], 
$depend['jr_pj_number'], $depend['jrn_def_name'], $depend['jrn_def_type'], 
$depend['jr_montant']);
+                }
+            }
+            else
+            {
+                printf("\n\r");
+            }
+        }
+    }
+
+    /**
+     * 
+     * @param type $p_choice
+     *       - 0 : operation reconcilied
+     *       - 1 : reconcilied with different amount
+     *       - 2 : reconcilied with same amount
+     *       - 3 : not reconcilied 
+     * @return $array
+     */
+    function get_data($p_choice)
+    {
+        switch ($p_choice)
+        {
+            case 0:
+                $array = $this->get_reconciled();
+                break;
+            case 1:
+                $array = $this->get_reconciled_amount(false);
+                break;
+            case 2:
+                $array = $this->get_reconciled_amount(true);
+                break;
+            case 3:
+                $array = $this->get_not_reconciled();
+                break;
+            default:
+                echo "Choix invalid";
+                throw new Exception("invalide");
+        }
+        return $array;
+    }
+
+    static function test_me()
+    {
+        $cn=new Database(dossier::id());
+        $rap=new Acc_Reconciliation($cn);
+        var_dump($rap->get_reconciled_amount('',false));
+    }
+
+}
diff --git a/include/class/class_acc_report.php 
b/include/class/class_acc_report.php
new file mode 100644
index 0000000..18c6538
--- /dev/null
+++ b/include/class/class_acc_report.php
@@ -0,0 +1,456 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+// Copyright Author Dany De Bontridder address@hidden
+/*! \file
+ * \brief Create, view, modify and parse report
+ */
+
+require_once NOALYSS_INCLUDE.'/lib/class_itext.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ibutton.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_report_row.php';
+require_once NOALYSS_INCLUDE.'/lib/class_impress.php';
+
+/*!
+ * \brief Class rapport  Create, view, modify and parse report
+ */
+
+class Acc_Report
+{
+
+    var $db;    /*!< $db database connx */
+    var $id;    /*!< $id formdef.fr_id */
+    var $name;  /*!< $name report's name */
+    var $aAcc_Report_row;              /*!< array of rapport_row */
+    var $nb;
+    /*!\brief  Constructor */
+    function __construct($p_cn,$p_id=0)
+    {
+        $this->db=$p_cn;
+        $this->id=$p_id;
+        $this->name='Nouveau';
+        $this->aAcc_Report_row=null;
+    }
+    /*!\brief Return the report's name
+     */
+    function get_name()
+    {
+        $ret=$this->db->exec_sql("select fr_label from formdef where 
fr_id=".$this->id);
+        if (Database::num_row($ret) == 0) return $this->name;
+        $a=Database::fetch_array($ret,0);
+        $this->name=$a['fr_label'];
+        return $this->name;
+    }
+    /*!\brief return all the row and parse formula
+     *        from a report
+     * \param $p_start start periode
+     * \param $p_end end periode
+     * \param $p_type_date type of the date : periode or calendar
+     */
+    function get_row($p_start,$p_end,$p_type_date)
+    {
+
+        $Res=$this->db->exec_sql("select fo_id ,
+                                 fo_fr_id,
+                                 fo_pos,
+                                 fo_label,
+                                 fo_formula,
+                                 fr_label from form
+                                 inner join formdef on fr_id=fo_fr_id
+                                 where fr_id =".$this->id.
+                                 "order by fo_pos");
+        $Max=Database::num_row($Res);
+        if ($Max==0)
+        {
+            $this->row=0;
+            return null;
+        }
+        $col=array();
+        for ($i=0;$i<$Max;$i++)
+        {
+            $l_line=Database::fetch_array($Res,$i);
+            $col[]=Impress::parse_formula($this->db,
+                                $l_line['fo_label'],
+                                $l_line['fo_formula'],
+                                $p_start,
+                                $p_end,
+                                true,
+                                $p_type_date
+                               );
+
+        } //for ($i
+        $this->row=$col;
+        return $col;
+    }
+    /*!
+     * \brief  Display a form for encoding a new report or update one
+     *
+     * \param $p_line number of line
+     *
+     */
+    function form($p_line=0)
+    {
+
+        $r="";
+        if ($p_line == 0 ) $p_line=count($this->aAcc_Report_row);
+        $r.= dossier::hidden();
+        $r.= HtmlInput::hidden('line',$p_line);
+        $r.= HtmlInput::hidden('fr_id',$this->id);
+        $wForm=new IText();
+        $r.="Nom du rapport : ";
+        $r.=$wForm->input('form_nom',$this->name);
+
+        $r.= '<TABLE id="rap1" width="100%">';
+        $r.= "<TR>";
+        $r.= "<TH> Position </TH>";
+        $r.= "<TH> Texte </TH>";
+        $r.= "<TH> Formule</TH>";
+
+        $r.= '</TR>';
+        $wName=new IText();
+        $wName->size=40;
+        $wPos=new IText();
+        $wPos->size=3;
+        $wForm=new IText();
+        $wForm->size=35;
+        for ( $i =0 ; $i < $p_line;$i++)
+        {
+
+            $r.= "<TR>";
+
+            $r.= "<TD>";
+            $wPos->value=( 
isset($this->aAcc_Report_row[$i]->fo_pos))?$this->aAcc_Report_row[$i]->fo_pos:$i+1;
+            $r.=$wPos->input("pos".$i);
+            $r.= '</TD>';
+
+
+            $r.= "<TD>";
+            $wName->value=( 
isset($this->aAcc_Report_row[$i]->fo_label))?$this->aAcc_Report_row[$i]->fo_label:"";
+            $r.=$wName->input("text".$i);
+            $r.= '</TD>';
+
+            $r.='<td>';
+            $search=new IPoste("form".$i);
+            $search->size=50;
+            $search->value=( 
isset($this->aAcc_Report_row[$i]->fo_formula))?$this->aAcc_Report_row[$i]->fo_formula:"";
+            $search->label=_("Recherche poste");
+            $search->set_attribute('gDossier',dossier::id());
+            $search->set_attribute('bracket',1);
+            $search->set_attribute('no_overwrite',1);
+            $search->set_attribute('noquery',1);
+            $search->set_attribute('account',$search->name);
+            $search->set_attribute('ipopup','ipop_card');
+
+            $r.=$search->input();
+            $r.='</td>';
+
+
+            $r.= "</TR>";
+        }
+
+        $r.= "</TABLE>";
+        $wButton=new IButton();
+        $wButton->javascript=" rapport_add_row('".dossier::id()."')";
+        $wButton->label="Ajout d'une ligne";
+        $r.=$wButton->input();
+        return $r;
+
+    }
+    /*!\brief save into form and form_def
+     */
+    function save()
+    {
+
+        if ( strlen(trim($this->name)) == 0 )
+            return;
+        if ( $this->id == 0 )
+            $this->insert();
+        else
+            $this->update();
+
+    }
+    function insert()
+    {
+        try
+        {
+            $this->db->start();
+            $ret_sql=$this->db->exec_sql(
+                         "insert into formdef (fr_label) values($1) returning 
fr_id",
+                         array($this->name)
+                     );
+            $this->id=Database::fetch_result($ret_sql,0,0);
+            $ix=1;
+            foreach ( $this->aAcc_Report_row as $row)
+            {
+                if ( strlen(trim($row->get_parameter("name"))) != 0 &&
+                        strlen(trim($row->get_parameter("formula"))) != 0 )
+                {
+                    
$ix=($row->get_parameter("position")!="")?$row->get_parameter("position"):$ix;
+                    $row->set_parameter("position",$ix);
+                    $ret_sql=$this->db->exec_sql(
+                                 "insert into form 
(fo_fr_id,fo_pos,fo_label,fo_formula)".
+                                 " values($1,$2,$3,$4)",
+                                 array($this->id,
+                                       $row->fo_pos,
+                                       $row->fo_label,
+                                       $row->fo_formula)
+                             );
+                }
+            }
+
+        }
+        catch (Exception $e)
+        {
+            $this->db->rollback();
+            echo $e->getMessage();
+        }
+        $this->db->commit();
+
+    }
+    function update()
+    {
+        try
+        {
+            $this->db->start();
+            $ret_sql=$this->db->exec_sql(
+                         "update formdef set fr_label=$1 where fr_id=$2",
+                         array($this->name,$this->id));
+            $ret_sql=$this->db->exec_sql(
+                         "delete from form where fo_fr_id=$1",
+                         array($this->id));
+            $ix=0;
+
+            foreach ( $this->aAcc_Report_row as $row)
+            {
+                if ( strlen(trim($row->get_parameter("name"))) != 0 &&
+                        strlen(trim($row->get_parameter("formula"))) != 0 )
+                {
+                    
$ix=($row->get_parameter("position")!="")?$row->get_parameter("position"):$ix;
+                    $row->set_parameter("position",$ix);
+                    $ret_sql=$this->db->exec_sql(
+                                 "insert into form 
(fo_fr_id,fo_pos,fo_label,fo_formula)".
+                                 " values($1,$2,$3,$4)",
+                                 array($this->id,
+                                       $row->fo_pos,
+                                       $row->fo_label,
+                                       $row->fo_formula)
+                             );
+                }
+            }
+
+
+        }
+        catch (Exception $e)
+        {
+            $this->db->rollback();
+            echo $e->getMessage();
+        }
+        $this->db->commit();
+    }
+    /*!\brief fill a form thanks an array, usually it is $_POST
+     *\param $p_array keys = fr_id, form_nom,textXX, formXX, posXX where
+        XX is an number
+     */
+    function from_array($p_array)
+    {
+        $this->id=(isset($p_array['fr_id']))?$p_array['fr_id']:0;
+        $this->name=(isset($p_array['form_nom']))?$p_array['form_nom']:"";
+        $ix=0;
+
+        $rr=new Acc_Report_Row();
+        $rr->set_parameter("form_id",$this->id);
+        $rr->set_parameter('database',$this->db);
+
+        $this->aAcc_Report_row=$rr->from_array($p_array);
+
+
+    }
+    /*!\brief the fr_id MUST be set before calling
+     */
+
+
+    function load()
+    {
+        $sql=$this->db->exec_sql(
+                 "select fr_label from formdef where fr_id=$1",
+                 array($this->id));
+        if ( Database::num_row($sql) == 0 ) return;
+        $this->name=Database::fetch_result($sql,0,0);
+        $sql=$this->db->exec_sql(
+                 "select fo_id,fo_pos,fo_label,fo_formula ".
+                 " from form ".
+                 " where fo_fr_id=$1 order by fo_pos",
+                 array($this->id));
+        $f=Database::fetch_all($sql);
+        $array=array();
+        if ( ! empty($f) )
+        {
+            foreach ($f as $r)
+            {
+                $obj=new Acc_Report_Row();
+                $obj->set_parameter("name",$r['fo_label']);
+                $obj->set_parameter("id",$r['fo_id']);
+                $obj->set_parameter("position",$r['fo_pos']);
+                $obj->set_parameter("formula",$r['fo_formula']);
+                $obj->set_parameter('database',$this->db);
+                $obj->set_parameter('form_id',$this->id);
+                $array[]=clone $obj;
+            }
+        }
+        $this->aAcc_Report_row=$array;
+
+    }
+    function delete()
+    {
+        $ret=$this->db->exec_sql(
+                 "delete from formdef where fr_id=$1",
+                 array($this->id)
+             );
+    }
+    /*!\brief get a list from formdef of all defined form
+     *
+     *\return array of object rapport
+     *
+     */
+    function get_list()
+    {
+        $sql="select fr_id,fr_label from formdef order by fr_label";
+        $ret=$this->db->exec_sql($sql);
+        if ( Database::num_row($ret) == 0 ) return array();
+        $array=Database::fetch_all($ret);
+        $obj=array();
+        foreach ($array as $row)
+        {
+            $tmp=new Acc_Report($this->db);
+            $tmp->id=$row['fr_id'];
+            $tmp->name=$row['fr_label'];
+            $obj[]=clone $tmp;
+        }
+        return $obj;
+    }
+    /*!\brief To make a SELECT button with the needed value, it is used
+     *by the SELECT widget
+     *\return string with html code
+     */
+    function make_array()
+    {
+        $sql=$this->db->make_array("select fr_id,fr_label from formdef order 
by fr_label");
+        return $sql;
+    }
+
+
+    /*!\brief write to a file the definition of a report
+     * \param p_file is the file name (default php://output)
+     */
+    function export_csv($p_file)
+    {
+        $this->load();
+
+        fputcsv($p_file,array($this->name));
+
+        foreach ($this->aAcc_Report_row as $row)
+        {
+            fputcsv($p_file,array($row->get_parameter("name"),
+                                  $row->get_parameter('position'),
+                                  $row->get_parameter('formula'))
+                   );
+        }
+
+    }
+    /*!\brief upload a definition of a report and insert it into the
+     * database
+     */
+    function upload()
+    {
+        if ( empty ($_FILES) ) return;
+        if ( strlen(trim($_FILES['report']['tmp_name'])) == 0 )
+        {
+            alert("Nom de fichier est vide");
+            return;
+        }
+        $file_report=tempnam('tmp','file_report');
+        if (  move_uploaded_file($_FILES['report']['tmp_name'],$file_report))
+        {
+            // File is uploaded now we can try to parse it
+            $file=fopen($file_report,'r');
+            $data=fgetcsv($file);
+            if ( empty($data) ) return;
+            $this->name=$data[0];
+            $array=array();
+            while($data=fgetcsv($file))
+            {
+                $obj=new Acc_Report_Row();
+                $obj->set_parameter("name",$data[0]);
+                $obj->set_parameter("id",0);
+                $obj->set_parameter("position",$data[1]);
+                $obj->set_parameter("formula",$data[2]);
+                $obj->set_parameter('database',$this->db);
+                $obj->set_parameter('form_id',0);
+                $array[]=clone $obj;
+            }
+            $this->aAcc_Report_row=$array;
+            $this->insert();
+        }
+    }
+    /**
+     address@hidden check if a report exist
+     address@hidden $p_id, optional, if given check the report with this fr_id
+     address@hidden return true if the report exist otherwise false
+     */
+    function exist($p_id=0)
+    {
+        $c=$this->id;
+        if ( $p_id != 0 ) $c=$p_id;
+        $ret=$this->db->exec_sql("select fr_label from formdef where 
fr_id=$1",array($c));
+        if (Database::num_row($ret) == 0) return false;
+        return true;
+    }
+    static function test_me()
+    {
+        $cn=new Database(dossier::id());
+        $a=new Acc_Report($cn);
+        print_r($a->get_list());
+        $array=array("text0"=>"test1",
+                     "form0"=>"7%",
+                     "text1"=>"test2",
+                     "form1"=>"6%",
+                     "fr_id"=>110,
+                     "form_nom"=>"Tableau"
+                    );
+        $a->from_array($array);
+        print_r($a);
+        echo '<form method="post">';
+        echo $a->form(10);
+
+        echo HtmlInput::submit('update','Enregistre');
+        /* Add a line should be a javascript see comptanalytic */
+        //  $r.= '<INPUT TYPE="submit" value="Ajoute une ligne" 
name="add_line">';
+        echo HtmlInput::submit('del_form','Efface ce rapport');
+        echo HtmlInput::hidden('test_select',$_REQUEST['test_select']);
+        echo "</FORM>";
+        if ( isset ($_POST['update']))
+        {
+            $b=new Acc_Report($cn);
+            $b->from_array($_POST);
+            echo '<hr>';
+            print_r($b);
+        }
+    }
+}
+
+?>
diff --git a/include/class_acc_report_row.php 
b/include/class/class_acc_report_row.php
similarity index 100%
rename from include/class_acc_report_row.php
rename to include/class/class_acc_report_row.php
diff --git a/include/class/class_acc_tva.php b/include/class/class_acc_tva.php
new file mode 100644
index 0000000..61e00a3
--- /dev/null
+++ b/include/class/class_acc_tva.php
@@ -0,0 +1,202 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief this class is used for the table tva_rate
+ */
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+
+/*!\brief Acc_Tva is used for to map the table tva_rate
+ * parameter are
+- private static $cn;  database connection
+- private static $variable=array("id"=>"tva_id",
+                "label"=>"tva_label",
+                "rate"=>"tva_rate",
+                "comment"=>"tva_comment",
+                "account"=>"tva_poste");
+
+*/
+class Acc_Tva
+{
+    private  $cn;              /*!< $cn database connection */
+    private static $variable=array("id"=>"tva_id",
+                                   "label"=>"tva_label",
+                                   "rate"=>"tva_rate",
+                                   "comment"=>"tva_comment",
+                                   "account"=>"tva_poste",
+                                    "both_side"=>'tva_both_side');
+
+    function __construct ($p_init,$p_tva_id=0)
+    {
+        $this->cn=$p_init;
+        $this->tva_id=$p_tva_id;
+        $this->poste="";
+    }
+    public function get_parameter($p_string)
+    {
+        if ( array_key_exists($p_string,self::$variable) )
+        {
+            $idx=self::$variable[$p_string];
+            return $this->$idx;
+        }
+
+        echo  (__FILE__.":".__LINE__.'Erreur attribut inexistant');
+    }
+    public function set_parameter($p_string,$p_value)
+    {
+        if ( array_key_exists($p_string,self::$variable) )
+        {
+            $idx=self::$variable[$p_string];
+            $this->$idx=$p_value;
+        }
+        else
+            throw new Exception("Attribut inexistant $p_string");
+
+
+    }
+    public function get_info()
+    {
+        return var_export(self::$variable,true);
+    }
+
+    public function verify()
+    {
+        // Verify that the elt we want to add is correct
+    }
+    public function save()
+    {
+
+        if (  $this->tva_id == 0 )
+            $this->insert();
+        else
+            $this->update();
+    }
+
+    public function insert()
+    {
+        if ( $this->verify() != 0 ) return;
+        $sql="select tva_insert($1,$2,$3,$4,$5)";
+
+        $res=$this->cn->exec_sql(
+                 $sql,
+                 array($this->tva_label,
+                       $this->tva_rate,
+                       $this->tva_comment,
+                       $this->tva_poste,
+                        $this->tva_both_side)
+             );
+        $this->tva_id=$this->cn->get_current_seq('s_tva');
+        $err=Database::fetch_result($res);
+    }
+
+    public function update()
+    {
+        if ( $this->verify() != 0 ) return;
+        $sql="update tva_rate set 
tva_label=$1,tva_rate=$2,tva_comment=$3,tva_poste=$4,tva_both_side=$5 ".
+             " where tva_id = $6";
+        $res=$this->cn->exec_sql(
+                 $sql,
+                 array($this->tva_label,
+                       $this->tva_rate,
+                       $this->tva_comment,
+                       $this->tva_poste,
+                       $this->tva_both_side,
+                       $this->tva_id)
+             );
+
+    }
+    /**
+     *Load the VAT,
+     address@hidden if the label is not found then we get an message error, so 
the best is probably
+     *to initialize the VAT object with default value
+     */
+    public function load()
+    {
+        $sql="select tva_id,tva_label,tva_rate, 
tva_comment,tva_poste,tva_both_side from tva_rate where tva_id=$1";
+        $res=$this->cn->exec_sql(
+                 $sql,
+                 array($this->tva_id)
+             );
+
+        if ( $this->cn->size() == 0 ) return -1;
+
+        $row=Database::fetch_array($res,0);
+        foreach ($row as $idx=>$value)
+        {
+            $this->$idx=$value;
+        }
+        return 0;
+    }
+    /*!\brief get the account of the side (debit or credit)
+     *\param $p_side is d or C
+     *\return the account to use
+     *\note call first load if tva_poste is empty
+     */
+    public function get_side($p_side)
+    {
+        if ( strlen($this->tva_poste) == 0 ) $this->load();
+        list($deb,$cred)=explode(",",$this->tva_poste);
+        switch ($p_side)
+        {
+        case 'd':
+                return $deb;
+            break;
+        case 'c':
+            return $cred;
+            break;
+        default:
+            throw (new Exception (__FILE__.':'.__LINE__." param est d ou c, on 
a recu [ $p_side ]"));
+        }
+    }
+    public function delete()
+    {
+        $sql="delete from tva_rate where tva_id=$1";
+        $res=$this->cn->exec_sql($sql,array($this->tva_id));
+    }
+    /*!\brief
+     * Test function
+     */
+    static function test_me()
+    {
+        $cn=new Database(dossier::id());
+        $a=new Acc_Tva($cn);
+        echo $a->get_info();
+        $a->set_parameter("id",1);
+        $a->load();
+        $a->set_parameter("id",0);
+        $a->set_parameter("rate","0.2222");
+        $a->set_parameter("label","test");
+        $a->save();
+        $a->load();
+        print_r($a);
+
+        $a->set_parameter("comment","un cht'it test");
+        $a->save();
+        $a->load();
+        print_r($a);
+
+        $a->delete();
+    }
+
+}
+
+/* test::test_me(); */
diff --git a/include/class/class_admin.php b/include/class/class_admin.php
new file mode 100644
index 0000000..b0a5a3d
--- /dev/null
+++ b/include/class/class_admin.php
@@ -0,0 +1,58 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+// Copyright Author Dany De Bontridder address@hidden
+require_once NOALYSS_INCLUDE.'/constant.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_parm_code.php';
+
+require_once NOALYSS_INCLUDE.'/class/class_fiche.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_account_ledger.php';
+require_once NOALYSS_INCLUDE.'/lib/user_common.php';
+/*! \file
+ * \brief Derived from class fiche Administration are a specific kind of card
+ *        concerned only by official (or not) administration
+ */
+/*!
+ * \brief  class  admin are a specific kind of card
+ */
+
+// Use the view vw_supplier
+//
+class Admin extends Fiche
+{
+
+    var $name;        /*!< $name name of the company */
+    var $street;      /*!< $street Street */
+    var $country;     /*!< $country Country */
+    var $cp;          /*!< $cp Zip code */
+    var $vat_number;  /*!< $vat_number vat number */
+
+    /*! \brief Constructor
+    /* only a db connection is needed */
+    function Admin($p_cn,$p_id=0)
+    {
+        $this->fiche_def_ref=FICHE_TYPE_ADM_TAX;
+        parent::__construct($p_cn,$p_id) ;
+    }
+
+
+
+}
+
+?>
diff --git a/include/class/class_anc_acc_link.php 
b/include/class/class_anc_acc_link.php
new file mode 100644
index 0000000..4adbcc8
--- /dev/null
+++ b/include/class/class_anc_acc_link.php
@@ -0,0 +1,61 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief link between accountancy and analytic, like table but as a listing
+ */
+require_once NOALYSS_INCLUDE.'/class/class_anc_print.php';
+
+class Anc_Acc_Link extends Anc_Print
+{
+  function __contruct($p_cn)
+  {
+    $this->cn=$p_cn;
+  }
+
+  /**
+   address@hidden get the parameters
+   */
+  function get_request()
+  {
+    parent::get_request();
+    $this->card_poste=HtmlInput::default_value('card_poste',1,$_GET);
+  }
+    function set_sql_filter()
+    {
+        $sql="";
+        $and=" and ";
+        if ( $this->from != "" )
+        {
+            $sql.="$and oa_date >= to_date('".$this->from."','DD.MM.YYYY')";
+        }
+        if ( $this->to != "" )
+        {
+            $sql.=" $and oa_date <= to_date('".$this->to."','DD.MM.YYYY')";
+        }
+
+        return $sql;
+
+    }
+
+
+}
+
diff --git a/include/class/class_anc_acc_list.php 
b/include/class/class_anc_acc_list.php
new file mode 100644
index 0000000..70fe3ac
--- /dev/null
+++ b/include/class/class_anc_acc_list.php
@@ -0,0 +1,545 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief
+ */
+
+require_once NOALYSS_INCLUDE.'/class/class_anc_acc_link.php';
+
+class Anc_Acc_List extends Anc_Acc_Link
+{
+  /**
+   address@hidden display form to get the parameter
+   *  - card_poste 1 by card, 2 by account
+   *  - from_poste
+   *  - to_poste
+   *  - from from date
+   *  - to until date
+   *  - pa_id Analytic plan to use
+   */
+  function display_form($p_hidden='')
+  {
+    $r=parent::display_form($p_hidden);
+    $icard=new ISelect('card_poste');
+    $icard->value=array(
+                       array('value'=>1,'label'=>'Par fiche /Activité'),
+                       array('value'=>2,'label'=>'Par poste 
comptable/Activité'),
+                       array('value'=>3,'label'=>'Par activité/Fiche'),
+                       array('value'=>4,'label'=>'Par activité/Poste 
Comptable')
+
+                       );
+
+    $icard->selected=$this->card_poste;
+    $r.=$icard->input();
+    $r.=HtmlInput::request_to_hidden(array('ac'));
+    return $r;
+  }
+ /**
+   * load the data
+   * does not return anything but give a value to this->aheader and this->arow
+   */
+  function load_anc_account()
+  {
+    $date=$this->set_sql_filter();
+    $date=($date != '')?"  $date":'';
+    $sql_from_poste=($this->from_poste!='')?" and  po.po_name >= 
upper('".Database::escape_string($this->from_poste)."')":'';
+    $sql_to_poste=($this->to_poste!='')?" and  po.po_name <= 
upper('".Database::escape_string($this->to_poste)."')":'';
+    $this->arow=$this->db->get_array("
+ SELECT po.po_id, po.pa_id, po.po_name, po.po_description, sum(
+        CASE
+            WHEN operation_analytique.oa_debit = true THEN 
operation_analytique.oa_amount * (-1)::numeric
+            ELSE operation_analytique.oa_amount
+        END) AS sum_amount, jrnx.j_poste, tmp_pcmn.pcm_lib AS name
+   FROM operation_analytique
+   JOIN poste_analytique po USING (po_id)
+   JOIN jrnx USING (j_id)
+   JOIN tmp_pcmn ON jrnx.j_poste::text = tmp_pcmn.pcm_val::text ".
+"                                      where
+               pa_id=$1 ".$date.$sql_from_poste.$sql_to_poste."
+
+  GROUP BY po.po_id, po.po_name, po.pa_id, jrnx.j_poste, tmp_pcmn.pcm_lib, 
po.po_description
+ HAVING sum(
+CASE
+    WHEN operation_analytique.oa_debit = true THEN 
operation_analytique.oa_amount * (-1)::numeric
+    ELSE operation_analytique.oa_amount
+END) <> 0::numeric  order by po_id,j_poste",array($this->pa_id));
+
+  }
+  /**
+   * load the data
+   * does not return anything but give a value to this->aheader and this->arow
+   */
+  function load_anc_card()
+  {
+    $date=$this->set_sql_filter();
+    $date=($date != '')?"  $date":'';
+    $sql_from_poste=($this->from_poste!='')?" and  po.po_name >= 
upper('".Database::escape_string($this->from_poste)."')":'';
+    $sql_to_poste=($this->to_poste!='')?" and  po.po_name <= 
upper('".Database::escape_string($this->to_poste)."')":'';
+    $this->arow=$this->db->get_array(" SELECT po.po_id, po.pa_id, po.po_name, 
po.po_description, sum(
+        CASE
+            WHEN operation_analytique.oa_debit = true THEN 
operation_analytique.oa_amount * (-1)::numeric
+            ELSE operation_analytique.oa_amount
+        END) AS sum_amount, jrnx.f_id, jrnx.j_qcode, ( SELECT 
fiche_detail.ad_value
+           FROM fiche_detail
+          WHERE fiche_detail.ad_id = 1 AND fiche_detail.f_id = jrnx.f_id) AS 
name
+   FROM operation_analytique
+   JOIN poste_analytique po USING (po_id)
+   JOIN jrnx USING (j_id) ".
+                                    " where pa_id=$1 
".$date.$sql_from_poste.$sql_to_poste
+                                    ."
+  GROUP BY po.po_id, po.po_name, po.pa_id, jrnx.f_id, jrnx.j_qcode, ( SELECT 
fiche_detail.ad_value
+   FROM fiche_detail
+  WHERE fiche_detail.ad_id = 1 AND fiche_detail.f_id = jrnx.f_id), 
po.po_description
+ HAVING sum(
+CASE
+    WHEN operation_analytique.oa_debit = true THEN 
operation_analytique.oa_amount * (-1)::numeric
+    ELSE operation_analytique.oa_amount
+END) <> 0::numeric order by po_name,name",array($this->pa_id));
+
+  }
+
+  /**
+   * load the data
+   * does not return anything but give a value to this->aheader and this->arow
+   */
+  function load_poste()
+  {
+    $date=$this->set_sql_filter();
+    $date=($date != '')?"  $date":'';
+    $sql_from_poste=($this->from_poste!='')?" and  po.po_name >= 
upper('".Database::escape_string($this->from_poste)."')":'';
+    $sql_to_poste=($this->to_poste!='')?" and  po.po_name <= 
upper('".Database::escape_string($this->to_poste)."')":'';
+  $this->arow=$this->db->get_array("SELECT po.po_id, po.pa_id, po.po_name, 
po.po_description, sum(
+        CASE
+            WHEN operation_analytique.oa_debit = true THEN 
operation_analytique.oa_amount * (-1)::numeric
+            ELSE operation_analytique.oa_amount
+        END) AS sum_amount, jrnx.j_poste, tmp_pcmn.pcm_lib AS name
+   FROM operation_analytique
+   JOIN poste_analytique po USING (po_id)
+   JOIN jrnx USING (j_id)
+   JOIN tmp_pcmn ON jrnx.j_poste::text = tmp_pcmn.pcm_val::text ".
+"                                      where
+               pa_id=$1 ".$date.$sql_from_poste.$sql_to_poste."
+
+  GROUP BY po.po_id, po.po_name, po.pa_id, jrnx.j_poste, tmp_pcmn.pcm_lib, 
po.po_description
+ HAVING sum(
+CASE
+    WHEN operation_analytique.oa_debit = true THEN 
operation_analytique.oa_amount * (-1)::numeric
+    ELSE operation_analytique.oa_amount
+END) <> 0::numeric  order by j_poste,po_name",array($this->pa_id));
+
+  }
+
+  /**
+   * load the data
+   * does not return anything but give a value to this->aheader and this->arow
+   */
+  function load_card()
+  {
+    $date=$this->set_sql_filter();
+    $date=($date != '')?"  $date":'';
+    $sql_from_poste=($this->from_poste!='')?" and  po.po_name >= 
upper('".Database::escape_string($this->from_poste)."')":'';
+    $sql_to_poste=($this->to_poste!='')?" and  po.po_name <= 
upper('".Database::escape_string($this->to_poste)."')":'';
+
+   $this->arow=$this->db->get_array(" SELECT po.po_id, po.pa_id, po.po_name, 
po.po_description, sum(
+        CASE
+            WHEN operation_analytique.oa_debit = true THEN 
operation_analytique.oa_amount * (-1)::numeric
+            ELSE operation_analytique.oa_amount
+        END) AS sum_amount, jrnx.f_id, jrnx.j_qcode, ( SELECT 
fiche_detail.ad_value
+           FROM fiche_detail
+          WHERE fiche_detail.ad_id = 1 AND fiche_detail.f_id = jrnx.f_id) AS 
name
+   FROM operation_analytique
+   JOIN poste_analytique po USING (po_id)
+   JOIN jrnx USING (j_id) ".
+                                    " where pa_id=$1 
".$date.$sql_from_poste.$sql_to_poste
+                                    ."
+  GROUP BY po.po_id, po.po_name, po.pa_id, jrnx.f_id, jrnx.j_qcode, ( SELECT 
fiche_detail.ad_value
+   FROM fiche_detail
+  WHERE fiche_detail.ad_id = 1 AND fiche_detail.f_id = jrnx.f_id), 
po.po_description
+ HAVING sum(
+CASE
+    WHEN operation_analytique.oa_debit = true THEN 
operation_analytique.oa_amount * (-1)::numeric
+    ELSE operation_analytique.oa_amount
+END) <> 0::numeric order by name,po_name",array($this->pa_id));
+  }
+  /**
+   address@hidden display the button export CSV
+   address@hidden $p_hidden is a string containing hidden items
+   address@hidden html string
+   */
+  function show_button($p_hidden="")
+  {
+    $r="";
+    $r.= '<form method="GET" action="export.php"  style="display:inline">';
+    $r.= HtmlInput::hidden("act","CSV:AncAccList");
+    $r.= HtmlInput::hidden("to",$this->to);
+    $r.= HtmlInput::hidden("from",$this->from);
+    $r.= HtmlInput::hidden("pa_id",$this->pa_id);
+    $r.= HtmlInput::hidden("from_poste",$this->from_poste);
+    $r.= HtmlInput::hidden("to_poste",$this->to_poste);
+    $r.= HtmlInput::hidden("card_poste",$this->card_poste);
+
+    $r.= $p_hidden;
+    $r.= dossier::hidden();
+    $r.=HtmlInput::submit('bt_csv',"Export en CSV");
+    $r.= '</form>';
+    return $r;
+  }
+  function display_html()
+  {
+    bcscale(2);
+    if ( $this->check()  != 0)
+      {
+       alert('Désolé mais une des dates données n\'est pas valide');
+       return;
+      }
+    
//---------------------------------------------------------------------------
+    // Card  - Acc
+    
//---------------------------------------------------------------------------
+
+    if ( $this->card_poste=='1')
+      {
+       $this->load_card();
+
+       /*
+        * Show all the result
+        */
+       $tot_card=0;$prev='';
+       echo '<table class="result" style="margin-left:5px;margin-top:5px">';
+       $tot_glob=0;
+       for ($i=0;$i<count($this->arow);$i++)
+         {
+           if ( $i == 0 )
+             {
+               $prev=$this->arow[$i]['f_id'];
+               echo '<tr><td>'.HtmlInput::history_card 
($this->arow[$i]['f_id'],$this->arow[$i]['j_qcode'].' 
'.$this->arow[$i]['name'],' display:inline').'</td></tr>';
+             }
+           $style= ( $i % 2 == 0)?' class="odd" ':' class="even" ';
+           if ( $i != 0 && $prev != $this->arow[$i]['f_id'])
+             {
+               echo  td('Total');
+               echo td(nbm($tot_card),' class="num"');
+               echo '</tr>';
+               echo '<tr  
style="padding-top:5px"><td>'.HtmlInput::history_card($this->arow[$i]['f_id'],$this->arow[$i]['j_qcode'].'
 '.$this->arow[$i]['name'],' display:inline ').'</td></tr>';
+               $tot_card=0;
+               $prev = $this->arow[$i]['f_id'];
+             }
+
+           echo '<tr '.$style.'>';
+           $amount=$this->arow[$i]['sum_amount'];
+           if ($amount==null)$amount=0;
+
+           $tot_card=bcadd($tot_card,$amount);
+           $tot_glob=bcadd($tot_glob,$amount);
+           echo td($this->arow[$i]['po_name']."   ".
+                   
$this->arow[$i]['po_description'],'style="padding-left:10"');
+           echo td(nbm($amount),' class="num" ');
+           echo '</tr>';
+
+         }
+       echo '<tr>';
+       echo  td('Total');
+       echo td(nbm($tot_card),' class="num"');
+       echo '</tr>';
+
+       echo '</table>';
+       echo '<h2> Résultat global '.nbm($tot_glob).'</h2>';
+      }
+    
//---------------------------------------------------------------------------
+    // Accountancy - Analytic
+    
//---------------------------------------------------------------------------
+
+    if ( $this->card_poste=='2')
+      {
+       $this->load_poste();
+       /*
+        * Show all the result
+        */
+       $tot_card=0;$prev='';
+       echo '<table class="result" style="margin-left:20px;margin-top:5px">';
+       $tot_glob=0;
+       for ($i=0;$i<count($this->arow);$i++)
+         {
+           if ( $i == 0 )
+             {
+               $prev=$this->arow[$i]['j_poste'];
+               echo '<tr><td>'.HtmlInput::history_account 
($this->arow[$i]['j_poste'],$this->arow[$i]['j_poste'].' 
'.$this->arow[$i]['name'],' display:inline').'</td></tr>';
+             }
+           $style= ( $i % 2 == 0)?' class="odd" ':' class="even" ';
+           if ( $i != 0 && $prev != $this->arow[$i]['j_poste'])
+             {
+               echo  td('Total');
+               echo td(nbm($tot_card),' class="num"');
+               echo '</tr>';
+               echo '<tr  
style="padding-top:5px"><td>'.HtmlInput::history_account($this->arow[$i]['j_poste'],$this->arow[$i]['j_poste'].'
 '.$this->arow[$i]['name'],' display:inline ').'</td></tr>';
+               $tot_card=0;
+               $prev = $this->arow[$i]['j_poste'];
+             }
+
+           echo '<tr '.$style.'>';
+           $amount=$this->arow[$i]['sum_amount'];
+           if ($amount==null)$amount=0;
+
+           $tot_card=bcadd($tot_card,$amount);
+           $tot_glob=bcadd($tot_glob,$amount);
+
+
+           echo td($this->arow[$i]['po_name']."   ".
+                   
$this->arow[$i]['po_description'],'style="padding-left:10"');
+           echo td(nbm($amount),' class="num" ');
+           echo '</tr>';
+
+         }
+       echo '<tr>';
+       echo  td('Total');
+       echo td(nbm($tot_card),' class="num"');
+       echo '</tr>';
+
+       echo '</table>';
+       echo td(nbm($tot_card),' class="num"');
+      }
+    
//---------------------------------------------------------------------------
+    // Acc after card
+    
//---------------------------------------------------------------------------
+    if ( $this->card_poste=='3')
+      {
+       $this->load_anc_card();
+       /*
+        * Show all the result
+        */
+       $tot_card=0;$prev='';
+       echo '<table class="result" style="margin-left:20px;margin-top:5px">';
+       $tot_glob=0;
+       for ($i=0;$i<count($this->arow);$i++)
+         {
+           if ( $i == 0 )
+             {
+               $prev=$this->arow[$i]['po_id'];
+               echo '<tr><td>'.$this->arow[$i]['po_name']."  
".$this->arow[$i]['po_description'].'</td></tr>';
+
+             }
+           $style= ( $i % 2 == 0)?' class="odd" ':' class="even" ';
+           if ( $i != 0 && $prev != $this->arow[$i]['po_id'])
+             {
+               echo  td('Total');
+               echo td(nbm($tot_card),' class="num"');
+               echo '</tr>';
+               echo '<tr><td>'.$this->arow[$i]['po_name']."  
".$this->arow[$i]['po_description'].'</td></tr>';
+
+               $tot_card=0;
+               $prev = $this->arow[$i]['po_id'];
+             }
+
+           echo '<tr '.$style.'>';
+           $amount=$this->arow[$i]['sum_amount'];
+           if ($amount==null)$amount=0;
+
+           $tot_card=bcadd($tot_card,$amount);
+           $tot_glob=bcadd($tot_glob,$amount);
+           echo '<td style="padding-left:10">'.HtmlInput::history_card 
($this->arow[$i]['f_id'],$this->arow[$i]['j_qcode'].' 
'.$this->arow[$i]['name'],' display:inline').'</td>';
+
+           echo td(nbm($amount),' class="num" ');
+           echo '</tr>';
+
+         }
+       echo '<tr>';
+       echo  td('Total');
+       echo td(nbm($tot_card),' class="num"');
+       echo '</tr>';
+
+       echo '</table>';
+       echo td(nbm($tot_card),' class="num"');
+      }
+    
//---------------------------------------------------------------------------
+    // Analytic - Accountancy
+    
//---------------------------------------------------------------------------
+
+
+    if ( $this->card_poste=='4')
+      {
+       $this->load_anc_account();
+
+       /*
+        * Show all the result
+        */
+       $tot_card=0;$prev='';
+       echo '<table class="result" style="margin-left:20px;margin-top:5px">';
+       $tot_glob=0;
+       for ($i=0;$i<count($this->arow);$i++)
+         {
+           if ( $i == 0 )
+             {
+               $prev=$this->arow[$i]['po_id'];
+               echo '<tr><td>'.$this->arow[$i]['po_name']."  
".$this->arow[$i]['po_description'].'</td></tr>';
+             }
+           $style= ( $i % 2 == 0)?' class="odd" ':' class="even" ';
+           if ( $i != 0 && $prev != $this->arow[$i]['po_id'])
+             {
+               echo  td('Total');
+               echo td(nbm($tot_card),' class="num"');
+               echo '</tr>';
+
+               $tot_card=0;
+               $prev = $this->arow[$i]['po_id'];
+               echo '<tr><td>'.$this->arow[$i]['po_name']."  
".$this->arow[$i]['po_description'].'</td></tr>';
+
+             }
+
+           echo '<tr '.$style.'>';
+           $amount=$this->arow[$i]['sum_amount'];
+           if ($amount==null)$amount=0;
+
+           $tot_card=bcadd($tot_card,$amount);
+           $tot_glob=bcadd($tot_glob,$amount);
+           echo '<td style="padding-left:10">'.HtmlInput::history_account 
($this->arow[$i]['j_poste'],$this->arow[$i]['j_poste'].' 
'.$this->arow[$i]['name'],' display:inline').'</td>';
+           echo td(nbm($amount),' class="num" ');
+           echo '</tr>';
+
+         }
+       echo '<tr>';
+       echo  td('Total');
+       echo td(nbm($tot_card),' class="num"');
+       echo '</tr>';
+
+       echo '</table>';
+       echo '<h2> Résultat global '.nbm($tot_glob).'</h2>';
+      }
+
+  }
+  function export_csv()
+  {
+   bcscale(2);
+   if ( $this->check () != 0 ) {throw new Exception (_("date invalide"));}
+      
//---------------------------------------------------------------------------
+    // Card  - Acc
+    
//---------------------------------------------------------------------------
+
+    if ( $this->card_poste=='1')
+      {
+       $this->load_card();
+
+       /*
+        * Show all the result
+        */
+       $prev='';
+
+
+       for ($i=0;$i<count($this->arow);$i++)
+         {
+           printf('"%s";" %s"', 
$this->arow[$i]['j_qcode'],$this->arow[$i]['name']);
+
+           $amount=$this->arow[$i]['sum_amount'];
+           if ($amount==null)$amount=0;
+
+           printf(';"%s";" %s";',
+                  $this->arow[$i]['po_name'],
+                  $this->arow[$i]['po_description']);
+           printf("%s",nb($amount));
+           printf("\r\n");
+         }
+      }
+    
//---------------------------------------------------------------------------
+    // Accountancy - Analytic
+    
//---------------------------------------------------------------------------
+
+    if ( $this->card_poste=='2')
+      {
+       $this->load_poste();
+       /*
+        * Show all the result
+        */
+       for ($i=0;$i<count($this->arow);$i++)
+         {
+           printf('"%s";" %s"', 
$this->arow[$i]['j_poste'],$this->arow[$i]['name']);
+
+           $amount=$this->arow[$i]['sum_amount'];
+           if ($amount==null)$amount=0;
+
+           printf(';"%s";" %s";',
+                  $this->arow[$i]['po_name'],
+                  $this->arow[$i]['po_description']);
+           printf("%s",nb($amount));
+           printf("\r\n");
+
+
+         }
+
+      }
+    
//---------------------------------------------------------------------------
+    // Acc after card
+    
//---------------------------------------------------------------------------
+    if ( $this->card_poste=='3')
+      {
+       $this->load_anc_card();
+       /*
+        * Show all the result
+        */
+       for ($i=0;$i<count($this->arow);$i++)
+         {
+           printf('"%s";" %s";', 
$this->arow[$i]['po_name'],$this->arow[$i]['po_description']);
+
+           $amount=$this->arow[$i]['sum_amount'];
+           if ($amount==null)$amount=0;
+
+           printf('"%s";"%s";',
+                  $this->arow[$i]['j_qcode'],
+                  $this->arow[$i]['name']);
+           printf("%s",nb($amount));
+           printf("\r\n");
+
+
+         }
+      }
+    
//---------------------------------------------------------------------------
+    // Analytic - Accountancy
+    
//---------------------------------------------------------------------------
+
+
+    if ( $this->card_poste=='4')
+      {
+       $this->load_anc_account();
+
+       /*
+        * Show all the result
+        */
+       for ($i=0;$i<count($this->arow);$i++)
+         {
+           printf('"%s";"%s";', 
$this->arow[$i]['po_name'],$this->arow[$i]['po_description']);
+
+           $amount=$this->arow[$i]['sum_amount'];
+           if ($amount==null)$amount=0;
+
+           printf('"%s";"%s";',
+                  $this->arow[$i]['j_poste'],
+                  $this->arow[$i]['name']);
+           printf("%s",nb($amount));
+           printf("\r\n");
+
+
+         }
+      }
+
+
+
+
+  }
+
+}
\ No newline at end of file
diff --git a/include/class/class_anc_account.php 
b/include/class/class_anc_account.php
new file mode 100644
index 0000000..282dde6
--- /dev/null
+++ b/include/class/class_anc_account.php
@@ -0,0 +1,349 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+*\brief contains the object for the poste_analytique (table poste_analytique)
+ */
+
+/*!\brief contains the object for the poste_analytique (table poste_analytique)
+ *
+ */
+require_once NOALYSS_INCLUDE.'/lib/class_ihidden.php';
+require_once NOALYSS_INCLUDE.'/lib/class_itext.php';
+require_once NOALYSS_INCLUDE.'/lib/class_iselect.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ispan.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/class/class_anc_plan.php';
+
+class Anc_Account
+{
+    var $id; /*!<  $id is po_id */
+    var $name;         /*!< po_name */
+    var $pa_id;                /*!< pa_id fk to the plan_analytique(pa_id) */
+    var $amount;               /*!< po_amount just an amount  */
+    var $description;       /*!< po_description description of the post */
+    var $db;   /*!< database     connection*/
+    var $ga_id;                /*!< FK to the table groupe analytique */
+    function Anc_Account($p_db,$p_id=0)
+    {
+        $this->db=$p_db;
+        $this->id=$p_id;
+        $this->ga_id=null;
+    }
+    /*! \brief retrieve data from the database and
+     *        fill the object
+     * \param $p_where the where clause
+     */
+    private function fetch_from_db($p_where)
+    {
+        $sql="select po_id,
+             po_name ,
+             pa_id,
+             po_amount,
+             po_description,
+             ga_id
+             from poste_analytique
+             where ".
+             $p_where;
+
+        $ret=$this->db->exec_sql($sql);
+        if ( Database::num_row($ret) == 0 )return null;
+        $line=Database::fetch_array($ret);
+
+        $this->id=$line['po_id'];
+        $this->name=$line['po_name'];
+        $this->pa_id=$line['pa_id'];
+        $this->amount=$line['po_amount'];
+        $this->description=$line['po_description'];
+        $this->ga_id=$line['ga_id'];
+
+
+    }
+    function get_by_id()
+    {
+        $this->fetch_from_db("po_id=".$this->id);
+    }
+    /*!
+     * \brief retrieve data thanks the name
+     * \param $p_name name of the analytic account
+     *
+     */
+    function get_by_name($p_name)
+    {
+        $p_name=sql_string($p_name);
+        if ( $p_name == null )
+            $p_name=$this->name;
+
+        $this->fetch_from_db("po_name='".$p_name."'");
+        echo "id = ".$this->id;
+    }
+    function add()
+    {
+        $this->format_data();
+        if ( strlen($this->name) == 0)
+            return;
+        if ( $this->ga_id == null || strlen(trim($this->ga_id)) == 0 )
+            $ga_id=NULL;
+        else
+            $ga_id=$this->ga_id;
+        $sql="insert into poste_analytique (
+             po_name ,
+             pa_id,
+             po_amount,
+             po_description,
+             ga_id
+             ) values ($1,$2,$3,$4,$5)";
+
+        try
+        {
+            
$this->db->exec_sql($sql,array($this->name,$this->pa_id,$this->amount,$this->description,$ga_id));
+
+        }
+        catch (Exception $e)
+        {
+            if ( DEBUG ) print_r($e);
+            echo "<p class=\"notice\">Doublon : l'enregistrement n'est pas 
sauve</p>";
+        }
+
+    }
+    static function make_array_name($cn,$pa_id)
+    {
+        $a=$cn->make_array("select  po_name,po_name from poste_analytique ".
+                           " where ".
+                           " pa_id = $1 order by po_name ",0,array($pa_id));
+        return $a;
+    }
+    function update()
+    {
+        $this->format_data();
+        if ( strlen($this->name) == 0)
+            return;
+        $sql="update poste_analytique ".
+             " set po_name=$1".
+             " ,pa_id=$2".
+             " ,po_amount=$3".
+             " ,po_description=$4".
+             " ,ga_id=$5".
+             " where po_id=$6";
+        try
+        {
+            
$this->db->exec_sql($sql,array($this->name,$this->pa_id,$this->amount,
+                                           
$this->description,$this->ga_id,$this->id));
+        }
+        catch (Exception $e)
+        {
+            echo "<p class=\"notice\">Doublon : l'enregistrement n'est pas 
sauve</p>";
+        }
+
+    }
+    private function format_data()
+    {
+
+        $this->name=$this->name;
+        $this->pa_id=$this->pa_id;
+        $this->amount=$this->amount;
+        if (strlen($this->amount) == 0 )
+            $this->amount=0.0;
+        if ( isNumber($this->amount) ==0 )
+            $this->amount=0;
+
+        $this->description=$this->description;
+    }
+    function delete()
+    {
+        $sql="delete from poste_analytique where po_id=".$this->id;
+        $this->db->exec_sql($sql);
+    }
+    /*! 
+     * \brief return an array of object Poste_Analytique
+     *
+     */
+    function get_list()
+    {
+        $sql="select po_id,
+             po_name ,
+             pa_id,
+             po_amount,
+             po_description,
+             ga_id
+             from poste_analytique ".
+             "   order by po_name";
+
+        $ex=$this->db->exec_sql($sql);
+        $ret=Database::fetch_all($ex);
+        if ( $ret  == null )
+            return null;
+
+        $array=array();
+        foreach ($ret as $line)
+        {
+            $object=new Anc_Account($this->db);
+
+            $object->id=$line['po_id'];
+            $object->name=$line['po_name'];
+            $object->pa_id=$line['pa_id'];
+            $object->amount=$line['po_amount'];
+            $object->description=$line['po_description'];
+            $object->ga_id=$line['ga_id'];
+            $array[]=clone $object;
+        }
+
+        return $array;
+    }
+    function display_list()
+    {
+        $array=$this->get_list();
+        if ( empty($array) )
+        {
+            echo "Vide";
+            return;
+        }
+        foreach ($array as $line)
+        {
+            echo $line->id." / ".$line->name." / ".$line->description."/".
+            $line->amount." / ".$line->pa_id."/".$line->ga_id."<br>";
+        }
+    }
+    function debug()
+    {
+        echo "id ".$this->id."<br>";
+        echo "name ".$this->name."<br>";
+        echo "pa_id ".$this->pa_id."<br>";
+        echo "amount ".$this->amount."<br>";
+        echo "description ".$this->description."<br>";
+        echo "ga_id ".$this->ga_id."<br>";
+    }
+    function form()
+    {
+        $r='';
+        $wName=new IText("po_name",$this->name);
+        $wAmount=new INum("po_amount",$this->amount);
+        $wDescription=new IText("po_description",$this->description);
+        $aGroup_analytic=$this->db->make_array("select ga_id,ga_id from 
groupe_analytique where pa_id=".$this->pa_id,1);
+        if ( count($aGroup_analytic) > 1 )
+        {
+            $wGa_id=new ISelect("ga_id");
+            $wGa_id->value=$aGroup_analytic;
+            $wGa_id->selected=$this->ga_id;
+            $wGa_id->table=1;
+        }
+        else
+        {
+            $wGa_id=new ISpan();
+        }
+        $pa=new Anc_Plan($this->db,$this->pa_id);
+        $pa->get();
+        $wPaName=new IText("",$pa->name);
+        $wPaName->table=1;
+        $wPaName->readOnly=true;
+
+        $wName->table=1;
+        $wAmount->table=1;
+        $wDescription->table=1;
+        $r.=HtmlInput::hidden("pa_id",$this->pa_id);
+        $r.=HtmlInput::hidden("po_id",$this->id);
+
+        $r.="<table>";
+
+        $r.="<tr>";
+        $r.=td(_('Nom'));
+        $r.=$wName->input();
+        $r.="</tr>";
+
+        $r.="<tr>";
+        $r.=td(_('Montant'));
+        $r.=$wAmount->input();
+        $r.="</tr>";
+
+
+        $r.="<tr>";
+        $r.=td(_('Description'));
+        $r.=$wDescription->input();
+        $r.="</tr>";
+
+        $r.="<tr>";
+        $r.=td(_('Plan Analytique'));
+        $r.=$wPaName->input();
+        $r.="</tr>";
+
+        $r.="<tr>";
+        $r.=td(_('Groupe'));
+        $r.=$wGa_id->input();
+        $r.="</tr>";
+
+        $r.="</table>";
+        return $r;
+
+    }
+    function get_from_array($p_array)
+    {
+        $this->name=(isset ($p_array['po_name']))?$p_array['po_name']:"";
+        $this->description=(isset 
($p_array['po_description']))?$p_array['po_description']:"";
+        $this->pa_id=(isset ($p_array['pa_id']))?$p_array['pa_id']:"";
+        $this->amount=(isset ($p_array['po_amount']))?$p_array['po_amount']:0;
+        $this->id=(isset ($p_array['po_id']))?$p_array['po_id']:-1;
+        //    $this->ga_id=(isset($p_array['ga_id']) && $p_array['ga_id'] == 
"-1" )?null:2;
+        $this->ga_id=(isset($p_array['ga_id']) && $p_array['ga_id'] != "-1" 
)?$p_array['ga_id']:null;
+    }
+    static function test_me()
+    {
+        $cn=new Database(dossier::id());
+        $pa_id=$cn->get_value("select max(pa_id) from plan_analytique");
+        $o=new Anc_Account($cn);
+        echo "<h1>Poste_Analytique</h1>";
+        echo "<h2>get_list</h2>";
+        $ee=$o->get_list();
+        print_r($ee);
+        //var_dump($ee);
+
+        echo "<h2>Add some </h2>";
+        $o->pa_id=$pa_id;
+        $o->name="test1";
+        $o->add();
+
+
+        $o->name="test2";
+        $o->add();
+
+        $o->name="test3";
+        $o->add();
+
+        $o->name="test4";
+        $o->add();
+
+        $o->name="test5";
+        $o->add();
+
+        echo "<h2> remove test1</h2>";
+        $o->get_by_name("test1");
+        $o->delete();
+        $o->display_list();
+
+        $o->get_by_name("test4");
+        echo "<hr>".$o->id."<hr>";
+        $o->name="Test Four";
+        $o->update();
+        $o->display_list();
+        $o->delete();
+        $o->display_list();
+    }
+}
+?>
diff --git a/include/class/class_anc_balance_double.php 
b/include/class/class_anc_balance_double.php
new file mode 100644
index 0000000..177a7f8
--- /dev/null
+++ b/include/class/class_anc_balance_double.php
@@ -0,0 +1,579 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief
+ *  Print the crossed balance between 2 plan
+ */
+
+/*! \brief
+ *  Print the crossed balance between 2 plan
+ *
+ */
+require_once NOALYSS_INCLUDE.'/lib/class_iselect.php';
+require_once NOALYSS_INCLUDE.'/lib/class_itext.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ibutton.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ihidden.php';
+require_once  NOALYSS_INCLUDE.'/class/class_anc_print.php';
+require_once  NOALYSS_INCLUDE.'/class/class_anc_plan.php';
+require_once NOALYSS_INCLUDE.'/lib/lib/class_pdf.php';
+
+class Anc_Balance_Double extends Anc_Print
+{
+    /*!
+     * \brief compute the html display
+     *
+     *
+     * \return string
+     */
+
+    function display_html ()
+    {
+        $r="";
+
+        $array=$this->load();
+        $odd=0;
+        if ( is_array($array) == false )
+        {
+            return $array;
+
+        }
+        $old="";
+        $tot_deb=0;
+        $tot_cred=0;
+
+        foreach ( $array as $row)
+        {
+            $odd++;
+
+            $r.=($odd%2==0)?'<tr class="odd">':'<tr class="even">';
+
+            if ( $old == $row['a_po_name'] )
+            {
+                $r.='<td></td>';
+            }
+            else
+            {
+
+                if ( $tot_deb != 0 || $tot_cred !=0 )
+                {
+                 $r.="<tr>".td('');
+                 $r.="<td>Total </td>".td(nbm($tot_deb),' 
class="num"').td(nbm($tot_cred),' class="num"');
+                    $s=abs($tot_deb-$tot_cred);
+                    $d=($tot_deb>$tot_cred)?'debit':'credit';
+                    $r.="<td class=\"num\">".nbm($s)."</td><td>$d</td>";
+                    $r.="</tr>";
+                }
+                $tot_deb=0;
+                $tot_cred=0;
+
+                // new
+                $r.="</table>";
+                $r.="<table class=\"result\" style=\"margin-bottom:3px\">";
+                $r.="<tr>";
+                $r.="<th style=\"width:30%\" >Poste comptable Analytique</th>";
+                $r.="<th style=\"width:30%\">Poste comptable Analytique</th>";
+                $r.="<th style=\"text-align:right\">D&eacute;bit</th>";
+                $r.="<th style=\"text-align:right\">Cr&eacute;dit</th>";
+                $r.="<th style=\"text-align:right\">Solde</th>";
+                $r.="<th>D/C</th>";
+                $r.="</tr>";
+               $r.='<tr>';
+                $r.=td($row['a_po_name'].' '.$row['a_po_description']);
+                $old=$row['a_po_name'];
+               $r.= '</tr>';
+               $r.= '<tr>';
+               $r.=td('');
+            }
+            $tot_deb+=$row['a_d'];
+            $tot_cred+=$row['a_c'];
+
+           $r.=td($row['b_po_name']." ".$row['b_po_description']);
+
+            $r.=td(nbm($row['a_d']),' class="num"');
+            $r.=td(nbm($row['a_c']),' class="num"');
+            $r.=td(nbm($row['a_solde']),' class="num"');
+            $r.=sprintf("<td>%s</td>",$row['a_debit']);
+            $r.="</tr>";
+        } /* end loop */
+
+        if ( $tot_deb != 0 || $tot_cred !=0 )
+        {
+         $r.="<tr>".td('');
+            $r.="<td>Total </td> <td ' class=\"num\"> ".nbm($tot_deb)." </td> 
<td ' class=\"num\">".nbm($tot_cred)."</td>";
+            $s=abs($tot_deb-$tot_cred);
+            $d=($tot_deb>$tot_cred)?'debit':'credit';
+            $r.=td(nbm($s),' class="num"')."<td>$d</td>";
+            $r.="</tr>";
+        }
+
+        $r.="</table>";
+       $r.=h2info('Résumé');
+        $r.='<table class="result">';
+       $r.='<tr>';
+       $r.=th('Po').
+         th('Nom').
+         th('Débit',' style="text-align:right"').
+         th('Crédit','style="text-align:right" ').
+         th('Solde',' style="text-align:right"');
+
+        $sum=$this->show_sum($array);
+       $tot_cred=0;$tot_deb=0;
+        foreach ($sum as $row)
+        {
+            $r.='<tr>';
+            $r.='<td>'.$row['poste'].'</td>';
+            $r.='<td>'.$row['desc'].'</td>';
+            $r.='<td class="num">'.nbm($row['debit']).'</td>';
+            $r.='<td class="num">'.nbm($row['credit']).'</td>';
+           $diff=bcsub($row['debit'],$row['credit']);
+           $tot_cred=bcadd($tot_cred,$row['credit']);
+           $tot_deb=bcadd($tot_deb,$row['debit']);
+
+           $r.=td(nbm($diff),' class="num" ');
+
+            $r.='<td>'.$row['dc'].'</td>';
+            $r.='</tr>';
+        }
+       $r.=td('');
+       $r.=td('total');
+       $r.=td(nbm($tot_deb),'class="num"');
+       $r.=td(nbm($tot_cred),'class="num"');
+       $solde=bcsub($tot_deb,$tot_cred);
+       $sign=($tot_cred<$tot_deb)?" - ":" + ";
+       $r.=td($sign.nbm($solde),'class="num" style="border:solid 1px 
blue;font-weight:bold"');
+       $r.='</tr>';
+        $r.='</table>';
+
+        return $r;
+    }
+    /*!
+     * \brief Display the result in pdf
+     *
+     * \return none
+     */
+    function display_pdf()
+    {
+        $array=$this->load();
+        if (empty($array))return;
+        $pdf=new PDF($this->db);
+        $pdf->Setdossierinfo(dossier::name());
+        $pdf->setTitle("Balance analytique",true);
+        $pdf->SetAuthor('NOALYSS');
+        $pdf->AliasNbPages();
+        $pdf->AddPage();
+
+        $pa=new Anc_Plan($this->db,$this->pa_id);
+        $pa->get();
+        $pb=new Anc_Plan($this->db,$this->pa_id2);
+        $pb->get();
+        $pdf->SetFont('DejaVu','B',9);
+        $pdf->Cell(0,7,sprintf("Balance croise plan %s %s ",
+                               $pa->name,
+                               $pb->name),1,0,'C');
+        $filtre_date="";
+        $filtre_pa="";
+        $filtre_pb="";
+
+        if ( $this->from !="" ||$this->to !="")
+            $filtre_date=sprintf("Filtre date  %s %s",
+                                 $this->from,
+                                 $this->to);
+        if ( $this->from_poste !="" ||$this->to_poste !="")
+            $filtre_pa=sprintf("Filtre poste plan1  %s %s",
+                               ($this->from_poste!="")?"de 
".$this->from_poste:" ",
+                               ($this->to_poste!="")?"jusque 
".$this->to_poste:"");
+
+        if ( $this->from_poste2 !="" ||$this->to_poste2 !="")
+            $filtre_pb=sprintf("Filtre poste plan2   %s  %s",
+                               ($this->from_poste2!="")?"de 
".$this->from_poste2:" ",
+                               ($this->to_poste2!="")?"jusque 
".$this->to_poste2:"");
+
+        $pdf->SetFont('DejaVu','',8);
+        $pdf->Cell(50,7,$filtre_date);
+        $pdf->Cell(50,7,$filtre_pa);
+        $pdf->Cell(50,7,$filtre_pb);
+        $pdf->Ln();
+
+        $pdf->SetFont('DejaVu','',6);
+        $pdf->Cell(20,7,'id','B');
+        $pdf->Cell(100,7,'Poste Comptable','B');
+        $pdf->Cell(20,7,'Débit','B',0,'L');
+        $pdf->Cell(20,7,'Crédit','B',0,'L');
+        $pdf->Cell(20,7,'Solde','B',0,'L');
+        $pdf->Cell(20,7,'D/C','B',0,'L');
+        $pdf->Ln();
+
+        for ($i=0;$i<count($array);$i++)
+        {
+            $row=$array[$i];
+            $pdf->Cell(20,6,$row['a_po_name'],0,0,'L');
+            $pdf->Cell(40,6,mb_substr($row['a_po_description'],0,31),0,0,'L');
+            $pdf->Cell(20,6,$row['b_po_name'],0,0,'L');
+            $pdf->Cell(40,6,mb_substr($row['b_po_description'],0,31),0,0,'L');
+            $pdf->Cell(20,6,$row['a_d'],0,0,'R');
+            $pdf->Cell(20,6,$row['a_c'],0,0,'R');
+            $pdf->Cell(20,6,$row['a_solde'],0,0,'R');
+            $pdf->Cell(20,6,$row['a_debit'],0,0,'C');
+            $pdf->Ln();
+        }
+
+        $sum=$this->show_sum($array);
+        $pdf->SetFont('DejaVu','B',8);
+        $pdf->Cell(70,6,'Somme',1,0,'C');
+        $pdf->Ln(5);
+        $pdf->SetFont('DejaVu','',6);
+
+        $pdf->Cell(20,7,'Poste');
+        $pdf->Cell(60,7,'Description','B');
+        $pdf->Cell(20,7,'Débit','B',0,'L');
+        $pdf->Cell(20,7,'Crédit','B',0,'L');
+        $pdf->Cell(20,7,'Solde','B',0,'L');
+        $pdf->Cell(20,7,'D/C','B',0,'L');
+        $pdf->Ln();
+
+        for ($i=0;$i<count($sum);$i++)
+        {
+            $row=$sum[$i];
+            $pdf->Cell(20,6,$row['poste'],0,0,'L');
+            $pdf->Cell(60,6,$row['desc'],0,0,'L');
+            $pdf->Cell(20,6,sprintf('%.2f',$row['debit']),0,0,'R');
+            $pdf->Cell(20,6,sprintf('%.2f',$row['credit']),0,0,'R');
+            $pdf->Cell(20,6,sprintf('%.2f',$row['solde']),0,0,'R');
+            $pdf->Cell(20,6,$row['dc'],0,0,'R');
+            $pdf->Ln();
+        }
+        $fDate=date('dmy-Hi');
+        $pdf->output('crossbalance-'.$fDate.'.pdf','D');
+    }
+
+
+    /*!
+     * \brief Compute the csv export
+     * \return string with the csv
+     */
+    function display_csv()
+    {
+        $r="";
+
+        $r.='"Poste comptable Analytique";';
+        $r.='"Poste comptable Analytique";';
+        $r.='"Debit";';
+        $r.='"Credit";';
+        $r.='"Solde";';
+        $r.='"D/C"';
+
+        $r.="\r\n";
+
+        $array=$this->load();
+        if ( is_array($array) == false )
+        {
+            return $array;
+
+        }
+        foreach ( $array as $row)
+        {
+
+            $r.=sprintf('"%s";',$row['a_po_name']);
+            $r.=sprintf('"%s";',$row['b_po_name']);
+            $r.=sprintf("%s;",nb($row['a_d']));
+            $r.=sprintf("%s;",nb($row['a_c']));
+            $r.=sprintf("%s;",nb($row['a_solde']));
+            $r.=sprintf('"%s"',$row['a_debit']);
+            $r.="\r\n";
+        }
+
+        return $r;
+
+    }
+    /*!
+     * \brief Compute  the form to display
+     * \param $p_hidden hidden tag to be included (gDossier,...)
+     *
+     *
+     * \return string containing the data
+     */
+    function display_form($p_string='')
+    {
+        $r=parent::display_form($p_string);
+        // show the second plan
+        $r.='<span style="padding:5px;margin:5px;border:2px double  
blue;display:block;">';
+        $plan=new Anc_Plan($this->db);
+        $plan_id=new ISelect("pa_id2");
+        $plan_id->value=$this->db->make_array("select pa_id, pa_name from 
plan_analytique order by pa_name");
+        $plan_id->selected=$this->pa_id2;
+        $r.= "Plan Analytique :".$plan_id->input();
+        $r.=HtmlInput::request_to_hidden(array('ac'));
+        $poste=new IText();
+        $poste->size=10;
+        $r.="Entre le poste ".$poste->input("from_poste2",$this->from_poste2);
+        $choose=new IButton();
+        $choose->name="Choix Poste";
+        $choose->label=_("Recherche");
+        
$choose->javascript="onClick=search_ca(".dossier::id().",'from_poste2','pa_id2')";
+        $r.=$choose->input();
+
+        $r.=" et le poste ".$poste->input("to_poste2",$this->to_poste2);
+        
$choose->javascript="onClick=search_ca(".dossier::id().",'to_poste2','pa_id2')";
+        $r.=$choose->input();
+        $r.='<span class="notice" style="display:block">'.
+            _('Selectionnez le plan qui vous int&eacute;resse avant de cliquer 
sur Recherche').
+            '</span>';
+
+        $r.='</span>';
+        $r.=HtmlInput::submit('Affiche', _('Rechercher'));
+        return $r;
+    }
+    /*!
+     * \brief Show the button to export in PDF or CSV
+     * \param $p_string hidden data to include in the form
+     *
+     *
+     * \return string with the button
+     */
+    function show_button($p_string="")
+    {
+        $r="";
+        $r.= '<form method="GET" action="export.php" style="display:inline">';
+        $r.= $p_string;
+        $r.= HtmlInput::hidden("to",$this->to);
+        $r.= HtmlInput::hidden("act","PDF:AncBalDouble");
+        $r.= HtmlInput::hidden("from",$this->from);
+        $r.= HtmlInput::hidden("pa_id",$this->pa_id);
+        $r.= HtmlInput::hidden("from_poste",$this->from_poste);
+        $r.= HtmlInput::hidden("to_poste",$this->to_poste);
+        $r.= HtmlInput::hidden("pa_id2",$this->pa_id2);
+        $r.= HtmlInput::hidden("from_poste2",$this->from_poste2);
+        $r.= HtmlInput::hidden("to_poste2",$this->to_poste2);
+        $r.=dossier::hidden();
+        $r.=HtmlInput::submit('bt_pdf',"Export en PDF");
+        $r.= '</form>';
+
+        $r.= '<form method="GET" action="export.php"  style="display:inline">';
+        $r.= HtmlInput::hidden("to",$this->to);
+        $r.= HtmlInput::hidden("act","CSV:AncBalDouble");
+        $r.= HtmlInput::hidden("from",$this->from);
+        $r.= HtmlInput::hidden("pa_id",$this->pa_id);
+        $r.= HtmlInput::hidden("from_poste",$this->from_poste);
+        $r.= HtmlInput::hidden("to_poste",$this->to_poste);
+        $r.= HtmlInput::hidden("pa_id2",$this->pa_id2);
+        $r.= HtmlInput::hidden("from_poste2",$this->from_poste2);
+        $r.= HtmlInput::hidden("to_poste2",$this->to_poste2);
+        $r.= $p_string;
+        $r.= dossier::hidden();
+        $r.=HtmlInput::submit('bt_csv',"Export en CSV");
+        $r.= '</form>';
+        return $r;
+
+    }
+    /*!
+     * \brief complete the object with the data in $_REQUEST
+     */
+    function get_request()
+    {
+        parent::get_request();
+        
$this->from_poste2=(isset($_REQUEST['from_poste2']))?$_REQUEST['from_poste2']:"";
+        
$this->to_poste2=(isset($_REQUEST['to_poste2']))?$_REQUEST['to_poste2']:"";
+        $this->pa_id2=(isset($_REQUEST['pa_id2']))?$_REQUEST['pa_id2']:"";
+
+    }
+    /*!
+     * \brief load the data from the database
+     *
+     * \return array
+     */
+    function load()
+    {
+        $filter_poste="";
+        $and="";
+        if ( $this->from_poste != "" )
+        {
+            $filter_poste.=" $and upper(pa.po_name)>= 
upper('".Database::escape_string($this->from_poste)."')";
+            $and=" and ";
+
+        }
+        if ( $this->to_poste != "" )
+        {
+            $filter_poste.=" $and upper(pa.po_name)<= 
upper('".Database::escape_string($this->to_poste)."')";
+            $and=" and ";
+        }
+
+        if ( $this->from_poste2 != "" )
+        {
+            $filter_poste.=" $and upper(pb.po_name)>= 
upper('".Database::escape_string($this->from_poste2)."')";
+            $and=" and ";
+        }
+        if ( $this->to_poste2 != "" )
+        {
+            $filter_poste.=" $and upper(pb.po_name)<= 
upper('".Database::escape_string($this->to_poste2)."')";
+            $and=" and ";
+        }
+        if ( $filter_poste != "")
+            $filter_poste=" where ".$filter_poste;
+
+        $sql="
+             select  a_po_id ,
+             pa.po_name as a_po_name,
+             pa.po_description as a_po_description,
+             pb.po_description as b_po_description,
+
+             b_po_id,
+             pb.po_name as b_po_name,
+             sum(a_oa_amount_c) as a_c,
+             sum(a_oa_amount_d) as a_d
+             from (select
+                       a.j_id,
+             a.po_id as a_po_id,
+             b.po_id as b_po_id,
+             case when a.oa_debit='t' then a.oa_amount else 0 end as 
a_oa_amount_d,
+             case when a.oa_debit='f' then a.oa_amount else 0 end as 
a_oa_amount_c
+             from
+             operation_analytique as a join operation_analytique as b on 
(a.j_id=b.j_id and a.oa_row=b.oa_row)
+               join poste_analytique as poa on (a.po_id=poa.po_id)
+               join poste_analytique as pob on (b.po_id=pob.po_id)
+             where poa.pa_id=".
+             $this->pa_id."
+             and pob.pa_id=".$this->pa_id2."  ".$this->set_sql_filter()."
+             ) as m join poste_analytique as pa on ( a_po_id=pa.po_id)
+             join poste_analytique as pb on (b_po_id=pb.po_id)
+
+             $filter_poste
+
+             group by 
a_po_id,b_po_id,pa.po_name,pa.po_description,pb.po_name,pb.po_description
+             order by 2;
+             ";
+
+
+        $res=$this->db->exec_sql($sql);
+        $this->has_data=Database::num_row($res);
+        if ( Database::num_row($res) == 0 )
+            return null;
+        $a=array();
+        $count=0;
+        $array=Database::fetch_all($res);
+        foreach ($array as $row)
+        {
+            $a[$count]['a_po_id']=$row['a_po_id'];
+            $a[$count]['a_d']=$row['a_d'];
+            $a[$count]['a_c']=$row['a_c'];
+            $a[$count]['b_po_id']=$row['b_po_id'];
+
+            $a[$count]['a_po_name']=$row['a_po_name'];
+            $a[$count]['a_po_description']=$row['a_po_description'];
+            $a[$count]['b_po_name']=$row['b_po_name'];
+            $a[$count]['b_po_description']=$row['b_po_description'];
+            $a[$count]['a_solde']=abs($row['a_d']-$row['a_c']);
+            $a[$count]['a_debit']=($row['a_d']>$row['a_c'])?"debit":"credit";
+
+            $count++;
+        }
+        return $a;
+
+
+    }
+
+
+    /*!
+     * \brief add extra lines  with sum of each account
+     * \param $p_array array returned by load()
+     */
+    function show_sum ($p_array)
+    {
+        $tot_deb=0;
+        $tot_cred=0;
+        $old="";
+        $first=true;
+        $array=array();
+        foreach ( $p_array as $row)
+        {
+
+            if ( $old != $row['a_po_name'] && $first==false )
+
+            {
+                $s=abs($tot_deb-$tot_cred);
+                $d=($tot_deb>$tot_cred)?'debit':'credit';
+                $array[]=array('poste'=>$old,'desc'=>$old_desc
+                                                    
,'debit'=>$tot_deb,'credit'=>$tot_cred,
+                               'solde'=>$s,'dc'=>$d);
+
+                $tot_deb=0;
+                $tot_cred=0;
+
+                $old=$row['a_po_name'];
+                $old_desc=$row['a_po_description'];
+            }
+
+            if ( $first )
+            {
+                $first=false;
+                $old=$row['a_po_name'];
+                $old_desc=$row['a_po_description'];
+            }
+
+            $tot_deb+=$row['a_d'];
+            $tot_cred+=$row['a_c'];
+
+
+        }
+        $s=abs($tot_deb-$tot_cred);
+        $d=($tot_deb>$tot_cred)?'debit':'credit';
+        $array[]=array('poste'=>$old,'desc'=>$old_desc
+                      ,'debit'=>$tot_deb,'credit'=>$tot_cred,
+
+                       'solde'=>$s,'dc'=>$d);
+
+
+        return $array;
+
+    }
+    /*!
+     * \brief for testing and debuggind the class
+     *        it must never be called from production system, it is
+     *        intended only for developpers
+     * \param
+     * \param
+     * \param
+     *
+     *
+     * \return none
+     */
+    static function test_me()
+    {
+        $a=new Database(dossier::id());
+
+        $bal=new Anc_Balance_Double($a);
+        $bal->get_request();
+
+        echo '<form method="GET">';
+
+        echo $bal->display_form();
+        echo '</form>';
+        if ( isset($_GET['result']))
+        {
+            echo $bal->show_button("","");
+            echo "<h1>HTML</h1>";
+            echo $bal->display_html();
+            echo "<h1>CSV</h1>";
+            echo $bal->display_csv();
+
+        }
+    }
+}
diff --git a/include/class/class_anc_balance_simple.php 
b/include/class/class_anc_balance_simple.php
new file mode 100644
index 0000000..246e78b
--- /dev/null
+++ b/include/class/class_anc_balance_simple.php
@@ -0,0 +1,311 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+  \brief manage the simple balance for CA, inherit from balance_ca
+ */
+
+require_once NOALYSS_INCLUDE.'/lib/class_ihidden.php';
+require_once  NOALYSS_INCLUDE.'/class/class_anc_print.php';
+require_once  NOALYSS_INCLUDE.'/class/class_anc_plan.php';
+require_once  NOALYSS_INCLUDE.'/lib/ac_common.php';
+require_once NOALYSS_INCLUDE.'/lib/lib/class_pdf.php';
+require_once  NOALYSS_INCLUDE.'/header_print.php';
+/*! \brief manage the simple balance for CA, inherit from balance_ca
+ *
+ */
+
+class Anc_Balance_Simple extends Anc_Print
+{
+
+    /*!
+     * \brief load the data from the database
+     *
+     * \return array
+     */
+    function load()
+    {
+        $filter=$this->set_sql_filter();
+        // sum debit
+
+        $sql="select m.po_id,sum(deb) as sum_deb,sum(cred) as sum_cred,";
+        $sql.=" po_name||'  '||coalesce(po_description,'') as po_name";
+        $sql.=" from ";
+        $sql.=" (select po_id,case when oa_debit='t' then oa_amount else 0 end 
as deb,";
+        $sql.="case when oa_debit='f' then oa_amount else 0 end as cred ";
+        $sql.=" from operation_analytique join poste_analytique using(po_id)";
+        $sql.=(empty($filter) == false)?" where ".$filter:"";
+        $sql.=" ) as m join poste_analytique using (po_id)";
+        $sql.=" where pa_id=".$this->pa_id;
+        $sql.=" group by po_id,po_name,po_description";
+        $sql.=" order by po_id";
+        $res=$this->db->exec_sql($sql);
+
+        if ( Database::num_row($res) == 0 ) {
+            $this->has_data=0;
+            return null;
+        }
+        $a=array();
+        $count=0;
+        $array=Database::fetch_all($res);
+        foreach ($array as $row)
+        {
+            $a[$count]['po_id']=$row['po_id'];
+            $a[$count]['sum_deb']=$row['sum_deb'];
+            $a[$count]['sum_cred']=$row['sum_cred'];
+            $a[$count]['po_name']=$row['po_name'];
+            $a[$count]['solde']=abs($row['sum_deb']-$row['sum_cred']);
+            
$a[$count]['debit']=($row['sum_deb']>$row['sum_cred'])?"debit":"credit";
+            $count++;
+        }
+        $this->has_data=$count;
+        return $a;
+
+
+    }
+    /*!
+     * \brief Set the filter (account_date)
+     *
+     * \return return the string to add to load
+     */
+
+
+    function set_sql_filter()
+    {
+        $sql="";
+        $and="";
+        if ( $this->from != "" )
+        {
+            $sql.=" oa_date >= to_date('".$this->from."','DD.MM.YYYY')";
+            $and=" and ";
+        }
+        if ( $this->to != "" )
+        {
+            $sql.=" $and oa_date <= to_date('".$this->to."','DD.MM.YYYY')";
+            $and=" and ";
+        }
+        if ( $this->from_poste != "" )
+        {
+            $sql.=" $and upper(po_name)>= upper('".$this->from_poste."')";
+            $and=" and ";
+        }
+        if ( $this->to_poste != "" )
+        {
+            $sql.=" $and upper(po_name)<= upper('".$this->to_poste."')";
+            $and=" and ";
+        }
+        return $sql;
+
+    }
+    /*!
+     * \brief compute the html display
+     *
+     *
+     * \return string
+     */
+    function display_html()
+    {
+        $r="<table class=\"result\">";
+        $r.="<tr>";
+        $r.="<th>Poste comptable Analytique</th>";
+        $r.="<th>D&eacute;bit</th>";
+        $r.="<th>Cr&eacute;dit</th>";
+        $r.="<th>Solde</th>";
+        $r.="<th>D/C</th>";
+        $r.="</tr>";
+
+        $array=$this->load();
+        $odd=0;
+        if ( is_array($array) == false )
+        {
+            return $array;
+
+        }
+        foreach ( $array as $row)
+        {
+            $odd++;
+
+            $r.=($odd%2==0)?'<tr class="odd">':'<tr class="even">';
+            // the name and po_id
+            //   $r.=sprintf("<td>%s</td>",$row['po_id']);
+            $r.=sprintf("<td align=\"left\">%s</td>",h($row['po_name']));
+            $r.=td(nbm($row['sum_deb']),' class="num"');
+            $r.=td(nbm($row['sum_cred']),' class="num"');
+            $r.=td(nbm($row['solde']),' class="num"');
+            $deb=($row['sum_deb'] > $row['sum_cred'])?"D":"C";
+            $deb=($row['solde'] == 0 )?'':$deb;
+            $r.=sprintf("<td>%s</td>",$deb);
+            $r.="</tr>";
+        }
+        $r.="</table>";
+        return $r;
+    }
+    /*!
+     * \brief Compute  the form to display
+     * \param $p_hidden hidden tag to be included (gDossier,...)
+     *
+     *
+     * \return string containing the data
+     */
+    function display_form($p_string="")
+    {
+        $r=parent::display_form($p_string);
+
+        $r.= HtmlInput::submit('Affiche', _('Rechercher'));
+
+        return $r;
+    }
+
+    /*!
+     * \brief Display the result in pdf
+     *
+     * \return none
+     */
+    function display_pdf()
+    {
+        $array=$this->load();
+        $pdf=new PDFBalance_Simple($this->db);
+        
$pdf->set_info($this->from_poste,$this->to_poste,$this->from,$this->to);
+        $pdf->AliasNbPages();
+        $pdf->AddPage();
+        $pdf->setTitle("Balance analytique",true);
+
+        $pdf->SetFont('DejaVu','',6);
+        for ($i=0;$i<count($array);$i++)
+        {
+            $row=$array[$i];
+            $pdf->Cell(20,6,$row['po_id'],0,0,'L');
+            $pdf->Cell(90,6,$row['po_name'],0,0,'L');
+            $pdf->Cell(20,6,sprintf('%s',nbm($row['sum_deb'])),0,0,'R');
+            $pdf->Cell(20,6,sprintf('%s',nbm($row['sum_cred'])),0,0,'R');
+            $pdf->Cell(20,6,sprintf('%s',nbm($row['solde'])),0,0,'R');
+            $pdf->Cell(20,6,$row['debit'],0,0,'R');
+            $pdf->Ln();
+        }
+        $fDate=date('dmy-Hi');
+        $pdf->output('simple-balance-'.$fDate.'.pdf','D');
+
+    }
+    /*!
+     * \brief Compute the csv export
+     * \return string with the csv
+     */
+    function display_csv()
+    {
+        $array=$this->load();
+        if ( is_array($array) == false )
+        {
+            return $array;
+
+        }
+        $r="";
+        foreach ( $array as $row)
+        {
+            // the name and po_id
+            $solde=($row['sum_cred']>$row['sum_deb'])?'C':'D';
+            $solde=($row['sum_cred']==$row['sum_deb'])?'':$solde;
+            $r.=sprintf("'%s';",$row['po_id']);
+            $r.=sprintf("'%s';",$row['po_name']);
+            $r.=sprintf("%s;",nb($row['sum_deb']));
+            $r.=sprintf("%s;",nb($row['sum_cred']));
+            $r.=sprintf("%s;",nb($row['solde']));
+            $r.=sprintf("'%s'",$row['debit']);
+            $r.="\r\n";
+        }
+        return $r;
+
+    }
+    /*!
+     * \brief Show the button to export in PDF or CSV
+     * \param $url_csv url of the csv
+     * \param $url_pdf url of the pdf
+     * \param $p_string hidden data to include in the form
+     *
+     *
+     * \return string with the button
+     */
+    function show_button($p_string="")
+    {
+        $r="";
+        $r.= '<form method="GET" action="export.php" style="display:inline">';
+        $r.= $p_string;
+        $r.= dossier::hidden();
+        $r.= HtmlInput::hidden("to",$this->to);
+        $r.= HtmlInput::hidden("act","PDF:AncBalSimple");
+
+        $r.= HtmlInput::hidden("from",$this->from);
+        $r.= HtmlInput::hidden("pa_id",$this->pa_id);
+        $r.= HtmlInput::hidden("from_poste",$this->from_poste);
+        $r.= HtmlInput::hidden("to_poste",$this->to_poste);
+        $r.=HtmlInput::submit('bt_pdf',"Export en PDF");
+        $r.= '</form>';
+
+        $r.= '<form method="GET" action="export.php"  style="display:inline">';
+        $r.= HtmlInput::hidden("act","CSV:AncBalSimple");
+        $r.= HtmlInput::hidden("to",$this->to);
+        $r.= HtmlInput::hidden("from",$this->from);
+        $r.= HtmlInput::hidden("pa_id",$this->pa_id);
+        $r.= HtmlInput::hidden("from_poste",$this->from_poste);
+        $r.= HtmlInput::hidden("to_poste",$this->to_poste);
+        $r.= $p_string;
+        $r.= dossier::hidden();
+        $r.=HtmlInput::submit('bt_csv',"Export en CSV");
+        $r.= '</form>';
+        return $r;
+    }
+
+    /*!
+     * \brief for testing and debuggind the class
+     *        it must never be called from production system, it is
+     *        intended only for developpers
+     * \param
+     * \param
+     * \param
+     *
+     *
+     * \return none
+     */
+    static  function test_me ()
+    {
+        // call the page with ?gDossier=14
+        $a=new Database(dossier::id());
+
+        $bal=new Anc_Balance_Simple($a);
+        $bal->get_request();
+
+        echo '<form method="GET">';
+
+        echo $bal->display_form();
+        echo '</form>';
+        if ( isset($_GET['result']))
+        {
+            echo $bal->show_button("","");
+            echo "<h1>HTML</h1>";
+            echo $bal->display_html();
+            echo "<h1>CSV</h1>";
+            echo $bal->display_csv();
+            /*         echo "<h1>pdf</h1>"; */
+            /*         echo $bal->display_pdf(); */
+
+        }
+
+    }
+}
diff --git a/include/class/class_anc_grandlivre.php 
b/include/class/class_anc_grandlivre.php
new file mode 100644
index 0000000..3cf02c4
--- /dev/null
+++ b/include/class/class_anc_grandlivre.php
@@ -0,0 +1,309 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief show the Grand Livre for analytic
+ */
+require_once NOALYSS_INCLUDE.'/class/class_anc_print.php';
+require_once NOALYSS_INCLUDE.'/lib/class_impress.php';
+
+class Anc_GrandLivre extends Anc_Print
+{
+    
+    function set_sql_filter()
+    {
+        $sql="";
+        $and=" and ";
+        if ( $this->from != "" )
+        {
+            $sql.="$and oa_date >= to_date('".$this->from."','DD.MM.YYYY')";
+        }
+        if ( $this->to != "" )
+        {
+            $sql.=" $and oa_date <= to_date('".$this->to."','DD.MM.YYYY')";
+        }
+
+        return $sql;
+
+    }
+      /*!
+     * \brief load the data from the database
+     *
+     * \return array
+     */
+    function load()
+    {
+      $filter_date=$this->set_sql_filter();
+      $cond_poste='';
+      if ($this->from_poste != "" )
+            $cond_poste=" and upper(po_name) >= 
upper('".$this->from_poste."')";
+        if ($this->to_poste != "" )
+            $cond_poste.=" and upper(po_name) <= upper('".$this->to_poste."')";
+        $pa_id_cond="";
+        if ( isset ( $this->pa_id) && $this->pa_id !='')
+            $pa_id_cond= "pa_id=".$this->pa_id." and";
+        $array=$this->db->get_array("  select oa_id,
+       po_name,
+       oa_description,
+       po_description,
+       oa_debit,
+       to_char(oa_date,'DD.MM.YYYY') as oa_date,
+       oa_amount,
+       oa_group,
+       j_id ,
+       jr_internal,
+       jr_id,
+       jr_comment,
+       j_poste,
+       jrnx.f_id,
+       ( select ad_value from fiche_Detail where f_id=jrnx.f_id and ad_id=23) 
as qcode,
+        jr_pj_number
+       from operation_analytique as B join poste_analytique using(po_id)
+       left join jrnx using (j_id)
+       left join jrn on  (j_grpt=jr_grpt_id)
+             where $pa_id_cond oa_amount <> 0.0  $cond_poste  $filter_date
+       order by po_name,oa_date::date,qcode,j_poste");
+        $this->has_data=count($array);
+        return $array;
+    }
+
+       function load_csv()
+    {
+      $filter_date=$this->set_sql_filter();
+      $cond_poste='';
+      if ($this->from_poste != "" )
+            $cond_poste=" and upper(po_name) >= 
upper('".$this->from_poste."')";
+        if ($this->to_poste != "" )
+            $cond_poste.=" and upper(po_name) <= upper('".$this->to_poste."')";
+        $pa_id_cond="";
+        if ( isset ( $this->pa_id) && $this->pa_id !='')
+            $pa_id_cond= "pa_id=".$this->pa_id." and";
+        $array=$this->db->get_array("  select
+       po_name,
+       to_char(oa_date,'DD.MM.YYYY') as oa_date,
+       j_poste,
+       ( select ad_value from fiche_Detail where f_id=jrnx.f_id and ad_id=23) 
as qcode,
+       jr_comment,
+        jr_pj_number,
+       jr_internal,
+        oa_row,
+       case when oa_debit='t' then 'D' else 'C' end,
+       oa_amount
+       from operation_analytique as B join poste_analytique using(po_id)
+       left join jrnx using (j_id)
+       left join jrn on  (j_grpt=jr_grpt_id)
+             where $pa_id_cond oa_amount <> 0.0  $cond_poste $filter_date
+       order by po_name,oa_date::date,qcode,j_poste");
+
+
+        return $array;
+    }
+    /* !
+     * \brief Show the button to export in PDF all the receipt
+     * 
+     * \param $p_string extra hidden value
+     * \return string with the button
+     */
+
+    function button_export_pdf($p_string = "")
+    {
+        if (CONVERT_GIF_PDF <> 'NOT' && PDFTK <> 'NOT')
+        {
+            $r = "";
+            $r.= HtmlInput::hidden("to", $this->to);
+            $r.= HtmlInput::hidden("from", $this->from);
+            $r.= HtmlInput::hidden("pa_id", $this->pa_id);
+            $r.= HtmlInput::hidden("from_poste", $this->from_poste);
+            $r.= HtmlInput::hidden("to_poste", $this->to_poste);
+            $r.= HtmlInput::hidden("act","PDF:AncReceipt");
+
+            $r.= $p_string;
+            $r.= dossier::hidden();
+            $r.=HtmlInput::submit('bt_receipt_anal_pdf', _("Export des pièces 
en PDF"));
+        } 
+        else 
+        {
+            
+            $r = "";
+            $msg = _("Les extensions pour convertir en pdf ne sont pas 
installées");
+            $r = HtmlInput::button("bt_receipt_anal", _('Export des pièces en 
PDF'), sprintf('onclick="alert(\'%s\')"',$msg));
+        }
+        return $r;
+    }
+   /*!
+     * \brief compute the html display
+     *
+     *
+     * \return string
+     */
+
+    function display_html()
+   {
+        $r = "";
+        //---Html
+        $array = $this->load();
+        if (is_array($array) == false || empty($array))
+        {
+            return 0;
+        }
+        $r.= '<table class="result" style="width:100%">';
+        $ix = 0;
+        $prev = 'xx';
+        $idx = 0;
+        $tot_deb = $tot_cred = 0;
+
+       bcscale(2);
+        foreach ($array as $row)
+        {
+            if ($prev != $row['po_name'])
+            {
+                if ($ix > 0)
+                {
+                    $r.='<tr>';
+                    $tot_solde = bcsub($tot_cred, $tot_deb);
+                    $sign = " ".($tot_solde > 0) ? 'C' : 'D';
+                   $r.=td('') . td('') . td('');
+                    $r.=td('') . td('') . td('') . td('') . td('') . 
td(nbm($tot_deb), ' class="num"') . td(nbm($tot_cred), ' class="num"') . 
td(nbm($tot_solde) . $sign, ' class="num notice"');
+                }
+                $r.='<tr>' . '<td colspan="7" style="width:auto">' . '<h2>' . 
h($row['po_name'] . ' ' . $row['po_description']) . '</td></tr>';
+                $r.= '<tr>' .
+                        '<th>' . '</th>' .
+                        '<th>' . _('Date') . '</th>' .
+                        '<th>' . _('Poste') . '</th>' .
+                        '<th>' . _('Quick_code') . '</th>' .
+                        '<th>' . _('Libellé') . '</th>' .
+                        '<th>' . '</th>' .
+                        '<th>' . _('Pièce') . '</th>' .
+                        '<th>' . _('Interne') . '</th>' .
+                        '<th style="text-align:right">' . _('Débit') . '</th>' 
.
+                        '<th style="text-align:right">' . _('Crédit') . 
'</th>' .
+                        '<th style="text-align:right">' . _('Prog.') . '</th>' 
.
+                        '</tr>';
+
+                $tot_deb = $tot_cred = 0;
+                $prev = $row['po_name'];
+                $ix++;
+            }
+            $class = ($idx % 2 == 0) ? 'even' : 'odd';
+            $idx++;
+            $r.='<tr class="' . $class . '">';
+            $detail = ($row['jr_id'] != null) ? 
HtmlInput::detail_op($row['jr_id'], $row['jr_internal']) : '';
+            $post_detail = ($row['j_poste'] != null) ? 
HtmlInput::history_account($row['j_poste'], $row['j_poste']) : '';
+            $card_detail = ($row['f_id'] != null) ? 
HtmlInput::history_card($row['f_id'], $row['qcode']) : '';
+            $amount_deb = ($row['oa_debit'] == 't') ? $row['oa_amount'] : 0;
+            $amount_cred = ($row['oa_debit'] == 'f') ? $row['oa_amount'] : 0;
+            $tot_deb = bcadd($tot_deb, $amount_deb);
+            $tot_cred = bcadd($tot_cred, $amount_cred);
+            $tot_solde=bcsub($tot_cred,$tot_deb);
+
+            /*
+             * Checked button
+             */
+            $str_ck = "";
+            $str_document = "";
+            if ($row['jr_id'] != null)
+            {
+                /*
+                 * Get receipt info  
+                 */
+                $str_document = 
HtmlInput::show_receipt_document($row['jr_id']);
+                if ($str_document != "")
+                {
+                    $ck = new ICheckBox('ck[]', $row['jr_id']);
+                    $str_ck = $ck->input();
+                }
+            }
+
+            $r.=
+                    '<td>' . $str_ck . '</td>' .
+                    '<td>' . $row['oa_date'] . '</td>' .
+                    td($post_detail) .
+                    td($card_detail) .
+                    td($row['jr_comment']) .
+                    '<td>' . $str_document . '</td>' .
+                    td($row['jr_pj_number']) .
+                    '<td>' . $detail . '</td>' .
+                    '<td class="num">' . nbm($amount_deb) . '</td>' .
+                    '<td class="num">' . nbm($amount_cred). '</td>'.
+                    '<td class="num">' . nbm($tot_solde). '</td>';
+            $r.= '</tr>';
+        }
+        $r.='<tr>';
+        $tot_solde = bcsub($tot_cred, $tot_deb);
+        $sign = ($tot_solde > 0) ? 'C' : 'D';
+       $r.=td('') . td('') . td('');
+        $r.=td('') . td('') . td('') . td('') . td('') . td(nbm($tot_deb), ' 
class="num"') . td(nbm($tot_cred), ' class="num"') . td(nbm($tot_solde) . 
$sign, '  class="num notice"');
+
+        $r.= '</table>';
+        return $r;
+    }
+      /*!
+     * \brief Show the button to export in PDF or CSV
+     * \param $url_csv url of the csv
+     * \param $url_pdf url of the pdf
+     * \param $p_string hidden data to include in the form
+     *
+     *
+     * \return string with the button
+     */
+    function show_button($p_string="")
+    {
+        $r="";
+        $r.= '<form method="GET" action="export.php"  style="display:inline">';
+        $r.= HtmlInput::hidden("act","CSV:AncGrandLivre");
+        $r.= HtmlInput::hidden("to",$this->to);
+        $r.= HtmlInput::hidden("from",$this->from);
+        $r.= HtmlInput::hidden("pa_id",$this->pa_id);
+        $r.= HtmlInput::hidden("from_poste",$this->from_poste);
+        $r.= HtmlInput::hidden("to_poste",$this->to_poste);
+        $r.= $p_string;
+        $r.= dossier::hidden();
+        $r.=HtmlInput::submit('bt_csv',"Export en CSV");
+        $r.= '</form>';
+        return $r;
+    }
+    function display_csv()
+    {
+        $r="";
+        //---Html
+        $array=$this->load_csv();
+        if ( is_array($array) == false )
+        {
+            return $array;
+
+        }
+
+        $ix=0;$prev='xx';
+       $tot_deb=$tot_cred=0;
+        $aheader=array();
+        $aheader[]=array("title"=>'Imp. Analytique','type'=>'string');
+        $aheader[]=array("title"=>'Date','type'=>'string');
+        $aheader[]=array("title"=>'Poste','type'=>'string');
+        $aheader[]=array("title"=>'Quick_Code','type'=>'string');
+        $aheader[]=array("title"=>'libelle','type'=>'string');
+        $aheader[]=array("title"=>'Pièce','type'=>'string');
+        $aheader[]=array("title"=>'Num.interne','type'=>'string');
+        $aheader[]=array("title"=>'row','type'=>'num');
+        $aheader[]=array("title"=>'Debit','type'=>'string');
+        $aheader[]=array("title"=>'Credit','type'=>'num');
+        Impress::array_to_csv($array, $aheader);
+    }
+}
diff --git a/include/class/class_anc_group.php 
b/include/class/class_anc_group.php
new file mode 100644
index 0000000..f31b8e4
--- /dev/null
+++ b/include/class/class_anc_group.php
@@ -0,0 +1,260 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief class for the group of the analytic account
+ *
+ */
+require_once  NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once  NOALYSS_INCLUDE.'/constant.php';
+require_once  NOALYSS_INCLUDE.'/class/class_dossier.php';
+require_once NOALYSS_INCLUDE.'/class/class_anc_print.php';
+
+/*! \brief class for the group of the analytic account
+ *
+ */
+class Anc_Group extends Anc_Print
+{
+    var $db;
+    var $ga_id;
+    var $ga_description;
+    var $pa_id;
+
+    function __construct ( $p_cn )
+    {
+        $this->db=$p_cn;
+        $this->ga_id=null;
+        $this->ga_description=null;
+        $this->pa_id=null;
+    }
+    /*!
+     * \brief insert into the database  an object
+     * \return message with error otherwise an empty string
+     */
+
+    function insert()
+    {
+        if (strlen ($this->ga_id) > 10 )            return '<span 
class="notice">'.
+                _('Taille de la code trop long maximum 10 
caractères').'</span>';
+        $sql=" insert into groupe_analytique (ga_id,ga_description,pa_id) 
values ('%s','%s',%d)";
+        $sql=sprintf($sql,Database::escape_string($this->ga_id),
+                     Database::escape_string($this->ga_description),
+                     $this->pa_id);
+        try
+        {
+            $this->db->exec_sql($sql);
+        }
+        catch (Exception $a)
+        {
+            return '<span class="notice">Doublon !!</span>';
+        }
+        return "";
+    }
+    /*!
+     * \brief remove from the database
+     */
+
+    function remove()
+    {
+        $this->ga_id=str_replace(' ','',$this->ga_id);
+        $this->ga_id=strtoupper($this->ga_id);
+        $sql=" delete from groupe_analytique where 
ga_id='".Database::escape_string($this->ga_id)."'";
+
+        $this->db->exec_sql($sql);
+    }
+
+    /*!
+     * \brief load from the database and make an object
+     */
+    function load()
+    {
+        $sql="select ga_id, ga_description,pa_id from groupe_analytique where".
+             " ga_id = ".$this->ga_id;
+        $res=$this->db->exec_sql($sql);
+        $array=Database::fetch_all($res);
+        if ( ! empty($array) )
+        {
+            $this->ga_id=$array['ga_id'];
+            $this->ga_description=$array['ga_description'];
+            $this->pa_id=$array['pa_id'];
+        }
+    }
+
+    /*!
+     * \brief fill the object thanks an array
+     * \param array
+     */
+    function get_from_array($p_array)
+    {
+        $this->ga_id=$p_array['ga_id'];
+        $this->pa_id=$p_array['pa_id'];
+        $this->ga_description=$p_array['ga_description'];
+    }
+    function myList()
+    {
+        $sql=" select ga_id,groupe_analytique.pa_id,pa_name,ga_description ".
+             " from groupe_analytique ".
+             " join plan_analytique using (pa_id)";
+        $r=$this->db->exec_sql($sql);
+        $array=Database::fetch_all($r);
+        $res=array();
+        if ( ! empty($array))
+        {
+            foreach ($array as $m )
+            {
+                $obj= new Anc_Group($this->db);
+                $obj->get_from_array($m);
+                $obj->pa_name=$m['pa_name'];
+                $res[]=clone $obj;
+            }
+        }
+        return $res;
+    }
+
+    function set_sql_filter()
+    {
+        $sql="";
+        $and="and ";
+        if ( $this->from != "" )
+        {
+            $sql.=" $and  oa_date >= to_date('".$this->from."','DD.MM.YYYY')";
+            $and=" and ";
+        }
+        if ( $this->to != "" )
+        {
+            $sql.=" $and oa_date <= to_date('".$this->to."','DD.MM.YYYY')";
+            $and=" and ";
+        }
+        if ( $this->from_poste != "" )
+        {
+            $sql.=" $and upper(po_name)>= upper('".$this->from_poste."')";
+            $and=" and ";
+        }
+        if ( $this->to_poste != "" )
+        {
+            $sql.=" $and upper(po_name)<= upper('".$this->to_poste."')";
+            $and=" and ";
+        }
+        return $sql;
+
+    }
+
+    function get_result()
+    {
+      $filter_date=$this->set_sql_filter();
+
+      $sql="with m as (select po_id,
+       po_name,
+       ga_id,
+       case when  oa_debit = 't' then oa_amount
+       else 0
+       end  as amount_deb,
+       case when oa_debit = 'f' then oa_amount
+       else 0
+       end as amount_cred,
+       oa_date
+       from operation_analytique
+join poste_analytique using (po_id)
+where pa_id=$1 $filter_date )
+select sum(amount_cred) as sum_cred, sum(amount_deb)as 
sum_deb,po_name,ga_id,ga_description
+from m left join groupe_analytique using (ga_id)
+group by ga_id,po_name,ga_description
+order by ga_description,po_name";
+      $ret=$this->db->get_array($sql,array($this->pa_id));
+
+      return $ret;
+    }
+
+    function display_html()
+    {
+      if ( $this->check()  != 0)
+       {
+         alert('Désolé mais une des dates données n\'est pas valide');
+         return;
+       }
+
+      $array=$this->get_result();
+      if ( empty ($array) ) return "";
+      require_once NOALYSS_INCLUDE.'/template/anc_balance_group.php';
+
+
+    }
+  /**
+   address@hidden display the button export CSV
+   address@hidden $p_hidden is a string containing hidden items
+   address@hidden html string
+   */
+  function show_button($p_hidden="")
+  {
+    $r="";
+    $r.= '<form method="GET" action="export.php"  style="display:inline">';
+    $r.= HtmlInput::hidden("act","CSV:AncBalGroup");
+    $r.= HtmlInput::hidden("to",$this->to);
+    $r.= HtmlInput::hidden("from",$this->from);
+    $r.= HtmlInput::hidden("pa_id",$this->pa_id);
+    $r.= HtmlInput::hidden("from_poste",$this->from_poste);
+    $r.= HtmlInput::hidden("to_poste",$this->to_poste);
+    $r.= $p_hidden;
+    $r.= dossier::hidden();
+    $r.=HtmlInput::submit('bt_csv',"Export en CSV");
+    $r.= '</form>';
+    return $r;
+  }
+  function export_csv()
+  {
+    $array=$this->get_result();
+    printf('"groupe";"activité";"débit";"credit";"solde"');
+    printf("\r\n");
+    bcscale(2);
+    for ($i=0;$i<count($array);$i++)
+      {
+       printf('"%s";"%s";%s;%s;%s',
+              $array[$i]['ga_id'],
+              $array[$i]['po_name'],
+              nb($array[$i]['sum_deb']),
+              nb($array[$i]['sum_cred']),
+              nb(bcsub($array[$i]['sum_cred'],$array[$i]['sum_deb']))
+              );
+       printf("\r\n");
+      }
+  }
+    static function test_me()
+    {
+
+        $cn=new Database(dossier::id());
+        print_r($cn);
+        $o=new Anc_Group($cn);
+        $r=$o->myList();
+        print_r($r);
+        echo '<hr>';
+        print_r($o);
+        $o->ga_id="DD' dd dDD";
+        $o->ga_description="Test 1";
+        $o->remove();
+        //    $o->insert();
+        $o->ga_id="DD";
+        $o->ga_description="Test 1";
+        $o->remove();
+
+        $r=$o->myList();
+        print_r($r);
+    }
+}
diff --git a/include/class/class_anc_group_operation.php 
b/include/class/class_anc_group_operation.php
new file mode 100644
index 0000000..08f9a7c
--- /dev/null
+++ b/include/class/class_anc_group_operation.php
@@ -0,0 +1,278 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ *  \brief group of object operations, used for misc operation
+ */
+
+/*! \brief group of object operations, used for misc operation
+ *
+ */
+require_once NOALYSS_INCLUDE.'/lib/class_idate.php';
+require_once NOALYSS_INCLUDE.'/lib/class_itext.php';
+require_once NOALYSS_INCLUDE.'/lib/class_iselect.php';
+require_once NOALYSS_INCLUDE.'/lib/class_icheckbox.php';
+require_once  NOALYSS_INCLUDE.'/class/class_anc_operation.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once  NOALYSS_INCLUDE.'/class/class_anc_plan.php';
+require_once  NOALYSS_INCLUDE.'/class/class_dossier.php';
+
+class Anc_Group_Operation
+{
+    var $db;   /*!< database connection */
+    var  $id;  /*!< oa_group, a group contains
+                          several rows of
+                          operation_analytique linked by the
+                          group id */
+
+    var $a_operation;                                          /*!< array of 
operations */
+    var $date;                                                 /*!< date of 
the operations */
+    var $pa_id;                                                        /*!< 
the concerned pa_id */
+
+    /*!\brief constructor */
+    function  Anc_Group_Operation($p_cn,$p_id=0)
+    {
+        $this->db=$p_cn;
+        $this->id=$p_id;
+        $this->date=date("d.m.Y");
+        $this->nMaxRow=10;
+    }
+    /*!\brief add several rows */
+    function add()
+    {
+
+        $amount=0;
+        try
+        {
+            $this->db->start();
+            foreach ($this->a_operation as $row)
+            {
+                $add=round($row->oa_amount,2);
+                $add=($row->oa_debit=='t')?$add:$add*(-1);
+                $amount+=round($add,2);
+                $row->add();
+            }
+            if ( $amount != 0 ) throw new Exception (_('Operation non 
equilibrée'));
+        }
+        catch (Exception $e)
+        {
+            echo $e->getTrace();
+            $this->db->rollback();
+            throw new Exception($e);
+        }
+        $this->db->commit();
+    }
+    /*!\brief show a form for the operation (several rows)
+     * \return the string containing the form but without the form tag
+     *
+     */
+    function form($p_readonly=0)
+    {
+        $wDate=new IDate("pdate",$this->date);
+        $wDate->table=1;
+        $wDate->size=10;
+        $wDate->readonly=$p_readonly;
+
+        $wDescription=new IText("pdesc");
+        $wDescription->table=0;
+        $wDescription->size=80;
+        $wDescription->readonly=$p_readonly;
+        // Show an existing operation
+        //
+        if ( isset ($this->a_operation[0]))
+        {
+            $wDate->value=$this->a_operation[0]->oa_date;
+            $wDescription->value=$this->a_operation[0]->oa_description;
+        }
+
+        $ret="";
+
+        $ret.='<table style="result"   >';
+
+        $ret.="<TR>".$wDate->input()."</tr>";
+        $ret.='<tr><td>Description</td>'.
+              '<td colspan="3">'.
+              $wDescription->input()."</td></tr>";
+        $Plan=new Anc_Plan($this->db);
+        $aPlan=$Plan->get_list();
+        
$max=(count($this->a_operation)<$this->nMaxRow)?$this->nMaxRow:count($this->a_operation);
+        $ret.='</table><table  id="ago" style="width: 100%;">';
+        /* show 10 rows */
+        $ret.="<tr>";
+        foreach ($aPlan as $d)
+        {
+            $idx=$d['id'];
+            /* array of possible value for the select */
+            $aPoste[$idx]=$this->db->make_array("select po_id as value,".
+                                                " 
po_name||':'||coalesce(po_description,'-') as label ".
+                                                " from poste_analytique ".
+                                                " where pa_id = ".$idx.
+                                                " order by po_name ");
+
+            $ret.="<th> Poste </th>";
+        }
+        $ret.="<th></th>".
+              "<th> Montant</th>".
+              "<th>D&eacute;bit</th>".
+              "</tr>";
+
+        for ($i = 0;$i < $max;$i++)
+        {
+            $ret.="<tr>";
+
+            foreach ($aPlan as $d)
+            {
+                $idx=$d['id'];
+                // init variable
+                $wSelect=new ISelect("pop".$i."plan".$idx);
+                $wSelect->value=$aPoste[$idx];
+                $wSelect->size=12;
+
+                $wSelect->readOnly=$p_readonly;
+                if ( isset($this->a_operation[$i]))
+                {
+                    $wSelect->selected=$this->a_operation[$i]->po_id;
+                }
+                $ret.=td($wSelect->input());
+            }
+            $wAmount=new INum("pamount$i",0.0);
+            $wAmount->size=12;
+            $wAmount->table=1;
+            $wAmount->javascript=" 
onChange=format_number(this);caod_checkTotal()";
+            $wAmount->readOnly=$p_readonly;
+
+            $wDebit=new ICheckBox("pdeb$i");
+            $wDebit->readOnly=$p_readonly;
+            $wDebit->javascript=" onChange=caod_checkTotal()";
+            if ( isset ($this->a_operation[$i]))
+            {
+                $wSelect->selected=$this->a_operation[$i]->po_id;
+                $wAmount->value=$this->a_operation[$i]->oa_amount;
+                $wDebit->value=$this->a_operation[$i]->oa_debit;
+                if ( $wDebit->value=='t')
+                {
+                    $wDebit->selected=true;
+                }
+
+            }
+
+            // build the table
+
+            $ret.="<TD></TD>";
+            $ret.=$wAmount->input();
+            $ret.=td($wDebit->input());
+
+            $ret.="</tr>";
+        }
+        $ret.="</table>";
+        if ( $p_readonly==false)
+        {
+            $add_row=new IButton('Ajouter');
+            $add_row->label=_('Ajouter une ligne');
+            $add_row->javascript='anc_add_row(\'ago\');';
+            $ret.=HtmlInput::hidden('nbrow',$max);
+
+            $ret.=$add_row->input();
+        }
+        return $ret;
+    }
+    /*!\brief fill row from $_POST data
+     *
+     */
+    function get_from_array($p_array)
+    {
+        $Plan=new Anc_Plan($this->db);
+        $aPlan=$Plan->get_list();
+
+
+        for ( $i = 0;$i <$p_array['nbrow'];$i++)
+        {
+            foreach ($aPlan as $d)
+            {
+                $idx=$d['id'];
+                $p=new Anc_Operation($this->db);
+                $p->oa_amount=$p_array["pamount$i"];
+
+                $p->oa_description=$p_array["pdesc"];
+                $p->oa_date=$p_array['pdate'];
+                $p->j_id=0;
+                $p->oa_debit=(isset ($p_array["pdeb$i"]))?'t':'f';
+                $p->oa_group=0;
+
+                $p->po_id=$p_array["pop$i"."plan".$idx];
+                $p->pa_id=$idx;
+                $this->a_operation[]=clone $p;
+            }
+        }
+    }
+    /*!\brief save the group of operation but only if the amount is
+       balanced  */
+    function save()
+    {
+        $this->db->start();
+        try
+        {
+            $oa_group=$this->db->get_next_seq('s_oa_group');
+            for ($i=0;$i<count($this->a_operation);$i++)
+            {
+                $this->a_operation[$i]->oa_group=$oa_group;
+                $this->a_operation[$i]->add();
+            }
+        }
+        catch (Exception $ex)
+        {
+            echo '<span class="error">'.
+            'Erreur dans l\'enregistrement '.
+            __FILE__.':'.__LINE__.' '.
+            $ex->getMessage();
+            $p_cn->rollback();
+            throw new Exception("Erreur ".$ex->getMessage());
+
+        }
+        $this->db->commit();
+    }
+    /*!\brief show the form */
+    function show()
+    {
+        return $this->form(1);
+    }
+    static function test_me()
+    {
+        $dossier=dossier::id();
+        $cn=new Database($dossier);
+
+        if ( isset($_POST['go']))
+        {
+            $b=new Anc_Group_Operation($cn);
+            $b->get_from_array($_POST);
+            return;
+        }
+
+        $a=new Anc_Group_Operation($cn);
+        echo '<form method="post">';
+        echo $a->form();
+        echo dossier::hidden();
+        echo '<input type="submit" name="go">';
+        echo '</form>';
+
+    }
+
+}
diff --git a/include/class/class_anc_key.php b/include/class/class_anc_key.php
new file mode 100644
index 0000000..d79bfbe
--- /dev/null
+++ b/include/class/class_anc_key.php
@@ -0,0 +1,354 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+// Copyright (2014) Author Dany De Bontridder address@hidden
+
+/**
+ * @file
+ * @brief Class to manage distribution keys for Analytic accountancy
+ * 
+ */
+require_once NOALYSS_INCLUDE.'/database/class_anc_key_sql.php';
+
+class Anc_Key
+{
+
+    private $key; /* !  the distribution key */
+    /**
+     * Return the number of keys available.
+     *  Return the number of keys available for the ledger given in parameter
+     * 
+     * @global $cn database connection
+     * @param $p_jrn number of the ledger (jrn_def.jrn_def_id
+     * @return number of available keys
+     */
+    static function key_avaiable($p_jrn)
+    {
+        global $cn;
+        $count=$cn->get_value (' select count(*) 
+            from key_distribution_ledger 
+            join key_distribution using (kd_id)
+            where
+            jrn_def_id=$1', array($p_jrn));
+        return $count;
+    }
+    function __construct($p_id=-1)
+    {
+        global $cn;
+        $this->key=new Anc_Key_SQL($cn, $p_id);
+        $this->a_ledger=null;
+        $this->a_activity=null;
+        $this->a_row=null;
+    }
+
+    /**
+     * @brief display list of available keys
+     * @param $p_amount   amount to distribute
+     * @param $p_target   target to update
+     * @param $p_ledger   is the jrn_def_id
+     */
+    static function display_choice($p_amount, $p_target,$p_ledger)
+    {
+        global $cn;
+        $a_key=$cn->get_array(' select kd_id,
+                kd_name,
+                kd_description
+                from
+                key_distribution
+                join key_distribution_ledger using (kd_id)
+                where
+                jrn_def_id=$1',
+                array(
+                    $p_ledger
+                ));
+        if (empty($a_key))
+        {
+            echo _('Aucune clef disponible');
+            echo _('Allez dans ANCKEY pour en ajouter pour ce journal');
+        }
+        include 'template/anc_key_display_choice.php';
+    }
+
+    /**
+     * @brief display a  list of keys, choose one to modify it
+     * 
+     */
+    static function display_list()
+    {
+        global $cn;
+        $a_key=$cn->get_array('select b.kd_id,b.kd_name,b.kd_description,
+                (select sum(ke_percent) from key_distribution_detail as a 
where a.kd_id=b.kd_id) as distrib 
+                from key_distribution as b order by b.kd_name');
+        if (empty($a_key))
+        {
+            echo _('Aucune clef disponible');
+        }
+        include 'template/anc_key_display_list.php';
+    }
+
+    /**
+     * @brief Show the detail for a key distribution and let you change it
+     * for adding or update
+     */
+    function input()
+    {
+        global $cn;
+
+        $plan=$cn->get_array('
+     select 
+     pa_id,
+     pa_name , 
+     pa_description 
+     from 
+       plan_analytique 
+     order by pa_name');
+        $count_max=count($plan);
+
+        $a_row=$cn->get_array('select ke_id,ke_row,ke_percent from 
key_distribution_detail 
+         where
+         kd_id=$1 order by ke_row', array($this->key->getp('id')));
+
+        require_once NOALYSS_INCLUDE.'/template/anc_key_input.php';
+    }
+
+    /**
+     * @brief verify that data are ok
+     * @param type $p_array
+     */
+    function verify($p_array)
+    {
+        $a_percent=$p_array['percent'];
+        if (count($a_percent)==0)
+        {
+            throw new Exception(_('Aucune répartition'));
+        }
+        $tot_percent=0;
+        bcscale(4);
+        for ($i=0; $i<count($a_percent); $i++)
+        {
+            $tot_percent=bcadd($tot_percent, $a_percent[$i]);
+        }
+        if ($tot_percent >100)
+        {
+            throw new Exception(_('Le total ne vaut pas 100, total calculé = 
').$tot_percent);
+        }
+        if ($p_array['name_key']=='') {
+            throw new Exception (_('Le nom ne peut être vide'));
+        }
+    }
+
+    /**
+     * @brief save the data of a repartition key.
+     * @param received an array
+     * index :
+     *   - key_id : key_distribution.kd_id
+     *   - row : array of key_distribution.ke_id (row
+     *   - pa : array of plan_analytic.pa_id (column)
+     *   - po_id : double array, 
+     *              first index is the row
+     *              second  index is the first plan, the second the second 
plan...(column)
+     *   - percent array, one per row
+     *   - jrn : array of available ledgers
+     * @note  if po_id == -1 then it is replaced by null, this why the pa_id 
is needed : to identify
+     *  the column
+     * @verbatim
+     
+        'key_id' => string '1' (length=1)
+        'row' => 
+          array
+            0 => string '1' (length=1)
+            1 => string '2' (length=1)
+            2 => string '3' (length=1)
+        'pa' => 
+          array
+            0 => string '1' (length=1)
+            1 => string '2' (length=1)
+        'po_id' => 
+          array
+            0 => 
+              array
+                0 => string '1' (length=1)
+                1 => string '8' (length=1)
+            1 => 
+              array
+                0 => string '2' (length=1)
+                1 => string '-1' (length=2)
+            2 => 
+              array
+                0 => string '3' (length=1)
+                1 => string '8' (length=1)
+        'percent' => 
+          array
+            0 => string '50.0000' (length=7)
+            1 => string '20.0000' (length=7)
+            2 => string '30.0000' (length=7)
+        'jrn' => 
+          array
+            0 => string '3' (length=1)
+            1 => string '2' (length=1)
+      @endverbatim
+     * 
+     */
+    function save($p_array)
+    {
+        global $cn;
+        $this->verify($p_array);
+        $cn->start();
+        // for each row
+        $a_row=$p_array['row'];
+        $a_ledger=HtmlInput::default_value("jrn",array(),$p_array);
+        $a_percent=$p_array['percent'];
+        $a_po_id=$p_array['po_id'];
+        $a_plan=$p_array['pa'];
+        try
+        {
+            $this->key->setp('name',$p_array['name_key']);
+            $this->key->setp('description',$p_array['description_key']);
+            $this->key->save();
+            for ($i=0; $i<count($a_row); $i++)
+            {
+                //save key_distribution_row
+                $key_row=new Anc_Key_Detail_SQL($cn);
+                $key_row->setp('id', $a_row[$i]);
+                $key_row->setp('key', $this->key->getp('id'));
+                $key_row->setp('row', $i+1);
+                $key_row->setp('percent', $a_percent[$i]);
+                $key_row->save();
+                //
+                // Save each activity + percent
+                $cn->exec_sql('delete from key_distribution_activity where 
ke_id=$1', array($key_row->getp('id')));
+
+                // Don't save row with 0 %
+                if ($a_percent[$i]==0)
+                {
+                    $key_row->delete();
+                    continue;
+                }
+                for ($j=0; $j<count($a_po_id[$i]); $j++)
+                {
+                    $activity=new Anc_Key_Activity_SQL($cn);
+                    $activity->setp('detail', $key_row->ke_id);
+                    $value=($a_po_id[$i][$j]==-1)?null:$a_po_id[$i][$j];
+                    $activity->setp('activity', $value);
+                    $activity->setp('plan',$a_plan[$j]);
+                    $activity->save();
+                }
+            }
+            // delete all from key_distribution_ledger
+            $cn->exec_sql('delete from key_distribution_ledger where 
kd_id=$1', array($this->key->getp('id')));
+            for ($k=0; $k<count($a_ledger); $k++)
+            {
+                $ledger=new Anc_Key_Ledger_SQL($cn);
+                $ledger->kd_id=$this->key->getp('id');
+                $ledger->jrn_def_id=$a_ledger[$k];
+                $ledger->save();
+            }
+            
+            $cn->commit();
+        }
+        catch (Exception $e)
+        {
+            if ( DEBUG ) { echo $e->getTraceAsString(); var_dump($_POST);} 
else { echo _('erreur');}
+            $cn->rollback();
+        }
+    }
+    /**
+     * @brief Call the Anc_Operation::display_form_plan with the right amounts.
+     * This function compute the array and amount to pass to the 
Anc_Operation::display_form_plan
+     * and replace the current table of activity with the value computed from 
the key.
+     * 
+     * @global $cn database connection
+     * @param $p_target Table to be replaced
+     * @param $p_amount amount to distribute among activities
+     */
+    function fill_table($p_target,$p_amount)
+    {
+        global $cn;
+        /* number is the index of the plan, he's computed from p_target */
+        $number=preg_replace('/det[0-9]/', '', $p_target);
+        $number=str_replace('t', '', $number);
+        $number=str_replace('popup', '', $number);
+        
+        $op[$number]=$p_amount;
+        $array['op']=$op;
+        $a_plan=$cn->get_array('select pa_id from plan_analytique order by 
pa_id');
+        for ($i=0;$i < count($a_plan);$i++)
+        {
+            $array['pa_id'][$i]=$a_plan[$i]['pa_id'];
+        }
+        
+        $a_poste=$cn->get_array('select po_id,ke_percent,pa_id,ke_row
+                 from key_distribution_activity 
+                 join key_distribution_detail using (ke_id)  
+                 where
+                 kd_id=$1
+                 order by ke_row,pa_id',
+                 array($this->key->getp('id')));
+
+        for ($i=0;$i< count($a_poste);$i++)
+        {
+            
$hplan[$number][$i]=($a_poste[$i]['po_id']==null)?-1:$a_poste[$i]['po_id'];
+        }
+        $array['hplan']=$hplan;
+        
+         $a_amount=$cn->get_array("select distinct ke_row,ke_percent 
+                 from key_distribution_activity 
+                 join key_distribution_detail using (ke_id) 
+                 where
+                    kd_id=$1
+                    and pa_id=$2
+                 order by ke_row",
+                 array($this->key->getp('id'),$a_plan[0]['pa_id']));
+         bcscale(2);
+        for ($i=0;$i< count($a_amount);$i++)
+        {
+            $val[$number][$i]=bcmul($p_amount,$a_amount[$i]['ke_percent'])/100;
+        }
+        $array['val']=$val;
+               
+        $anc_operation=new Anc_Operation($cn);
+        echo $anc_operation->display_form_plan($array, 1, 1, $number, 
$p_amount,'',false);
+        
+    }
+    /**
+     address@hidden show a form for adding a key + button to display it
+     * 
+     */
+    static function key_add()
+    {
+        $key=new Anc_Key();
+        $key->key->setp('name',_('Nouvelle clef'));
+        $key->key->setp('description',_('Description de la nouvelle clef'));
+        ?>
+<input type="button" class="smallbutton" value="<?php echo  _('Ajout')?>" 
onclick="$('key_add_div_id').show()">
+<div id="key_add_div_id" style="display: none">
+<?php
+        $key->input();
+        echo '</div>';
+        
+    }
+    /**
+     address@hidden delete the distribution key 
+     */
+    function delete ()
+    {
+        $this->key->delete();
+    }
+}
diff --git a/include/class/class_anc_listing.php 
b/include/class/class_anc_listing.php
new file mode 100644
index 0000000..9804ad9
--- /dev/null
+++ b/include/class/class_anc_listing.php
@@ -0,0 +1,216 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief definition of Anc_Listing
+ */
+
+require_once NOALYSS_INCLUDE.'/lib/class_ihidden.php';
+require_once  NOALYSS_INCLUDE.'/class/class_anc_plan.php';
+require_once  NOALYSS_INCLUDE.'/class/class_anc_print.php';
+require_once  NOALYSS_INCLUDE.'/class/class_anc_operation.php';
+/*!
+ * \brief manage the CA listing
+ *
+ * \return
+ */
+
+class Anc_Listing extends Anc_Print
+{
+    function display_form($p_string="")
+    {
+        echo '<form method="get">';
+        $r=parent::display_form($p_string);
+        $r.=HtmlInput::submit('result', _('Rechercher'));
+        $r.= '</form>';
+        return $r;
+
+    }
+    /*!
+     * \brief complete the object with the data in $_REQUEST
+     */
+
+    function get_request()
+    {
+        parent::get_request();
+        $this->pa_id=(isset($_REQUEST['pa_id']))?$_REQUEST['pa_id']:"";
+    }
+    /*!
+     * \brief compute the html display
+     *
+     *
+     * \return string
+     */
+
+    function display_html()
+    {
+        $idx=0;
+        $r="";
+        //---Html
+        $array=$this->load();
+        if ( is_array($array) == false ||  empty($array) )
+        {
+            return 0;
+        }
+        $r.= '<table class="result" style="width=100%">';
+        $r.= '<tr>'.
+             '<th>'._('Date').'</th>'.
+             '<th>'._('Poste').'</th>'.
+             '<th>'._('Quick_code').'</th>'.
+             '<th>'._('Analytique').'</th>'.
+         th(_('Description')).
+             '<th>'._('libelle').'</th>'.
+             '<th>'._('Num.interne').'</th>'.
+             '<th>'._('Montant').'</th>'.
+             '<th>'._('D/C').'</th>'.
+             '</tr>';
+        foreach ( $array as $row )
+        {
+            $class=($idx%2==0)?'even':'odd';
+            $idx++;
+            $r.= '<tr class="'.$class.'">';
+           $detail=($row['jr_id'] != 
null)?HtmlInput::detail_op($row['jr_id'],$row['jr_internal']):'';
+           $post_detail=($row['j_poste'] != 
null)?HtmlInput::history_account($row['j_poste'],$row['j_poste']):'';
+           $card_detail=($row['f_id'] != 
null)?HtmlInput::history_card($row['f_id'],$row['qcode']):'';
+
+            $r.=
+                '<td>'.$row['oa_date'].'</td>'.
+             td($post_detail).
+             td($card_detail).
+             '<td>'.h($row['po_name']).'</td>'.
+             '<td>'.h($row['oa_description']).'</td>'.
+             td($row['jr_comment']).
+             '<td>'.$detail.'</td>'.
+             '<td class="num">'.nbm($row['oa_amount']).'</td>'.
+                '<td>'.(($row['oa_debit']=='f')?'CREDIT':'DEBIT').'</td>';
+            $r.= '</tr>';
+        }
+        $r.= '</table>';
+        return $r;
+    }
+    /*!
+     * \brief load the data from the database
+     *
+     * \return array
+     */
+    function load()
+    {
+        $op=new Anc_Operation ($this->db);
+        $op->pa_id=$this->pa_id;
+        
$array=$op->get_list($this->from,$this->to,$this->from_poste,$this->to_poste);
+        if (! $array ) 
+        {
+            $this->has_data=0;
+        }
+        else 
+        {
+            $this->has_data=count($array);
+        }
+        return $array;
+    }
+    /*!
+     * \brief Compute the csv export
+     * \return string with the csv
+     */
+
+    function display_csv()
+    {
+        
$array=$this->load($this->from,$this->to,$this->from_poste,$this->to_poste);
+        if ( empty($array) == true )
+        {
+            return $array;
+
+        }
+        $r="";
+        foreach ( $array as $row)
+        {
+            // the name and po_id
+            $r.=sprintf('"%s";',$row['oa_date']);
+            $r.=sprintf('"%s";',$row['j_poste']);
+            $r.=sprintf('"%s";',$row['qcode']);
+            $r.=sprintf('"%s";',$row['po_name']);
+            $r.=sprintf('"%s";',$row['oa_description']);
+            $r.=sprintf('"%s";',$row['oa_description']);
+
+            $r.=sprintf("%12.2f;",$row['oa_amount']);
+            $r.=sprintf("'%s'",(($row['oa_debit']=='f')?'CREDIT':'DEBIT'));
+            $r.="\r\n";
+        }
+        return $r;
+
+    }
+
+    /*!
+     * \brief show the export button to pdf and CSV
+     * \param $p_string string containing some HTML tag as hidden field
+     * \param
+     * \param
+     *
+     *
+     * \return string containing the html code
+     */
+    function show_button($p_string='')
+    {
+        $r="";
+        $submit=HtmlInput::submit('','');
+        $hidden=new IHidden();
+        /* for the export in PDF
+         * Not yet needed, the html print should be enough
+        $r.= '<form method="GET" action="ca_list_pdf.php" 
style="display:inline">';
+        $r.= $p_string;
+        $r.= dossier::hidden();
+        $r.= $hidden->input("to",$this->to);
+        $r.= $hidden->input("from",$this->from);
+        $r.= $hidden->input("pa_id",$this->pa_id);
+        $r.= $hidden->input("from_poste",$this->from_poste);
+        $r.= $hidden->input("to_poste",$this->to_poste);
+        $r.=HtmlInput::submit('bt_pdf',"Export en PDF");
+        $r.= '</form>';
+        */
+
+        $r.= '<form method="GET" action="export.php"  style="display:inline">';
+        $r.= HtmlInput::hidden("to",$this->to);
+        $r.= HtmlInput::hidden("from",$this->from);
+        $r.= HtmlInput::hidden("pa_id",$this->pa_id);
+        $r.= HtmlInput::hidden("from_poste",$this->from_poste);
+        $r.= HtmlInput::hidden("to_poste",$this->to_poste);
+       $r.=HtmlInput::hidden('act','CSV:AncList');
+        $r.=HtmlInput::hidden('ac',$_REQUEST['ac']);
+        $r.= $p_string;
+        $r.= dossier::hidden();
+        $r.=HtmlInput::submit('bt_csv',"Export en CSV");
+        $r.= '</form>';
+        return $r;
+
+    }
+    /*!
+     * \brief debugging and test function for dev. only
+     * \param
+     * \param
+     * \param
+     *
+     *
+     * \return
+     */
+    static  function test_me()
+    {
+    }
+}
diff --git a/include/class/class_anc_operation.php 
b/include/class/class_anc_operation.php
new file mode 100644
index 0000000..1c029b7
--- /dev/null
+++ b/include/class/class_anc_operation.php
@@ -0,0 +1,964 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ *\brief definition of Anc_Operation
+ */
+require_once NOALYSS_INCLUDE.'/lib/class_ibutton.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ihidden.php';
+require_once NOALYSS_INCLUDE.'/lib/class_iselect.php';
+require_once NOALYSS_INCLUDE.'/lib/class_itext.php';
+require_once NOALYSS_INCLUDE.'/class/class_anc_plan.php';
+require_once  NOALYSS_INCLUDE.'/lib/user_common.php';
+
+/*! \brief this class is used to show the form for entering an
+ *   operation only FOR analytic operation
+ *   to save it, to display or to get a list from a certain period
+ *
+ */
+class Anc_Operation
+{
+    var $db;   /*!< database connection */
+    var $row;  /*!< array of row for one operation*/
+    var $list; /*!< array of all operation */
+    var $id;   /*!< = oa_id (one row) */
+    var $po_id;        /*!< poste analytique */
+    var $oa_amount;    /*!< amount for one row */
+    var $oa_description;       /*!< comment for one row */
+    var $oa_debit;     /*!< true for debit or false */
+    var $j_id;         /*!< foreign key to a jrnx operation
+                                      (or null if none */
+    var $oa_group;   /*!< group of operation  */
+    var $oa_date;         /*!< equal to j_date if j_id is not    null */
+    var $pa_id;        /*!< the plan analytique id */
+    /**
+     * In the case, the amount comes from a ND VAT, the variable
+     * contents the jrnx.j_id of the source which was used to compute 
+     * the amount
+     */
+    var $oa_jrnx_id_source; 
+    /**
+     * @brief signed of the amount
+     */
+    var $oa_positive;
+    var $in_div; /*< name of the div if any, default empty string*/
+    /*!\brief constructor
+     *
+     */
+    function Anc_Operation ($p_cn,$p_id=0)
+    {
+        $this->db=$p_cn;
+        $this->id=$p_id;
+        $this->oa_jrnx_id_source=null;
+        $this->oa_positive='Y';
+        $this->has_data=0;
+        $this->in_div="";
+    }
+    /*!\brief add a row  to the table operation_analytique
+     * \note if $this->oa_group if 0 then a sequence id will be computed for
+     * the oa_group, if $this->j_id=0 then it will be null
+     *
+     */
+    function add($p_seq=0)
+    {
+
+        if ( $this->oa_group == 0)
+        {
+            $this->oa_group=$this->db->get_next_seq('s_oa_group');
+        }
+
+        if ( $this->j_id == 0 )
+        {
+            $this->j_id=null;
+        } else {
+            // must be the same side than the operation
+            if ( $this->oa_jrnx_id_source == null)
+            {
+                $side=$this->db->get_value('select j_debit from jrnx where 
j_id=$1',
+                    array($this->j_id));
+            } else 
+            {
+                $side=$this->db->get_value('select j_debit from jrnx where 
j_id=$1',
+                    array($this->oa_jrnx_id_source));
+            }
+            $this->oa_debit=$side;
+        }
+
+
+        // we don't save null operations
+        if ( $this->oa_amount == 0 || $this->po_id==-1)
+            return;
+        
+        if ( $this->oa_amount< 0) 
+        {
+            // if negatif must be oa_positive='N'
+            $this->oa_positive='N';
+            $this->oa_debit=($this->oa_debit=='t')?'f':'t';
+        }
+        
+        $oa_row=(isset($this->oa_row))?$this->oa_row:null;
+        $sql="insert into operation_analytique (
+             po_id, 
+             oa_amount,
+             oa_description,
+             oa_debit,
+             oa_group,
+             j_id,
+             oa_date,
+             oa_row,
+             oa_jrnx_id_source,
+             oa_positive
+             ) values ($1,$2,$3,$4,$5,$6,to_date($7,'DD.MM.YYYY'),$8,$9,$10)";
+
+        $this->db->exec_sql($sql,array(
+                $this->po_id, // 1
+                abs($this->oa_amount), //2
+                $this->oa_description, //3
+                $this->oa_debit, //4
+                $this->oa_group, //5
+                $this->j_id, //6
+                $this->oa_date, //7
+                $oa_row, //8
+                $this->oa_jrnx_id_source, //8
+                $this->oa_positive
+                ));
+
+    }
+    /*!\brief delete a row from the table operation_analytique
+     * \note be carefull : do not delete a row when we have a group
+     */
+    function delete()
+    {
+        $sql="delete from operation_analytique where oa_id=$1";
+
+        $this->db->exec_sql($sql,array($this->oa_id));
+    }
+
+    /*!\brief get a list of row from a certain periode
+     */
+    function get_list($p_from,$p_to,$p_from_poste="",$p_to_poste="")
+    {
+        $cond="";
+        $cond_poste="";
+
+        if ($p_from!="")
+            $cond="and (jr_date >= to_date('$p_from','DD.MM.YYYY')  or oa_date 
>= to_date('$p_from','DD.MM.YYYY') )";
+        if ( $p_to!="" )
+            $cond.="and (jr_date <=to_date('$p_to','DD.MM.YYYY') or  oa_date 
<=to_date('$p_to','DD.MM.YYYY')) ";
+
+        if ($p_from_poste != "" )
+            $cond_poste=" and upper(po_name) >= upper('".$p_from_poste."')";
+        if ($p_to_poste != "" )
+            $cond_poste.=" and upper(po_name) <= upper('".$p_to_poste."')";
+        $pa_id_cond="";
+        if ( isset ( $this->pa_id) && $this->pa_id !='')
+            $pa_id_cond= "pa_id=".$this->pa_id." and";
+       $sql="
+        
+       select oa_id,
+       po_name,
+       oa_description,
+       po_description,
+       oa_debit,
+       (case when jr_date is not null then to_char(jr_date,'DD.MM.YYYY') else 
to_char(oa_date,'DD.MM.YYYY') end )  as oa_date,
+       oa_amount,
+       oa_group,
+       j_id ,
+       jr_internal,
+       jr_id,
+       jr_comment,
+       j_poste,
+       jrnx.f_id,
+       ( select ad_value from fiche_Detail where f_id=jrnx.f_id and ad_id=23) 
as qcode,
+        jr_pj_number
+       from operation_analytique as B join poste_analytique using(po_id)
+       left join jrnx using (j_id)
+       left join jrn on  (j_grpt=jr_grpt_id)
+             where $pa_id_cond oa_amount <> 0.0 $cond $cond_poste
+       order by jr_date,oa_group,oa_debit desc,oa_id";
+
+        $RetSql=$this->db->exec_sql($sql);
+        $array=Database::fetch_all($RetSql);
+        return $array;
+    }
+
+    /*\brief show the HTML table for the operation
+     */
+    function html_table($p_from)
+    {
+        if ($p_from=="")
+        {
+            $from="";
+            $to="";
+        }
+        else
+        {
+            $p=new Periode($this->db);
+            list($from,$to)=$p->get_date_limit($p_from);
+        }
+
+        $array=$this->get_list($from,$to);
+        if ( empty($array)  )
+            return "Pas d'enregistrement trouv&eacute;";
+
+        // navigation_bar
+        $step=$_SESSION['g_pagesize'];
+        $page=(isset($_GET['offset']))?$_GET['page']:1;
+        $offset=(isset($_GET['offset']))?$_GET['offset']:0;
+        $bar=navigation_bar($offset+1,count($array),$step,$page);
+
+        if ( $step !=-1)
+            $view=array_splice($array,$offset,$step);
+        else
+            $view=$array;
+
+        $gDossier=dossier::id();
+        $ret="";
+        $ret.=$bar;
+
+        $count=0;
+        $group=0;
+        $oldgroup=0;
+        $oldjrid=0;
+
+        foreach ($view as $row)
+        {
+            $group=$row['oa_group'];
+            if ( $group !=$oldgroup )
+            {
+                if ( $oldgroup!=0 )
+                {
+
+                    $efface=new IButton();
+                    
$efface->javascript="anc_remove_operation(".$gDossier.",".$oldgroup.")";
+                    $efface->name="Efface";
+                    $efface->label="Efface";
+                    $ret.="<td>".$efface->input()."</td>";
+
+                    $this->oa_group=$oldgroup;
+                    $jr_id=$this->get_jrid();
+
+                    if ( $jr_id != 0)
+                    {
+                        // get the old jr_id
+                        $detail=new IButton();
+                        $detail->javascript="viewOperation($jr_id,$gDossier)";
+                        $detail->name="Detail";
+                        $detail->label="Detail";
+                        $ret.="<td>".$detail->input()."</td>";
+                    }
+                    $ret.='</table>';
+
+                }
+                $ret.='<table id="'.$row['oa_group'].'" class="result">';
+
+                $ret.="<tr class=\"highlight\">".
+                      td($row['oa_date']).
+                      "<td>".
+                      HtmlInput::detail_op($row['jr_id'],  
h($row['oa_description']." ".$row['jr_pj_number'])).
+                      "</td>".
+                        td();
+
+                $ret.="<td>".
+                      "Groupe id : ".$row['oa_group'].
+                      "</td>".
+
+                $oldgroup=$group;
+
+            }
+
+            $class=($count%2==0)?"odd":"even";
+            $count++;
+            $cred= ( $row['oa_debit'] == 'f')?"CREDIT":"DEBIT";
+            $ret.="<tr class=\"$class\">";
+            $ret.= "<td>".
+                   h($row['po_name']).
+                   "</td>";
+
+           $ret.=td(h($row['po_description']));
+
+            $ret.='<td class="num">'.  nbm($row['oa_amount']).
+                  "</td>".
+                  "<td>".
+                  $cred.
+                  "</td>".
+
+                  "</tr>";
+        }
+
+
+        $efface=new IButton();
+        $efface->javascript="anc_remove_operation("."$gDossier,".$oldgroup.")";
+        $efface->name="Efface";
+        $efface->label="Efface";
+        $ret.="<td>".$efface->input()."</td>";
+        // get the old jr_id
+        $this->oa_group=$oldgroup;
+        $jr_id=$this->get_jrid();
+        if ( $jr_id != 0 )
+        {
+            $detail=new IButton();
+            $detail->javascript="modifyOperation($jr_id,'".$gDossier."')";
+            $detail->name="Detail";
+            $detail->label="Detail";
+            $ret.="<td>".$detail->input()."</td>";
+        }
+        $ret.='</table>';
+        $ret.=$bar;
+        return $ret;
+    }
+    /*!\brief retrieve an operation thanks a jrnx.j_id
+     * \param the jrnx.j_id
+     * \return null if nothing is found other an array
+     */
+    function get_by_jid($p_jid)
+    {
+        $array=array();
+        $a_plan=$this->db->get_array('select pa_id from plan_analytique order 
by pa_id');
+        $res=array();
+        /*
+         * For one oa_row
+         */
+        $a_rowcount=$this->db->get_array("select distinct  oa_row "
+                ." from operation_analytique where j_id=$1 order by oa_row", 
array($p_jid));
+
+        for ($i=0; $i<count($a_rowcount); $i++)
+        {
+            /*
+             * Get one row as template for filling the missing 
+             */
+            $a_existing=$this->db->get_array('
+                    select distinct oa_id,
+                     po_id,
+                     oa_amount,
+                     oa_description,
+                     oa_debit,
+                     j_id,
+                     oa_group,
+                     oa_date,
+                     pa_id,
+                     oa_row,
+                     oa_positive
+                     from operation_analytique join poste_analytique using 
(po_id)
+                     where
+                     j_id=$1 and oa_row = $2 
+                     order by j_id,oa_row', 
+                    array($p_jid, $a_rowcount[$i]['oa_row']));
+            
+            // the first row we found will be the template
+            $template=$a_existing[0];
+            /*
+             * For each plan
+             */
+            for ($j=0; $j<count($a_plan); $j++)
+            {
+                /*
+                 * Fetch the row with this pa_id, oa_row, max : 1 row
+                 */
+                $a_fetch=$this->db->get_array('
+                    select distinct oa_id,
+                     po_id,
+                     oa_amount,
+                     oa_description,
+                     oa_debit,
+                     j_id,
+                     oa_group,
+                     oa_date,
+                     pa_id,
+                     oa_row,
+                     oa_positive
+                     from operation_analytique join poste_analytique using 
(po_id)
+                     where
+                     j_id=$1 and oa_row = $2  and pa_id=$3', array($p_jid,
+                    $a_rowcount[$i]['oa_row'],
+                    $a_plan[$j]['pa_id']
+                        )
+                );
+                if (count($a_fetch)==0)
+                {
+                    $a_fetch=$template;
+                    $a_fetch['pa_id']=$a_plan[$j]['pa_id'];
+                    $a_fetch['po_id']=-1;
+                    $a_fetch['oa_id']='';
+                    $res[]=$a_fetch;
+                }
+                else
+                if (count($a_fetch)==1)
+                {
+                    $res[]=$a_fetch[0];
+                }
+            }
+        }
+
+        foreach ($res as $row)
+        {
+            $a=new Anc_Operation($this->db);
+            foreach ($row as $attr=> $value)
+            {
+                $a->$attr=$row[$attr];
+            }
+            $array[]=clone $a;
+        }
+
+
+        return $array;
+    }
+
+    /*!\brief modify an op from modify_op.php
+     *
+     */
+    function update_from_jrnx($p_po_id)
+    {
+        $a=$this->get_by_jid($this->j_id);
+        if ( $a == null )
+        {
+            // retrieve data from jrnx
+            $sql="select jr_date,j_montant,j_debit from jrnx ".
+                 " join jrn on (jr_grpt_id = j_grpt) ".
+                 "where j_id=".$this->j_id;
+            $res=$this->db->exec_sql($sql);
+            if (Database::num_row($res) == 0 ) return;
+            $row=Database::fetch_array($res,0);
+            $this->oa_amount=$row['j_amount'];
+            $this->oa_date=$row['jr_date'];
+            $this->oa_debit=$row['j_debit'];
+            $this->oa_description=$row['jr_comment'];
+            $this->add();
+        }
+        else
+        {
+            foreach ($a as $row )
+            {
+                if ( $row->pa_id == $this->pa_id )
+                {
+                    $row->po_id=$p_po_id;
+                    $row->update();
+                }
+            }
+        }
+    }
+    /*!\brief retrieve the jr_id thanks the oa_group */
+    function get_jrid()
+    {
+        $sql="select distinct jr_id from jrn join jrnx on (j_grpt=jr_grpt_id) 
join operation_analytique using (j_id) where j_id is not null and 
oa_group=".$this->oa_group;
+        $res=$this->db->exec_sql($sql);
+        if ( Database::num_row($res) == 0 ) return 0;
+        $ret=Database::fetch_all($res);
+        return $ret[0]['jr_id'];
+    }
+    /*\brief this function get the balance for a certain period
+     *\param $p_from from date (accountancy period)
+     *\param $p_to to dat  (accountancy period)
+     *\param  $p_plan_id the plan id
+     */
+    function get_balance($p_from,$p_to,$p_plan_id)
+    {
+        // for the operation connected to jrnx
+        $cond=sql_filter_per($this->db,$p_from,$p_to,'p_id','j_date');
+        $sql="select oa_id, po_id, oa_amount, oa_debit, j_date from jrnx join 
operation_analytique using (j_id)
+             join poste_analytique using (po_id)
+             where
+             $cond and j_id is not null and pa_id=$p_plan_id";
+
+        // OD
+        $cond=sql_filter_per($this->db,$p_from,$p_to,'p_id','oa_date');
+        $sql="union select oa_id, po_id, oa_amount, oa_debit,oa_date from
+             operation_analytique
+             join poste_analytique using (po_id)
+             where j_id is null and
+             $cond and pa_id=$p_plan_id ";
+        try
+        {
+            $res=$this->db->exec_sql($sql);
+            $array=Database::fetch_all($res);
+        }
+        catch (Exception $e)
+        {
+            var_dump($e);
+        }
+    }
+    /*!\brief display the form for PA
+     *\param $p_array contains POST (or GET) data (val[] hplan[][] op[])
+     * \param $p_null = 1 if PA optional otherwise 0 mandatory
+     * \param $p_mode == form 1 ==> read/write otherwise 0==>readonly
+     * \param $p_seq number of the row
+     * \param $p_amount amount
+     * \param $p_id operation is detailled in a HTML popup, if several
+     *  are opened, the tableid MUST be different. So we need to use a new 
parameter
+     * \param $p_add_button true, show the button, false don't display them
+     * \see save_form_plan
+    @note
+    - op is an array containing the line number
+    - pa_id is an array of the existing array
+    - hplan is an array of the POSTE ANALYTIQUE id used, the size of hplan 
from 0 to x,
+    x can be bigger than the number of plan id
+    - val contains the amount by row inside the table. One operation (j_id) 
you can have several rows
+    @code
+    0 =>
+      array
+        'op' => int 200
+    'pa_id' =>
+      array
+        0 => string '14' (length=2)
+        1 => string '15' (length=2)
+    'hplan' =>
+      array
+        1 =>
+          array
+            0 => string '25' (length=2)
+            1 => string '26' (length=2)
+    'val' =>
+      array
+        1 =>
+          array
+            0 => string '100.0000' (length=8)
+
+    @endcode
+     */
+    function 
display_form_plan($p_array,$p_null,$p_mode,$p_seq,$p_amount,$p_id='',$p_add_button=true)
+    {
+        if ( $p_array != null)
+            extract ($p_array);
+        $result="";
+        $plan=new Anc_Plan($this->db);
+        $a_plan=$plan->get_list(" order by pa_id ");
+        if ( empty ($a_plan) ) return "";
+        $table_id="t".$p_seq;
+        $hidden=new IHidden();
+
+               $readonly=($p_mode==1)?false:true;
+
+        $result.=$hidden->input('amount_'.$table_id,$p_amount);
+        if ( $p_mode==1 )
+            $result.='<table id="'.$p_id.$table_id.'">';
+        else
+            $result.='<table>';
+        $result.="<tr>".$plan->header()."<th>montant</th></tr>";
+
+        /* compute the number of rows */
+        $nb_row=(isset($val[$p_seq]))?count($val[$p_seq]):1;
+        $count=0;
+
+        $remain=abs($p_amount);
+        $ctrl_remain="remain".$this->in_div.$table_id;
+
+        for ( $i=0; $i < $nb_row;$i++)
+        {
+            $result.='<tr>';
+
+            foreach ($a_plan as $r_plan)
+            {
+
+                $array=$this->db->make_array(
+                           "select po_id as value,".
+                           " html_quote(po_name) as label from 
poste_analytique ".
+                           " where pa_id = ".$r_plan['id'].
+                           " order by po_name",$p_null);
+                $select =new ISelect("hplan[".$p_seq."][]",$array);
+                $select->table=0;
+                // view only or editables
+                if (  $p_mode==1 )
+                {
+                    // editable
+                    $select->readonly=false;
+                    if ( isset($hplan) && isset($hplan[$p_seq][$count]) ){
+                        $select->selected=$hplan[$p_seq][$count];
+
+                                       }
+                }
+                else
+                {
+                                       if ( isset($hplan) && 
isset($hplan[$p_seq][$count]) ){
+                        $select->selected=$hplan[$p_seq][$count];
+                                       }
+                    // view only
+                    $select->readOnly=true;
+                }
+                if ($p_mode==1)
+                    $result.='<td>'.$select->input().'</td>';
+                else
+                    $result.='<td>'.$select->display().'</td>';
+                $count++;
+
+
+            }
+            $value=new INum();
+           
$value->javascript='onchange="format_number(this);anc_refresh_remain(\''.$this->in_div.$table_id.'\',\''.$p_seq.'\')"';
+            $value->name="val[".$p_seq."][]";
+            $value->size=6;
+            
$value->value=(isset($val[$p_seq][$i]))?$val[$p_seq][$i]:abs($p_amount);
+            $value->readOnly=($p_mode==1)?false:true;
+            $remain=bcsub($remain,$value->value);
+            $result.='<td>'.$value->input().'</td>';
+
+            $result.="</tr>";
+        }
+
+        $result.="</table>";
+
+        if ($p_add_button && $p_mode == 1)
+        {
+            $style_remain=($remain==0)?'style="color:green"':' 
style="color:red"';
+            $result.=" Reste à imputer =  ".
+                     '<span class="remain" '.$style_remain.' 
id="'.$ctrl_remain.'">'.
+                            $remain.'</span>';
+            // add a button to add a row
+            $button=new IButton();
+            $button->javascript="add_row('".$p_id."$table_id',$p_seq);";
+            $button->name="js".$p_id.$p_seq;
+            $button->label=_("Nouvelle ligne");
+
+            $result.="<br>".$button->input();
+            /**
+             * Add a button for distribution key
+             * 
+             */
+            $ledger=HtmlInput::default_value_post("p_jrn", 0);
+            if ($ledger==0) {
+                $ledger=$this->db->get_value('select j_jrn_def from jrnx where 
j_id=$1',array($this->j_id));
+            }
+            $gDossier=Dossier::id();
+            $button_key=new IButton();
+            
$button_key->javascript="anc_key_choice(".$gDossier.",'".$p_id."$table_id',$p_amount,'".$ledger."');";
+            $button_key->name="js".$p_id.$p_seq;
+            $button_key->label=_("Clef");
+            $result .= $button_key->input();
+
+        }
+
+        return $result;
+    }
+    /**
+     * Save the ND VAT with prorata
+     * 
+     * @param $p_array usually $_POST
+     * @param $p_item item of the form
+     * @param $p_j_id jrnx.j_id concerned writing
+     * @param $p_nd amount nd vat
+     * @see Anc_Operation::save_form_plan_vat_nd
+     * @return type
+     */
+    function save_form_plan_vat_nd($p_array,$p_item,$p_j_id,$p_nd)
+    {
+        bcscale(4);
+        extract($p_array);
+       if (! isset ($hplan) ) return;
+        
+        if ( ! isset(${'amount_t'.$p_item}) )
+            throw new Exception ('amount not set');
+        
+        $tot=0;
+        /* variable for in array
+           pa_id array of existing pa_id
+           hplan double array with the pa_id (column)
+           val double array by row with amount
+           op contains sequence
+           p_item is used to identify what op is concerned
+        */
+        /* echo "j_id = $j_id p_item = $p_item 
hplan=".var_export($hplan[$p_item],true)." val = 
".var_export($val[$p_item],true).'<br>'; */
+        /* for each row */
+        //   for ($i=0;$i<count($val[$p_item]);$i++) {
+        $idx_pa_id=0;
+        $row=0;
+        $a_Anc_Operation=array();
+        // foreach col PA
+        for ($e=0;$e<count($hplan[$p_item]);$e++)
+        {
+            if ( $idx_pa_id == count($pa_id))
+            {
+                $idx_pa_id=0;
+                $row++;
+            }
+            if ($hplan[$p_item][$e] != -1 && $val[$p_item][$row] != '')
+            {
+                $op=new Anc_Operation($this->db);
+                $op->po_id=$hplan[$p_item][$e];
+                $op->oa_group=$this->oa_group;
+                $op->j_id=$p_j_id;
+                $ratio=bcdiv($val[$p_item][$row],${"amount_t".$p_item});
+                $amount=  bcmul($p_nd, $ratio);
+                $op->oa_amount=round($amount,2);
+                $op->oa_debit=$this->oa_debit;
+                $op->oa_date=$this->oa_date;
+
+                $op->oa_description=$this->oa_description;
+                $op->oa_row=$row;
+                $op->oa_jrnx_id_source=$this->oa_jrnx_id_source;
+                $a_Anc_Operation[]=clone $op;
+            }
+            $idx_pa_id++;
+        }
+        $nb_op=count($a_Anc_Operation);
+        bcscale(2);
+        for ($i=0;$i<$nb_op;$i++)
+        {
+            $tot=bcadd($tot,$a_Anc_Operation[$i]->oa_amount);
+        }
+        if ( $tot != $p_nd )
+        {
+            $diff=  bcsub($tot, $p_nd);
+            
$a_Anc_Operation[0]->oa_amount=bcsub($a_Anc_Operation[0]->oa_amount,$diff);
+        }
+        for ($i=0;$i<$nb_op;$i++)
+        {
+            $a_Anc_Operation[$i]->add();
+        }
+    }
+    /*!\brief it called for each item, the data are taken from $p_array
+     *  data and set before in this.
+     * \param $p_item if the item nb for each item (purchase or selling
+     *  merchandise)
+     * \param $p_array structure
+     * \verbatim
+      nb_tA A is the number of the item it contains the number of
+              rows of CA for this card
+      valAlR amount for the CA (item A row R)
+      ta_AoCrow_R contains the value of the pa_id and po_id for this
+                  row with the form pa_id_po_id %d_%d
+     *\endverbatim
+     * \attention The idea is one j_id matches several oa_id,
+     *  serveral data are set before the call :
+     *   -j_id
+     *   -oa_debit
+     *   -oa_group
+     *   -oa_date
+     *   -oa_description
+     *
+     */
+    function save_form_plan($p_array,$p_item,$p_j_id)
+    {
+        extract($p_array);
+       if (! isset ($hplan) ) return;
+        /* variable for in array
+           pa_id array of existing pa_id
+           hplan double array with the pa_id (column)
+           val double array by row with amount
+           op contains sequence
+           p_item is used to identify what op is concerned
+        */
+        /* echo "j_id = $j_id p_item = $p_item 
hplan=".var_export($hplan[$p_item],true)." val = 
".var_export($val[$p_item],true).'<br>'; */
+        /* for each row */
+        //   for ($i=0;$i<count($val[$p_item]);$i++) {
+        $idx_pa_id=0;
+        $row=0;
+        // foreach col PA
+        for ($e=0;$e<count($hplan[$p_item]);$e++)
+        {
+            if ( $idx_pa_id == count($pa_id))
+            {
+                $idx_pa_id=0;
+                $row++;
+            }
+            if ($hplan[$p_item][$e] != -1 && $val[$p_item][$row] != '')
+            {
+                $op=new Anc_Operation($this->db);
+                $op->po_id=$hplan[$p_item][$e];
+                $op->oa_group=$this->oa_group;
+                $op->j_id=$p_j_id;
+                $op->oa_amount=$val[$p_item][$row];
+                $op->oa_debit=$this->oa_debit;
+                $op->oa_date=$this->oa_date;
+
+                $op->oa_description=$this->oa_description;
+                $op->oa_row=$row;
+                $op->add();
+            }
+            $idx_pa_id++;
+        }
+        // }
+    }
+
+    /**
+    address@hidden save a whole form from a update box
+    address@hidden $p_array  for ALL j_id
+    address@hidden
+    address@hidden
+    address@hidden save_form_plan to_request
+    @code
+
+    @endcode
+    */
+    function save_update_form($p_array)
+    {
+        extract($p_array);
+        for ($i = 0; $i < count($op); $i++)
+        {
+            /* clean operation_analytique */
+            $this->db->exec_sql('delete from operation_analytique where 
j_id=$1', array($op[$i]));
+
+            /* get missing data for adding */
+            $a_missing = $this->db->get_array("select 
to_char(jr_date,'DD.MM.YYYY') 
+                    as mdate,j_montant,j_debit,jr_comment ,j_poste
+                    from jrnx join jrn on (j_grpt=jr_grpt_id) where j_id=$1", 
array($op[$i]));
+            $missing = $a_missing[0];
+           
+            $this->oa_description = $missing['jr_comment'];
+            $this->j_id = $op[$i];
+            $group = $this->db->get_next_seq("s_oa_group"); /* for analytic */
+            $this->oa_group = $group;
+            $this->oa_date = $missing['mdate'];
+            $this->save_form_plan($p_array, $i, $op[$i]);
+            
+            // There is ND VAT amount
+            $a_nd = $this->db->get_array('select j_id from operation_analytique
+                where oa_jrnx_id_source=$1', array($op[$i]));
+            if (count($a_nd) > 0)
+            {
+                // for each ND VAT amount
+                for ($e=0;$e<count($a_nd);$e++)
+                {
+                    $this->db->exec_sql('delete from operation_analytique 
where j_id=$1', array($a_nd[$e]['j_id']));
+                    /* get missing data for adding */
+                    $a_missing_vat = $this->db->get_array("select 
to_char(jr_date,'DD.MM.YYYY') as mdate,j_montant,j_debit,jr_comment from jrnx 
join jrn on (j_grpt=jr_grpt_id) where j_id=$1", array($a_nd[$e]['j_id']));
+                    $missing_vat = $a_missing_vat[0];
+                    $this->oa_debit = 't';
+                    $this->oa_description = $missing_vat['jr_comment'];
+                    $this->j_id = $op[$i];
+                    $group = $this->db->get_next_seq("s_oa_group"); /* for 
analytic */
+                    $this->oa_group = $group;
+                    $this->oa_date = $missing_vat['mdate'];
+                    $this->oa_jrnx_id_source=$op[$i];
+                    $p_array['amount_t'.$i]=$missing['j_montant'];
+                    $this->save_form_plan_vat_nd($p_array, $i, 
$a_nd[$e]['j_id'],$missing_vat['j_montant']);
+                }
+            }
+        }
+    }
+
+    /*\brief transform a array of operation into a array usage by
+     *display_form_plan & save_form_plan
+     *\param $p_array array of operation
+     *\param $p_line line
+     *\return an array complying with \see save_form_plan
+     */
+    function to_request ($p_array,$p_line)
+    {
+        $result=array();
+        $result[]=array('op'=>$this->j_id);
+        $pa_id=array();
+
+        /* First add the pa_id */
+        for ($i=0;$i < count($p_array);$i++)
+        {
+            if ( in_array($p_array[$i]->pa_id,$pa_id)==false)
+                $pa_id[]=$p_array[$i]->pa_id;
+        }
+        $result['pa_id']=$pa_id;
+
+        /* add the hplan */
+        $seq=0;
+        for ($i=0;$i < count($p_array);$i++)
+        {
+            $hplan[$p_line][$i]=$p_array[$i]->po_id;
+        }
+        $result['hplan']=$hplan;
+        /* Add the amount */
+        $idx_pa=0;
+        $jrn_def=$this->db->get_value('select jrn_def_type from jrnx join 
jrn_def on (j_jrn_def=jrn_def_id) where j_id=$1',array($this->j_id));
+        for ($i=0;$i < count($p_array);$i++)
+        {
+            
+            /*
+             * For the bank, negatif are always on the debit and positif on 
the credit
+             */
+            if ( $jrn_def != 'FIN')
+            {
+                
$val[$p_line][$p_array[$i]->oa_row]=($p_array[$i]->oa_positive=='Y')?$p_array[$i]->oa_amount:($p_array[$i]->oa_amount*(-1));
+            }
+            else
+            {
+                $val[$p_line][$p_array[$i]->oa_row]=$p_array[$i]->oa_amount;
+            }
+        }
+        $result['val']=$val;
+        return $result;
+    }
+    /*!
+     * \brief delete from operation_analytique
+     * \param $p_jid the operation_analytique.j_id field
+     *
+     * \return none
+     */
+    function delete_by_jid($p_jid)
+    {
+        $sql="delete from operation_analytique where j_id=$p_jid";
+        $this->db->exec_sql($sql);
+    }
+    /*\brief Display a table with analytic accounting in
+     *       detail of operation
+     address@hidden $this->j_id must be set
+     *\param $p_mode 0 = readonly or 1=writable
+     *\param $p_amount amount
+     *\param $p_id unique id
+     address@hidden display_form_plan
+     *\return string to display
+     */
+    function display_table($p_mode,$p_amount,$p_id)
+    {
+        static $seq=-1;                /* first seq == 0 */
+        $seq++;
+
+        $array=$this->get_by_jid($this->j_id) ;
+        if ( $array != null )
+        {
+            $request=$this->to_request($array,$seq);
+            return 
"<td>".$this->display_form_plan($request,1,$p_mode,$seq,$p_amount,$p_id)."</td>";
+        }
+        else
+        {
+            return 
'<td>'.$this->display_form_plan(null,1,$p_mode,$seq,$p_amount,$p_id)."</TD>";
+        }
+        return "";
+
+    }
+///////////////////////////////////////////////////////////////////////////
+// TEST
+///////////////////////////////////////////////////////////////////////////
+    /*\brief test the class
+     *\param
+     *\param
+     *\return
+     */
+    function test_me()
+    {
+        $cn=new Database(dossier::id());
+        $anco=new Anc_Operation($cn);
+        $j_id=200;
+        $anco->j_id=$j_id;
+        $array=$anco->get_by_jid($j_id);
+        $a=$anco->to_request($array,1);
+        echo '<form>';
+        echo dossier::hidden();
+        echo HtmlInput::hidden('j_id',$j_id);
+        echo HtmlInput::hidden('test_select',$_REQUEST['test_select']);
+        echo $anco->display_table(1,15002,0);
+        echo '<input type="submit" name="save">';
+        echo '</form>';
+        if ( isset($_REQUEST['save']))
+        {
+            echo "to_save";
+            var_dump($_REQUEST);
+        }
+        var_dump($a);
+
+    }
+
+}
diff --git a/include/class/class_anc_plan.php b/include/class/class_anc_plan.php
new file mode 100644
index 0000000..2597c1f
--- /dev/null
+++ b/include/class/class_anc_plan.php
@@ -0,0 +1,248 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief Concerns the Analytic plan (table plan_analytique)
+ */
+
+/*! \brief
+ *  Concerns the Analytic plan (table plan_analytique)
+ */
+require_once NOALYSS_INCLUDE.'/lib/class_itext.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ihidden.php';
+require_once NOALYSS_INCLUDE.'/constant.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/class/class_anc_account.php';
+require_once  NOALYSS_INCLUDE.'/class/class_dossier.php';
+
+class Anc_Plan
+{
+    var $db; /*!<database connection */
+    var $name;                                         /*!< name 
plan_analytique.pa_name */
+    var $description;                          /*!< description of the PA 
plan_analytique.pa_description*/
+    var $id;                                           /*!< id = 
plan_analytique.pa_id */
+
+    function Anc_Plan($p_cn,$p_id=0)
+    {
+        $this->db=$p_cn;
+        $this->id=$p_id;
+        $this->name="";
+        $this->description="";
+        $this->get();
+    }
+    /*!\brief get the list of all existing PA
+     * \return an array of PA (not object)
+     *
+     */
+    function get_list($p_order=" order by pa_name")
+    {
+        $array=array();
+        $sql="select pa_id as id,pa_name as name,".
+             "pa_description as description from plan_analytique $p_order";
+        $ret=$this->db->exec_sql($sql);
+        $array=Database::fetch_all($ret);
+        return $array;
+    }
+
+    function get()
+    {
+        if ( $this->id==0) return;
+
+        $sql="select pa_name,pa_description from plan_analytique where 
pa_id=".$this->id;
+        $ret= $this->db->exec_sql($sql);
+        if ( Database::num_row($ret) == 0)
+        {
+            return;
+        }
+        $a=  Database::fetch_array($ret,0);
+        $this->name=$a['pa_name'];
+        $this->description=$a['pa_description'];
+
+    }
+
+    function delete()
+    {
+        if ( $this->id == 0 ) return;
+        $this->db->exec_sql("delete from plan_analytique where 
pa_id=".$this->id);
+    }
+
+    function update()
+    {
+        if ( $this->id==0) return;
+        $name=sql_string($this->name);
+        if ( strlen($name) == 0)
+            return;
+
+        $description=sql_string($this->description);
+        $this->db->exec_sql("update plan_analytique set pa_name=$1,
+                            pa_description=$2 where 
pa_id=$3",array($name,$description,$this->id));
+    }
+
+    function add()
+    {
+        $name=sql_string($this->name);
+        if ( strlen($name) == 0)
+            return;
+        if ( $this->isAppend() == false) return;
+        $description=sql_string($this->description);
+        $this->db->exec_sql("insert into 
plan_analytique(pa_name,pa_description)".
+                            " values (".
+                            "'".$name."',".
+                            "'".$description."')");
+        $this->id=$this->db->get_current_seq('plan_analytique_pa_id_seq');
+
+    }
+    function form()
+    {
+
+        $wName=new IText('pa_name',$this->name);
+
+        $wName->table=1;
+        $wDescription=new IText('pa_description',$this->description);
+        $wDescription->table=1;
+        $wId=new IHidden("pa_id",$this->id);
+        $ret="<TABLE>";
+        $ret.='<tr>'.td(_('Nom')).$wName->input().'</tr>';
+        $ret.="<tr>".td(_('Description')).$wDescription->input()."</tr>";
+        $ret.="</table>";
+        $ret.=$wId->input();
+        return $ret;
+    }
+    function isAppend()
+    {
+        $count=$this->db->get_value("select count(pa_id) from 
plan_analytique");
+
+        if ( $count > 10 )
+            return false;
+        else
+            return true;
+    }
+    /*!\brief get all the poste related to the current
+     *        Analytic plan
+     * \return an array of Poste_analytic object
+     */
+    function get_poste_analytique($p_order="")
+    {
+        $sql="select po_id,po_name from poste_analytique where 
pa_id=".$this->id." $p_order";
+        $r=$this->db->exec_sql($sql);
+        $ret=array();
+        if ( Database::num_row($r) == 0 )
+            return $ret;
+
+        $all=Database::fetch_all($r);
+        foreach ($all as $line)
+        {
+            $obj=new Anc_Account($this->db,$line['po_id']);
+            $obj->get_by_id();
+            $ret[]=clone $obj;
+        }
+        return $ret;
+    }
+    /*!\brief show the header for a table for PA
+     * \return string like <th>name</th>...
+     */
+    function header()
+    {
+        $res="";
+        $a_plan=$this->get_list(" order by pa_id");
+        if ( empty($a_plan)) return "";
+        foreach ($a_plan as $r_plan)
+        {
+            $res.="<th>".h($r_plan['name'])."</th>";
+        }
+        return $res;
+    }
+    function count()
+    {
+        $a=$this->db->count_sql("select pa_id from plan_analytique");
+        return $a;
+    }
+    function exist()
+    {
+        $a=$this->db->count_sql("select pa_id from plan_analytique where 
pa_id=".
+                                Database::escape_string($this->pa_id));
+
+        return ($a==0)?false:true;
+
+    }
+    /**
+    address@hidden return an HTML string containing hidden input type to
+    * hold the differant PA_ID
+    address@hidden $p_array contains a array, it is the result of the fct
+    * Anc_Plan::get_list
+    address@hidden html string
+    address@hidden Anc_Plan::get_list
+    */
+    static function hidden($p_array)
+    {
+        $r='';
+        for ($i_anc=0;$i_anc <count($p_array);$i_anc++)
+        {
+            $r.=HtmlInput::hidden('pa_id[]',$p_array[$i_anc]['id']);
+        }
+        return $r;
+    }
+    static function test_me()
+    {
+        $cn=new Database(dossier::id());
+        echo "<h1>Plan analytique : test</h1>";
+        echo "clean";
+        $cn->exec_sql("delete from plan_analytique");
+
+        $p=new Anc_Plan($cn);
+        echo "<h2>Add</h2>";
+        $p->name="Nouveau 1";
+        $p->description="C'est un test";
+        echo "Add<hr>";
+        $p->add();
+        $p->name="Nouveau 2";
+        $p->add();
+        $pa_id=$p->id;
+        echo $p->id."/";
+        $p->name="Nouveau 3";
+        $p->add();
+        echo $p->id."/";
+
+
+        $p->name="Nouveau 4";
+        $p->add();
+        echo $p->id;
+
+        echo "<h2>get</h2>";
+        $p->get();
+        var_dump($p);
+        echo "<h2>Update</h2> ";
+        $p->name="Update ";
+        $p->description="c'est change";
+        $p->update();
+        $p->get();
+        var_dump($p);
+        echo "<h2>get_list</h2>";
+        $a=$p->get_list();
+        var_dump($a);
+        echo "<h2>delete </h2>";
+        $p->delete();
+
+
+    }
+}
+
+?>
diff --git a/include/class/class_anc_print.php 
b/include/class/class_anc_print.php
new file mode 100644
index 0000000..24d79df
--- /dev/null
+++ b/include/class/class_anc_print.php
@@ -0,0 +1,224 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ *  \brief this class is the mother class for the CA printing
+ */
+
+/*! \brief this class is the mother class for the CA printing
+ *
+ *
+ */
+require_once NOALYSS_INCLUDE.'/lib/class_idate.php';
+require_once NOALYSS_INCLUDE.'/lib/class_itext.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ihidden.php';
+require_once NOALYSS_INCLUDE.'/lib/class_iselect.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ibutton.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/constant.php';
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+require_once  NOALYSS_INCLUDE.'/class/class_anc_plan.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ianccard.php';
+class Anc_Print
+{
+    var $db;                                           /*!< $db database 
connection */
+    var $to;                                           /*!< $to start date */
+    var $from;                                         /*!< $from end date */
+    var $from_poste;                           /*!< $from_poste from poste  */
+    var $to_poste;                             /*!< $to_poste to the poste */
+
+    function Anc_Print($p_cn)
+    {
+        $this->db=$p_cn;
+        $this->from="";
+        $this->to="";
+        $this->from_poste="";
+        $this->to_poste="";
+        $this->has_data=0;
+
+    }
+    /*!
+     * \brief complete the object with the data in $_REQUEST
+     */
+    function get_request()
+    {
+        if ( isset($_REQUEST['from']))
+            $this->from=$_REQUEST['from'];
+
+        if ( isset($_REQUEST['to']))
+            $this->to=$_REQUEST['to'];
+
+        if ( isset($_REQUEST['from_poste']))
+            $this->from_poste=$_REQUEST['from_poste'];
+
+        if ( isset($_REQUEST['to_poste']))
+            $this->to_poste=$_REQUEST['to_poste'];
+        if ( isset($_REQUEST['pa_id']))
+            $this->pa_id=$_REQUEST['pa_id'];
+        else
+            $this->pa_id="";
+
+    }
+    /*!
+     * \brief Compute  the form to display
+     * \param $p_hidden hidden tag to be included (gDossier,...)
+     *
+     *
+     * \return string containing the data
+     */
+    function display_form($p_hidden="")
+    {
+        /* if there is no analytic plan return */
+        $pa=new Anc_Plan($this->db);
+        if ( $pa->count() == 0 )
+        {
+            echo '<div class="content">';
+            echo '<h2 class="error">'._('Aucun plan défini').'</h2>';
+            echo '</div>';
+            return;
+        }
+
+        $from=new IDate('from','from');
+        $from->size=10;
+        $from->value=$this->from;
+
+        $to=new IDate('to','to');
+        $to->value=$this->to;
+        $to->size=10;
+
+        $from_poste=new IAncCard('from_poste','from_poste');
+        $from_poste->size=10;
+        $from_poste->plan_ctl='pa_id';
+        $from_poste->value=$this->from_poste;
+
+        $to_poste=new IAncCard('to_poste','to_poste');
+        $to_poste->value=$this->to_poste;
+        $to_poste->size=10;
+
+        $hidden=new IHidden();
+        $r=dossier::hidden();
+        $r.=$hidden->input("result","1");
+        
+        $r.=HtmlInput::request_to_hidden(array('ac'));
+        $r.=$p_hidden;
+        $plan=new Anc_Plan($this->db);
+        $plan_id=new ISelect("pa_id");
+        $plan_id->value=$this->db->make_array("select pa_id, pa_name from 
plan_analytique order by pa_name");
+        $plan_id->selected=$this->pa_id;
+        $choose_from=new IButton();
+        $choose_from->name=_("Choix Poste");
+        $choose_from->label=_("Recherche");
+        
$choose_from->javascript="onClick=search_ca(".dossier::id().",'from_poste','pa_id')";
+        
+
+        $choose_to=new IButton();
+        $choose_to->name=_("Choix Poste");
+        $choose_to->label=_("Recherche");
+
+        
+        
$choose_to->javascript="onClick=search_ca(".dossier::id().",'to_poste','pa_id')";
+      
+        $r.=HtmlInput::request_to_hidden(array('ac'));
+        ob_start();
+        ?>
+<table>
+    <tr>
+        <td>
+            <?php 
+                echo _('Depuis') ;
+                echo HtmlInput::infobulle(37);
+            ?>
+        </td>
+        <td>
+            <?php 
+                echo $from->input(); 
+            ?>
+        </td>
+    </tr>
+    <tr>
+        <td>
+            <?php 
+                echo _('Jusque') ;
+                echo HtmlInput::infobulle(37);
+            ?>
+        </td>
+        <td>
+            <?php 
+                echo $to->input(); 
+            ?>
+        </td>
+    </tr>
+    
+</table>
+<span style="padding:5px;margin:5px;display:block;">
+    <?php echo _( "Plan Analytique :").$plan_id->input(); 
+        echo HtmlInput::infobulle(42);
+    ?>
+</span>
+
+<?php
+        $r.=ob_get_clean();
+        $r.=_("Entre l'activité ").$from_poste->input();
+        $r.=$choose_from->input();
+        $r.=_(" et l'activité ").$to_poste->input();
+        $r.=$choose_to->input();
+
+        $r.='</span>';
+        return $r;
+    }
+    /*!
+     * \brief Set the filter (account_date)
+     *
+     * \return return the string to add to load
+     */
+
+    function set_sql_filter()
+    {
+        $sql="";
+        $and=" and ";
+        if ( $this->from != "" )
+        {
+            $sql.="$and a.oa_date >= to_date('".$this->from."','DD.MM.YYYY')";
+        }
+        if ( $this->to != "" )
+        {
+            $sql.=" $and a.oa_date <= to_date('".$this->to."','DD.MM.YYYY')";
+        }
+
+        return $sql;
+
+    }
+  function check()
+  {
+
+    /*
+     * check date
+     */
+    if (($this->from != '' && isDate ($this->from) == 0)
+       ||
+       ($this->to != '' && isDate ($this->to) == 0))
+      return -1;
+
+    return 0;
+  }
+
+
+}
diff --git a/include/class/class_anc_table.php 
b/include/class/class_anc_table.php
new file mode 100644
index 0000000..01ef0fa
--- /dev/null
+++ b/include/class/class_anc_table.php
@@ -0,0 +1,329 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief object to show a table: link between accountancy and analytic
+ */
+require_once NOALYSS_INCLUDE.'/class/class_anc_acc_link.php';
+
+class Anc_Table extends Anc_Acc_Link
+{
+  /**
+   address@hidden display form to get the parameter 
+   *  - card_poste 1 by card, 2 by account
+   *  - from_poste 
+   *  - to_poste
+   *  - from from date
+   *  - to until date
+   *  - pa_id Analytic plan to use
+   */
+  function display_form($p_hidden='')
+  {
+    $r=parent::display_form($p_hidden);
+    $icard=new ISelect('card_poste');
+    $icard->value=array(
+                       array('value'=>1,'label'=>'Par fiche'),
+                       array('value'=>2,'label'=>'Par poste comptable')
+                       );
+    $icard->selected=$this->card_poste;
+    $r.=$icard->input();
+    $r.=HtmlInput::request_to_hidden(array('ac'));
+    return $r;
+  }
+
+
+  /**
+   * load the data
+   * does not return anything but give a value to this->aheader and this->arow
+   */
+  function load_poste()
+  {
+    $sql_from_poste=($this->from_poste!='')?" and  po.po_name >= 
upper('".Database::escape_string($this->from_poste)."')":'';
+    $sql_to_poste=($this->to_poste!='')?" and  po.po_name <= 
upper('".Database::escape_string($this->to_poste)."')":'';
+    $this->db->exec_sql('create temporary table table_analytic as select * 
from comptaproc.table_analytic_account(\''.$this->from.'\',\''.$this->to.'\')');
+
+    $header="select distinct po_id,po_name  from table_analytic
+               where
+               pa_id=$1 ".$sql_from_poste.$sql_to_poste." order by po_name";
+    $this->aheader=$this->db->get_array($header,array($this->pa_id));
+    
+    $this->arow=$this->db->get_array("select distinct card_account,name
+               from table_analytic
+               where
+               pa_id=$1 ".$sql_from_poste.$sql_to_poste." order by 
card_account",array($this->pa_id));
+
+    $this->sql='select sum_amount from  table_analytic where card_account=$1 
and po_id=$2 and pa_id='.$this->pa_id.' '.$sql_from_poste.$sql_to_poste;
+  }
+
+  /**
+   * load the data
+   * does not return anything but give a value to this->aheader and this->arow
+   */
+  function load_card()
+  {
+    $sql_from_poste=($this->from_poste!='')?" and  po.po_name >= 
upper('".Database::escape_string($this->from_poste)."')":'';
+    $sql_to_poste=($this->to_poste!='')?" and  po.po_name <= 
upper('".Database::escape_string($this->to_poste)."')":'';
+    $this->db->exec_sql('create temporary table table_analytic as select * 
from comptaproc.table_analytic_card(\''.$this->from.'\',\''.$this->to.'\')');
+
+    $header="select distinct po_id,po_name from table_analytic
+               where
+               pa_id=$1 ".$sql_from_poste.$sql_to_poste." order by po_name";
+    $this->aheader=$this->db->get_array($header,array($this->pa_id));
+    
+    $this->arow=$this->db->get_array("select distinct f_id,card_account,name 
from  table_analytic 
+                       where
+               pa_id=$1 ".$sql_from_poste.$sql_to_poste." order by 
name",array($this->pa_id));
+    $this->sql='select sum_amount from table_analytic where f_id=$1 and 
po_id=$2 and pa_id='.$this->pa_id.' '.$sql_from_poste.$sql_to_poste;
+  }
+  /**
+   address@hidden display the button export CSV
+   address@hidden $p_hidden is a string containing hidden items
+   address@hidden html string
+   */  
+  function show_button($p_hidden)
+  {
+    $r="";
+    $r.= '<form method="GET" action="export.php"  style="display:inline">';
+    $r.= HtmlInput::hidden("act","CSV:AncTable");
+    $r.= HtmlInput::hidden("to",$this->to);
+    $r.= HtmlInput::hidden("from",$this->from);
+    $r.= HtmlInput::hidden("pa_id",$this->pa_id);
+    $r.= HtmlInput::hidden("from_poste",$this->from_poste);
+    $r.= HtmlInput::hidden("to_poste",$this->to_poste);
+    $r.= HtmlInput::hidden("card_poste",$this->card_poste);
+    $r.= $p_hidden;
+    $r.= dossier::hidden();
+    $r.=HtmlInput::submit('bt_csv',"Export en CSV");
+    $r.= '</form>';
+    return $r;
+  }
+  function display_html()
+  {
+    bcscale(2);
+    if ( $this->check()  != 0)
+      {
+       alert('Désolé mais une des dates données n\'est pas valide');
+       return;
+      }
+
+    if ( $this->card_poste=='1')
+      {
+       $this->load_card();
+
+       echo '<table class="result">';
+       echo '<tr>';
+       echo th('Fiche');
+       foreach ($this->aheader as $h)
+         {
+           echo '<th style="text-align:right">'.h($h['po_name']).'</th>';
+         }
+       echo th('Total',' style="text-align:right"');
+       echo '</tr>';
+       /*
+        * Show all the result
+        */
+       $tot_global=0;
+       for ($i=0;$i<count($this->arow);$i++)
+         {
+           $tr=($i%2==0)?'<tr class="even">':'<tr class="odd">';
+            echo $tr;
+           echo 
td(HtmlInput::history_card($this->arow[$i]['f_id'],$this->arow[$i]['card_account'].'
 '.$this->arow[$i]['name']));
+           $tot_row=0;
+           for ($x=0;$x<count($this->aheader);$x++)
+             {
+               
$amount=$this->db->get_value($this->sql,array($this->arow[$i]['f_id'],$this->aheader[$x]['po_id']));
+               if ($amount==null)$amount=0;
+               if ( isset($tot_col[$x]))
+                 {
+                   $tot_col[$x]=bcadd($tot_col[$x],$amount);
+                 }
+               else
+                 {
+                   $tot_col[$x]=$amount;
+                 }
+               echo td(nbm($amount),' class="num" ');
+               $tot_row=bcadd($tot_row,$amount);
+             }
+           echo td(nbm($tot_row),' class="num"');
+           $tot_global=bcadd($tot_global,$tot_row);
+           echo '</tr>';
+                   
+
+         }
+       echo '<tr>';
+       echo td('Totaux');
+       for ($i=0;$i<count($this->aheader);$i++)
+         {
+           echo td(nbm($tot_col[$i]),' class="num"');
+         }
+       echo td(nbm($tot_global),' class="num input_text notice" ');
+       echo '</tr>';
+       echo '</table>';
+      }
+    if ( $this->card_poste=='2')
+      {
+       $this->load_poste();
+
+       echo '<table class="result">';
+       echo '<tr>';
+       echo th('poste comptable ');
+       foreach ($this->aheader as $h)
+         {
+           echo '<th style="text-align:right">'.h($h['po_name']).'</th>';
+         }
+       echo th('Total',' style="text-align:right"');
+       echo '</tr>';
+       /*
+        * Show all the result
+        */
+       $tot_global=0;
+       for ($i=0;$i<count($this->arow);$i++)
+         {
+            $tr=($i%2==0)?'<tr class="even">':'<tr class="odd">';
+            echo $tr;
+            echo 
td(HtmlInput::history_account($this->arow[$i]['card_account'],$this->arow[$i]['card_account'].'
 '.$this->arow[$i]['name']));
+           $tot_row=0;
+           for ($x=0;$x<count($this->aheader);$x++)
+             {
+               
$amount=$this->db->get_value($this->sql,array($this->arow[$i]['card_account'],$this->aheader[$x]['po_id']));
+               if ($amount==null)$amount=0;
+               if ( isset($tot_col[$x]))
+                 {
+                   $tot_col[$x]=bcadd($tot_col[$x],$amount);
+                 }
+               else
+                 {
+                   $tot_col[$x]=$amount;
+                 }
+               echo td(nbm($amount),' class="num" ');
+               $tot_row=bcadd($tot_row,$amount);
+             }
+           echo td(nbm($tot_row),' class="num"');
+           $tot_global=bcadd($tot_global,$tot_row);
+           echo '</tr>';
+                   
+
+         }
+       echo '<tr>';
+
+       echo td('Totaux');
+       for ($i=0;$i<count($this->aheader);$i++)
+         {
+           echo td(nbm($tot_col[$i]),' class="num"');
+         }
+       echo td(nbm($tot_global),' class="num input_text notice" ');
+       echo '</tr>';
+       echo '</table>';
+
+      }
+
+  }
+  function export_csv()
+  {
+   bcscale(2);
+   if ( $this->check () != 0 ) {throw new Exception ( "DATE INVALIDE");}
+
+    if ( $this->card_poste=='1')
+      {
+       $this->load_card();
+
+       echo '"Fiche"';
+       foreach ($this->aheader as $h)
+         {
+           echo ';"'.$h['po_name'].'"';
+         }
+       echo ';"Total"';
+       printf("\r\n");
+       /*
+        * Show all the result
+        */
+
+       for ($i=0;$i<count($this->arow);$i++)
+         {
+
+           printf('"%s"',$this->arow[$i]['card_account'].' 
'.$this->arow[$i]['name']);
+           $tot_row=0;
+           for ($x=0;$x<count($this->aheader);$x++)
+             {
+               
$amount=$this->db->get_value($this->sql,array($this->arow[$i]['f_id'],$this->aheader[$x]['po_id']));
+               if ($amount==null)$amount=0;
+               if ( isset($tot_col[$x]))
+                 {
+                   $tot_col[$x]=bcadd($tot_col[$x],$amount);
+                 }
+               else
+                 {
+                   $tot_col[$x]=$amount;
+                 }
+               printf(";%s",nb($amount));
+               $tot_row=bcadd($tot_row,$amount);
+             }
+           printf(";%s",nb($tot_row));
+           printf("\r\n");
+                   
+
+         }
+      }
+    if ( $this->card_poste=='2')
+      {
+       $this->load_poste();
+
+       echo '"Poste"';
+       foreach ($this->aheader as $h)
+         {
+           echo ';"'.$h['po_name'].'"';
+         }
+       echo ';"Total"';
+       printf("\r\n");
+       /*
+        * Show all the result
+        */
+
+       for ($i=0;$i<count($this->arow);$i++)
+         {
+
+           printf('"%s"',$this->arow[$i]['card_account'].' 
'.$this->arow[$i]['name']);
+           $tot_row=0;
+           for ($x=0;$x<count($this->aheader);$x++)
+             {
+               
$amount=$this->db->get_value($this->sql,array($this->arow[$i]['card_account'],$this->aheader[$x]['po_id']));
+               if ($amount==null)$amount=0;
+               if ( isset($tot_col[$x]))
+                 {
+                   $tot_col[$x]=bcadd($tot_col[$x],$amount);
+                 }
+               else
+                 {
+                   $tot_col[$x]=$amount;
+                 }
+               printf(";%s",nb($amount));
+               $tot_row=bcadd($tot_row,$amount);
+             }
+           printf(";%s",nb($tot_row));
+           printf("\r\n");
+                   
+
+         }
+      }
+   
+  }
+
+}
\ No newline at end of file
diff --git a/include/class/class_anticipation.php 
b/include/class/class_anticipation.php
new file mode 100644
index 0000000..2adf7df
--- /dev/null
+++ b/include/class/class_anticipation.php
@@ -0,0 +1,452 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/**
+ * @file
+ * @brief  Manage the anticipation, prediction of sales, expense, bank...
+ *
+ */
+/**
+ address@hidden Manage the anticipation of expense, sales,...
+ address@hidden Forecast Forecast_Cat Forecast_Item
+ *
+ */
+require_once NOALYSS_INCLUDE.'/class/class_forecast.php';
+require_once NOALYSS_INCLUDE.'/class/class_forecast_cat.php';
+require_once NOALYSS_INCLUDE.'/class/class_forecast_item.php';
+require_once NOALYSS_INCLUDE.'/class/class_fiche.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_account_ledger.php';
+require_once NOALYSS_INCLUDE.'/class/class_periode.php';
+require_once NOALYSS_INCLUDE.'/lib/class_impress.php';
+
+class Anticipation
+{
+    /* example private $variable=array("val1"=>1,"val2"=>"Seconde 
valeur","val3"=>0); */
+    private static $variable=array ("id"=>"f_id","name"=>"f_name");
+    private $cn;
+    var $cat; /*!< array of object categorie (forecast_cat)*/
+    var $item; /*< array of object item (forecast_item) */
+    /**
+     * @brief constructor
+     * @param $p_init Database object
+     */
+    function __construct ($p_init,$p_id=0)
+    {
+        $this->cn=$p_init;
+        $this->f_id=$p_id;
+    }
+    public function get_parameter($p_string)
+    {
+        if ( array_key_exists($p_string,self::$variable) )
+        {
+            $idx=self::$variable[$p_string];
+            return $this->$idx;
+        }
+        else
+            throw new Exception("Attribut inexistant $p_string");
+    }
+    public function set_parameter($p_string,$p_value)
+    {
+        if ( array_key_exists($p_string,self::$variable) )
+        {
+            $idx=self::$variable[$p_string];
+            $this->$idx=$p_value;
+        }
+        else
+            throw new Exception("Attribut inexistant $p_string");
+
+
+    }
+    public function get_info()
+    {
+        return var_export(self::$variable,true);
+    }
+    public function verify()
+    {
+        // Verify that the elt we want to add is correct
+        // the f_name must be unique (case insensitive)
+        return 0;
+    }
+    public function save()
+    {
+        /* please adapt */
+        if (  $this->get_parameter("id") == 0 )
+            $this->insert();
+        else
+            $this->update();
+    }
+
+    public function insert()
+    {
+        if ( $this->verify() != 0 ) return;
+    }
+
+    public function update()
+{}
+
+    public function load()
+    {}
+    /**
+     address@hidden Display the result of the forecast
+     address@hidden $p_periode
+     address@hidden HTML String with the code
+     */
+    public function display()
+    {
+               bcscale(4);
+        $forecast=new Forecast($this->cn,$this->f_id);
+        $forecast->load();
+        $str_name=h($forecast->get_parameter('name'));
+
+       $start=$forecast->get_parameter('start_date');
+       $end=$forecast->get_parameter('end_date');
+
+       if ( $start=='') throw new Exception (_('Période de début non 
valable'));
+       if ( $end=='') throw new Exception (_('Période de fin non valable'));
+
+       $per=new Periode($this->cn,$start);
+       $str_start=format_date($per->first_day());
+
+       $per=new Periode($this->cn,$end);
+       $str_end=format_date($per->last_day());
+
+
+        $r="";
+        $aCat=$this->cn->get_array('select fc_id,fc_desc from forecast_cat 
where f_id=$1 order by fc_order',array($this->f_id));
+        $aItem=array();
+        $aReal=array();
+        $poste=new Acc_Account_Ledger($this->cn,0);
+        $fiche=new Fiche($this->cn);
+        $aPeriode=$this->cn->get_array("select p_id,to_char(p_start,'MM.YYYY') 
as myear from parm_periode
+                                        where p_start >= (select p_start from 
parm_periode where p_id=$start)
+                                         and p_end <= (select p_end from 
parm_periode where p_id=$end)
+                                        order by p_start;");
+       $error=array();
+        for($j=0;$j<count($aCat);$j++)
+        {
+            $aItem[$j]=$this->cn->get_array('select 
fi_card,fi_account,fi_text,fi_amount,fi_debit from forecast_item where fc_id=$1 
 and fi_pid=0 order by fi_order ',array($aCat[$j]['fc_id']));
+            $aPerMonth[$j]=$this->cn->get_array('select 
fi_pid,fi_card,fi_account,fi_text,fi_amount,fi_debit from forecast_item where 
fc_id=$1 and fi_pid !=0 order by fi_order ',array($aCat[$j]['fc_id']));
+
+            /* compute the real amount for periode */
+            for($k=0;$k<count($aItem[$j]);$k++)
+            {
+                /* for each periode */
+                for ($l=0;$l<count($aPeriode);$l++)
+                {
+                    if ($aItem[$j][$k]['fi_account']=='')
+                    {
+                        $fiche->id=$aItem[$j][$k]['fi_card'];
+                        $amount=$fiche->get_solde_detail("j_tech_per = 
".$aPeriode[$l]['p_id']);
+                       if ($aItem[$j][$k]['fi_debit']=='C' && 
$amount['debit']>$amount['credit'])  $amount['solde']=$amount["solde"]*(-1);
+                       if ($aItem[$j][$k]['fi_debit']=='D' && 
$amount['debit']<$amount['credit'])  $amount['solde']=$amount["solde"]*(-1);
+
+                    }
+                    else
+                    {
+                        $poste->id=$aItem[$j][$k]['fi_account'];
+                       
$aresult=Impress::parse_formula($this->cn,"OK",$poste->id,$aPeriode[$l]['p_id'],$aPeriode[$l]['p_id']);
+                        $tmp_label=$aresult['desc'];
+                       $amount['solde']=$aresult['montant'];
+
+                       if ( $tmp_label != 'OK') $error[]="<li> 
".$aItem[$j][$k]['fi_text'].$poste->id.'</li>';
+                    }
+                    $aReal[$j][$k][$l]=$amount['solde'];
+                }
+            }
+
+        }
+        ob_start();
+        require_once NOALYSS_INCLUDE.'/template/forecast_result.php';
+        $r.=ob_get_contents();
+        ob_end_clean();
+        return $r;
+    }
+    public static function div()
+    {
+        $r='<div id="div_anti" style="display:none">';
+        $r.= '</div>';
+        return $r;
+    }
+    public function delete()
+    {}
+    /**
+     address@hidden Display a form for modifying the name or/and the category 
of an existing
+     * anticipation
+     address@hidden html string with the form
+     */
+    private function form_cat_mod()
+    {
+        global $g_user;
+        $a=new Forecast($this->cn,$this->f_id);
+        $a->load();
+        $name=new IText('an_name');
+        $name->value=$a->get_parameter("name");
+        $str_name=$name->input();
+        $str_action=_('Modification');
+
+       $start_date=new IPeriod('start_date');
+       $start_date->type=ALL;
+       $start_date->cn=$this->cn;
+       $start_date->show_end_date=false;
+       $start_date->show_start_date=true;
+       $start_date->user=$g_user;
+       $start_date->filter_year=false;
+
+       $end_date=new IPeriod('end_date');
+       $end_date->type=ALL;
+       $end_date->cn=$this->cn;
+       $end_date->show_end_date=true;
+       $end_date->show_start_date=false;
+       $end_date->user=$g_user;
+       $end_date->filter_year=false;
+
+       $start_date->value=$a->f_start_date;
+       $end_date->value=$a->f_end_date;
+
+       $str_start_date=$start_date->input();
+       $str_end_date=$end_date->input();
+
+
+        $r=HtmlInput::hidden('f_id',$this->f_id);
+        $array=Forecast_Cat::load_all($this->cn,$this->f_id);
+
+        for ($i=0;$i<MAX_CAT;$i++)
+        {
+            /* category name */
+            
$name_name=(isset($array[$i]['fc_id']))?'fr_cat'.$array[$i]['fc_id']:'fr_cat_new'.$i;
+            $name=new IText($name_name);
+            $name->value=(isset 
($array[$i]['fc_desc']))?$array[$i]['fc_desc']:'';
+            $aCat[$i]['name']=$name->input();
+
+
+            /* category order */
+            
$order_name=(isset($array[$i]['fc_id']))?'fc_order'.$array[$i]['fc_id']:'fc_order_new'.$i;
+            $order=new IText($order_name);
+            
$order->value=(isset($array[$i]['fc_order']))?$array[$i]['fc_order']:$i+1;
+            $aCat[$i]['order']=$order->input();
+        }
+
+        ob_start();
+        require_once NOALYSS_INCLUDE.'/template/forecast_cat.php';
+        $r.=ob_get_contents();
+        ob_end_clean();
+        return $r;
+    }
+    /**
+     address@hidden Display a form for adding an new anticipation
+     address@hidden html string with the form
+     */
+    private function form_cat_new()
+    {
+     global $g_user;
+      $r="";
+        $str_action=_('Nouveau');
+
+        $name=new IText('an_name');
+        $str_name=$name->input();
+
+       $start_date=new IPeriod('start_date');
+       $start_date->type=ALL;
+       $start_date->cn=$this->cn;
+       $start_date->show_end_date=false;
+       $start_date->show_start_date=true;
+       $start_date->user=$g_user;
+       $start_date->filter_year=false;
+
+       $end_date=new IPeriod('end_date');
+       $end_date->type=ALL;
+       $end_date->cn=$this->cn;
+       $end_date->show_end_date=true;
+       $end_date->show_start_date=false;
+       $end_date->user=$g_user;
+       $end_date->filter_year=false;
+
+       $period=$g_user->get_periode();
+       $per=new Periode($this->cn,$period);
+       $year=$per->get_exercice();
+
+       list($per_start,$per_end)=$per->get_limit($year);
+       $start_date->value=$per_start->p_id;
+       $end_date->value=$per_end->p_id;
+
+       $str_start_date=$start_date->input();
+       $str_end_date=$end_date->input();
+
+        $aLabel=array(_('Ventes'),_('Dépense'),_('Banque'));
+        $aCat=array();
+
+        for ($i=0;$i<MAX_CAT;$i++)
+        {
+            /* category name */
+            $name=new IText('fr_cat'.$i);
+            $name->value=(isset($aLabel[$i]))?$aLabel[$i]:'';
+            $aCat[$i]['name']=$name->input();
+
+
+            /* category order */
+            $order=new IText('fr_order'.$i);
+            $order->value=$i+1;
+            $aCat[$i]['order']=$order->input();
+        }
+
+        ob_start();
+        require_once NOALYSS_INCLUDE.'/template/forecast_cat.php';
+        $r.=ob_get_contents();
+        ob_end_clean();
+        return $r;
+
+    }
+    /**
+     * @brief create an empty object anticipation
+     * @return html string with the form
+     */
+    public  function form_cat()
+    {
+        if ($this->f_id != 0)
+            return $this->form_cat_mod();
+        else
+            return $this->form_cat_new();
+    }
+    /**
+     address@hidden display a form for modifying or add a forecast
+     address@hidden HTML code
+     */
+    public function form_item()
+    {
+        $forecast=new Forecast($this->cn,$this->f_id);
+        $forecast->load();
+        $str_name=$forecast->get_parameter('name');
+        $str_start=$forecast->get_parameter('start_date');
+        $str_end=$forecast->get_parameter('end_date');
+
+
+        $r="";
+        $str_action=_("Elements");
+        $cat=new Forecast_Cat($this->cn);
+        $array=$cat->make_array($this->f_id);
+        $periode=new Periode($this->cn);
+        $aPeriode=$this->cn->make_array("select 
p_id,to_char(p_start,'MM.YYYY') as label from parm_periode
+                                  where p_start >= (select p_start from 
parm_periode where p_id=$str_start)
+                                   and p_end <= (select p_end from 
parm_periode where p_id=$str_end)
+                                  order by p_start");
+        $aPeriode[]=array('value'=>0,'label'=>'Mensuel');
+        $value=$this->cn->get_array("select 
fi_id,fi_text,fi_account,fi_card,fc_id,fi_amount,fi_debit,fi_pid ".
+                                    " from forecast_item ".
+                                    "  where fc_id in (select fc_id from 
forecast_cat where f_id = $1)",array($this->f_id));
+        $max=(count($value) < 
MAX_FORECAST_ITEM)?MAX_FORECAST_ITEM:count($value);
+        $r.=HtmlInput::hidden('nbrow',$max);
+
+        for ($i=0;$i<$max;$i++)
+        {
+            if (isset($value[$i]['fi_id']))
+            {
+                $r.=HtmlInput::hidden('fi_id'.$i,$value[$i]['fi_id']);
+            }
+            /* category*/
+            $category=new ISelect();
+            $category->name='an_cat'.$i;
+            $category->value=$array;
+            
$category->selected=(isset($value[$i]["fc_id"]))?$value[$i]["fc_id"]:-1;
+            $aCat[$i]['cat']=$category->input();
+
+            /* amount   */
+            $amount=new INum('an_cat_amount'.$i);
+            
$amount->value=(isset($value[$i]["fi_amount"]))?$value[$i]["fi_amount"]:0;
+            $aCat[$i]['amount']=$amount->input();
+
+            /* Accounting*/
+            $account=new IPoste('an_cat_acc'.$i);
+            $account->set_attribute('ipopup','ipop_account');
+           //            $account->set_attribute('label','an_label'.$i);
+            $account->set_attribute('account','an_cat_acc'.$i);
+           $account->set_attribute('bracket',1);
+           $account->set_attribute('no_overwrite',1);
+           $account->set_attribute('noquery',1);
+           $account->css_size="85%";
+            
$account->value=(isset($value[$i]["fi_account"]))?$value[$i]["fi_account"]:"";
+            $aCat[$i]['account']=$account->input();
+            /*Quick Code */
+            $qc=new ICard('an_qc'.$i);
+            // If double click call the javascript fill_ipopcard
+            $qc->set_dblclick("fill_ipopcard(this);");
+
+            // This attribute is mandatory, it is the name of the IPopup
+            $qc->set_attribute('ipopup','ipopcard');
+
+            // name of the field to update with the name of the card
+            $qc->set_attribute('label','an_label'.$i);
+
+            // Type of card : all
+            $qc->set_attribute('typecard','all');
+            $qc->set_attribute('jrn',0);
+            $qc->extra='all';
+
+            // when value selected in the autcomplete
+            $qc->set_function('fill_data');
+            if (isset($value[$i]["fi_card"]))
+            {
+                $f=new Fiche($this->cn,$value[$i]["fi_card"]);
+                $qc->value=$f->strAttribut(ATTR_DEF_QUICKCODE);
+                ;
+            }
+
+            $aCat[$i]['qc']=$qc->search().$qc->input();
+            /* Label */
+            $label=new IText('an_label'.$i);
+            
$label->value=(isset($value[$i]["fi_text"]))?$value[$i]["fi_text"]:"";
+            $aCat[$i]['name']=$label->input();
+
+            //Deb or Cred
+            $deb=new ISelect('an_deb'.$i);
+            
$deb->selected=(isset($value[$i]["fi_debit"]))?$value[$i]["fi_debit"]:-1;
+            $deb->value=array(array('value'=>'D','label'=>_('Débit')),
+                              array('value'=>'C','label'=>_('Crédit'))
+                             );
+            $aCat[$i]['deb']=$deb->input();
+            //Periode
+            $isPeriode=new ISelect('month'.$i);
+            $isPeriode->value=$aPeriode;
+            
$isPeriode->selected=(isset($value[$i]["fi_pid"]))?$value[$i]["fi_pid"]:0;
+            $aCat[$i]['per']=$isPeriode->input();
+        }
+        $add_row=new IButton('add_row');
+        $add_row->label=_('Ajouter une ligne');
+        $add_row->javascript='for_add_row(\'fortable\')';
+        $f_add_row=$add_row->input();
+        ob_start();
+        require_once NOALYSS_INCLUDE.'/template/forecast-detail.php';
+        $r.=ob_get_contents();
+        ob_end_clean();
+        return $r;
+    }
+    /**
+     * @brief unit test
+     */
+    static function test_me()
+    {
+        $cn=new Database(dossier::id());
+        $test=new Anticipation($cn);
+
+    }
+
+}
+
+?>
diff --git a/include/class/class_balance_age.php 
b/include/class/class_balance_age.php
new file mode 100644
index 0000000..563bfd0
--- /dev/null
+++ b/include/class/class_balance_age.php
@@ -0,0 +1,240 @@
+<?php
+
+/*
+ * Copyright (C) 2015 Dany De Bontridder <address@hidden>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+require_once NOALYSS_INCLUDE.'/class/class_lettering.php';
+
+/* * *
+ * @file 
+ * @brief compute the ageing balance, currently this code is not used
+ *
+ */
+
+class Balance_Age
+{
+
+    private $cn;
+
+    function __construct($p_cn)
+    {
+        $this->cn=$p_cn;
+        $this->afiche=null;
+    }
+
+    function get_array_card($p_type, $p_extra="")
+    {
+        switch ($p_type)
+        {
+            case 'X':
+                $this->afiche=$this->cn->get_array("
+            with m as (select distinct qp_supplier as f_id from quant_purchase 
union select qs_client from quant_sold)
+            select distinct fiche.f_id as f_id ,f1.ad_value as name, 
f3.ad_value as first_name,f2.ad_value  as quick_code  
+                from fiche 
+                    join m on (fiche.f_id=m.f_id)
+                    join fiche_detail as f1 on (fiche.f_id=f1.f_id and 
f1.ad_id=1) 
+                    join fiche_detail as f2 on (fiche.f_id=f2.f_id and 
f2.ad_id=23) 
+                    left join fiche_detail as f3 on (fiche.f_id=f3.f_id and 
f3.ad_id=32)
+                 where 
+                 fiche.fd_id=$1
+                 order by f1.ad_value
+                 ", array($p_extra));
+                break;
+            case 'U':
+                $fiche=new Fiche($this->cn, $p_extra);
+                $this->afiche[0]['f_id']=$fiche->id;
+                $this->afiche[0]['quick_code']=$fiche->get_quick_code();
+                $this->afiche[0]['name']=$fiche->strAttribut(ATTR_DEF_NAME, 0);
+                
$this->afiche[0]['first_name']=$fiche->strAttribut(ATTR_DEF_FIRST_NAME, 0);
+                break;
+            case 'F':
+                $this->afiche=$this->cn->get_array("
+            select distinct qp_supplier as f_id ,f1.ad_value as name, 
f3.ad_value as first_name,f2.ad_value  as quick_code  
+                from quant_purchase join 
+                    fiche_detail as f1 on (qp_supplier=f1.f_id and f1.ad_id=1) 
+                    join fiche_detail as f2 on (qp_supplier=f2.f_id and 
f2.ad_id=23) 
+                    left join fiche_detail as f3 on (qp_supplier=f3.f_id and 
f3.ad_id=32)
+                 order by f1.ad_value
+                 ");
+                break;
+            case 'C':
+                $this->afiche=$this->cn->get_array("
+             select distinct qs_client as f_id ,f1.ad_value as name, 
f3.ad_value as first_name,f2.ad_value  as quick_code  
+                from quant_sold join 
+                    fiche_detail as f1 on (qs_client=f1.f_id and f1.ad_id=1) 
+                    join fiche_detail as f2 on (qs_client=f2.f_id and 
f2.ad_id=23) 
+                    left join fiche_detail as f3 on (qs_client=f3.f_id and 
f3.ad_id=32)
+                 order by f1.ad_value
+                 ");
+                break;
+            default:
+                throw new Exception('Type invalide');
+        }
+    }
+
+    function display_card($p_date_start, $p_fiche, $p_let)
+    {
+        $this->get_array_card('U', $p_fiche);
+        $a_fiche=$this->afiche;
+        $nb_fiche=count($a_fiche);
+        require 'template/balance_aged_result.php';
+    }
+
+    function display_category($p_date_start, $p_cat, $p_let)
+    {
+        // Get all fiche from Purchase
+
+        $this->get_array_card('X', $p_cat);
+        $a_fiche=$this->afiche;
+        $nb_fiche=count($a_fiche);
+        require 'template/balance_aged_result.php';
+    }
+
+    /**
+     * Display all the operation for the customer
+     * @param type $p_date_start min date  of the operatin
+     * @param type $p_let 'unlet' only unlettered or 'let' for all
+     */
+    function display_purchase($p_date_start, $p_let)
+    {
+        // Get all fiche from Purchase
+        $this->get_array_card('F');
+        $a_fiche=$this->afiche;
+        $nb_fiche=count($a_fiche);
+        require 'template/balance_aged_result.php';
+    }
+
+    /**
+     * Display all the operation for the supplier
+     * @param type $p_date_start min date  of the operatin
+     * @param type $p_let 'unlet' only unlettered or 'let' for all
+     */
+    function display_sale($p_date_start, $p_let)
+    {
+        // Get all fiche from Purchase
+        $this->get_array_card('C');
+        $a_fiche=$this->afiche;
+        $nb_fiche=count($a_fiche);
+        require 'template/balance_aged_result.php';
+    }
+
+    function export_csv($p_date_start, $p_let)
+    {
+        $nb_fiche=count($this->afiche);
+        $title=sprintf('"%s";', _('QuickCode'));
+        $title.=sprintf('"%s";', _('Nom'));
+        $title.=sprintf('"%s";', _('Prénom'));
+        $title.=sprintf('"%s";', _('Date'));
+        $title.=sprintf('"%s";', _('N° pièce'));
+        $title.=sprintf('"%s";', _('Interne'));
+        $title.=sprintf('"%s";', _('Fin'));
+        $title.=sprintf('"%s";', _('<30 jours'));
+        $title.=sprintf('"%s";', _('entre 30 et 60 jours'));
+        $title.=sprintf('"%s";', _('entre 60 et 90 jours'));
+        $title.=sprintf('"%s";', _('> 90 jours'));
+        $title.=sprintf("\n\r");
+        $flag_title=false;
+        for ($i=0; $i<$nb_fiche; $i++)
+        {
+            $card=new Lettering_Card($this->cn, 
$this->afiche[$i]['quick_code']);
+            $card->set_parameter('start', $p_date_start);
+            $card->get_balance_ageing($p_let);
+            if (empty($card->content))
+                continue;
+            if ( ! $flag_title ) { echo $title;$flag_title=true;}
+            $nb_row=count($card->content);
+            $sum_lt_30=0;
+            $sum_gt_30_lt_60=0;
+            $sum_gt_60_lt_90=0;
+            $sum_gt_90=0;
+            $sum_fin=0;
+            for ($j=0; $j<$nb_row; $j++)
+            {
+                $show=true;
+                printf('"%s";', str_replace('"', '', 
$this->afiche[$i]['quick_code']));
+                printf('"%s";', str_replace('"', '', 
$this->afiche[$i]['name']));
+                printf('"%s";', str_replace('"', '', 
$this->afiche[$i]['first_name']));
+                printf('"%s";', $card->content[$j]['j_date_fmt']);
+                printf('"%s";', $card->content[$j]['jr_pj_number']);
+                printf('"%s";', $card->content[$j]['jr_internal']);
+                if 
($card->content[$j]['jrn_def_type']=='FIN'||$card->content[$j]['jrn_def_type']=='ODS')
+                {
+                    printf("%s;", nb($card->content[$j]['j_montant']));
+                    $sum_fin=bcadd($sum_fin, $card->content[$j]['j_montant']);
+                    $show=false;
+                }
+                else
+                {
+                    printf('0;');
+                }
+                if ($show&&$card->content[$j]['day_paid']<=30)
+                {
+                    printf("%s;", nb($card->content[$j]['j_montant']));
+                    $sum_lt_30=bcadd($sum_lt_30, 
$card->content[$j]['j_montant']);
+                    $show=false;
+                }
+                else
+                {
+                    printf('0;');
+                }
+
+                if 
($show&&$card->content[$j]['day_paid']>30&&$card->content[$j]['day_paid']<=60)
+                {
+                    printf("%s;", nb($card->content[$j]['j_montant']));
+                    $sum_gt_30_lt_60=bcadd($sum_gt_30_lt_60, 
$card->content[$j]['j_montant']);
+                }
+                else
+                {
+                    printf('0;');
+                }
+
+                if 
($show&&$card->content[$j]['day_paid']>60&&$card->content[$j]['day_paid']<=90)
+                {
+                    printf("%s;", nb($card->content[$j]['j_montant']));
+                    $sum_gt_60_lt_90=bcadd($sum_gt_60_lt_90, 
$card->content[$j]['j_montant']);
+                }
+                else
+                {
+                    printf('0;');
+                }
+                if ($show&&$card->content[$j]['day_paid']>90)
+                {
+                    printf("%s", nb($card->content[$j]['j_montant']));
+                    $sum_gt_90=bcadd($sum_gt_90, 
$card->content[$j]['j_montant']);
+                }
+                else
+                {
+                    printf('0;');
+                }
+                printf("\n\r");
+            }
+            printf('"%s";', _('Totaux'));
+            printf('"";');
+            printf('"";');
+            printf('"";');
+            printf('"";');
+            printf('"";');
+            printf('%s;', nb($sum_fin));
+            printf('%s;', nb($sum_lt_30));
+            printf('%s;', nb($sum_gt_30_lt_60));
+            printf('%s;', nb($sum_gt_60_lt_90));
+            printf('%s', nb($sum_gt_90));
+            printf("\n\r");
+        }
+    }
+
+}
diff --git a/include/class/class_bank.php b/include/class/class_bank.php
new file mode 100644
index 0000000..8e90ab0
--- /dev/null
+++ b/include/class/class_bank.php
@@ -0,0 +1,58 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+// Copyright Author Dany De Bontridder address@hidden
+require_once NOALYSS_INCLUDE.'/constant.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_parm_code.php';
+
+require_once NOALYSS_INCLUDE.'/class/class_fiche.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_account_ledger.php';
+require_once NOALYSS_INCLUDE.'/lib/user_common.php';
+/*! \file
+ * \brief Derived from class fiche Administration are a specific kind of card
+ *        concerned only by official (or not) administration
+ */
+/*!
+ * \brief  class  admin are a specific kind of card
+ */
+
+// Use the view vw_supplier
+//
+class Bank extends Fiche
+{
+
+    var $name;        /*!< $name name of the company */
+    var $street;      /*!< $street Street */
+    var $country;     /*!< $country Country */
+    var $cp;          /*!< $cp Zip code */
+    var $vat_number;  /*!< $vat_number vat number */
+
+    /*! \brief Constructor
+    /* only a db connection is needed */
+    function __construct($p_cn,$p_id=0)
+    {
+        $this->fiche_def_ref=FICHE_TYPE_FIN;
+        parent::__construct($p_cn,$p_id) ;
+    }
+
+
+
+}
+
+?>
diff --git a/include/class_calendar.php b/include/class/class_calendar.php
similarity index 100%
rename from include/class_calendar.php
rename to include/class/class_calendar.php
diff --git a/include/class/class_contact.php b/include/class/class_contact.php
new file mode 100644
index 0000000..9c70161
--- /dev/null
+++ b/include/class/class_contact.php
@@ -0,0 +1,143 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+// Copyright Author Dany De Bontridder address@hidden
+//!\brief class for the contact, contact are derived from fiche
+require_once NOALYSS_INCLUDE.'/class/class_fiche.php';
+require_once NOALYSS_INCLUDE.'/constant.php';
+require_once NOALYSS_INCLUDE.'/lib/user_common.php';
+/*! \file
+ * \brief Contact are a card which are own by a another card (customer, 
supplier...)
+ */
+/*!
+ * \brief Class contact (customer, supplier...)
+ */
+
+class contact extends Fiche
+{
+    var $company; /*!< $company company of the contact 
(ad_id=ATTR_DEF_COMPANY)*/
+    /*!\brief constructor */
+    function contact($p_cn,$p_id=0)
+    {
+        $this->fiche_def_ref=FICHE_TYPE_CONTACT;
+        parent::__construct($p_cn,$p_id) ;
+        $this->company="";
+    }
+    /*!   Summary
+     **************************************************
+     * \brief  show the default screen
+     *
+     * \param  p_search (filter)
+     *
+     * \return string to display
+     */
+    function Summary($p_search="",$p_action="",$p_sql="",$p_nothing=false)
+    {
+        $p_search=sql_string($p_search);
+        $extra_sql="";
+        if ( $this->company != "")
+        {
+            $extra_sql="and f_id in (select f_id from fiche_detail
+                       where ad_value=upper('".$this->company."') and 
ad_id=".ATTR_DEF_COMPANY.") ";
+        }
+        $url=urlencode($_SERVER['REQUEST_URI']);
+        $script=$_SERVER['PHP_SELF'];
+        // Creation of the nav bar
+        // Get the max numberRow
+        
$all_contact=$this->count_by_modele($this->fiche_def_ref,$p_search,$extra_sql);
+        // Get offset and page variable
+        $offset=( isset ($_REQUEST['offset'] )) ?$_REQUEST['offset']:0;
+        $page=(isset($_REQUEST['page']))?$_REQUEST['page']:1;
+        
$bar=navigation_bar($offset,$all_contact,$_SESSION['g_pagesize'],$page);
+        // set a filter ?
+        $search="";
+        if ( trim($p_search) != "" )
+        {
+            $search=" and f_id in
+                    (select f_id from fiche_Detail
+                    where
+                    ad_id=1 and ad_value ~* '$p_search') ";
+        }
+        // Get The result Array
+        
$step_contact=$this->get_by_category($offset,$search.$extra_sql.$p_sql);
+
+               if ( $all_contact == 0 ) return "";
+        $r=$bar;
+        $r.='<table id="contact_tb" class="sortable">
+            <TR>
+            <th>Quick Code</th>
+            <th>Nom</th>
+            <th>Prénom</th>
+                       <th>Société</th>
+            <th>Téléphone</th>
+            <th>email</th>
+            <th>Fax</th>
+            </TR>';
+        $base=$_SERVER['PHP_SELF'];
+        // Compute the url
+        $url="";
+        $and="?";
+        $get=$_GET;
+        if ( isset ($get) )
+        {
+            foreach ($get as $name=>$value )
+            {
+                // we clean the parameter offset, step, page and size
+                if (  ! in_array($name,array('f_id','detail')))
+                {
+                    $url.=$and.$name."=".$value;
+                    $and="&";
+                }// if
+            }//foreach
+        }// if
+        $back_url=urlencode($_SERVER['REQUEST_URI']);
+        if ( sizeof ($step_contact ) == 0 )
+            return $r;
+        $idx=0;
+        foreach ($step_contact as $contact )
+        {
+            $l_company=new Fiche($this->cn);
+            
$l_company->get_by_qcode($contact->strAttribut(ATTR_DEF_COMPANY),false);
+            $l_company_name=$l_company->strAttribut(ATTR_DEF_NAME);
+            if ( $l_company_name == NOTFOUND ) $l_company_name="";
+            // add popup for detail
+            if ( $l_company_name !="")
+            {
+                               
$l_company_name=HtmlInput::card_detail($contact->strAttribut(ATTR_DEF_COMPANY),$l_company_name,'style="text-decoration:underline;"');
+            }
+            $tr=($idx%2==0)?' <tr class="odd">':'<tr class="even">';
+            $idx++;
+            $r.=$tr;
+            $qcode=$contact->strAttribut(ATTR_DEF_QUICKCODE);
+            $r.='<TD>'.HtmlInput::card_detail($qcode)."</TD>";
+            $r.="<TD>".$contact->strAttribut(ATTR_DEF_NAME)."</TD>";
+            $r.="<TD>".$contact->strAttribut(ATTR_DEF_FIRST_NAME)."</TD>";
+            $r.="<TD>".$l_company_name."</TD>";
+            $r.="<TD>".$contact->strAttribut(ATTR_DEF_TEL)."</TD>";
+            $r.="<TD>".$contact->strAttribut(ATTR_DEF_EMAIL)."</TD>".
+                "<TD> ".$contact->strAttribut(ATTR_DEF_FAX)."</TD>";
+
+            $r.="</TR>";
+
+        }
+        $r.="</TABLE>";
+        $r.=$bar;
+        return $r;
+    }
+
+}
diff --git a/include/class/class_customer.php b/include/class/class_customer.php
new file mode 100644
index 0000000..1c9a49e
--- /dev/null
+++ b/include/class/class_customer.php
@@ -0,0 +1,187 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+// Copyright Author Dany De Bontridder address@hidden
+require_once NOALYSS_INCLUDE.'/constant.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_parm_code.php';
+require_once NOALYSS_INCLUDE.'/class/class_periode.php';
+require_once NOALYSS_INCLUDE.'/class/class_fiche.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_account_ledger.php';
+require_once NOALYSS_INCLUDE.'/lib/user_common.php';
+/*! \file
+ * \brief Derived from class fiche Customer are a specific kind of card
+ */
+/*!
+ * \brief  class  Customer are a specific kind of card
+ */
+
+// Use the view vw_customer
+//
+class Customer extends Fiche
+{
+
+    var $poste;      /*!<  $poste poste comptable */
+    var $name;        /*!<  $name name of the company */
+    var $street;      /*!<  $street Street */
+    var $country;     /*!<  $country Country */
+    var $cp;          /*!<  $cp Zip code */
+    var $vat_number;  /*!<  $vat_number vat number */
+
+    /*! \brief Constructor
+    /* only a db connection is needed */
+    function __construct($p_cn,$p_id=0)
+    {
+        $this->fiche_def_ref=FICHE_TYPE_CLIENT;
+        parent::__construct($p_cn,$p_id) ;
+
+    }
+    /*! \brief  Get all info contains in the view
+     *  thanks to the poste elt (account)
+    */
+    function get_by_account($p_poste=0)
+    {
+        $this->poste=($p_poste==0)?$this->poste:$p_poste;
+        $sql="select * from vw_client where poste_comptable=$1";
+        $Res=$this->cn->exec_sql($sql,array($this->poste));
+        if ( Database::num_row($Res) == 0) return null;
+        if ( Database::num_row($Res) > 1 ) throw new Exception ('Plusieurs 
fiches avec le même poste',1);
+        // There is only _one_ row by customer
+        $row=Database::fetch_array($Res,0);
+        $this->name=$row['name'];
+        $this->id=$row['f_id'];
+        $this->street=$row['rue'];
+        $this->cp=$row['code_postal'];
+        $this->country=$row['pays'];
+        $this->vat_number=$row['tva_num'];
+
+    }
+    /*!
+     * \brief  Get all the info for making a vat listing
+     *           for the vat administration
+     *
+     * \param   $p_year
+     * 
+     * \return  double array structure is 
+     *            ( j_poste,name,vat_number,amount,tva,customer(object)
+     *
+     */
+    function VatListing($p_year)
+    {
+        $cond_sql=" and   A.j_date = B.j_date and extract(year from A.j_date) 
='$p_year'";
+        /* List of customer  */
+        $aCustomer=$this->cn->get_array('select 
f_id,name,quick_code,tva_num,poste_comptable from vw_client '.
+                                        " where tva_num !='' ");
+
+        /* Use the code */
+
+        // BASE ACCOUNT
+        // for belgium
+        $s=new Acc_Parm_Code($this->cn,'VENTE');
+        $s->load();
+        $SOLD=$s->p_value;
+
+        $c=new Acc_Parm_Code($this->cn,'CUSTOMER');
+        $c->load();
+        $CUSTOMER=$c->p_value;
+
+        $t=new Acc_Parm_Code($this->cn,'COMPTE_TVA');
+        $t->load();
+        $TVA=$t->p_value;
+
+        $a_Res=array();
+        /* for each customer compute VAT, Amount...*/
+        foreach ($aCustomer as $l )
+        {
+            // Seek the customer
+            //---
+            $customer=$l['quick_code'];
+            $a_Res[$customer]['name']=$l['name'];
+            $a_Res[$customer]['vat_number']=$l['tva_num'];
+            $a_Res[$customer]['amount']=0;
+            $a_Res[$customer]['tva']=0;
+            $a_Res[$customer]['poste_comptable']=$l['poste_comptable'];
+            /* retrieve only operation of sold and vat */
+            // Get all the sell operation
+            //----
+            $sql="select distinct j_grpt
+                 from
+                 jrnx as A
+                 join jrnx as B using (j_grpt)
+                 where
+                 A.j_qcode = '".$l['quick_code']."' and
+                 B.j_poste::text like '".$SOLD."%'
+                 $cond_sql
+                 ";
+
+            $Res=$this->cn->exec_sql($sql);
+            // Foreach operation
+            // where 7% or tva account are involved
+            // and store the result in an array (a_Res)
+            //---
+
+            for ($i=0; $i < Database::num_row($Res);$i++)
+            {
+                // Get each row
+                //---
+                $row1=Database::fetch_array($Res,$i);
+
+
+                // select the operation
+                //----
+                $Res2=$this->cn->exec_sql("select j_poste,j_montant,j_debit 
from jrnx where j_grpt=".$row1['j_grpt']);
+                $a_row=Database::fetch_all($Res2);
+
+                // Store the amount in the array
+                //---
+                foreach ($a_row as $e)
+                {
+                    $amount=0;
+                    $tva=0;
+                    if ( substr($e['j_poste'],0, strlen($SOLD))===$SOLD)
+                    {
+                        
$amount=($e['j_debit']=='f')?$e['j_montant']:$e['j_montant']*-1;
+                    }
+                    if ( substr($e['j_poste'],0, strlen($TVA))===$TVA)
+                    {
+                        
$tva=($e['j_debit']=='f')?$e['j_montant']:$e['j_montant']*-1;
+                    }
+                    // store sold
+                    //---
+                    
$a_Res[$customer]['amount']=(isset($a_Res[$customer]['amount']))?$a_Res[$customer]['amount']:0;
+                    $a_Res[$customer]['amount']+=$amount;
+
+                    // store vat
+                    //---
+                    
$a_Res[$customer]['tva']=(isset($a_Res[$customer]['tva']))?$a_Res[$customer]['tva']:0;
+                    $a_Res[$customer]['tva']+=$tva;
+
+                    // store customef info
+                    //---
+                    $a_Res[$customer]['customer']=$customer;
+                }
+            }// foreach $a
+        } // foreach ( customer)
+
+        return $a_Res;
+    }
+
+
+}
+
+?>
diff --git a/include/class/class_default_menu.php 
b/include/class/class_default_menu.php
new file mode 100644
index 0000000..7aa595d
--- /dev/null
+++ b/include/class/class_default_menu.php
@@ -0,0 +1,153 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+// Copyright Author Dany De Bontridder address@hidden
+
+/**
+ * Description of class_default_menu
+ *
+ * @author dany
+ */
+require_once NOALYSS_INCLUDE.'/database/class_default_menu_sql.php';
+require_once NOALYSS_INCLUDE.'/lib/class_itext.php';
+
+class Default_Menu
+{
+
+    /**
+     * $a_menu_def is an array of Default_Menu_SQL
+     */
+    private $a_menu_def;
+
+    /**
+     * Possible value
+     */
+    private $code; // array with the valid code
+
+    function __construct()
+    {
+        global $cn;
+        $menu = new Default_Menu_SQL($cn);
+        $ret = $menu->seek();
+        for ($i = 0; $i < Database::num_row($ret); $i++)
+        {
+            $tmenu = $menu->next($ret, $i);
+            $idx = $tmenu->getp('md_code');
+            $this->a_menu_def[$idx] = $tmenu->getp('me_code');
+        }
+        $this->code = explode(',', 'code_follow,code_invoice');
+    }
+
+    function input_value()
+    {
+        $code_invoice = new IText('code_invoice', 
$this->a_menu_def['code_invoice']);
+        $code_follow = new IText('code_follow', 
$this->a_menu_def['code_follow']);
+        echo '<p>' . _('Code pour création facture depuis gestion') . 
$code_invoice->input() . '</p>';
+        echo '<p>' . _('Code pour appel gestion') . $code_follow->input() . 
'</p>';
+    }
+
+    private function check_code($p_string)
+    {
+        global $cn;
+        $count = $cn->get_value('select count(*) from 
v_menu_description_favori where '
+                . 'code = $1', array($p_string));
+        if ($count == 0)
+        {
+            throw new Exception('code_inexistant');
+        }
+    }
+
+    function verify()
+    {
+        foreach ($this->code as $code)
+        {
+            $this->check_code($this->a_menu_def[$code]);
+        }
+    }
+
+    function set($p_string, $p_value)
+    {
+        if (in_array($p_string, $this->code) == false)
+        {
+            throw new Exception("code_invalid");
+        }
+        $this->a_menu_def[$p_string] = $p_value;
+    }
+    function get ($p_string)
+    {
+        return $this->a_menu_def[$p_string];
+    }
+
+    function save()
+    {
+        global $cn;
+        try
+        {
+            $this->verify();
+            foreach ($this->code as $key => $value)
+            {
+                $cn->exec_sql('update menu_default set me_code=$1 where
+                        md_code =$2', array($value,$this->a_menu_def[$value]));
+            }
+        } catch (Exception $e)
+        {
+            $e->getTraceAsString();
+            throw $e;
+        }
+    }
+
+    static function test_me()
+    {
+        global $cn, $g_user, $g_succeed, $g_failed;
+
+        echo h2('Constructor', '');
+        $a = new Default_Menu();
+        echo $g_succeed . 'constructor';
+        if (count($a->a_menu_def) != 2)
+            echo $g_failed;
+        else
+            echo $g_succeed;
+        echo h2("input_value", "");
+        $a->input_value();
+        echo h2('verify');
+        $a->verify();
+        try {
+            echo h2('Verify must failed');
+            $a->set('code_follow', 'MEMNU/MEMEM/');
+            $a->verify();   
+        } catch (Exception $e) {
+            echo $g_succeed. " OK ";
+        }
+        echo h2('Verify must succeed');
+        try {
+            $a->set('code_follow', 'GESTION/FOLLOW');
+            $a->verify();
+            echo $g_succeed. " OK ";
+        } catch (Exception $e)
+        {
+            echo $g_failed."NOK";
+        }
+        echo h2('Save');
+        $a->save();
+        echo h2('GET');
+        echo ( assert($a->get('code_follow')=='GESTION/FOLLOW') 
)?$g_succeed.$a->get('code_follow'):$g_failed.$a->get('code_follow');
+        echo ( assert($a->get('code_invoice')=='COMPTA/VENMENU/VEN') 
)?$g_succeed.$a->get('code_invoice'):$g_failed.$a->get('code_invoice');
+        echo $a->get('code_invoice');
+    }
+
+}
diff --git a/include/class/class_document.php b/include/class/class_document.php
new file mode 100644
index 0000000..f0153d4
--- /dev/null
+++ b/include/class/class_document.php
@@ -0,0 +1,1285 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+// Copyright Author Dany De Bontridder address@hidden
+require_once NOALYSS_INCLUDE.'/class/class_own.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_account_ledger.php';
+require_once NOALYSS_INCLUDE.'/class/class_follow_up.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_tva.php';
+require_once NOALYSS_INCLUDE.'/class/class_user.php';
+require_once NOALYSS_INCLUDE.'/lib/class_zip_extended.php';
+
+/*! \file
+ * \brief Class Document corresponds to the table document
+ */
+/*! \brief Class Document corresponds to the table document
+ */
+class Document
+{
+    var $db;          /*!< $db Database connexion*/
+    var $d_id;        /*!< $d_id Document id */
+    var $ag_id;       /*!< $ag_id action_gestion.ag_id (pk) */
+    var $d_mimetype;  /*!< $d_mimetype  */
+    var $d_filename;  /*!< $d_filename */
+    var $d_lob;       /*!< $d_lob the oid of the lob */
+    var $d_description;       /*!< Description of the file*/
+    var $d_number;    /*!< $d_number number of the document */
+    var $md_id;       /*!< $md_id document's template */
+    /* Constructor
+     * \param $p_cn Database connection
+     */
+    function Document($p_cn,$p_d_id=0)
+    {
+        $this->db=$p_cn;
+        $this->d_id=$p_d_id;
+        $this->counter=0;
+    }
+    /*!\brief insert a minimal document and set the d_id
+     */
+    function blank()
+    {
+        $this->d_id=$this->db->get_next_seq("document_d_id_seq");
+        // affect a number
+        
$this->d_number=$this->db->get_next_seq("seq_doc_type_".$this->md_type);
+        $sql=sprintf('insert into document(d_id,ag_id,d_number) 
values(%d,%d,%d)',
+                     $this->d_id,
+                     $this->ag_id,
+                     $this->d_number);
+        $this->db->exec_sql($sql);
+
+    }
+       function compute_filename($pj,$filename)
+       {
+               foreach (array('/','*','<','>',';',',','\\','.',':') as $i) {
+                       $pj= str_replace($i, "-",$pj);
+               }
+               // save the suffix
+               $pos_prefix=strrpos($filename,".");
+               if ($pos_prefix == 0) $pos_prefix=strlen($filename);
+               $filename_no=substr($filename,0,$pos_prefix);
+               $filename_suff=substr($filename,$pos_prefix,strlen($filename));
+               $new_filename=  strtolower($filename_no."-".$pj.$filename_suff);
+               return $new_filename;
+       }
+    /*!
+     * \brief Generate the document, Call $this-\>Replace to replace
+     *        tag by value
+     address@hidden p_array contains the data normally it is the $_POST
+     address@hidden contains the new filename
+     * \return an array : the url where the generated doc can be found, the 
name
+     * of the file and his mimetype
+     */
+    function Generate($p_array,$p_filename="")
+    {
+        // create a temp directory in /tmp to unpack file and to parse it
+        $dirname=tempnam($_ENV['TMP'],'doc_');
+
+
+        unlink($dirname);
+        mkdir ($dirname);
+        // Retrieve the lob and save it into $dirname
+        $this->db->start();
+        $dm_info="select md_name,md_type,md_lob,md_filename,md_mimetype
+                 from document_modele where md_id=".$this->md_id;
+        $Res=$this->db->exec_sql($dm_info);
+
+        $row=Database::fetch_array($Res,0);
+        $this->d_lob=$row['md_lob'];
+        $this->d_filename=$row['md_filename'];
+        $this->d_mimetype=$row['md_mimetype'];
+        $this->d_name=$row['md_name'];
+
+
+        chdir($dirname);
+        $filename=$row['md_filename'];
+        
$exp=$this->db->lo_export($row['md_lob'],$dirname.DIRECTORY_SEPARATOR.$filename);
+        if ( $exp === false ) echo_warning( __FILE__.":".__LINE__."Export NOK 
$filename");
+
+        $type="n";
+        // if the doc is a OOo, we need to unzip it first
+        // and the name of the file to change is always content.xml
+        if ( strpos($row['md_mimetype'],'vnd.oasis') != 0 )
+        {
+            ob_start();
+           $zip = new Zip_Extended;
+           if ($zip->open($filename) === TRUE) {
+             $zip->extractTo($dirname.DIRECTORY_SEPARATOR);
+             $zip->close();
+           } else {
+             echo __FILE__.":".__LINE__."cannot unzip model ".$filename;
+           }
+
+            // Remove the file we do  not need anymore
+            unlink($filename);
+            ob_end_clean();
+            $file_to_parse="content.xml";
+            $type="OOo";
+        }
+        else
+            $file_to_parse=$filename;
+        // affect a number
+        
$this->d_number=$this->db->get_next_seq("seq_doc_type_".$row['md_type']);
+
+        // parse the document - return the doc number ?
+        $this->ParseDocument($dirname,$file_to_parse,$type,$p_array);
+
+        $this->db->commit();
+        // if the doc is a OOo, we need to re-zip it
+        if ( strpos($row['md_mimetype'],'vnd.oasis') != 0 )
+        {
+            ob_start();
+           $zip = new Zip_Extended;
+            $res = $zip->open($filename, ZipArchive::CREATE);
+            if($res !== TRUE)
+             {
+               throw new Exception ( __FILE__.":".__LINE__."cannot recreate 
zip");
+             }
+           $zip->add_recurse_folder($dirname.DIRECTORY_SEPARATOR);
+           $zip->close();
+
+            ob_end_clean();
+
+            $file_to_parse=$filename;
+        }
+               if ( $p_filename !="") {
+
+                       $this->d_filename=$this->compute_filename($p_filename, 
$this->d_filename);
+               }
+        $this->SaveGenerated($dirname.DIRECTORY_SEPARATOR.$file_to_parse);
+        // Invoice
+        $ret='<A class="mtitle" 
HREF="show_document.php?d_id='.$this->d_id.'&'.dossier::get().'">Document 
g&eacute;n&eacute;r&eacute;</A>';
+        @rmdir($dirname);
+        return $ret;
+    }
+
+    /*! ParseDocument
+     * \brief This function parse a document and replace all
+     *        the predefined tags by a value. This functions
+     *        generate diffent documents (invoice, order, letter)
+     *        with the info from the database
+     *
+     * \param $p_dir directory name
+     * \param $p_file filename
+     * \param $p_type For the OOo document the tag are &lt and &gt instead of 
< and >
+     * \param $p_array variable from $_POST
+     */
+    function ParseDocument($p_dir,$p_file,$p_type,$p_array)
+    {
+
+        /*!\note Replace in the doc the tags by their values.
+         *  - MY_*   table parameter
+         *  - ART_VEN* table quant_sold for invoice
+         *  - CUST_* table quant_sold and fiche for invoice
+         *  - e_* for the invoice in the $_POST
+         */
+        // open the document
+        $infile_name=$p_dir.DIRECTORY_SEPARATOR.$p_file;
+        $h=fopen($infile_name,"r");
+
+        // check if tmpdir exist otherwise create it
+        $temp_dir=$_SERVER["DOCUMENT_ROOT"].DIRECTORY_SEPARATOR.'tmp';
+        if ( is_dir($temp_dir) == false )
+        {
+            if ( mkdir($temp_dir) == false )
+            {
+                $msg=_("Ne peut pas créer le répertoire ".$temp_dir); 
+                throw new Exception($msg);
+            }
+        }
+        // Compute output_name
+        $output_name=tempnam($temp_dir,"gen_doc_");
+        $output_file=fopen($output_name,"w+");
+        // check if the opening is sucessfull
+        if (  $h === false )
+        {
+            echo __FILE__.":".__LINE__."cannot open $p_dir $p_file ";
+            $msg=_("Ne peut pas ouvrir $p_dir $p_file"); 
+            throw new Exception($msg);
+        }
+        if ( $output_file == false)
+        {
+            $msg=_("Ne peut pas ouvrir $p_dir $p_file"); 
+            echo $msg;
+            throw new Exception($msg);
+        }
+        // compute the regex
+        if ( $p_type=='OOo')
+        {
+            
$regex="/=*&lt;&lt;[A-Z]+_*[A-Z]*_*[A-Z]*_*[A-Z]*_*[0-9]*&gt;&gt;/i";
+            $lt="&lt;";
+            $gt="&gt;";
+        }
+        else
+        {
+            $regex="/=*<<[A-Z]+_*[A-Z]*_*[A-Z]*_*[A-Z]*_*[0-9]*>>/i";
+            $lt="<";
+            $gt=">";
+        }
+
+        //read the file
+        while(! feof($h))
+         {
+            // replace the tag
+            $buffer=fgets($h);
+            // search in the buffer the magic << and >>
+            // while preg_match_all finds something to replace
+            while ( preg_match_all ($regex,$buffer,$f) >0  )
+             {
+
+
+                foreach ( $f as $apattern )
+                 {
+
+
+                   foreach($apattern as $pattern)
+                     {
+
+
+                       $to_remove=$pattern;
+                       // we remove the < and > from the pattern
+                       $tag=str_replace($lt,'',$pattern);
+                       $tag=str_replace($gt,'',$tag);
+
+
+                       // if the pattern if found we replace it
+                       $value=$this->Replace($tag,$p_array);
+                       if ( strpos($value,'ERROR') != false )            
$value="";
+                        /*
+                         * Change type of cell to numeric
+                         *  allow numeric cel in ODT for the formatting and 
formula
+                         */
+                       if ( is_numeric($value) && $p_type=='OOo')
+                         {
+                           
$searched='/office:value-type="string"><text:p>'.$pattern.'/';
+                           $replaced='office:value-type="float" 
office:value="'.$value.'"><text:p>'.$pattern;
+                           $buffer=preg_replace($searched, $replaced, 
$buffer,1);
+                         }
+                       // replace into the $buffer
+                       // take the position in the buffer
+                       $pos=strpos($buffer,$to_remove);
+                       // get the length of the string to remove
+                       $len=strlen($to_remove);
+                       if ( $p_type=='OOo' )
+                         {
+                           $value=str_replace('&','&amp;',$value);
+                           $value=str_replace('<','&lt;',$value);
+                           $value=str_replace('>','&gt;',$value);
+                           $value=str_replace('"','&quot;',$value);
+                           $value=str_replace("'",'&apos;',$value);
+                         }
+                       $buffer=substr_replace($buffer,$value,$pos,$len);
+
+                       // if the pattern if found we replace it
+                     }
+                 }
+             }
+            // write into the output_file
+            fwrite($output_file,$buffer);
+
+         }
+        fclose($h);
+        fclose($output_file);
+        if ( ($ret=copy ($output_name,$infile_name)) == FALSE )
+        {
+            echo _('Ne peut pas sauver '.$output_name.' vers '.$infile_name.' 
code d\'erreur ='.$ret);
+        }
+
+
+    }
+    /*! SaveGenerated
+     * \brief Save the generated Document
+     * \param $p_file is the generated file
+     *
+     *
+     * \return 0 if no error otherwise 1
+     */
+    function SaveGenerated($p_file)
+    {
+        // We save the generated file
+        $doc=new Document($this->db);
+        $this->db->start();
+        $this->d_lob=$this->db->lo_import($p_file);
+        if ( $this->d_lob == false )
+        {
+            echo "ne peut pas importer [$p_file]";
+            return 1;
+        }
+
+        $sql="insert into document(ag_id,d_lob,d_number,d_filename,d_mimetype)
+             values ($1,$2,$3,$4,$5)";
+
+        $this->db->exec_sql($sql,      array($this->ag_id,
+                                             $this->d_lob,
+                                             $this->d_number,
+                                             $this->d_filename,
+                                             $this->d_mimetype));
+        $this->d_id=$this->db->get_current_seq("document_d_id_seq");
+        // Clean the file
+        unlink ($p_file);
+        $this->db->commit();
+        return 0;
+    }
+    /*! Upload
+     * \brief Upload a file into document
+     *  all the needed data are in $_FILES we don't increment the seq
+     * \param $p_file : array containing by default $_FILES
+     *
+     * \return
+     */
+    function Upload($p_ag_id)
+    {
+        // nothing to save
+        if ( sizeof($_FILES) == 0 ) return;
+
+        /* for several files  */
+        /* $_FILES is now an array */
+        // Start Transaction
+        $this->db->start();
+        $name=$_FILES['file_upload']['name'];
+        for ($i = 0; $i < sizeof($name);$i++)
+        {
+            $new_name=tempnam($_ENV['TMP'],'doc_');
+            // check if a file is submitted
+            if ( strlen($_FILES['file_upload']['tmp_name'][$i]) != 0 )
+            {
+                // upload the file and move it to temp directory
+                if ( 
move_uploaded_file($_FILES['file_upload']['tmp_name'][$i],$new_name))
+                {
+                    $oid=$this->db->lo_import($new_name);
+                    // check if the lob is in the database
+                    if ( $oid == false )
+                    {
+                        $this->db->rollback();
+                        return 1;
+                    }
+                }
+                // the upload in the database is successfull
+                $this->d_lob=$oid;
+                $this->d_filename=$_FILES['file_upload']['name'][$i];
+                $this->d_mimetype=$_FILES['file_upload']['type'][$i];
+                $this->d_description=  strip_tags($_POST['input_desc'][$i]);
+                // insert into  the table
+                $sql="insert into document (ag_id, 
d_lob,d_filename,d_mimetype,d_number,d_description) values ($1,$2,$3,$4,$5,$6)";
+                
$this->db->exec_sql($sql,array($p_ag_id,$this->d_lob,$this->d_filename,$this->d_mimetype,1,$this->d_description));
+            }
+        } /* end for */
+        $this->db->commit();
+
+    }
+    /**
+     * Copy a existing OID (LOB) into the table document
+     * @note  use of global variable $cn which is the db connx to the current 
folder
+     * @param type $p_ag_id Follow_Up::ag_id
+     * @param type $p_lob oid of existing document
+     * @param type $p_filename filename of existing document
+     * @param type $p_mimetype mimetype of existing document
+     * @param type $p_description Description of existing document (default 
empty)
+     */
+    static function insert_existing_document($p_ag_id, $p_lob, $p_filename, 
$p_mimetype, $p_description = "")
+    {
+        global $cn;
+        // insert into  the table
+        $sql = "insert into document (ag_id, 
d_lob,d_filename,d_mimetype,d_number,d_description) values ($1,$2,$3,$4,$5,$6)";
+        $cn->exec_sql($sql, array($p_ag_id, $p_lob, $p_filename, $p_mimetype, 
1, $p_description));
+    }
+
+    /*! a_ref
+     * \brief create and compute a string for reference the doc <A ...>
+     *
+     * \return a string
+     */
+    function anchor()
+    {
+        if ( $this->d_id == 0 )
+            return '';
+        $image='<IMG SRC="image/insert_table.gif" 
title="'.$this->d_filename.'" border="0">';
+        $r="";
+        $r='<A class="mtitle" 
HREF="show_document.php?d_id='.$this->d_id.'&'.dossier::get().'">'.$image.'</A>';
+        return $r;
+    }
+    /** Get
+     * \brief Send the document
+     */
+    function Send()
+    {
+        // retrieve the template and generate document
+        $this->db->start();
+        $ret=$this->db->exec_sql(
+                 "select d_id,d_lob,d_filename,d_mimetype from document where 
d_id=".$this->d_id );
+        if ( Database::num_row ($ret) == 0 )
+            return;
+        $row=Database::fetch_array($ret,0);
+        //the document  is saved into file $tmp
+        $tmp=tempnam($_ENV['TMP'],'document_');
+        $this->db->lo_export($row['d_lob'],$tmp);
+        $this->d_mimetype=$row['d_mimetype'];
+        $this->d_filename=$row['d_filename'];
+
+        // send it to stdout
+        ini_set('zlib.output_compression','Off');
+        header("Pragma: public");
+        header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
+        header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
+        header("Cache-Control: must-revalidate");
+        header('Content-type: '.$this->d_mimetype);
+        header('Content-Disposition: 
attachment;filename="'.$this->d_filename.'"',FALSE);
+        header("Accept-Ranges: bytes");
+        $file=fopen($tmp,'r');
+        while ( !feof ($file) )
+        {
+            echo fread($file,8192);
+        }
+        fclose($file);
+
+        unlink ($tmp);
+
+        $this->db->commit();
+
+    }
+    /*!\brief get all the document of a given action
+     *\param $ag_id the ag_id from action::ag_id (primary key)
+     *\return an array of objects document or an empty array if nothing found
+     */
+    function get_all($ag_id)
+    {
+        $res=$this->db->get_array('select d_id, ag_id, d_lob, d_number, 
d_filename,'.
+                                  ' d_mimetype,d_description from document 
where ag_id=$1',array($ag_id));
+        $a=array();
+        for ($i=0;$i<sizeof($res); $i++ )
+        {
+            $doc=new Document($this->db);
+            $doc->d_id=$res[$i]['d_id'];
+            $doc->ag_id=$res[$i]['ag_id'];
+            $doc->d_lob=$res[$i]['d_lob'];
+            $doc->d_number=$res[$i]['d_number'];
+            $doc->d_filename=$res[$i]['d_filename'];
+            $doc->d_mimetype=$res[$i]['d_mimetype'];
+            $doc->d_description=$row['d_description'];
+            $a[$i]=clone $doc;
+        }
+        return $a;
+    }
+
+    /*!\brief Get  complete all the data member thx info from the database
+     */
+    function get()
+    {
+        $sql="select * from document where d_id=".$this->d_id;
+        $ret=$this->db->exec_sql($sql);
+        if ( Database::num_row($ret) == 0 )
+            return;
+        $row=Database::fetch_array($ret,0);
+        $this->ag_id=$row['ag_id'];
+        $this->d_mimetype=$row['d_mimetype'];
+        $this->d_filename=$row['d_filename'];
+        $this->d_lob=$row['d_lob'];
+        $this->d_number=$row['d_number'];
+        $this->d_description=$row['d_description'];
+
+    }
+    /*!
+     * \brief replace the TAG by the real value, this value can be into
+     * the database or in $_POST
+     * The possible tags are
+     *  - [CUST_NAME] customer's name
+     *  - [CUST_ADDR_1] customer's address line 1
+     *  - [CUST_CP] customer's ZIP code
+     *  - [CUST_CO] customer's country
+     *  - [CUST_CITY] customer's city
+     *  - [CUST_VAT] customer's VAT
+     *  - [MARCH_NEXT]   end this item and increment the counter $i
+     *  - [DATE_LIMIT]
+     *  - [VEN_ART_NAME]
+     *  - [VEN_ART_PRICE]
+     *  - [VEN_ART_QUANT]
+     *  - [VEN_ART_TVA_CODE]
+     *  - [VEN_ART_STOCK_CODE]
+     *  - [VEN_HTVA]
+     *  - [VEN_TVAC]
+     *  - [VEN_TVA]
+     *  - [TOTAL_VEN_HTVA]
+     *  - [DATE_CALC]
+     *  - [DATE]
+     *  - [DATE_LIMIT]
+     *  - [DATE_LIMIT_CALC]
+     *  - [NUMBER]
+     *  - [MY_NAME]
+     *  - [MY_CP]
+     *  - [MY_COMMUNE]
+     *  - [MY_TVA]
+     *  - [MY_STREET]
+     *  - [MY_NUMBER]
+     *  - [TVA_CODE]
+     *  - [TVA_RATE]
+     *  - [BON_COMMANDE]
+     *  - [OTHER_INFO]
+     *  - [CUST_NUM]
+     *  - [CUST_BANQUE_NAME]
+     *  - [CUST_BANQUE_NO]
+     *  - [USER]
+     *  - [REFERENCE]
+     *  - [BENEF_NAME]
+     *  - [BENEF_BANQUE_NAME]
+     *  - [BENEF_BANQUE_NO]
+     *  - [BENEF_ADDR_1]
+     *  - [BENEF_CP]
+     *  - [BENEF_CO]
+     *  - [BENEF_CITY]
+     *  - [BENEF_VAT]
+     *  - [ACOMPTE]
+     *  - [TITLE]
+     *  - [DESCRIPTION]
+     *
+     * \param $p_tag TAG
+     * \param $p_array data from $_POST
+     * \return String which must replace the tag
+     */
+    function Replace($p_tag,$p_array)
+    {
+               global $g_parameter;
+        $p_tag=strtoupper($p_tag);
+        $p_tag=str_replace('=','',$p_tag);
+        $r="Tag inconnu";
+
+        switch ($p_tag)
+        {
+               case 'DATE':
+                       $r=(isset 
($p_array['ag_timestamp']))?$p_array['ag_timestamp']:$p_array['e_date'];
+                       break;
+        case 'DATE_CALC':
+                $r=' Date inconnue ';
+            // Date are in $p_array['ag_date']
+            // or $p_array['e_date']
+            if ( isset ($p_array['ag_timestamp'])) {
+                
$date=format_date($p_array['ag_timestamp'],'DD.MM.YYYY','YYYY-MM-DD');
+                $r=$date;
+            }
+            if ( isset ($p_array['e_date'])) {
+                
$date=format_date($p_array['e_date'],'DD.MM.YYYY','YYYY-MM-DD');
+                $r=$date;
+            }
+            break;
+            //
+            //  the company priv
+
+        case 'MY_NAME':
+            $r=$g_parameter->MY_NAME;
+            break;
+        case 'MY_CP':
+            $r=$g_parameter->MY_CP;
+            break;
+        case 'MY_COMMUNE':
+            $r=$g_parameter->MY_COMMUNE;
+            break;
+        case 'MY_TVA':
+            $r=$g_parameter->MY_TVA;
+            break;
+        case 'MY_STREET':
+            $r=$g_parameter->MY_STREET;
+            break;
+        case 'MY_NUMBER':
+            $r=$g_parameter->MY_NUMBER;
+            break;
+        case 'MY_TEL':
+            $r=$g_parameter->MY_TEL;
+            break;
+        case 'MY_FAX':
+            $r=$g_parameter->MY_FAX;
+            break;
+        case 'MY_PAYS':
+            $r=$g_parameter->MY_PAYS;
+            break;
+
+            // customer
+            /*\note The CUST_* are retrieved thx the $p_array['tiers']
+             * which contains the quick_code
+             */
+        case 'SOLDE':
+            $tiers=new Fiche($this->db);
+            
$qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
+            $tiers->get_by_qcode($qcode,false);
+            $p=$tiers->strAttribut(ATTR_DEF_ACCOUNT);
+            $poste=new Acc_Account_Ledger($this->db,$p);
+            $r=$poste->get_solde(' true' );
+            break;
+        case 'CUST_NAME':
+            $tiers=new Fiche($this->db);
+            
$qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
+            $tiers->get_by_qcode($qcode,false);
+            $r=$tiers->strAttribut(ATTR_DEF_NAME);
+            break;
+        case 'CUST_ADDR_1':
+            $tiers=new Fiche($this->db);
+            
$qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
+            $tiers->get_by_qcode($qcode,false);
+            $r=$tiers->strAttribut(ATTR_DEF_ADRESS);
+
+            break ;
+        case 'CUST_CP':
+            $tiers=new Fiche($this->db);
+
+            
$qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
+            $tiers->get_by_qcode($qcode,false);
+            $r=$tiers->strAttribut(ATTR_DEF_CP);
+
+            break;
+        case 'CUST_CITY':
+            $tiers=new Fiche($this->db);
+
+            
$qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
+            $tiers->get_by_qcode($qcode,false);
+            $r=$tiers->strAttribut(ATTR_DEF_CITY);
+
+            break;
+
+        case 'CUST_CO':
+            $tiers=new Fiche($this->db);
+
+            
$qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
+            $tiers->get_by_qcode($qcode,false);
+            $r=$tiers->strAttribut(ATTR_DEF_PAYS);
+
+            break;
+            // Marchandise in $p_array['e_march*']
+            // \see user_form_achat.php or user_form_ven.php
+        case 'CUST_VAT':
+            $tiers=new Fiche($this->db);
+
+            
$qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
+            $tiers->get_by_qcode($qcode,false);
+            $r=$tiers->strAttribut(ATTR_DEF_NUMTVA);
+            break;
+        case 'CUST_NUM':
+            $tiers=new Fiche($this->db);
+            
$qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
+            $tiers->get_by_qcode($qcode,false);
+            $r=$tiers->strAttribut(ATTR_DEF_NUMBER_CUSTOMER);
+            break;
+        case 'CUST_BANQUE_NO':
+            $tiers=new Fiche($this->db);
+            
$qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
+            $tiers->get_by_qcode($qcode,false);
+            $r=$tiers->strAttribut(ATTR_DEF_BQ_NO);
+            break;
+        case 'CUST_BANQUE_NAME':
+            $tiers=new Fiche($this->db);
+            
$qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
+            $tiers->get_by_qcode($qcode,false);
+            $r=$tiers->strAttribut(ATTR_DEF_BQ_NAME);
+            break;
+            /* 
--------------------------------------------------------------------------------
 */
+            /* BENEFIT (fee notes */
+        case 'BENEF_NAME':
+            $tiers=new Fiche($this->db);
+            $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
+            if ( $qcode=='')
+            {
+                $r='';
+                break;
+            }
+            $tiers->get_by_qcode($qcode,false);
+            $r=$tiers->strAttribut(ATTR_DEF_NAME);
+            break;
+        case 'BENEF_ADDR_1':
+            $tiers=new Fiche($this->db);
+            $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
+            if ( $qcode=='')
+            {
+                $r='';
+                break;
+            }
+            $tiers->get_by_qcode($qcode,false);
+            $r=$tiers->strAttribut(ATTR_DEF_ADRESS);
+
+            break ;
+        case 'BENEF_CP':
+            $tiers=new Fiche($this->db);
+
+            $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
+            if ( $qcode=='')
+            {
+                $r='';
+                break;
+            }
+            $tiers->get_by_qcode($qcode,false);
+            $r=$tiers->strAttribut(ATTR_DEF_CP);
+
+            break;
+        case 'BENEF_CITY':
+            $tiers=new Fiche($this->db);
+
+            $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
+            if ( $qcode=='')
+            {
+                $r='';
+                break;
+            }
+            $tiers->get_by_qcode($qcode,false);
+            $r=$tiers->strAttribut(ATTR_DEF_CITY);
+
+            break;
+
+        case 'BENEF_CO':
+            $tiers=new Fiche($this->db);
+
+            $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
+            if ( $qcode=='')
+            {
+                $r='';
+                break;
+            }
+            $tiers->get_by_qcode($qcode,false);
+            $r=$tiers->strAttribut(ATTR_DEF_PAYS);
+
+            break;
+            // Marchandise in $p_array['e_march*']
+            // \see user_form_achat.php or user_form_ven.php
+        case 'BENEF_VAT':
+            $tiers=new Fiche($this->db);
+
+            $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
+            if ( $qcode=='')
+            {
+                $r='';
+                break;
+            }
+            $tiers->get_by_qcode($qcode,false);
+            $r=$tiers->strAttribut(ATTR_DEF_NUMTVA);
+            break;
+        case 'BENEF_NUM':
+            $tiers=new Fiche($this->db);
+            $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
+            if ( $qcode=='')
+            {
+                $r='';
+                break;
+            }
+            $tiers->get_by_qcode($qcode,false);
+            $r=$tiers->strAttribut(ATTR_DEF_NUMBER_CUSTOMER);
+            break;
+        case 'BENEF_BANQUE_NO':
+            $tiers=new Fiche($this->db);
+            $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
+            if ( $qcode=='')
+            {
+                $r='';
+                break;
+            }
+            $tiers->get_by_qcode($qcode,false);
+            $r=$tiers->strAttribut(ATTR_DEF_BQ_NO);
+            break;
+        case 'BENEF_BANQUE_NAME':
+            $tiers=new Fiche($this->db);
+            $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
+            if ( $qcode=='')
+            {
+                $r='';
+                break;
+            }
+            $tiers->get_by_qcode($qcode,false);
+            $r=$tiers->strAttribut(ATTR_DEF_BQ_NAME);
+            break;
+
+            // Marchandise in $p_array['e_march*']
+            // \see user_form_achat.php or user_form_ven.php
+        case 'NUMBER':
+            $r=$this->d_number;
+            break;
+
+        case 'USER' :
+            return $_SESSION['use_name'].', '.$_SESSION['use_first_name'];
+
+            break;
+        case 'REFERENCE':
+            $act=new Follow_Up($this->db);
+            $act->ag_id=$this->ag_id;
+            $act->get();
+            $r=$act->ag_ref;
+            break;
+
+            /*
+             *  - [VEN_ART_NAME]
+             *  - [VEN_ART_PRICE]
+             *  - [VEN_ART_QUANT]
+             *  - [VEN_ART_TVA_CODE]
+             *  - [VEN_ART_STOCK_CODE]
+             *  - [VEN_HTVA]
+             *  - [VEN_TVAC]
+             *  - [VEN_TVA]
+             *  - [TOTAL_VEN_HTVA]
+             *  - [DATE_LIMIT]
+             */
+        case 'DATE_LIMIT_CALC':
+            extract ($p_array);
+            $id='e_ech' ;
+            if ( !isset (${$id}) ) return "";
+            $r=format_date(${$id},'DD.MM.YYYY','YYYY-MM-DD');
+            break;
+      case 'DATE_LIMIT':
+            extract ($p_array);
+            $id='e_ech' ;
+            if ( !isset (${$id}) ) return "";
+            $r=${$id};
+            break;
+        case 'MARCH_NEXT':
+            $this->counter++;
+            $r='';
+            break;
+
+        case 'VEN_ART_NAME':
+            extract ($p_array);
+            $id='e_march'.$this->counter;
+            // check if the march exists
+            if ( ! isset (${$id})) return "";
+            // check that something is sold
+            if ( ${'e_march'.$this->counter.'_price'} != 0 && 
${'e_quant'.$this->counter} != 0 )
+            {
+                $f=new Fiche($this->db);
+                $f->get_by_qcode(${$id},false);
+                $r=$f->strAttribut(ATTR_DEF_NAME);
+            }
+            else $r = "";
+            break;
+       case 'VEN_ART_LABEL':
+            extract ($p_array);
+            $id='e_march'.$this->counter."_label";
+            // check if the march exists
+
+            if (! isset (${$id}) || (isset (${$id}) && strlen(trim(${$id})) == 
0))
+                {
+                    $id = 'e_march' . $this->counter;
+                    // check if the march exists
+                    if (!isset(${$id}))
+                        $r= "";
+                    else 
+                    {
+                    // check that something is sold
+                        if (${'e_march' . $this->counter . '_price'} != 0 && 
${'e_quant' . $this->counter} != 0)
+                        {
+                            $f = new Fiche($this->db);
+                            $f->get_by_qcode(${$id}, false);
+                            $r = $f->strAttribut(ATTR_DEF_NAME);
+                        } else
+                            $r = "";
+                    }
+                }
+                else
+                    $r=${'e_march'.$this->counter.'_label'};
+            break;
+        case 'VEN_ART_STOCK_CODE':
+            extract ($p_array);
+                    $id = 'e_march' . $this->counter;
+                    // check if the march exists
+                    if (!isset(${$id}))
+                        $r= "";
+                    else 
+                    {
+                    // check that something is sold
+                        if (${'e_march' . $this->counter . '_price'} != 0 && 
${'e_quant' . $this->counter} != 0)
+                        {
+                            $f = new Fiche($this->db);
+                            $f->get_by_qcode(${$id}, false);
+                            $r = $f->strAttribut(ATTR_DEF_STOCK);
+                            $r=($r == NOTFOUND)?'':$r;
+                        } 
+                    }
+            break;
+        case 'VEN_ART_PRICE':
+            extract ($p_array);
+            $id='e_march'.$this->counter.'_price' ;
+            if ( !isset (${$id}) ) return "";
+                       if (${$id} == 0 ) return "";
+            $r=${$id};
+            break;
+
+        case 'TVA_RATE':
+        case 'VEN_ART_TVA_RATE':
+            extract ($p_array);
+            $id='e_march'.$this->counter.'_tva_id';
+            if ( !isset (${$id}) ) return "";
+            if ( ${$id} == -1 || ${$id}=='' ) return "";
+            $march_id='e_march'.$this->counter.'_price' ;
+            if ( ! isset (${$march_id})) return '';
+            $tva=new Acc_Tva($this->db);
+            $tva->set_parameter("id",${$id});
+            if ( $tva->load() == -1) return '';
+            return $tva->get_parameter("rate");
+            break;
+
+        case 'TVA_CODE':
+        case 'VEN_ART_TVA_CODE':
+            extract ($p_array);
+            $id='e_march'.$this->counter.'_tva_id';
+            if ( !isset (${$id}) ) return "";
+            if ( ${$id} == -1 ) return "";
+            $qt='e_quant'.$this->counter;
+            $price='e_march'.$this->counter.'_price' ;
+            if ( ${$price} == 0 || ${$qt} == 0
+                    || strlen(trim( $price )) ==0
+                    || strlen(trim($qt)) ==0)
+                return "";
+
+            $r=${$id};
+            break;
+
+        case 'TVA_LABEL':
+            extract ($p_array);
+            $id='e_march'.$this->counter.'_tva_id';
+            if ( !isset (${$id}) ) return "";
+            $march_id='e_march'.$this->counter.'_price' ;
+            if ( ! isset (${$march_id})) return '';
+            if ( ${$march_id} == 0) return '';
+            $tva=new Acc_Tva($this->db,${$id});
+            if ($tva->load() == -1 ) return "";
+            $r=$tva->get_parameter('label');
+
+            break;
+
+            /* total VAT for one sold */
+        case 'TVA_AMOUNT':
+        case 'VEN_TVA':
+            extract ($p_array);
+            $qt='e_quant'.$this->counter;
+            $price='e_march'.$this->counter.'_price' ;
+            $tva='e_march'.$this->counter.'_tva_id';
+            /* if we do not use vat this var. is not set */
+            if ( !isset(${$tva}) ) return '';
+            if ( !isset (${'e_march'.$this->counter}) ) return "";
+            // check that something is sold
+            if ( ${$price} == 0 || ${$qt} == 0
+                    || strlen(trim( $price )) ==0
+                    || strlen(trim($qt)) ==0)
+                return "";
+            $r=${'e_march'.$this->counter.'_tva_amount'};
+            break;
+            /* TVA automatically computed */
+        case 'VEN_ART_TVA':
+        
+            extract ($p_array);
+            $qt='e_quant'.$this->counter;
+            $price='e_march'.$this->counter.'_price' ;
+            $tva='e_march'.$this->counter.'_tva_id';
+            if ( !isset (${'e_march'.$this->counter}) ) return "";
+            // check that something is sold
+            if ( ${$price} == 0 || ${$qt} == 0
+                    || strlen(trim( $price )) ==0
+                    || strlen(trim($qt)) ==0)
+                return "";
+            $oTva=new Acc_Tva($this->db,${$tva});
+            if ($oTva->load() == -1 ) return "";
+            $r=round(${$price},2)*$oTva->get_parameter('rate');
+            $r=round($r,2);
+            break;
+
+        case 'VEN_ART_TVAC':
+            extract ($p_array);
+            $qt='e_quant'.$this->counter;
+            $price='e_march'.$this->counter.'_price' ;
+            $tva='e_march'.$this->counter.'_tva_id';
+            if ( !isset (${'e_march'.$this->counter}) ) return "";
+            // check that something is sold
+            if ( ${$price} == 0 || ${$qt} == 0
+                    || strlen(trim( $price )) ==0
+                    || strlen(trim($qt)) ==0)
+                return "";
+            if ( ! isset (${$tva}) ) return '';
+            $tva=new Acc_Tva($this->db,${$tva});
+            if ($tva->load() == -1 )
+            {
+                $r=round(${$price},2);
+            }
+            else
+            {
+                $r=round(${$price}*$tva->get_parameter('rate')+${$price},2);
+            }
+
+            break;
+
+        case 'VEN_ART_QUANT':
+            extract ($p_array);
+            $id='e_quant'.$this->counter;
+            if ( !isset (${$id}) ) return "";
+            // check that something is sold
+            if ( ${'e_march'.$this->counter.'_price'} == 0
+                    || ${'e_quant'.$this->counter} == 0
+                    || strlen(trim( ${'e_march'.$this->counter.'_price'} )) ==0
+                    || strlen(trim(${'e_quant'.$this->counter})) ==0 )
+                return "";
+            $r=${$id};
+            break;
+
+        case 'VEN_HTVA':
+            extract ($p_array);
+            $id='e_march'.$this->counter.'_price' ;
+            $quant='e_quant'.$this->counter;
+            if ( !isset (${$id}) ) return "";
+
+            // check that something is sold
+            if ( ${'e_march'.$this->counter.'_price'} == 0 || 
${'e_quant'.$this->counter} == 0
+                    || strlen(trim( ${'e_march'.$this->counter.'_price'} )) ==0
+                    || strlen(trim(${'e_quant'.$this->counter})) ==0)
+                return "";
+                       bcscale(4);
+            $r=bcmul(${$id},${$quant});
+                       $r=round($r,2);
+            break;
+
+        case 'VEN_TVAC':
+            extract ($p_array);
+            $id='e_march'.$this->counter.'_tva_amount' ;
+            $price='e_march'.$this->counter.'_price' ;
+            $quant='e_quant'.$this->counter;
+            if ( ! isset(${'e_march'.$this->counter.'_price'})|| 
!isset(${'e_quant'.$this->counter}))     return "";
+            // check that something is sold
+            if ( ${'e_march'.$this->counter.'_price'} == 0 || 
${'e_quant'.$this->counter} == 0 ) return "";
+                       bcscale(4);
+            // if TVA not exist
+            if ( ! isset(${$id}))
+                $r=  bcmul(${$price},${$quant});
+            else{
+                $r=  bcmul(${$price},${$quant});
+                $r=bcadd($r,${$id});
+                       }
+                       $r=round($r,2);
+                       return $r;
+            break;
+
+        case 'TOTAL_VEN_HTVA':
+            extract($p_array);
+                       bcscale(4);
+            $sum=0.0;
+            for ($i=0;$i<$nb_item;$i++)
+            {
+                $sell='e_march'.$i.'_price';
+                $qt='e_quant'.$i;
+
+                if ( ! isset (${$sell}) ) break;
+
+                if ( strlen(trim(${$sell})) == 0 ||
+                        strlen(trim(${$qt})) == 0 ||
+                        ${$qt}==0 || ${$sell}==0)
+                    continue;
+                $tmp1=bcmul(${$sell},${$qt});
+                $sum=bcadd($sum,$tmp1);
+
+
+            }
+            $r=round($sum,2);
+            break;
+        case 'TOTAL_VEN_TVAC':
+            extract($p_array);
+            $sum=0.0;
+                       bcscale(4);
+            for ($i=0;$i<$nb_item;$i++)
+            {
+                $tva='e_march'.$i.'_tva_amount';
+                $tva_amount=0;
+                /* if we do not use vat this var. is not set */
+                if ( isset(${$tva}) )
+                {
+                    $tva_amount=${$tva};
+                }
+                $sell=${'e_march'.$i.'_price'};
+                $qt=${'e_quant'.$i};
+                               $tot=bcmul($sell,$qt);
+                               $tot=bcadd($tot,$tva_amount);
+                               $sum=bcadd($sum,$tot);
+            }
+            $r=round($sum,2);
+
+            break;
+        case 'TOTAL_TVA':
+            extract($p_array);
+            $sum=0.0;
+            for ($i=0;$i<$nb_item;$i++)
+            {
+                $tva='e_march'.$i.'_tva_amount';
+                if (! isset(${$tva})) $tva_amount=0.0;
+                else $tva_amount=$
+                                     {
+                                         $tva
+                                     };
+                $sum+=$tva_amount;
+                $sum=round($sum,2);
+            }
+            $r=$sum;
+
+            break;
+        case 'BON_COMMANDE':
+            if ( isset($p_array['bon_comm']))
+                return $p_array['bon_comm'];
+            else
+                return "";
+            break;
+        case 'PJ':
+            if ( isset($p_array['e_pj']))
+                return $p_array['e_pj'];
+            else
+                return "";
+
+        case 'OTHER_INFO':
+            if ( isset($p_array['other_info']))
+                return $p_array['other_info'];
+            else
+                return "";
+            break;
+        case 'COMMENT':
+            if ( isset($p_array['e_comm']))
+                return $p_array['e_comm'];
+            break;
+        case 'ACOMPTE':
+            if ( isset($p_array['acompte']))
+                return $p_array['acompte'];
+                       return "0";
+            break;
+        case 'STOCK_NAME':
+                if ( ! isset ($p_array['repo'])) return "";
+                $ret=$this->db->get_value('select r_name from 
public.stock_repository where r_id=$1',array($p_array['repo']));
+                return $ret;
+        case 'STOCK_ADRESS':
+                if ( ! isset ($p_array['repo'])) return "";
+                $ret=$this->db->get_value('select r_adress from 
public.stock_repository where r_id=$1',array($p_array['repo']));
+                return $ret;
+        case 'STOCK_COUNTRY':
+                if ( ! isset ($p_array['repo'])) return "";
+                $ret=$this->db->get_value('select r_country from 
public.stock_repository where r_id=$1',array($p_array['repo']));
+                return $ret;
+        case 'STOCK_CITY':
+                if ( ! isset ($p_array['repo'])) return "";
+                $ret=$this->db->get_value('select r_city from 
public.stock_repository where r_id=$1',array($p_array['repo']));
+                return $ret;
+        case 'STOCK_PHONE':
+                if ( ! isset ($p_array['repo'])) return "";
+                $ret=$this->db->get_value('select r_phone from 
public.stock_repository where r_id=$1',array($p_array['repo']));
+                return $ret;
+        case 'TITLE':
+            $title=HtmlInput::default_value_request("ag_title", "");
+            return $title;
+
+               }
+        /*
+         * retrieve the value of ATTR for e_march
+         */
+        if (preg_match('/^ATTR/', $p_tag) == 1)
+        {
+            // Retrieve f_id
+            if ( isset ($p_array['e_march'.$this->counter]))
+            {
+                $id = $p_array['e_march' . $this->counter];
+                $r=$this->replace_special_tag($id,$p_tag);
+            }
+        }
+        /*
+         * retrieve the value of ATTR for e_march
+         */
+        if (preg_match('/^BENEFATTR/', $p_tag) == 1)
+        {
+            $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
+            // Retrieve f_id
+             $r=$this->replace_special_tag($qcode,$p_tag);
+        }
+        if (preg_match('/^CUSTATTR/', $p_tag) == 1)
+        {
+            if ( isset($p_array['qcode_dest']) || isset($p_array['e_client']) )
+            {
+                
$qcode=(isset($p_array['qcode_dest']))?$p_array['qcode_dest']:$p_array['e_client'];
+                $r=$this->replace_special_tag($qcode,$p_tag);
+            }
+        }
+        return $r;
+    }
+    /*!\brief remove a row from the table document, the lob object is not 
deleted
+     *        because can be linked elsewhere
+     */
+    function remove()
+    {
+      $d_lob=$this->db->get_value('select d_lob from document where d_id=$1',
+                                 array($this->d_id));
+        $sql='delete from document where d_id='.$this->d_id;
+        $this->db->exec_sql($sql);
+        if ( $d_lob != 0 )
+            $this->db->lo_unlink($d_lob);
+    }
+    /*!\brief Move a document from the table document into the concerned row
+     *        the document is not copied : it is only a link
+     *
+     * \param $p_internal internal code
+     *
+     */
+    function MoveDocumentPj($p_internal)
+    {
+        $sql="update jrn set jr_pj=$1,jr_pj_name=$2,jr_pj_type=$3 where 
jr_internal=$4";
+
+        
$this->db->exec_sql($sql,array($this->d_lob,$this->d_filename,$this->d_mimetype,$p_internal));
+        // clean the table document
+        $sql='delete from document where d_id='.$this->d_id;
+        $this->db->exec_sql($sql);
+
+
+    }
+    /**
+     *Replace a special tag *TAGxxxx with the value from fiche_detail, the xxxx
+     * is the ad_value
+     * @param $p_qcode qcode of the card
+     * @param $p_tag tag to parse
+     * @return  the ad_value contained in fiche_detail or for the type 
"select" the
+     *          label
+     */
+    function replace_special_tag($p_qcode, $p_tag)
+    {
+        // check if the march exists
+        if ($p_qcode == "")
+            return "";
+
+        $f = new Fiche($this->db);
+        $found = $f->get_by_qcode($p_qcode, false);
+        // if not found exit
+        if ($found == 1)
+            return "";
+
+        // get the ad_id
+        $attr=preg_replace("/^.*ATTR/","",$p_tag);
+
+        if (isNumber($attr) == 0) return "";
+        $ad_type=$this->db->get_value("select ad_type from attr_def where 
ad_id=$1",array($attr));
+
+        // get ad_value
+        $ad_value=$this->db->get_value("select ad_value from fiche_detail 
where f_id=$1 and ad_id=$2",array($f->id,$attr));
+
+        // if ad_id is type select execute select and get value
+        if ( $ad_type=="select")
+        {
+            $sql=$this->db->get_value("select ad_extra from attr_def where 
ad_id=$1",array($attr));
+            $array= $this->db->make_array($sql);
+            for ($a=0;$a<count ($array);$a++)
+            {
+                if ($array[$a]['value']==$ad_value)
+                    return $array[$a]['label'];
+            }
+            
+        }
+        // if ad_id is not type select get value
+        return $ad_value;
+    }
+    function update_description ($p_desc)
+    {
+        $this->db->exec_sql('update document set d_description = $1 where 
d_id=$2',
+                array($p_desc,$this->d_id));
+    }
+
+}
diff --git a/include/class_document_export.php 
b/include/class/class_document_export.php
similarity index 100%
rename from include/class_document_export.php
rename to include/class/class_document_export.php
diff --git a/include/class/class_document_modele.php 
b/include/class/class_document_modele.php
new file mode 100644
index 0000000..85c6ae5
--- /dev/null
+++ b/include/class/class_document_modele.php
@@ -0,0 +1,364 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+// Copyright Author Dany De Bontridder address@hidden
+/*! \file
+ * \brief Class for the document template
+ */
+/*!
+ * \brief Class for the document template
+ */
+require_once NOALYSS_INCLUDE.'/lib/class_icheckbox.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ihidden.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ifile.php';
+class Document_modele
+{
+    var $cn;           /*!< $cn  database connection */
+    var $md_id;                /*!< $md_id pk */
+    var $md_name;         /*!< $md_name template's name */
+    var $md_type;         /*!< $md_type template's type (letter, invoice, 
order...) */
+    var $md_lob;          /*!< $md_lob Document file */
+    var $md_sequence;     /*!<  $md_sequence sequence name (autogenerate) */
+    var $sequence;        /*!< $sequence sequence number used by the create 
sequence start with */
+    var $md_affect;    /*!< $md_affect if you can use it in VEN for sale, ACH 
for purchase or GES for follow-up */
+    //Constructor parameter = database connexion
+    function Document_modele($p_cn,$p_id=-1)
+    {
+        $this->cn=$p_cn;
+        $this->md_id=$p_id;
+    }
+
+    /*!
+     **************************************************
+     * \brief : show all the stored document_modele.
+     *        return a string containing all the data
+     *        separate by TD & TR tag
+     * \return table in HTML Code
+     */
+    function myList()
+    {
+        $s=dossier::get();
+        $sql="select md_id,md_name,md_affect,dt_value from document_modele 
join document_type on(dt_id=md_type) order by md_name";
+        $Res=$this->cn->exec_sql($sql);
+        $all=Database::fetch_all($Res);
+       $r='';
+        if ( Database::num_row($Res) != 0 ) {
+
+         $r.='<p><form method="post">';
+         $r.=dossier::hidden();
+         $r.="<table>";
+         $r.="<tr> ";
+         $r.=th(_('Nom'));
+         $r.=th(_('Catégorie'));
+         $r.=th(_('Affect.'));
+         $r.=th(_('Fichier'));
+         $r.=th(_('Effacer'));
+         $r.="</tr>";
+         foreach ( $all as $row)
+           {
+             $r.="<tr>";
+             $r.="<td>";
+             $r.=h($row['md_name']);
+             $r.="</td>";
+             $r.="<td>";
+             $r.=$row['dt_value'];
+             $r.="</td>";
+             $r.=td(h($row['md_affect']));
+             $r.="<td>";
+             $r.='<A 
HREF="show_document_modele.php?md_id='.$row['md_id'].'&'.$s.'">Document</a>';
+             $r.="</td>";
+             $r.="<TD>";
+             $c=new ICheckBox();
+             $c->name="dm_remove_".$row['md_id'];
+             $r.=$c->input();
+             $r.="</td>";
+             
$r.=td(HtmlInput::detail_modele_document($row['md_id'],'Modifier'));
+
+             $r.="</tr>";
+           }
+         $r.="</table>";
+
+         // need hidden parameter for subaction
+         $a=new IHidden();
+         $a->name="sa";
+         $a->value="rm_template";
+         $r.=$a->input();
+         $r.=HtmlInput::submit("rm_template","Effacer la sélection");
+       }
+       $b=new IButton('show');
+       $b->label="Ajout d'un document";
+       $b->javascript="$('add_modele').style.display='block';new 
Draggable('add_modele',{starteffect:function(){
+                      new 
Effect.Highlight(obj.id,{scroll:window,queue:'end'});}});";
+               $r.=$b->input();
+        $r.="</form></p>";
+        return $r;
+    }
+    /*!
+     * \brief :  Save a document_modele in the database,
+     *       if the document_modele doesn't exist yet it will be
+     *       first created (-> insert into document_modele)
+     *       in that case the name and the type must be set
+     *       set before calling Save, the name will be modified
+     *       with sql_string
+     *
+     */
+    function Save()
+    {
+        // if name is empty return immediately
+        if ( trim(strlen($this->md_name))==0)
+            return;
+        try
+        {
+            // Start transaction
+            $this->cn->start();
+            // Save data into the table document_modele
+            // if $this->md_id == -1 it means it is a new document model
+            // so first we have to insert it
+            // the name and the type must be set before calling save
+            if ( $this->md_id == -1)
+            {
+
+                // insert into the table document_modele
+                
$this->md_id=$this->cn->get_next_seq('document_modele_md_id_seq');
+                $sql="insert into 
document_modele(md_id,md_name,md_type,md_affect)
+                     values ($1,$2,$3,$4)";
+
+                
$Ret=$this->cn->exec_sql($sql,array($this->md_id,$this->md_name,$this->md_type,$this->md_affect));
+                // create the sequence for this modele of document
+                
$this->md_sequence="document_".$this->cn->get_next_seq("document_seq");
+                // if start is not equal to 0 and he's a number than the user
+                // request a number change
+
+                if ( $this->start != 0 && isNumber($this->start) == 1 )
+                {
+                    $sql="alter sequence seq_doc_type_".$this->md_type." 
restart ".$this->start;
+                    $this->cn->exec_sql($sql);
+                }
+
+            }
+            // Save the file
+            $new_name=tempnam($_ENV['TMP'],'document_');
+            if ( strlen ($_FILES['doc']['tmp_name']) != 0 )
+            {
+                if (move_uploaded_file($_FILES['doc']['tmp_name'],
+                                       $new_name))
+                {
+                    // echo "Image saved";
+                    $oid= $this->cn->lo_import($new_name);
+                    if ( $oid == false )
+                    {
+                        
echo_error('class/class_document_modele.php',__LINE__,"cannot upload document");
+                        $this->cn->rollback();
+                        return;
+                    }
+                    // Remove old document
+                    $ret=$this->cn->exec_sql("select md_lob from 
document_modele where md_id=".$this->md_id);
+                    if (Database::num_row($ret) != 0)
+                    {
+                        $r=Database::fetch_array($ret,0);
+                        $old_oid=$r['md_lob'];
+                        if (strlen($old_oid) != 0)
+                            $this->cn->lo_unlink($old_oid);
+                    }
+                    // Load new document
+                    $this->cn->exec_sql("update document_modele set 
md_lob=".$oid.", md_mimetype='".$_FILES['doc']['type']."' 
,md_filename='".$_FILES['doc']['name']."' where md_id=".$this->md_id);
+                    $this->cn->commit();
+                }
+                else
+                {
+                    echo "<H1>Error</H1>";
+                    $this->cn->rollback();
+                   throw new Exception("Erreur".__FILE__.__LINE__);
+                }
+            }
+        }
+        catch (Exception $e)
+        {
+            rollback($this->cn);
+            return ;
+        }
+    }
+    /*!
+     * \brief Remove a template
+     * \return nothing
+     */
+    function Delete()
+    {
+        $this->cn->start();
+        // first we unlink the document
+        $sql="select md_lob from document_modele where md_id=".$this->md_id;
+        $res=$this->cn->exec_sql($sql);
+        $r=Database::fetch_array($res,0);
+        // if a lob is found
+        if ( strlen ($r['md_lob']) &&
+                $this->cn->exist_blob($r['md_lob']) )
+        {
+            // we remove it first
+            $this->cn->lo_unlink($r['md_lob']);
+        }
+        // now we can delete the row
+        $sql="delete from document_modele where md_id =".$this->md_id;
+        $sql=$this->cn->exec_sql($sql);
+        $this->cn->commit();
+    }
+
+    /**
+     * @brief show the form for loading a template
+     * @param p_action for the field action = destination url
+     *
+     *
+     * @return string containing the forms
+     */
+    function form()
+    {
+        $r='<p class="notice">';
+        $r.='Veuillez introduire les mod&egrave;les servant à 
g&eacute;n&eacute;rer vos documents';
+        $r.='</p>';
+        $r.='<form enctype="multipart/form-data"  method="post">';
+        $r.=dossier::hidden();
+        // we need to add the sub action as hidden
+        $h=new IHidden();
+        $h->name="sa";
+        $h->value="add_document";
+
+        $r.=$h->input();
+
+        $r.='<table>';
+        $t=new IText();
+        $t->name="md_name";
+        $r.="<tr><td> Nom </td><td>".$t->input()."</td>";
+
+        $r.="</tr>";
+        $r.="<tr><td>Catégorie de document </td>";
+        $w=new ISelect();
+        $w->name="md_type";
+
+        $w->value=$this->cn->make_array('select dt_id,dt_value from 
document_type order by dt_value');
+        $r.="<td>".$w->input()."</td></tr>";
+
+        $r.='<tr>';
+        $r.=td(_('Affectation'));
+        $waffect=new ISelect();
+        $waffect->name='md_affect';
+        $waffect->value=array(
+                            array('value'=>'ACH','label'=>_('Uniquement 
journaux achat')),
+                            array('value'=>'VEN','label'=>_('Uniquement 
journaux vente')),
+                            array('value'=>'GES','label'=>_('Partie gestion'))
+                        );
+
+        $r.=td($waffect->input());
+        $r.='</tr>';
+
+        $f=new IFile();
+        $f->name="doc";
+        $r.="<tr><td>fichier</td><td> ".$f->input()."</td></tr>";
+
+        $start=new IText();
+        $start->name="start_seq";
+        $start->size=9;
+        $start->value="0";
+
+        $r.="<tr><td> Numerotation commence a</td><td> 
".$start->input()."</td>";
+        $r.='<td class="notice">Si vous laissez &agrave; 0, la 
num&eacute;rotation ne changera pas, la prochaine facture sera n+1, n étant le 
n° que vous avez donn&eacute;</td>';
+        $r.="</tr>";
+        $r.='</table>';
+        $r.=HtmlInput::submit('add_document','Ajout');
+        $r.="</form></p>";
+        return $r;
+    }
+    /*!\brief load the value of a document_modele,the ag_id variable must be 
set
+     */
+    function load()
+    {
+        $array=$this->cn->get_array("SELECT md_id, md_name, md_lob, md_type, 
md_filename, md_mimetype,md_affect".
+                                    " FROM document_modele where 
md_id=$1",array($this->md_id));
+        if ( count($array) == 0 ) return null;
+        foreach ( array('md_name', 'md_lob','md_type', 'md_filename', 
'md_mimetype','md_affect') as $idx)
+        {
+            $this->$idx=$array[0][$idx];
+        }
+    }
+    /*!
+     * \brief :  update a document_modele in the database,
+     */
+    function update($p_array)
+    {
+      $this->load();
+        // if name is empty return immediately
+        if ( trim(strlen($p_array['md_name']))==0)
+            return;
+        try
+        {
+            // Start transaction
+            $this->cn->start();
+           $sql="update document_modele set md_name=$1,md_type=$2,md_affect=$3 
where md_id=$4";
+           $this->cn->exec_sql($sql,array(
+                                          $p_array['md_name'],
+                                          $p_array['md_type'],
+                                          $p_array['md_affect'],
+                                          $this->md_id
+                                          ));
+           if ( $p_array['seq'] != 0 )
+             
$this->cn->alter_seq('seq_doc_type_'.$p_array['md_type'],$p_array['seq']);
+
+            // Save the file
+            $new_name=tempnam($_ENV['TMP'],'document_');
+            if ( strlen ($_FILES['doc']['tmp_name']) != 0 )
+            {
+                if (move_uploaded_file($_FILES['doc']['tmp_name'],
+                                       $new_name))
+                {
+                    // echo "Image saved";
+                    $oid= $this->cn->lo_import($new_name);
+                    if ( $oid == false )
+                    {
+                        
echo_error('class/class_document_modele.php',__LINE__,"cannot upload document");
+                        $this->cn->rollback();
+                        return;
+                    }
+                    // Remove old document
+                    $ret=$this->cn->exec_sql("select md_lob from 
document_modele where md_id=".$this->md_id);
+                    if (Database::num_row($ret) != 0)
+                    {
+                        $r=Database::fetch_array($ret,0);
+                        $old_oid=$r['md_lob'];
+                        if (strlen($old_oid) != 0)
+                            $this->cn->lo_unlink($old_oid);
+                    }
+                    // Load new document
+                    $this->cn->exec_sql("update document_modele set 
md_lob=".$oid.", md_mimetype='".$_FILES['doc']['type']."' 
,md_filename='".$_FILES['doc']['name']."' where md_id=".$this->md_id);
+                    $this->cn->commit();
+                }
+                else
+                {
+                    echo "<H1>Error</H1>";
+                    $this->cn->rollback();
+                    throw new Exception("Erreur".__FILE__.__LINE__);
+                }
+            }
+        }
+        catch (Exception $e)
+        {
+            rollback($this->cn);
+            return ;
+        }
+       $this->cn->commit();
+    }
+
+}
+?>
diff --git a/include/class_document_type.php 
b/include/class/class_document_type.php
similarity index 100%
rename from include/class_document_type.php
rename to include/class/class_document_type.php
diff --git a/include/class/class_dossier.php b/include/class/class_dossier.php
new file mode 100644
index 0000000..3531657
--- /dev/null
+++ b/include/class/class_dossier.php
@@ -0,0 +1,314 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief the class for the dossier, everywhere we need to know to
+ * which folder we are connected, because we can't use $_SESSION, we
+ * need to pass the dossier_id via a _GET or a POST variable
+ */
+
+/*! \brief manage the current dossier, everywhere we need to know to
+ * which folder we are connected, because we can't use $_SESSION, we
+ * need to pass the dossier_id via a _GET or a POST variable
+ *  private static $variable=array("id"=>"dos_id",
+                                "name"=>"dos_name",
+                                "desc"=>"dos_description");
+ *
+ */
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
+
+class Dossier
+{
+    private static $variable=array("id"=>"dos_id",
+                                   "name"=>"dos_name",
+                                   "desc"=>"dos_description");
+    function __construct($p_id)
+    {
+        $this->cn=new Database();      // Connect to the repository
+        $this->dos_id=$p_id;
+    }
+    /*!\brief return the $_REQUEST['gDossier'] after a check */
+    static function id()
+    {
+        self::check();
+        return $_REQUEST['gDossier'];
+    }
+
+    /**
+     * @brief Show the folder where user have access. 
+     * @param  p_type string   
+       - A for all dossiers 
+       - R for accessible folders
+       - X forbidden folders
+     * @param p_login is the user name
+     * @param p_text is a part of the name where are looking for
+     * @return     nothing
+     *
+     */
+    static function show_dossier($p_type,$p_login="",$p_text="",$limit=0)
+    {
+        $cn=new Database();
+        $str_limit=($limit==0)?'':' limit '.$limit;
+        if ( $p_type == "A")
+        {
+            $l_sql="select *, 'W' as priv_priv from ac_dossier where dos_name 
~* $2 or dos_description ~* $2 ORDER BY dos_name $str_limit  ";
+            $a_row=$cn->get_array($l_sql,$p_text);
+            return $a_row;
+        }
+        else if ($p_type == "R")
+        {
+            $l_sql="select * from jnt_use_dos
+                   natural join ac_dossier
+                   natural join ac_users
+                   where
+                   use_login=$1
+                   and ( dos_name ~* $2 or dos_description ~* $2)
+                   
+                   order by dos_name 
+                   $str_limit
+                   ";
+            
+            $a_row=$cn->get_array($l_sql,array($p_login,$p_text));
+            return $a_row;
+
+        } 
+        else  if ($p_type == 'X')
+        {
+            $l_sql=' select * from ac_dossier where dos_id not in 
+                  (select dos_id from jnt_use_dos where use_id=$1)
+                  and ( dos_name ~* $2 or dos_description ~* $2)
+                  order by dos_name '.$str_limit;
+            $a_row=$cn->get_array($l_sql,array($p_login,$p_text));
+            return $a_row;
+
+        }
+        else
+        {
+            throw new Exception (_("Erreur paramètre"));
+        } 
+        
+       
+    }
+    /**
+     * Count the number of folder in the repository
+     * @return integer
+     */
+    function count() 
+    {
+        $nb_folder=$this->cn->get_value('select count(*) from ac_dossier');
+        return $nb_folder;
+    }
+    /*!
+     * \brief Return all the users
+     * as an array
+     */
+    function get_user_folder($sql="")
+    {
+
+        $sql="
+            select
+                use_id,
+                use_first_name,
+                use_name,
+                use_login,
+                use_active,
+                use_admin,
+                ag_dossier
+            from
+            ac_users  as ac
+            left join    (select array_to_string(array_agg(dos_name),',') as 
ag_dossier,jt.use_id as jt_use_id
+                        from ac_dossier as ds
+                        join  jnt_use_dos as jt on (jt.dos_id=ds.dos_id)
+                        group by jt.use_id) as dossier_name on 
(jt_use_id=ac.use_id)
+            where
+            use_login!='phpcompta'
+            $sql
+            ";
+
+        $res=$this->cn->get_array($sql);
+        return $res;
+        }
+
+    /*!\brief check if gDossier is set */
+    static function check()
+    {
+        if ( ! isset ($_REQUEST['gDossier']) )
+        {
+            echo_error ('Dossier inconnu ');
+            exit('Dossier invalide ');
+        }
+        $id=$_REQUEST['gDossier'];
+        if ( is_numeric ($id) == 0 ||
+                strlen($id)> 6 ||
+                $id > 999999)
+            exit('gDossier Invalide : '.$id);
+
+    }
+    /*!\brief return a string to put to gDossier into a GET */
+    static function get()
+    {
+        self::check();
+        return "gDossier=".$_REQUEST['gDossier'];
+
+    }
+
+    /*!\brief return a string to set gDossier into a FORM */
+    static function hidden()
+    {
+        self::check();
+        return '<input type="hidden" id="gDossier" name="gDossier" 
value="'.$_REQUEST['gDossier'].'">';
+    }
+    /*!\brief retrieve the name of the current dossier */
+    static function name($id=0)
+    {
+        self::check();
+
+        $cn=new Database();
+        $id=($id==0)?$_REQUEST['gDossier']:$id;
+        $name=$cn->get_value("select dos_name from ac_dossier where 
dos_id=$1",array($_REQUEST['gDossier']));
+        return $name;
+    }
+
+    public function get_parameter($p_string)
+    {
+        if ( array_key_exists($p_string,self::$variable) )
+        {
+            $idx=self::$variable[$p_string];
+            return $this->$idx;
+        }
+        else
+            throw new Exception("Attribut inexistant $p_string");
+    }
+    public function set_parameter($p_string,$p_value)
+    {
+        if ( array_key_exists($p_string,self::$variable) )
+        {
+            $idx=self::$variable[$p_string];
+            $this->$idx=$p_value;
+        }
+        else
+           throw new Exception("Attribut inexistant $p_string");
+
+
+    }
+    public function get_info()
+    {
+        return var_export(self::$variable,true);
+    }
+
+    public function save()
+    {
+        $this->update();
+    }
+
+    public function update()
+    {
+        if ( strlen(trim($this->dos_name))== 0 ) return;
+
+        if ( $this->cn->get_value("select count(*) from ac_dossier where 
dos_name=$1 and dos_id<>$2",
+                                  array($this->dos_name,$this->dos_id)) !=0 )
+            return ;
+
+        $sql="update ac_dossier set dos_name=$1,dos_description=$2 ".
+             " where dos_id = $3";
+        $res=$this->cn->exec_sql(
+                 $sql,
+                 array(trim($this->dos_name),
+                       trim($this->dos_description),
+                       $this->dos_id)
+             );
+    }
+
+    public function load()
+    {
+
+        $sql="select dos_name,dos_description from ac_dossier where dos_id=$1";
+
+        $res=$this->cn->exec_sql(
+                 $sql,
+                 array($this->dos_id)
+             );
+
+        if ( Database::num_row($res) == 0 ) return;
+        $row=Database::fetch_array($res,0);
+        foreach ($row as $idx=>$value)
+        {
+            $this->$idx=$value;
+        }
+
+    }
+
+    static function get_version($p_cn)
+       {
+               return $p_cn->get_value('select val from version');
+       }
+
+       static function connect()
+       {
+               $id = Dossier::id();
+               $cn = new Database($id);
+               return $cn;
+       }
+       /**
+        *connect to folder and give to admin. the profile Admin(builtin)
+        * @param int $p_id dossier::id()
+        */
+       static function synchro_admin($p_id)
+       {
+               // connect to target
+               $cn=new Database($p_id);
+
+               if (! $cn->exist_table("profile_menu"))
+               {
+                       echo_warning("Dossier invalide");
+                       return;
+               }
+               // connect to repo
+               $repo=new Database();
+
+               $a_admin=$repo->get_array("select use_login from ac_users where
+                       use_admin=1 and use_active=1");
+               try
+               {
+                       /**
+                        * synchro global
+                        */
+                       $cn->start();
+                       for ($i=0;$i<count($a_admin);$i++)
+                       {
+                               $exist=$cn->get_value("select p_id from 
profile_user
+                                       where 
user_name=$1",array($a_admin[$i]['use_login']));
+                               if ( $exist == "")
+                               {
+                                       $cn->exec_sql("insert into 
profile_user(user_name,p_id) values($1,1)",
+                                                       
array($a_admin[$i]['use_login']));
+                               }
+
+                       }
+                       $cn->commit();
+               } catch(Exception $e)
+               {
+                       echo_warning($e->getMessage());
+                       $cn->rollback();
+               }
+       }
+}
diff --git a/include/class/class_exercice.php b/include/class/class_exercice.php
new file mode 100644
index 0000000..702aef9
--- /dev/null
+++ b/include/class/class_exercice.php
@@ -0,0 +1,77 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief about the accountant exercice
+ */
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/lib/class_iselect.php';
+class Exercice
+{
+  function __construct(&$cn)
+  {
+    $this->cn=$cn;
+  }
+  /**
+   *return the number of different exercices into a folder
+   address@hidden $cn is the database connexion object database
+   address@hidden the count of exercice
+   */
+   function count()
+  {
+    $count=$this->cn->get_value('select count(distinct p_exercice) from 
parm_periode');
+    return $count;
+  }
+   /**
+    *Show a ISelect with the different exercices
+    address@hidden $name of the iselect
+    address@hidden $selected the selected year  (default = '')
+    address@hidden $js javascript (default = '')
+    address@hidden ISelect object
+    */
+   function select($name,$selected='',$js='')
+   {
+     $iselect=new ISelect($name);
+     $iselect->value=$this->cn->make_array('select distinct 
p_exercice,p_exercice from parm_periode order by 1');
+     $iselect->selected=$selected;
+     $iselect->javascript=$js;
+     return $iselect;
+   }
+   /**
+    *Show a ISelect with the different exercices, display start and end date
+    address@hidden $name of the iselect
+    address@hidden $selected the selected year  (default = '')
+    address@hidden $js javascript (default = '')
+    address@hidden ISelect object
+    */
+   function select_date($name,$selected='',$js='')
+   {
+     $iselect=new ISelect($name);
+     $iselect->value=$this->cn->make_array("select distinct p_exercice,to_char 
(min(p_start),'DD.MM.YY')
+                                                                               
                                                         ||' - '
+                                                                               
                                                         ||to_char 
(max(p_end),'DD.MM.YY')
+                                                                               
        from parm_periode
+                                                                               
        group by p_exercice order by 1");
+     $iselect->selected=$selected;
+     $iselect->javascript=$js;
+     return $iselect;
+   }
+}
diff --git a/include/class/class_extension.php 
b/include/class/class_extension.php
new file mode 100644
index 0000000..00a82df
--- /dev/null
+++ b/include/class/class_extension.php
@@ -0,0 +1,309 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief the extension class manages the plugins for the security, the access
+ * the inclusion...
+ */
+/*!\brief manage the extension, it involves the table extension
+ *
+ * Data member
+ * - $cn database connection
+ * - $variable :
+ *    -  id (extension.ex_id)
+ *    -  name (extension.ex_name)
+ *    - plugin_code (extension.ex_code)
+ *    - desc (extension.ex_desc)
+ *    - enable (extension.ex_enable)
+ *    - filepath (extension.ex_file)
+ */
+require_once NOALYSS_INCLUDE.'/database/class_menu_ref_sql.php';
+require_once NOALYSS_INCLUDE.'/database/class_profile_sql.php';
+require_once NOALYSS_INCLUDE.'/class/class_menu_ref.php';
+require_once NOALYSS_INCLUDE.'/class/class_profile_menu.php';
+
+class Extension extends Menu_Ref_sql
+{
+    public function verify()
+    {
+        // Verify that the elt we want to add is correct
+        if (trim($this->me_code)=="") throw new Exception('Le code ne peut pas 
être vide');
+        if (trim($this->me_menu)=="") throw new Exception('Le nom ne peut pas 
être vide');
+        if (trim($this->me_file)=="") throw new Exception('Chemin incorrect');
+        if 
(file_exists('..'.DIRECTORY_SEPARATOR.'include'.DIRECTORY_SEPARATOR.'ext'.DIRECTORY_SEPARATOR.$this->me_file)
 == false)
+            throw new Exception ('Extension non trouvée, le chemin est-il 
correct?');
+    }
+    /address@hidden search a extension, the what is the column (extends_code */
+    function search($p_what)
+    {
+               $this->me_code=strtoupper($p_what);
+               if ( $this->load() == -1) return null;
+               return 1;
+    }
+    /*!\brief return 1 if the user given in parameter can access this extension
+     * otherwise returns 0
+     *\param $p_login the user login
+     *\return 1 has access, 0 has no access
+     */
+    function can_request($p_login)
+    {
+               $cnt=$this->cn->get_value("select count(*) from menu_ref
+                                                                               
join profile_menu using (me_code)
+                                                                               
join profile_user using (p_id)
+                                                                               
where
+                                                                               
me_code=$1
+                                                                               
and user_name=$2",
+                                                               
array($this->me_code,$p_login));
+               if ( $cnt > 0)        return 1;
+               return 0;
+    }
+    /address@hidden make an array of the available plugin for the current user
+     * @return  an array
+     address@hidden ISelect
+     */
+    static function make_array($cn)
+    {
+        $sql="select DISTINCT me_code as value, me_menu as label from ".
+             " menu_ref join profile_menu using (me_code)
+                                join profile_user using (p_id) where ".
+             " user_name=$1 and me_type='PL' ORDER BY ME_MENU";
+        $a=$cn->get_array($sql,array($_SESSION['g_user']));
+        return $a;
+    }
+    static function check_version($i)
+    {
+        global $version_noalyss;
+        if ( ! isset ($version_noalyss) || $version_noalyss < $i )
+        {
+            alert('Cette extension ne fonctionne pas sur cette version de 
NOALYSS'.
+                  ' Veuillez mettre votre programme a jour. Version minimum 
'.$i);
+            return;
+        }
+        Extension::check_plugin_version();
+    }
+    /**
+     * insert into the table profile_menu for the given profile id and 
depending
+     * of the module $p_module
+     * @global type $cn
+     * @param type $p_id profile.p_id
+     * @param type $p_module menu_ref.me_code
+     * @throws Exception 10 : profile absent , 20 module absent , 30 No parent 
menu
+     */
+    function insert_profile_menu($p_id=1,$p_module='EXT')
+    {
+        global $cn;
+        //profile exists ?
+        $profile=new Profile_sql($cn,$p_id);
+        if ( $profile->p_id != $p_id) {
+                throw new Exception(_('Profil inexistant'),10);
+        }
+        // Menu exists
+        $module=new Menu_Ref($cn,$p_module);
+        if ($module->me_code==null) {
+                throw new Exception(_('Module inexistant'),20);
+        }
+        // Dependency
+        $dep_id=$cn->get_value('select pm_id from profile_menu 
+                where
+                p_id=$1
+                and me_code = $2 ',array($p_id,$p_module));
+        // throw an exception if there is no dependency
+        if ($dep_id=="") {
+                throw new Exception(_('Pas de menu ').$p_module,30);
+        }
+        
+        $profil_menu=new Profile_Menu($cn);
+        $profil_menu->me_code=$this->me_code;
+        $profil_menu->me_code_dep=$p_module;
+        $profil_menu->p_type_display='S';
+        $profil_menu->p_id=$p_id;
+        $profil_menu->pm_id_dep=$dep_id;
+        
+        $cnt=$profil_menu->count(' where p_id=$1 and me_code = 
$2',array($p_id,$this->me_code));
+        if ( $cnt==0) {
+            $profil_menu->insert();
+        }
+
+        
+    }
+    function remove_from_profile_menu($p_id)
+    {
+        global $cn;
+       
+         $cn->exec_sql('delete from profile_menu  where (me_code = $1 or 
me_code in (select me_code from menu_ref where me_file=$2)) and 
p_id=$3',array($this->me_code,$this->me_file,$p_id));
+        
+    }
+    /**
+     * Insert a plugin into the given profile, by default always insert into 
EXT
+     * 
+     * @param type $p_id profile.p_id
+     * @throws Exception if duplicate or error db
+     */
+       function insert_plugin()
+       {
+               try
+               {
+                       $this->cn->start();
+                       $this->verify();
+                       // check if duplicate
+                       $this->me_code = strtoupper($this->me_code);
+                       $count = $this->cn->get_value("select count(*) from 
menu_ref where me_code=$1", array($this->me_code));
+                       if ($count != 0)
+                               throw new Exception("Doublon");
+                       $this->me_type = 'PL';
+                       $this->insert();
+                       $this->cn->commit();
+               }
+               catch (Exception $exc)
+               {
+                       echo alert($exc->getMessage());
+               }
+       }
+       function update_plugin()
+       {
+               try
+               {
+                       $this->cn->start();
+                       $this->verify();
+                       $this->me_type = 'PL';
+                       $this->update();
+                       $this->cn->commit();
+               }
+               catch (Exception $exc)
+               {
+                       echo alert($exc->getMessage());
+               }
+       }
+       function remove_plugin()
+       {
+               try
+               {
+                       $this->cn->start();
+                       $this->delete();
+                       $this->cn->commit();
+               }
+               catch (Exception $exc)
+               {
+                       echo alert($exc->getMessage());
+               }
+       }
+       /**
+        *remove all the schema from the plugins
+        * @param Database $p_cn
+        */
+       static function clean(Database $p_cn)
+       {
+               
$a_ext=array("tva_belge","amortissement","impdol","coprop","importbank");
+               for($i=0;$i<count($a_ext);$i++){
+                       if ($p_cn->exist_schema($a_ext[$i])) {
+                               $p_cn->exec_sql("drop schema ".$a_ext[$i]." 
cascade");
+                       }
+               }
+       }
+        static function check_plugin_version()
+        {
+            global $g_user,$version_plugin;
+            if ($g_user->Admin() == 1)
+            {
+                if (SITE_UPDATE_PLUGIN != "")
+                {
+                    $update = @file_get_contents(SITE_UPDATE_PLUGIN);
+                    if ($update > $version_plugin)
+                    {
+                        echo '<div id="version_plugin_div_id" 
class="inner_box" 
style="position:absolute;zindex:2;top:5px;left:37.5%;width:25%">';
+                        echo '<p class="notice">';
+                        echo "Mise à jour disponible des plugins pour NOALYSS, 
version actuelle : $update votre version $version_plugin";
+                        echo '</p>';
+                         echo '<p style="text-align:center">'.
+                               '<a id="version_plugin_button" class="button" 
onclick="$(\'version_plugin_div_id\').remove()">'.
+                         _('Fermer').
+                         "</a></p>";
+                        echo '</div>';
+                    }
+                }
+            }
+        }
+        /**
+         * Check that the xml contains all the needed information to change 
them into
+         * a extension, the exception code is 0 if the element is optional
+         * @brief Check XML.
+         * @param SimpleXMLElement $xml
+         * @throws Exception
+         */
+        function check_xml(SimpleXMLElement $xml)
+        {
+            try {
+                if ( !isset ($xml->plugin)) throw new Exception(_('Manque 
plugin'),1);
+                $nb_plugin=count($xml->plugin);
+            
+                for ($i=0;$i<$nb_plugin;$i++)
+                {
+                    if ( !isset ($xml->plugin[$i]->name)) throw new 
Exception(_('Manque nom'),1);
+                    if ( !isset ($xml->plugin[$i]->description)) throw new 
Exception(_('Manque description'),0);
+                    if ( !isset ($xml->plugin[$i]->code)) throw new 
Exception(_('Manque code'),1);
+                    if ( !isset ($xml->plugin[$i]->author)) throw new 
Exception(_('Manque auteur'),0);
+                    if ( !isset ($xml->plugin[$i]->root)) throw new 
Exception(_('Manque répertoire racine'),1);
+                    if ( !isset ($xml->plugin[$i]->file)) throw new 
Exception(_('Manque fichier à inclure'),1);
+                }
+            } catch (Exception $ex) {
+                throw $ex;
+            }
+        }
+         /**
+         * Parse a XML file to complete an array of extension objects
+         * @brief Create extension from XML.
+         * @param type $p_file filename
+         * @return array of Extension
+         */
+        static function read_definition($p_file)
+        {
+            global $cn;
+            $dom=new DomDocument('1.0');
+            $dom->load($p_file);
+            $xml=simplexml_import_dom($dom);
+            $nb_plugin=count($xml->plugin);
+            $a_extension=array();
+            for ($i=0;$i<$nb_plugin;$i++)
+            {
+                
+                $extension=new Extension($cn);
+                try {
+                        $extension->check_xml($xml);
+                } catch (Exception $ex) {
+                    echo_warning($e->getMessage());
+                    if ( $ex->getCode()==1) {
+                        continue;
+                    }
+                    
+                }
+                
$extension->me_file=trim($xml->plugin[$i]->root).'/'.trim($xml->plugin[$i]->file);
+                $extension->me_code=trim($xml->plugin[$i]->code);
+                $extension->me_description=(isset 
($xml->plugin[$i]->description))?trim($xml->plugin[$i]->description):"";
+                
$extension->me_description_etendue=(trim($xml->plugin[$i]->author))?trim($xml->plugin[$i]->author):"";
+                $extension->me_type='PL';
+                $extension->me_menu=trim($xml->plugin[$i]->name);
+                
$extension->me_parameter='plugin_code='.trim($xml->plugin[$i]->code);
+                $a_extension[]=clone $extension;
+            }
+            return $a_extension;
+        }
+}
+
diff --git a/include/class/class_fiche.php b/include/class/class_fiche.php
new file mode 100644
index 0000000..cb06d48
--- /dev/null
+++ b/include/class/class_fiche.php
@@ -0,0 +1,1992 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+
+
+// Copyright Author Dany De Bontridder address@hidden
+include_once("class/class_fiche_attr.php");
+require_once NOALYSS_INCLUDE.'/lib/class_ispan.php';
+require_once NOALYSS_INCLUDE.'/lib/class_itva_popup.php';
+require_once NOALYSS_INCLUDE.'/lib/class_itext.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ihidden.php';
+require_once NOALYSS_INCLUDE.'/class/class_fiche_def.php';
+require_once NOALYSS_INCLUDE.'/lib/class_iposte.php';
+
+/*! \file
+ * \brief define Class fiche, this class are using
+ *        class attribut
+ */
+/*!
+ * \brief define Class fiche and fiche def, those class are using
+ *        class attribut. When adding or modifing new card in a IPOPUP
+ *        the ipopup for the accounting item is ipop_account
+ */
+
+//-----------------------------------------------------
+// class fiche
+//-----------------------------------------------------
+class Fiche
+{
+    var $cn;           /*! < $cn database connection */
+    var $id;           /*! < $id fiche.f_id */
+    var $fiche_def;    /*! < $fiche_def fd_id */
+    var $attribut;     /*! < $attribut array of attribut object */
+    var $fiche_def_ref; /*!< $fiche_def_ref Type */
+    var $row;           /*! < All the row from the ledgers */
+    var $quick_code;           /*!< quick_code of the card */
+    function __construct($p_cn,$p_id=0)
+    {
+        $this->cn=$p_cn;
+        $this->id=$p_id;
+        $this->quick_code='';
+    }
+    /**
+     address@hidden used with a usort function, to sort an array of Fiche on 
the name
+     */
+    static function cmp_name(Fiche $o1,Fiche $o2)
+    {
+        return 
strcmp($o1->strAttribut(ATTR_DEF_NAME),$o2->strAttribut(ATTR_DEF_NAME));
+    }
+
+  /**
+   address@hidden get the available bank_account filtered by the security
+   address@hidden array of card
+   */
+    function get_bk_account()
+    {
+        global $g_user;
+      $sql_ledger=$g_user->get_ledger_sql('FIN',3);
+      $avail=$this->cn->get_array("select jrn_def_id,jrn_def_name,"
+              . "jrn_def_bank,jrn_def_description from jrn_def where 
jrn_def_type='FIN' and $sql_ledger
+                            order by jrn_def_name");
+
+      if ( count($avail) == 0 )
+            return null;
+
+      for ($i=0;$i<count($avail);$i++)
+        {
+            $t=new Fiche($this->cn,$avail[$i]['jrn_def_bank']);
+            $t->ledger_name=$avail[$i]['jrn_def_name'];
+            $t->ledger_description=$avail[$i]['jrn_def_description'];
+            $t->getAttribut();
+            $all[$i]=$t;
+
+        }
+        return $all;
+    }
+
+
+    /*!   get_by_qcode($p_qcode)
+     * \brief Retrieve a card thx his quick_code
+     *        complete the object,, set the id member of the object or set it
+     *        to 0 if no card is found
+     * \param $p_qcode quick_code (ad_id=23)
+     * \param $p_all retrieve all the attribut of the card, possible value
+     * are true or false. false retrieves only the f_id. By default true
+     * \return 0 success 1 error not found
+     */
+    function get_by_qcode($p_qcode=null,$p_all=true)
+    {
+        if ( $p_qcode == null )
+            $p_qcode=$this->quick_code;
+        $p_qcode=trim($p_qcode);
+        $sql="select f_id from fiche_detail
+             where ad_id=23 and ad_value=upper($1)";
+        $this->id=$this->cn->get_value($sql,array($p_qcode));
+        if ( $this->cn->count()==0)
+        {
+            $this->id=0;
+            return 1;
+        }
+
+
+        if ( $p_all )
+            $this->getAttribut();
+        return 0;
+    }
+    /**
+     address@hidden set an attribute by a value, if the attribut array is empty
+     * a call to getAttribut is performed
+     address@hidden the AD_ID
+     address@hidden the value
+     address@hidden constant.php table: attr_def
+     */
+    function setAttribut($p_ad_id,$p_value)
+    {
+        if ( sizeof($this->attribut)==0 ) $this->getAttribut();
+        for ($e=0;$e <sizeof($this->attribut);$e++)
+        {
+            if ( $this->attribut[$e]->ad_id == $p_ad_id )
+            {
+                $this->attribut[$e]->av_text=$p_value;
+                break;
+            }
+        }
+    }
+    /**
+     *\brief  get all the attribute of a card, add missing ones
+     *         and sort the array ($this-\>attribut) by ad_id
+     */
+    function getAttribut()
+    {
+        if ( $this->id == 0)
+        {
+            return;
+        }
+        $sql="select *
+             from
+                   fiche
+             natural join fiche_detail
+            join jnt_fic_attr on (jnt_fic_attr.fd_id=fiche.fd_id and 
fiche_detail.ad_id=jnt_fic_attr.ad_id)
+             join attr_def on (attr_def.ad_id=fiche_detail.ad_id) where 
f_id=".$this->id.
+             " order by jnt_order";
+
+        $Ret=$this->cn->exec_sql($sql);
+        if ( ($Max=Database::num_row($Ret)) == 0 )
+            return ;
+        for ($i=0;$i<$Max;$i++)
+        {
+            $row=Database::fetch_array($Ret,$i);
+            $this->fiche_def=$row['fd_id'];
+            $t=new Fiche_Attr ($this->cn);
+            $t->ad_id=$row['ad_id'];
+            $t->ad_text=$row['ad_text'];
+            $t->av_text=$row['ad_value'];
+            $t->ad_type=$row['ad_type'];
+            $t->ad_size=$row['ad_size'];
+            $t->ad_extra=$row['ad_extra'];
+            $t->jnt_order=$row['jnt_order'];
+            $this->attribut[$i]=$t;
+        }
+        $e=new Fiche_Def($this->cn,$this->fiche_def);
+        $e->GetAttribut();
+
+        if ( sizeof($this->attribut) != sizeof($e->attribut ) )
+        {
+
+            /*
+                        * !! Missing attribute
+                        */
+            foreach ($e->attribut as $f )
+            {
+                $flag=0;
+                foreach ($this->attribut as $g )
+                {
+                    if ( $g->ad_id == $f->ad_id )
+                        $flag=1;
+                }
+                if ( $flag == 0 )
+                {
+                    // there's a missing one, we insert it
+                    $t=new Fiche_Attr ($f->ad_id);
+                    $t->av_text="";
+                    $t->ad_text=$f->ad_text;
+                    $t->jnt_order=$f->jnt_order;
+                    $t->ad_type=$f->ad_type;
+                    $t->ad_size=$f->ad_size;
+                    $t->ad_id=$f->ad_id;
+                    $t->ad_extra=$f->ad_extra;
+                    $this->attribut[$Max]=$t;
+                    $Max++;
+                } // if flag == 0
+
+            }// foreach
+
+
+        }//missing attribut
+    }
+    /**
+     * @brief find the card with the p_attribut equal to p_value, it is not 
case sensitive
+     * @param $p_attribut attribute to find see table attr_def
+     * @param $p_value value in attr_value.av_text
+     * @return return ARRAY OF jft_id,f_id,fd_id,ad_id,av_text
+     */
+    function seek($p_attribut,$p_value)
+    {
+        $sql="select jft_id,f_id,fd_id,ad_id,ad_value from fiche join 
fiche_detail using (f_id)
+             where ad_id=$1 and upper(ad_value)=upper($2)";
+        $res=$this->cn->get_array($sql,array($p_attribut,$p_value));
+        return $res;
+    }
+
+    /*!
+     * \brief give the size of a card object
+     *
+     * \return size
+     */
+    function size()
+    {
+        if ( isset ($this->ad_id))
+            return sizeof($this->ad_id);
+        else
+            return 0;
+    }
+
+
+    /*!
+     **************************************************
+     * \brief  Return array of card from the frd family
+     *
+     * \param $p_frd_id the fiche_def_ref.frd_id
+     * \param $p_search p_search is a filter on the name
+     * \param $p_sql extra sql condition
+     *
+     * \return array of fiche object
+     */
+    function count_by_modele($p_frd_id,$p_search="",$p_sql="")
+    {
+        $sql="select *
+             from
+             fiche join fiche_Def using (fd_id)
+             where frd_id=".$p_frd_id;
+        if ( $p_search != "" )
+        {
+            $a=sql_string($p_search);
+            $sql="select * from vw_fiche_attr where frd_id=".$p_frd_id.
+                 " and vw_name ~* '$p_search'";
+        }
+
+        $Ret=$this->cn->exec_sql($sql.$p_sql);
+
+        return Database::num_row($Ret) ;
+    }
+    /*!
+     **************************************************
+     * \brief  Return array of card from the frd family
+     *
+     *
+     * \param  $p_frd_id the fiche_def_ref.frd_id
+     * \param  $p_offset
+     * \param  $p_search is an optional filter
+     *\param $p_order : possible values are name, f_id
+     * \return array of fiche object
+     */
+    function GetByDef($p_frd_id,$p_offset=-1,$p_search="",$p_order='')
+    {
+        switch($p_order)
+        {
+        case 'name' :
+                $order=' order by name';
+            break;
+        case 'f_id':
+            $order='order by f_id';
+            break;
+        default:
+            $order='';
+        }
+        if ( $p_offset == -1 )
+        {
+            $sql="select *
+                 from
+                 fiche join fiche_Def using (fd_id) join vw_fiche_name 
using(f_id)
+                 where frd_id=".$p_frd_id." $p_search ".$order;
+        }
+        else
+        {
+            $limit=($_SESSION['g_pagesize']!=-1)?"limit 
".$_SESSION['g_pagesize']:"";
+            $sql="select *
+                 from
+                 fiche join fiche_Def using (fd_id) join vw_fiche_name 
using(f_id)
+                 where frd_id=".$p_frd_id." $p_search $order  "
+                 .$limit." offset ".$p_offset;
+
+        }
+
+        $Ret=$this->cn->exec_sql($sql);
+        if ( ($Max=Database::num_row($Ret)) == 0 )
+            return ;
+        $all[0]=new Fiche($this->cn);
+
+        for ($i=0;$i<$Max;$i++)
+        {
+            $row=Database::fetch_array($Ret,$i);
+            $t=new Fiche($this->cn,$row['f_id']);
+            $t->getAttribut();
+            $all[$i]=clone $t;
+
+        }
+        return $all;
+    }
+    function ShowTable()
+    {
+        echo "<TR><TD> ".
+        $this->id."</TD>".
+        "<TR> <TD>".
+        $this->attribut_value."</TD>".
+        "<TR> <TD>".
+        $this->attribut_def."</TD></TR>";
+    }
+    /***
+     * @brief  return the string of the given attribute
+     *        (attr_def.ad_id)
+     * @param $p_ad_id the AD_ID from attr_def.ad_id
+     * @param $p_return 1 return NOTFOUND otherwise an empty string
+     * @see constant.php
+     * @return string
+     */
+    function strAttribut($p_ad_id,$p_return=1)
+    {
+               $return=($p_return==1)?NOTFOUND:"";
+        if ( sizeof ($this->attribut) == 0 )
+        {
+
+            if ($this->id==0) {
+                                       return $return;
+                       }
+            // object is not in memory we need to look into the database
+            $sql="select ad_value from fiche_detail
+                 where f_id= $1  and ad_id= $2 ";
+            $Res=$this->cn->exec_sql($sql,array($this->id,$p_ad_id));
+            $row=Database::fetch_all($Res);
+            // if not found return error
+            if ( $row == false )
+                return $return;
+
+            return $row[0]['ad_value'];
+        }
+
+        foreach ($this->attribut as $e)
+        {
+            if ( $e->ad_id == $p_ad_id )
+                return $e->av_text;
+        }
+        return $return;
+    }
+    /**
+     * @brief make an array of attributes of the category of card 
(FICHE_DEF.FD_ID)
+     *The array can be used with the function insert, it will return a struct 
like this :
+     * in the first key (av_textX),  X is the ATTR_DEF::AD_ID
+    \verbatim
+    Example
+    Array
+    (
+      [av_text1] => Nom
+      [av_text12] => Personne de contact
+      [av_text5] => Poste Comptable
+      [av_text13] => numéro de tva
+      [av_text14] => Adresse
+      [av_text15] => code postal
+      [av_text24] => Ville
+      [av_text16] => pays
+      [av_text17] => téléphone
+      [av_text18] => email
+      [av_text23] => Quick Code
+    )
+
+    \endverbatim
+     *\param $pfd_id FICHE_DEF::FD_ID
+     *\return an array of attribute
+     *\exception Exception if the cat of card doesn't exist, 
Exception.getCode()=1
+     *\see fiche::insert()
+     */
+    function to_array($pfd_id)
+    {
+        $sql="select 'av_text'||to_char(ad_id,'9999') as key,".
+             " ad_text ".
+             " from fiche_def join jnt_fic_attr using (fd_id)".
+             " join attr_def using (ad_id) ".
+             " where fd_id=$1 order by jnt_order";
+        $ret=$this->cn->get_array($sql,array($pfd_id));
+        if ( empty($ret)) throw new Exception(_('Cette categorie de card 
n\'existe pas').' '.$pfd_id,1);
+        $array=array();
+        foreach($ret as $idx=>$val)
+        {
+            $a=str_replace(' ','',$val['key']);
+            $array[$a]=$val['ad_text'];
+        }
+        return $array;
+
+    }
+    /*!
+     * \brief  insert a new record
+     *         show a blank card to be filled
+     *
+     * \param  $p_fiche_def is the fiche_def.fd_id
+     *
+     * \return HTML Code
+     */
+    function blank($p_fiche_def)
+    {
+        // array = array of attribute object sorted on ad_id
+        $f=new Fiche_Def($this->cn,$p_fiche_def);
+        $f->get();
+        $array=$f->getAttribut();
+        $r=h2(_('Catégorie').' '.$f->label,"");
+        $r.='<table style="width:98%;margin:1%">';
+        foreach ($array as $attr)
+        {
+            $table=0;
+            $msg="";$bulle='';
+            if ( $attr->ad_id == ATTR_DEF_ACCOUNT)
+            {
+                $w=new IPoste("av_text".$attr->ad_id);
+                $w->set_attribute('ipopup','ipop_account');
+                $w->set_attribute('account',"av_text".$attr->ad_id);
+                               $w->dbl_click_history();
+                //  account created automatically
+                $sql="select account_auto($p_fiche_def)";
+                $ret_sql=$this->cn->exec_sql($sql);
+                $a=Database::fetch_array($ret_sql,0);
+                $label=new ISpan();
+                $label->name="av_text".$attr->ad_id."_label";
+
+                if ( $a['account_auto'] == 't' )
+                    $msg.=$label->input()." <span style=\"color:red\">".
+                                               _("Rappel: Poste créé 
automatiquement à partir de ")
+                                               .$f->class_base." </span> ";
+                else
+                {
+                    // if there is a class base in fiche_def_ref, this account 
will be the
+                    // the default one
+                    if ( strlen(trim($f->class_base)) != 0 )
+                    {
+                        $msg.="<TD>".$label->input()." <span 
style=\"color:red\">"._("Rappel: Poste par défaut sera ").
+                              $f->class_base.
+                              " !</span> ";
+                        $w->value=$f->class_base;
+                    }
+
+                }
+                $r.="<TR>".td(_("Poste Comptable"),' class="input_text" ' 
).td($w->input().$msg)."</TR>";
+                continue;
+            }
+            elseif ( $attr->ad_id == ATTR_DEF_TVA)
+            {
+                $w=new ITva_Popup('popup_tva');
+                $w->table=1;
+            }
+
+            else
+            {
+             switch ($attr->ad_type)
+                {
+                    case 'text':
+                            $w = new IText();
+                            $w->css_size = "100%";
+                            break;
+                    case 'numeric':
+                            $w = new INum();
+                            $w->prec=($attr->ad_extra=="")?2:$attr->ad_extra;
+                            $w->size = $attr->ad_size;
+                            break;
+                    case 'date':
+                            $w = new IDate();
+                            break;
+                    case 'zone':
+                            $w = new ITextArea();
+                            $w->style=' class="itextarea" 
style="margin:0px;width:100%"';
+                            break;
+                    case 'poste':
+                            $w = new IPoste("av_text" . $attr->ad_id);
+                            $w->set_attribute('ipopup', 'ipop_account');
+                            $w->set_attribute('account', "av_text" . 
$attr->ad_id);
+                            $w->table = 1;
+                            $bulle = HtmlInput::infobulle(14);
+                            break;
+                    case 'select':
+                            $w = new ISelect("av_text" . $attr->ad_id);
+                            $w->value = $this->cn->make_array($attr->ad_extra);
+                            $w->style= 'style="width:100%"';
+                            break;
+                    case 'card':
+                            $w = new ICard("av_text" . $attr->ad_id);
+                            // filter on frd_id
+                            $w->extra = $attr->ad_extra;
+                            $w->extra2 = 0;
+                            $label = new ISpan();
+                            $label->name = "av_text" . $attr->ad_id . "_label";
+                            $w->set_attribute('ipopup', 'ipopcard');
+                            $w->set_attribute('typecard', $attr->ad_extra);
+                            $w->set_attribute('inp', "av_text" . $attr->ad_id);
+                            $w->set_attribute('label', "av_text" . 
$attr->ad_id . "_label");
+                            $msg = $w->search();
+                            $msg.=$label->input();
+                            break;
+                }
+                $w->table = 0;
+            }
+            $w->table = $table;
+            $w->label = $attr->ad_text;
+            $w->name = "av_text" . $attr->ad_id;
+            if ($attr->ad_id == 21 || 
$attr->ad_id==22||$attr->ad_id==20||$attr->ad_id==31)
+            {
+                    $bulle=HtmlInput::infobulle(21);
+            }
+            $r.="<TR>" . td(_($w->label)." $bulle", ' class="input_text" ') . 
td($w->input()." $msg")." </TR>";
+        }
+        $r.= '</table>';
+        return $r;
+    }
+
+
+    /*!
+     * \brief  Display object instance, getAttribute
+     *        sort the attribute and add missing ones
+     * \param $p_readonly true= if can not modify, otherwise false
+     *
+     *
+     * \return string to display or FNT string for fiche non trouvé
+     */
+    function Display($p_readonly)
+    {
+        $this->GetAttribut();
+        $attr=$this->attribut;
+        /* show card type here */
+        $type_card=$this->cn->get_value('select fd_label '
+                . ' from fiche_def join fiche using (fd_id) where f_id=$1',
+                array($this->id));
+        $ret="";
+        $ret.=h2(_("Catégorie")." ".$type_card, 'style="display:inline"');
+        $ret.='<span style="font-weight:bolder;margin-right:5px;float:right">'.
+                _('id fiche').':'.$this->id."</span>";
+        $ret.="<table style=\"width:98%;margin:1%\">";
+        if (empty($attr))
+        {
+            return 'FNT';
+        }
+
+        /* for each attribute */
+        foreach ($attr as $r)
+        {
+            $msg="";
+            $bulle="";
+            if ($p_readonly)
+            {
+                $w=new IText();
+                $w->table=1;
+                $w->readOnly=true;
+                $w->css_size="100%";
+            }
+            if ($p_readonly==false)
+            {
+
+                if ($r->ad_id==ATTR_DEF_ACCOUNT)
+                {
+                    $w=new IPoste("av_text".$r->ad_id);
+                    $w->set_attribute('ipopup', 'ipop_account');
+                    $w->set_attribute('account', "av_text".$r->ad_id);
+                    $w->dbl_click_history();
+                    //  account created automatically
+                    $w->table=0;
+                    $w->value=$r->av_text;
+                    //  account created automatically
+                    $sql="select account_auto($this->fiche_def)";
+                    $ret_sql=$this->cn->exec_sql($sql);
+                    $a=Database::fetch_array($ret_sql, 0);
+                    $bulle=HtmlInput::infobulle(10);
+
+                    if ($a['account_auto']=='t')
+                        $bulle.=HtmlInput::warnbulle(11);
+                }
+                elseif ($r->ad_id==ATTR_DEF_TVA)
+                {
+                    $w=new ITva_Popup('popup_tva');
+                    $w->table=1;
+                    $w->value=$r->av_text;
+                }
+                else
+                {
+                    switch ($r->ad_type)
+                    {
+                        case 'text':
+                            $w=new IText('av_text'.$r->ad_id);
+                            $w->css_size="100%";
+                            $w->value=$r->av_text;
+                            break;
+                        case 'numeric':
+                            $w=new INum('av_text'.$r->ad_id);
+                            $w->size=$r->ad_size;
+                            $w->prec=($r->ad_extra=="")?2:$r->ad_extra;
+                            $w->value=$r->av_text;
+                            break;
+                        case 'date':
+                            $w=new IDate('av_text'.$r->ad_id);
+                            $w->value=$r->av_text;
+                            break;
+                        case 'zone':
+                            $w=new ITextArea('av_text'.$r->ad_id);
+                            $w->style=' class="itextarea" 
style="margin:0px;width:100%"';
+                            $w->value=$r->av_text;
+                            break;
+                        case 'poste':
+                            $w=new IPoste("av_text".$r->ad_id);
+                            $w->set_attribute('ipopup', 'ipop_account');
+                            $w->set_attribute('account', "av_text".$r->ad_id);
+                            $w->dbl_click_history();
+                            $w->width=$r->ad_size;
+                            $w->table=0;
+                            $bulle=HtmlInput::infobulle(14);
+                            $w->value=$r->av_text;
+                            break;
+                        case 'card':
+                            $uniq=rand(0, 1000);
+                            $w=new ICard("av_text".$r->ad_id);
+                            $w->id="card_".$this->id.$uniq;
+                            // filter on ad_extra
+
+                            $filter=$r->ad_extra;
+                            $w->width=$r->ad_size;
+                            $w->extra=$filter;
+                            $w->extra2=0;
+                            $label=new ISpan();
+                            $label->name="av_text".$uniq.$r->ad_id."_label";
+                            $fiche=new Fiche($this->cn);
+                            $fiche->get_by_qcode($r->av_text);
+                            if ($fiche->id==0)
+                            {
+                                $label->value=(trim($r->av_text)=='')?"":" 
"._("Fiche non trouvée")." ";
+                                $r->av_text="";
+                            }
+                            else
+                            {
+                                
$label->value=$fiche->strAttribut(ATTR_DEF_NAME).
+                                        " ".
+                                        
$fiche->strAttribut(ATTR_DEF_FIRST_NAME,0);
+                            }
+                            $w->set_attribute('ipopup', 'ipopcard');
+                            $w->set_attribute('typecard', $filter);
+                            $w->set_attribute('inp', "av_text".$r->ad_id);
+                            $w->set_attribute('label', $label->name);
+                            $w->autocomplete=0;
+                            $w->dblclick="fill_ipopcard(this);";
+                            $msg=$w->search();
+                            $msg.=$label->input();
+                            $w->value=$r->av_text;
+                            break;
+                        case 'select':
+                            $w=new ISelect();
+                            $w->value=$this->cn->make_array($r->ad_extra);
+                            $w->selected=$r->av_text;
+                            $w->style=' style="width:100%" ';
+                            break;
+                        default:
+                            var_dump($r);
+                            throw new Exception("Type invalide");
+                    }
+                    $w->table=0;
+                }
+            }
+            else
+            {
+                switch ($r->ad_type)
+                {
+                    case 'select':
+                        $x=new ISelect();
+                        $x->value=$this->cn->make_array($r->ad_extra);
+                        $x->selected=$r->av_text;
+                        $value=$x->display();
+                        $w->value=$value;
+                        break;
+                    default:
+                        $w->value=$r->av_text;
+                }
+            }
+
+            $w->name="av_text".$r->ad_id;
+            $w->readOnly=$p_readonly;
+
+            if ($r->ad_id==21||$r->ad_id==22||$r->ad_id==20||$r->ad_id==31)
+            {
+                $bulle=HtmlInput::infobulle(21);
+            }
+            $ret.="<TR>".td(_($r->ad_text).$bulle).td($w->input()." ".$msg)." 
</TR>";
+        }
+
+        $ret.="</table>";
+
+        return $ret;
+    }
+
+    /*!
+     * \brief  Save a card, call insert or update
+     *
+     * \param p_fiche_def (default 0)
+     */
+    function Save($p_fiche_def=0)
+    {
+        // new card or only a update ?
+        if ( $this->id == 0 )
+            $this->insert($p_fiche_def);
+        else
+            $this->update();
+    }
+    /*!
+     * \brief  insert a new record
+     *
+     * \param $p_fiche_def fiche_def.fd_id
+     * \param $p_array is the array containing the data
+     *\param $transation if we want to manage the transaction in this function
+     * true for small insert and false for a larger loading, the BEGIN / 
COMMIT sql
+     * must be done into the caller
+     av_textX where X is the ad_id
+     *\verb
+    example
+    av_text1=>'name'
+    \endverb
+     */
+    function insert($p_fiche_def,$p_array=null,$transaction=true)
+    {
+        if ($p_array==null)
+            $p_array=$_POST;
+
+        $fiche_id=$this->cn->get_next_seq('s_fiche');
+        $this->id=$fiche_id;
+        // first we create the card
+        if ($transaction)
+            $this->cn->start();
+        /*
+         * Sort the array for having the name AFTER the quickcode and the 
+         * Accounting
+         */
+        ksort($p_array);
+
+        try
+        {
+            $sql=sprintf("insert into fiche(f_id,fd_id)".
+                    " values (%d,%d)", $fiche_id, $p_fiche_def);
+            $Ret=$this->cn->exec_sql($sql);
+            // parse the $p_array array
+            foreach ($p_array as $name=> $value)
+            {
+                /* avoid the button for searching an accounting item */
+                if (preg_match('/^av_text[0-9]+$/', $name)==0)
+                    continue;
+
+                list ($id)=sscanf($name, "av_text%d");
+                if ($id==null)
+                    continue;
+
+                // Special traitement
+                // quickcode
+                if ($id==ATTR_DEF_QUICKCODE)
+                {
+                    $sql=sprintf("select insert_quick_code(%d,'%s')", 
$fiche_id,
+                            sql_string($value));
+                    $this->cn->exec_sql($sql);
+                    continue;
+                }
+                // name
+                if ($id==ATTR_DEF_NAME)
+                {
+                    if (strlen(trim($value))==0)
+                        $value="pas de nom";
+                }
+                // account
+                if ($id==ATTR_DEF_ACCOUNT)
+                {
+                    $v=mb_substr(sql_string($value), 0, 40);
+                    try
+                    {
+
+                        if (strlen(trim($v))!=0)
+                        {
+                            if (strpos($value, ',')==0)
+                            {
+                                $v=$this->cn->get_value("select 
format_account($1)",
+                                        array($value));
+                            }
+                            else
+                            {
+                                $ac_array=explode(",", $value);
+                                if (count($ac_array)<>2)
+                                    throw new Exception('Désolé, il y a trop 
de virgule dans le poste comptable '.h($value));
+                                $part1=$ac_array[0];
+                                $part2=$ac_array[1];
+                                $part1=$this->cn->get_value('select 
format_account($1)',
+                                        array($part1));
+                                $part2=$this->cn->get_value('select 
format_account($1)',
+                                        array($part2));
+                                $v=$part1.','.$part2;
+                            }
+                            $parameter=array($this->id, $v);
+                        }
+                        else
+                        {
+                            $parameter=array($this->id, null);
+                        }
+                        $v=$this->cn->get_value("select account_insert($1,$2)",
+                                $parameter);
+                    }
+                    catch (Exception $e)
+                    {
+                        throw new Exception("Erreur : ce compte [$v] n'a pas 
de compte parent.".
+                        "L'opération est annulée", 1);
+                    }
+                    continue;
+                }
+                // TVA
+                if ($id==ATTR_DEF_TVA)
+                {
+                    // Verify if the rate exists, if not then do not update
+                    if (strlen(trim($value))!=0)
+                    {
+                        if (isNumber($value)==0)
+                            continue;
+                        if ($this->cn->count_sql("select * from tva_rate where 
tva_id=".$value)==0)
+                        {
+                            continue;
+                        }
+                    }
+                }
+                // Normal traitement
+                $value2=sql_string($value);
+
+                $sql=sprintf("select attribut_insert(%d,%d,'%s')", $fiche_id,
+                        $id, strip_tags(trim($value2)));
+                $this->cn->exec_sql($sql);
+            }
+        }
+        catch (Exception $e)
+        {
+            $this->cn->rollback();
+            throw ($e);
+            return;
+        }
+        if ($transaction)
+            $this->cn->commit();
+        return;
+    }
+
+    /*!\brief update a card
+     */
+    function update($p_array=null)
+    {
+        global $g_user;
+        if ($p_array==null)
+            $p_array=$_POST;
+
+        try
+        {
+            $this->cn->start();
+            // parse the $p_array array
+            foreach ($p_array as $name=> $value)
+            {
+                if (preg_match('/^av_text[0-9]+$/', $name)==0)
+                    continue;
+
+                list ($id)=sscanf($name, "av_text%d");
+
+                if ($id==null)
+                    continue;
+
+                // retrieve jft_id to update table attr_value
+                $sql=" select jft_id from fiche_detail where ad_id=$id and 
f_id=$this->id";
+                $Ret=$this->cn->exec_sql($sql);
+                if (Database::num_row($Ret)==0)
+                {
+                    // we need to insert this new attribut
+                    $jft_id=$this->cn->get_next_seq('s_jnt_fic_att_value');
+
+                    $sql2="insert into 
fiche_detail(jft_id,ad_id,f_id,ad_value) values ($1,$2,$3,NULL)";
+
+                    $ret2=$this->cn->exec_sql($sql2,
+                            array($jft_id, $id, $this->id));
+                }
+                else
+                {
+                    $tmp=Database::fetch_array($Ret, 0);
+                    $jft_id=$tmp['jft_id'];
+                }
+                // Special traitement
+                // quickcode
+                if ($id==ATTR_DEF_QUICKCODE)
+                {
+                    $sql=sprintf("select update_quick_code(%d,'%s')", $jft_id,
+                            sql_string($value));
+                    $this->cn->exec_sql($sql);
+                    continue;
+                }
+                // name
+                if ($id==ATTR_DEF_NAME)
+                {
+                    if (strlen(trim($value))==0)
+                        continue;
+                }
+                // account
+                if ($id==ATTR_DEF_ACCOUNT)
+                {
+                    $v=sql_string($value);
+                    if (trim($v)!='')
+                    {
+                        if (strpos($v, ',')!=0)
+                        {
+                            $ac_array=explode(",", $v);
+                            if (count($ac_array)<>2)
+                                throw new Exception('Désolé, il y a trop de 
virgule dans le poste comptable '.h($v));
+                            $part1=$ac_array[0];
+                            $part2=$ac_array[1];
+                            $part1=$this->cn->get_value('select 
format_account($1)',
+                                    array($part1));
+                            $part2=$this->cn->get_value('select 
format_account($1)',
+                                    array($part2));
+                            $v=$part1.','.$part2;
+                        }
+                        else
+                        {
+                            $v=$this->cn->get_value('select 
format_account($1)',
+                                    array($value));
+                        }
+                        $sql=sprintf("select account_update(%d,'%s')",
+                                $this->id, $v);
+                        try
+                        {
+                            $this->cn->exec_sql($sql);
+                        }
+                        catch (Exception $e)
+                        {
+                            throw new Exception(__LINE__."Erreur : ce compte 
[$v] n'a pas de compte parent.".
+                            "L'op&eacute;ration est annul&eacute;e");
+                        }
+                        continue;
+                    }
+                    if (strlen(trim($v))==0)
+                    {
+
+                        $sql=sprintf("select account_update(%d,null)", 
$this->id);
+                        try
+                        {
+                            $Ret=$this->cn->exec_sql($sql);
+                        }
+                        catch (Exception $e)
+                        {
+                            throw new Exception(__LINE__."Erreur : ce compte 
[$v] n'a pas de compte parent.".
+                            "L'opération est annulée");
+                        }
+
+                        continue;
+                    }
+                }
+                // TVA
+                if ($id==ATTR_DEF_TVA)
+                {
+                    // Verify if the rate exists, if not then do not update
+                    if (strlen(trim($value))!=0)
+                    {
+                        if ($this->cn->count_sql("select * from tva_rate where 
tva_id=".$value)==0)
+                        {
+                            continue;
+                        }
+                    }
+                }
+                // Normal traitement
+                $sql="update fiche_detail set ad_value=$1 where jft_id=$2";
+                $this->cn->exec_sql($sql, array(strip_tags($value), $jft_id));
+            }
+        }
+        catch (Exception $e)
+        {
+            echo '<span class="error">'.
+            $e->getMessage().
+            '</span>';
+            $this->cn->rollback();
+            return;
+        }
+        $this->cn->commit();
+        return;
+    }
+
+    /*!\brief  remove a card
+    */
+    function remove($silent=false)
+    {
+        if ( $this->id==0 ) return;
+        // verify if that card has not been used is a ledger
+        // if the card has its own account in PCMN
+        // Get the fiche_def.fd_id from fiche.f_id
+        $this->Get();
+        $fiche_def=new Fiche_Def($this->cn,$this->fiche_def);
+        $fiche_def->get();
+
+        // if the card is used do not removed it
+        $qcode=$this->strAttribut(ATTR_DEF_QUICKCODE);
+
+        if ( $this->cn->count_sql("select * from jrnx where 
j_qcode='".Database::escape_string($qcode)."'") != 0)
+        {
+            if ( ! $silent ) {
+               alert(_('Impossible cette fiche est utilisée dans un journal'));
+            }
+            return 1;
+        }
+
+        $this->delete();
+               return 0;
+    }
+
+
+    /*!\brief return the name of a card
+     *
+     */
+    function getName()
+    {
+        $sql="select ad_value from fiche_detail
+             where ad_id=1 and f_id=$1";
+        $Res=$this->cn->exec_sql($sql,array($this->id));
+        $r=Database::fetch_all($Res);
+        if ( sizeof($r) == 0 )
+            return 1;
+        return $r[0]['ad_value'];
+    }
+
+    /*!\brief return the quick_code of a card
+     * \return null if not quick_code is found
+     */
+    function get_quick_code()
+    {
+        $sql="select ad_value from fiche_detail where ad_id=23 and f_id=$1";
+        $Res=$this->cn->exec_sql($sql,array($this->id));
+        $r=Database::fetch_all($Res);
+        if ( sizeof($r) == 0 )
+            return null;
+        return $r[0]['ad_value'];
+    }
+
+    /*!\brief Synonum of fiche::getAttribut
+     */
+    function Get()
+    {
+        $this->getAttribut();
+    }
+    /*!\brief Synonum of fiche::getAttribut
+     */
+    function load() 
+    {
+        $this->getAttribut();
+    }
+    /*!\brief get all the card thanks the fiche_def_ref
+     * \param $p_offset (default =-1)
+     * \param $p_search sql condition
+     * \return array of fiche object
+     */
+    function get_by_category($p_offset=-1,$p_search="",$p_order='')
+    {
+        return 
fiche::GetByDef($this->fiche_def_ref,$p_offset,$p_search,$p_order);
+    }
+    /*!\brief retrieve the frd_id of the fiche it is the type of the
+     *        card (bank, purchase...)
+     *        (fiche_def_ref primary key)
+     */
+    function get_fiche_def_ref_id()
+    {
+        $result=$this->cn->get_array("select frd_id from fiche join fiche_Def 
using (fd_id) where f_id=".$this->id);
+        if ( $result == null )
+            return null;
+
+        return $result[0]['frd_id'];
+    }
+    /**
+     address@hidden fetch and return and array
+     address@hidden get_row get_row_date
+     */
+    private function get_row_result($res)
+    {
+        $array=array();
+        $tot_cred=0.0;
+        $tot_deb=0.0;
+        $Max=Database::num_row($res);
+        if ( $Max == 0 ) return null;
+        for ($i=0;$i<$Max;$i++)
+        {
+            $array[]=Database::fetch_array($res,$i);
+            if ($array[$i]['j_debit']=='t')
+            {
+                $tot_deb+=$array[$i]['deb_montant'] ;
+            }
+            else
+            {
+                $tot_cred+=$array[$i]['cred_montant'] ;
+            }
+        }
+        $this->row=$array;
+        return array($array,$tot_deb,$tot_cred);
+    }
+    /*!
+     * \brief  Get data for poste
+     *
+     * \param  $p_from periode from
+     * \param  $p_to   end periode
+     *\param $op_let 0 all operation, 1 only lettered one, 2 only unlettered 
one
+     * \return double array 
(j_date,deb_montant,cred_montant,description,jrn_name,j_debit,jr_internal)
+     *         (tot_deb,tot_credit
+     *
+     */
+    function get_row_date($p_from,$p_to,$op_let=0)
+    {
+        global $g_user;
+        if ( $this->id == 0 )
+        {
+            echo_error("class_fiche",__LINE__,"id is 0");
+            return;
+        }
+        $filter_sql=$g_user->get_ledger_sql('ALL',3);
+        $sql_let='';
+        switch ($op_let)
+        {
+        case 0:
+            break;
+        case 1:
+            $sql_let=' and j_id in (select j_id from letter_cred union select 
j_id from letter_deb)';
+            break;
+        case '2':
+            $sql_let=' and j_id not in (select j_id from letter_cred union 
select j_id from letter_deb) ';
+            break;
+        }
+
+        $qcode=$this->strAttribut(ATTR_DEF_QUICKCODE);
+        $Res=$this->cn->exec_sql("select distinct 
substring(jr_pj_number,'[0-9]+$'),j_id,j_date,to_char(j_date,'DD.MM.YYYY') as 
j_date_fmt,j_qcode,".
+                                 "case when j_debit='t' then j_montant else 0 
end as deb_montant,".
+                                 "case when j_debit='f' then j_montant else 0 
end as cred_montant,".
+                                 " jr_comment as description,jrn_def_name as 
jrn_name,".
+                                " jr_pj_number,".
+                                 "j_debit, 
jr_internal,jr_id,coalesce(comptaproc.get_letter_jnt(j_id),-1) as letter, ".
+                                " jr_tech_per,p_exercice,jrn_def_name,
+                                                                 jrn_def_code".
+                                 " from jrnx left join jrn_def on 
jrn_def_id=j_jrn_def ".
+                                 " left join jrn on jr_grpt_id=j_grpt".
+                                " left join parm_periode on (p_id=jr_tech_per) 
".
+                                 " where j_qcode=$1 and ".
+                                 " ( to_date($2,'DD.MM.YYYY') <= j_date and ".
+                                 "   to_date($3,'DD.MM.YYYY') >= j_date )".
+                                 " and $filter_sql $sql_let ".
+                                 " order by 
j_date,substring(jr_pj_number,'[0-9]+$')",array($qcode,$p_from,$p_to));
+
+        return $this->get_row_result($Res);
+    }
+
+    /*!
+     * \brief  Get data for poste
+     *
+     * \param  $p_from periode from
+     * \param  $p_to   end periode
+     * \return double array 
(j_date,deb_montant,cred_montant,description,jrn_name,j_debit,jr_internal)
+     *         (tot_deb,tot_credit
+     *
+     */
+    function get_row($p_from,$p_to)
+    {
+        if ( $this->id == 0 )
+        {
+            echo_error("class_fiche",__LINE__,"id is 0");
+            return;
+        }
+        $qcode=$this->strAttribut(ATTR_DEF_QUICKCODE);
+        $periode=sql_filter_per($this->cn,$p_from,$p_to,'p_id','jr_tech_per');
+
+        $Res=$this->cn->exec_sql("select j_date,to_char(j_date,'DD.MM.YYYY') 
as j_date_fmt,j_qcode,".
+                                 "case when j_debit='t' then j_montant else 0 
end as deb_montant,".
+                                 "case when j_debit='f' then j_montant else 0 
end as cred_montant,".
+                                 " jr_comment as description,jrn_def_name as 
jrn_name,".
+                                 "j_debit, jr_internal,jr_id ".
+                                 " from jrnx left join jrn_def on 
jrn_def_id=j_jrn_def ".
+                                 " left join jrn on jr_grpt_id=j_grpt".
+                                 " where j_qcode='".$qcode."' and ".$periode.
+                                 " order by j_date::date");
+        return $this->get_row_result($Res);
+
+    }
+    /*!
+     * \brief HtmlTable, display a HTML of a card for the asked period
+     *\param $op_let 0 all operation, 1 only lettered one, 2 only unlettered 
one
+     * \return none
+     */
+    function HtmlTableDetail($p_array=null,$op_let=0)
+    {
+        if ( $p_array == null)
+            $p_array=$_REQUEST;
+
+        $name=$this->getName();
+
+        list($array,$tot_deb,$tot_cred)=$this->get_row_date( 
$p_array['from_periode'],
+                                        $p_array['to_periode'],
+                                        $op_let
+                                                           );
+
+        if ( count($this->row ) == 0 )
+            return;
+        $qcode=$this->strAttribut(ATTR_DEF_QUICKCODE);
+
+        $rep="";
+        $already_seen=array();
+        echo '<h2 class="info">'.$this->id." ".$name.'</h2>';
+        echo "<TABLE class=\"result\" 
style=\"width:100%;border-collapse:separate;border-spacing:5px\">";
+        echo "<TR>".
+        "<TH>"._("n° de pièce / Code interne")." </TH>".
+        "<TH>"._("Date")."</TH>".
+        "<TH>"._("Description")." </TH>".
+        "<TH>"._('Montant')."  </TH>".
+        "<TH> "._('Débit/Crédit')." </TH>".
+        "</TR>";
+
+        foreach ( $this->row as $op )
+        {
+            if ( in_array($op['jr_internal'],$already_seen) )
+                continue;
+            else
+                $already_seen[]=$op['jr_internal'];
+            echo "<TR  
style=\"text-align:center;background-color:lightgrey\">".
+            "<td>".$op['jr_pj_number']." / ".$op['jr_internal']."</td>".
+            "<td>".$op['j_date']."</td>".
+            "<td>".h($op['description'])."</td>".
+            "<td>"."</td>".
+            "<td>"."</td>".
+            "</TR>";
+            $ac=new Acc_Operation($this->cn);
+            $ac->jr_id=$op['jr_id'];
+            $ac->qcode=$qcode;
+            echo $ac->display_jrnx_detail(1);
+
+        }
+        $solde_type=($tot_deb>$tot_cred)?_("solde débiteur"):_("solde 
créditeur");
+        $diff=round(abs($tot_deb-$tot_cred),2);
+        echo "<TR>".
+        "<TD>$solde_type".
+        "<TD>$diff</TD>".
+        "<TD></TD>".
+        "<TD>$tot_deb</TD>".
+        "<TD>$tot_cred</TD>".
+        "</TR>";
+
+        echo "</table>";
+
+        return;
+    }
+    /*!
+     * \brief HtmlTable, display a HTML of a card for the asked period
+     * \param $p_array default = null keys = from_periode, to_periode
+     *\param $op_let 0 all operation, 1 only lettered one, 2 only unlettered 
one
+     *\return -1 if nothing is found otherwise 0
+     *\see get_row_date
+     */
+    function HtmlTable($p_array=null,$op_let=0,$from_div=1)
+    {
+        if ( $p_array == null)
+            $p_array=$_REQUEST;
+        $progress=0;
+               // if from_periode is greater than to periode then swap the 
values
+               if (cmpDate($p_array['from_periode'],$p_array['to_periode']) > 
0)
+               {
+                       $tmp=$p_array['from_periode'];
+                       $p_array['from_periode']=$p_array['to_periode'];
+                       $p_array['to_periode']=$tmp;
+
+               }
+        list($array, $tot_deb, $tot_cred) = 
$this->get_row_date($p_array['from_periode'], $p_array['to_periode'], $op_let);
+
+        if ( count($this->row ) == 0 )
+            return -1;
+
+        $rep="";
+       if ( $from_div==1)
+         {
+           echo "<TABLE class=\"resultfooter\" 
style=\"margin:1%;width:98%;;border-collapse:separate;border-spacing:0px 
5px\">";
+         }
+       else
+         {
+           echo "<TABLE id=\"tb" . $from_div . "\"class=\"result\" 
style=\"margin:1%;width:98%;border-collapse:separate;border-spacing:0px 2px\">";
+               }
+        echo '<tbody>';
+        echo "<TR>".
+        "<TH style=\"text-align:left\">"._('Date')."</TH>".
+        "<TH style=\"text-align:left\">"._('n° pièce')." </TH>".
+        "<TH style=\"text-align:left\">"._('Code interne')." </TH>".
+        "<TH style=\"text-align:left\">"._('Description')." </TH>".
+        "<TH style=\"text-align:right\">"._('Débit')."  </TH>".
+        "<TH style=\"text-align:right\">"._('Crédit')." </TH>".
+        th('Prog.','style="text-align:right"').
+        th('Let.','style="text-align:right"');
+        "</TR>"
+        ;
+       $old_exercice="";$sum_deb=0;$sum_cred=0;
+       bcscale(2);
+       $idx=0;
+        foreach ( $this->row as $op )
+        {
+            $vw_operation = sprintf('<A class="detail" 
style="text-decoration:underline;color:red" 
HREF="javascript:modifyOperation(\'%s\',\'%s\')" >%s</A>', $op['jr_id'], 
dossier::id(), $op['jr_internal']);
+            $let = '';
+                       $html_let = "";
+                       if ($op['letter'] != -1)
+                       {
+                               $let = strtoupper(base_convert($op['letter'], 
10, 36));
+                               $html_let = 
HtmlInput::show_reconcile($from_div, $let);
+                       }
+                       $tmp_diff=bcsub($op['deb_montant'],$op['cred_montant']);
+
+           /*
+            * reset prog. balance to zero if we change of exercice
+            */
+           if ( $old_exercice != $op['p_exercice'])
+             {
+               if ($old_exercice != '' )
+                 {
+                   $progress=bcsub($sum_deb,$sum_cred);
+                       $side="&nbsp;".$this->get_amount_side($progress);
+                   echo "<TR class=\"highlight\">".
+                      "<TD>$old_exercice</TD>".
+                     td('').
+                     "<TD></TD>".
+                     "<TD>Totaux</TD>".
+                     "<TD style=\"text-align:right\">".nbm($sum_deb)."</TD>".
+                     "<TD style=\"text-align:right\">".nbm($sum_cred)."</TD>".
+                     td(nbm(abs($progress)).$side,'style="text-align:right"').
+                     td('').
+                     "</TR>";
+                   $sum_cred=0;
+                   $sum_deb=0;
+                   $progress=0;
+                 }
+             }
+            $progress=bcadd($progress,$tmp_diff);
+                       $side="&nbsp;".$this->get_amount_side($progress);
+           $sum_cred=bcadd($sum_cred,$op['cred_montant']);
+           $sum_deb=bcadd($sum_deb,$op['deb_montant']);
+               if ($idx%2 == 0) $class='class="odd"'; else $class=' 
class="even"';
+               $idx++;
+
+           echo "<TR $class name=\"tr_" . $let . "_" . $from_div . "\">" .
+                       
"<TD>".smaller_date(format_date($op['j_date_fmt']))."</TD>".
+             td(h($op['jr_pj_number'])).
+            "<TD>".$vw_operation."</TD>".
+            "<TD>".h($op['description'])."</TD>".
+            "<TD style=\"text-align:right\">".nbm($op['deb_montant'])."</TD>".
+             "<TD 
style=\"text-align:right\">".nbm($op['cred_montant'])."</TD>".
+             td(nbm(abs($progress)).$side,'style="text-align:right"').
+            td($html_let, ' style="text-align:right"') .
+                       "</TR>";
+           $old_exercice=$op['p_exercice'];
+
+        }
+        $solde_type=($sum_deb>$sum_cred)?"solde débiteur":"solde créditeur";
+        $diff=abs(bcsub($sum_deb,$sum_cred));
+        echo '<tfoot>';
+       echo "<TR class=\"highlight\">".
+        "<TD>Totaux</TD>".
+        "<TD ></TD>".
+        "<TD ></TD>".
+        "<TD></TD>".
+        "<TD  style=\"text-align:right\">".nbm($sum_deb)."</TD>".
+        "<TD  style=\"text-align:right\">".nbm($sum_cred)."</TD>".
+         "<TD style=\"text-align:right\">".nbm($diff)."</TD>".
+
+        "</TR>";
+        echo "<TR style=\"font-weight:bold\">".
+        "<TD>$solde_type</TD>".
+         "<TD style=\"text-align:right\">".nbm($diff)."</TD>".
+        "<TD></TD>".
+        "</TR>";
+        echo '</tfoot>';
+        echo '</tbody>';
+
+        echo "</table>";
+
+        return 0;
+    }
+    /*!
+     * \brief Display HTML Table Header (button)
+     *
+     * \return none
+     */
+    function HtmlTableHeader($p_array=null)
+    {
+        if ( $p_array == null)
+            $p_array=$_REQUEST;
+
+        $hid=new IHidden();
+        echo '<div class="noprint">';
+        echo "<table >";
+        echo '<TR>';
+
+        echo '<TD><form method="GET" ACTION="">'.
+            HtmlInput::submit('bt_other',"Autre poste").
+            HtmlInput::array_to_hidden(array('gDossier','ac'), $_REQUEST).
+            dossier::hidden().
+            
$hid->input("type","poste").$hid->input('p_action','impress')."</form></TD>";
+        
$str_ople=(isset($_REQUEST['ople']))?HtmlInput::hidden('ople',$_REQUEST['ople']):'';
+
+        echo '<TD><form method="GET" ACTION="export.php">'.
+            HtmlInput::submit('bt_pdf',_("Export PDF")).
+            dossier::hidden().$str_ople.
+              HtmlInput::hidden('act','PDF:fichedetail').
+            $hid->input("type","poste").
+            $hid->input('p_action','impress').
+            $hid->input("f_id",$this->id).
+            dossier::hidden().
+            $hid->input("from_periode",$p_array['from_periode']).
+            $hid->input("to_periode",$p_array['to_periode']);
+        if (isset($p_array['oper_detail']))
+            echo $hid->input('oper_detail','on');
+
+        echo "</form></TD>";
+
+        echo '<TD><form method="GET" ACTION="export.php">'.
+        HtmlInput::submit('bt_csv',_("Export CSV")).
+         HtmlInput::hidden('act','CSV:fichedetail').
+        dossier::hidden().$str_ople.
+        $hid->input("type","poste").
+        $hid->input('p_action','impress').
+        $hid->input("f_id",$this->id).
+        $hid->input("from_periode",$p_array['from_periode']).
+        $hid->input("to_periode",$p_array['to_periode']);
+        if (isset($p_array['oper_detail']))
+            echo $hid->input('oper_detail','on');
+
+        echo "</form></TD>";
+               echo "</form></TD>";
+               echo '<td style="vertical-align:top">';
+               echo HtmlInput::print_window();
+               echo '</td>';
+        echo "</table>";
+        echo '</div>';
+
+    }
+    /*!
+     * \brief   give the balance of an card
+     * \return
+     *      balance of the card
+     *
+     */
+    function get_solde_detail($p_cond="")
+    {
+        if ( $this->id == 0 ) return array('credit'=>0,'debit'=>0,'solde'=>0);
+        $qcode=$this->strAttribut(ATTR_DEF_QUICKCODE);
+
+        if ( $p_cond != "") $p_cond=" and ".$p_cond;
+        $Res=$this->cn->exec_sql("select sum(deb) as sum_deb, sum(cred) as 
sum_cred from
+                                 ( select j_poste,
+                                 case when j_debit='t' then j_montant else 0 
end as deb,
+                                 case when j_debit='f' then j_montant else 0 
end as cred
+                                 from jrnx
+                                 where
+                                 j_qcode = ('$qcode'::text)
+                                 $p_cond
+                                 ) as m  ");
+        $Max=Database::num_row($Res);
+        if ($Max==0) return 0;
+        $r=Database::fetch_array($Res,0);
+
+        return array('debit'=>$r['sum_deb'],
+                     'credit'=>$r['sum_cred'],
+                     'solde'=>abs($r['sum_deb']-$r['sum_cred']));
+    }
+    /**
+     *get the bank balance with receipt or not
+     *
+     */
+    function get_bk_balance($p_cond="")
+    {
+        if ( $this->id == 0 ) throw  new Exception('fiche->id est nul');
+        $qcode=$this->strAttribut(ATTR_DEF_QUICKCODE);
+
+        if ( $p_cond != "") $p_cond=" and ".$p_cond;
+       $sql="select sum(deb) as sum_deb, sum(cred) as sum_cred from
+                                 ( select j_poste,
+                                 case when j_debit='t' then j_montant else 0 
end as deb,
+                                 case when j_debit='f' then j_montant else 0 
end as cred
+                                 from jrnx
+                                 join jrn on (jr_grpt_id=j_grpt)
+                                 where
+                                 j_qcode = ('$qcode'::text)
+                                 $p_cond
+                                 ) as m  ";
+
+        $Res=$this->cn->exec_sql($sql);
+        $Max=Database::num_row($Res);
+        if ($Max==0) return 0;
+        $r=Database::fetch_array($Res,0);
+
+        return array('debit'=>$r['sum_deb'],
+                     'credit'=>$r['sum_cred'],
+                     'solde'=>abs($r['sum_deb']-$r['sum_cred']));
+
+    }
+    /*!\brief check if an attribute is empty
+     *\param $p_attr the id of the attribut to check (ad_id)
+     *\return return true is the attribute is empty or missing
+     */
+    function empty_attribute($p_attr)
+    {
+        $sql="select ad_value
+             from fiche_detail
+             natural join fiche
+             left join attr_def using (ad_id) where f_id=".$this->id.
+             " and ad_id = ".$p_attr.
+             " order by ad_id";
+        $res=$this->cn->exec_sql($sql);
+        if ( Database::num_row($res) == 0 ) return true;
+        $text=Database::fetch_result($res,0,0);
+        return (strlen(trim($text)) > 0)?false:true;
+
+
+    }
+    /*! Summary
+     * \brief  show the default screen
+     *
+     * \param $p_search (filter)
+     * \param $p_action used for specific action bank, red if credit < debit
+     * \param $p_sql SQL to filter the number of card must start with AND
+     * \param $p_amount true : only cards with at least one operation default 
: false
+     * \return: string to display
+     */
+    function Summary($p_search="",$p_action="",$p_sql="",$p_amount=false)
+    {
+        global $g_user;
+        $bank=new Acc_Parm_Code($this->cn,'BANQUE');
+        $cash=new Acc_Parm_Code($this->cn,'CAISSE');
+        $cc=new Acc_Parm_Code($this->cn,'COMPTE_COURANT');
+        
+        bcscale(4);
+        $gDossier=dossier::id();
+        $p_search=sql_string($p_search);
+        $script=$_SERVER['PHP_SELF'];
+        // Creation of the nav bar
+        // Get the max numberRow
+        $filter_amount='';
+        global $g_user;
+
+        $filter_year="  j_tech_per in (select p_id from parm_periode ".
+                     "where p_exercice='".$g_user->get_exercice()."')";
+
+        if ( $p_amount) $filter_amount=' and f_id in (select f_id from jrnx 
where  '.$filter_year.')';
+
+        
$all_tiers=$this->count_by_modele($this->fiche_def_ref,"",$p_sql.$filter_amount);
+        // Get offset and page variable
+        $offset=( isset ($_REQUEST['offset'] )) ?$_REQUEST['offset']:0;
+        $page=(isset($_REQUEST['page']))?$_REQUEST['page']:1;
+        $bar=navigation_bar($offset,$all_tiers,$_SESSION['g_pagesize'],$page);
+
+        // set a filter ?
+        $search=$p_sql;
+
+        $exercice=$g_user->get_exercice();
+        $tPeriode=new Periode($this->cn);
+        list($max,$min)=$tPeriode->get_limit($exercice);
+
+
+        if ( trim($p_search) != "" )
+        {
+            $search.=" and f_id in
+                     (select distinct f_id from fiche_detail
+                     where
+                     ad_id in (1,32,30,23,18,13) and ad_value ~* '$p_search')";
+        }
+        // Get The result Array
+        
$step_tiers=$this->get_by_category($offset,$search.$filter_amount,'name');
+
+        if ( $all_tiers == 0 || count($step_tiers)==0 ) return "";
+        $r="";
+        $r.=_("Filtre rapide ").HtmlInput::filter_table("tiers_tb", '0,1,2', 
1);
+        $r.=$bar;
+        
+        $r.='<table  id="tiers_tb" class="sortable"  
style="width:90%;margin-left:5%">
+            <TR >
+            <TH>'._('Quick Code').HtmlInput::infobulle(17).'</TH>'.
+            '<th>'._('Poste comptable').'</th>'.
+            '<th  class="sorttable_sorted_reverse">'._('Nom').'<span 
id="sorttable_sortrevind">&nbsp;&blacktriangle;</span>'.'</th>
+            <th>'._('Adresse').'</th>
+            <th style="text-align:right">'._('Total débit').'</th>
+            <th style="text-align:right">'._('Total crédit').'</th>
+            <th style="text-align:right">'._('Solde').'</th>';
+        $r.='</TR>';
+        if ( sizeof ($step_tiers ) == 0 )
+            return $r;
+
+        $i=0;
+               $deb=0;$cred=0;
+        foreach ($step_tiers as $tiers )
+        {
+            $i++;
+            
+             /* Filter on the default year */
+             $amount=$tiers->get_solde_detail($filter_year);
+
+            /* skip the tiers without operation */
+            if ( $p_amount && $amount['debit']==0 && $amount['credit'] == 0 && 
$amount['solde'] == 0 ) continue;
+
+            $odd="";
+             $odd  = ($i % 2 == 0 ) ? ' odd ': ' even ';
+             $accounting=$tiers->strAttribut(ATTR_DEF_ACCOUNT);
+             if ( $p_action == 'bank' && $amount['debit'] <  $amount['credit'] 
 ){
+                 if ( strpos($accounting,$bank->p_value)===0 || 
strpos($accounting,$cash->p_value)===0 || strpos($accounting,$cc->p_value)===0){
+                 //put in red if c>d
+                 $odd.=" notice ";
+                 }
+             }
+        
+             $odd=' class="'.$odd.'"';
+             
+            $r.="<TR $odd>";
+            
$url_detail=$script.'?'.http_build_query(array('sb'=>'detail','sc'=>'sv','ac'=>$_REQUEST['ac'],'f_id'=>$tiers->id,'gDossier'=>$gDossier));
+            $e=sprintf('<A HREF="%s" title="Détail" class="line"> ',
+                       $url_detail);
+
+            $r.="<TD> $e".$tiers->strAttribut(ATTR_DEF_QUICKCODE)."</A></TD>";
+            $r.="<TD> $e".$accounting."</TD>";
+            $r.="<TD>".h($tiers->strAttribut(ATTR_DEF_NAME))."</TD>";
+            $r.="<TD>".h($tiers->strAttribut(ATTR_DEF_ADRESS).
+                         " ".$tiers->strAttribut(ATTR_DEF_CP).
+                         " ".$tiers->strAttribut(ATTR_DEF_PAYS)).
+                "</TD>";
+            $str_deb=(($amount['debit']==0)?0:nbm($amount['debit']));
+            $str_cred=(($amount['credit']==0)?0:nbm($amount['credit']));
+            $str_solde=nbm($amount['solde']);
+            $r.='<TD sorttable_customkey="'.$amount['debit'].'" align="right"> 
'.$str_deb.'</TD>';
+            $r.='<TD sorttable_customkey="'.$amount['credit'].'" 
align="right"> '.$str_cred.'</TD>';
+            $side=($amount['debit'] >  $amount['credit'])?'D':'C';
+            $side=($amount['debit'] ==  $amount['credit'])?'=':$side;
+            $red="";
+            if ( $p_action == 'customer' && $amount['debit'] <  
$amount['credit']  ){
+                 //put in red if d>c
+                 $red=" notice ";
+             }
+             if ( $p_action == 'supplier' && $amount['debit'] >  
$amount['credit']  ){
+                 //put in red if c>d
+                 $red=" notice ";
+             }
+            $r.='<TD class="'.$red.'" 
sorttable_customkey="'.$amount['solde'].'" align="right"> '.$str_solde."$side 
</TD>";
+            $deb=bcadd($deb,$amount['debit']);
+            $cred=bcadd($cred,$amount['credit']);
+
+            $r.="</TR>";
+
+        }
+               $r.="<tfoot >";
+               $solde=abs(bcsub($deb,$cred));
+                $side=($deb > $cred)?'Débit':'Crédit';
+                $r.='<tr class="highlight">';
+               
$r.=td("").td("").td("").td("Totaux").td(nbm($deb),'class="num"').td(nbm($cred),'class="num"').td("
 $side ".nbm($solde),'class="num"');
+                $r.='</tr>';
+               $r.="</tfoot>";
+        $r.="</TABLE>";
+        $r.=$bar;
+        return $r;
+    }
+    /*!
+     * \brief get the fd_id of the card : fd_id, it set the attribute fd_id
+     */
+    function get_categorie()
+    {
+        if ( $this->id == 0 ) throw  new Exception('class_fiche : f_id = 0 ');
+        $sql='select fd_id from fiche where f_id='.$this->id;
+        $R=$this->cn->get_value($sql);
+        if ( $R == "" )
+            $this->fd_id=0;
+        else
+            $this->fd_id=$R;
+    }
+    /*!
+     ***************************************************
+     * \brief   Check if a fiche is used by a jrn
+     *  return 1 if the  fiche is in the range otherwise 0, the quick_code
+     *  or the id  must be set
+     *
+     *
+     * \param   $p_jrn journal_id
+     * \param   $p_type : deb or cred default empty
+     *
+     * \return 1 if the fiche is in the range otherwise < 1
+     *        -1 the card doesn't exist
+     *        -2 the ledger has no card to check
+     *
+     */
+    function belong_ledger($p_jrn,$p_type="")
+    {
+        // check if we have a quick_code or a f_id
+        if (($this->quick_code==null || $this->quick_code == "" )
+                && $this->id == 0 )
+        {
+            throw  new Exception( 'erreur ni quick_code ni f_id ne sont 
donnes');
+        }
+
+        //retrieve the quick_code
+        if ( $this->quick_code=="")
+            $this->quick_code=$this->get_quick_code();
+
+
+        if ( $this->quick_code==null)
+            return -1;
+
+        if ( $this->id == 0 )
+            if ( $this->get_by_qcode(null,false) == 1)
+                return -1;
+
+        $get="";
+        if ( $p_type == 'deb' )
+        {
+            $get='jrn_def_fiche_deb';
+        }
+        if ( $p_type == 'cred' )
+        {
+            $get='jrn_def_fiche_cred';
+        }
+        if ( $get != "" )
+        {
+            $Res=$this->cn->exec_sql("select $get as fiche from jrn_def where 
jrn_def_id=$p_jrn");
+        }
+        else
+        {
+            // Get all the fiche type (deb and cred)
+            $Res=$this->cn->exec_sql(" select jrn_def_fiche_cred as fiche
+                                     from jrn_def where jrn_def_id=$p_jrn
+                                     union
+                                     select jrn_def_fiche_deb
+                                     from jrn_def where jrn_def_id=$p_jrn"
+                                    );
+        }
+        $Max=Database::num_row($Res);
+        if ( $Max==0)
+        {
+            return -2;
+        }
+        /* convert the array to a string */
+        $list=Database::fetch_all($Res);
+        $str_list="";
+        $comma='';
+        foreach ($list as $row)
+        {
+            if ( $row['fiche'] != '' )
+            {
+                $str_list.=$comma.$row['fiche'];
+                $comma=',';
+            }
+        }
+        // Normally Max must be == 1
+
+        if ( $str_list=="")
+        {
+            return -3;
+        }
+
+        $sql="select *
+             from fiche
+             where
+             fd_id in (".$str_list.") and f_id= ".$this->id;
+
+        $Res=$this->cn->exec_sql($sql);
+        $Max=Database::num_row($Res);
+        if ($Max==0 )
+            return 0;
+        else
+            return 1;
+    }
+    /*!\brief  get all the card from a categorie
+     *\param $p_cn database connx
+     *\param $pFd_id is the category id
+     *\param $p_order for the sort, possible values is name_asc,name_desc or 
nothing
+     *\return an array of card, but only the fiche->id is set
+     */
+    static function get_fiche_def($p_cn,$pFd_id,$p_order='')
+    {
+        switch ($p_order)
+        {
+        case 'name_asc':
+            $sql='select f_id,ad_value from fiche join fiche_detail using 
(f_id) where ad_id=1 and fd_id=$1 order by 2 asc';
+            break;
+        case 'name_desc':
+            $sql='select f_id,ad_value from fiche join fiche_detail using 
(f_id) where ad_id=1 and fd_id=$1 order by 2 desc';
+            break;
+        default:
+            $sql='select f_id from fiche  where fd_id=$1 ';
+        }
+        $array=$p_cn->get_array($sql,array($pFd_id));
+
+       return $array;
+    }
+    /*!\brief check if a card is used
+     *\return return true is a card is used otherwise false
+     */
+    function is_used()
+    {
+        /* retrieve first the quickcode */
+        $qcode=$this->strAttribut(ATTR_DEF_QUICKCODE);
+        $sql='select count(*) as c from jrnx where j_qcode=$1';
+        $count=$this->cn->get_value($sql,array($qcode));
+        if ( $count == 0 ) return false;
+        return true;
+    }
+    /*\brief remove a card without verification */
+    function delete()
+    {
+        // Remove from attr_value
+        $Res=$this->cn->exec_sql("delete from fiche_detail
+                                 where
+                                   f_id=".$this->id);
+
+        // Remove from fiche
+        $Res=$this->cn->exec_sql("delete from fiche where f_id=".$this->id);
+
+    }
+    /*!\brief create the sql statement for retrieving all
+     * the card
+     *\return string with sql statement
+     *\param $array contains the condition
+    \verbatim
+       [jrn] => 2
+       [typecard] => cred / deb / filter or list
+       [query] => string
+    \endverbatim
+     *\note the typecard cred, deb or filter must be used with jrn, the value 
of list means a list of fd_id
+     *\see ajax_card.php cards.js
+     */
+    function build_sql($array)
+    {
+        if (!empty($array))
+            extract($array);
+        $and='';
+        $filter_fd_id='true';
+        $filter_query='';
+        if (isset($typecard))
+        {
+            if (strpos($typecard, "sql")==false)
+            {
+                switch ($typecard)
+                {
+                    case 'cred':
+                        if (!isset($jrn))
+                            throw ('Erreur pas de valeur pour jrn');
+                        $filter_jrn=$this->cn->make_list("select 
jrn_def_fiche_cred from jrn_Def where jrn_def_id=$1",
+                                array($jrn));
+                        $filter_fd_id=" fd_id in (".$filter_jrn.")";
+                        $and=" and ";
+                        break;
+                    case 'deb':
+                        if (!isset($jrn))
+                            throw ('Erreur pas de valeur pour jrn');
+                        $filter_jrn=$this->cn->make_list("select 
jrn_def_fiche_deb from jrn_Def where jrn_def_id=$1",
+                                array($jrn));
+                        $filter_fd_id=" fd_id in (".$filter_jrn.")";
+                        $and=" and ";
+                        break;
+                    case 'filter':
+                        if (!isset($jrn))
+                            throw ('Erreur pas de valeur pour jrn');
+                        $filter_jrn=$this->cn->make_list("select 
jrn_def_fiche_deb from jrn_Def where jrn_def_id=$1",
+                                array($jrn));
+
+                        if (trim($filter_jrn)!='')
+                            $fp1=" fd_id in (".$filter_jrn.")";
+                        else
+                            $fp1="fd_id < 0";
+
+                        $filter_jrn=$this->cn->make_list("select 
jrn_def_fiche_cred from jrn_Def where jrn_def_id=$1",
+                                array($jrn));
+
+                        if (trim($filter_jrn)!='')
+                            $fp2=" fd_id in (".$filter_jrn.")";
+                        else
+                            $fp2="fd_id < 0";
+
+                        $filter_fd_id='('.$fp1.' or '.$fp2.')';
+
+                        $and=" and ";
+                        break;
+                    case 'all':
+                        $filter_fd_id=' true';
+                        break;
+                    default:
+                        if (trim($typecard)!='')
+                            $filter_fd_id=' fd_id in ('.$typecard.')';
+                        else
+                            $filter_fd_id=' fd_id < 0';
+                }
+            }
+            else
+            {
+                $filter_fd_id=str_replace('[sql]', '', $typecard);
+            }
+        }
+
+        $and=" and ";
+        if (isset($query))
+        {
+            $query=sql_string($query);
+
+            if (strlen(trim($query))>1)
+            {
+                $filter_query=$and."(vw_name ilike '%$query%' or quick_code 
ilike ('%$query%') "
+                        ." or vw_description ilike '%$query%' or tva_num ilike 
'%$query%' or accounting like upper('$query%'))";
+            }
+            else
+            {
+                $filter_query='';
+            }
+        }
+        $sql="select * from vw_fiche_attr where ".$filter_fd_id.$filter_query;
+        return $sql;
+    }
+
+    /**
+     address@hidden move a card to another cat. The properties will changed
+     * and be removed
+     address@hidden $p_fdid the fd_id of destination
+     */
+    function move_to($p_fdid)
+    {
+        $this->cn->start();
+        $this->cn->exec_sql('update fiche set fd_id=$1 where 
f_id=$2',array($p_fdid,$this->id));
+        // add missing
+        $this->cn->exec_sql('select 
fiche_attribut_synchro($1)',array($p_fdid));
+        // add to the destination missing fields
+        $this->cn->exec_sql("insert into jnt_fic_attr (fd_id,ad_id,jnt_order) 
select $1,ad_id,100 from fiche_detail where f_id=$2 and ad_id not in (select 
ad_id from jnt_fic_attr where fd_id=$3)",array($p_fdid,$this->id,$p_fdid));
+        $this->cn->commit();
+    }
+    /**
+     * return the letter C if amount is > 0, D if < 0 or =
+     * @param type $p_amount
+     * @return string
+     */
+    function get_amount_side($p_amount)
+    {
+            if ($p_amount == 0)
+                    return "=";
+            if ($p_amount < 0)
+                    return "C";
+            if ($p_amount > 0)
+                    return "D";
+    }
+    static function test_me()
+    {
+        $cn=new Database(dossier::id());
+        $a=new Fiche($cn);
+        $select_cat=new ISelect('fd_id');
+        $select_cat->value=$cn->make_array('select fd_id,fd_label from 
fiche_def where frd_id='.
+                                           FICHE_TYPE_CLIENT);
+        echo '<FORM METHOD="GET"> ';
+        echo dossier::hidden();
+        echo HtmlInput::hidden('test_select',$_GET['test_select']);
+        echo 'Choix de la catégorie';
+        echo $select_cat->input();
+        echo HtmlInput::submit('go_card','Afficher');
+        echo '</form>';
+        if ( isset ($_GET['go_card']))
+        {
+            $empty=$a->to_array($_GET['fd_id']);
+            print_r($empty);
+        }
+    }
+
+       function get_gestion_title()
+       {
+               $r = "<h2>" . h($this->getName()) . " " . 
h($this->getAttribut(ATTR_DEF_FIRST_NAME)) . '[' . $this->get_quick_code() . 
']</h2>';
+               return $r;
+       }
+       function get_all_account()
+       {
+
+       }
+}
+
+?>
diff --git a/include/class/class_fiche_attr.php 
b/include/class/class_fiche_attr.php
new file mode 100644
index 0000000..eaf1d22
--- /dev/null
+++ b/include/class/class_fiche_attr.php
@@ -0,0 +1,284 @@
+<?php
+//This file is part of NOALYSS and is under GPL 
+//see licence.txt
+/**
+ address@hidden Manage the table attr_def
+ *
+ *
+ */
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
+
+class Fiche_Attr
+{
+    /* example private 
$variable=array("easy_name"=>column_name,"email"=>"column_name_email","val3"=>0);
 */
+
+    protected 
$variable=array("id"=>"ad_id","desc"=>"ad_text","type"=>"ad_type","size"=>"ad_size","extra"=>"ad_extra");
+    function __construct ($p_cn,$p_id=0)
+    {
+        $this->cn=$p_cn;
+        if ( $p_id == 0 )
+        {
+            /* Initialize an empty object */
+            foreach ($this->variable as $key=>$value) $this->$value='';
+        }
+        else
+        {
+            /* load it */
+            $this->ad_id=$p_id;
+            $this->load();
+        }
+    }
+    public function get_parameter($p_string)
+    {
+        if ( array_key_exists($p_string,$this->variable) )
+        {
+            $idx=$this->variable[$p_string];
+            return $this->$idx;
+        }
+        else
+            throw new Exception (__FILE__.":".__LINE__.$p_string.'Erreur 
attribut inexistant');
+    }
+    public function set_parameter($p_string,$p_value)
+    {
+        if ( array_key_exists($p_string,$this->variable) )
+        {
+            $idx=$this->variable[$p_string];
+            $this->$idx=$p_value;
+        }
+        else
+            throw new Exception (__FILE__.":".__LINE__.$p_string.'Erreur 
attribut inexistant');
+    }
+    public function get_info()
+    {
+        return var_export($this,true);
+    }
+    public function verify()
+    {
+        // Verify that the elt we want to add is correct
+        /* verify only the datatype */
+        if ( strlen(trim($this->ad_text))==0)
+            throw new Exception('La description ne peut pas être vide',1);
+        if ( strlen(trim($this->ad_type))==0)
+            throw new Exception('Le type ne peut pas être vide',1);
+        $this->ad_type=strtolower($this->ad_type);
+        if ( 
in_array($this->ad_type,array('date','text','numeric','zone','poste','card','select'))==false)
+            throw new Exception('Le type doit être text, numeric,poste, card, 
select ou date',1);
+        if ( trim($this->ad_size)=='' || 
isNumber($this->ad_size)==0||$this->ad_size>22)
+        {
+            switch ($this->ad_type)
+            {
+            case 'text':
+                    $this->ad_size=22;
+                break;
+            case 'numeric':
+                $this->ad_size=9;
+                break;
+            case 'date':
+                $this->ad_size=8;
+                break;
+            case 'zone':
+                $this->ad_size=22;
+                break;
+
+            default:
+                $this->ad_size=22;
+            }
+        }
+               if ( $this->ad_type == 'numeric' ) {
+                       
$this->ad_extra=(trim($this->ad_extra)=='')?'2':$this->ad_extra;
+                       if (isNumber($this->ad_extra) == 0) throw new Exception 
("La précision doit être un chiffre");
+
+               }
+               if ( $this->ad_type == 'select')
+        {
+                if (trim($this->ad_extra)=="") throw new Exception ("La 
requête SQL est vide ");
+               if ( preg_match('/^\h*select/i',$this->ad_extra)  == 0) throw 
new Exception ("La requête SQL doit commencer par SELECT ");
+                try{
+
+                        $this->cn->exec_sql($this->ad_extra);
+                }catch (Exception $e)
+                {
+                    throw new Exception ("La requête SQL 
".h($this->ad_extra)." est invalide ");
+                }
+        }
+    }
+    public function save()
+    {
+
+        /* please adapt */
+        if (  $this->ad_id == 0 )
+            $this->insert();
+        else
+            $this->update();
+    }
+    /**
+     address@hidden retrieve array of object thanks a condition
+     address@hidden $cond condition (where clause)
+     address@hidden $p_array array for the SQL stmt
+     address@hidden Database::get_array
+     address@hidden an empty array if nothing is found
+     */
+    public function seek($cond='',$p_array=null)
+    {
+        if ( $cond != '')
+            $sql="select * from attr_def where $cond order by ad_text";
+        else
+            $sql="select * from attr_def order by ad_text";
+
+        $aobj=array();
+        $array= $this->cn->get_array($sql,$p_array);
+        // map each row in a object
+        $size=$this->cn->count();
+        if ( $size == 0 ) return $aobj;
+        for ($i=0;$i<$size;$i++)
+        {
+            $oobj=new Fiche_Attr ($this->cn);
+            foreach ($array[$i] as $idx=>$value)
+            {
+                $oobj->$idx=$value;
+            }
+            $aobj[]=clone $oobj;
+        }
+        return $aobj;
+    }
+    public function insert()
+    {
+        try{
+        $this->verify();
+        /*  please adapt */
+        $sql="insert into attr_def(ad_text
+             ,ad_type,ad_size,ad_extra
+             ) values ($1
+             ,$2,$3,$4
+             ) returning ad_id";
+
+        $this->ad_id=$this->cn->get_value(
+                         $sql,
+                         array( 
$this->ad_text,$this->ad_type,$this->ad_size,$this->ad_extra
+                              )
+                     );
+        } catch (Exception $e)
+        {
+            throw $e;
+        }
+
+    }
+
+    public function update()
+    {
+        try
+        {
+         $this->verify();
+        if ( $this->ad_id < 9000) return;
+        /*   please adapt */
+        $sql=" update attr_def set ad_text = $1
+             ,ad_type = $2,ad_size=$4,ad_extra=$5
+             where ad_id= $3";
+        $res=$this->cn->exec_sql(
+                 $sql,
+                 array($this->ad_text
+                       ,$this->ad_type
+                       ,$this->ad_id,$this->ad_size,$this->ad_extra)
+             );
+        }catch (Exception $e)
+        {
+            throw $e;
+        }
+
+
+    }
+    /**
+     address@hidden load a object
+     address@hidden 0 on success -1 the object is not found
+     */
+    public function load()
+    {
+
+        $sql="select ad_text
+             ,ad_type,ad_size,ad_extra
+             from attr_def where ad_id=$1";
+        /* please adapt */
+        $res=$this->cn->get_array(
+                 $sql,
+                 array($this->ad_id)
+             );
+
+        if ( count($res) == 0 )
+        {
+            /* Initialize an empty object */
+            foreach ($this->variable as $key=>$value) $this->$key='';
+
+            return -1;
+        }
+        foreach ($res[0] as $idx=>$value)
+        {
+            $this->$idx=$value;
+        }
+        return 0;
+    }
+
+    public function delete()
+    {
+        if ($this->ad_id < 9000)  return;
+        $sql=$this->cn->exec_sql("delete from fiche_detail  where ad_id=$1 ",
+                                 array($this->ad_id));
+
+       $sql="delete from jnt_fic_attr where ad_id=$1";
+        $res=$this->cn->exec_sql($sql,array($this->ad_id));
+
+        $sql="delete from attr_def where ad_id=$1";
+        $res=$this->cn->exec_sql($sql,array($this->ad_id));
+
+    }
+    /**
+     * Unit test for the class
+     */
+    static function test_me()
+    {
+        $cn=new Database(25);
+        $cn->start();
+        echo h2info('Test object vide');
+        $obj=new Fiche_Attr($cn);
+        var_dump($obj);
+
+        echo h2info('Test object NON vide');
+        $obj->set_parameter('j_id',3);
+        $obj->load();
+        var_dump($obj);
+
+        echo h2info('Update');
+        $obj->set_parameter('j_qcode','NOUVEAU CODE');
+        $obj->save();
+        $obj->load();
+        var_dump($obj);
+
+        echo h2info('Insert');
+        $obj->set_parameter('j_id',0);
+        $obj->save();
+        $obj->load();
+        var_dump($obj);
+
+        echo h2info('Delete');
+        $obj->delete();
+        echo (($obj->load()==0)?'Trouve':'non trouve');
+        var_dump($obj);
+        $cn->rollback();
+
+    }
+    /*!
+     address@hidden used with a usort function, to sort an array of Attribut 
on the attribut_id (ad_id)
+     */
+    static function sort_by_id($o1,$o2)
+    {
+        if ( $o1->ad_id > $o2->ad_id ) return 1;
+        if ( $o1->ad_id == $o2->ad_id ) return 0;
+        return -1;
+    }
+
+
+}
+//Fiche_Attr::test_me();
+
+
+
diff --git a/include/class/class_fiche_def.php 
b/include/class/class_fiche_def.php
new file mode 100644
index 0000000..c3f731b
--- /dev/null
+++ b/include/class/class_fiche_def.php
@@ -0,0 +1,816 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+// Copyright Author Dany De Bontridder address@hidden
+require_once NOALYSS_INCLUDE.'/class/class_fiche_attr.php';
+require_once NOALYSS_INCLUDE.'/lib/class_itext.php';
+require_once NOALYSS_INCLUDE.'/class/class_fiche_def_ref.php';
+require_once NOALYSS_INCLUDE.'/class/class_fiche.php';
+require_once NOALYSS_INCLUDE.'/lib/user_common.php';
+require_once NOALYSS_INCLUDE.'/lib/class_iradio.php';
+
+/*! \file
+ * \brief define Class fiche and fiche def, those class are using
+ *        class attribut
+ */
+/*!
+ * \brief define Class fiche and fiche def, those class are using
+ *        class attribut
+ */
+class Fiche_Def
+{
+    var $cn;           // database connection
+    var $id;                   // id (fiche_def.fd_id
+    var $label;                        // fiche_def.fd_label
+    var $class_base;           // fiche_def.fd_class_base
+    var $fiche_def;            // fiche_def.frd_id = fiche_def_ref.frd_id
+    var $create_account;               // fd_create_account: flag
+    var $all;
+    var $attribut;             // get from attr_xxx tables
+    function __construct($p_cn,$p_id = 0)
+    {
+        $this->cn=$p_cn;
+        $this->id=$p_id;
+    }
+    /*!\brief show the content of the form to create  a new Fiche_Def_Ref
+    */
+    function input ()
+    {
+        $ref=$this->cn->get_array("select * from fiche_def_ref order by 
frd_text");
+        $iradio=new IRadio();
+        /* the accounting item */
+        $class_base=new IPoste('class_base');
+        $class_base->set_attribute('ipopup','ipop_account');
+        $class_base->set_attribute('account','class_base');
+        $class_base->set_attribute('label','acc_label');
+        $f_class_base=$class_base->input();
+               $fd_description=new ITextarea('fd_description');
+               $fd_description->width=80;
+               $fd_description->heigh=4;
+               $fd_description->style='class="itextarea" 
style="margin-left:0px;vertical-align:text-top"';
+        require_once  NOALYSS_INCLUDE.'/template/fiche_def_input.php';
+        return;
+    }
+
+    /*!
+     *  \brief  Get attribut of a fiche_def
+     *
+     * \return string value of the attribute
+     */
+    function getAttribut()
+    {
+        $sql="select * from jnt_fic_attr ".
+             " natural join attr_def where fd_id=".$this->id.
+             " order by jnt_order";
+
+        $Ret=$this->cn->exec_sql($sql);
+
+        if ( ($Max=Database::num_row($Ret)) == 0 )
+            return ;
+        for ($i=0;$i < $Max;$i++)
+        {
+            $row=Database::fetch_array($Ret,$i);
+            $t = new Fiche_Attr($this->cn);
+            $t->ad_id=$row['ad_id'];
+            $t->ad_text=$row['ad_text'];
+            $t->jnt_order=$row['jnt_order'];
+            $t->ad_size=$row['ad_size'];
+            $t->ad_type=$row['ad_type'];
+            $t->ad_extra=$row['ad_extra'];
+            $this->attribut[$i]=clone $t;
+        }
+        return $this->attribut;
+    }
+
+    /*!
+    * \brief  Get attribut of the fiche_def
+    *
+    */
+    function get()
+    {
+        if ( $this->id == 0 )
+            return 0;
+        /*    $this->cn->exec_sql('select fiche_attribut_synchro($1)',
+        array($this->id));
+        */
+        $sql="select * from fiche_def ".
+             " where fd_id=".$this->id;
+        $Ret=$this->cn->exec_sql($sql);
+        if ( ($Max=Database::num_row($Ret)) == 0 )
+            return ;
+        $row=Database::fetch_array($Ret,0);
+        $this->label=$row['fd_label'];
+        $this->class_base=$row['fd_class_base'];
+        $this->fiche_def=$row['frd_id'];
+        $this->create_account=$row['fd_create_account'];
+        $this->fd_description=$row['fd_description'];
+    }
+    /*!
+     **************************************************
+     * \brief  Get all the fiche_def
+     *
+     * \return an array of fiche_def object
+     */
+    function get_all()
+    {
+        $sql="select * from fiche_def ";
+
+        $Ret=$this->cn->exec_sql($sql);
+        if ( ($Max=Database::num_row($Ret)) == 0 )
+            return ;
+
+        for ( $i = 0; $i < $Max;$i++)
+        {
+            $row=Database::fetch_array($Ret,$i);
+            $this->all[$i]=new Fiche_Def($this->cn,$row['fd_id']);
+            $this->all[$i]->label=$row['fd_label'];
+            $this->all[$i]->class_base=$row['fd_class_base'];
+            $this->all[$i]->fiche_def=$row['frd_id'];
+            $this->all[$i]->create_account=$row['fd_create_account'];
+        }
+    }
+    /*!
+     **************************************************
+     * \brief  Check in vw_fiche_def if a fiche has
+     *           a attribut X
+     *
+     *
+     * \param  $p_attr attribut to check
+     * \return  true or false
+     */
+    function HasAttribute($p_attr)
+    {
+        return ($this->cn->count_sql("select * from vw_fiche_def where 
ad_id=$p_attr and fd_id=".$this->id)>0)?true:false;
+
+    }
+    /*!
+     **************************************************
+     * \brief  Display category into a table
+     *
+     * \return HTML row
+     */
+    function Display()
+    {
+               $tab = new Sort_Table();
+
+               $url = HtmlInput::get_to_string(array('ac', 'gDossier'));
+               $tab->add(_("Nom de fiche"), $url, "order by fd_label asc", 
"order by fd_label desc", "na", "nd");
+               $tab->add(_("Basé sur le poste comptable"), $url, "order by 
fd_class_base asc", "order by fd_class_base desc", "pa", "pd");
+               $tab->add(_("Calcul automatique du poste comptable"), $url, 
"order by fd_create_account asc", "order by fd_create_account desc", "ca", 
"cd");
+               $tab->add(_("Basé sur le modèle"), $url, "order by frd_text 
asc", "order by frd_text  desc", "ma", "md");
+
+               $order = (isset($_GET['ord'])) ? 
$tab->get_sql_order($_GET["ord"]) : $tab->get_sql_order("na");
+
+
+               $res = $this->cn->exec_sql("SELECT fd_id, fd_class_base, 
fd_label, fd_create_account, fiche_def_ref.frd_id,
+frd_text , fd_description FROM fiche_def join fiche_def_ref on 
(fiche_def.frd_id=fiche_def_ref.frd_id)
+$order
+");
+
+               require_once NOALYSS_INCLUDE.'/template/fiche_def_list.php';
+       }
+    /*!\brief Add a fiche category thanks the element from the array
+     * you cannot add twice the same cat. name
+     * table : insert into fiche_def
+     *         insert into attr_def
+     *
+     * \param $array array
+     *        index FICHE_REF
+     *              nom_mod
+     *              class_base
+     *              fd_description
+     */
+    function Add($array)
+    {
+        /** 
+         * Check needed info
+         */
+        $p_nom_mod = HtmlInput::default_value('nom_mod', "", $array);
+        $p_fd_description = HtmlInput::default_value('fd_description', "", 
$array);
+        $p_class_base= HtmlInput::default_value('class_base', "", $array);
+        $p_fiche_def= HtmlInput::default_value('FICHE_REF', "", $array);
+        $p_create= HtmlInput::default_value('create', "off", $array);
+        
+        // If there is no description then add a empty one
+        if ( ! isset ($p_fd_description)) {
+            $p_fd_description="";
+        }
+        // Format correctly the name of the cat. of card
+        $p_nom_mod=sql_string($p_nom_mod);
+
+
+        // Name can't be empty
+        if ( strlen(trim($p_nom_mod)) == 0 )
+       {
+            alert (_('Le nom de la catégorie ne peut pas être vide'));
+            return 1;
+       }
+        // $p_fiche_def can't be empty
+        if ( strlen(trim($p_fiche_def)) == 0 )
+       {
+            alert (_('Un modéle de catégorie est obligatoire'));
+            return 1;
+       }
+        
+        /* check if the cat. name already exists */
+        $sql="select count(*) from fiche_Def where upper(fd_label)=upper($1)";
+        $count=$this->cn->get_value($sql,array(trim($p_nom_mod)));
+
+        if ($count != 0 ) {
+                        echo alert (_('Catégorie existante'));
+                       return 1;
+               }
+        // Set the value of fiche_def.fd_create_account
+        // automatic creation for 'poste comptable'
+        if ( $p_create == "on" && strlen(trim($p_class_base)) != 0)
+            $p_create='true';
+        else
+            $p_create='false';
+
+        // Class is valid ?
+        if ( sql_string($p_class_base) != null || ( $p_class_base !='' && 
strpos(',',$p_class_base) != 0 ))
+        {
+            // p_class is a valid number
+            $sql="insert into 
fiche_def(fd_label,fd_class_base,frd_id,fd_create_account,fd_description)
+                 values ($1,$2,$3,$4,$5) returning fd_id";
+
+            
$fd_id=$this->cn->get_value($sql,array($p_nom_mod,$p_class_base,$p_fiche_def,$p_create,$p_fd_description));
+
+            // p_class must be added to tmp_pcmn if it is a single accounting
+            if ( strpos(',',$p_class_base) ==0)
+            {
+                $sql="select account_add($1,$2)";
+                $Res=$this->cn->exec_sql($sql,array($p_class_base,$p_nom_mod));
+            }
+                       // Get the fd_id
+                       $fd_id=$this->cn->get_current_seq('s_fdef');
+
+                       // update jnt_fic_attr
+                       $sql=sprintf("insert into 
jnt_fic_attr(fd_id,ad_id,jnt_order)
+                                        values 
(%d,%d,10)",$fd_id,ATTR_DEF_ACCOUNT);
+                       $Res=$this->cn->exec_sql($sql);
+        }
+        else
+        {
+            //There is no class base not even as default
+            $sql="insert into 
fiche_def(fd_label,frd_id,fd_create_account,fd_description) values 
($1,$2,$3,$4) returning fd_id";
+
+
+            
$this->id=$this->cn->get_value($sql,array($p_nom_mod,$p_fiche_def,$p_create,$p_fd_description));
+
+            // Get the fd_id
+            $fd_id=$this->cn->get_current_seq('s_fdef');
+
+        }
+
+        // Get the default attr_def from attr_min
+        $def_attr=$this->get_attr_min($p_fiche_def);
+
+        //if defaut attr not null
+        // build the sql insert for the table attr_def
+        if (sizeof($def_attr) != 0 )
+        {
+            // insert all the mandatory fields into jnt_fiche_attr
+            $jnt_order=10;
+            foreach ( $def_attr as $i=>$v)
+            {
+                               $order=$jnt_order;
+                if ( $v['ad_id'] == ATTR_DEF_NAME )
+                    $order=0;
+                               $count=$this->cn->get_value("select count(*) 
from jnt_fic_attr where fd_id=$1 and ad_id=$2",array($fd_id,$v['ad_id']));
+                               if ($count == 0)
+                               {
+                                       $sql=sprintf("insert into 
jnt_fic_Attr(fd_id,ad_id,jnt_order)
+                             values (%d,%s,%d)",
+                             $fd_id,$v['ad_id'],$order);
+                                       $this->cn->exec_sql($sql);
+                                       $jnt_order+=10;
+                               }
+            }
+        }
+        $this->id=$fd_id;
+        return 0;
+
+    }//--------------end function Add ----------------------------
+    /*!
+     * \brief Get all the card where the fiche_def.fd_id is given in parameter
+     * \param $step = 0 we don't use the offset, page_size,...
+     *        $step = 1 we use the jnr_bar_nav
+     *
+     * \return array ('f_id'=>..,'ad_value'=>..)
+     *\see fiche
+     */
+    function get_by_type($step=0)
+    {
+        $sql="select f_id,ad_value
+             from
+             fiche join fiche_detail using(f_id)
+             where ad_id=1 and fd_id=$1 order by 2";
+
+        // we use navigation_bar
+        if ($step == 1  && $_SESSION['g_pagesize'] != -1   )
+        {
+            $offset=(isset($_GET['offset']))?$_GET['offset']:0;
+            $step=$_SESSION['g_pagesize'];
+            $sql.=" offset $offset limit $step";
+        }
+
+        $Ret=$this->cn->get_array($sql,array($this->id));
+
+        return $Ret;
+    }
+    /*!
+     * \brief Get all the card where the fiche_def.frd_id is given in parameter
+     * \return array of fiche or null is nothing is found
+     */
+    function get_by_category($p_cat)
+    {
+        $sql="select f_id,ad_value
+             from
+             fiche join fiche_def  using(fd_id)
+            join fiche_detail using(f_id)
+             where ad_id=1 and frd_id=$1 order by 2 ";
+
+        $Ret=$this->cn->exec_sql($sql,array($p_cat));
+        if ( ($Max=Database::num_row($Ret)) == 0 )
+            return null;
+        $all[0]=new Fiche($this->cn);
+
+        for ($i=0;$i<$Max;$i++)
+        {
+            $row=Database::fetch_array($Ret,$i);
+            $t=new Fiche($this->cn,$row['f_id']);
+            $t->getAttribut();
+            $all[$i]=$t;
+
+        }
+        return $all;
+    }
+
+    /*!\brief list the card of a fd_id
+     */
+    function myList()
+    {
+        $this->get();
+        echo '<H2 class="info">'.$this->id." ".$this->label.'</H2>';
+
+        $step=$_SESSION['g_pagesize'];
+        $sql_limit="";
+        $sql_offset="";
+        $bar="";
+        if ( $step != -1 )
+        {
+
+            $page=(isset($_GET['page']))?$_GET['page']:1;
+            $offset=(isset($_GET['offset']))?$_GET['offset']:0;
+            $max_line=$this->cn->count_sql("select f_id,ad_value  from
+                                           fiche join fiche_detail using (f_id)
+                                           where fd_id='".$this->id."' and 
ad_id=".ATTR_DEF_NAME." order by f_id");
+            $sql_limit=" limit ".$step;
+            $sql_offset=" offset ".$offset;
+            $bar=navigation_bar($offset,$max_line,$step,$page);
+        }
+
+        // Get all name the cards of the select category
+        // 1 for attr_def.ad_id is always the name
+        $Res=$this->cn->exec_sql("select f_id,vw_name,quick_code  from ".
+                                 " vw_fiche_attr ".
+                                 " where fd_id='".$this->id.
+                                 "' order by f_id $sql_offset $sql_limit ");
+        $Max=Database::num_row($Res);
+        echo $bar;
+        $str="";
+        // save the url
+        // with offet &offset=15&step=15&page=2&size=15
+        if ( $_SESSION['g_pagesize'] != -1)
+        {
+            $str=sprintf("&offset=%s&step=%s&page=%s&size=%s",
+                         $offset,
+                         $step,
+                         $page,
+                         $max_line);
+        }
+
+
+        echo '<FORM METHOD="POST" 
action="?p_action=fiche&action=vue'.$str.'">';
+       echo HtmlInput::hidden('ac',$_REQUEST['ac']);
+        echo dossier::hidden();
+        echo HtmlInput::hidden("fiche",$this->id);
+        echo HtmlInput::submit('add','Ajout fiche');
+        echo '</FORM>';
+        $str_dossier=dossier::get();
+        echo '<table>';
+        for ( $i = 0; $i < $Max; $i++)
+        {
+            $l_line=Database::fetch_array($Res,$i);
+            if ( $i%2 == 0)
+                echo '<TR class="odd">';
+            else
+                echo '<TR class="even">';
+
+            $span_mod='<TD><A href="?p_action=fiche&'.$str_dossier.
+                   '&action=detail&fiche_id='.$l_line['f_id'].$str.'&fiche='.
+                   
$_REQUEST['fiche'].'&ac='.$_REQUEST['ac'].'">'.$l_line['quick_code']
+                   .'</A></TD>';
+
+            echo $span_mod.'<TD>'.h($l_line['vw_name'])."</TD>";
+            echo '</tr>';
+        }
+        echo '</table>';
+        echo '<FORM METHOD="POST" 
action="?p_action=fiche&action=vue'.$str.'">';
+       echo HtmlInput::hidden('ac',$_REQUEST['ac']);
+        echo dossier::hidden();
+        echo HtmlInput::hidden("fiche",$this->id);
+        echo HtmlInput::submit('add','Ajout fiche');
+        echo '</FORM>';
+        echo $bar;
+
+    }
+    /*!\brief show input for the basic attribute : label, class_base, 
create_account
+     * use only when we want to update
+     *
+     *\return HTML string with the form
+     */
+    function input_base()
+    {
+        $r="";
+        $r.=_('Label');
+        $label=new IText('label',$this->label);
+        $r.=$label->input();
+        $r.='<br>';
+        /* the accounting item */
+        $class_base=new IPoste('class_base',$this->class_base);
+        $class_base->set_attribute('ipopup','ipop_account');
+        $class_base->set_attribute('account','class_base');
+        $class_base->set_attribute('label','acc_label');
+        $fd_description=new ITextarea('fd_description',$this->fd_description);
+        $fd_description->width=80;
+        $fd_description->heigh=4;
+        $fd_description->style='class="itextarea" 
style="margin-left:0px;vertical-align:text-top"';
+
+        $r.=_('Poste Comptable de base').' : ';
+        $r.=$class_base->input();
+        $r.='<span id="acc_label"></span><br>';
+               $r.='<br/>';
+               $r.=" Description ".$fd_description->input();
+        /* auto Create */
+               $r.='<br/>';
+        $ck=new ICheckBox('create');
+        $ck->selected=($this->create_account=='f')?false:true;
+        $r.=_('Chaque fiche aura automatiquement son propre poste comptable : 
');
+        $r.=$ck->input();
+        return $r;
+    }
+    /*!\brief Display all the attribut of the fiche_def
+     *\param $str give the action possible values are remove, empty
+     */
+    function DisplayAttribut($str="")
+    {
+        if ( $this->id == 0 )
+            return ;
+           $this->cn->exec_sql('select 
fiche_attribut_synchro($1)',array($this->id));
+
+                  $MaxLine=sizeof($this->attribut);
+        $r="<TABLE>";
+       $r.="<tr>".th('Nom 
attribut').th('').th('Ordre','style="text-align:right"').'</tr>';
+        // Display each attribute
+        $add_action="";
+        for ($i=0;$i<$MaxLine;$i++)
+        {
+            $class="even";
+            if ( $i % 2 == 0 )
+                $class="odd";
+
+            $r.='<TR class="'.$class.'"><td>';
+            // Can change the name
+            if ( $this->attribut[$i]->ad_id == ATTR_DEF_NAME )
+            {
+                continue;
+            }
+            else
+            {
+                if ( $str == "remove" )
+                {
+                    //Only for the not mandatory attribute (not defined in 
attr_min)
+                    if ( $this->cn->count_sql("select * from attr_min where 
frd_id=".
+                                              $this->fiche_def." and ad_id = 
".$this->attribut[$i]->ad_id) == 0
+                            && $this->attribut[$i]->ad_id != ATTR_DEF_QUICKCODE
+                            && $this->attribut[$i]->ad_id != ATTR_DEF_ACCOUNT
+                       )
+                    {
+                        $add_action=sprintf( '</TD><TD> Supprimer <input 
type="checkbox" name="chk_remove[]" value="%d">',
+                                             $this->attribut[$i]->ad_id);
+                    }
+                    else
+                        $add_action="</td><td>";
+                }
+                // The attribut.
+                $a=sprintf('%s ',  $this->attribut[$i]->ad_text);
+                $r.=$a.$add_action;
+                /*----------------------------------------  */
+                /*  ORDER OF THE CARD */
+                /*----------------------------------------  */
+                $order=new IText();
+                $order->name='jnt_order'.$this->attribut[$i]->ad_id;
+                $order->size=3;
+                $order->value=$this->attribut[$i]->jnt_order;
+                $r.='</td><td> '.$order->input();
+            }
+            $r.= '</td></tr>';
+        }
+
+        // Show the possible attribute which are not already attribute of the 
model
+        // of card
+        $Res=$this->cn->exec_sql("select ad_id,ad_text from attr_def
+                                 where
+                                 ad_id not in (select ad_id from fiche_def 
natural join jnt_fic_attr
+                                 where fd_id=$1) order by 
ad_text",array($this->id) );
+        $M=Database::num_row($Res);
+
+        // Show the unused attribute
+        $r.='<TR> <TD>';
+        $r.= '<SELECT NAME="ad_id">';
+        for ($i=0;$i<$M;$i++)
+        {
+            $l=Database::fetch_array($Res,$i);
+            $a=sprintf('<OPTION VALUE="%s"> %s',
+                       $l['ad_id'],$l['ad_text']);
+            $r.=$a;
+        }
+        $r.='</SELECT>';
+
+        $r.="</TABLE>";
+        return $r;
+    }
+    /*!\brief Save the label of the fiche_def
+     * \param $p_label label
+     */
+    function SaveLabel($p_label)
+    {
+        if ( $this->id == 0 ) return;
+        $p_label=sql_string($p_label);
+        if (strlen(trim ($p_label)) == 0 )
+        {
+            return;
+        }
+        $sql=sprintf("update   fiche_def set fd_label='%s' ".
+                     "where                    fd_id=%d",
+                     $p_label,$this->id);
+        $Res=$this->cn->exec_sql($sql);
+
+    }
+    /*!\brief set the auto create accounting item for each card and
+     * save it into the database
+     * \param $p_label true or false
+     */
+    function set_autocreate($p_label)
+    {
+        if ( $this->id == 0 ) return;
+        if ($p_label==true)
+            $t='t';
+        if ($p_label==false)
+            $t='f';
+
+        $sql="update   fiche_def set fd_create_account=$1 ".
+             "where                    fd_id=$2";
+
+        $Res=$this->cn->exec_sql($sql,array($t,$this->id));
+
+    }
+    /*!\brief Save the class base
+     * \param $p_label label
+     */
+    function save_class_base($p_label)
+    {
+        if ( $this->id == 0 ) return;
+        $p_label=sql_string($p_label);
+
+        $sql="update   fiche_def set fd_class_base=$1 ".
+             "where                    fd_id=$2";
+
+        $Res=$this->cn->exec_sql($sql,array($p_label,$this->id));
+    }
+       function save_description($p_description)
+       {
+               if ( $this->id == 0)                    return;
+               $this->cn->exec_sql("update fiche_def set fd_description=$1 
where fd_id=$2",array($p_description,$this->id));
+       }
+
+
+    /*!\brief insert a new attribut for this fiche_def
+     * \param $p_ad_id id of the attribut
+     */
+    function InsertAttribut($p_ad_id)
+    {
+        if ( $this->id == 0 ) return;
+        /* ORDER */
+        $this->GetAttribut();
+        $max=sizeof($this->attribut)*15;
+        // Insert a new attribute for the model
+        // it means insert a row in jnt_fic_attr
+        $sql=sprintf("insert into jnt_fic_attr (fd_id,ad_id,jnt_order) values 
(%d,%d,%d)",
+                     $this->id,$p_ad_id,$max);
+        $Res=$this->cn->exec_sql($sql);
+    }
+    /*!\brief remove an attribut for this fiche_def
+     * \param array of ad_id to remove
+     * \remark you can't remove the attribut defined in attr_min
+     */
+    function RemoveAttribut($array)
+    {
+        foreach ($array as $ch)
+        {
+            $this->cn->start();
+            $sql="delete from jnt_fic_attr where fd_id=$1 ".
+                 "   and ad_id=$2";
+            $this->cn->exec_sql($sql,array($this->id,$ch));
+
+            $sql="delete from fiche_detail  where jft_id in ( select ".
+                 " jft_id from fiche_Detail ".
+                 " join fiche using(f_id) ".
+                 " where ".
+                 "fd_id = $1 and ".
+                 "ad_id=$2)";
+            $this->cn->exec_sql($sql,array($this->id,$ch));
+
+            $this->cn->commit();
+        }
+    }
+
+    /*!\brief save the order of a card, update the column 
jnt_fic_attr.jnt_order
+     *\param $p_array containing the order
+     */
+    function save_order($p_array)
+    {
+        extract($p_array);
+        $this->GetAttribut();
+        foreach ($this->attribut as $row)
+        {
+            if ( $row->ad_id == 1 ) continue;
+            if ( ${'jnt_order'.$row->ad_id} <= 0 ) continue;
+            $sql='update jnt_fic_attr set jnt_order=$1 where fd_id=$2 and 
ad_id=$3';
+            $this->cn->exec_sql($sql,array(${'jnt_order'.$row->ad_id},
+                                           $this->id,
+                                           $row->ad_id));
+
+        }
+        /* correct the order */
+        $this->cn->exec_sql('select attribute_correct_order()');
+    }
+
+
+    /*!\brief remove all the card from a categorie after having verify
+     *that the card is not used and then remove also the category
+     *\return the remains items, not equal to 0 if a card remains and
+     *then the category is not removed
+     */
+    function remove()
+    {
+        if ( $this->id >= 500000 ) {
+            throw new Exception(_('Catégorie verrouillée '));
+        }
+        $remain=0;
+        /* get all the card */
+        $aFiche=fiche::get_fiche_def($this->cn,$this->id);
+        if ( $aFiche != null )
+        {
+            /* check if the card is used */
+            foreach ($aFiche as $dfiche)
+            {
+             $fiche=new Fiche($this->cn,$dfiche['f_id']);
+
+                /* if the card is not used then remove it otherwise increment 
remains */
+                if ( $fiche->is_used() == false )
+                {
+                    $fiche->delete();
+                }
+                else
+                    $remain++;
+            }
+        }
+        /* if remains == 0 then remove cat */
+        if ( $remain == 0 )
+        {
+            $sql='delete from jnt_fic_attr where fd_id=$1';
+            $this->cn->exec_sql($sql,array($this->id));
+            $sql='delete from fiche_def where fd_id=$1';
+            $this->cn->exec_sql($sql,array($this->id));
+        }
+
+        return $remain;
+
+    }
+    /*!
+     * \brief  retrieve the mandatory field of the card model
+     *
+     * \param $p_fiche_def_ref
+     * \return array of ad_id  (attr_min.ad_id) and  labels (attr_def.ad_text)
+     */
+    function get_attr_min($p_fiche_def_ref)
+    {
+
+        // find the min attr for the fiche_def_ref
+        $Sql="select ad_id,ad_text from attr_min natural join attr_def
+             natural join fiche_def_ref
+             where
+             frd_id= $1";
+        $Res=$this->cn->exec_sql($Sql,array($p_fiche_def_ref));
+        $Num=Database::num_row($Res);
+
+        // test the number of returned rows
+        if ($Num == 0 ) return null;
+
+        // Get Results & Store them in a array
+        for ($i=0;$i<$Num;$i++)
+        {
+            $f=Database::fetch_array($Res,$i);
+            $array[$i]['ad_id']=$f['ad_id'];
+            $array[$i]['ad_text']=$f['ad_text'];
+        }
+        return $array;
+    }
+    /*!\brief count the number of fiche_def (category) which has the frd_id 
(type of category)
+     *\param $p_frd_id is the frd_id in constant.php the FICHE_TYPE_
+     *\return the number of cat. of card of the given type
+     *\see constant.php
+     */
+    function count_category($p_frd_id)
+    {
+        $ret=$this->cn->count_sql("select fd_id from fiche_def where 
frd_id=$1",array($p_frd_id));
+        return $ret;
+    }
+       function input_detail()
+       {
+               $r = "";
+               // Save the label
+
+               $this->get();
+               $this->GetAttribut();
+               $r.= '<H2 class="info">' . $this->id . " " . h($this->label) . 
'</H2>';
+               $r.='<fieldset><legend>'._('Données générales').'</legend>';
+
+               /* show the values label class_base and create account */
+               $r.='<form method="post">';
+               $r.=dossier::hidden();
+               $r.=HtmlInput::hidden("fd_id", $this->id);
+               $r.=HtmlInput::hidden("p_action", "fiche");
+               $r.= $this->input_base();
+               $r.='<hr>';
+               $r.=HtmlInput::submit('change_name', _('Sauver'));
+               $r.='</form>';
+               $r.='</fieldset>';
+               /* attributes */
+               $r.='<fieldset><legend>'._('Détails').'</legend>';
+
+               $r.= '<FORM  id="input_detail_frm" method="POST">';
+               $r.=dossier::hidden();
+               $r.=HtmlInput::hidden("fd_id", $this->id);
+               $r.=HtmlInput::hidden("action", "");
+               $r.= $this->DisplayAttribut("remove");
+               $r.= HtmlInput::submit('add_line_bt', _('Ajoutez cet élément'),
+                        'onclick="$(\'action\').value=\'add_line\'"');
+               $r.= HtmlInput::submit("save_line_bt", _("Sauvez"),
+                        'onclick="$(\'action\').value=\'save_line\'"');
+                        
+               $r.=HtmlInput::submit('remove_cat_bt', _('Effacer cette 
catégorie'), 'onclick="$(\'action\').value=\'remove_cat\';return 
confirm_box(\'input_detail_frm\',\'' . _('Vous confirmez ?') . '\')"');
+               // if there is nothing to remove then hide the button
+               if (strpos($r, "chk_remove") != 0)
+               {
+                    $r.=HtmlInput::submit('remove_line_bt', _("Enleve les 
éléments cochés"), 
+                            
'onclick="$(\'action\').value=\'remove_line\';return 
confirm_box(\'input_detail_frm\',\'' . _('Vous confirmez ?') . '\')"');
+               }
+               $r.= "</form>";
+               $r.=" <p class=\"notice\"> " . _("Attention : il n'y aura pas 
de demande de confirmation pour enlever les
+                                   attributs sélectionnés. Il ne sera pas 
possible de revenir en arrière") . "</p>";
+               $r.='</fieldset>';
+               return $r;
+       }
+       function input_new()
+       {
+               $single=new Tool_Uos("dup");
+               echo '<form method="post" style="display:inline">';
+               echo $single->hidden();
+               echo HtmlInput::hidden("p_action","fiche");
+               echo dossier::hidden();
+               echo $this->input(); //    CreateCategory($cn,$search);
+               echo HtmlInput::submit("add_modele" ,_("Sauve"));
+               echo '</FORM>';
+       }
+
+}
+?>
diff --git a/include/class_fiche_def_ref.php 
b/include/class/class_fiche_def_ref.php
similarity index 100%
rename from include/class_fiche_def_ref.php
rename to include/class/class_fiche_def_ref.php
diff --git a/include/class/class_follow_up.php 
b/include/class/class_follow_up.php
new file mode 100644
index 0000000..86c6cca
--- /dev/null
+++ b/include/class/class_follow_up.php
@@ -0,0 +1,1840 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+// Copyright Author Dany De Bontridder address@hidden
+require_once NOALYSS_INCLUDE.'/lib/class_itextarea.php';
+require_once NOALYSS_INCLUDE.'/lib/class_idate.php';
+require_once NOALYSS_INCLUDE.'/lib/class_iselect.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ihidden.php';
+require_once NOALYSS_INCLUDE.'/lib/class_itext.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ispan.php';
+require_once NOALYSS_INCLUDE.'/lib/class_icard.php';
+require_once NOALYSS_INCLUDE.'/lib/class_icheckbox.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ifile.php';
+require_once NOALYSS_INCLUDE.'/class/class_fiche.php';
+require_once NOALYSS_INCLUDE.'/class/class_document.php';
+require_once NOALYSS_INCLUDE.'/class/class_document_type.php';
+require_once NOALYSS_INCLUDE.'/class/class_document_modele.php';
+require_once NOALYSS_INCLUDE.'/lib/user_common.php';
+require_once NOALYSS_INCLUDE.'/class/class_follow_up_detail.php';
+require_once NOALYSS_INCLUDE.'/lib/class_inum.php';
+require_once NOALYSS_INCLUDE.'/lib/class_sort_table.php';
+require_once NOALYSS_INCLUDE.'/lib/class_irelated_action.php';
+require_once NOALYSS_INCLUDE.'/class/class_tag.php';
+require_once NOALYSS_INCLUDE.'/class/class_default_menu.php';
+/**
+ * \file
+ * \brief class_action for manipulating actions
+ * action can be :
+ * <ul>
+ * <li>an invoice
+ * <li>a meeting
+ * <li>an order
+ * <li>a letter
+ * </ul>
+ * The table document_type are the possible actions
+ */
+
+/**
+ * \brief class_action for manipulating actions
+ * action can be :
+ * <ul>
+ * <li> a meeting
+ * <li>an order
+ * <li>a letter
+ * </ul>
+ * The table document_type are the possible actions
+ */
+class Follow_Up
+{
+
+    var $db; /* !<  $db  database connexion    */
+    var $ag_timestamp;  /* !<   $ag_timestamp document date 
(ag_gestion.ag_timestamp) */
+    var $dt_id;   /* !<   $dt_id type of the document (document_type.dt_id) */
+    var $ag_state; /* !<   $ag_state stage of the document (printed, send to 
client...) */
+    var $d_number;   /* !<   $d_number number of the document */
+    var $d_filename; /* !<   $d_filename filename's document      */
+    var $d_mimetype; /* !<   $d_mimetype document's filename      */
+    var $ag_title;   /* !<   $ag_title title document        */
+    var $f_id; /* !<   $f_id_dest fiche id (From field )  */
+    var $ag_ref;  /* !< $ag_ref is the ref  */
+    var $ag_hour;  /* !< $ag_hour is the hour of the meeting, action */
+    var $ag_priority; /* !< $ag_priority is the priority 1 High, 2 medium, 3 
low */
+    var $ag_dest;  /* !< $ag_dest person who is in charged */
+    var $ag_contact;  /* !< $ag_contact contact */
+    var $ag_remind_date;  /* !< $ag_contact contact */
+
+    /**
+     * @brief $operation string related operation
+     */
+    var $operation;
+
+    /**
+     * @brief $action string related action
+     */
+    var $action;
+
+    /**
+     * @brief constructor
+     * \brief constructor
+     * \param p_cn database connection
+     */
+    function __construct($p_cn, $p_id=0)
+    {
+        $this->db=$p_cn;
+        $this->ag_id=$p_id;
+        $this->f_id=0;
+        $this->aAction_detail=array();
+        $this->operation="";
+        $this->action="";
+    }
+    /**
+     * Create a filter based on the current user, 
+     * @global type $g_user Connected user
+     * @param type $cn Database connection
+     * @param type $p_mode Mode is R (for Read) or W (for write)
+     * @return string SQL where clause to include in the SQL 
+     * example: (ag_dest in (select p_granted from user_sec_action_profile 
where p_id=x)
+     */
+    static function sql_security_filter($cn, $p_mode)
+    {
+        global $g_user;
+        $profile=$cn->get_value("select p_id from profile_user where 
user_name=$1", array($g_user->login));
+        if ($profile=='')
+            die("Security");
+        if ($p_mode=='R')
+        {
+            $sql=" (ag_dest in (select p_granted from user_sec_action_profile 
where p_id=$profile ) ) ";
+        } else if ($p_mode=='W')
+        {
+            $sql=" ( ag_dest in (select p_granted from user_sec_action_profile 
where p_id=$profile and ua_right='W' ) )";
+        } else  {
+            error_log(_('Securité'));
+            throw new Exception(_('Securité'));
+        }
+        return $sql;
+    }
+
+    //----------------------------------------------------------------------
+    /**
+     * \brief Display the object, the tags for the FORM
+     *        are in the caller. It will be used for adding and updating
+     *        action
+     * \note  If  ag_id is not equal to zero then it is an update otherwise
+     *        it is a new document
+     *
+     * \param $p_view form will be in readonly mode (value: READ, UPD or NEW  )
+     * \param $p_gen true we show the tag for generating a doc (value : true 
or false) and adding files
+     * \param $p_base is the ac parameter
+     * \param $retour is the html code for the return button
+     * \note  update the reference number or the document type is not allowed
+     *
+     *
+     * \return string containing the html code
+     */
+    function Display($p_view, $p_gen, $p_base, $retour="")
+    {
+        global $g_user;
+        if ($p_view=='UPD')
+        {
+            $upd=true;
+            $readonly=false;
+        }
+        elseif ($p_view=="NEW")
+        {
+            $upd=false;
+            $readonly=false;
+            $this->ag_ref=_("Nouveau");
+        }
+        elseif ($p_view=='READ')
+        {
+            $upd=true;
+            $readonly=true;
+        }
+        else
+        {
+            throw new Exception('class_action'.__LINE__.'Follow_Up::Display 
error unknown parameter'.$p_view);
+        }
+        // Compute the widget
+        // Date
+        $date=new IDate();
+        $date->readOnly=$readonly;
+        $date->name="ag_timestamp";
+        $date->id="ag_timestamp";
+        $date->value=$this->ag_timestamp;
+
+        $remind_date=new IDate();
+        $remind_date->readOnly=$readonly;
+        $remind_date->name="ag_remind_date";
+        $remind_date->id="ag_remind_date";
+        $remind_date->value=$this->ag_remind_date;
+
+
+        // Doc Type
+        $doc_type=new ISelect();
+        $doc_type->name="dt_id";
+        $doc_type->value=$this->db->make_array("select dt_id,dt_value from 
document_type order by dt_value", 1);
+        $doc_type->selected=$this->dt_id;
+        $doc_type->readOnly=$readonly;
+        $str_doc_type=$doc_type->input();
+
+        // Description
+        $desc=new ITextArea();
+        $desc->style=' class="itextarea" style="width:80%;margin-left:0px"';
+        $desc->name="ag_comment";
+        $desc->readOnly=$readonly;
+        $acomment=$this->db->get_array("SELECT agc_id, ag_id, 
to_char(agc_date,'DD.MM.YYYY HH24:MI') as str_agc_date, agc_comment, tech_user
+                                FROM action_gestion_comment where ag_id=$1 
order by agc_id;", array($this->ag_id)
+        );
+
+        // List opération liées
+        $operation=$this->db->get_array("select 
ago_id,j.jr_id,j.jr_internal,j.jr_comment,to_char(j.jr_date,'DD.MM.YY') as 
str_date
+                       from jrn as j join action_gestion_operation as ago on 
(j.jr_id=ago.jr_id)
+                       where ag_id=$1 order by jr_date", array($this->ag_id));
+        $iconcerned=new IConcerned('operation');
+
+        // List related action
+        $action=$this->db->get_array("
+                       select ag_id,ag_ref,substr(ag_title,1,40) as 
sub_title,to_char(ag_timestamp,'DD.MM.YY') as str_date ,
+                               ag_timestamp,dt_value
+                                       from action_gestion
+                                        join document_type on (ag_type=dt_id)
+                               where
+                               ag_id in (select aga_greatest from 
action_gestion_related where aga_least =$1)
+                               or
+                               ag_id in (select aga_least from 
action_gestion_related where aga_greatest =$1)
+                               order by ag_timestamp", array($this->ag_id));
+        $iaction=new IRelated_Action('action');
+        $iaction->value=(isset($this->action))?$this->action:"";
+
+        // state
+        // Retrieve the value
+        $a=$this->db->make_array("select s_id,s_value from document_state ");
+        $state=new ISelect();
+        $state->readOnly=$readonly;
+        $state->name="ag_state";
+        $state->value=$a;
+        $state->selected=$this->ag_state;
+        $str_state=$state->input();
+
+        // Retrieve the value if there is an attached doc
+        $doc_ref="";
+        // Document id
+
+        $h2=new IHidden();
+        $h2->name="d_id";
+        $h2->value=$this->d_id;
+
+        if ($this->d_id!=0&&$this->d_id!="")
+        {
+            $h2->readonly=($p_view=='NEW')?false:true;
+            $doc=new Document($this->db, $this->d_id);
+            $doc->get();
+            if (strlen(trim($doc->d_lob))!=0)
+            {
+                $d_id=new IHidden();
+                $doc_ref="<p> Document ".$doc->anchor().'</p>';
+                $doc_ref.=$h2->input().$d_id->input('d_id', $this->d_id);
+            }
+        }
+
+
+        // title
+        $title=new IText();
+        $title->readOnly=$readonly;
+        $title->name="ag_title";
+        $title->value=$this->ag_title;
+        $title->size=60;
+
+
+        // Priority of the ag_priority
+        $ag_priority=new ISelect();
+        $ag_priority->readOnly=$readonly;
+        $ag_priority->name="ag_priority";
+        $ag_priority->selected=$this->ag_priority;
+        $ag_priority->value=array(array('value'=>1, 'label'=>'Haute'),
+            array('value'=>2, 'label'=>'Moyenne'),
+            array('value'=>3, 'label'=>'Basse')
+        );
+        $str_ag_priority=$ag_priority->input();
+
+        // hour of the action (meeting) ag_hour
+        $ag_hour=new IText();
+        $ag_hour->readOnly=$readonly;
+        $ag_hour->name="ag_hour";
+        $ag_hour->value=$this->ag_hour;
+        $ag_hour->size=6;
+        $ag_hour->javascript=" onblur=check_hour('ag_hour');";
+        $str_ag_hour=$ag_hour->input();
+
+        // Profile in charged of the action
+        $ag_dest=new ISelect();
+        $ag_dest->readOnly=$readonly;
+        $ag_dest->name="ag_dest";
+        // select profile
+        $aAg_dest=$this->db->make_array("select  p_id as value, ".
+                "p_name as label ".
+                " from profile  where p_id in (select p_granted from 
user_sec_action_profile where ua_right='W' and p_id=".$g_user->get_profile().") 
order by 2");
+
+        $ag_dest->value=$aAg_dest;
+        $ag_dest->selected=$this->ag_dest;
+        $str_ag_dest=$ag_dest->input();
+
+        // ag_ref
+        // Always false for update
+
+        $client_label=new ISpan();
+
+        /* Add button */
+        $f_add_button=new IButton('add_card');
+        $f_add_button->label=_('Créer une nouvelle fiche');
+        $f_add_button->set_attribute('ipopup', 'ipop_newcard');
+        $filter=$this->db->make_list('select fd_id from fiche_def ');
+        $f_add_button->set_attribute('filter', $filter);
+
+        $f_add_button->javascript=" select_card_type(this);";
+        $str_add_button=$f_add_button->input();
+
+        // f_id_dest sender
+        if ($this->qcode_dest!=NOTFOUND&&strlen(trim($this->qcode_dest))!=0)
+        {
+            $tiers=new Fiche($this->db);
+            $tiers->get_by_qcode($this->qcode_dest);
+            $qcode_dest_label=$tiers->strAttribut(1);
+            $this->f_id_dest=$tiers->id;
+        }
+        else
+        {
+            
$qcode_dest_label=($this->f_id_dest==0||trim($this->qcode_dest)=="")?'Interne 
':'Error';
+        }
+
+        $h_ag_id=new IHidden();
+        // if concerns another action : show the link otherwise nothing
+        //
+               // sender
+        $w=new ICard();
+        $w->readOnly=$readonly;
+        $w->jrn=0;
+        $w->name='qcode_dest';
+        $w->value=($this->f_id_dest!=0)?$this->qcode_dest:"";
+        $w->label="";
+        $list_recipient=$this->db->make_list('select fd_id from fiche_def 
where frd_id in (14,25,8,9,16)');
+        $w->extra=$list_recipient;
+        $w->set_attribute('typecard', $list_recipient);
+        $w->set_dblclick("fill_ipopcard(this);");
+        $w->set_attribute('ipopup', 'ipopcard');
+
+        // name of the field to update with the name of the card
+        $w->set_attribute('label', 'qcode_dest_label');
+        // name of the field to update with the name of the card
+        $w->set_attribute('typecard', $w->extra);
+        $w->set_function('fill_data');
+        $w->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ', 
$w->name);
+
+        $sp=new ISpan();
+        $sp->name='qcode_dest_label';
+        $sp->value=$qcode_dest_label;
+
+        // autre - a refaire pour avoir plusieurs fiches
+        // Sur le modèle des tags
+        $ag_contact=new ICard();
+        $ag_contact->readOnly=$readonly;
+        $ag_contact->jrn=0;
+        $ag_contact->name='ag_contact';
+        $ag_contact->value='';
+        $ag_contact->set_attribute('ipopup', 'ipopcard');
+
+        if ($this->ag_contact!=0)
+        {
+            $contact=new Fiche($this->db, $this->ag_contact);
+            $ag_contact->value=$contact->get_quick_code();
+        }
+
+        $ag_contact->label="";
+
+        $list_contact=$this->db->make_list('select fd_id from fiche_def where 
frd_id=16');
+        $ag_contact->extra=$list_contact;
+
+        $ag_contact->set_dblclick("fill_ipopcard(this);");
+        // name of the field to update with the name of the card
+        $ag_contact->set_attribute('label', 'ag_contact_label');
+        // name of the field to update with the name of the card
+        $ag_contact->set_attribute('typecard', $list_contact);
+        $ag_contact->set_function('fill_data');
+        $ag_contact->javascript=sprintf(' 
onchange="fill_data_onchange(\'%s\');" ', $ag_contact->name);
+
+        $spcontact=new ISpan();
+        $spcontact->name='ag_contact_label';
+        $spcontact->value='';
+        $fiche_contact=new Fiche($this->db);
+        $fiche_contact->get_by_qcode($this->ag_contact);
+        if ($fiche_contact->id!=0)
+        {
+            $spcontact->value=$fiche_contact->strAttribut(ATTR_DEF_NAME);
+        }
+
+
+        $h_agrefid=new IHidden();
+        $iag_ref=new IText("ag_ref");
+        $iag_ref->value=$this->ag_ref;
+        $iag_ref->readOnly=($p_view=="NEW"||$p_view=='READ')?true:false;
+        $str_ag_ref=$iag_ref->input();
+        // Preparing the return string
+        $r="";
+
+        /* for new files */
+        $upload=new IFile();
+        $upload->name="file_upload[]";
+        $upload->readOnly=$readonly;
+        $upload->value="";
+        $aAttachedFile=$this->db->get_array('select 
d_id,d_filename,d_description,d_mimetype,'.
+                '\'show_document.php?'.
+                Dossier::get().'&d_id=\'||d_id as link'.
+                ' from document where ag_id=$1', array($this->ag_id));
+        /* create the select for document */
+        $aDocMod=new ISelect();
+        $aDocMod->name='doc_mod';
+        $aDocMod->value=$this->db->make_array('select md_id,dt_value||\' : 
\'||md_name as md_name'.
+                ' from document_modele join document_type on (md_type=dt_id)'.
+                ' order by md_name');
+        $str_select_doc=$aDocMod->input();
+        /* if no document then do not show the generate button */
+        if (empty($aDocMod->value))
+            $str_submit_generate="";
+        else
+            $str_submit_generate=HtmlInput::submit("generate", _("Génére le 
document"));
+
+        $ag_id=$this->ag_id;
+
+        /* fid = Icard  */
+        $icard=new ICard();
+        $icard->jrn=0;
+        $icard->table=0;
+        $icard->extra2='QuickCode';
+        $icard->noadd="no";
+        $icard->extra='all';
+
+        /* Text desc  */
+        $text=new IText();
+        $num=new INum();
+
+        /* TVA */
+        $itva=new ITva_Popup($this->db);
+        $itva->in_table=true;
+        $aCard=array();
+        /* create aArticle for the detail section */
+        
$article_count=(count($this->aAction_detail)==0)?MAX_ARTICLE:count($this->aAction_detail);
+        /* Compute total */
+        $tot_item=0;
+        $tot_vat=0;
+        for ($i=0; $i<$article_count; $i++)
+        {
+            /* fid = Icard  */
+            $icard=new ICard();
+            $icard->jrn=0;
+            $icard->table=0;
+            $icard->noadd="no";
+            $icard->extra='all';
+            $icard->name="e_march".$i;
+            
$tmp_ad=(isset($this->aAction_detail[$i]))?$this->aAction_detail[$i]:false;
+            $icard->readOnly=$readonly;
+            $icard->value='';
+            $aCard[$i]=0;
+            if ($tmp_ad)
+            {
+                $march=new Fiche($this->db);
+                $f=$tmp_ad->get_parameter('qcode');
+                if ($f!=0)
+                {
+                    $march->id=$f;
+                    $icard->value=$march->get_quick_code();
+                    $aCard[$i]=$f;
+                }
+            }
+            $icard->set_dblclick("fill_ipopcard(this);");
+            // name of the field to update with the name of the card
+            $icard->set_attribute('label', "e_march".$i."_label");
+            // name of the field to update with the name of the card
+            $icard->set_attribute('typecard', $icard->extra);
+            $icard->set_attribute('ipopup', 'ipopcard');
+            $icard->set_function('fill_data');
+            $icard->javascript=sprintf(' 
onchange="fill_data_onchange(\'%s\');" ', $icard->name);
+
+            $aArticle[$i]['fid']=$icard->search().$icard->input();
+
+            $text->javascript=' 
onchange="clean_tva('.$i.');compute_ledger('.$i.')"';
+            $text->css_size="100%";
+            $text->name="e_march".$i."_label";
+            $text->id="e_march".$i."_label";
+            $text->size=40;
+            $text->value=($tmp_ad)?$tmp_ad->get_parameter('text'):"";
+            $text->readOnly=$readonly;
+            $aArticle[$i]['desc']=$text->input();
+
+            $num->javascript=' 
onchange="format_number(this);clean_tva('.$i.');compute_ledger('.$i.')"';
+            $num->name="e_march".$i."_price";
+            $num->id="e_march".$i."_price";
+            $num->size=8;
+            $num->readOnly=$readonly;
+            $num->value=($tmp_ad)?$tmp_ad->get_parameter('price_unit'):0;
+            $aArticle[$i]['pu']=$num->input();
+
+            $num->name="e_quant".$i;
+            $num->id="e_quant".$i;
+            $num->size=8;
+            $num->value=($tmp_ad)?$tmp_ad->get_parameter('quantity'):0;
+            $aArticle[$i]['quant']=$num->input();
+
+            $itva->name='e_march'.$i.'_tva_id';
+            $itva->id='e_march'.$i.'_tva_id';
+            $itva->value=($tmp_ad)?$tmp_ad->get_parameter('tva_id'):0;
+            $itva->readOnly=$readonly;
+            $itva->js=' 
onchange="format_number(this);clean_tva('.$i.');compute_ledger('.$i.')"';
+            $itva->set_attribute('compute', $i);
+
+            $aArticle[$i]['tvaid']=$itva->input();
+
+            $num->name="e_march".$i."_tva_amount";
+            $num->id="e_march".$i."_tva_amount";
+            $num->value=($tmp_ad)?$tmp_ad->get_parameter('tva_amount'):0;
+            $num->javascript=" onchange=\"compute_ledger('".$i." ')\"";
+            $num->size=8;
+            $aArticle[$i]['tva']=$num->input();
+            $tot_vat=bcadd($tot_vat,$num->value);
+
+            $num->name="tvac_march".$i;
+            $num->id="tvac_march".$i;
+            $num->value=($tmp_ad)?$tmp_ad->get_parameter('total'):0;
+            $num->size=8;
+            $aArticle[$i]['tvac']=$num->input();
+            $tot_item=bcadd($tot_item,$num->value);
+
+            $aArticle[$i]['hidden_htva']=HtmlInput::hidden('htva_march'.$i, 0);
+            $aArticle[$i]['hidden_tva']=HtmlInput::hidden('tva_march'.$i, 0);
+            $aArticle[$i]['ad_id']=($tmp_ad)?HtmlInput::hidden('ad_id'.$i, 
$tmp_ad->get_parameter('id')):HtmlInput::hidden('ad_id'.$i, 0);
+        }
+
+        /* Add the needed hidden values */
+        $r.=dossier::hidden();
+
+        /* add the number of item */
+        $Hid=new IHidden();
+        $r.=$Hid->input("nb_item", $article_count);
+        $r.=HtmlInput::request_to_hidden(array("closed_action", 
"remind_date_end", "remind_date", "sag_ref", "only_internal", "state", "qcode", 
"ag_dest_query", "action_query", "tdoc", "date_start", "date_end", "hsstate", 
"searchtag"));
+        $a_tag=$this->tag_get();
+        $menu=new Default_Menu();
+        /* get template */
+        ob_start();
+        require 'template/detail-action.php';
+        $content=ob_get_contents();
+        ob_end_clean();
+        $r.=$content;
+
+        //hidden
+        $r.="<p>";
+        $r.=$h2->input();
+        $r.=$h_ag_id->input('ag_id', $this->ag_id);
+        $hidden2=new IHidden();
+        $r.=$hidden2->input('f_id_dest', $this->f_id_dest);
+        $r.="</p>";
+
+        return $r;
+    }
+
+    //----------------------------------------------------------------------
+    /*     * \brief This function shows the detail of an action thanks the 
ag_id
+     */
+    function get()
+    {
+        $sql="select ag_id,to_char (ag_timestamp,'DD.MM.YYYY') as 
ag_timestamp,".
+                " f_id_dest,ag_title,ag_ref,d_id,ag_type,ag_state, ag_owner, ".
+                "  ag_dest, ag_hour, ag_priority, ag_contact,to_char 
(ag_remind_date,'DD.MM.YYYY') as ag_remind_date ".
+                " from action_gestion left join document using (ag_id) where 
ag_id=".$this->ag_id;
+        $r=$this->db->exec_sql($sql);
+        $row=Database::fetch_all($r);
+        if ($row==false)
+        {
+            $this->ag_id=0;
+            return;
+        }
+        $this->ag_timestamp=$row[0]['ag_timestamp'];
+        $this->ag_contact=$row[0]['ag_contact'];
+        $this->f_id_dest=$row[0]['f_id_dest'];
+        $this->ag_title=$row[0]['ag_title'];
+        $this->ag_type=$row[0]['ag_type'];
+        $this->ag_ref=$row[0]['ag_ref'];
+        $this->ag_state=$row[0]['ag_state'];
+        $this->d_id=$row[0]['d_id'];
+        $this->ag_dest=$row[0]['ag_dest'];
+        $this->ag_hour=$row[0]['ag_hour'];
+        $this->ag_priority=$row[0]['ag_priority'];
+        $this->ag_remind_date=$row[0]['ag_remind_date'];
+        $this->ag_owner=$row[0]['ag_owner'];
+
+        $action_detail=new Follow_Up_Detail($this->db);
+        $action_detail->set_parameter('ag_id', $this->ag_id);
+        $this->aAction_detail=$action_detail->load_all();
+
+
+        // if there is no document set 0 to d_id
+        if ($this->d_id=="")
+            $this->d_id=0;
+        // if there is a document fill the object
+        if ($this->d_id!=0)
+        {
+            $this->state=$row['0']['ag_state'];
+            $this->ag_state=$row[0]['ag_state'];
+        }
+        $this->dt_id=$this->ag_type;
+        $aexp=new Fiche($this->db, $this->f_id_dest);
+        $this->qcode_dest=$aexp->strAttribut(ATTR_DEF_QUICKCODE);
+    }
+
+    /**
+     * \brief Save the document and propose to save the generated document or
+     *  to upload one, the data are included except the file. Temporary the 
generated
+     * document is save.
+     * The files into $_FILES['file_upload'] will be saved
+     * @note the array $_POST['input_desc'] must be set, contains the 
description
+     * of the uploaded files
+     *
+     * \return
+     */
+    function save()
+    {
+
+        // Get The sequence id,
+        $seq_name="seq_doc_type_".$this->dt_id;
+        $str_file="";
+        $add_file='';
+
+        // f_id exp
+        $exp=new Fiche($this->db);
+        $exp->get_by_qcode($this->qcode_dest);
+        $exp->id=($exp->id==0)?null:$exp->id;
+
+        $contact=new Fiche($this->db);
+        $contact->get_by_qcode($this->ag_contact);
+
+        if (trim($this->ag_title)=="")
+        {
+            $doc_mod=new document_type($this->db);
+            $doc_mod->dt_id=$this->dt_id;
+            $doc_mod->get();
+            $this->ag_title=$doc_mod->dt_value;
+        }
+        $this->ag_id=$this->db->get_next_seq('action_gestion_ag_id_seq');
+
+        // Create the reference
+        $ag_ref=$this->db->get_value('select dt_prefix from document_type 
where dt_id=$1', array($this->dt_id)).'-'.$this->db->get_next_seq($seq_name);
+        $this->ag_ref=$ag_ref;
+
+        // save into the database
+        if ($this->ag_remind_date!=null||$this->ag_remind_date!='')
+        {
+            $sql="insert into action_gestion".
+                    "(ag_id,ag_timestamp,ag_type,ag_title,f_id_dest,ag_ref, 
ag_dest, ".
+                    " ag_hour, 
ag_priority,ag_owner,ag_contact,ag_state,ag_remind_date) ".
+                    " values 
($1,to_date($2,'DD.MM.YYYY'),$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,to_date($13,'DD.MM.YYYY'))";
+        }
+        else
+        {
+            $this->ag_remind_date=null;
+            $sql="insert into action_gestion".
+                    "(ag_id,ag_timestamp,ag_type,ag_title,f_id_dest,ag_ref, 
ag_dest, ".
+                    " ag_hour, 
ag_priority,ag_owner,ag_contact,ag_state,ag_remind_date) ".
+                    " values 
($1,to_date($2,'DD.MM.YYYY'),$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13)";
+        }
+        $this->db->exec_sql($sql, array($this->ag_id, /* 1 */
+            $this->ag_timestamp, /* 2 */
+            $this->dt_id, /* 3 */
+            $this->ag_title, /* 4 */
+            $exp->id, /* 5 */
+            $ag_ref, /* 6 */
+            $this->ag_dest, /* 7 */
+            $this->ag_hour, /* 8 */
+            $this->ag_priority, /* 9 */
+            $_SESSION['g_user'], /* 10 */
+            $contact->id, /* 11 */
+            $this->ag_state, /* 12 */
+            $this->ag_remind_date /* 13 */
+                )
+        );
+
+        /* insert also the details */
+        for ($i=0; $i<$_POST['nb_item']; $i++)
+        {
+            $act=new Follow_Up_Detail($this->db);
+            $act->from_array($_POST, $i);
+            if ($act->f_id==0)
+                continue;
+            $act->ag_id=$this->ag_id;
+            $act->save();
+        }
+
+        /* Upload the documents */
+        $doc=new Document($this->db);
+        $doc->Upload($this->ag_id);
+        if (trim($this->ag_comment)!='')
+        {
+            $this->db->exec_sql("insert into action_gestion_comment 
(ag_id,tech_user,agc_comment) values ($1,$2,$3)"
+                    , array($this->ag_id, $_SESSION['g_user'], 
$this->ag_comment));
+        }
+        $this->insert_operation();
+        $this->insert_action();
+    }
+
+    /**
+     * myList($p_base, $p_filter = "", $p_search = "") 
+     * Show list of action by default if sorted on date
+     * @param $p_base base url with ac...
+     * @param $p_filter filters on the document_type
+     * @param $p_search must a valid sql command ( ex 'and  ag_title like 
upper('%hjkh%'))
+     * @return string containing html code
+     */
+    function myList($p_base, $p_filter="", $p_search="")
+    {
+        // for the sort
+        $url=HtmlInput::get_to_string(array("closed_action", 
"remind_date_end", "remind_date", "sag_ref", "only_internal", "state", "qcode", 
"ag_dest_query", "action_query", "tdoc", "date_start", "date_end", "hsstate", 
"searchtag")).'&'.$p_base;
+
+        $table=new Sort_Table();
+        $table->add('Date Doc.', $url, 'order by ag_timestamp asc', 'order by 
ag_timestamp desc', 'da', 'dd');
+        $table->add('Date Comm.', $url, 'order by last_comment', 'order by 
last_comment desc', 'dca', 'dcd');
+        $table->add('Date Limite', $url, 'order by ag_remind_date asc', 'order 
by ag_remind_date  desc', 'ra', 'rd');
+        $table->add('Tag', $url, 'order by tags asc', 'order by tags desc', 
'taa', 'tad');
+        $table->add('Réf.', $url, 'order by ag_ref asc', 'order by ag_ref 
desc', 'ra', 'rd');
+        $table->add('Groupe', $url, "order by coalesce((select p_name from 
profile where p_id=ag_dest),'Aucun groupe')", "order by coalesce((select p_name 
from profile where p_id=ag_dest),'Aucun groupe') desc", 'dea', 'ded');
+        $table->add('Dest/Exp', $url, 'order by name asc', 'order by name 
desc', 'ea', 'ed');
+        $table->add('Titre', $url, 'order by ag_title asc', 'order by ag_title 
desc', 'ta', 'td');
+
+        $ord=(!isset($_GET['ord']))?"dcd":$_GET['ord'];
+        $sort=$table->get_sql_order($ord);
+
+        if (strlen(trim($p_filter))!=0)
+            $p_filter_doc=" dt_id in ( $p_filter )";
+        else
+            $p_filter_doc=" 1=1 ";
+
+        $sql="
+             select ag_id,to_char(ag_timestamp,'DD.MM.YYYY') as my_date,
+                to_char(ag_remind_date,'DD.MM.YYYY') as my_remind,
+                to_char(coalesce((select max(agc_date) from 
action_gestion_comment as agc where 
agc.ag_id=ag.ag_id),ag_timestamp),'DD.MM.YY') as str_last_comment,
+                coalesce((select max(agc_date) from action_gestion_comment as 
agc where agc.ag_id=ag.ag_id),ag_timestamp) as last_comment,
+                f_id_dest,
+                s_value,
+                ag_title,dt_value,ag_ref, ag_priority,ag_state,
+                coalesce((select p_name from profile where 
p_id=ag_dest),'Aucun groupe') as dest,
+                (select ad_value from fiche_Detail where f_id=ag.f_id_dest and 
ad_id=1) as name,
+                array_to_string((select array_agg(t1.t_tag) from action_tags 
as a1 join tags as t1 on (a1.t_id=t1.t_id) where a1.ag_id=ag.ag_id ),',') as 
tags
+            from action_gestion as ag
+                join document_type on (ag_type=dt_id)
+                join document_state on (ag_state=s_id)
+             where $p_filter_doc $p_search $sort";
+        $max_line=$this->db->count_sql($sql);
+        $step=$_SESSION['g_pagesize'];
+        $page=(isset($_GET['offset']))?$_GET['page']:1;
+        
$offset=(isset($_GET['offset']))?Database::escape_string($_GET['offset']):0;
+        if ($step!=-1)
+            $limit=" LIMIT $step OFFSET $offset ";
+        else
+            $limit='';
+        $bar=navigation_bar($offset, $max_line, $step, $page);
+
+        $Res=$this->db->exec_sql($sql.$limit);
+        $a_row=Database::fetch_all($Res);
+
+        $r="";
+        $r.='<p>'.$bar.'</p>';
+        $r.='<table class="document">';
+        $r.="<tr>";
+        $r.='<th name="ag_id_td" style="display:none" 
>'.ICheckBox::toggle_checkbox('ag', 'list_ag_frm').'</th>';
+        $r.='<th>'.$table->get_header(0).'</th>';
+        $r.='<th>'.$table->get_header(1).'</th>';
+        $r.='<th>'.$table->get_header(2).'</th>';
+        $r.='<th>'.$table->get_header(3).'</th>';
+        $r.='<th>'.$table->get_header(4).'</th>';
+        $r.='<th>'.$table->get_header(5).'</th>';
+        $r.='<th>'.$table->get_header(6).'</th>';
+        $r.='<th>'.$table->get_header(7).'</th>';
+        $r.=th('Priorité');
+        $r.="</tr>";
+
+
+        // if there are no records return a message
+        if (sizeof($a_row)==0 or $a_row==false)
+        {
+            $r='<div style="clear:both">';
+            $r.='<hr>Aucun enregistrement trouvé';
+            $r.="</div>";
+            return $r;
+        }
+        $today=date('d.m.Y');
+        $i=0;
+        $checkbox=new ICheckBox("mag_id[]");
+        //show the sub_action
+        foreach ($a_row as $row)
+        {
+            $href='<A class="document" 
HREF="do.php?'.$p_base.HtmlInput::get_to_string(array("closed_action", 
"remind_date_end", "remind_date", "sag_ref", "only_internal", "state", 
"gDossier", "qcode", "ag_dest_query", "action_query", "tdoc", "date_start", 
"date_end", "hsstate", "searchtag", "ac"), 
"&").'&sa=detail&ag_id='.$row['ag_id'].'">';
+            $i++;
+            $tr=($i%2==0)?'even':'odd';
+            if ($row['ag_priority']<2)
+                $tr='priority1';
+            $st='';
+            if ($row['my_date']==$today)
+                $st=' style="font-weight:bold; border:2px solid orange;"';
+            $date_remind=format_date($row['my_remind'], 'DD.MM.YYYY', 
'YYYYMMDD');
+            $date_today=date('Ymd');
+            if 
($date_remind!=""&&$date_remind==$date_today&&$row['ag_state']!=1&&$row['ag_state']!=3)
+                $st=' style="font-weight:bold;background:orange"';
+            if 
($date_remind!=""&&$date_remind<$date_today&&$row['ag_state']!=1&&$row['ag_state']!=3)
+                $st=' 
style="font-weight:bold;background:#FF0000;color:white;"';
+            $r.="<tr class=\"$tr\" $st>";
+            $checkbox->value=$row['ag_id'];
+            $r.='<td name="ag_id_td" 
style="display:none">'.$checkbox->input().'</td>';
+            $r.="<td>".$href.smaller_date($row['my_date']).'</a>'."</td>";
+            $r.="<td>".$href.$row['str_last_comment'].'</a>'."</td>";
+            $r.="<td>".$href.smaller_date($row['my_remind']).'</a>'."</td>";
+            $r.="<td>".$href.h($row['tags']).'</a>'."</td>";
+            $r.="<td>".$href.$row['ag_ref'].'</a>'."</td>";
+            $r.="<td>".$href.h($row['dest']).'</a>'."</td>";
+
+            // Expediteur
+            $fexp=new Fiche($this->db);
+            $fexp->id=$row['f_id_dest'];
+            $qcode_dest=$fexp->strAttribut(ATTR_DEF_QUICKCODE);
+
+            $qexp=($qcode_dest==NOTFOUND)?"Interne":$qcode_dest;
+            $jsexp=sprintf("javascript:showfiche('%s')", $qexp);
+            if ($qexp!='Interne')
+            {
+                $r.="<td>$href".$qexp." : ".$fexp->getName().'</a></td>';
+            }
+            else
+                $r.="<td>$href Interne </a></td>";
+
+            $ref="";
+
+
+            $r.='<td>'.$href.
+                    h($row['ag_title'])."</A></td>";
+
+            /*
+             * State
+             */
+            switch ($row['ag_priority'])
+            {
+                case 1:
+                    $priority='Haute';
+                    break;
+                case 2:
+                    $priority="Moyenne";
+                    break;
+                case 3:
+                    $priority="Important";
+                    break;
+            }
+            $r.=td($priority);
+
+            $r.="<td>".$ref."</td>";
+            $r.="</tr>";
+        }
+
+        $r.="</table>";
+
+        $r.='<p>'.$bar.'</p>';
+        return $r;
+    }
+
+    //----------------------------------------------------------------------
+    /*     * \brief Update the data into the database
+     *
+     * \return true on success otherwise false
+     */
+    function Update()
+    {
+
+        // if ag_id == 0 nothing to do
+        if ($this->ag_id==0)
+            return;
+        // retrieve customer
+        // f_id
+
+        if (trim($this->qcode_dest)=="")
+        {
+            // internal document
+            $this->f_id_dest=null; // internal document
+        }
+        else
+        {
+            $tiers=new Fiche($this->db);
+            if ($tiers->get_by_qcode($this->qcode_dest)==-1) // Error we 
cannot retrieve this qcode
+                return false;
+            else
+                $this->f_id_dest=$tiers->id;
+        }
+        $contact=new Fiche($this->db);
+        if ($contact->get_by_qcode($this->ag_contact)==-1)
+            $contact->id=0;
+
+        // reload the old one
+        $old=new Follow_Up($this->db);
+        $old->ag_id=$this->ag_id;
+        $old->get();
+
+        // If ag_ref changed then check if unique
+        if ($old->ag_ref!=$this->ag_ref)
+        {
+            $nAg_ref=$this->db->get_value("select count(*) from action_gestion 
where ag_ref=$1", array($this->ag_ref));
+            if ($nAg_ref!=0)
+            {
+                echo h2("Référence en double, référence non sauvée", 
'class="error"');
+                $this->ag_ref=$old->ag_ref;
+            }
+        }
+
+
+        if ($this->ag_remind_date!=null)
+        {
+            $this->db->exec_sql("update action_gestion set ".
+                    " ag_timestamp=to_date($1,'DD.MM.YYYY'),".
+                    " ag_title=$2,".
+                    " ag_type=$3, ".
+                    " f_id_dest=$4, ".
+                    "ag_state=$5,".
+                    " ag_hour = $7 ,".
+                    " ag_priority = $8 ,".
+                    " ag_dest = $9 , ".
+                    " ag_contact = $10, ".
+                    " ag_ref = $11, ".
+                    " ag_remind_date=to_date($12,'DD.MM.YYYY') ".
+                    " where ag_id = $6", array(
+                $this->ag_timestamp, /* 1 */
+                $this->ag_title, /* 2 */
+                $this->dt_id, /* 3 */
+                $this->f_id_dest, /* 4 */
+                $this->ag_state, /* 5 */
+                $this->ag_id, /* 6 */
+                $this->ag_hour, /* 7 */
+                $this->ag_priority, /* 8 */
+                $this->ag_dest, /* 9 */
+                $contact->id, /* 10 */
+                $this->ag_ref, /* 11 */
+                $this->ag_remind_date /* 12 */
+            ));
+        }
+        else
+        {
+            $this->db->exec_sql("update action_gestion set ".
+                    " ag_timestamp=to_date($1,'DD.MM.YYYY'),".
+                    " ag_title=$2,".
+                    " ag_type=$3, ".
+                    " f_id_dest=$4, ".
+                    "ag_state=$5,".
+                    " ag_hour = $7 ,".
+                    " ag_priority = $8 ,".
+                    " ag_dest = $9 , ".
+                    " ag_contact = $10, ".
+                    " ag_ref = $11, ".
+                    " ag_remind_date=null ".
+                    " where ag_id = $6", array(
+                $this->ag_timestamp, /* 1 */
+                $this->ag_title, /* 2 */
+                $this->dt_id, /* 3 */
+                $this->f_id_dest, /* 4 */
+                $this->ag_state, /* 5 */
+                $this->ag_id, /* 6 */
+                $this->ag_hour, /* 7 */
+                $this->ag_priority, /* 8 */
+                $this->ag_dest, /* 9 */
+                $contact->id, /* 10 */
+                $this->ag_ref /* 11 */
+            ));
+        }
+        // Upload  documents
+        $doc=new Document($this->db);
+        $doc->Upload($this->ag_id);
+
+        /* save action details */
+        for ($i=0; $i<$_POST['nb_item']; $i++)
+        {
+            $act=new Follow_Up_Detail($this->db);
+            $act->from_array($_POST, $i);
+            if ($act->f_id==0&&$act->ad_id!=0)
+                $act->delete();
+            if ($act->f_id==0)
+                continue;
+            $act->save();
+        }
+        if (trim($this->ag_comment)!='')
+        {
+            $this->db->exec_sql("insert into action_gestion_comment 
(ag_id,tech_user,agc_comment) values ($1,$2,$3)"
+                    , array($this->ag_id, $_SESSION['g_user'], 
$this->ag_comment));
+        }
+        $this->insert_operation();
+        $this->insert_action();
+        return true;
+    }
+
+    /**
+     * \brief generate the document and add it to the action
+     * \param md_id is the id of the document_modele
+     * \param $p_array contains normally the $_POST
+     */
+    function generate_document($md_id, $p_array)
+    {
+        $doc=new Document($this->db);
+        $mod=new Document_Modele($this->db, $md_id);
+        $mod->load();
+        $doc->f_id=$this->f_id_dest;
+        $doc->md_id=$md_id;
+        $doc->ag_id=$this->ag_id;
+        $doc->Generate($p_array);
+    }
+
+    /**
+     * \brief put an array in the variable member, the indice
+     * is the member name
+     * \param $p_array to parse
+     *      - ag_id id of the Follow_up
+     *      - ag_ref reference of the action
+     *      - qcode_dest quick_code of the card of dest
+     *      - f_id_dest f_id of the card of dest
+     *      - dt_id Document_Modele::dt_id
+     *      - ag_state document_state::s_id (default:2)
+     *      - ag_title title of the action
+     *      - ag_hour
+     *      - ag_dest Profile, profile of the user
+     *      - ag_comment comment
+     *      - ag_remind_date Remind Date
+     *      - operation related operation
+     *      - action related action 
+     *      - op deprecated
+     * \return nothing
+     */
+    function fromArray($p_array)
+    {
+        global $g_user;
+        $this->ag_id=(isset($p_array['ag_id']))?$p_array['ag_id']:0;
+        $this->ag_ref=(isset($p_array['ag_ref']))?$p_array['ag_ref']:"";
+        
$this->qcode_dest=(isset($p_array['qcode_dest']))?$p_array['qcode_dest']:"";
+        
$this->f_id_dest=(isset($p_array['f_id_dest']))?$p_array['f_id_dest']:null;
+        
$this->ag_timestamp=(isset($p_array['ag_timestamp']))?$p_array['ag_timestamp']:date('d.m.Y');
+        
$this->qcode_dest=(isset($p_array['qcode_dest']))?$p_array['qcode_dest']:"";
+        $this->dt_id=(isset($p_array['dt_id']))?$p_array['dt_id']:"";
+        $this->ag_state=(isset($p_array['ag_state']))?$p_array['ag_state']:2;
+        $this->ag_ref=(isset($p_array['ag_ref']))?$p_array['ag_ref']:"";
+        $this->ag_title=(isset($p_array['ag_title']))?$p_array['ag_title']:"";
+        $this->ag_hour=(isset($p_array['ag_hour']))?$p_array['ag_hour']:"";
+        
$this->ag_dest=(isset($p_array['ag_dest']))?$p_array['ag_dest']:$g_user->get_profile();
+        
$this->ag_priority=(isset($p_array['ag_priority']))?$p_array['ag_priority']:2;
+        
$this->ag_contact=(isset($p_array['ag_contact']))?$p_array['ag_contact']:"";
+        
$this->ag_comment=(isset($p_array['ag_comment']))?$p_array['ag_comment']:"";
+        
$this->ag_remind_date=(isset($p_array['ag_remind_date']))?$p_array['ag_remind_date']:null;
+        
$this->operation=(isset($p_array['operation']))?$p_array['operation']:null;
+        /**
+         * @todo
+         * deprecated : to remove
+          $this->op = (isset($p_array['op'])) ? $p_array['op'] : null;
+         */
+        $this->action=(isset($p_array['action']))?$p_array['action']:null;
+    }
+
+    /**
+     * \brief remove the action
+     *
+     */
+    function remove()
+    {
+        $this->get();
+        // remove the key
+        $sql="delete from action_gestion where ag_id=$1";
+        $this->db->exec_sql($sql, array($this->ag_id));
+
+        /*  check the number of attached document */
+        $doc=new Document($this->db);
+        $aDoc=$doc->get_all($this->ag_id);
+        if (!empty($aDoc))
+        {
+            // if there are documents
+            for ($i=0; $i<sizeof($aDoc); $i++)
+            {
+                $aDoc[$i]->remove();
+            }
+        }
+    }
+
+    /**
+     * \brief return the last p_limit operation into an array, there is a 
security
+     * on user
+     * \param $p_limit is the max of operation to return
+     * \return $p_array of Follow_Up object
+     */
+    function get_last($p_limit)
+    {
+        
+        $sql="select coalesce(vw_name,'Interne') as 
vw_name,quick_code,ag_id,ag_title,ag_ref, 
dt_value,to_char(ag_timestamp,'DD.MM.YYYY') as ag_timestamp_fmt,ag_timestamp ".
+                " from action_gestion join document_type ".
+                " on (ag_type=dt_id) "
+                . "left join vw_fiche_attr on (f_id=f_id_dest) "
+                . "where ag_state in (2,3) "
+                . "and ".self::sql_security_filter($this->db,'R').
+                        "order by ag_timestamp desc limit $p_limit";
+        $array=$this->db->get_array($sql);
+        return $array;
+    }
+
+    /**
+     * get the action where the remind day is today
+     * @return array
+     */
+    function get_today()
+    {
+        $sql="select ag_ref,coalesce(vw_name,'Interne') as 
vw_name,ag_id,ag_title,ag_ref, dt_value,to_char(ag_remind_date,'DD.MM.YYYY') as 
ag_timestamp_fmt,ag_timestamp ".
+                " from action_gestion join document_type ".
+                " on (ag_type=dt_id) 
+                  left join vw_fiche_attr on (f_id=f_id_dest) 
+                  where 
+                  ag_state not in (1,4)
+                  and 
to_char(ag_remind_date,'DDMMYYYY')=to_char(now(),'DDMMYYYY')
+                  and ". self::sql_security_filter($this->db,'R');
+        $array=$this->db->get_array($sql);
+        return $array;
+    }
+
+    /**
+     * get the action where the remind day is today
+     * @return array
+     */
+    function get_late()
+    {
+        $sql="select ag_ref,coalesce(vw_name,'Interne') as 
vw_name,ag_id,ag_title,ag_ref, dt_value,to_char(ag_remind_date,'DD.MM.YYYY') as 
ag_timestamp_fmt,ag_timestamp ".
+                " from action_gestion join document_type ".
+                " on (ag_type=dt_id) left join vw_fiche_attr on 
(f_id=f_id_dest) where ag_state not in  (1,4)
+                               and ag_remind_date < now()  and 
".self::sql_security_filter($this->db,'R');
+        $array=$this->db->get_array($sql);
+        return $array;
+    }
+
+    /**
+     * insert a related operation
+     */
+    function insert_operation()
+    {
+        if (trim($this->operation)=='')
+            return;
+        $array=explode(",", $this->operation);
+        for ($i=0; $i<count($array); $i++)
+        {
+            if ($this->db->get_value("select count(*) from 
action_gestion_operation
+                               where ag_id=$1 and jr_id=$2", 
array($this->ag_id, $array[$i]))==0)
+            {
+                $this->db->exec_sql("insert into action_gestion_operation 
(ag_id,jr_id) values ($1,$2)", array($this->ag_id, $array[$i]));
+            }
+        }
+    }
+
+    /**
+     * remove a related operation
+     * @deprecated not used : dead_code
+     * @todo to remove
+     */
+    function remove_operation_deprecated()
+    {
+        if ($this->op==null)
+            return;
+        $op=$this->op;
+        for ($i=0; $i<count($op); $i++)
+        {
+            $this->db->exec_sql("delete from action_gestion_operation where 
ago_id=$1", array($op[$i]));
+        }
+    }
+
+    /**
+     * Display only a search box for searching an action
+     * @param $cn database connx
+     */
+    static function display_search($cn, $inner=false)
+    {
+        $a=(isset($_GET['action_query']))?$_GET['action_query']:"";
+        $qcode=(isset($_GET['qcode']))?$_GET['qcode']:"";
+
+        $supl_hidden='';
+        if (isset($_REQUEST['sc']))
+            $supl_hidden.=HtmlInput::hidden('sc', $_REQUEST['sc']);
+        if (isset($_REQUEST['f_id']))
+        {
+            $supl_hidden.=HtmlInput::hidden('f_id', $_REQUEST['f_id']);
+            $f=new Fiche($cn, $_REQUEST['f_id']);
+            $supl_hidden.=HtmlInput::hidden('qcode_dest', 
$f->get_quick_code());
+        }
+        if (isset($_REQUEST['sb']))
+            $supl_hidden.=HtmlInput::hidden('sb', $_REQUEST['sb']);
+        $supl_hidden.=HtmlInput::hidden('ac', $_REQUEST['ac']);
+
+        /**
+         * Show the default button (add action, show search...)
+         */
+        if (!$inner)
+            require_once NOALYSS_INCLUDE.'/template/action_button.php';
+
+        $w=new ICard();
+        $w->name='qcode';
+        $w->id=$w->generate_id($w->name);
+        $w->value=$qcode;
+        $w->extra="all";
+        $w->typecard='all';
+        $w->jrn=0;
+        $w->table=0;
+        $list=$cn->make_list("select fd_id from fiche_def where frd_id in 
(4,8,9,14,15,16,25)");
+        $w->extra=$list;
+
+
+        /* type of documents */
+        $type_doc=new ISelect('tdoc');
+        $aTDoc=$cn->make_array('select dt_id,dt_value from document_type order 
by dt_value');
+        $aTDoc[]=array('value'=>'-1', 'label'=>_('Tous les types'));
+        $type_doc->value=$aTDoc;
+        $type_doc->selected=(isset($_GET['tdoc']))?$_GET['tdoc']:-1;
+
+        /* State of documents */
+        $type_state=new ISelect('state');
+        $aState=$cn->make_array('select s_id,s_value from document_state order 
by s_value');
+        $aState[]=array('value'=>'-1', 'label'=>_('Tous les Etats'));
+        $type_state->value=$aState;
+        $type_state->selected=(isset($_GET['state']))?$_GET['state']:-1;
+
+
+
+        /* Except State of documents */
+        $hsExcptype_state=new ISelect('hsstate');
+        $aExcpState=$cn->make_array('select s_id,s_value from document_state 
order by s_value');
+        $aExcpState[]=array('value'=>'-1', 'label'=>_('Aucun'));
+        $hsExcptype_state->value=$aExcpState;
+        
$hsExcptype_state->selected=(isset($_GET['hsstate']))?$_GET['hsstate']:-1;
+
+
+        // date
+        $start=new IDate('date_start');
+        $start->value=(isset($_GET['date_start']))?$_GET['date_start']:"";
+        $end=new IDate('date_end');
+        $end->value=(isset($_GET['date_end']))?$_GET['date_end']:"";
+
+        // Closed action
+        $closed_action=new ICheckBox('closed_action');
+        $closed_action->selected=(isset($_GET['closed_action']))?true:false;
+
+        // Internal
+        $only_internal=new ICheckBox('only_internal');
+        $only_internal->selected=(isset($_GET['only_internal']))?true:false;
+        // select profile
+        $aAg_dest=$cn->make_array("select  p_id as value, ".
+                "p_name as label ".
+                " from profile order by 2");
+        $aAg_dest[]=array('value'=>'-2', 'label'=>_('Tous les profiles'));
+        $ag_dest=new ISelect();
+        $ag_dest->name="ag_dest_query";
+        $ag_dest->value=$aAg_dest;
+        
$ag_dest->selected=(isset($_GET["ag_dest_query"]))?$_GET["ag_dest_query"]:-2;
+        $str_ag_dest=$ag_dest->input();
+        $osag_ref=new IText("sag_ref");
+        $osag_ref->value=(isset($_GET['sag_ref']))?$_GET['sag_ref']:"";
+        $remind_date=new IDate('remind_date');
+        
$remind_date->value=(isset($_GET['remind_date']))?$_GET['remind_date']:"";
+        $remind_date_end=new IDate('remind_date_end');
+        
$remind_date_end->value=(isset($_GET['remind_date_end']))?$_GET['remind_date_end']:"";
+        $otag=new Tag($cn);
+
+        // show the  action in
+        require_once NOALYSS_INCLUDE.'/template/action_search.php';
+    }
+
+    /**
+     * @brief show a list of documents
+     * @param $cn database connextion
+     * @param $p_base base URL
+     */
+    static function show_action_list($cn, $p_base)
+    {
+
+        Follow_Up::display_search($cn);
+
+        $act=new Follow_Up($cn);
+        /** \brief
+         *  \note The field 'recherche' is   about a part of the title or a 
ref. number
+         */
+        $query=Follow_Up::create_query($cn);
+
+        echo '<form method="POST" id="list_ag_frm" style="display:inline">';
+        echo HtmlInput::request_to_hidden(array("gDossier", "ac", "sb", "sc", 
"f_id"));
+        require_once NOALYSS_INCLUDE.'/template/action_other_action.php';
+        echo $act->myList($p_base, "", $query);
+        echo '</form>';
+    }
+
+    /**
+     * Create a subquery to filter thanks the selected tag
+     * @param  $cn db connx
+     * @param $p_array
+     * @return SQL 
+     */
+    static function filter_by_tag($cn, $p_array=null)
+    {
+        if ($p_array==null)
+            $p_array=$_GET;
+
+        extract($p_array);
+        $query="";
+        if (count($searchtag)==0)
+            return "";
+        for ($i=0; $i<count($searchtag); $i++)
+        {
+            if (isNumber($searchtag[$i])==1)
+                $query .= ' and ag_id in (select ag_id from action_tags where 
t_id= '.sql_string($searchtag[$i]).')';
+        }
+        return $query;
+    }
+
+    /**
+     * Get date from $_GET and create the sql stmt for the query
+     * @note the query is taken in $_REQUEST
+     * @see Follow_Up::ShowActionList
+     * @return string SQL condition
+     */
+    static function create_query($cn, $p_array=null)
+    {
+        if ($p_array==null)
+            $p_array=$_GET;
+
+        extract($p_array);
+        $action_query="";
+
+
+        if (isset($_REQUEST['action_query']))
+        {
+            // if a query is request build the sql stmt
+            $action_query="and (ag_title ~* 
'".sql_string($_REQUEST['action_query'])."' ".
+                    "or ag_ref ='".trim(sql_string($_REQUEST['action_query'])).
+                    "' or ag_id in (select ag_id from action_gestion_comment 
where agc_comment ~* '".trim(sql_string($_REQUEST['action_query']))."')".
+                    ")";
+        }
+
+        $str="";
+        if (isset($qcode))
+        {
+            // verify that qcode is not empty
+            if (strlen(trim($qcode))!=0)
+            {
+
+                $fiche=new Fiche($cn);
+                $fiche->get_by_qcode($_REQUEST['qcode']);
+                // if quick code not found then nothing
+                if ($fiche->id==0)
+                    $str=' and false ';
+                else
+                    $str=" and (f_id_dest= ".$fiche->id." or ag_id in (select 
ag_id from action_person as ap where ap.f_id=".$fiche->id.")  )";
+            }
+        }
+        if (isset($tdoc)&&$tdoc!=-1)
+        {
+            $action_query .= ' and dt_id = '.sql_string($tdoc);
+        }
+        if (isset($state)&&$state!=-1)
+        {
+            $action_query .= ' and ag_state= '.sql_string($state);
+        }
+        if (isset($hsstate)&&$hsstate!=-1)
+        {
+            $action_query .= ' and ag_state <> '.sql_string($hsstate);
+        }
+        if (isset($sag_ref)&&trim($sag_ref)!="")
+        {
+            $query .= ' and ag_ref= \''.sql_string($sag_ref)."'";
+        }
+
+        if (isset($_GET['only_internal']))
+            $action_query .= ' and f_id_dest=0 ';
+
+        if (isset($date_start)&&isDate($date_start)!=null)
+        {
+            $action_query.=" and ag_timestamp >= 
to_date('$date_start','DD.MM.YYYY')";
+        }
+        if (isset($date_end)&&isDate($date_end)!=null)
+        {
+            $action_query.=" and ag_timestamp <= 
to_date('$date_end','DD.MM.YYYY')";
+        }
+        if (isset($ag_dest_query)&&$ag_dest_query!=-2)
+        {
+            $action_query.= " and ((ag_dest = ".sql_string($ag_dest_query)." 
and ".self::sql_security_filter($cn, "R").") or ".
+                    "(ag_dest = ".sql_string($ag_dest_query)." and 
".self::sql_security_filter($cn, "R")." and ".
+                    " ag_owner='".$_SESSION['g_user']."'))";
+        }
+        else
+        {
+            $action_query .=" and (ag_owner='".$_SESSION['g_user']."' or 
".self::sql_security_filter($cn, "R")." or ag_dest=-1 )";
+        }
+
+
+        if (isNumber($ag_id)==1&&$ag_id!=0)
+        {
+            $action_query=" and ag_id= ".sql_string($ag_id);
+        }
+        if 
(isset($remind_date)&&$remind_date!=""&&isDate($remind_date)==$remind_date)
+        {
+            $action_query .= " and 
to_date('".sql_string($remind_date)."','DD.MM.YYYY')<= ag_remind_date";
+        }
+        if 
(isset($remind_date_end)&&$remind_date_end!=""&&isDate($remind_date_end)==$remind_date_end)
+        {
+            $action_query .= " and 
to_date('".sql_string($remind_date_end)."','DD.MM.YYYY')>= ag_remind_date";
+        }
+        if (!isset($closed_action))
+        {
+            $action_query.=" and s_status is null ";
+        }
+        if (isset($searchtag))
+        {
+            $action_query .= Follow_Up::filter_by_tag($cn, $p_array);
+        }
+        return $action_query.$str;
+    }
+
+    /**
+     * Show the result of a search in an inner windows, the result is limited 
to 25
+     * @param type $cn database connx
+     * @param type $p_sql the query
+     */
+    static function short_list($cn, $p_sql)
+    {
+        $sql="
+             select ag_id,to_char(ag_timestamp,'DD.MM.YY') as my_date,
+                        f_id_dest,
+             substr(ag_title,1,40) as sub_ag_title,dt_value,ag_ref, 
ag_priority,ag_state,
+                       coalesce((select p_name from profile where 
p_id=ag_dest),'Aucun groupe') as dest,
+                               (select ad_value from fiche_Detail where 
f_id=action_gestion.f_id_dest and ad_id=1) as name
+             from action_gestion
+             join document_type on (ag_type=dt_id)
+                        join document_state on (s_id=ag_state)
+             where $p_sql";
+        $max_line=$cn->count_sql($sql);
+
+        $limit=($max_line>25)?25:$max_line;
+        $Res=$cn->exec_sql($sql."limit ".$limit);
+        $a_row=Database::fetch_all($Res);
+        require_once NOALYSS_INCLUDE.'/template/action_search_result.php';
+    }
+
+    /**
+     * Insert a related action into the table action_gestion_related
+     */
+    function insert_action()
+    {
+        if (trim($this->action)=='')
+            return;
+        $array=explode(",", $this->action);
+        for ($i=0; $i<count($array); $i++)
+        {
+            if ($this->db->get_value("select count(*) from 
action_gestion_related
+                               where (aga_least=$1 and aga_greatest=$2) or 
(aga_greatest=$1 and aga_least=$2)", array($array[$i], 
$this->ag_id))==0&&$this->ag_id!=$array[$i])
+            {
+                $this->db->exec_sql("insert into 
action_gestion_related(aga_least,aga_greatest) values ($1,$2)", 
array($this->ag_id, $array[$i]));
+            }
+        }
+    }
+
+    /**
+     * export to CSV the query the p_array has
+     * @param array $p_array
+     */
+    function export_csv($p_array)
+    {
+        extract($p_array);
+
+
+        $p_search=self::create_query($this->db, $p_array);
+        $sql="
+             select ag_id,
+                       to_char(ag_timestamp,'DD.MM.YYYY') as my_date,
+                        to_char(ag_remind_date,'DD.MM.YYYY') as my_remind,
+                         to_char(coalesce((select max(agc_date) from 
action_gestion_comment as agc where agc.ag_id=ag_id),ag_timestamp),'DD.MM.YY') 
as last_comment,
+                        array_to_string((select array_agg(t1.t_tag) from 
action_tags as a1 join tags as t1 on (a1.t_id=t1.t_id) where a1.ag_id=ag.ag_id 
),',') as tags,
+                               (select ad_value from fiche_Detail where 
f_id=ag.f_id_dest and ad_id=1) as name,
+             ag_title,
+                       dt_value,
+                       ag_ref,
+                       ag_priority,
+                       ag_state,
+                         
+                       coalesce((select p_name from profile where 
p_id=ag_dest),'Aucun groupe') as dest
+             from action_gestion as ag
+             join document_type on (ag.ag_type=dt_id)
+                        join document_state on(ag.ag_state=s_id)
+             where  true  $p_search order by ag.ag_timestamp,ag.ag_id";
+        $ret=$this->db->exec_sql($sql);
+
+        if (Database::num_row($ret)==0)
+            return;
+        $this->db->query_to_csv($ret, array(
+            array("title"=>"doc id", "type"=>"string"),
+            array("title"=>"date", "type"=>"date"),
+            array("title"=>"rappel", "type"=>"date"),
+            array("title"=>"date dernier commentaire", "type"=>"date"),
+            array("title"=>"tags", "type"=>"string"),
+            array("title"=>"nom", "type"=>"string"),
+            array("title"=>"titre", "type"=>"string"),
+            array("title"=>"type document", "type"=>"string"),
+            array("title"=>"ref", "type"=>"string"),
+            array("title"=>"priorite", "type"=>"string"),
+            array("title"=>"etat", "type"=>"string"),
+            array("title"=>"profil", "type"=>"string")
+                )
+        );
+    }
+
+    static function get_all_operation($p_jr_id)
+    {
+        global $cn;
+        $array=$cn->get_array("
+                       select ag_id,ag_ref,ago_id,
+                               ag_title
+                               from action_gestion
+                               join action_gestion_operation using(ag_id)
+                               where
+                               jr_id=$1", array($p_jr_id));
+        return $array;
+    }
+
+    /**
+     * @brief get the tags of the current objet
+     * @return an array idx [ag_id,t_id,at_id,t_tag]
+     */
+    function tag_get()
+    {
+        if ($this->ag_id==0)
+            return;
+        $sql='select b.ag_id,b.t_id,b.at_id,a.t_tag'
+                .' from '
+                .' tags as a join action_tags as b on (a.t_id=b.t_id)'
+                .' where ag_id=$1 '
+                .' order by a.t_tag';
+        $array=$this->db->get_array($sql, array($this->ag_id));
+        return $array;
+    }
+
+    /**
+     * @brief show the tags of the current objet
+     * normally used by ajax. The same tag cannot be added twice
+     * 
+     */
+    function tag_add($p_t_id)
+    {
+        if ($this->ag_id==0)
+            return;
+        $count=$this->db->get_value('select count(*) from action_tags'.
+                ' where ag_id=$1 and t_id=$2', array($this->ag_id, $p_t_id));
+        if ($count>0)
+            return;
+        $sql=' insert into action_tags (ag_id,t_id) values ($1,$2)';
+        $this->db->exec_sql($sql, array($this->ag_id, $p_t_id));
+    }
+
+    /**
+     * @brief remove the tags of the current objet
+     * normally used by ajax
+     */
+    function tag_remove($p_t_id)
+    {
+        if ($this->ag_id==0)
+            return;
+        $sql=' delete from action_tags where ag_id=$1 and t_id=$2';
+        $this->db->exec_sql($sql, array($this->ag_id, $p_t_id));
+    }
+
+    /**
+     * @brief show the cell content in Display for the tags
+     * called also by ajax
+     */
+    function tag_cell()
+    {
+        global $g_user;
+        $a_tag=$this->tag_get();
+        $c=count($a_tag);
+        for ($e=0; $e<$c; $e++)
+        {
+            echo '<span style="border:1px solid black;margin-right:5px;">';
+            echo $a_tag[$e]['t_tag'];
+            if ($g_user->can_write_action($this->ag_id)==true)
+            {
+                
$js_remove=sprintf("onclick=\"action_tag_remove('%s','%s','%s')\"", 
dossier::id(), $this->ag_id, $a_tag[$e]['t_id']);
+                echo HtmlInput::anchor(SMALLX, "javascript:void(0)", 
$js_remove, ' class="smallbutton" style="padding:0px;display:inline" ');
+            }
+            echo '</span>';
+            echo '&nbsp;';
+            echo '&nbsp;';
+        }
+        $js=sprintf("onclick=\"action_tag_select('%s','%s')\"", dossier::id(), 
$this->ag_id);
+        if ($g_user->can_write_action($this->ag_id)==true)
+        {
+            echo HtmlInput::button('tag_bt', 'Ajout tag', $js, 'smallbutton');
+        }
+    }
+
+    static function action_tag_remove($cn, $p_array)
+    {
+        global $g_user;
+        $mag_id=$p_array['mag_id'];
+        $remtag=$p_array['remtag'];
+        for ($i=0; $i<count($mag_id); $i++)
+        {
+            if ($g_user->can_write_action($mag_id[$i])==false)
+                continue;
+            for ($e=0; $e<count($remtag); $e++)
+            {
+                $a=new Follow_Up($cn, $mag_id[$i]);
+                $a->tag_remove($remtag[$e]);
+            }
+        }
+    }
+
+    static function action_tag_add($cn, $p_array)
+    {
+        global $g_user;
+        $mag_id=$p_array['mag_id'];
+        $addtag=$p_array['addtag'];
+        for ($i=0; $i<count($mag_id); $i++)
+        {
+            if ($g_user->can_write_action($mag_id[$i])==false)
+                continue;
+            for ($e=0; $e<count($addtag); $e++)
+            {
+                $a=new Follow_Up($cn, $mag_id[$i]);
+                $a->tag_add($addtag[$e]);
+            }
+        }
+    }
+
+    static function action_tag_clear($cn, $p_array)
+    {
+        global $g_user;
+        $mag_id=$p_array['mag_id'];
+        for ($i=0; $i<count($mag_id); $i++)
+        {
+            if ($g_user->can_write_action($mag_id[$i])==false)
+                continue;
+            $a=new Follow_Up($cn, $mag_id[$i]);
+            $a->tag_clear();
+        }
+    }
+
+    static function action_print($cn, $p_array)
+    {
+        global $g_user;
+        $mag_id=$p_array['mag_id'];
+        for ($i=0; $i<count($mag_id); $i++)
+        {
+            if ($g_user->can_read_action($mag_id[$i])==false)
+                continue;
+            $a=new Follow_Up($cn, $mag_id[$i]);
+            $a->get();
+            echo '<div class="content">';
+            echo $a->Display("READ", false, "");
+            echo '</div>';
+            echo '<P id="breakhere"> - - </p>';
+        }
+    }
+
+    function tag_clear()
+    {
+        $this->db->exec_sql('delete from action_tags where ag_id=$1', 
array($this->ag_id));
+    }
+
+    static function action_set_state($cn, $p_array)
+    {
+
+        global $g_user;
+        $mag_id=$p_array['mag_id'];
+        $state=$p_array['ag_state'];
+        for ($i=0; $i<count($mag_id); $i++)
+        {
+            if ($g_user->can_write_action($mag_id[$i])==false)
+                continue;
+            $cn->exec_sql('update action_gestion set ag_state=$1 where 
ag_id=$2', array($state, $mag_id[$i]));
+        }
+    }
+
+    static function action_remove($cn, $p_array)
+    {
+        global $g_user;
+
+        $mag_id=$p_array['mag_id'];
+        for ($i=0; $i<count($mag_id); $i++)
+        {
+            if ($g_user->can_write_action($mag_id[$i])==false)
+                continue;
+            $cn->exec_sql('delete from action_gestion where ag_id=$1', 
array($mag_id[$i]));
+        }
+    }
+
+    /**
+     * Verify that data are correct
+     * @throws Exception
+     */
+    function verify()
+    {
+        if ($this->dt_id==-1)
+        {
+            throw new Exception(_('Type action invalide'), 10);
+        }
+        if (isDate($this->ag_timestamp)!=$this->ag_timestamp)
+            throw new Exception(_('Date invalide'), 20);
+        if (isDate($this->ag_remind_date)!=$this->ag_remind_date)
+            throw new Exception(_('Date invalide'), 30);
+        if ($this->f_id_dest==0)
+            $this->f_id_dest=null;
+    }
+
+    /**
+     *  Add another concerned (tiers, supplier...)
+     * @global type $g_user
+     * @param type $p_fiche_id
+     */
+    function insert_linked_card($p_fiche_id)
+    {
+        global $g_user;
+        if ($g_user->can_write_action($this->ag_id))
+        {
+            /**
+             * insert into action_person
+             */
+            $count=$this->db->get_value('select count(*) from action_person 
where f_id=$1 and ag_id=$2', array($p_fiche_id, $this->ag_id));
+            if ($count==0)
+            {
+                $this->db->exec_sql('insert into action_person (ag_id,f_id) 
values ($1,$2)', array($this->ag_id, $p_fiche_id));
+            }
+        }
+    }
+
+    /**
+     * Remove  another concerned (tiers, supplier...)
+     * @global type $g_user
+     * @param type $p_fiche_id
+     */
+    function remove_linked_card($p_fiche_id)
+    {
+        global $g_user;
+        if ($g_user->can_write_action($this->ag_id))
+        {
+            $this->db->exec_sql('delete from action_person where ag_id = $1 
and f_id = $2', array($this->ag_id, $p_fiche_id));
+        }
+    }
+
+    /**
+     * Display the other concerned (tiers, supplier...)
+     * @return string
+     */
+    function display_linked()
+    {
+        $a_linked=$this->db->get_array('select ap_id,f_id from action_person 
where ag_id=$1', array($this->ag_id));
+        if (count($a_linked)==0)
+            return "";
+        for ($i=0; $i<count($a_linked); $i++)
+        {
+            $fiche=new Fiche($this->db, $a_linked[$i]['f_id']);
+            $qc=$fiche->get_quick_code();
+            
$js_remove=sprintf("onclick=\"action_remove_concerned('%s','%s','%s')\"", 
dossier::id(), $a_linked[$i]['f_id'], $this->ag_id);
+            echo '<span style="border:1px solid black;margin-right:5px;">';
+            echo $qc;
+            echo HtmlInput::anchor(SMALLX, "javascript:void(0)", $js_remove, ' 
class="smallbutton" style="padding:0px;display:inline" ');
+            echo '</span>';
+            echo '&nbsp;';
+            echo '&nbsp;';
+        }
+    }
+    /**
+     * @brief display a small form to enter a new event
+     * 
+     */
+    function display_short()
+    {
+        $cn=$this->db;
+        include 'template/action_display_short.php'; 
+    }
+    /**
+     * Add an event , with the minimum of informations, 
+     * used in Dashboard and Scheduler
+     */
+    function save_short()
+    {
+        global $g_user;
+        // check if we can add
+        if ($g_user->can_add_action($this->ag_dest) == FALSE ) 
+        {
+                throw new Exception(_('SECURITE : Ajout impossible'));
+        }
+        
+            
+        
+        // Get The sequence id,
+        $seq_name="seq_doc_type_".$this->dt_id;
+        $str_file="";
+        $add_file='';
+
+        
+        $this->ag_id=$this->db->get_next_seq('action_gestion_ag_id_seq');
+
+        // Create the reference
+        $ag_ref=$this->db->get_value('select dt_prefix from document_type '
+                . 'where dt_id=$1', array($this->dt_id))
+                .'-'.$this->db->get_next_seq($seq_name);
+        
+        $this->ag_ref=$ag_ref;
+        /**
+         * If ag_ref already exist then compute a new one
+         */
+        
+        // save into the database
+        $sql="insert into action_gestion".
+                    "(ag_id,ag_timestamp,ag_type,ag_title,f_id_dest,ag_ref, "
+                . "ag_dest, ".
+                    "  ag_priority,ag_owner,ag_state,ag_remind_date) ".
+                    " values "
+                . "($1,to_date($2,'DD.MM.YYYY'),$3,$4,$5,$6,"
+                . "$7,"
+                . "$8,$9,$10,to_date($11,'DD.MM.YYYY'))";
+        
+        $this->db->exec_sql($sql, array(
+            $this->ag_id, /* 1 */
+            $this->ag_timestamp, /* 2 */
+            $this->dt_id, /* 3 */
+            $this->ag_title, /* 4 */
+            $this->f_id_dest, /* 5 */
+            $ag_ref, /* 6 */
+            $this->ag_dest, /* 7 */
+            $this->ag_priority, /* 8 */
+            $_SESSION['g_user'], /* 9 */
+            $this->ag_state, /* 10 */
+            $this->ag_remind_date /* 11 */
+           )
+        );
+
+        if (trim($this->ag_comment)!='')
+        {
+            $this->db->exec_sql("insert into action_gestion_comment 
(ag_id,tech_user,agc_comment) values ($1,$2,$3)"
+                    , array($this->ag_id, $_SESSION['g_user'], 
$this->ag_comment));
+        }
+    }
+}
diff --git a/include/class/class_follow_up_detail.php 
b/include/class/class_follow_up_detail.php
new file mode 100644
index 0000000..89f7e1d
--- /dev/null
+++ b/include/class/class_follow_up_detail.php
@@ -0,0 +1,248 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+require_once  NOALYSS_INCLUDE.'/class/class_fiche.php';
+require_once  NOALYSS_INCLUDE.'/lib/class_database.php';
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief Follow_Up details are the details for a actions
+ */
+
+/*!\brief Follow_Up Details are the details for an actions, it means
+ * the details of an order, delivery order, submit a quote...
+ * this class is linked to the table action_detail
+ * - "id"=>"ad_id", primary key
+ * - "qcode"=>"f_id", quick_code
+ * - "text"=>"ad_text", description lines
+ * - "price_unit"=>"ad_pu", price by unit
+ * - "quantity"=>"ad_quant", quantity
+ * - "tva_id"=>"ad_tva_id", tva_od
+ * - "tva_amount"=>"ad_tva_amount", vat amount
+ * - "total"=>"ad_total_amount", total amount including vat
+ * - "ag_id"=>"ag_id" => foreign key to action_gestion
+ * -  db is the database connection
+ */
+class Follow_Up_Detail
+{
+    private static $variable=array(
+                                 "id"=>"ad_id",
+                                 "qcode"=>"f_id",
+                                 "text"=>"ad_text",
+                                 "price_unit"=>"ad_pu",
+                                 "quantity"=>"ad_quant",
+                                 "tva_id"=>"ad_tva_id",
+                                 "tva_amount"=>"ad_tva_amount",
+                                 "total"=>"ad_total_amount",
+                                 "ag_id"=>"ag_id"
+                             );
+    function __construct ($p_cn,$p_id=0)
+    {
+        $this->db=$p_cn;
+        $this->ad_id=$p_id;
+    }
+    public function get_parameter($p_string)
+    {
+        if ( array_key_exists($p_string,self::$variable) )
+        {
+            $idx=self::$variable[$p_string];
+            return $this->$idx;
+        }
+        else
+           throw new Exception("Attribut inexistant $p_string");
+    }
+    public function set_parameter($p_string,$p_value)
+    {
+        if ( array_key_exists($p_string,self::$variable) )
+        {
+            $idx=self::$variable[$p_string];
+            $this->$idx=$p_value;
+        }
+        else
+            throw new Exception("Attribut inexistant $p_string");
+
+
+    }
+    public function get_info()
+    {
+        return var_export(self::$variable,true);
+    }
+    public function verify()
+    {
+        // Verify that the elt we want to add is correct
+        return 0;
+    }
+    public function save()
+    {
+        if (  $this->ad_id == 0 )
+            $this->insert();
+        else
+            $this->update();
+    }
+
+    public function insert()
+    {
+        if ( $this->verify() != 0 ) return;
+        $sql='INSERT INTO action_detail('.
+             ' f_id, ad_text, ad_pu, ad_quant, ad_tva_id, ad_tva_amount,'.
+             '   ad_total_amount, ag_id)'.
+             ' VALUES ($1, $2, $3, $4,$5,$6,$7,$8) returning ad_id';
+        $this->ad_id=$this->db->get_value($sql,array(
+                                              $this->f_id,
+                                              $this->ad_text,
+                                              $this->ad_pu,
+                                              $this->ad_quant,
+                                              $this->ad_tva_id,
+                                              $this->ad_tva_amount,
+                                              $this->ad_total_amount,
+                                              $this->ag_id
+                                          )
+                                         );
+
+    }
+
+    public function update()
+    {
+        if ( $this->verify() != 0 ) return;
+
+        $sql='UPDATE action_detail '.
+             ' SET f_id=$1, ad_text=$2, ad_pu=$3, ad_quant=$4, ad_tva_id=$5,'.
+             '     ad_tva_amount=$6, ad_total_amount=$7, ag_id=$8'.
+             ' WHERE ad_id=$9';
+        $this->id=$this->db->exec_sql($sql,array(
+                                          $this->f_id,
+                                          $this->ad_text,
+                                          $this->ad_pu,
+                                          $this->ad_quant,
+                                          $this->ad_tva_id,
+                                          $this->ad_tva_amount,
+                                          $this->ad_total_amount,
+                                          $this->ag_id,
+                                          $this->ad_id
+                                      )
+                                     );
+
+
+    }
+    /*!\brief retrieve all the details of an Follow_Up
+     *\return array of Action_Detail
+     *\see Follow_Up::get
+     */
+    public function load_all()
+    {
+        $sql="SELECT ad_id, f_id, ad_text, ad_pu, ad_quant, ad_tva_id, 
ad_tva_amount,
+             ad_total_amount, ag_id   FROM action_detail ".
+             " where ag_id=$1 order by ad_id";
+        $res=$this->db->get_array(
+                 $sql,
+                 array($this->ag_id)
+             );
+        if ( $this->db->count() == 0 ) return;
+        $aRet=array();
+        for($i=0;$i<count($res);$i++)
+        {
+            $a=new Follow_Up_Detail($this->db);
+            $row=$res[$i];
+            foreach ($row as $idx=>$value)
+            {
+                $a->$idx=$value;
+            }
+            $aRet[$i]=clone $a;
+        }
+        return $aRet;
+    }
+
+    public function load()
+    {
+        $sql="SELECT ad_id, f_id, ad_text, ad_pu, ad_quant, ad_tva_id, 
ad_tva_amount,
+             ad_total_amount, ag_id   FROM action_detail".
+             " where ad_id=$1";
+
+        $res=$this->db->get_array($this->db,
+                                  $sql,
+                                  array($this->ad_id)
+                                 );
+        if ( $this->db->count() == 0 ) return;
+        $row=$res[0];
+        foreach ($row as $idx=>$value)
+        {
+            $this->$idx=$value;
+        }
+
+    }
+    public function delete()
+    {
+               $sql="delete from action_detail where ad_id=$1";
+               $this->db->exec_sql($sql,array($this->ad_id));
+       }
+    /*!\brief Fill an Action_Detail Object with the data contained in an array
+    *\param $array
+     - [ad_id7] => ad_id
+     - [e_march7] =>  f_id
+     - [e_march7_label] => ad_text
+     - [e_march7_price] => ad_pu
+     - [e_quant7] => ad_quant
+     - [e_march7_tva_id] => ad_tva_id
+     - [e_march7_tva_amount] => ad_tva_amount
+     - [tvac_march7] => ad_total_amount
+     - [ag_id] => ag_id
+     *\param $idx is the idx (example 7)
+     *\note    */
+    public function from_array($array,$idx)
+    {
+        $row=$array;
+        $this->ad_id=(isset($row['ad_id'.$idx]))?$row['ad_id'.$idx]:0;
+
+        $qcode=(isset($row['e_march'.$idx]))?$row['e_march'.$idx]:"";
+        if (trim($qcode)=='')
+        {
+            $this->f_id=0;
+        }
+        else
+        {
+            $tmp=new Fiche($this->db);
+            $tmp->get_by_qcode($qcode,false);
+            $this->f_id=$tmp->id;
+        }
+        
$this->ad_text=(isset($row['e_march'.$idx.'_label']))?$row['e_march'.$idx.'_label']:"";
+        
$this->ad_pu=(isset($row['e_march'.$idx.'_price']))?$row['e_march'.$idx.'_price']:0;
+        $this->ad_quant=(isset($row['e_quant'.$idx]))?$row['e_quant'.$idx]:0;
+        
$this->ad_tva_id=(isset($row['e_march'.$idx.'_tva_id']))?$row['e_march'.$idx.'_tva_id']:0;
+        
$this->ad_tva_amount=(isset($row['e_march'.$idx.'_tva_amount']))?$row['e_march'.$idx.'_tva_amount']:0;
+        
$this->ad_total_amount=(isset($row['tvac_march'.$idx]))?$row['tvac_march'.$idx]:0;
+        $this->ag_id=(isset($array['ag_id']))?$array['ag_id']:0;
+        /* protect numeric */
+        if (trim($this->ad_pu)=="" || isNumber($this->ad_pu)==0) 
$this->ad_pu=0;
+        if (trim($this->ad_quant)=="" || isNumber($this->ad_quant)==0) 
$this->ad_quant=0;
+        if (trim($this->ad_tva_amount)==""||isNumber($this->ad_tva_amount)==0) 
$this->ad_tva_amount=0;
+        if 
(trim($this->ad_total_amount)==""||isNumber($this->ad_total_amount)==0) 
$this->ad_total_amount=0;
+        if (trim($this->ad_tva_id)=="" || isNumber($this->ad_tva_id)==0) 
$this->ad_tva_id=0;
+    }
+    /*!\brief
+     *\param
+     *\return
+     *\note
+     *\see
+     */
+    static function test_me()
+{}
+
+}
+
+/* test::test_me(); */
+
diff --git a/include/class_forecast.php b/include/class/class_forecast.php
similarity index 100%
rename from include/class_forecast.php
rename to include/class/class_forecast.php
diff --git a/include/class_forecast_cat.php 
b/include/class/class_forecast_cat.php
similarity index 100%
rename from include/class_forecast_cat.php
rename to include/class/class_forecast_cat.php
diff --git a/include/class_forecast_item.php 
b/include/class/class_forecast_item.php
similarity index 100%
rename from include/class_forecast_item.php
rename to include/class/class_forecast_item.php
diff --git a/include/class/class_gestion_purchase.php 
b/include/class/class_gestion_purchase.php
new file mode 100644
index 0000000..b738bb3
--- /dev/null
+++ b/include/class/class_gestion_purchase.php
@@ -0,0 +1,128 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+* \brief Definition of the class gestion_purchase
+ */
+
+/*! \brief this object handles the table quant_purchase
+ *
+ */
+require_once  NOALYSS_INCLUDE.'/class/class_gestion_table.php';
+
+
+class gestion_purchase extends gestion_table
+{
+    var $qp_id;                                        /*!< id */
+    var $qp_internal;                          /*!< internal code */
+    var $qp_fiche;                                     /*!< card id 
(fiche.f_id) */
+    var $qp_quantite;                          /*!< quantity */
+    var $qp_price;                                     /*!< quantity */
+    var $qp_vat;                                       /*!< vat amount */
+    var $qp_vat_code;                          /*!< vat_code */
+    var $qp_nd_amount;                         /*!< no deductible */
+    var $qp_nd_tva;                            /*!< tva not deductible */
+    var $qp_nd_tva_recup;                      /*!< tva ded via taxe */
+    var $qp_supplier;                          /*!< supplier code (f_id) */
+    var $qp_valid;
+    var $j_id;                                         /*!< jrnx.j_id
+                                                                 */
+    var $qp_dep_priv;          /*!< private purchase */
+    var $qp_vat_sided;      /* autoliquidation */
+    /*!\brief return an array of gestion_table, the object are
+     * retrieved thanks the qs_internal
+     */
+    function get_list()
+    {
+        if ($this->qp_internal=="")
+            throw  new Exception(__FILE__.__LINE__." qs_internal est vide");
+        $sql="select  qp_id,
+             qp_internal,
+             qp_fiche,
+             qp_quantite,
+             qp_price,
+             qp_vat,
+             qp_vat_code,
+             tva_rate,
+             tva_label,
+             qp_nd_amount,
+             qp_nd_tva,
+             qp_nd_tva_recup,
+             qp_supplier,
+             j_id,
+             qp_dep_priv,
+             qp_vat_sided
+             from quant_purchase left join tva_rate on (qp_vat_code=tva_id)
+             where qp_internal='".$this->qp_internal."'";
+        $ret=$this->db->exec_sql($sql);
+        // $res contains all the line
+        $res=Database::fetch_all($ret);
+
+        if ( sizeof($res)==0) return null;
+        $count=0;
+        foreach ($res as $row)
+        {
+            $t_gestion_purchase=new gestion_purchase($this->db);
+            foreach ($row as $idx=>$value)
+            $t_gestion_purchase->$idx=$value;
+            $array[$count]=clone $t_gestion_purchase;
+            $count++;
+        }
+        return $array;
+    }
+    function search_by_jid($p_jid)
+    {
+        $res=$this->db->exec_sql("select qp_id from quant_purchase where 
j_id=".$p_jid);
+
+        if ( Database::num_row($res) == 1)
+            $this->qp_id=Database::fetch_result($res,0,0);
+        else
+            $this->qp_id=0;
+    }
+    function load()
+    {
+        $sql="select  qp_id,
+             qp_internal,
+             qp_fiche,
+             qp_quantite,
+             qp_price,
+             qp_vat,
+             qp_vat_code,
+             qp_nd_amount,
+             qp_nd_tva,
+             qp_nd_tva_recup,
+             qp_supplier,
+             j_id,
+             qp_dep_priv,
+             qp_vat_sided
+             from quant_purchase
+             where qp_id=".$this->qp_id;
+        $ret=$this->db->exec_sql($sql);
+        // $res contains all the line
+        $res=Database::fetch_all($ret);
+
+        if ( empty($res) ) return null;
+        foreach ($res[0] as $idx=>$value)
+        $this->$idx=$value;
+
+    }
+
+}
diff --git a/include/class/class_gestion_sold.php 
b/include/class/class_gestion_sold.php
new file mode 100644
index 0000000..a047ab6
--- /dev/null
+++ b/include/class/class_gestion_sold.php
@@ -0,0 +1,115 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief definition of the class gestion_sold
+ */
+
+/*! \brief this object handles the table quant_sold
+ *
+ */
+
+require_once  NOALYSS_INCLUDE.'/class/class_gestion_table.php';
+
+
+class gestion_sold extends gestion_table
+{
+    var $qs_id;                                        /*!< $qs_id primary key 
*/
+    var $qs_internal;                          /*!< qs_internal */
+    var $qs_fiche;                             /*!< f_id code  */
+    var $qs_quantite;                          /*!< quantity of the card */
+    var $qs_price;                             /*!< price */
+    var $qs_vat;                                       /*!< vat_amount */
+    var $qs_vat_code;                          /*!< vat_code */
+    var $qs_client;                            /*!< f_id of the customer */
+    var $qs_valid;                             /*!< will not be used */
+    var $j_id;                                 /*!< jrnx.j_id */
+    var $qs_vat_sided;
+    /*!\brief return an array of gestion_table, the object are
+     * retrieved thanks the qs_internal
+     */
+    function get_list()
+    {
+        if ($this->qs_internal=="")
+            throw  new Exception(__FILE__.__LINE__." qs_internal est vide");
+        $sql="select  qs_id,
+             qs_internal,
+             qs_fiche,
+             qs_quantite,
+             qs_price,
+             qs_vat,
+             tva_label,
+             tva_rate,
+             qs_vat_code,
+             qs_client,
+             j_id,
+             qs_vat_sided
+             from quant_sold left join tva_rate on (qs_vat_code=tva_id)
+             where qs_internal='".$this->qs_internal."'";
+        $ret=$this->db->exec_sql($sql);
+        // $res contains all the line
+        $res=Database::fetch_all($ret);
+
+        if ( sizeof($res)==0) return null;
+        $count=0;
+
+        foreach ($res as $row)
+        {
+            $t_gestion_sold=new gestion_sold($this->db);
+            foreach ($row as $idx=>$value)
+            $t_gestion_sold->$idx=$value;
+            $array[$count]=clone $t_gestion_sold;
+            $count++;
+        }
+        return $array;
+    }
+     function search_by_jid($p_jid)
+    {
+        $res=$this->db->exec_sql("select qs_id from quant_sold where 
j_id=".$p_jid);
+
+        if ( Database::num_row($res) == 1)
+            $this->qs_id=Database::fetch_result($res,0,0);
+        else
+            $this->qs_id=0;
+    }
+    function load()
+    {
+       $sql=" select  qs_id,
+             qs_internal,
+             qs_fiche,
+             qs_quantite,
+             qs_price,
+             qs_vat,
+             qs_vat_code,
+             qs_client,
+             j_id,
+             qs_vat_sided
+             from quant_sold 
+             where qs_id=$1";
+       $ret=$this->db->exec_sql($sql,array($this->qs_id));
+        // $res contains all the line
+        $res=Database::fetch_all($ret);
+
+        if ( empty($res) ) return null;
+        foreach ($res[0] as $idx=>$value)
+        $this->$idx=$value;
+    }
+}
diff --git a/include/class_gestion_table.php 
b/include/class/class_gestion_table.php
similarity index 100%
rename from include/class_gestion_table.php
rename to include/class/class_gestion_table.php
diff --git a/include/class/class_lettering.php 
b/include/class/class_lettering.php
new file mode 100644
index 0000000..ccfd202
--- /dev/null
+++ b/include/class/class_lettering.php
@@ -0,0 +1,760 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief letter the accounting entry (row level)
+ */
+require_once  NOALYSS_INCLUDE.'/class/class_user.php';
+
+/**
+ address@hidden mother class for the lettering by account and by card
+ * use the tables jnt_letter, letter_deb and letter_cred
+ * - "account"=>"account",       => the accounting of the j_id (use by 
Lettering_Account)
+ * - "quick_code"=>"quick_code", => the quick_code of the j_id (used by 
Lettering_Card)
+ * - "start"=>"start",    => date of the first day
+ * - "end"=>"end",                => date of the last day
+ * - "sql_ledger"=>"sql_ledger"  => the sql clause to filter on the available 
ledgers
+*/
+class Lettering
+{
+
+    protected $variable=array("account"=>"account", /* the accounting of the 
j_id (use by Lettering_Account) */
+                              "quick_code"=>"quick_code", /* the quick_code of 
the j_id (used by Lettering_Card) */
+                              "start"=>"start",                /* date of the 
first day */
+                              "end"=>"end",            /* date of the last day 
*/
+                              "sql_ledger"=>"sql_ledger"       /*   the sql 
clause to filter on the available ledgers */
+                             )
+                        ;
+    /**
+     * constructor
+     address@hidden $p_init resource to database
+     address@hidden by default start and end are the 1.1.exercice to 
31.12.exercice
+     */
+    function __construct ($p_init)
+    {
+        $this->db=$p_init;
+        $a=new User($p_init);
+        $exercice=$a->get_exercice();
+        $this->start='01.01.'.$exercice;
+        $this->end='31.12.'.$exercice;
+        // available ledgers
+        
$this->sql_ledger=str_replace('jrn_def_id','jr_def_id',$a->get_ledger_sql('ALL',3));
+
+    }
+    public function get_parameter($p_string)
+    {
+        if ( array_key_exists($p_string,$this->variable) )
+        {
+            $idx=$this->variable[$p_string];
+            return $this->$idx;
+        }
+        else
+            throw new Exception (__FILE__.":".__LINE__.$p_string.'Erreur 
attribut inexistant');
+    }
+    public function set_parameter($p_string,$p_value)
+    {
+        if ( array_key_exists($p_string,$this->variable) )
+        {
+            $idx=$this->variable[$p_string];
+            $this->$idx=$p_value;
+        }
+        else
+            throw new Exception (__FILE__.":".__LINE__.$p_string.'Erreur 
attribut inexistant');
+    }
+    /**
+     *Use to just insert a couple of lettered operation
+     */
+    function insert_couple($j_id1,$j_id2)
+    {
+
+        /*  take needed data */
+        $first=$this->db->get_value('select j_debit from jrnx where 
j_id=$1',array($j_id1));
+        if ( $this->db->count() == 0 ) throw new Exception ('Opération non 
existante');
+
+        $second=$this->db->get_value('select j_debit from jrnx where 
j_id=$1',array($j_id2));
+        if ( $this->db->count() == 0 ) throw new Exception ('Opération non 
existante');
+               $sql_already="select distinct(jl_id)
+                       from jnt_letter
+                       left outer join letter_deb using (jl_id)
+                       left outer join letter_cred using (jl_id)
+                       where
+                       letter_deb.j_id = $1 or letter_cred.j_id=$1";
+               $let1=0;$let2=0;
+               $already=$this->db->get_array($sql_already,array($j_id1));
+               if ( count ($already ) > 0) {
+                       if ( count($already)==1) {
+                               // retrieve the letter
+                               $let1=$this->db->get_value("select 
distinct(jl_id)
+                                                                               
from jnt_letter
+                                                                               
left outer join letter_deb using (jl_id)
+                                                                               
left outer join letter_cred using (jl_id)
+                                                                               
where
+                                                                               
letter_deb.j_id = $1 or letter_cred.j_id=$1",array($j_id1));
+                       }else
+                       {
+                               return;
+                       }
+               }
+
+               $already=$this->db->get_array($sql_already,array($j_id2));
+               if ( count ($already ) > 0) {
+                       if ( count($already)==1) {
+                               // retrieve the letter
+                               $let2=$this->db->get_value("select 
distinct(jl_id)
+                                                                               
from jnt_letter
+                                                                               
left outer join letter_deb using (jl_id)
+                                                                               
left outer join letter_cred using (jl_id)
+                                                                               
where
+                                                                               
letter_deb.j_id = $1 or letter_cred.j_id=$1",array($j_id2));
+                       }else  {
+                               return;
+                       }
+               }
+               $jl_id=0;
+               // already linked together
+               if ( $let1 != 0 && $let1 == $let2 )return;
+
+               // already linked
+               if ( $let1 != 0 && $let2!=0 && $let1 != $let2 )return;
+
+               // none is linked
+               if ( $let1 == 0 && $let2==0)
+               {
+                       $jl_id=$this->db->get_next_seq("jnt_letter_jl_id_seq");
+                       $this->db->exec_sql('insert into jnt_letter(jl_id) 
values($1)',
+                                                               array($jl_id));
+               }
+               // one is linked but not the other
+               if ( $let1 == 0 && $let2 != 0 ) $jl_id=$let2;
+               if ( $let1 != 0 && $let2 == 0 ) $jl_id=$let1;
+
+               /* insert */
+        if ( $first == 't')
+        {
+            // save into letter_deb
+            if ($let1 == 0) $ld_id=$this->db->get_value('insert into 
letter_deb(j_id,jl_id) values($1,$2) returning ld_id',array($j_id1,$jl_id));
+        }
+        else
+        {
+            if ($let1 == 0)$lc_id=$this->db->get_value('insert into 
letter_cred(j_id,jl_id)  values($1,$2) returning lc_id',array($j_id1,$jl_id));
+        }
+        if ( $second == 't')
+        {
+            // save into letter_deb
+            if ($let2 == 0)$ld_id=$this->db->get_value('insert into 
letter_deb(j_id,jl_id) values($1,$2) returning ld_id',array($j_id2,$jl_id));
+        }
+        else
+        {
+            if ($let2 == 0)$lc_id=$this->db->get_value('insert into 
letter_cred(j_id,jl_id)  values($1,$2) returning lc_id',array($j_id2,$jl_id));
+        }
+
+    }
+    public function get_info()
+    {
+        return var_export(self::$variable,true);
+    }
+    public function verify()
+    {
+        // Verify that the elt we want to add is correct
+    }
+    /**
+     address@hidden save from array
+     address@hidden $p_array
+    @code
+    'gDossier' => string '13' (length=2)
+    'letter_j_id' =>
+       ck => array
+    @endcode
+    */
+    public function save($p_array)
+    {
+        if ( ! isset ($p_array['letter_j_id'])) return;
+        $this->db->exec_sql('delete from jnt_letter where 
jl_id=$1',array($p_array['jnt_id']));
+
+        $this->db->start();
+        $jl_id=$this->db->get_next_seq("jnt_letter_jl_id_seq");
+        $this->db->exec_sql('insert into jnt_letter(jl_id) values($1)',
+                            array($jl_id));
+
+        // save the source
+        $deb=$this->db->get_value('select j_debit,j_montant from jrnx where 
j_id=$1',array($p_array['j_id']));
+        if ( $deb == 't')
+        {
+            // save into letter_deb
+            $ld_id=$this->db->get_value('insert into letter_deb(j_id,jl_id) 
values($1,$2) returning ld_id',array($p_array['j_id'],$jl_id));
+        }
+        else
+        {
+            $lc_id=$this->db->get_value('insert into letter_cred(j_id,jl_id)  
values($1,$2) returning lc_id',array($p_array['j_id'],$jl_id));
+        }
+        $count=0;
+        // save dest
+        for($i=0;$i<count($p_array['letter_j_id']);$i++)
+        {
+            if (isset ($p_array['ck'][$i]) && $p_array['ck'][$i] !="-2")
+            { //if 1
+                // save the dest
+                $deb=$this->db->get_value('select j_debit,j_montant from jrnx 
where j_id=$1',array($p_array['ck'][$i]));
+                if ( $deb == 't')
+                {
+                    $count++;
+                    // save into letter_deb
+                    $ld_id=$this->db->get_value('insert into 
letter_deb(j_id,jl_id) values($1,$2) returning 
ld_id',array($p_array['ck'][$i],$jl_id));
+                }
+                else
+                {
+                    $count++;
+                    $lc_id=$this->db->get_value('insert into 
letter_cred(j_id,jl_id)  values($1,$2) returning 
lc_id',array($p_array['ck'][$i],$jl_id));
+                }
+            } //end if 1
+        } //end for
+        // save into jnt_letter
+        /* if only one row we delete the joint */
+        if ( $count==0)
+        {
+            $this->db->rollback();
+        }
+        $this->db->commit();
+    }
+    /**
+     address@hidden retrieve * row thanks a condition
+     */
+    public function seek($cond,$p_array=null)
+    {
+        /*
+          $sql="select * from * where $cond";
+          return $this->cn->get_array($cond,$p_array)
+        */
+    }
+    public function insert()
+    {
+        if ( $this->verify() != 0 ) return;
+
+    }
+    /**
+     *show all the record from jrnx and their status (linked or not)
+     *it fills the array $this->content
+     */
+    protected function show_all()
+    {
+        $this->get_all();
+        $r="";
+        ob_start();
+        include('template/letter_all.php');
+        $r=ob_get_contents();
+        ob_end_clean();
+        return $r;
+    }
+       function get_linked($p_jlid)
+       {
+               $sql="select j_id,j_date,to_char(j_date,'DD.MM.YYYY') as 
j_date_fmt,
+             j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
+             coalesce(comptaproc.get_letter_jnt(j_id),-1) as letter
+             from jrnx join jrn on (j_grpt = jr_grpt_id)
+                        where
+                        j_id in (select j_id from letter_cred where jl_id=$1
+                                       union all
+                                       select j_id from letter_deb where 
jl_id=$1)
+                                       order by j_date";
+
+               $this->linked=$this->db->get_array($sql,array($p_jlid));
+       }
+    /**
+     *show only the lettered records from jrnx
+     *it fills the array $this->content
+     */
+    protected function show_lettered()
+    {
+        $this->get_letter();
+        $r="";
+        ob_start();
+        include('template/letter_all.php');
+        $r=ob_get_contents();
+        ob_end_clean();
+        return $r;
+    }
+       /**
+     *show only the lettered records from jrnx
+     *it fills the array $this->content
+     */
+    protected function show_lettered_diff()
+    {
+        $this->get_letter_diff();
+        $r="";
+        ob_start();
+        include('template/letter_all.php');
+        $r=ob_get_contents();
+        ob_end_clean();
+        return $r;
+    }
+
+    /**
+     *show only the not lettered records from jrnx
+     *it fills the array $this->content
+     */
+
+    protected function show_not_lettered()
+    {
+        $this->get_unletter();
+        $r="";
+        ob_start();
+        include('template/letter_all.php');
+        $r=ob_get_contents();
+        ob_end_clean();
+        return $r;
+    }
+    /**
+     *wrapper : it call show_all, show_lettered or show_not_lettered depending
+     * of the parameter
+     address@hidden $p_type poss. values are all, unletter, letter
+     */
+    public function show_list($p_type)
+    {
+        switch($p_type)
+        {
+        case 'all':
+                return $this->show_all();
+            break;
+        case 'unletter':
+            return $this->show_not_lettered();
+            break;
+        case 'letter':
+            return $this->show_lettered();
+            break;
+               case 'letter_diff':
+                       return $this->show_lettered_diff();
+                       break;
+        }
+        throw new Exception ("[$p_type] is no unknown");
+    }
+
+    public function show_letter($p_jid)
+    {
+        $j_debit=$this->db->get_value('select j_Debit from jrnx where 
j_id=$1',array($p_jid));
+        $amount_init=$this->db->get_value('select j_montant from jrnx where 
j_id=$1',array($p_jid));
+
+        $this->get_filter($p_jid);
+        // retrieve jnt_letter.id
+        $sql="select distinct(jl_id) from jnt_letter  left outer join 
letter_deb using (jl_id) left outer join letter_cred using (jl_id)
+             where letter_deb.j_id = $1 or letter_cred.j_id=$2";
+        $a_jnt_id=$this->db->get_array($sql,array($p_jid,$p_jid));
+
+        if (count($a_jnt_id)==0 )
+               {
+                       $jnt_id=-2;
+               } else
+               {
+                       $jnt_id=$a_jnt_id[0]['jl_id'];
+               }
+               $this->get_linked($jnt_id);
+        ob_start();
+        require_once NOALYSS_INCLUDE.'/template/letter_prop.php';
+        $r=ob_get_contents();
+        ob_end_clean();
+        $r.=HtmlInput::hidden('j_id',$p_jid);
+        $r.=HtmlInput::hidden('jnt_id',$jnt_id);
+
+        return $r;
+    }
+
+    public function update()
+    {
+        if ( $this->verify() != 0 ) return;
+    }
+
+    public function load()
+{}
+
+    public function delete()
+    {
+        throw new Exception ('delete not implemented');
+    }
+    /**
+     * Unit test for the class
+     */
+    static function test_me()
+    {}
+
+}
+/**
+ * only for operation retrieved thanks a account (jrnx.j_poste)
+ * manage the accounting entries for a given account
+ */
+
+class Lettering_Account extends Lettering
+{
+    function __construct($p_init,$p_account=null)
+    {
+        parent::__construct($p_init);
+        $this->account=$p_account;
+        $this->object_type='account';
+    }
+
+    /**
+     * fills the this->content, datas are filtered thanks
+     * - fil_deb poss values t (debit), f(credit), ' ' (everything)
+     * - fil_amount_max max amount
+     * - fil_amount_min min amount
+     * - $this->start min date
+     * - $this->end max date
+     * - this->account: accounting
+     */
+    public function get_filter($p_jid=0)
+    {
+        $filter_deb='';
+        if (isset($this->fil_deb))
+        {
+            switch ($this->fil_deb)
+            {
+            case 0:
+                $filter_deb=" and j_debit='t' ";
+                break;
+            case 1:
+                $filter_deb=" and j_debit='f' ";
+                break;
+            case 2:
+                $filter_deb=" ";
+                break;
+            }
+
+        }
+        $filter_amount="";
+        if ( isset ($this->fil_amount_max ) &&
+                isset ($this->fil_amount_min ) &&
+                isNumber($this->fil_amount_max)==1 &&
+                isNumber($this->fil_amount_min)==1 &&
+                ($this->fil_amount_max != 0 || $this->fil_amount_min != 0) )
+            $filter_amount=" and (j_montant >= $this->fil_amount_min and 
j_montant<=$this->fil_amount_max  or 
(coalesce(comptaproc.get_letter_jnt($p_jid),-1)= 
coalesce(comptaproc.get_letter_jnt(j_id),-1) and 
coalesce(comptaproc.get_letter_jnt($p_jid),-1) <> -1 )) ";
+        $sql="
+             select j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,
+             j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
+             coalesce(comptaproc.get_letter_jnt(j_id),-1) as letter
+             from jrnx join jrn on (j_grpt = jr_grpt_id)
+             where j_poste = $1 and j_date >= to_date($2,'DD.MM.YYYY') and 
j_date <= to_date ($3,'DD.MM.YYYY')
+             and $this->sql_ledger
+             $filter_deb
+             $filter_amount
+             order by j_date,j_id";
+
+        
$this->content=$this->db->get_array($sql,array($this->account,$this->start,$this->end));
+    }
+
+    /**
+     * fills this->content with all the operation for the 
this->account(jrnx.j_poste)
+     */
+    public function get_all()
+    {
+        $sql=" with let_diff as (select jl_id,deb_amount-cred_amount as 
diff_letter1
+                       from
+                       ( select jl_id,coalesce(sum(j_montant),0) as 
cred_amount from letter_cred join jrnx using (j_id) group by jl_id) as CRED
+                       left join (select jl_id,coalesce(sum(j_montant),0) as 
deb_amount from letter_deb join jrnx using (j_id) group by jl_id) as DEB using 
(jl_id)) ,
+                       letter_jl as (select jl_id,j_id from letter_cred union 
all select jl_id,j_id from letter_deb)
+                       select j_id,j_date,to_char(j_date,'DD.MM.YYYY') as 
j_date_fmt,jr_pj_number,
+                                               
j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
+                                                       
coalesce(let_diff.jl_id,-1) as letter,
+                                       diff_letter1 as letter_diff
+                                               from jrnx join jrn on (j_grpt = 
jr_grpt_id)
+                                               left join letter_jl using (j_id)
+                                               left join let_diff using (jl_id)
+             where j_poste = $1 and j_date >= to_date($2,'DD.MM.YYYY') and 
j_date <= to_date ($3,'DD.MM.YYYY')
+             and $this->sql_ledger
+
+             order by j_date,j_id";
+        
$this->content=$this->db->get_array($sql,array($this->account,$this->start,$this->end));
+    }
+    /**
+     * same as get_all but only for lettered operation
+     */
+    public function get_letter()
+    {
+        $sql="
+                       with let_diff as (select jl_id,deb_amount-cred_amount 
as diff_letter1
+                       from
+                       ( select jl_id,coalesce(sum(j_montant),0) as 
cred_amount from letter_cred join jrnx using (j_id) group by jl_id) as CRED
+                       left join (select jl_id,coalesce(sum(j_montant),0) as 
deb_amount from letter_deb join jrnx using (j_id) group by jl_id) as DEB using 
(jl_id)) ,
+                       letter_jl as (select jl_id,j_id from letter_cred union 
all select jl_id,j_id from letter_deb)
+                       select j_id,j_date,to_char(j_date,'DD.MM.YYYY') as 
j_date_fmt,jr_pj_number,
+                                               
j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
+                                               let_diff.jl_id as letter,
+                                       diff_letter1 as letter_diff
+                                               from jrnx join jrn on (j_grpt = 
jr_grpt_id)
+                                                join letter_jl using (j_id)
+                                               left join let_diff using (jl_id)
+                                       where j_poste = $1 and j_date >= 
to_date($2,'DD.MM.YYYY') and j_date <= to_date ($3,'DD.MM.YYYY')
+             and $this->sql_ledger
+             order by j_date,j_id";
+        
$this->content=$this->db->get_array($sql,array($this->account,$this->start,$this->end));
+    }
+        /**
+     * same as get_all but only for lettered operation
+     */
+    public function get_letter_diff()
+    {
+        $sql="
+            with let_diff as (select jl_id,deb_amount-cred_amount as 
diff_letter1
+                       from
+                       ( select jl_id,coalesce(sum(j_montant),0) as 
cred_amount from letter_cred join jrnx using (j_id) group by jl_id) as CRED
+                       left join (select jl_id,coalesce(sum(j_montant),0) as 
deb_amount from letter_deb join jrnx using (j_id) group by jl_id) as DEB using 
(jl_id)) ,
+                       letter_jl as (select jl_id,j_id from letter_cred union 
all select jl_id,j_id from letter_deb)
+                       select  distinct 
j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,jr_pj_number,
+                                               
j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
+                                               let_diff.jl_id as letter,
+                                       diff_letter1 as letter_diff
+                                               from
+                                               jrnx join jrn on (j_grpt = 
jr_grpt_id)
+                                                join letter_jl using (j_id)
+                                               join let_diff using (jl_id)
+             where j_poste = $1 and j_date >= to_date($2,'DD.MM.YYYY') and 
j_date <= to_date ($3,'DD.MM.YYYY')
+             and $this->sql_ledger
+                        and diff_letter1 <> 0
+             order by j_date,j_id";
+        
$this->content=$this->db->get_array($sql,array($this->account,$this->start,$this->end));
+    }
+    /**
+     * same as get_all but only for unlettered operation
+     */
+
+    public function get_unletter()
+    {
+        $sql="
+                       with letter_jl as (select jl_id,j_id from letter_cred 
union all select jl_id,j_id from letter_deb)
+                       select j_id,j_date,to_char(j_date,'DD.MM.YYYY') as 
j_date_fmt,jr_pj_number,
+                                               
j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
+                                               -1 as letter,
+                                       0 as letter_diff
+                                               from jrnx join jrn on (j_grpt = 
jr_grpt_id)
+             where j_poste = $1 and j_date >= to_date($2,'DD.MM.YYYY') and 
j_date <= to_date ($3,'DD.MM.YYYY')
+             and $this->sql_ledger
+             and j_id not in (select j_id from letter_jl)
+             order by j_date,j_id";
+        
$this->content=$this->db->get_array($sql,array($this->account,$this->start,$this->end));
+    }
+
+}
+/**
+ * only for operation retrieved thanks a quick_code
+ * manage the accounting entries for a given card
+ */
+class Lettering_Card extends Lettering
+{
+    /**
+     *constructor
+     address@hidden $p_init db resource
+     address@hidden $p_qcode quick_code of the jrnx.j_id
+     */
+    function __construct($p_init,$p_qcode=null)
+    {
+        parent::__construct($p_init);
+        $this->quick_code=$p_qcode;
+        $this->object_type='card';
+    }
+    /**
+     * fills the this->content, datas are filtered thanks
+     * - fil_deb poss values t (debit), f(credit), ' ' (everything)
+     * - fil_amount_max max amount
+     * - fil_amount_min min amount
+     * - $this->start min date
+     * - $this->end max date
+     * - this->quick_code: quick_code
+     */
+    public function get_filter($p_jid=0)
+    {
+        $filter_deb='';
+        if (isset($this->fil_deb))
+        {
+            switch ($this->fil_deb)
+            {
+            case 0:
+                $filter_deb=" and j_debit='t' ";
+                break;
+            case 1:
+                $filter_deb=" and j_debit='f' ";
+                break;
+            case 2:
+                $filter_deb=" ";
+                break;
+            }
+
+        }
+        $filter_amount="";
+        if ( isset ($this->fil_amount_max ) &&
+                isset ($this->fil_amount_min ) &&
+                isNumber($this->fil_amount_max)==1 &&
+                isNumber($this->fil_amount_min)==1 &&
+                ($this->fil_amount_max != 0 || $this->fil_amount_min != 0) )
+         $filter_amount=" and (j_montant between $this->fil_amount_min and 
$this->fil_amount_max or (coalesce(comptaproc.get_letter_jnt($p_jid),-1)= 
coalesce(comptaproc.get_letter_jnt(j_id),-1) and 
coalesce(comptaproc.get_letter_jnt($p_jid),-1) <> -1 )) ";
+        $sql="
+            with let_diff as (select jl_id,deb_amount-cred_amount as 
diff_letter1
+                       from
+                       ( select jl_id,coalesce(sum(j_montant),0) as 
cred_amount from letter_cred join jrnx using (j_id) group by jl_id) as CRED
+                       left join (select jl_id,coalesce(sum(j_montant),0) as 
deb_amount from letter_deb join jrnx using (j_id) group by jl_id) as DEB using 
(jl_id)) ,
+                       letter_jl as (select jl_id,j_id from letter_cred union 
all select jl_id,j_id from letter_deb)
+                       select distinct 
j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,jr_pj_number,
+                                               
j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
+                                               coalesce(let_diff.jl_id,-1) as 
letter,
+                                       diff_letter1 as letter_diff
+                                               from jrnx join jrn on (j_grpt = 
jr_grpt_id)
+                                               left join letter_jl using (j_id)
+                                               left join let_diff using (jl_id)
+             where j_qcode = upper($1) and j_date >= to_date($2,'DD.MM.YYYY') 
and j_date <= to_date ($3,'DD.MM.YYYY')
+             and $this->sql_ledger
+             $filter_deb
+             $filter_amount
+             order by j_date,j_id";
+
+        
$this->content=$this->db->get_array($sql,array($this->quick_code,$this->start,$this->end));
+    }
+    /**
+     * fills this->content with all the operation for the 
this->quick_code(j_qcode)
+     */
+    public function get_all()
+    {
+        $sql="
+       with let_diff as (select jl_id,deb_amount-cred_amount as diff_letter1
+                       from
+                       ( select jl_id,coalesce(sum(j_montant),0) as 
cred_amount from letter_cred join jrnx using (j_id) group by jl_id) as CRED
+                       left join (select jl_id,coalesce(sum(j_montant),0) as 
deb_amount from letter_deb join jrnx using (j_id) group by jl_id) as DEB using 
(jl_id)) ,
+                       letter_jl as (select jl_id,j_id from letter_cred union 
all select jl_id,j_id from letter_deb)
+                       select DISTINCT 
j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,jr_pj_number,
+                                               
j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
+                                               coalesce(let_diff.jl_id,-1) as 
letter,
+                                       diff_letter1 as letter_diff
+                                               from jrnx join jrn on (j_grpt = 
jr_grpt_id)
+                                               left join letter_jl using (j_id)
+                                               left join let_diff using (jl_id)
+             where j_qcode = upper($1) and j_date >= to_date($2,'DD.MM.YYYY') 
and j_date <= to_date ($3,'DD.MM.YYYY')
+             and $this->sql_ledger
+
+             order by j_date,j_id";
+        
$this->content=$this->db->get_array($sql,array($this->quick_code,$this->start,$this->end));
+    }
+    /**
+     * same as get_all but only for lettered operation
+     */
+
+    public function get_letter()
+    {
+        $sql="
+    with let_diff as (select jl_id,deb_amount-cred_amount as diff_letter1
+                       from
+                       ( select jl_id,coalesce(sum(j_montant),0) as 
cred_amount from letter_cred join jrnx using (j_id) group by jl_id) as CRED
+                       left join (select jl_id,coalesce(sum(j_montant),0) as 
deb_amount from letter_deb join jrnx using (j_id) group by jl_id) as DEB using 
(jl_id)) ,
+                       letter_jl as (select jl_id,j_id from letter_cred union 
all select jl_id,j_id from letter_deb)
+                       select j_id,j_date,to_char(j_date,'DD.MM.YYYY') as 
j_date_fmt,jr_pj_number,
+                                               
j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
+                                               let_diff.jl_id as letter,
+                                       diff_letter1 as letter_diff
+                                               from jrnx join jrn on (j_grpt = 
jr_grpt_id)
+                                               join letter_jl using (j_id)
+                                               left join let_diff using (jl_id)
+             where j_qcode = upper($1) and j_date >= to_date($2,'DD.MM.YYYY') 
and j_date <= to_date ($3,'DD.MM.YYYY')
+             and $this->sql_ledger
+             order by j_date,j_id";
+        
$this->content=$this->db->get_array($sql,array($this->quick_code,$this->start,$this->end));
+    }
+           public function get_letter_diff()
+    {
+        $sql="
+   with let_diff as (select jl_id,deb_amount-cred_amount as diff_letter1
+                       from
+                       ( select jl_id,coalesce(sum(j_montant),0) as 
cred_amount from letter_cred join jrnx using (j_id) group by jl_id) as CRED
+                       left join (select jl_id,coalesce(sum(j_montant),0) as 
deb_amount from letter_deb join jrnx using (j_id) group by jl_id) as DEB using 
(jl_id)) ,
+                       letter_jl as (select jl_id,j_id from letter_cred union 
all select jl_id,j_id from letter_deb)
+                       select distinct 
j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,jr_pj_number,
+                                               
j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
+                                               let_diff.jl_id as letter,
+                                       diff_letter1 as letter_diff
+                                               from jrnx join jrn on (j_grpt = 
jr_grpt_id)
+                                               left join letter_jl using (j_id)
+                                               left join let_diff using (jl_id)
+             where j_qcode = upper($1) and j_date >= to_date($2,'DD.MM.YYYY') 
and j_date <= to_date ($3,'DD.MM.YYYY')
+             and $this->sql_ledger
+                        and diff_letter1 <>0
+             order by j_date,j_id";
+        
$this->content=$this->db->get_array($sql,array($this->quick_code,$this->start,$this->end));
+    }
+    /**
+     * same as get_all but only for unlettered operation
+     */
+    public function get_unletter()
+    {
+        $sql="
+             select j_id,j_date,to_char(j_date,'DD.MM.YYYY') as 
j_date_fmt,jr_pj_number,
+             j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
+             -1 as letter,
+                        0 as letter_diff
+             from jrnx join jrn on (j_grpt = jr_grpt_id)
+             where j_qcode = upper($1) and j_date >= to_date($2,'DD.MM.YYYY') 
and j_date <= to_date ($3,'DD.MM.YYYY')
+             and $this->sql_ledger
+             and j_id not in (select j_id from letter_deb join jnt_letter 
using (jl_id) union select j_id from letter_cred join jnt_letter using (jl_id) )
+             order by j_date,j_id";
+        
$this->content=$this->db->get_array($sql,array($this->quick_code,$this->start,$this->end));
+    }
+    /**
+     * fill $this->content with the rows from this query
+     * Columns are 
+     *  - j_id, id of jrnx
+     *  - j_date, date opeation (yyyy.mm.dd)
+     *  - to_char(j_date,'DD.MM.YYYY') as j_date_fmt,
+     *  - jr_pj_number, receipt number
+     *  - j_montant, amount of the rows
+     *  - j_debit,  Debit or credit
+     *  - jr_comment, label of the operation
+     *  - jr_internal, internal number
+     *  - jr_id, id of jrn
+     *  - jr_def_id, id of the ledger (jrn_def.jrn_def_id)
+     *  - coalesce(let_diff.jl_id,-1) as letter, id of the lettering , -1 
means unlettered
+     *  - diff_letter1 as letter_diff, delta between lettered operation
+     *  - extract ('days' from 
coalesce(jr_date_paid,now())-coalesce(jr_ech,jr_date)) as day_paid, days 
between operation and payment
+     *  - jd1.jrn_def_type type of the ledger (FIN, ODS,VEN or ACH)
+     * 
+     * 
+     * @param type $p_type  value is unlet for unlettered operation or let for 
everything
+     */
+    public function get_balance_ageing($p_type)
+    {
+        $sql_let = ($p_type =='unlet')?'  let_diff.jl_id is null and':'';
+        $sql = 
+               "  with let_diff as (select jl_id,deb_amount-cred_amount as 
diff_letter1
+                        from
+                        ( select jl_id,coalesce(sum(j_montant),0) as 
cred_amount from letter_cred join jrnx using (j_id) group by jl_id) as CRED
+                        left join (select jl_id,coalesce(sum(j_montant),0) as 
deb_amount from letter_deb join jrnx using (j_id) group by jl_id) as DEB using 
(jl_id)) ,
+                        letter_jl as (select jl_id,j_id from letter_cred union 
all select jl_id,j_id from letter_deb)
+                select DISTINCT j_id,j_date,to_char(j_date,'DD.MM.YYYY') as 
j_date_fmt,jr_pj_number,
+                                                                
j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
+                                                                
coalesce(let_diff.jl_id,-1) as letter,
+                                                                diff_letter1 
as letter_diff,
+                                                                extract 
('days' from coalesce(jr_date_paid,now())-coalesce(jr_ech,jr_date)) as day_paid,
+                                                                
jd1.jrn_def_type
+                                                                from jrnx join 
jrn on (j_grpt = jr_grpt_id)
+                                                                join jrn_def 
as jd1 on (jrn.jr_def_id=jd1.jrn_def_id)
+                                                                left join 
letter_jl using (j_id)
+                                                                left join 
let_diff using (jl_id)
+                where 
+                 {$sql_let}
+                  j_qcode = upper($1) 
+                and j_date >= to_date($2,'DD.MM.YYYY')
+                and {$this->sql_ledger}
+                 order by j_date,j_id";
+        
$this->content=$this->db->get_array($sql,array($this->quick_code,$this->start));
+
+     }
+}
diff --git a/include/class/class_manager.php b/include/class/class_manager.php
new file mode 100644
index 0000000..76a0686
--- /dev/null
+++ b/include/class/class_manager.php
@@ -0,0 +1,62 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+require_once NOALYSS_INCLUDE.'/constant.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_parm_code.php';
+require_once NOALYSS_INCLUDE.'/class/class_periode.php';
+require_once NOALYSS_INCLUDE.'/class/class_fiche.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_account_ledger.php';
+require_once NOALYSS_INCLUDE.'/lib/user_common.php';
+/*! \file
+ * \brief Derived from class fiche Supplier are a specific kind of card
+ */
+/*!
+ * \brief  class  Supplier are a specific kind of card
+ */
+
+// Use the view vw_supplier
+//
+class Manager extends Fiche
+{
+
+    var $poste;      /*!< $poste poste comptable */
+    var $name;        /*!< $name name of the company */
+    var $first_name;
+    var $street;      /*!< $street Street */
+    var $country;     /*!< $country Country */
+    var $cp;          /*!< $cp Zip code */
+    var $vat_number;  /*!< $vat_number vat number */
+
+    /*! \brief Constructor
+    /* only a db connection is needed */
+    function __construct($p_cn,$p_id=0)
+    {
+        $this->fiche_def_ref=FICHE_TYPE_EMPL;
+        parent::__construct($p_cn,$p_id) ;
+
+    }
+    
+
+
+
+}
+
+?>
diff --git a/include/class/class_menu_ref.php b/include/class/class_menu_ref.php
new file mode 100644
index 0000000..d18a232
--- /dev/null
+++ b/include/class/class_menu_ref.php
@@ -0,0 +1,59 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+// Copyright Author Dany De Bontridder address@hidden
+/**
+ address@hidden
+ address@hidden Menu_Ref let you manage the available menu
+ */
+require_once NOALYSS_INCLUDE.'/database/class_menu_ref_sql.php';
+class Menu_Ref extends Menu_Ref_sql
+{
+    function format_code()
+    {
+        $this->me_code=strtoupper($this->me_code);
+        $this->me_code=trim($this->me_code);
+        $this->me_code=str_replace('<','',$this->me_code);
+        $this->me_code=str_replace('>','',$this->me_code);
+    }
+    function verify()
+    {
+               try
+               {
+        parent::verify();
+        if ( $this->me_code == -1)
+        {
+            $this->format_code();
+            if ( $this->cn->get_value("select count(*) from menu_ref where 
me_code=$1",array($this->me_code)) > 0)
+                    throw new Exception ('Doublon');
+            if (trim($this->me_code)=='')
+                    throw new Exception ('Ce menu existe déjà');
+        }
+        if ( ! file_exists('../include/'.$this->me_file)) throw new Exception 
('Ce menu fichier '.$this->me_file." n'existe pas");
+
+        return 0;
+               } catch (Exception $e)
+               {
+                       alert($e->getMessage());
+                       return -1;
+               }
+    }
+
+}
+
+?>
diff --git a/include/class_own.php b/include/class/class_own.php
similarity index 100%
rename from include/class_own.php
rename to include/class/class_own.php
diff --git a/include/class/class_periode.php b/include/class/class_periode.php
new file mode 100644
index 0000000..1df3079
--- /dev/null
+++ b/include/class/class_periode.php
@@ -0,0 +1,575 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief definition of the class periode
+ */
+/*!
+ * \brief For the periode tables parm_periode and jrn_periode
+ */
+require_once  NOALYSS_INCLUDE.'/lib/ac_common.php';
+require_once  NOALYSS_INCLUDE.'/lib/class_database.php';
+class Periode
+{
+    var $cn;                   /*!< database connection */
+    var $jrn_def_id;           /*!< the jr, 0 means all the ledger*/
+    var $p_id;                 /*!< pk of parm_periode */
+    var $status;                       /*!< status is CL for closed, OP for
+                                           open and CE for centralized */
+    var $p_start;                      /*!< start of the periode */
+    var $p_end;                        /*!< end of the periode */
+    function __construct($p_cn,$p_id=0)
+    {
+        $this->p_id=$p_id;
+        $this->cn=$p_cn;
+    }
+    function set_jrn($p_jrn)
+    {
+        $this->jrn_def_id=$p_jrn;
+    }
+    function set_periode($pp_id)
+    {
+        $this->p_id=$pp_id;
+    }
+    /*!\brief return the p_id of the start and the end of the exercice
+     *into an array
+     *\param $p_exercice
+     *\return array [start]=>,[end]=>
+     */
+    function limit_year($p_exercice)
+    {
+        $sql_start="select p_id from parm_periode where p_exercice=$1 order by 
p_start  ASC limit 1";
+        $start=$this->cn->get_value($sql_start,array($p_exercice));
+        $sql_end="select p_id from parm_periode where p_exercice=$1 order by 
p_end  DESC limit 1";
+        $end=$this->cn->get_value($sql_end,array($p_exercice));
+        return array("start"=>$start,"end"=>$end);
+    }
+    /*!\brief check if a periode is closed. If jrn_def_id is set to a no zero 
value then check only for this ledger
+     *\return 1 is the periode is closed otherwise return 0
+     */
+    function is_closed()
+    {
+        if ( $this->jrn_def_id != 0 )
+            $sql="select status from jrn_periode ".
+                 " where jrn_def_id=".$this->jrn_def_id.
+                 " and p_id =".$this->p_id;
+        else
+            $sql="select p_closed as status from parm_periode ".
+                 " where ".
+                 " p_id =".$this->p_id;
+        $res=$this->cn->exec_sql($sql);
+        $status=Database::fetch_result($res,0,0);
+        if ( $status == 'CL' || $status=='t' ||$status=='CE')
+            return 1;
+        return 0;
+    }
+    function is_open()
+    {
+        /* if jrn_Def_id == 0 then we check the global otherwise we check
+           a ledger */
+        if ( $this->jrn_def_id != 0 )
+            $sql="select status from jrn_periode ".
+                 " where jrn_def_id=".$this->jrn_def_id.
+                 " and p_id =".$this->p_id;
+        else
+            $sql="select p_closed as status from parm_periode ".
+                 " where ".
+                 " p_id =".$this->p_id;
+        $res=$this->cn->exec_sql($sql);
+        $status=Database::fetch_result($res,0,0);
+        if ( $status == 'OP' || $status=='f' )
+            return 1;
+        return 0;
+    }
+    function is_centralized()
+    {
+        if ( $this->jrn_def_id != 0 )
+            $sql="select status from jrn_periode ".
+                 " where jrn_def_id=".$this->jrn_def_id.
+                 " and p_id =".$this->p_id;
+        else
+            $sql="select p_centralized as status from parm_periode ".
+                 " where ".
+                 " p_id =".$this->p_id;
+        $res=$this->cn->exec_sql($sql);
+        $status=Database::fetch_result($res,0,0);
+        if ( $status == 'CE' || $status=='t' )
+            return 1;
+        return 0;
+    }
+    function reopen()
+    {
+        if ( $this->jrn_def_id == 0 )
+        {
+         $this->cn->exec_sql("update parm_periode set 
p_closed='f',p_central='f' where p_id=$1",
+                           array($_GET['p_per']));
+
+         $this->cn->exec_sql("update jrn_periode set status='OP' ".
+                                " where p_id = ".$this->p_id);
+
+         return;
+        }
+        else
+        {
+            $this->cn->exec_sql("update jrn_periode set status='OP' ".
+                                " where jrn_def_id=".$this->jrn_def_id." and ".
+                                " p_id = ".$this->p_id);
+           /* if one ledger is open then the periode is open */
+           $this->cn->exec_sql("update parm_periode set p_closed=false where 
p_id=".$this->p_id);
+            return;
+        }
+
+    }
+
+    function close()
+    {
+        if ( $this->jrn_def_id == 0 )
+        {
+            $this->cn->exec_sql("update parm_periode set p_closed=true where 
p_id=".
+                                $this->p_id);
+            $this->cn->exec_sql("update jrn_periode set status='CL' ".
+                                " where p_id = ".$this->p_id);
+
+            return;
+        }
+        else
+        {
+            $this->cn->exec_sql("update jrn_periode set status='CL' ".
+                                " where jrn_def_id=".$this->jrn_def_id." and ".
+                                " p_id = ".$this->p_id);
+            /* if all ledgers have this periode closed then synchro with
+            the table parm_periode
+            */
+            $nJrn=$this->cn->count_sql( "select * from jrn_periode where ".
+                                        " p_id=".$this->p_id);
+            $nJrnPeriode=$this->cn->count_sql( "select * from jrn_periode 
where ".
+                                               " p_id=".$this->p_id." and 
status='CL'");
+
+            if ( $nJrnPeriode==$nJrn)
+                $this->cn->exec_sql("update parm_periode set p_closed=true 
where p_id=".$this->p_id);
+            return;
+        }
+
+    }
+    function centralized()
+    {
+        if ( $this->jrn_def_id == 0 )
+        {
+            $this->cn->exec_sql("update parm_periode set p_central=true");
+            return;
+        }
+        else
+        {
+            $this->cn->exec_sql("update jrn_periode set status='CE' ".
+                                " where ".
+                                " p_id = ".$this->p_id);
+            return;
+        }
+
+    }
+    /*!
+     * \brief Display all the periode and their status
+     *
+     */
+
+    function display_form_periode()
+    {
+        $str_dossier=dossier::get();
+
+        if ( $this->jrn_def_id==0 )
+        {
+            $Res=$this->cn->exec_sql("select 
p_id,to_char(p_start,'DD.MM.YYYY') as date_start,to_char(p_end,'DD.MM.YYYY') as 
date_end,p_central,p_closed,p_exercice,
+                                     (select count(jr_id) as count_op from jrn 
where jr_tech_per = p_id) as count_op
+                                     from parm_periode
+                                     order by p_start,p_end");
+            $Max=Database::num_row($Res);
+            echo '<form id="periode_frm" method="POST" onsubmit="return 
confirm_box(this,\'Confirmez-vous la fermeture des périodes choisies ?\')" >';
+            echo 
HtmlInput::array_to_hidden(array('ac','gDossier','jrn_def_id','choose'), 
$_REQUEST);
+            echo '<TABLE ALIGN="CENTER">';
+            echo "</TR>";
+            echo '<th>'.ICheckBox::toggle_checkbox("per_toggle", 
"periode_frm")."</th>";
+            echo '<TH> Date d&eacute;but </TH>';
+            echo '<TH> Date fin </TH>';
+            echo '<TH> Exercice </TH>';
+            echo "</TR>";
+
+            for ($i=0;$i<$Max;$i++)
+            {
+                $l_line=Database::fetch_array($Res,$i);
+               $class="even";
+               if ( $i % 2 == 0 )
+                 $class="odd";
+               $style='';
+               if ( $l_line['p_closed'] == 't')
+                 $style="color:red";
+                echo '<TR class="'.$class.'" style="'.$style.'">';
+                echo '<td>';
+                if ( $l_line['p_closed'] == 'f') {
+                              $per_to_close=new ICheckBox('sel_per_close[]');
+                              $per_to_close->value=$l_line['p_id'];
+                             echo $per_to_close->input();
+               }
+               echo '</td>';
+
+                echo '<TD ALIGN="CENTER"> '.$l_line['date_start'].'</TD>';
+                echo '<TD  ALIGN="CENTER"> '.$l_line['date_end'].'</TD>';
+                echo '<TD  ALIGN="CENTER"> '.$l_line['p_exercice'].'</TD>';
+
+                if ( $l_line['p_closed'] == 't' )
+                {
+                    
$closed=($l_line['p_central']=='t')?'<TD>Centralis&eacute;e</TD>':'<TD>Ferm&eacute;e</TD>';
+                    $change='<TD></TD>';
+                   $remove=sprintf(_('Nombre opérations 
%d'),$l_line['count_op']);
+                    $remove=td($remove,' class="mtitle" ');
+                    $change=td ('<A class="mtitle" HREF="javascript:void(0)"'
+                            . ' onclick="return 
confirm_box(null,\''._('Confirmez Réouverture').' ?\',function() 
{window.location=\'do.php?ac='.$_REQUEST['ac'].'&action=reopen&p_per='.$l_line['p_id'].'&'.$str_dossier.'\';}
 )"> Réouverture</A>',' class="mtitle"');
+
+                }
+                else
+                {
+                    if ($l_line['count_op'] == 0 )
+                    {
+                     $change=HtmlInput::display_periode($l_line['p_id']);
+                    }
+                    else
+                    {
+                     $change="Non modifiable";
+                    }
+                   $change=td($change,' class="mtitle" ');
+                   $reopen=td("");
+
+
+                    $remove='<TD class="mtitle">';
+
+
+                    if ($l_line['count_op'] == 0 )
+                    {
+                        
$go='do.php?'.http_build_query(array('ac'=>$_REQUEST['ac'],
+                            'action'=>'delete_per',
+                            'p_per'=>$l_line['p_id'],
+                            'gDossier'=>Dossier::id()));
+                        
+                        $remove.='<A class="mtitle" HREF="javascript:void(0)" '
+                                . 'onclick="return confirm_box 
(null,\''._('Confirmez effacement ?').'\',function() { 
window.location=\''.$go.'\'});" >'
+                                . ' Efface</A>';
+                    }
+                    else
+                    {
+                        $remove.=sprintf(_('Nombre opérations 
%d'),$l_line['count_op']);
+                    }
+                    $remove.='</td>';
+                }
+                echo $change;
+
+                echo $remove;
+
+               echo '</TR>';
+
+            }
+            echo '</table>';
+            echo '<p style="text-align:center">';
+            echo HtmlInput::hidden("close_per", 1);
+            echo HtmlInput::submit('close_per_bt','Fermeture des périodes 
sélectionnées');
+            echo '</p>';
+            echo '</form>';
+            $but=new IButton('show_per_add','Ajout d\'une période');
+            $but->javascript="$('periode_add_div').show();";
+            echo $but->input();
+            echo '<div class="inner_box" style="width:40%;" 
id="periode_add_div">';
+            echo HtmlInput::title_box("Ajout d'une 
période","periode_add_div","hide");
+            echo '<FORM  METHOD="POST">';
+            echo dossier::hidden();
+           $istart=new IDate('p_date_start');
+           $iend=new IDate('p_date_end');
+           $iexercice=new INum('p_exercice');
+           $iexercice->size=5;
+            echo '<table>';
+            echo '<TR> ';
+            echo td('Date de début');
+            echo td($istart->input());
+            echo '</tr><tr>';
+            echo td('Date de fin');
+           echo td($iend->input());
+
+            echo '</tr><tr>';
+            echo td('Exercice');
+           echo td($iexercice->input());
+
+            echo '</TABLE>';
+
+            echo HtmlInput::submit('add_per','Valider');
+            echo '</FORM>';
+            echo '</div>';
+            echo create_script("$('periode_add_div').hide();new 
Draggable('periode_add_div',{starteffect:function()
+                                  {
+                                     new 
Effect.Highlight(obj.id,{scroll:window,queue:'end'});
+                                  }}
+                         );");
+        }
+        else
+        {
+            $Res=$this->cn->exec_sql("select 
p_id,to_char(p_start,'DD.MM.YYYY') as date_start,to_char(p_end,'DD.MM.YYYY') as 
date_end,status,p_exercice
+                                     from parm_periode join jrn_periode using 
(p_id) where jrn_def_id=".$this->jrn_def_id."
+                                     order by p_start,p_end");
+            $Max=Database::num_row($Res);
+            $r=$this->cn->exec_sql('select jrn_Def_name from jrn_Def where 
jrn_Def_id='.
+                                   $this->jrn_def_id);
+            $jrn_name=Database::fetch_result($r,0,0);
+            echo '<h2> Journal '.$jrn_name.'</h2>';
+            echo '<form id="periode_frm" method="POST" onsubmit="return 
confirm_box(this,\'Confirmez-vous la fermeture des périodes choisies ?\')" >';
+            echo 
HtmlInput::array_to_hidden(array('ac','gDossier','jrn_def_id','choose'), 
$_REQUEST);
+
+            echo '<TABLE ALIGN="CENTER">';
+            echo "</TR>";
+            echo '<th>'.ICheckBox::toggle_checkbox("per_toggle", 
"periode_frm")."</th>";
+            echo '<TH> Date d&eacute;but </TH>';
+            echo '<TH> Date fin </TH>';
+            echo '<TH> Exercice </TH>';
+            echo "</TR>";
+
+            for ($i=0;$i<$Max;$i++)
+            {
+                $l_line=Database::fetch_array($Res,$i);
+                if ( $l_line['status'] != 'OP' )
+                 echo '<TR style="COLOR:RED">';
+               else
+                 echo '<TR>';
+                echo '<td>';
+                if ( $l_line['status'] == 'OP') {
+                              $per_to_close=new ICheckBox('sel_per_close[]');
+                              $per_to_close->value=$l_line['p_id'];
+                             echo $per_to_close->input();
+               }
+                echo '</td>';
+                echo '<TD ALIGN="CENTER"> '.$l_line['date_start'].'</TD>';
+                echo '<TD  ALIGN="CENTER"> '.$l_line['date_end'].'</TD>';
+                echo '<TD  ALIGN="CENTER"> '.$l_line['p_exercice'].'</TD>';
+                $closed="";
+                if ( $l_line['status'] != 'OP' )
+                {
+                    $go='do.php?'.http_build_query(array('ac'=>$_REQUEST['ac'],
+                        'action'=>'reopen',
+                        'p_per'=>$l_line['p_id'],
+                        'gDossier'=>Dossier::id(),
+                        'jrn_def_id'=>$this->jrn_def_id));
+                    
+                 $closed=td ('<A class="mtitle" HREF="javascript:void(0)" '
+                          . 'onclick="return confirm_box(null,\''._('Confirmez 
Réouverture').' ?\',function() {window.location=\''.$go.'\';} );"> 
Réouverture</A>',' class="mtitle"');
+                }
+               
+                echo "$closed";
+
+                echo '</TR>';
+
+            }
+            echo '</TABLE>';
+            echo '<p style="text-align:center">';
+            echo HtmlInput::submit('close_per','Fermeture des périodes 
sélectionnées');
+            echo '</p>';
+            echo '</form>';
+
+        }
+    }
+    function insert($p_date_start,$p_date_end,$p_exercice)
+    {
+        try
+        {
+
+        if (isDate($p_date_start) == null ||
+                isDate($p_date_end) == null ||
+                strlen (trim($p_exercice)) == 0 ||
+                (string) $p_exercice != (string)(int) $p_exercice
+         ||$p_exercice < COMPTA_MIN_YEAR || $p_exercice > COMPTA_MAX_YEAR)
+
+        {
+         throw new Exception ("Paramètre invalide");
+        }
+        $p_id=$this->cn->get_next_seq('s_periode');
+        $sql=sprintf(" insert into 
parm_periode(p_id,p_start,p_end,p_closed,p_exercice)".
+                     "values 
(%d,to_date('%s','DD.MM.YYYY'),to_date('%s','DD.MM.YYYY')".
+                     ",'f','%s')",
+                     $p_id,
+                     $p_date_start,
+                     $p_date_end,
+                     $p_exercice);
+            $this->cn->start();
+            $Res=$this->cn->exec_sql($sql);
+            $Res=$this->cn->exec_sql("insert into jrn_periode 
(jrn_def_id,p_id,status) ".
+                                     "select jrn_def_id,$p_id,'OP' from 
jrn_def");
+            $this->cn->commit();
+        }
+        catch (Exception $e)
+        {
+            $this->cn->rollback();
+            return 1;
+        }
+        return 0;
+    }
+    /*!\brief load data from database
+     *\return 0 on success and -1 on error
+     */
+    function load()
+    {
+        if ($this->p_id == '') $this->p_id=-1;
+        $row=$this->cn->get_array("select 
p_start,p_end,p_exercice,p_closed,p_central from parm_periode where p_id=$1",
+                                  array($this->p_id));
+        if ($row == null ) return -1;
+
+        $this->p_start=$row[0]['p_start'];
+        $this->p_end=$row[0]['p_end'];
+        $this->p_exercice=$row[0]['p_exercice'];
+        $this->p_closed=$row[0]['p_closed'];
+        $this->p_central=$row[0]['p_central'];
+        return 0;
+    }
+
+    /*!\brief return the max and the min periode of the exercice given
+     *in parameter
+     *\param $p_exercice is the exercice
+     *\return an array of Periode object
+     */
+    function get_limit($p_exercice)
+    {
+
+        $max=$this->cn->get_value("select p_id from parm_periode where 
p_exercice=$1 order by p_start asc limit 1",array($p_exercice));
+        $min=$this->cn->get_value("select p_id from parm_periode where 
p_exercice=$1 order by p_start desc limit 1",array($p_exercice));
+        $rMax=new Periode($this->cn);
+        $rMax->p_id=$max;
+        if ( $rMax->load() ) throw new Exception('Periode n\'existe pas');
+        $rMin=new Periode($this->cn);
+        $rMin->p_id=$min;
+        if ( $rMin->load() ) throw new Exception('Periode n\'existe pas');
+        return array($rMax,$rMin);
+    }
+    /*!
+     * \brief Give the start & end date of a periode
+     * \param $p_periode is the periode id, if omitted the value is the 
current object
+     * \return array containing the start date & the end date, index are 
p_start and p_end or NULL if
+     * nothing is found
+    \verbatim
+    $ret['p_start']=>'01.01.2009'
+    $ret['p_end']=>'31.01.2009'
+    \endverbatim
+     */
+    public function get_date_limit($p_periode = 0)
+    {
+        if ( $p_periode == 0 ) $p_periode=$this->p_id;
+        $sql="select to_char(p_start,'DD.MM.YYYY') as p_start,
+             to_char(p_end,'DD.MM.YYYY')   as p_end
+             from parm_periode
+             where p_id=$1";
+        $Res=$this->cn->exec_sql($sql,array($p_periode));
+        if ( Database::num_row($Res) == 0) return null;
+        return Database::fetch_array($Res,0);
+
+    }
+    /*!\brief return the first day of periode
+     *the this->p_id must be set
+     *\return a string with the date (DD.MM.YYYY)
+     */
+    public function first_day($p=0)
+    {
+               if ($p==0) $p=$this->p_id;
+        list($p_start,$p_end)=$this->get_date_limit($p);
+        return $p_start;
+    }
+    /*!\brief return the last day of periode
+     *the this->p_id must be set
+     *\return a string with the date (DD.MM.YYYY)
+     */
+    public function last_day($p=0)
+    {
+               if ($p==0) $p=$this->p_id;
+        list($p_start,$p_end)=$this->get_date_limit($p);
+        return $p_end;
+    }
+
+    function get_exercice($p_id=0)
+    {
+        if ( $p_id == 0 )  $p_id=$this->p_id;
+        $sql="select p_exercice from parm_periode where p_id=".$p_id;
+        $Res=$this->cn->exec_sql($sql);
+        if ( Database::num_row($Res) == 0) return null;
+        return Database::fetch_result($Res,0,0);
+
+    }
+    /*!\brief retrieve the periode thanks the date_end
+    *\param $p_date format DD.MM.YYYY
+     * \return the periode id
+     *\exception if not periode is found or if more than one periode is found
+     */
+    function find_periode($p_date)
+    {
+        $sql="select p_id from parm_periode where p_start <= 
to_date($1,'DD.MM.YYYY') and p_end >= to_date($1,'DD.MM.YYYY') ";
+        $ret=$this->cn->exec_sql($sql,array($p_date));
+        $nb_periode=Database::num_row($ret);
+        if (  $nb_periode == 0 )
+            throw  (new Exception('Aucune période trouvée',101));
+        if ( $nb_periode > 1 )
+            throw  (new Exception("Trop de périodes trouvées $nb_periode pour 
$p_date",100));
+        $per=Database::fetch_result($ret,0);
+        $this->p_id=$per;
+        return $per;
+    }
+    /**
+     *add a exerice of 13 periode
+     */
+    function insert_exercice($p_exercice,$nb_periode)
+    {
+      try
+       {
+         if ( $nb_periode != 12 && $nb_periode != 13) throw new Exception 
('Nombre de période incorrectes');
+         $this->cn->start();
+         for ($i=1;$i < 12;$i++)
+           {
+             $date_start=sprintf('01.%02d.%d',$i,$p_exercice);
+             $date_end=$this->cn->get_value("select 
to_char(to_date('$date_start','DD.MM.YYYY')+interval '1 month'-interval '1 
day','DD.MM.YYYY')");
+             if ( $this->insert($date_start,$date_end,$p_exercice) != 0)
+               {
+                 throw new Exception('Erreur insertion période');
+               }
+           }
+         if ( $nb_periode==12 && 
$this->insert('01.12.'.$p_exercice,'31.12.'.$p_exercice,$p_exercice) != 0 )
+           {
+             throw new Exception('Erreur insertion période');
+           }
+         if ( $nb_periode==13)
+           {
+             if 
($this->insert('01.12.'.$p_exercice,'30.12.'.$p_exercice,$p_exercice) != 0 )    
     throw new Exception('Erreur insertion période');
+             if 
($this->insert('31.12.'.$p_exercice,'31.12.'.$p_exercice,$p_exercice) != 0 )    
     throw new Exception('Erreur insertion période');
+           }
+
+
+         $this->cn->commit();
+       }
+      catch (Exception $e)
+       {
+         $this->cn->rollback();
+       }
+    }
+    static function test_me()
+    {
+        $cn=new Database(dossier::id());
+        $obj=new Periode($cn);
+        $obj->set_jrn(1);
+        $obj->display_form_periode();
+    }
+}
diff --git a/include/class/class_pre_op_ach.php 
b/include/class/class_pre_op_ach.php
new file mode 100644
index 0000000..2f92bf2
--- /dev/null
+++ b/include/class/class_pre_op_ach.php
@@ -0,0 +1,394 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief definition of the class pre_op_ach
+ */
+require_once  NOALYSS_INCLUDE.'/class/class_pre_operation.php';
+
+/*---------------------------------------------------------------------- */
+/*!\brief concerns the predefined operation for ACH ledger
+ */
+class Pre_op_ach extends Pre_operation_detail
+{
+    var $op;
+    function __construct($cn,$p_id=0)
+    {
+        parent::__construct($cn,$p_id);
+
+        $this->operation->od_direct='f';
+    }
+
+    function get_post()
+    {
+        parent::get_post();
+        $this->operation->od_direct='f';
+        $this->e_client=$_POST['e_client'];
+        for ($i=0;$i<$this->operation->nb_item;$i++)
+        {
+            $march="e_march".$i;
+            $this->$march=$_POST['e_march'.$i];
+            $this->{"e_march".$i."_price"}=(isset 
($_POST['e_march'.$i."_price"]))?$_POST['e_march'.$i."_price"]:0;
+            $this->{"e_march".$i."_tva_id"}=(isset 
($_POST['e_march'.$i."_tva_id"]))?$_POST['e_march'.$i."_tva_id"]:0;
+            
$this->{"e_march".$i."_tva_amount"}=(isset($_POST['e_march'.$i."_tva_amount"]))?$_POST['e_march'.$i."_tva_amount"]:0;
+            $this->{"e_quant".$i}=$_POST['e_quant'.$i];
+
+        }
+    }
+
+    /*!
+     * \brief save the detail and op in the database
+     *
+     */
+    function save()
+    {
+        try
+        {
+            $this->db->start();
+            if ($this->operation->save() == false )
+                return;
+            // save the client
+            $sql=sprintf('insert into op_predef_detail 
(od_id,opd_poste,opd_debit)'.
+                         ' values '.
+                         "(%d,'%s','%s')",
+                         $this->operation->od_id,
+                         $this->e_client,
+                         "f");
+            $this->db->exec_sql($sql);
+            // save the selling
+            for ($i=0;$i<$this->operation->nb_item;$i++)
+            {
+                $sql=sprintf('insert into op_predef_detail 
(opd_poste,opd_amount,opd_tva_id,opd_quantity,'.
+                             'opd_debit,od_id,opd_tva_amount)'.
+                             ' values '.
+                             "('%s',%.2f,%d,%f,'%s',%d,%f)",
+                             $this->{"e_march".$i},
+                             $this->{"e_march".$i."_price"},
+                             $this->{"e_march".$i."_tva_id"},
+                             $this->{"e_quant".$i},
+                             't',
+                             $this->operation->od_id,
+                             $this->{"e_march".$i."_tva_amount"}
+                            );
+                $this->db->exec_sql($sql);
+            }
+        }
+        catch (Exception $e)
+        {
+            echo ($e->getMessage());
+            $this->db->rollback();
+        }
+        $this->db->commit();
+    }
+    /*!\brief compute an array accordingly with the FormVenView function
+        * @return an array for filling the form
+     */
+    function compute_array()
+    {
+        $count=0;
+        $a_op=$this->operation->load();
+        $array=$this->operation->compute_array($a_op);
+        $p_array=$this->load();
+               if ( empty ($p_array)) return array();
+        foreach ($p_array as $row)
+        {
+            if ( $row['opd_debit']=='f')
+            {
+                $array+=array('e_client'=>$row['opd_poste']);
+            }
+            else
+            {
+                $array+=array("e_march".$count=>$row['opd_poste'],
+                              "e_march".$count."_price"=>$row['opd_amount'],
+                              "e_march".$count."_tva_id"=>$row['opd_tva_id'],
+                              
"e_march".$count."_tva_amount"=>$row['opd_tva_amount'],
+                              "e_quant".$count=>$row['opd_quantity']
+                             );
+                $count++;
+            }
+        }
+        return $array;
+    }
+    /**
+     * @brief 
+     * load the data from the database and return an array
+     * \return an array
+     */
+    function load()
+    {
+        $sql="select opd_id,opd_poste,opd_amount,opd_tva_id,opd_debit,".
+             " opd_quantity,opd_tva_amount from op_predef_detail where 
od_id=".$this->operation->od_id.
+             " order by opd_id";
+        $res=$this->db->exec_sql($sql);
+        $array=Database::fetch_all($res);
+        return $array;
+    }
+    function set_od_id($p_id)
+    {
+        $this->operation->od_id=$p_id;
+    }
+   function display($p_array)
+   {
+        require_once NOALYSS_INCLUDE.'/class/class_acc_ledger_purchase.php';
+       global $g_parameter,$g_user;
+       extract($p_array);
+       $ledger=new Acc_Ledger_Purchase($this->db,$this->jrn_def_id);
+        if ( $p_array != null ) extract($p_array);
+
+        $flag_tva=$g_parameter->MY_TVA_USE;
+        /* Add button */
+        $f_add_button=new IButton('add_card');
+        $f_add_button->label=_('Créer une nouvelle fiche');
+               $f_add_button->tabindex=-1;
+        $f_add_button->set_attribute('ipopup','ipop_newcard');
+        $f_add_button->set_attribute('jrn',$this->jrn_def_id);
+        $f_add_button->javascript=" 
this.jrn=\$('p_jrn').value;select_card_type(this);";
+
+        $f_add_button2=new IButton('add_card2');
+               $f_add_button2->tabindex=-1;
+        $f_add_button2->label=_('Créer une nouvelle fiche');
+        $f_add_button2->set_attribute('ipopup','ipop_newcard');
+        $f_add_button2->set_attribute('filter',$ledger->get_all_fiche_def ());
+        //    $f_add_button2->set_attribute('jrn',$ledger->id);
+        $f_add_button2->javascript="  
this.jrn=\$('p_jrn').value;select_card_type(this);";
+        $str_add_button="";
+        $str_add_button2="";
+        if ($g_user->check_action(FICADD)==1)
+        {
+                $str_add_button=$f_add_button->input();
+                $str_add_button2=$f_add_button2->input();
+        }
+
+        $r="";
+        $r.=dossier::hidden();
+        $f_legend=_("En-tête facture fournisseur");
+        $f_legend_detail=_("Détail articles acheté");
+
+        // Ledger (p_jrn)
+        //--
+        /* if we suggest the next pj, then we need a javascript */
+        $add_js="";
+
+        // Display the customer
+        //--
+        $fiche='cred';
+
+        // Save old value and set a new one
+        //--
+        $e_client=( isset ($e_client) )?$e_client:"";
+        $e_client_label="&nbsp;";//str_pad("",100,".");
+
+
+        // retrieve e_client_label
+        //--
+
+        if ( strlen(trim($e_client)) !=  0)
+        {
+            $fClient=new Fiche($ledger->db);
+            $fClient->get_by_qcode($e_client);
+            $e_client_label=$fClient->strAttribut(ATTR_DEF_NAME).' '.
+                            ' Adresse : 
'.$fClient->strAttribut(ATTR_DEF_ADRESS).' '.
+                            $fClient->strAttribut(ATTR_DEF_CP).' '.
+                            $fClient->strAttribut(ATTR_DEF_CITY).' ';
+
+
+        }
+
+        $W1=new ICard();
+        $W1->label=_("Fournisseur ").HtmlInput::infobulle(0) ;
+        $W1->name="e_client";
+        $W1->tabindex=3;
+        $W1->value=$e_client;
+        $W1->table=0;
+        $W1->set_dblclick("fill_ipopcard(this);");
+        $W1->set_attribute('ipopup','ipopcard');
+
+        // name of the field to update with the name of the card
+        $W1->set_attribute('label','e_client_label');
+        // name of the field to update with the name of the card
+        $W1->set_attribute('typecard','cred');
+
+        // Add the callback function to filter the card on the jrn
+        $W1->set_callback('filter_card');
+        $W1->set_function('fill_data');
+        $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
+                                $W1->name);
+        $f_client_qcode=$W1->input();
+        $client_label=new ISpan();
+        $client_label->table=0;
+        $f_client=$client_label->input("e_client_label",$e_client_label);
+        $f_client_bt=$W1->search();
+
+
+        // Record the current number of article
+               $min=$ledger->get_min_row();
+        $p_article= ( isset ($nb_item))?$nb_item:$min;
+        $max=($p_article < $min)?$min:$p_article;
+
+        $e_comment=(isset($e_comment))?$e_comment:"";
+        $Hid=new IHidden();
+        $r.=$Hid->input("nb_item",$p_article);
+        // For each article
+        //--
+        for ($i=0;$i< $max ;$i++)
+        {
+            // Code id, price & vat code
+            //--
+            $march=(isset(${"e_march$i"}))?${"e_march$i"}:""                   
;
+            
$march_price=(isset(${"e_march".$i."_price"}))?${"e_march".$i."_price"}:""
+                         ;
+            /* use vat */
+            if ( $g_parameter->MY_TVA_USE=='Y')
+            {
+                
$march_tva_id=(isset(${"e_march$i"."_tva_id"}))?${"e_march$i"."_tva_id"}:"";
+                
$march_tva_amount=(isset(${"e_march$i"."_tva_amount"}))?${"e_march$i"."_tva_amount"}:"";
+            }
+
+
+
+            
$march_label=(isset(${"e_march".$i."_label"}))?${"e_march".$i."_label"}:"";
+            // retrieve the tva label and name
+            //--
+            if ( strlen(trim($march))!=0  && strlen(trim($march_label))==0 )
+            {
+                $fMarch=new Fiche($ledger->db);
+                $fMarch->get_by_qcode($march);
+                $march_label=$fMarch->strAttribut(ATTR_DEF_NAME);
+                /* vat use */
+                if ( ! isset($march_tva_id) && $g_parameter->MY_TVA_USE=='Y' )
+                    $march_tva_id=$fMarch->strAttribut(ATTR_DEF_TVA);
+            }
+            // Show input
+            //--
+            $W1=new ICard();
+            $W1->label="";
+            $W1->name="e_march".$i;
+            $W1->value=$march;
+            $W1->table=1;
+            $W1->set_dblclick("fill_ipopcard(this);");
+            $W1->set_attribute('ipopup','ipopcard');
+
+            $W1->set_attribute('typecard','deb');
+
+            // name of the field to update with the name of the card
+            $W1->set_attribute('label','e_march'.$i.'_label');
+            // name of the field with the price
+            $W1->set_attribute('purchase','e_march'.$i.'_price'); /* 
autocomplete */
+            $W1->set_attribute('price','e_march'.$i.'_price');    /* via 
search */
+
+            // name of the field with the TVA_ID
+            $W1->set_attribute('tvaid','e_march'.$i.'_tva_id');
+            // Add the callback function to filter the card on the jrn
+            $W1->set_callback('filter_card');
+            $W1->set_function('fill_data');
+            $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
+                                    $W1->name);
+            $W1->readonly=false;
+            $array[$i]['quick_code']=$W1->input();
+            $array[$i]['bt']=$W1->search();
+
+            $array[$i]['hidden']='';
+            // For computing we need some hidden field for holding the value
+            if ( $g_parameter->MY_TVA_USE=='Y')
+            {
+                $array[$i]['hidden'].=HtmlInput::hidden('tva_march'.$i,0);
+            }
+
+            if ( $g_parameter->MY_TVA_USE=='Y')
+                $tvac=new INum('tvac_march'.$i);
+            else
+                $tvac=new IHidden('tvac_march'.$i);
+
+            $tvac->readOnly=1;
+            $tvac->value=0;
+            $array[$i]['tvac']=$tvac->input();
+
+            $htva=new INum('htva_march'.$i);
+            $htva->readOnly=1;
+
+            $htva->value=0;
+            $array[$i]['htva']=$htva->input();
+
+            if ( $g_parameter->MY_UPDLAB == 'Y')
+            {
+                $Span=new IText("e_march".$i."_label");
+                $Span->css_size="100%";
+            } else
+            {
+                $Span=new ISpan("e_march".$i."_label");
+            }
+            $Span->value=$march_label;
+            $Span->setReadOnly(false);
+            // card's name, price
+            //--
+            
$array[$i]['denom']=$Span->input("e_march".$i."_label",$march_label);
+            // price
+            $Price=new INum();
+            $Price->setReadOnly(false);
+            $Price->size=9;
+            
$Price->javascript="onBlur='format_number(this);clean_tva($i);compute_ledger($i)'";
+            $array[$i]['pu']=$Price->input("e_march".$i."_price",$march_price);
+            if ( $g_parameter->MY_TVA_USE=='Y')
+            {
+
+                // vat label
+                //--
+                $Tva=new ITva_Popup($ledger->db);
+                
$Tva->js="onblur=\"format_number(this);onChange=clean_tva($i);compute_ledger($i)\"";
+                $Tva->in_table=true;
+                $Tva->set_attribute('compute',$i);
+                $Tva->value=$march_tva_id;
+                $array[$i]['tva']=$Tva->input("e_march$i"."_tva_id");
+
+                // Tva_amount
+
+                // price
+                $Tva_amount=new INum();
+                $Tva_amount->setReadOnly(false);
+                $Tva_amount->size=9;
+                
$Tva_amount->javascript="onBlur='format_number(this);compute_ledger($i)'";
+                
$array[$i]['amount_tva']=$Tva_amount->input("e_march".$i."_tva_amount",$march_tva_amount);
+            }
+            // quantity
+            //--
+            $quant=(isset(${"e_quant$i"}))?${"e_quant$i"}:"1"
+                   ;
+            $Quantity=new INum();
+            $Quantity->setReadOnly(false);
+            $Quantity->size=9;
+            
$Quantity->javascript="onChange=format_number(this);clean_tva($i);compute_ledger($i)";
+            $array[$i]['quantity']=$Quantity->input("e_quant".$i,$quant);
+
+        }
+        $f_type=_('Fournisseur');
+
+        ob_start();
+        require_once NOALYSS_INCLUDE.'/template/predf_ledger_detail.php';
+        $r.=ob_get_contents();
+        ob_end_clean();
+
+        // Set correctly the REQUEST param for jrn_type
+        $r.= HtmlInput::hidden('jrn_type','ACH');
+        $r.= HtmlInput::button('add_item',_('Ajout article'),      ' 
onClick="ledger_add_row()"');
+
+        return $r;
+   }
+}
\ No newline at end of file
diff --git a/include/class/class_pre_op_advanced.php 
b/include/class/class_pre_op_advanced.php
new file mode 100644
index 0000000..e0ba253
--- /dev/null
+++ b/include/class/class_pre_op_advanced.php
@@ -0,0 +1,289 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief definition of the class Pre_Op_Advanced
+ */
+require_once  NOALYSS_INCLUDE.'/class/class_pre_operation.php';
+
+/*---------------------------------------------------------------------- */
+/*!\brief concerns the predefined operation for the operation from 'Ecriture 
direct'
+ */
+class Pre_Op_Advanced extends Pre_operation_detail
+{
+    var $op;
+    function Pre_Op_Advanced($cn)
+    {
+        parent::__construct($cn);
+        $this->operation->od_direct='t';
+    }
+    function get_post()
+    {
+        parent::get_post();
+
+        extract($_POST);
+
+        for ($i=0;$i<$this->operation->nb_item;$i++)
+        {
+            $poste=HtmlInput::default_value_post("poste".$i, null);
+            $qcode=HtmlInput::default_value_post("qc_".$i, null);
+            
+            if ( $poste == null && $qcode == null )                continue;
+            
+            if ($poste != null && trim ($poste) != "")
+            {
+                $this->{'poste'.$i}=$poste;
+                 $this->{'isqc'.$i}='f';
+            }
+            
+            if ( $qcode != null && trim ($qcode) != "") {
+                $this->{'isqc'.$i}=(trim($_POST['qc_'.$i]) != "")?'t':'f';
+                $this->{'poste'.$i}=trim ($qcode);
+            }   
+            $this->{"amount".$i}=$_POST['amount'.$i];
+            $this->{"ck".$i}=(isset($_POST['ck'.$i]))?'t':'f';
+
+        }
+    }
+    /*!
+     * \brief save the detail and op in the database
+     *
+     */
+    function save()
+    {
+        try
+        {
+            if ($this->operation->save() == false )
+                return;
+            $this->db->start();
+            // save the selling
+            for ($i=0;$i<$this->operation->nb_item;$i++)
+            {
+                if ( ! isset ($this->{"poste".$i}))
+                    continue;
+
+                $sql=sprintf('insert into op_predef_detail 
(opd_poste,opd_amount,'.
+                             'opd_debit,od_id,opd_qc)'.
+                             ' values '.
+                             "('%s',%.2f,'%s',%d,'%s')",
+                             $this->{"poste".$i},
+                             $this->{"amount".$i},
+                             $this->{"ck".$i},
+                             $this->operation->od_id,
+                             $this->{'isqc'.$i}
+                            );
+
+                $this->db->exec_sql($sql);
+
+            }
+             $this->db->commit();
+            
+        }
+        catch (Exception $e)
+        {
+            echo ($e->getMessage());
+            $this->db->rollback();
+        }
+
+    }
+    /*!\brief compute an array accordingly with the FormVenView function
+     */
+    function compute_array()
+    {
+        $count=0;
+        $a_op=$this->operation->load();
+        $array=$this->operation->compute_array($a_op);
+        $array['desc']=$array['e_comm'];
+        $p_array=$this->load();
+               if (empty($p_array)) return array();
+        foreach ($p_array as $row)
+        {
+            $tmp_array=array("qc_".$count=>'',
+                             "poste".$count=>'',
+                             "amount".$count=>$row['opd_amount'],
+                             'ck'.$count=>$row['opd_debit']
+                            );
+
+            if ( $row['opd_qc'] == 't' )
+                $tmp_array['qc_'.$count]=$row['opd_poste'];
+            else
+                $tmp_array['poste'.$count]=$row['opd_poste'];
+
+
+            if ( $row['opd_debit'] == 'f' )
+                unset ($tmp_array['ck'.$count]);
+
+            $array+=$tmp_array;
+            $count++;
+
+        }
+
+        return $array;
+    }
+    /*!\brief load the data from the database and return an array
+     * \return an array
+     */
+    function load()
+    {
+        $sql="select opd_id,opd_poste,opd_amount,opd_debit,".
+             " opd_qc from op_predef_detail where 
od_id=".$this->operation->od_id.
+             " order by opd_id";
+        $res=$this->db->exec_sql($sql);
+        $array=Database::fetch_all($res);
+        return $array;
+    }
+    function set_od_id($p_id)
+    {
+        $this->operation->od_id=$p_id;
+    }
+       function display($p_array)
+    {
+        global $g_parameter, $g_user;
+        require_once NOALYSS_INCLUDE.'/class/class_acc_ledger.php';
+        $legder=new Acc_Ledger($this->db,$this->jrn_def_id);
+        $legder->nb=$legder->get_min_row();
+
+        if ($p_array != null)
+                extract($p_array);
+        $add_js = "";
+       
+        $ret = "";
+        if ($g_user->check_action(FICADD) == 1)
+        {
+                /* Add button */
+                $f_add_button = new IButton('add_card');
+                $f_add_button->label = _('Créer une nouvelle fiche');
+                $f_add_button->set_attribute('ipopup', 'ipop_newcard');
+                $f_add_button->set_attribute('jrn', $legder->id);
+                $f_add_button->javascript = " 
this.jrn=\$('p_jrn').value;select_card_type(this);";
+                $f_add_button->input();
+        }
+       
+        $nb_row = (isset($nb_item) ) ? $nb_item : $legder->nb;
+
+        $ret.=HtmlInput::hidden('nb_item', $nb_row);
+        $ret.=HtmlInput::hidden('p_jrn', $this->jrn_def_id);
+        $ret.=dossier::hidden();
+        
+        $ret.=dossier::hidden();
+
+        $ret.=HtmlInput::hidden('jrn_type', $legder->get_type());
+        $info = HtmlInput::infobulle(0);
+        $info_poste = HtmlInput::infobulle(9);
+        if ($g_user->check_action(FICADD) == 1)
+                $ret.=$f_add_button->input();
+        $ret.='<table id="quick_item" style="width:100%">';
+        $ret.='<tr>' .
+                        '<th style="text-align:left">Quickcode' . $info . 
'</th>' .
+                        '<th style="text-align:left">' . _('Poste') . 
$info_poste . '</th>' .
+                        '<th style="text-align:left">' . _('Libellé') . 
'</th>' .
+                        '<th style="text-align:left">' . _('Montant') . 
'</th>' .
+                        '<th style="text-align:left">' . _('Débit') . '</th>' .
+                        '</tr>';
+
+
+        for ($i = 0; $i < $nb_row; $i++)
+        {
+                // Quick Code
+                $quick_code = new ICard('qc_' . $i);
+                $quick_code->set_dblclick("fill_ipopcard(this);");
+                $quick_code->set_attribute('ipopup', 'ipopcard');
+
+                // name of the field to update with the name of the card
+                $quick_code->set_attribute('label', "ld" . $i);
+                $quick_code->set_attribute('jrn', $legder->id);
+
+                // name of the field to update with the name of the card
+                $quick_code->set_attribute('typecard', 'filter');
+
+                // Add the callback function to filter the card on the jrn
+                $quick_code->set_callback('filter_card');
+                $quick_code->set_function('fill_data');
+                $quick_code->javascript = sprintf(' 
onchange="fill_data_onchange(\'%s\');" ', $quick_code->name);
+
+                $quick_code->jrn = $legder->id;
+                $quick_code->value = (isset(${'qc_' . $i})) ? ${'qc_' . $i} : 
"";
+
+                $label = '';
+                if ($quick_code->value != '')
+                {
+                        $Fiche = new Fiche($legder->db);
+                        $Fiche->get_by_qcode($quick_code->value);
+                        $label = $Fiche->strAttribut(ATTR_DEF_NAME);
+                }
+
+
+                // Account
+                $poste = new IPoste();
+                $poste->name = 'poste' . $i;
+                $poste->set_attribute('jrn', $legder->id);
+                $poste->set_attribute('ipopup', 'ipop_account');
+                $poste->set_attribute('label', 'ld' . $i);
+                $poste->set_attribute('account', 'poste' . $i);
+                $poste->set_attribute('dossier', Dossier::id());
+
+                $poste->value = (isset(${'poste' . $i})) ? ${"poste" . $i} : ''
+                ;
+                $poste->dbl_click_history();
+
+
+                if ($poste->value != '')
+                {
+                        $Poste = new Acc_Account($legder->db);
+                        $Poste->set_parameter('value', $poste->value);
+                        $label = $Poste->get_lib();
+                }
+
+                // Description of the line
+                $line_desc = new IText();
+                $line_desc->name = 'ld' . $i;
+                $line_desc->size = 30;
+                $line_desc->value = (isset(${"ld" . $i})) ? ${"ld" . $i} :
+                                $label;
+
+                // Amount
+                $amount = new INum();
+                $amount->size = 10;
+                $amount->name = 'amount' . $i;
+                $amount->value = (isset(${'amount' . $i})) ? ${"amount" . $i} 
: ''
+                ;
+                $amount->javascript = ' 
onChange="format_number(this);checkTotalDirect()"';
+                // D/C
+                $deb = new ICheckBox();
+                $deb->name = 'ck' . $i;
+                $deb->selected = (isset(${'ck' . $i})) ? true : false;
+                $deb->javascript = ' onChange="checkTotalDirect()"';
+
+                $ret.='<tr>';
+                $ret.='<td>' . $quick_code->input() . $quick_code->search() . 
'</td>';
+                $ret.='<td>' . $poste->input() .
+                                '<script> document.getElementById(\'poste' . 
$i . '\').onblur=function(){ if (trim(this.value) !=\'\') 
{document.getElementById(\'qc_' . $i . '\').value="";}}</script>' .
+                                '</td>';
+                $ret.='<td>' . $line_desc->input() . '</td>';
+                $ret.='<td>' . $amount->input() . '</td>';
+                $ret.='<td>' . $deb->input() . '</td>';
+                $ret.='</tr>';
+                // If readonly == 1 then show CA
+        }
+        $ret.='</table>';
+        return $ret;
+    }
+}
diff --git a/include/class/class_pre_op_fin.php 
b/include/class/class_pre_op_fin.php
new file mode 100644
index 0000000..25e4752
--- /dev/null
+++ b/include/class/class_pre_op_fin.php
@@ -0,0 +1,135 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief definition of the class Pre_op_fin
+ */
+require_once  NOALYSS_INCLUDE.'/class/class_pre_operation.php';
+
+/*---------------------------------------------------------------------- */
+/*!\brief concerns the predefined operation for FIN ledger
+ */
+class Pre_op_fin extends Pre_operation_detail
+{
+    var $op;
+    function __construct($cn)
+    {
+        parent::__construct($cn);
+        $this->operation->od_direct='f';
+    }
+
+    function get_post()
+    {
+        parent::get_post();
+        $this->operation->od_direct='f';
+        $this->e_bank_account=$_POST['e_bank_account'];
+        for ($i=0;$i<$this->operation->nb_item;$i++)
+        {
+            $this->{"e_other".$i}=$_POST['e_other'.$i];
+            $this->{"e_other".$i."_comment"}=$_POST['e_other'.$i.'_comment'];
+            $this->{"e_other".$i."_amount"}=$_POST['e_other'.$i."_amount"];
+        }
+    }
+    /*!
+     * \brief save the detail and op in the database
+     *
+     */
+    function save()
+    {
+        try
+        {
+            $this->db->start();
+            if ($this->operation->save() == false )
+                return;
+            // save the client
+            $sql=sprintf('insert into op_predef_detail 
(od_id,opd_poste,opd_debit)'.
+                         ' values '.
+                         "(%d,'%s','%s')",
+                         $this->operation->od_id,
+                         $this->e_bank_account,
+                         "t");
+            $this->db->exec_sql($sql);
+            // save the selling
+            for ($i=0;$i<$this->operation->nb_item;$i++)
+            {
+                $sql=sprintf('insert into op_predef_detail (opd_poste,'.
+                             'opd_amount,opd_comment,'.
+                             'opd_debit,od_id)'.
+                             ' values '.
+                             "('%s',%.2f,'%s','%s',%d)",
+                             $this->{"e_other".$i},
+                             $this->{"e_other".$i."_amount"},
+                             $this->{"e_other".$i."_comment"},
+                             'f',
+                             $this->operation->od_id
+                            );
+                $this->db->exec_sql($sql);
+            }
+        }
+        catch (Exception $e)
+        {
+            echo ($e->getMessage());
+            $this->db->rollback();
+        }
+
+    }
+    /*!\brief compute an array accordingly with the FormVenView function
+     */
+    function compute_array()
+    {
+        $count=0;
+        $a_op=$this->operation->load();
+        $array=$this->operation->compute_array($a_op);
+        $p_array=$this->load();
+        foreach ($p_array as $row)
+        {
+            if ( $row['opd_debit']=='t')
+            {
+                $array+=array('e_bank_account'=>$row['opd_poste']);
+            }
+            else
+            {
+                $array+=array("e_other".$count=>$row['opd_poste'],
+                              "e_other".$count."_amount"=>$row['opd_amount'],
+                              "e_other".$count."_comment"=>$row['opd_comment']
+                             );
+                $count++;
+            }
+        }
+        return $array;
+    }
+    /*!\brief load the data from the database and return an array
+     * \return an array 
+     */
+    function load()
+    {
+        $sql="select opd_id,opd_poste,opd_amount,opd_comment,opd_debit".
+             " from op_predef_detail where od_id=".$this->operation->od_id.
+             " order by opd_id";
+        $res=$this->db->exec_sql($sql);
+        $array=Database::fetch_all($res);
+        return $array;
+    }
+    function set_od_id($p_id)
+    {
+        $this->operation->od_id=$p_id;
+    }
+}
diff --git a/include/class/class_pre_op_ods.php 
b/include/class/class_pre_op_ods.php
new file mode 100644
index 0000000..db576ba
--- /dev/null
+++ b/include/class/class_pre_op_ods.php
@@ -0,0 +1,122 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief definition of the class Pre_op_ods
+ */
+require_once  NOALYSS_INCLUDE.'/class/class_pre_operation.php';
+
+/*---------------------------------------------------------------------- */
+/*!\brief concerns the predefined operation for ODS ledger
+*/
+class Pre_op_ods extends Pre_operation_detail
+{
+    var $op;
+    function __construct($cn,$p_id=0)
+    {
+        parent::__construct($cn,$p_id);
+        $this->operation->od_direct='f';
+    }
+
+    function get_post()
+    {
+        parent::get_post();
+        $this->operation->od_direct='f';
+        for ($i=0;$i<$this->operation->nb_item;$i++)
+        {
+
+            $this->{"e_account".$i}=$_POST['e_account'.$i];
+            $this->{"e_account".$i."_amount"}=$_POST['e_account'.$i."_amount"];
+            $this->{"e_account".$i."_type"}=$_POST['e_account'.$i."_type"];
+
+        }
+    }
+    /*!
+     * \brief save the detail and op in the database
+     *
+     */
+    function save()
+    {
+        try
+        {
+            $this->db->start();
+            if ($this->operation->save() == false )
+                return;
+
+            // save the selling
+            for ($i=0;$i<$this->operation->nb_item;$i++)
+            {
+                $sql=sprintf('insert into op_predef_detail 
(opd_poste,opd_amount,'.
+                             'opd_debit,od_id)'.
+                             ' values '.
+                             "('%s',%.2f,'%s',%d)",
+                             $this->{"e_account".$i},
+                             $this->{"e_account".$i."_amount"},
+                             ($this->{"e_account".$i."_type"}=='d')?'t':'f',
+                             $this->operation->od_id
+                            );
+                $this->db->exec_sql($sql);
+            }
+        }
+        catch (Exception $e)
+        {
+            echo ($e->getMessage());
+            $this->db->rollback();
+        }
+
+    }
+    /*!\brief compute an array accordingly with the FormVenView function
+     */
+    function compute_array()
+    {
+        $count=0;
+        $a_op=$this->operation->load();
+        $array=$this->operation->compute_array($a_op);
+        $p_array=$this->load();
+        foreach ($p_array as $row)
+        {
+            $c=($row['opd_debit']=='t')?'d':'c';
+            $array+=array("e_account".$count=>$row['opd_poste'],
+                          "e_account".$count."_amount"=>$row['opd_amount'],
+                          "e_account".$count."_type"=>$c
+                         );
+            $count++;
+
+        }
+        return $array;
+    }
+    /*!\brief load the data from the database and return an array
+     * \return an array 
+     */
+    function load()
+    {
+        $sql="select opd_id,opd_poste,opd_amount,opd_debit".
+             "  from op_predef_detail where od_id=".$this->operation->od_id.
+             " order by opd_debit, opd_id,opd_amount";
+        $res=$this->db->exec_sql($sql);
+        $array=Database::fetch_all($res);
+        return $array;
+    }
+    function set_od_id($p_id)
+    {
+        $this->operation->od_id=$p_id;
+    }
+}
diff --git a/include/class/class_pre_op_ven.php 
b/include/class/class_pre_op_ven.php
new file mode 100644
index 0000000..6a8e4d8
--- /dev/null
+++ b/include/class/class_pre_op_ven.php
@@ -0,0 +1,387 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief definition of the class Pre_op_ven
+ */
+require_once  NOALYSS_INCLUDE.'/class/class_pre_operation.php';
+
+/*---------------------------------------------------------------------- */
+/*!\brief concerns the predefined operation for VEN ledger
+*/
+class Pre_op_ven extends Pre_operation_detail
+{
+    var $op;
+    function __construct($cn,$p_id=0)
+    {
+        parent::__construct($cn,$p_id);
+        $this->operation->od_direct='f';
+    }
+
+    function get_post()
+    {
+        parent::get_post();
+        $this->operation->od_direct='f';
+        $this->e_client=$_POST['e_client'];
+        for ($i=0;$i<$this->operation->nb_item;$i++)
+        {
+            $march="e_march".$i;
+            $this->$march=$_POST['e_march'.$i];
+            $this->{"e_march".$i."_price"}=$_POST['e_march'.$i."_price"];
+            
$this->{"e_march".$i."_tva_id"}=(isset($_POST['e_march'.$i."_tva_id"]))?$_POST['e_march'.$i."_tva_id"]:0;
+            $this->{"e_quant".$i}=$_POST['e_quant'.$i];
+
+        }
+    }
+    /*!
+     * \brief save the detail and op in the database
+     *
+     */
+    function save()
+    {
+        try
+        {
+            $this->db->start();
+            if ($this->operation->save() == false )
+                return;
+            // save the client
+            $sql=sprintf('insert into op_predef_detail 
(od_id,opd_poste,opd_debit)'.
+                         ' values '.
+                         "(%d,'%s','%s')",
+                         $this->operation->od_id,
+                         $this->e_client,
+                         "t");
+            $this->db->exec_sql($sql);
+            // save the selling
+            for ($i=0;$i<$this->operation->nb_item;$i++)
+            {
+                if ( strlen(trim($this->{"e_march".$i}))==0) continue;
+                $sql=sprintf('insert into op_predef_detail 
(opd_poste,opd_amount,opd_tva_id,opd_quantity,'.
+                             'opd_debit,od_id)'.
+                             ' values '.
+                             "('%s',%.2f,%d,%f,'%s',%d)",
+                             $this->{"e_march".$i},
+                             $this->{"e_march".$i."_price"},
+                             $this->{"e_march".$i."_tva_id"},
+                             $this->{"e_quant".$i},
+                             'f',
+                             $this->operation->od_id
+                            );
+                $this->db->exec_sql($sql);
+            }
+        }
+        catch (Exception $e)
+        {
+            echo ($e->getMessage());
+            $this->db->rollback();
+        }
+        $this->db->commit();
+
+    }
+    /*!\brief compute an array accordingly with the FormVenView function
+     */
+    function compute_array()
+    {
+        $count=0;
+        $a_op=$this->operation->load();
+        $array=$this->operation->compute_array($a_op);
+        $p_array=$this->load();
+               if (empty($p_array)) return array();
+        foreach ($p_array as $row)
+        {
+            if ( $row['opd_debit']=='t')
+            {
+                $array+=array('e_client'=>$row['opd_poste']);
+            }
+            else
+            {
+                $array+=array("e_march".$count=>$row['opd_poste'],
+                              "e_march".$count."_price"=>$row['opd_amount'],
+                              "e_march".$count."_tva_id"=>$row['opd_tva_id'],
+                              "e_quant".$count=>$row['opd_quantity']
+                             );
+                $count++;
+            }
+        }
+        return $array;
+    }
+    /*!\brief load the data from the database and return an array
+     * \return an array
+     */
+    function load()
+    {
+        $sql="select opd_id,opd_poste,opd_amount,opd_tva_id,opd_debit,".
+             " opd_quantity from op_predef_detail where 
od_id=".$this->operation->od_id.
+             " order by opd_id";
+        $res=$this->db->exec_sql($sql);
+        $array=Database::fetch_all($res);
+        return $array;
+    }
+    function set_od_id($p_id)
+    {
+        $this->operation->od_id=$p_id;
+    }
+    function display($p_array)
+    {
+        global $g_parameter,$g_user;
+        if ( $p_array != null ) extract($p_array);
+        require_once NOALYSS_INCLUDE.'/class/class_acc_ledger_sold.php';
+        $ledger=new Acc_Ledger_Sold($this->db,$this->jrn_def_id);
+
+        $flag_tva=$g_parameter->MY_TVA_USE;
+        /* Add button */
+        $f_add_button=new IButton('add_card');
+               $f_add_button->tabindex=-1;
+        $f_add_button->label=_('Créer une nouvelle fiche');
+        $f_add_button->set_attribute('ipopup','ipop_newcard');
+        $f_add_button->set_attribute('jrn',$ledger->id);
+        $f_add_button->javascript="this.jrn=\$('p_jrn').value; 
select_card_type(this);";
+
+        $f_add_button2=new IButton('add_card2');
+               $f_add_button2->tabindex=-1;
+        $f_add_button2->label=_('Créer une nouvelle fiche');
+        $f_add_button2->set_attribute('ipopup','ipop_newcard');
+        $f_add_button2->set_attribute('filter',$ledger->get_all_fiche_def ());
+        //    $f_add_button2->set_attribute('jrn',$ledger->id);
+        $f_add_button2->javascript=" 
this.jrn=\$('p_jrn').value;select_card_type(this);";
+
+        $str_add_button="";
+        $str_add_button2="";
+        if ($g_user->check_action(FICADD)==1)
+        {
+                $str_add_button=$f_add_button->input();
+                $str_add_button2=$f_add_button2->input();
+        }
+
+        $r='';
+        $r.=dossier::hidden();
+        $f_legend=_('En-tête facture client');
+
+
+        /* if we suggest the next pj, then we need a javascript */
+
+        // Display the customer
+        //--
+        $fiche='deb';
+
+        // Save old value and set a new one
+        //--
+        $e_client=( isset ($e_client) )?$e_client:"";
+        $e_client_label="&nbsp;";//str_pad("",100,".");
+
+
+        // retrieve e_client_label
+        //--
+
+        if ( strlen(trim($e_client)) !=  0)
+        {
+            $fClient=new Fiche($ledger->db);
+            $fClient->get_by_qcode($e_client);
+            $e_client_label=$fClient->strAttribut(ATTR_DEF_NAME).' '.
+                            ' Adresse : 
'.$fClient->strAttribut(ATTR_DEF_ADRESS).' '.
+                            $fClient->strAttribut(ATTR_DEF_CP).' '.
+                            $fClient->strAttribut(ATTR_DEF_CITY).' ';
+
+
+        }
+
+        $W1=new ICard();
+        $W1->label="Client ".HtmlInput::infobulle(0) ;
+        $W1->name="e_client";
+        $W1->tabindex=3;
+        $W1->value=$e_client;
+        $W1->table=0;
+        $W1->set_dblclick("fill_ipopcard(this);");
+        $W1->set_attribute('ipopup','ipopcard');
+
+        // name of the field to update with the name of the card
+        $W1->set_attribute('label','e_client_label');
+        // name of the field to update with the name of the card
+        $W1->set_attribute('typecard','deb');
+
+        // Add the callback function to filter the card on the jrn
+        $W1->set_callback('filter_card');
+        $W1->set_function('fill_data');
+        $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
+                                $W1->name);
+        $f_client_qcode=$W1->input();
+        $client_label=new ISpan();
+        $client_label->table=0;
+        $f_client=$client_label->input("e_client_label",$e_client_label);
+        $f_client_bt=$W1->search();
+
+
+        // Record the current number of article
+               $min=$ledger->get_min_row();
+        $p_article= ( isset ($nb_item))?$nb_item:$min;
+        $max=($p_article < $min)?$min:$p_article;
+
+        $e_comment=(isset($e_comment))?$e_comment:"";
+        $Hid=new IHidden();
+        $r.=$Hid->input("nb_item",$p_article);
+
+        $f_legend_detail=_("Détail articles vendus");
+
+        // For each article
+        //--
+        for ($i=0;$i< $max;$i++)
+        {
+            // Code id, price & vat code
+            //--
+            $march=(isset(${"e_march$i"}))?${"e_march$i"}:""
+                   ;
+            
$march_price=(isset(${"e_march".$i."_price"}))?${"e_march".$i."_price"}:""
+                         ;
+            if ( $flag_tva=='Y')
+            {
+                
$march_tva_id=(isset(${"e_march$i"."_tva_id"}))?${"e_march$i"."_tva_id"}:"";
+                
$march_tva_amount=(isset(${"e_march$i"."_tva_amount"}))?${"e_march$i"."_tva_amount"}:"";
+            }
+            
$march_label=(isset(${"e_march".$i."_label"}))?${"e_march".$i."_label"}:"";
+
+            // retrieve the tva label and name
+            //--
+            if ( strlen(trim($march))!=0 && strlen(trim($march_label))==0)
+            {
+                $fMarch=new Fiche($ledger->db);
+                $fMarch->get_by_qcode($march);
+                $march_label=$fMarch->strAttribut(ATTR_DEF_NAME);
+                if ( $flag_tva=='Y')
+                {
+                    if ( ! (isset(${"e_march$i"."_tva_id"})))
+                        $march_tva_id=$fMarch->strAttribut(ATTR_DEF_TVA);
+                }
+            }
+            // Show input
+            //--
+            $W1=new ICard();
+            $W1->label="";
+            $W1->name="e_march".$i;
+            $W1->value=$march;
+            $W1->table=1;
+            $W1->set_attribute('typecard','cred');
+            $W1->set_dblclick("fill_ipopcard(this);");
+            $W1->set_attribute('ipopup','ipopcard');
+
+            // name of the field to update with the name of the card
+            $W1->set_attribute('label','e_march'.$i.'_label');
+            // name of the field with the price
+            $W1->set_attribute('price','e_march'.$i.'_price');
+            // name of the field with the TVA_ID
+            $W1->set_attribute('tvaid','e_march'.$i.'_tva_id');
+            // Add the callback function to filter the card on the jrn
+            $W1->set_callback('filter_card');
+            $W1->set_function('fill_data');
+            $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
+                                    $W1->name);
+
+            $W1->readonly=false;
+
+            $array[$i]['quick_code']=$W1->input();
+            $array[$i]['bt']=$W1->search();
+            // For computing we need some hidden field for holding the value
+            $array[$i]['hidden']='';
+            if ( $flag_tva=='Y') 
$array[$i]['hidden'].=HtmlInput::hidden('tva_march'.$i,0);
+
+            $htva=new INum('htva_march'.$i);
+            $htva->readOnly=1;
+            $htva->value=0;
+            $array[$i]['htva']=$htva->input();
+
+            if ( $g_parameter->MY_TVA_USE=='Y')
+                $tvac=new INum('tvac_march'.$i);
+            else
+                $tvac=new IHidden('tvac_march'.$i);
+
+            $tvac->readOnly=1;
+            $tvac->value=0;
+            $array[$i]['tvac']=$tvac->input();
+
+            if ( $g_parameter->MY_UPDLAB == 'Y')
+            {
+                $Span=new IText("e_march".$i."_label");
+
+                $Span->css_size="100%";
+            } else
+            {
+                $Span=new ISpan("e_march".$i."_label");
+            }
+            $Span->value=$march_label;
+            $Span->setReadOnly(false);
+            // card's name, price
+            //--
+            
$array[$i]['denom']=$Span->input("e_march".$i."_label",$march_label);
+            // price
+            $Price=new INum();
+            $Price->setReadOnly(false);
+            $Price->size=9;
+            
$Price->javascript="onBlur='format_number(this);clean_tva($i);compute_ledger($i)'";
+            $array[$i]['pu']=$Price->input("e_march".$i."_price",$march_price);
+            $array[$i]['tva']='';
+            $array[$i]['amount_tva']='';
+            // if tva is not needed then no tva field
+            if ( $flag_tva == 'Y' )
+            {
+                // vat label
+                //--
+                $Tva=new ITva_Popup($ledger->db);
+                $Tva->in_table=true;
+                $Tva->set_attribute('compute',$i);
+
+                
$Tva->js='onblur="format_number(this);clean_tva('.$i.');compute_ledger('.$i.')"';
+                $Tva->value=$march_tva_id;
+                $array[$i]['tva']=$Tva->input("e_march$i"."_tva_id");
+                // vat amount
+                //--
+                $wTva_amount=new INum();
+                $wTva_amount->readOnly=false;
+                $wTva_amount->size=6;
+                
$wTva_amount->javascript="onBlur='format_number(this);compute_ledger($i)'";
+                
$array[$i]['amount_tva']=$wTva_amount->input("e_march".$i."_tva_amount",$march_tva_amount);
+            }
+            // quantity
+            //--
+            $quant=(isset(${"e_quant$i"}))?${"e_quant$i"}:"1"
+                   ;
+            $Quantity=new INum();
+            $Quantity->setReadOnly(false);
+            $Quantity->size=8;
+            
$Quantity->javascript="onChange='format_number(this);clean_tva($i);compute_ledger($i)'";
+            $array[$i]['quantity']=$Quantity->input("e_quant".$i,$quant);
+
+        }// foreach article
+        $f_type=_('Client');
+
+
+        ob_start();
+        require_once NOALYSS_INCLUDE.'/template/predf_ledger_detail.php';
+        $r.=ob_get_contents();
+        ob_end_clean();
+
+
+
+        // Set correctly the REQUEST param for jrn_type
+        $r.=HtmlInput::hidden('jrn_type','VEN');
+
+        $r.=HtmlInput::button('add_item',_('Ajout article'),      ' 
onClick="ledger_add_row()"');
+        return $r;
+    }
+}
diff --git a/include/class/class_pre_operation.php 
b/include/class/class_pre_operation.php
new file mode 100644
index 0000000..60b031a
--- /dev/null
+++ b/include/class/class_pre_operation.php
@@ -0,0 +1,332 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief definition of Pre_operation
+ */
+
+/*! \brief manage the predefined operation, link to the table op_def
+ * and op_def_detail
+ *
+ */
+require_once NOALYSS_INCLUDE.'/lib/class_iselect.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ihidden.php';
+require_once NOALYSS_INCLUDE.'/class/class_pre_op_ach.php';
+require_once NOALYSS_INCLUDE.'/class/class_pre_op_ven.php';
+require_once NOALYSS_INCLUDE.'/class/class_pre_op_advanced.php';
+class Pre_operation
+{
+    var $db;                                           /*!< $db database 
connection */
+    var $nb_item;                                      /*!< $nb_item nb of 
item */
+    var $p_jrn;                                        /*!< $p_jrn jrn_def_id 
*/
+    var $jrn_type;                                     /*!< $jrn_type */
+    var $name;                                         /*!< $name name of the 
predef. operation */
+
+    function Pre_operation($cn,$p_id=0)
+    {
+        $this->db=$cn;
+        $this->od_direct='false';
+        $this->od_id=$p_id;
+    }
+    /**
+     * @brief Propose to save the operation into a predefined operation
+     * @return HTML  string
+     */
+    static function save_propose() {
+        $r="";
+        $r.= '<p class="decale">';
+        $r.= _("Donnez un nom pour sauver cette opération comme modèle")." 
<br>";
+        $opd_name = new IText('opd_name');
+        $r.= "Nom du modèle " . $opd_name->input();
+        $opd_description=new ITextarea('od_description');
+        $opd_description->style=' class="itextarea" 
style="width:30em;height:4em;vertical-align:top"';
+        $r.='</p>';
+        $r.= '<p class="decale">';
+        $r.= _('Description (max 50 car.)');   
+        $r.='<br>';
+        $r.=$opd_description->input();
+        $r.='</p>';
+        return $r;
+    }
+
+    /*!\brief fill the object with the $_POST variable */
+    function get_post()
+    {
+        $this->nb_item=$_POST['nb_item'];
+        $this->p_jrn=$_REQUEST['p_jrn'];
+        $this->jrn_type=$_POST['jrn_type'];
+        
+       $this->name=$_POST['opd_name'];
+
+        $this->name=(trim($this->name)=='')?$_POST['e_comm']:$this->name;
+        $this->description=  $_POST['od_description'];
+        if ( $this->name=="")
+        {
+            $n=$this->db->get_next_seq('op_def_op_seq');
+            $this->name=$this->jrn_type.$n;
+            // common value
+        }
+    }
+    function delete ()
+    {
+        $sql="delete from op_predef where od_id=".$this->od_id;
+        $this->db->exec_sql($sql);
+    }
+    /*!\brief save the predef check first is the name is unique
+     * \return true op.success otherwise false
+     */
+    function save()
+    {
+
+        if (   $this->db->count_sql("select * from op_predef ".
+                                  "where 
upper(od_name)=upper('".Database::escape_string($this->name)."')".
+                                  "and jrn_def_id=".$this->p_jrn)
+                != 0 )
+        {
+            $this->name="copy_".$this->name."_".microtime(true);
+        }
+        if ( $this->count()  > MAX_PREDEFINED_OPERATION )
+        {
+            echo '<span class="notice">'.("Vous avez atteint le max. 
d'op&eacute;ration pr&eacute;d&eacute;finie, d&eacute;sol&eacute;").'</span>';
+            return false;
+        }
+        $sql='insert into op_predef 
(jrn_def_id,od_name,od_item,od_jrn_type,od_direct,od_description)'.
+                     'values'.
+                     "($1,$2,$3,$4,$5  ,$6               )";
+        $this->db->exec_sql($sql,array($this->p_jrn,
+                     $this->name,
+                     $this->nb_item,
+                     $this->jrn_type,
+                     $this->od_direct,
+                     $this->description,
+            ));
+        $this->od_id=$this->db->get_current_seq('op_def_op_seq');
+        return true;
+    }
+    /*!\brief load the data from the database and return an array
+     * \return an array
+     */
+    function load()
+    {
+        $sql="select 
od_id,jrn_def_id,od_name,od_item,od_jrn_type,od_description".
+             " from op_predef where od_id=".$this->od_id.
+             " order by od_name";
+        $res=$this->db->exec_sql($sql);
+        $array=Database::fetch_all($res);
+        foreach 
(array('jrn_def_id','od_name','od_item','od_jrn_type','od_description') as 
$field) {
+            $this->$field=$array[0][$field];
+        }
+        switch ($this->od_jrn_type) {
+            case 'ACH':
+                $this->detail=new Pre_op_ach($this->db);
+                break;
+            case 'VEN':
+                $this->detail=new Pre_Op_ven($this->db);
+                break;
+            case 'ODS':
+                $this->detail=new Pre_op_advanced($this->db);
+                break;
+            default:
+                throw new Exception('Load PreOperatoin 
failed'.$this->od_jrn_type);
+          }
+        $this->detail->set_od_id($this->od_id);
+        $this->detail->jrn_def_id=$this->jrn_def_id;
+        
+        return $array;
+    }
+    function compute_array()
+    {
+        $p_array=$this->load();
+        $array=array(
+                   "e_comm"=>$p_array[0]["od_name"],
+                   
"nb_item"=>(($p_array[0]["od_item"]<10?10:$p_array[0]["od_item"]))   ,
+                   "p_jrn"=>$p_array[0]["jrn_def_id"],
+                   "jrn_type"=>$p_array[0]["od_jrn_type"],
+                   "od_description"=>$p_array['0']['od_description']
+               );
+        return $array;
+
+    }
+
+    /*!\brief show the button for selecting a predefined operation */
+    function show_button()
+    {
+
+        $select=new ISelect();
+        $value=$this->db->make_array("select od_id,od_name from op_predef ".
+                                     " where jrn_def_id=".$this->p_jrn.
+                                     " and od_direct ='".$this->od_direct."'".
+                                     " order by od_name");
+
+        if ( empty($value)==true) return "";
+        $select->value=$value;
+        $r=$select->input("pre_def");
+
+        return $r;
+    }
+    /*!\brief count the number of pred operation for a ledger */
+    function count()
+    {
+        $a=$this->db->count_sql("select od_id,od_name from op_predef ".
+                                " where jrn_def_id=".$this->p_jrn.
+                                " and od_direct ='".$this->od_direct."'".
+                                " order by od_name");
+        return $a;
+    }
+    /*!\brief get the list of the predef. operation of a ledger
+     * \return string
+     */
+    function get_list_ledger()
+    {
+        $sql="select od_id,od_name,od_description from op_predef ".
+             " where jrn_def_id=".$this->p_jrn.
+             " and od_direct ='".$this->od_direct."'".
+             " order by od_name";
+        $res=$this->db->exec_sql($sql);
+        $all=Database::fetch_all($res);
+        return $all;
+    }
+    /*!\brief set the ledger
+     * \param $p_jrn is the ledger (jrn_id)
+     */
+    function set_jrn($p_jrn)
+    {
+        $this->p_jrn=$p_jrn;
+    }
+   
+    /**
+     * 
+     * @brief display the detail of predefined operation, normally everything 
+     * is loaded
+     */
+    function display() 
+    {
+        $array=$this->detail->compute_array();
+        echo $this->detail->display($array);
+    }
+}
+
+/*!\brief mother of the pre_op_XXX, it contains only one data : an
+ * object Pre_Operation. The child class contains an array of
+ * Pre_Operation object
+ */
+class Pre_operation_detail
+{
+    var $operation;
+    function __construct($p_cn,$p_id=0)
+    {
+        $this->db=$p_cn;
+        $this->operation=new Pre_operation($this->db);
+        
$this->valid=array('ledger'=>'jrn_def_id','ledger_type'=>'jrn_type','direct'=>'od_direct');
+               $this->jrn_def_id=-1;
+    }
+
+
+    /*!\brief show a form to use pre_op
+     */
+    function form_get ($p_url)
+    {
+        $r=HtmlInput::button_action(_("Modèle d'opérations"), ' 
$(\'modele_op_div\').style.display=\'block\';$(\'lk_modele_op_tab\').focus();');
+        $r.='<div id="modele_op_div" class="noprint">';
+        $r.=HtmlInput::title_box(_("Modèle d'opérations"), 'modele_op_div', 
'hide');
+        $hid=new IHidden();
+        $r.=$hid->input("action","use_opd");
+        $r.=$hid->input("jrn_type",$this->get("ledger_type"));
+        $r.= $this->show_button($p_url);
+        $r.='</div>';
+        return $r;
+
+    }
+    /*!\brief count the number of pred operation for a ledger */
+    function count()
+    {
+        $a=$this->db->count_sql("select od_id,od_name from op_predef ".
+                                " where jrn_def_id=".$this->jrn_def_id.
+                                " and od_direct ='".$this->od_direct."'".
+                                " order by od_name");
+        return $a;
+    }
+    /*!\brief show the button for selecting a predefined operation */
+    function show_button($p_url)
+    {
+        
+        
+        $value=$this->db->get_array("select od_id,od_name,od_description from 
op_predef ".
+                                     " where jrn_def_id=$1".
+                                     " and od_direct =$2".
+                                     " order by od_name",
+                            array($this->jrn_def_id,$this->od_direct ));
+        
+        if ( $this->jrn_def_id=='') $value=array();
+        
+        $r="";
+        $r.='<h2>'._("Choisissez un modèle").'</h2>';
+        $r.=_('Filtrer').' '.HtmlInput::filter_table('modele_op_tab', '0', 
'0');
+        $r.='<table style="width:100%" id="modele_op_tab">';
+        for ($i=0;$i<count($value);$i++) {
+            $r.='<tr class="'.(($i%2==0)?"even":"odd").'">';
+            $r.='<td 
style="font-weight:bold;vertical-align:top;text-decoration:underline">';
+            $r.=sprintf('<a href="%s&pre_def=%s" 
onclick="waiting_box()">%s</a> ',
+                    $p_url,$value[$i]['od_id'],$value[$i]['od_name']);
+            $r.='</td>';
+            $r.='<td>'.h($value[$i]['od_description']).'</td>';
+            $r.='</tr>';
+        }
+        $r.='</table>';
+        return $r;
+    }
+    public function   get_operation()
+    {
+               if ( $this->jrn_def_id=='') return array();
+        $value=$this->db->make_array("select od_id,od_name from op_predef ".
+                                     " where 
jrn_def_id=".sql_string($this->jrn_def_id).
+                                     " and od_direct 
='".sql_string($this->od_direct)."'".
+                                     " order by od_name",1);
+        return $value;
+    }
+    function set($p_param,$value)
+    {
+        if ( ! isset ($this->valid[$p_param] ) )
+        {
+            $msg=_(" le parametre $p_param n'existe pas 
".__FILE__.':'.__LINE__);
+            throw new Exception($msg);
+        }
+        $attr=$this->valid[$p_param];
+        $this->$attr=$value;
+    }
+    function get($p_param)
+    {
+
+        if ( ! isset ($this->valid[$p_param] ) )
+        {
+            $msg=_(" le parametre $p_param n'existe pas 
".__FILE__.':'.__LINE__);
+            throw new Exception($msg);
+        }
+        $attr=$this->valid[$p_param];
+        return $this->$attr;
+    }
+
+    function get_post()
+    {
+        $this->operation->get_post();
+    }
+
+}
diff --git a/include/class/class_print_ledger.php 
b/include/class/class_print_ledger.php
new file mode 100644
index 0000000..90403ed
--- /dev/null
+++ b/include/class/class_print_ledger.php
@@ -0,0 +1,130 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/**
+ *  Parent class for the print_ledger class
+ *
+ * @author danydb
+ */
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/class/class_print_ledger_detail.php';
+require_once NOALYSS_INCLUDE.'/class/class_print_ledger_simple.php';
+require_once 
NOALYSS_INCLUDE.'/class/class_print_ledger_simple_without_vat.php';
+require_once NOALYSS_INCLUDE.'/class/class_print_ledger_fin.php';
+require_once NOALYSS_INCLUDE.'/class/class_print_ledger_misc.php';
+require_once NOALYSS_INCLUDE.'/class/class_print_ledger_detail_item.php';
+
+/**
+ * @brief Strategie class for the print_ledger class
+ * 
+ */
+class Print_Ledger {
+
+    /**
+     * Create an object Print_Ledger* depending on $p_type_export ( 0 => 
accounting
+     * 1-> one row per operation 2-> detail of item)
+     * @param type $cn
+     * @param type $p_type_export
+     * @param type $p_format_output CSV or PDF
+     * @param Acc_Ledger $ledger
+     */
+    static function factory(Database $cn, $p_type_export, $p_format_output, 
Acc_Ledger $p_ledger) {
+        /**
+         * For PDF output
+         */
+        if ($p_format_output == 'PDF') {
+            switch ($p_type_export) {
+                case 0:
+                    //---------------------------------------------
+                    // Detailled Printing (accounting )
+                    //---------------------------------------------
+                    return new Print_Ledger_Detail($cn, $p_ledger);
+                    break;
+
+                case 1:
+                    
//----------------------------------------------------------------------
+                    // Simple Printing Purchase Ledger
+                    
//---------------------------------------------------------------------
+                    $own = new Own($cn);
+                    $jrn_type = $p_ledger->get_type();
+
+
+                    if ($jrn_type == 'ACH' || $jrn_type == 'VEN') {
+                        if (
+                                ($jrn_type == 'ACH' && $cn->get_value('select 
count(qp_id) from quant_purchase') == 0) ||
+                                ($jrn_type == 'VEN' && $cn->get_value('select 
count(qs_id) from quant_sold') == 0)
+                        ) {
+                            $pdf = new Print_Ledger_Simple_without_vat($cn, 
$p_ledger);
+                            $pdf->set_error(_('Ce journal ne peut être imprimé 
en mode simple'));
+                            return $pdf;
+                        }
+                        if ($own->MY_TVA_USE == 'Y') {
+                            $pdf = new Print_Ledger_Simple($cn, $p_ledger);
+                            return $pdf;
+                        }
+                        if ($own->MY_TVA_USE == 'N') {
+                            $pdf = new Print_Ledger_Simple_without_vat($cn, 
$p_ledger);
+                            return $pdf;
+                        }
+                    }
+
+                    if ($jrn_type == 'FIN') {
+                        $pdf = new Print_Ledger_Financial($cn, $p_ledger);
+                        return $pdf;
+                    }
+                    if ($jrn_type == 'ODS' || $p_ledger->id == 0) {
+                        $pdf = new Print_Ledger_Misc($cn, $p_ledger);
+                        return $pdf;
+                    }
+                    break;
+                case 2:
+                    /**********************************************************
+                     * Print Detail Operation + Item
+                     
********************************************************** */
+                    $own = new Own($cn);
+                    $jrn_type = $p_ledger->get_type();
+                    if ($jrn_type == 'FIN') {
+                        $pdf = new Print_Ledger_Financial($cn, $p_ledger);
+                        return $pdf;
+                        ;
+                    }
+                    if ($jrn_type == 'ODS' || $p_ledger->id == 0) {
+                        $pdf = new Print_Ledger_Misc($cn, $p_ledger);
+                        return $pdf;
+                    }
+                    if (
+                            ($jrn_type == 'ACH' && $cn->get_value('select 
count(qp_id) from quant_purchase') == 0) ||
+                            ($jrn_type == 'VEN' && $cn->get_value('select 
count(qs_id) from quant_sold') == 0)
+                    ) {
+                        $pdf = new Print_Ledger_Simple_without_vat($cn, 
$p_ledger);
+                        $pdf->set_error('Ce journal ne peut être imprimé en 
mode simple');
+                        return $pdf;
+                    }
+                    $pdf = new Print_Ledger_Detail_Item($cn,$p_ledger);
+                    return $pdf;
+                    
+            } // end switch
+        } // end $p_format == PDF
+    }
+
+// end function
+}
+
+?>
diff --git a/include/class/class_print_ledger_detail.php 
b/include/class/class_print_ledger_detail.php
new file mode 100644
index 0000000..c02608f
--- /dev/null
+++ b/include/class/class_print_ledger_detail.php
@@ -0,0 +1,148 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief this class extends PDF and let you export the detailled printing
+ *  of any ledgers
+ */
+require_once NOALYSS_INCLUDE.'/lib/lib/class_pdf.php';
+
+class Print_Ledger_Detail extends PDF
+{
+    public function __construct ($p_cn = null, Acc_Ledger $ledger)
+    {
+
+        if($p_cn == null) die("No database connection. Abort.");
+        
+        parent::__construct($p_cn,'L', 'mm', 'A4');
+        $this->ledger=$ledger;
+        date_default_timezone_set ('Europe/Paris');
+
+    }
+
+    function setDossierInfo($dossier = "n/a")
+    {
+        $this->dossier = dossier::name()." ".$dossier;
+    }
+
+    function Header()
+    {
+        //Arial bold 12
+        $this->SetFont('DejaVu', 'B', 12);
+        //Title
+        $this->Cell(0,10,$this->dossier, 'B', 0, 'C');
+        //Line break
+        $this->Ln(20);
+    }
+    function Footer()
+    {
+        //Position at 2 cm from bottom
+        $this->SetY(-20);
+        //Arial italic 8
+        $this->SetFont('Arial', 'I', 8);
+        //Page number
+        $this->Cell(0,8,'Date '.$this->date." - Page 
".$this->PageNo().'/{nb}',0,0,'L');
+        // Created by NOALYSS
+        $this->Cell(0,8,'Created by NOALYSS, online on 
http://www.aevalys.eu',0,0,'R',false,'http://www.aevalys.eu');
+
+    }
+    function Cell ($w, $h=0, $txt='', $border=0, $ln=0, $align='', 
$fill=false, $link='')
+    {
+        $txt = str_replace("\\", "", $txt);
+        return parent::Cell($w, $h, $txt, $border, $ln, $align, $fill, $link);
+    }
+
+    function export()
+    {
+        
+        // detailled printing
+        $rap_deb=0;
+        $rap_cred=0;
+        // take all operations from jrn
+        
$array=$this->ledger->get_operation($_GET['from_periode'],$_GET['to_periode']);
+
+        $this->SetFont('DejaVu','BI',7);
+        $this->Cell(215,7,'report Débit',0,0,'R');
+        $this->Cell(30,7,nbm($rap_deb),0,0,'R');
+        $this->Ln(4);
+        $this->Cell(215,7,'report Crédit',0,0,'R');
+        $this->Cell(30,7,nbm($rap_cred),0,0,'R');
+        $this->Ln(4);
+
+        // print all operation
+        for ($i=0;$i< count($array);$i++)
+        {
+            $this->SetFont('DejaVuCond','B',7);
+            $row=$array[$i];
+
+            $this->LongLine(20,7,$row['pj']);
+            $this->Cell(15,7,$row['date_fmt']);
+            $this->Cell(20,7,$row['internal']);
+            $this->LongLine(170,7,$row['comment']);
+            $this->Cell(20,7,nbm($row['montant']),0,0,'R');
+
+            $this->Ln();
+            // get the entries
+            $aEntry=$this->cn->get_array("select 
j_id,j_poste,j_qcode,j_montant,j_debit, j_text,".
+                                                                               
 " case when j_text='' or j_text is null then pcm_lib else j_text end as desc,".
+                                         " pcm_lib ".
+                                         " from jrnx join tmp_pcmn on 
(j_poste=pcm_val) where j_grpt = $1".
+                                         " order by j_debit desc,j_id",
+                                         array($row['jr_grpt_id']));
+            for ($j=0;$j<count($aEntry);$j++)
+            {
+                $this->SetFont('DejaVuCond','',7);
+                $entry=$aEntry[$j];
+                // $this->Cell(15,6,$entry['j_id'],0,0,'R');
+                $this->Cell(32,6,$entry['j_qcode'],0,0,'R');
+                $this->Cell(23,6,$entry['j_poste'],0,0,'R');
+
+                // if j_qcode is not empty retrieve name
+                if ( $entry['j_text'] =='' && $entry['j_qcode'] != '')
+                {
+                    $f_id=$this->cn->get_value('select f_id from 
vw_poste_qcode where j_qcode=$1',array($entry['j_qcode']));
+                    if ($f_id != '')
+                        $name=$this->cn->get_value('select ad_value from 
fiche_detail where f_id=$1 and ad_id=1',
+                                                   array($f_id));
+                    else
+                        $name=$entry['pcm_lib'];
+                }
+                else
+                    $name=$entry['desc'];
+                $this->Cell(150,6,$name,0,0,'L');
+
+                // print amount
+                $str_amount=nbm($entry['j_montant']);
+                if ( $entry['j_debit']=='t')
+                {
+                    $this->Cell(20,6,$str_amount,0,0,'R');
+                    $this->Cell(20,6,'',0,0,'R');
+                }
+                else
+                {
+                    $this->Cell(20,6,'',0,0,'R');
+                    $this->Cell(20,6,$str_amount,0,0,'R');
+                }
+                $this->Ln(4);
+            }
+        }
+    }
+}
diff --git a/include/class/class_print_ledger_detail_item.php 
b/include/class/class_print_ledger_detail_item.php
new file mode 100644
index 0000000..64c7620
--- /dev/null
+++ b/include/class/class_print_ledger_detail_item.php
@@ -0,0 +1,174 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+// Copyright Author Dany De Bontridder address@hidden
+/**
+ * Print detail of operation PURCHASE or SOLD plus the items
+ * There is no report of the different amounts
+ *
+ * @author danydb
+ */
+require_once NOALYSS_INCLUDE.'/class/class_acc_ledger_sold.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_ledger_purchase.php';
+class Print_Ledger_Detail_Item extends PDFLand
+{
+    public function __construct (Database $p_cn,Acc_Ledger $p_jrn)
+    {
+
+        if($p_cn == null) die("No database connection. Abort.");
+
+        parent::__construct($p_cn,'L', 'mm', 'A4');
+        $this->ledger=$p_jrn;
+        $this->show_col=true;
+    }
+
+    function setDossierInfo($dossier = "n/a")
+    {
+        $this->dossier = dossier::name()." ".$dossier;
+    }
+    /**
+     address@hidden write the header of each page
+     */
+    function Header()
+    {
+        //Arial bold 12
+        $this->SetFont('DejaVu', 'B', 12);
+        //Title
+        $this->Cell(0,10,$this->dossier, 'B', 0, 'C');
+        //Line break
+        $this->Ln(20);
+        $high=6;
+        $this->SetFont('DejaVu', '', 6);
+        $this->LongLine(20, $high, _('Date'),0,  'L', false);
+        $this->Cell(20, $high, _('Numéro interne'), 0, 0, 'L', false);
+        $this->LongLine(50, $high, _('Code'),0,'L',false);
+        $this->LongLine(80, $high, _('Libellé'),0,'L',false);
+        $this->Cell(20, $high, _('Tot HTVA'), 0, 0, 'R', false);
+        $this->Cell(20, $high, _('Tot TVA NP'), 0, 0, 'R', false);
+        $this->Cell(20, $high, "", 0, 0, 'R', false);
+        $this->Cell(20, $high, _('Tot TVA'), 0, 0, 'R', false);
+        $this->Cell(20, $high, _('TVAC'), 0, 0, 'R', false);
+        $this->Ln(6);
+        $this->show_col=true;
+        
+    }
+    /**
+     address@hidden write the Footer
+     */
+    function Footer()
+    {
+        $this->Ln(2);
+        $this->SetFont('Arial', 'I', 8);
+        $this->Cell(50,8,' Journal '.$this->ledger->get_name(),0,0,'C');
+        //Arial italic 8
+        //Page number
+        $this->Cell(30,8,'Date '.$this->date." - Page 
".$this->PageNo().'/{nb}',0,0,'L');
+        // Created by NOALYSS
+        $this->Cell(0,8,'Created by NOALYSS, online on 
http://www.aevalys.eu',0,0,'R',false,'http://www.aevalys.eu');
+    }
+
+    function Cell ($w, $h=0, $txt='', $border=0, $ln=0, $align='', 
$fill=false, $link='')
+    {
+        $txt = str_replace("\\", "", $txt);
+        return parent::Cell($w, $h, $txt, $border, $ln, $align, $fill, $link);
+    }
+    /**
+     address@hidden export the ledger in  PDF
+     */
+    function export()
+    {
+      bcscale(2);
+      $jrn_type=$this->ledger->get_type();
+      switch ($jrn_type)
+      {
+          case 'VEN':
+              $ledger=new Acc_Ledger_Sold($this->cn, 
$this->ledger->jrn_def_id);
+              
$ret_detail=$ledger->get_detail_sale($_GET['from_periode'],$_GET['to_periode']);
+              break;
+          case 'ACH':
+                $ledger=new Acc_Ledger_Purchase($this->cn, 
$this->ledger->jrn_def_id);
+                
$ret_detail=$ledger->get_detail_purchase($_GET['from_periode'],$_GET['to_periode']);
+              break;
+          default:
+              die (__FILE__.":".__LINE__.'Journal invalide');
+              break;
+      }
+        if ( $ret_detail == null ) return;
+        $nb=Database::num_row($ret_detail);
+        $this->SetFont('DejaVu', '', 6);
+        $internal="";
+        $this->SetFillColor(220,221,255);
+        $high=4;
+        for ( $i=0;$i< $nb ;$i++)
+        {
+            
+            $row=Database::fetch_array($ret_detail, $i);
+            if ($internal != $row['jr_internal'])
+            {
+                // Print the general info line width=270mm
+                $this->LongLine(20, $high, $row['jr_date'],1,  'L', true);
+                $this->Cell(20, $high, $row['jr_internal'], 1, 0, 'L', true);
+                $this->LongLine(50, $high, $row['quick_code']." 
".$row['tiers_name'],1,'L',true);
+                $this->LongLine(80, $high, $row['jr_comment'],1,'L',true);
+                $this->Cell(20, $high, nbm($row['htva']), 1, 0, 'R', true);
+                $this->Cell(20, $high, nbm($row['tot_tva_np']), 1, 0, 'R', 
true);
+                $this->Cell(20, $high, "", 1, 0, 'R', true);
+                $this->Cell(20, $high, nbm($row['tot_vat']), 1, 0, 'R', true);
+                $sum=bcadd($row['htva'],$row['tot_vat']);
+                $sum=bcsub($sum,$row['tot_tva_np']);
+                $this->Cell(20, $high, nbm($sum), 1, 0, 'R', true);
+                $internal=$row['jr_internal'];
+                $this->Ln(6);
+               // on the first line, the code for each column is displaid
+                if ( $this->show_col == true ) {
+                    //
+                    // Header detail
+                    $this->LongLine(30,$high,'QuickCode');
+                    $this->Cell(30,$high,'Poste');
+                    $this->LongLine(70,$high,'Libellé');
+                    $this->Cell(20,$high,'Prix/Unit',0,0,'R');
+                    $this->Cell(20,$high,'Quant.',0,0,'R');
+                    $this->Cell(20,$high,'HTVA',0,0,'R');
+                    $this->Cell(20,$high,'TVA NP',0,0,'R');
+                    $this->Cell(20,$high,'Code TVA');
+                    $this->Cell(20,$high,'TVA',0,0,'R');
+                    $this->Cell(20,$high,'TVAC',0,0,'R');
+                    $this->Ln(6);
+                    $this->show_col=false;
+                 } 
+            }
+            // Print detail sale / purchase
+            $this->LongLine(30,$high,$row['j_qcode']);
+            $this->Cell(30,$high,$row['j_poste']);
+            $comment=($row['j_text']=="")?$row['item_name']:$row['j_text'];
+            $this->LongLine(70,$high,$comment);
+            $this->Cell(20,$high,nbm($row['price_per_unit']),0,0,'R');
+            $this->Cell(20,$high,nbm($row['quantity']),0,0,'R');
+            $this->Cell(20,$high,nbm($row['price']),0,0,'R');
+            $this->Cell(20,$high,nbm($row['vat_sided']),0,0,'R');
+            $this->Cell(20,$high,$row['vat_code']." ".$row['tva_label']);
+            $this->Cell(20,$high,nbm($row['vat']),0,0,'R');
+            $sum=bcadd($row['price'],$row['vat']);
+            $this->Cell(20,$high,nbm($sum),0,0,'R');
+            $this->Ln(6);
+            
+        }
+    }
+
+}
+?>
diff --git a/include/class/class_print_ledger_fin.php 
b/include/class/class_print_ledger_fin.php
new file mode 100644
index 0000000..8355327
--- /dev/null
+++ b/include/class/class_print_ledger_fin.php
@@ -0,0 +1,119 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief print a listing of financial
+ */
+require_once NOALYSS_INCLUDE.'/lib/lib/class_pdf.php';
+class Print_Ledger_Financial extends PDF
+{
+    private $rap_amount; /* amount from begining exercice */
+    private $tp_amount; /* amount total page */
+    
+    function __construct($p_cn,  Acc_Ledger $p_jrn)
+    {
+        parent::__construct($p_cn,'P','mm','A4');
+        $this->ledger=$p_jrn;
+        $this->jrn_type=$p_jrn->get_type();
+        
+        // report from begin exercice
+        $this->rap_amount=0; 
+        
+        // total page
+        $this->tp_amount=0;
+        
+        $amount=$this->ledger->previous_amount($_GET['from_periode']);
+        $this->rap_amount=$amount['amount'];
+    }
+    function Header()
+    {
+        //Arial bold 12
+        $this->SetFont('DejaVu', 'B', 12);
+        //Title
+        $this->Cell(0,10,$this->dossier, 'B', 0, 'C');
+        //Line break
+        $this->SetFont('DejaVu', 'B', 7);
+        $this->Ln(10);
+        $this->Cell(40,6,_('report'),0,0,'R');
+        $this->Cell(40,6,nbm($this->rap_amount),0,0,'R');
+        $this->Ln(6);
+        $this->SetFont('DejaVu', 'B', 7);
+        $this->Cell(15,6,'Piece');
+        $this->Cell(10,6,'Date');
+        $this->Cell(15,6,'Interne');
+        $this->Cell(40,6,'Dest/Orig');
+        $this->Cell(80,6,'Commentaire');
+        $this->Cell(20,6,'Montant');
+        $this->Ln(6);
+        
+    }
+    function Footer()
+    {
+        $this->SetFont('DejaVu', 'B', 7);
+
+        $this->Cell(40,6,_('Total page'),0,0,'R');
+        $this->Cell(40,6,nbm($this->tp_amount),0,0,'R');
+        bcscale(2);
+        $this->rap_amount=bcadd($this->rap_amount,$this->tp_amount);
+        $this->Cell(40,6,_('Total à reporter'),0,0,'R');
+        $this->Cell(40,6,nbm($this->rap_amount),0,0,'R');
+        $this->tp_amount=0;
+        //Position at 2 cm from bottom
+        $this->SetY(-20);
+        //Arial italic 8
+        $this->SetFont('Arial', 'I', 8);
+        //Page number
+        $this->Cell(0,8,'Date '.$this->date." - Page 
".$this->PageNo().'/{nb}',0,0,'C');
+        $this->Ln(3);
+        // Created by NOALYSS
+        $this->Cell(0,8,'Created by NOALYSS, online on 
http://www.aevalys.eu',0,0,'C',false,'http://www.aevalys.eu');
+
+    }
+    /**
+     address@hidden print the pdf for a financial ledger
+     */
+    function export()
+    {
+        $a_jrn=$this->ledger->get_operation($_GET['from_periode'],
+                                            $_GET['to_periode']);
+        $this->SetFont('DejaVu', '', 6);
+        if ( $a_jrn == null ) return;
+        bcscale(2);
+        for ( $i=0;$i<count($a_jrn);$i++)
+        {
+            $row=$a_jrn[$i];
+            $this->LongLine(15,5,$row['pj']);
+            $this->Cell(10,5,$row['date_fmt']);
+            $this->Cell(15,5,$row['internal']);
+
+            $name=$this->ledger->get_tiers($this->jrn_type,$row['id']);
+            $this->LongLine(40,5,$name,0,'L');
+
+
+            $this->LongLine(80,5,$row['comment'],0,'L');
+            $amount=$this->cn->get_value('select qf_amount from quant_fin 
where jr_id=$1',array( $row['id']));
+            $this->Cell(20,5,sprintf('%s',nbm($amount)),0,0,'R');
+            $this->Ln(5);
+            $this->tp_amount=bcadd($this->tp_amount,$amount);
+
+        }
+    }
+}
diff --git a/include/class/class_print_ledger_misc.php 
b/include/class/class_print_ledger_misc.php
new file mode 100644
index 0000000..95515ee
--- /dev/null
+++ b/include/class/class_print_ledger_misc.php
@@ -0,0 +1,97 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief print a listing of financial
+ */
+require_once NOALYSS_INCLUDE.'/lib/lib/class_pdf.php';
+class Print_Ledger_Misc extends PDF
+{
+    function __construct($p_cn,$p_jrn)
+    {
+        parent::__construct($p_cn,'P','mm','A4');
+        $this->ledger=$p_jrn;
+        $this->jrn_type=$p_jrn->get_type();
+    }
+    function Header()
+    {
+        //Arial bold 12
+        $this->SetFont('DejaVu', 'B', 12);
+        //Title
+        $this->Cell(0,10,$this->dossier, 'B', 0, 'C');
+        //Line break
+        $this->Ln(20);
+        $this->SetFont('DejaVu', 'B', 7);
+        $this->Cell(30,6,'Piece');
+        $this->Cell(10,6,'Date');
+        $this->Cell(20,6,'Interne');
+        $this->Cell(25,6,'Tiers');
+        $this->Cell(80,6,'Commentaire');
+        $this->Cell(15,6,'Montant');
+        $this->Ln(6);
+
+    }
+    function Footer()
+    {
+        //Position at 2 cm from bottom
+        $this->SetY(-20);
+        //Arial italic 8
+        $this->SetFont('Arial', 'I', 8);
+        //Page number
+        $this->Cell(0,8,'Date '.$this->date." - Page 
".$this->PageNo().'/{nb}',0,0,'C');
+        $this->Ln(3);
+        // Created by NOALYSS
+        $this->Cell(0,8,'Created by NOALYSS, online on 
http://www.aevalys.eu',0,0,'C',false,'http://www.aevalys.eu');
+    }
+    /**
+     address@hidden print the pdf
+     address@hidden
+     address@hidden
+     address@hidden
+     address@hidden
+     */
+    function export()
+    {
+        $a_jrn=$this->ledger->get_rowSimple($_GET['from_periode'],
+                                            $_GET['to_periode']);
+        $this->SetFont('DejaVu', '', 6);
+        if ( $a_jrn == null ) return;
+        for ( $i=0;$i<count($a_jrn);$i++)
+        {
+            $row=$a_jrn[$i];
+            $this->LongLine(30,5,$row['jr_pj_number']);
+            $this->Cell(10,5,  smaller_date($row['date']));
+            $this->Cell(20,5,$row['jr_internal']);
+           $type=$this->cn->get_value("select jrn_def_type from jrn_def where 
jrn_def_id=$1",array($a_jrn[$i]['jr_def_id']));
+           
$other=mb_substr($this->ledger->get_tiers($type,$a_jrn[$i]['jr_id']),0,25);
+           $this->LongLine(25,5,$other,0,'L');
+            $positive=$row['montant'];
+            $this->LongLine(80,5,$row['comment'],0,'L');
+             if ( $type == 'FIN' ) {
+              $positive = $this->cn->get_value("select qf_amount from 
quant_fin  ".
+                                         " where jr_id=".$row['jr_id']);
+             }
+            $this->Cell(15,5,nbm($positive),0,0,'R');
+            $this->Ln(5);
+
+        }
+    }
+}
diff --git a/include/class/class_print_ledger_simple.php 
b/include/class/class_print_ledger_simple.php
new file mode 100644
index 0000000..5a560f8
--- /dev/null
+++ b/include/class/class_print_ledger_simple.php
@@ -0,0 +1,277 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief this class extends PDF and let you export the detailled printing
+ *  of any ledgers
+ */
+require_once NOALYSS_INCLUDE.'/lib/lib/class_pdf.php';
+
+class Print_Ledger_Simple extends PDF
+{
+    public function __construct ($p_cn,  Acc_Ledger $p_jrn)
+    {
+
+        if($p_cn == null) die("No database connection. Abort.");
+
+        parent::__construct($p_cn,'L', 'mm', 'A4');
+        $this->ledger=$p_jrn;
+        $this->a_Tva=$this->ledger->existing_vat();
+        foreach($this->a_Tva as $line_tva)
+        {
+            //initialize Amount TVA
+            $tmp1=$line_tva['tva_id'];
+            $this->rap_tva[$tmp1]=0;
+        }
+        $this->jrn_type=$p_jrn->get_type();
+        
//----------------------------------------------------------------------
+        /* report
+         *
+         * get rappel to initialize amount rap_xx
+         *the easiest way is to compute sum from quant_
+         */
+        $this->previous=$this->ledger->previous_amount($_GET['from_periode']);
+
+        /* initialize the amount to report */
+        foreach($this->previous['tva'] as $line_tva)
+        {
+            //initialize Amount TVA
+            $tmp1=$line_tva['tva_id'];
+            $this->rap_tva[$tmp1]=$line_tva['sum_vat'];
+        }
+
+        $this->rap_htva=$this->previous['price'];
+        $this->rap_tvac=$this->previous['price']+$this->previous['vat'];
+        $this->rap_priv=$this->previous['priv'];
+        $this->rap_nd=$this->previous['tva_nd'];
+        $this->rap_tva_np=$this->previous['tva_np'];
+    }
+
+    function setDossierInfo($dossier = "n/a")
+    {
+        $this->dossier = dossier::name()." ".$dossier;
+    }
+    /**
+     address@hidden write the header of each page
+     */
+    function Header()
+    {
+        //Arial bold 12
+        $this->SetFont('DejaVu', 'B', 12);
+        //Title
+        $this->Cell(0,10,$this->dossier, 'B', 0, 'C');
+        //Line break
+        $this->Ln(20);
+        $this->SetFont('DejaVu', 'B', 8);
+        /* column header */
+        
//----------------------------------------------------------------------
+        // Show column header, if $flag_tva is false then display vat as column
+        foreach($this->a_Tva as $line_tva)
+        {
+            //initialize Amount TVA
+            $tmp1=$line_tva['tva_id'];
+            
$this->rap_tva[$tmp1]=(isset($this->rap_tva[$tmp1]))?$this->rap_tva[$tmp1]:0;
+        }
+        $this->Cell(15,6,'Pièce');
+        $this->Cell(10,6,'Date');
+        $this->Cell(13,6,'ref');
+        if ( $this->jrn_type=='ACH')
+            $this->Cell(40,6,'Client');
+        else
+            $this->Cell(40,6,'Fournisseur');
+
+        $flag_tva=(count($this->a_Tva) > 4)?true:false;
+        if ( !$flag_tva )      $this->Cell(65,6,'Description');
+
+        $this->Cell(15,6,'HTVA',0,0,'R');
+        if ( $this->jrn_type=='ACH')
+        {
+            $this->Cell(15,6,'Priv/DNA',0,0,'R');
+            $this->Cell(15,6,'TVA ND',0,0,'R');
+        }
+        $this->Cell(15,6,'TVA NP',0,0,'R'); // Unpaid TVA --> autoliquidation, 
NPR
+        foreach($this->a_Tva as $line_tva)
+        {
+            $this->Cell(15,6,$line_tva['tva_label'],0,0,'R');
+        }
+        $this->Cell(15,6,'TVAC',0,0,'R');
+        $this->Ln(5);
+
+        $this->SetFont('DejaVu','',6);
+        // page Header
+        $this->Cell(143,6,'report',0,0,'R');
+        $this->Cell(15,6,nbm($this->rap_htva),0,0,'R'); /* HTVA */
+        if ( $this->jrn_type != 'VEN')
+        {
+            $this->Cell(15,6,nbm($this->rap_priv),0,0,'R');  /* prive */
+            $this->Cell(15,6,nbm($this->rap_nd),0,0,'R');  /* Tva ND */
+        }
+        $this->Cell(15,6,nbm($this->rap_tva_np),0,0,'R');  /* Tva ND */
+        foreach($this->rap_tva as $line_tva)
+        $this->Cell(15,6,nbm($line_tva),0,0,'R');
+        $this->Cell(15,6,nbm($this->rap_tvac),0,0,'R'); /* Tvac */
+
+        $this->Ln(6);
+        //total page
+        $this->tp_htva=0.0;
+        $this->tp_tvac=0.0;
+        $this->tp_priv=0;
+        $this->tp_nd=0;
+        $this->tp_tva_np=0;
+        foreach($this->a_Tva as $line_tva)
+        {
+            //initialize Amount TVA
+            $tmp1=$line_tva['tva_id'];
+            $this->tp_tva[$tmp1]=0.0;
+        }
+    }
+    /**
+     address@hidden write the Footer
+     */
+    function Footer()
+    {
+        //Position at 3 cm from bottom
+        $this->SetY(-20);
+        /* write reporting  */
+        $this->Cell(143,6,'Total page ','T',0,'R'); /* HTVA */
+        $this->Cell(15,6,nbm($this->tp_htva),'T',0,'R'); /* HTVA */
+        if ( $this->jrn_type !='VEN')
+        {
+            $this->Cell(15,6,nbm($this->tp_priv),'T',0,'R');  /* prive */
+            $this->Cell(15,6,nbm($this->tp_nd),'T',0,'R');  /* Tva ND */
+        }
+        $this->Cell(15,6,nbm($this->tp_tva_np),'T',0,'R');  /* Tva Unpaid */
+        foreach($this->a_Tva as $line_tva)
+        {
+            $l=$line_tva['tva_id'];
+            $this->Cell(15,6,nbm($this->tp_tva[$l]),'T',0,'R');
+        }
+        
+        $this->Cell(15,6,nbm($this->tp_tvac),'T',0,'R'); /* Tvac */
+        $this->Ln(2);
+
+        $this->Cell(143,6,'report',0,0,'R'); /* HTVA */
+        $this->Cell(15,6,nbm($this->rap_htva),0,0,'R'); /* HTVA */
+        if ( $this->jrn_type !='VEN')
+        {
+            $this->Cell(15,6,nbm($this->rap_priv),0,0,'R');  /* prive */
+            $this->Cell(15,6,nbm($this->rap_nd),0,0,'R');  /* Tva ND */
+        }
+        $this->Cell(15,6,nbm($this->rap_tva_np),0,0,'R');  /* Tva ND */
+        
+        foreach($this->a_Tva as $line_tva)
+        {
+            $l=$line_tva['tva_id'];
+            $this->Cell(15,6,nbm($this->rap_tva[$l]),0,0,'R');
+        }
+        $this->Cell(15,6,nbm($this->rap_tvac),0,0,'R'); /* Tvac */
+        $this->Ln(2);
+
+        //Arial italic 8
+        $this->SetFont('Arial', 'I', 8);
+        //Page number
+        $this->Cell(0,8,'Date '.$this->date." - Page 
".$this->PageNo().'/{nb}',0,0,'L');
+        // Created by NOALYSS
+        $this->Cell(0,8,'Created by NOALYSS, online on 
http://www.aevalys.eu',0,0,'R',false,'http://www.aevalys.eu');
+    }
+
+    function Cell ($w, $h=0, $txt='', $border=0, $ln=0, $align='', 
$fill=false, $link='')
+    {
+        $txt = str_replace("\\", "", $txt);
+        return parent::Cell($w, $h, $txt, $border, $ln, $align, $fill, $link);
+    }
+    /**
+     address@hidden export the ledger in  PDF
+     */
+    function export()
+    {
+      bcscale(2);
+        $a_jrn=$this->ledger->get_operation($_GET['from_periode'],
+                                            $_GET['to_periode']);
+
+        if ( $a_jrn == null ) return;
+        for ( $i=0;$i<count($a_jrn);$i++)
+        {
+            /* initialize tva */
+            for ($f=0;$f<count($this->a_Tva);$f++)
+            {
+                $l=$this->a_Tva[$f]['tva_id'];
+                $atva_amount[$l]=0;
+            }
+
+            // retrieve info from ledger
+            $aAmountVat=$this->ledger->vat_operation($a_jrn[$i]['jr_grpt_id']);
+
+            // put vat into array
+            for ($f=0;$f<count($aAmountVat);$f++)
+            {
+                $l=$aAmountVat[$f]['tva_id'];
+                
$atva_amount[$l]=bcadd($atva_amount[$l],$aAmountVat[$f]['sum_vat']);
+                
$this->tp_tva[$l]=bcadd($this->tp_tva[$l],$aAmountVat[$f]['sum_vat']);
+                
$this->rap_tva[$l]=bcadd($this->rap_tva[$l],$aAmountVat[$f]['sum_vat']);
+                
+            }
+
+            $row=$a_jrn[$i];
+            $this->LongLine(15,5,($row['pj']),0);
+            $this->Cell(10,5,$row['date_fmt'],0,0);
+            $this->Cell(13,5,$row['internal'],0,0);
+            list($qc,$name)=$this->get_tiers($row['id'],$this->jrn_type);
+            $this->LongLine(40,5,"[".$qc."]".$name,0,'L');
+
+            $this->LongLine(65,5,mb_substr($row['comment'],0,150),0,'L');
+
+            /* get other amount (without vat, total vat included, private, ND 
*/
+            $other=$this->ledger->get_other_amount($a_jrn[$i]['jr_grpt_id']);
+            $this->tp_htva=bcadd($this->tp_htva,$other['price']);
+            $this->tp_tvac=bcadd($this->tp_tvac,$other['price']+$other['vat']);
+            $this->tp_tva_np=bcadd($this->tp_tva_np,$other['tva_np']);
+            $this->tp_priv=bcadd($this->tp_priv,$other['priv']);
+            $this->tp_nd=bcadd($this->tp_nd,$other['tva_nd']);
+            $this->rap_htva=bcadd($this->rap_htva,$other['price']);
+            $this->rap_tvac=bcadd($this->rap_tvac,bcadd($other['price'], 
bcsub($other['vat'],$other['tva_np'])));
+            $this->rap_priv=bcadd($this->rap_priv,$other['priv']);
+            $this->rap_nd=bcadd($this->rap_nd,$other['tva_nd']);
+            $this->rap_tva_np=bcadd($this->rap_tva_np,$other['tva_np']);
+
+
+            $this->Cell(15,5,nbm($other['price']),0,0,'R');
+            if ( $this->jrn_type !='VEN')
+            {
+             $this->Cell(15,5,nbm($other['priv']),0,0,'R');
+             $this->Cell(15,5,nbm($other['tva_nd']),0,0,'R');
+            }
+            
+           $this->Cell(15,5,nbm($other['tva_np']),0,0,'R');
+            
+            foreach ($atva_amount as $row_atva_amount)
+            {
+                    $this->Cell(15, 5, nbm($row_atva_amount), 0, 0, 'R');
+            }
+
+           $l_tvac=bcadd($other['price'], 
bcsub($other['vat'],$other['tva_np']));
+           $l_tvac=bcadd($l_tvac,$other['tva_nd']);
+            $this->Cell(15,5,nbm($l_tvac),0,0,'R');
+            $this->Ln(5);
+        }
+    }
+
+}
diff --git a/include/class/class_print_ledger_simple_without_vat.php 
b/include/class/class_print_ledger_simple_without_vat.php
new file mode 100644
index 0000000..b7c3ae1
--- /dev/null
+++ b/include/class/class_print_ledger_simple_without_vat.php
@@ -0,0 +1,185 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief this class extends PDF and let you export the detailled printing
+ *  of any ledgers
+ */
+require_once NOALYSS_INCLUDE.'/lib/lib/class_pdf.php';
+
+class Print_Ledger_Simple_Without_Vat extends PDF
+{
+    public function __construct ($p_cn,$p_jrn)
+    {
+
+        if($p_cn == null) die("No database connection. Abort.");
+
+        parent::__construct($p_cn,'L', 'mm', 'A4');
+        $this->ledger=$p_jrn;
+        $this->jrn_type=$p_jrn->get_type();
+        
//----------------------------------------------------------------------
+        /* report
+         *
+         * get rappel to initialize amount rap_xx
+         *the easiest way is to compute sum from quant_
+         */
+        $this->previous=$this->ledger->previous_amount($_GET['from_periode']);
+
+
+        $this->rap_htva=$this->previous['price'];
+        $this->rap_tvac=$this->previous['price'];
+        $this->rap_priv=$this->previous['priv'];
+
+
+    }
+
+    function setDossierInfo($dossier = "n/a")
+    {
+        $this->dossier = dossier::name()." ".$dossier;
+    }
+    /**
+     address@hidden write the header of each page
+     */
+    function Header()
+    {
+        //Arial bold 12
+        $this->SetFont('DejaVu', 'B', 12);
+        //Title
+        $this->Cell(0,10,$this->dossier, 'B', 0, 'C');
+        //Line break
+        $this->Ln(20);
+        $this->SetFont('DejaVu', 'B', 8);
+        /* column header */
+        $this->Cell(15,6,'Pièce');
+        $this->Cell(15,6,'Date');
+        $this->Cell(20,6,'ref');
+        if ( $this->jrn_type=='ACH')
+            $this->Cell(60,6,'Client');
+        else
+            $this->Cell(60,6,'Fournisseur');
+        $this->Cell(105,6,'Commentaire');
+        if ( $this->jrn_type=='ACH')
+        {
+            $this->Cell(15,6,'Privé',0,0,'R');
+        }
+        $this->Cell(15,6,'Prix',0,0,'R');
+
+        $this->Ln(5);
+
+        $this->SetFont('DejaVu','',6);
+        // page Header
+        $this->Cell(215,6,'report',0,0,'R'); /* HTVA */
+        if ( $this->jrn_type != 'VEN')
+        {
+            $this->Cell(15,6,sprintf('%.2f',$this->rap_priv),0,0,'R');  /* 
prive */
+        }
+        $this->Cell(15,6,sprintf('%.2f',$this->rap_htva),0,0,'R'); /* HTVA */
+
+
+
+
+        $this->Ln(6);
+        //total page
+        $this->tp_htva=0.0;
+        $this->tp_tvac=0.0;
+        $this->tp_priv=0;
+        $this->tp_nd=0;
+    }
+    /**
+     address@hidden write the Footer
+     */
+    function Footer()
+    {
+        //Position at 3 cm from bottom
+        $this->SetY(-20);
+        /* write reporting  */
+        $this->Cell(215,6,'Total page ','T',0,'R'); /* HTVA */
+        if ( $this->jrn_type !='VEN')
+        {
+            $this->Cell(15,6,sprintf('%.2f',$this->tp_priv),'T',0,'R');  /* 
prive */
+        }
+        $this->Cell(15,6,sprintf('%.2f',$this->tp_htva),'T',0,'R'); /* HTVA */
+        $this->Cell(0,6,'','T',0,'R'); /* line */
+        $this->Ln(2);
+
+        $this->Cell(215,6,'report',0,0,'R'); /* HTVA */
+        if ( $this->jrn_type !='VEN')
+        {
+            $this->Cell(15,6,sprintf('%.2f',$this->rap_priv),0,0,'R');  /* 
prive */
+        }
+        $this->Cell(15,6,sprintf('%.2f',$this->rap_htva),0,0,'R'); /* HTVA */
+        $this->Ln(2);
+
+        //Arial italic 8
+        $this->SetFont('Arial', 'I', 8);
+        //Page number
+        $this->Cell(0,8,'Date '.$this->date." - Page 
".$this->PageNo().'/{nb}',0,0,'L');
+        // Created by NOALYSS
+        $this->Cell(0,8,'Created by NOALYSS, online on 
http://www.aevalys.eu',0,0,'R',false,'http://www.aevalys.eu');
+    }
+
+    function Cell ($w, $h=0, $txt='', $border=0, $ln=0, $align='', 
$fill=false, $link='')
+    {
+        $txt = str_replace("\\", "", $txt);
+        return parent::Cell($w, $h, $txt, $border, $ln, $align, $fill, $link);
+    }
+    /**
+     address@hidden export the ledger in  PDF
+     */
+    function export()
+    {
+
+        $a_jrn=$this->ledger->get_operation($_GET['from_periode'],
+                                            $_GET['to_periode']);
+
+        if ( $a_jrn == null ) return;
+        for ( $i=0;$i<count($a_jrn);$i++)
+        {
+
+            $row=$a_jrn[$i];
+            $this->LongLine(15,5,($row['pj']),0);
+            $this->Cell(15,5,$row['date_fmt'],0,0);
+            $this->Cell(20,5,$row['internal'],0,0);
+            list($qc,$name)=$this->get_tiers($row['id'],$this->jrn_type);
+            $this->Cell(20,5,$qc,0,0);
+            $this->LongLine(40,5,$name,0,'L');
+
+            $this->LongLine(105,5,$row['comment'],0,'L');
+
+            /* get other amount (without vat, total vat included, private, ND 
*/
+            $other=$this->ledger->get_other_amount($a_jrn[$i]['jr_grpt_id']);
+            $this->tp_htva+=$other['price'];
+            $this->tp_priv+=$other['priv'];
+            $this->rap_htva+=$other['price'];
+            $this->rap_priv+=$other['priv'];
+
+
+            if ( $this->jrn_type !='VEN')
+            {
+                $this->Cell(15,6,sprintf("%.2f",$other['priv']),0,0,'R');
+            }
+
+            $this->Cell(15,6,sprintf("%.2f",$other['price']),0,0,'R');
+            $this->Ln(5);
+        }
+    }
+
+}
diff --git a/include/class/class_profile_menu.php 
b/include/class/class_profile_menu.php
new file mode 100644
index 0000000..e53f469
--- /dev/null
+++ b/include/class/class_profile_menu.php
@@ -0,0 +1,280 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+// Copyright Author Dany De Bontridder address@hidden
+
+require_once NOALYSS_INCLUDE.'/database/class_profile_menu_sql.php';
+
+/**
+ * Manage the menu of a profile
+ *
+ * @author dany
+ */
+class Profile_Menu extends Profile_Menu_sql
+{
+
+    function __construct($p_cn, $p_id=-1)
+    {
+        $this->cn=$p_cn;
+        parent::__construct($p_cn, $p_id);
+    }
+
+    /**
+     * Display the content of a profile menu for printing
+     * @param type $resource
+     * @param type $p_id
+     */
+    function sub_menu($resource, $p_id)
+    {
+        if (Database::num_row($resource)!=0)
+        {
+            ////
+            // If there are submenus
+            $gDossier=dossier::id();
+            echo '<td>';
+            for ($e=0; $e<Database::num_row($resource); $e++)
+            {
+                $menu=Database::fetch_array($resource, $e);
+                $me_code=$menu['me_code'];
+
+                $me_code_dep=$menu['me_code_dep'];
+
+                $mp_type=$menu['p_type_display'];
+
+                $me_menu=$menu['me_menu'];
+                $me_desc=$menu['me_description'];
+                $me_def=($menu['pm_default']=='1')?'<span class="notice" 
style="display:inline">Défaut</span>':'';
+                ?>
+                <li id="sub<?php echo $menu['pm_id'] ?>">
+
+                    <?php echo $me_menu ?>
+                    <?php echo $me_desc ?>  <?php echo $me_def ?>
+                    <?php $ret2=$this->cn->exec_sql("
+                                    SELECT pm_id,
+                                            pm.me_code,
+                                            me_code_dep,
+                                            p_id,
+                                            p_order,
+                                            p_type_display,
+                                            pm_default,
+                                            pm_desc,
+                                            me_menu,
+                                            me_description
+                                            FROM profile_menu as pm
+                                                    join profile_menu_type on 
(p_type_display=pm_type)
+                                                    join menu_ref as mr on 
(mr.me_code=pm.me_code)
+                                            where
+                                            p_id=$1 and me_code_dep=$2
+                                            order by p_order asc
+                        ", array($p_id, $me_code)); ?>
+                    <span>
+                        <?php
+                        echo HtmlInput::anchor(SMALLX, "",
+                                sprintf(" onclick = 
\"remove_sub_menu(%d,%d)\"",
+                                        Dossier::id(), $menu['pm_id']),
+                                'class="tinybutton"')
+                        ?>
+                    </span>
+                    <?php
+                    echo "</li>";
+                } //end loop e
+                echo '</ul>';
+            } // end if
+        }
+
+        /**
+         * Show a table with all the menu and the type
+         * @param type $p_id profile.p_id
+         */
+        function display_profile_menu_detail()
+        {
+            $a_module=$this->cn->get_array("
+                       SELECT pm_id,
+                                       pm.me_code,
+                                       me_code_dep,
+                                       p_id,
+                                       p_order,
+                                       p_type_display,
+                                       pm_default,
+                                       pm_desc,
+                                       me_menu,
+                                       me_description,
+                                        me_url,
+                                        me_file,
+                                        me_javascript
+                       FROM profile_menu as pm 
+                        join profile_menu_type on (p_type_display=pm_type)
+                       join menu_ref as mr on (mr.me_code=pm.me_code)
+                       where
+                       p_id=$1 and p_type_display='M'
+                       order by p_order asc
+                       ", array($this->p_id));
+            ////////////////////////////////////////////////////////////
+            // With a module
+            ////////////////////////////////////////////////////////////
+            $this->display_module($a_module);
+
+            //*******************************************
+            // show also menu without a module
+            //*******************************************
+            $ret=$this->cn->exec_sql("
+                                        SELECT pm_id,
+                                        pm.me_code,
+                                        me_code_dep,
+                                        p_id,
+                                        p_order,
+                                        p_type_display,
+                                        pm_default,
+                                        pm_desc,
+                                        me_menu,
+                                        me_description
+                                        FROM profile_menu as pm
+                                                join profile_menu_type on 
(p_type_display=pm_type)
+                                                join menu_ref as mr on 
(mr.me_code=pm.me_code)
+                                       where
+                                       p_id=$1 and  p_type_display not in 
('M','P') and me_code_dep is null
+                                       order by p_order asc
+                                                       ", array($this->p_id));
+        }
+
+        /**
+         * @brief Display the module, with a javascript inside to show the 
menu 
+         * contained in the module
+         * Used for setting the configuration
+         * @param $ap_module $array of module received from 
display_profile_menu_detail  
+         * @see Profile_menu::display_profile_menu_detail
+         */
+        function display_module($ap_module)
+        {
+            include 
NOALYSS_INCLUDE.'/template/profile_menu_display_module.php';
+        }
+
+        /**
+         * @brief  Display all menu and submenu of a module.
+         * @see display_profile_module 
+         * 
+         */
+        function display_module_menu($p_module_id, $p_level)
+        {
+            // Get the submenu
+            $a_module=$this->cn->get_array('
+                SELECT pm_id, 
+                    me_code, 
+                    me_code_dep, 
+                    p_id, 
+                    p_order, 
+                    p_type_display, 
+                    pm_default,
+                    me_menu,
+                    me_file,
+                    me_url,
+                    me_javascript,
+                    me_parameter,
+                    me_description
+                FROM profile_menu
+                join menu_ref using (me_code)
+                where
+                p_id = $1 and
+                pm_id_dep = $2 order by p_order',
+                    array($this->p_id, $p_module_id));
+            require 
NOALYSS_INCLUDE.'/template/profile_menu_display_submenu.php';
+        }
+
+        /**
+         * display all the accessible export of a profile $p_id
+         * @param type $p_id profile.p_id
+         */
+        function printing()
+        {
+            $ret=$this->cn->exec_sql("
+                            SELECT pm_id,
+                                pm.me_code,
+                                me_code_dep,
+                                p_id,
+                                p_order,
+                                p_type_display,
+                                pm_default,
+                                pm_desc,
+                                me_menu,
+                                me_description
+                                FROM profile_menu as pm
+                                        join profile_menu_type on 
(p_type_display=pm_type)
+                                        join menu_ref as mr on 
(mr.me_code=pm.me_code)
+                                where
+                                p_id=$1 and me_type='PR'
+                                order by p_order asc
+                                                       ", array($this->p_id));
+            // Menu by module
+            $gDossier=Dossier::id();
+            $this->sub_menu($ret, $this->p_id);
+        }
+
+        /**
+         * Show the available profile for the profile $p_id, it concerns only 
the action of management (action-gestion)
+         * @param $p_id is the profile p_id
+         */
+        function available_profile()
+        {
+            $array=$this->cn->get_array("
+                                       select 
p.p_id,p.p_name,s.p_granted,s.ua_id,s.ua_right
+                                               from profile as p
+                                               join user_sec_action_profile as 
s on (s.p_granted=p.p_id)
+                                               where s.p_id=$1
+                                       union
+                                               select p2.p_id, 
p2.p_name,null,null,'X'
+                                               from profile as p2
+                                               where
+                                               p2.p_id not in (select 
p_granted from user_sec_action_profile where p_id = $1) order by p_name;
+                               ", array($this->p_id));
+            $aright_value=array(
+                array('value'=>'R', 'label'=>_('Lecture')),
+                array('value'=>'W', 'label'=>_('Ecriture')),
+                array('value'=>'X', 'label'=>_('Aucun accès'))
+            );
+            require_once NOALYSS_INCLUDE.'/template/user_sec_profile.php';
+        }
+
+        /**
+         * Show the available repository for the profile $p_id
+         * @param $p_id is the profile p_id
+         */
+        function available_repository()
+        {
+            $array=$this->cn->get_array("
+                                       select 
p.r_id,p.r_name,s.ur_id,s.ur_right
+                                               from stock_repository as p
+                                               join profile_sec_repository as 
s on (s.r_id=p.r_id)
+                                               where s.p_id=$1
+                                       union
+                                               select p2.r_id, 
p2.r_name,null,'X'
+                                               from stock_repository as p2
+                                               where
+                                               p2.r_id not in (select r_id 
from profile_sec_repository where p_id = $1) order by r_name;
+                               ", array($this->p_id));
+            $aright_value=array(
+                array('value'=>'R', 'label'=>_('Lecture')),
+                array('value'=>'W', 'label'=>_('Ecriture')),
+                array('value'=>'X', 'label'=>_('Aucun accès'))
+            );
+            require_once 
NOALYSS_INCLUDE.'/template/profile_sec_repository.php';
+        }
+
+    }
+
+    //end class
+    ?>
\ No newline at end of file
diff --git a/include/class/class_stock.php b/include/class/class_stock.php
new file mode 100644
index 0000000..76fcb43
--- /dev/null
+++ b/include/class/class_stock.php
@@ -0,0 +1,342 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/**
+ * @file
+ * @brief
+ *
+ *
+ */
+require_once NOALYSS_INCLUDE.'/database/class_stock_sql.php';
+
+class Stock extends Stock_Sql
+{
+
+       /**
+        * show history of all the stock movement
+        * @param $p_array usually contains $_GET
+        */
+       function history($p_array)
+       {
+
+               $sql = $this->create_query_histo($p_array);
+               require_once NOALYSS_INCLUDE.'/lib/class_sort_table.php';
+               $p_url = HtmlInput::get_to_string(array("gDossier", "ac", 
"wcard", "wdate_start", "wdate_end", "wrepo",
+                                       "wamount_start", "wamount_end", 
"wcode_stock", "wdirection"));
+
+               $tb = new Sort_Table();
+               $tb->add("Date", $p_url, " order by real_date asc", "order by 
real_date desc", "da", "dd");
+               $tb->add("Code Stock", $p_url, " order by sg_code asc", "order 
by sg_code desc", "sa", "sd");
+               $tb->add("Dépôt", $p_url, " order by r_name asc", "order by 
r_name desc", "ra", "rd");
+               $tb->add("Fiche", $p_url, " order by 2 asc", "order by 2 desc", 
"fa", "fd");
+               $tb->add("Commentaire", $p_url, " order by 
coalesce(sg_comment,jr_comment)  asc", "order by 
coalesce(sg_comment,jr_comment)  desc", "ca", "cd");
+               $tb->add("Montant", $p_url, " order by j_montant asc", "order 
by j_montant desc", "ja", "jd");
+               $tb->add("Quantité", $p_url, " order by sg_quantity asc", 
"order by sg_quantity  desc", "qa", "qd");
+               $tb->add("IN/OUT", $p_url, " order by (case when sg_type='c' 
then 'OUT' when sg_type='c' then 'IN' end ) asc", "order by (case when 
sg_type='c' then 'OUT' when sg_type='c' then 'IN' end ) desc", "ta", "td");
+               $order = (isset($p_array['ord'])) ? $p_array['ord'] : 'da';
+
+               $sql.=$tb->get_sql_order($order);
+               $step = $_SESSION['g_pagesize'];
+               $page = (isset($_GET['offset'])) ? $_GET['page'] : 1;
+               $offset = (isset($_GET['offset'])) ? $_GET['offset'] : 0;
+
+               $res = $this->cn->exec_sql($sql);
+
+               $max_row = Database::num_row($res);
+
+               $nav_bar = navigation_bar($offset, $max_row, 0, $page);
+
+               if ($step != -1)
+                       $res = $this->cn->exec_sql($sql . " , sg_id asc limit " 
. $step . " offset " . $offset);
+               $max_row = Database::num_row($res);
+
+               $this->search_box_button();
+               $this->search_box($p_array);
+               require_once NOALYSS_INCLUDE.'/template/stock_histo.php';
+               $this->export_stock_histo_form();
+               echo HtmlInput::print_window();
+       }
+
+       function export_stock_histo_form()
+       {
+               echo '<form style="display:inline" method="GET" 
action="export.php">';
+                echo HtmlInput::get_to_hidden(array("gDossier", "wcard", 
"wdate_start", "wdate_end", "wrepo",
+                                       "wamount_start", "wamount_end", 
"wcode_stock", "wdirection"));
+                echo HtmlInput::hidden('act','CSV:StockHisto');
+                echo HtmlInput::submit('stockhisto','Export CSV');
+                echo '</form>';
+       }
+       function export_stock_summary_list_form()
+       {
+               echo '<form style="display:inline"  method="GET" 
action="export.php">';
+                echo HtmlInput::get_to_hidden(array("gDossier", 
"state_exercice"));
+                echo HtmlInput::hidden('act','CSV:StockResmList');
+
+                echo HtmlInput::submit('stockresm','Export CSV');
+                echo '</form>';
+       }
+       function search_box_button()
+       {
+               $bt = HtmlInput::button("Recherche", "Recherche", ' 
onclick="$(\'histo_search_d\').show();"');
+               echo $bt;
+       }
+
+       function search_box($p_array)
+       {
+               // Declaration
+               global $g_user;
+               $wrepo = HtmlInput::select_stock($this->cn, "wrepo", 'R');
+               $wrepo->value[] = array('value' => -1, 'label' => 'Tous les 
dépôts');
+
+               $wdate_start = new IDate('wdate_start');
+               $wdate_end = new IDate('wdate_end');
+               $wamount_start = new INum('wamount_start');
+               $wamount_end = new INum('wamount_end');
+               $wcard = new ICard('wcard');
+               $wcode_stock = new ICard('wcode_stock');
+               $wdirection = new ISelect("wdirection");
+
+               // value
+               $wrepo->selected = HtmlInput::default_value("wrepo", -1, 
$p_array);
+
+               // Date start / end
+               $exercice = $g_user->get_exercice();
+               $periode = new Periode($this->cn);
+               list($periode_start, $periode_end) = 
$periode->get_limit($exercice);
+
+               $wdate_start->value = HtmlInput::default_value("wdate_start", 
$periode_start->first_day(), $p_array);
+               $wdate_end->value = HtmlInput::default_value("wdate_end", 
$periode_end->last_day(), $p_array);
+               //amounts
+               $wamount_start->value = 
HtmlInput::default_value("wamount_start", 0, $p_array);
+               $wamount_end->value = HtmlInput::default_value("wamount_end", 
0, $p_array);
+
+               //Card
+               $wcard->extra = "all";
+               $wcard->set_attribute("typecard", "all");
+               $wcard->value = HtmlInput::default_value("wcard", "", $p_array);
+
+               //Card stock
+               $wcode_stock->extra = " [sql] fd_id=500000 ";
+               $wcode_stock->set_attribute("typecard", "[sql] fd_id=500000");
+               $wcode_stock->value = HtmlInput::default_value("wcard", "", 
$p_array);
+
+               // Repository
+               $wcode_stock->value = HtmlInput::default_value("wcode_stock", 
"", $p_array);
+
+               //Direction
+               $wdirection->value = array(
+                       array('value' => "-1", 'label' => "Tout"),
+                       array('value' => "c", 'label' => "OUT"),
+                       array('value' => "d", 'label' => "IN")
+               );
+               $wdirection->selected = HtmlInput::default_value("wdirection", 
"-1", $p_array);
+
+               require_once NOALYSS_INCLUDE.'/template/stock_histo_search.php';
+       }
+
+       function create_query_histo($p_array)
+       {
+               global $cn,$g_user;
+               $profile=$g_user->get_profile();
+               $sql = "
+                       select sg_id,
+                               sg.f_id,
+                               (select ad_value from fiche_Detail as fd1 where 
ad_id=1 and fd1.f_id=jx.f_id) as fname,
+                               (select ad_value from fiche_Detail as fd1 where 
ad_id=23 and fd1.f_id=jx.f_id) as qcode,
+                               sg_code,
+                               coalesce(sg_comment,jr_comment) as ccomment,
+                               sg_exercice,
+                               r_name,
+                               sg.r_id,
+                               j_montant,
+                               jr_date,
+                               sg_quantity,
+                               case when sg_type='c' then 'OUT' when 
sg_type='d' then 'IN' end as direction,
+                               jr_internal,
+                               jr_id,
+                               coalesce(sg_date,jr_date) as real_date,
+                               to_char(coalesce(sg_date,jr_date),'DD.MM.YY') 
as cdate
+                       from stock_goods as sg
+                       join stock_repository as sr on (sg.r_id=sr.r_id)
+                       left join jrnx as jx on (sg.j_id=jx.j_id)
+                       left join jrn as j on (j.jr_grpt_id=jx.j_grpt)
+                       where
+                       sg.r_id in (select r_id from profile_sec_repository 
where p_id = $profile)";
+               $and = " and ";
+               $clause = "";
+               if (isset($p_array['wdate_start']) && $p_array['wdate_start'] 
!= '')
+               {
+                       $clause = $and." to_date('" . 
sql_string($p_array['wdate_start']) . 
"','DD.MM.YYYY')<=coalesce(sg_date,jr_date) ";
+               }
+               if (isset($p_array['wdate_end']) && $p_array['wdate_end'] != '')
+               {
+                       $clause.=$and . " to_date('" . 
sql_string($p_array['wdate_end']) . "','DD.MM.YYYY')>=coalesce(sg_date,jr_date) 
";
+               }
+               if (isset($p_array['wamount_start']) && 
$p_array['wamount_start'] != '' && isNumber($p_array['wamount_start']) == 1
+                                && $p_array['wamount_start'] != 0 )
+               {
+                       $clause.=$and . " j_montant >= " . 
sql_string($p_array['wamount_start']);
+               }
+               if (isset($p_array['wamount_end'])
+                               && $p_array['wamount_end'] != ''
+                               && $p_array['wamount_end'] != 0
+                               && isNumber($p_array['wamount_end']) == 1)
+               {
+                       $clause.=$and . " j_montant <= " . 
sql_string($p_array['wamount_end']);
+               }
+               if (isset($p_array['wcard']) && $p_array['wcard'] != '')
+               {
+                       $f = new Fiche($this->cn);
+                       $f->get_by_qcode($p_array['wcard'], false);
+                       if ($f->id != 0)
+                       {
+                               $clause.=$and . " sg.f_id =  " . 
sql_string($f->id);
+                       }
+               }
+               if (isset($p_array['wcode_stock']) && $p_array['wcode_stock'] 
!= "")
+               {
+                       $clause.=$and . " upper(sg_code) =  upper('" . 
sql_string(trim($p_array['wcode_stock'])) . "')";
+               }
+               if (isset($p_array['wrepo']) && $p_array['wrepo'] != -1)
+               {
+                       $clause.=$and . " sg.r_id = " . 
sql_string($p_array['wrepo']);
+               }
+               if (isset($p_array['wdirection']) && $p_array['wdirection'] != 
-1)
+               {
+                       $clause.=$and . " sg.sg_type = '" . 
sql_string($p_array['wdirection']) . "'";
+               }
+
+               return $sql . $clause;
+       }
+
+       function summary($p_array)
+       {
+               global $cn, $g_user;
+               $tmp_id=$this->build_tmp_table($p_array);
+               // Build condition
+               $a_repository = $g_user->get_available_repository('R');
+               $a_code = $cn->get_array("select distinct sg_code from 
tmp_stockgood_detail where s_id=$1", array($tmp_id));
+               if (isset($p_array['present']))
+               {
+                       $present = $p_array['present'];
+               }
+               else
+               {
+                       $present = 'T';
+               }
+               if ($present == 'T')
+               {
+                       require_once 
NOALYSS_INCLUDE.'/template/stock_summary_table.php';
+               }
+               if ($present == 'L')
+               {
+                       require_once 
NOALYSS_INCLUDE.'/template/stock_summary_list.php';
+                       $this->export_stock_summary_list_form();
+
+               }
+               echo HtmlInput::print_window();
+       }
+       function build_tmp_table($p_array)
+       {
+               global $cn,$g_user;
+                // exercice 
+                if (isset ($p_array['state_exercice']))
+                {
+                    $periode=new Periode($cn);
+                    $date=  format_date($p_array['state_exercice'], 
'YYYY-MM-DD');
+                    $periode->find_periode($date);
+                    
+                } else {
+                    $periode_id=$g_user->get_periode();
+                    $periode=new Periode($cn,$periode_id);
+                }
+                $periode->load();
+               $tmp_id = $cn->get_next_seq("public.tmp_stockgood_s_id_seq");
+               $cn->exec_sql("delete from tmp_stockgood where s_date < now() - 
interval '2 days' ");
+               $cn->exec_sql("insert into tmp_stockgood(s_id) values ($1)", 
array($tmp_id));
+
+               // get all readable repository
+               $a_repository = $g_user->get_available_repository('R');
+
+               // From ACH : IN
+               $sql_repo_detail = "
+                       insert into 
tmp_stockgood_detail(s_id,sg_code,s_qin,r_id,f_id)
+                               select $tmp_id,trim(sg_code), 
coalesce(sum(sg_quantity),0) as qin,r_id,f_id
+                               from stock_goods
+                               where
+                                       sg_type='d'
+                                       and j_id is not null
+                                       and j_id in (select j_id from jrnx 
where  j_tech_per in (select p_id from parm_periode where p_exercice=$2))
+                                       and r_id  in (select r_id from 
profile_sec_repository where p_id=$1)
+                                       group by r_id,trim(sg_code),f_id
+                       ";
+
+               // From VEN : out
+               $cn->exec_sql($sql_repo_detail, array($g_user->get_profile(), 
$periode->p_exercice));
+               $sql_repo_detail = "
+                               insert into 
tmp_stockgood_detail(s_id,sg_code,s_qout,r_id,f_id)
+                               select $tmp_id,trim(sg_code) , 
coalesce(sum(sg_quantity),0) as qout,r_id,f_id
+                               from stock_goods as sg
+                               where
+                                       sg_type='c'
+                                       and sg.j_id is not null
+                                       and sg.j_id in (select j_id from jrnx 
where  j_tech_per in (select p_id from parm_periode where p_exercice=$2))
+                                       and sg.r_id  in (select r_id from 
profile_sec_repository where p_id=$1)
+                                       group by r_id,trim(sg_code),f_id
+                       ";
+               $cn->exec_sql($sql_repo_detail, array($g_user->get_profile(), 
$periode->p_exercice));
+
+               // From INV  IN
+               $sql_repo_detail = "
+                       insert into 
tmp_stockgood_detail(s_id,sg_code,s_qin,r_id,f_id)
+                               select $tmp_id,trim(sg_code) , 
coalesce(sum(sg_quantity),0) as qin,r_id,f_id
+                               from stock_goods as sg
+                               where
+                                       sg_type='d'
+                                       and j_id is null
+                                       and sg_date >= ( select min(p_start) 
from parm_periode where p_exercice=$2)
+                                       and sg_date <= ( select max(p_end) from 
parm_periode where p_exercice=$2)
+                                        and sg.r_id  in (select r_id from 
profile_sec_repository where p_id=$1)
+                                       group by r_id,trim(sg_code),f_id
+                       ";
+               // From INV: OUT
+               $cn->exec_sql($sql_repo_detail, array($g_user->get_profile(), 
$periode->p_exercice));
+               $sql_repo_detail = "
+                               insert into 
tmp_stockgood_detail(s_id,sg_code,s_qout,r_id,f_id)
+                               select $tmp_id,trim(sg_code), 
coalesce(sum(sg_quantity),0) as qout,r_id,f_id
+                               from stock_goods
+                               where
+                                       sg_type='c'
+                                       and j_id is null
+                                        and r_id  in (select r_id from 
profile_sec_repository where p_id=$1)
+                                        and sg_date >= ( select min(p_start) 
from parm_periode where p_exercice=$2)
+                                       and sg_date <= ( select max(p_end) from 
parm_periode where p_exercice=$2)                                       
+                                        group by r_id,trim(sg_code),f_id
+                       ";
+               $cn->exec_sql($sql_repo_detail, array($g_user->get_profile(), 
$periode->p_exercice));
+               return $tmp_id;
+       }
+    
+
+}
+
+?>
diff --git a/include/class/class_stock_goods.php 
b/include/class/class_stock_goods.php
new file mode 100644
index 0000000..cfbd681
--- /dev/null
+++ b/include/class/class_stock_goods.php
@@ -0,0 +1,272 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/**
+ * @file
+ * @brief Manage the goods
+ *
+ */
+require_once NOALYSS_INCLUDE.'/database/class_stock_goods_sql.php';
+
+class Stock_Goods extends Stock_Goods_Sql
+{
+/**
+ * if an array if receive the keys are
+ *  p_date
+ *  p_depot
+ *  f_idX f_id
+ *  sg_codeX
+ *  sg_type0
+ *
+ * @global $cn database connx
+ * @param $p_array
+ * if an array if receive the keys are
+ *  p_date
+ *  p_depot
+ *  f_idX f_id
+ *  sg_codeX
+ *  sg_type0
+ * @param $p_readonly true or false
+ */
+       function input($p_array = null, $p_readonly = false)
+       {
+               global $cn;
+
+               if ($p_array != null)
+               {
+                       extract($p_array);
+               }
+               else
+               {
+                       $p_date = '';
+                       $p_motif = '';
+                       $p_depot = 0;
+               }
+               $date = new IDate('p_date', $p_date);
+               $date->setReadOnly($p_readonly);
+               $motif = new IText('p_motif', $p_motif);
+               $motif->setReadOnly($p_readonly);
+               $motif->size = 80;
+               $idepo = HtmlInput::select_stock($cn, "p_depot", "W");
+               $idepo->setReadOnly($p_readonly);
+               if (count($idepo->value) == 0)
+               {
+                       NoAccess();
+                       die();
+               }
+               $idepo->selected = $p_depot;
+                if ($p_readonly ) {
+                    $nb=$row;
+                } else {
+                    if (isset ($row ) )
+                    {
+                        $nb=($row > MAX_ARTICLE_STOCK)?$row:MAX_ARTICLE_STOCK;
+                    }else {
+                        $nb=MAX_ARTICLE_STOCK;
+                    }
+                }
+               for ($e = 0; $e < $nb; $e++)
+               {//ATTR_DEF_STOCKfiche_
+                       $sg_code[$e] = new ICard('sg_code' . $e);
+                       $sg_code[$e]->extra = "[sql]  fd_id = 500000";
+                       $sg_code[$e]->set_attribute("typecard", 
$sg_code[$e]->extra);
+                       $sg_code[$e]->set_attribute("label", "label" . $e);
+                       $sg_code[$e]->value = (isset(${'sg_code' . $e})) ? 
${'sg_code' . $e} : '';
+                       $sg_quantity[$e] = new INum('sg_quantity' . $e);
+                       $sg_quantity[$e]->value = (isset(${'sg_quantity' . 
$e})) ? ${'sg_quantity' . $e} : '';
+                       $label[$e] = new ISpan("label$e");
+                       if (trim($sg_code[$e]->value) != '')
+                       {
+                               $label[$e]->value = $cn->get_value("select 
vw_name from vw_fiche_attr where quick_code=$1", array($sg_code[$e]->value));
+                       }
+                       $sg_code[$e]->setReadOnly($p_readonly);
+                       $sg_quantity[$e]->setReadOnly($p_readonly);
+                       if ( isset (${'sg_type'.$e})) {
+                               $sg_type[$e]=(${'sg_type'.$e}=='c')?'OUT':'IN';
+                       }
+                       if ( isset (${'f_id'.$e})) {
+                               $fiche[$e]=new Fiche($this->cn,${'f_id'.$e});
+                       }
+               }
+                $select_exercice=new ISelect('p_exercice');
+                $select_exercice->value=$cn->make_array('select distinct 
p_exercice,p_exercice from parm_periode order by 1 desc');
+                
+                require_once NOALYSS_INCLUDE.'/template/stock_inv.php';
+       }
+
+       function record_save($p_array)
+       {
+               global $cn;
+               try
+               {
+                       if (isDate($p_array['p_date']) == null)
+                               throw new Exception('Date invalide');
+                       $cn->start();
+                       $ch = new Stock_Change_Sql($cn);
+                       $ch->setp("c_comment", $p_array['p_motif']);
+                       $ch->setp("r_id", $p_array['p_depot']);
+                       $ch->setp("c_date", $p_array['p_date']);
+                       $ch->setp('tech_user', $_SESSION['g_user']);
+                       $ch->insert();
+                       $per = new Periode($cn);
+                       $periode = $per->find_periode($p_array['p_date']);
+                       $exercice = $per->get_exercice($periode);
+                        $nb=$p_array['row'];
+                       for ($i = 0; $i < $nb; $i++)
+                       {
+                               $a = new Stock_Goods_Sql($cn);
+                               if ($p_array['sg_quantity' . $i] != 0 &&
+                                               trim($p_array['sg_code' . $i]) 
!= '')
+                               {
+                                        $stock=  
strtoupper(trim($p_array['sg_code' . $i]));
+                                       $fiche=new Fiche($cn);
+                                       $fiche->get_by_qcode($p_array['sg_code' 
. $i]);
+                                       /*
+                                         * check if code stock does exist
+                                         */
+                                        $count=$cn->get_value('select count(*) 
from fiche_detail where ad_id=$1 and ad_value=$2',
+                                                array(ATTR_DEF_STOCK,$stock));
+                                        if ( $count==0) {
+                                            throw new Exception("Code stock 
inexistant");
+                                        }
+                                       $a->f_id=$fiche->id;
+                                       $a->sg_code = $stock;
+                                       $a->sg_quantity = 
abs($p_array['sg_quantity' . $i]);
+                                       $a->sg_type = ($p_array['sg_quantity' . 
$i] > 0) ? 'd' : 'c';
+                                       $a->sg_comment = $p_array['p_motif'];
+                                       $a->tech_user = $_SESSION['g_user'];
+                                       $a->r_id = $p_array['p_depot'];
+                                       $a->sg_exercice = $exercice;
+                                       $a->c_id = $ch->c_id;
+                                       $a->sg_date=$p_array['p_date'];
+                                       $a->insert();
+                               }
+                       }
+                       $cn->commit();
+               }
+               catch (Exception $exc)
+               {
+                       echo $exc->getTraceAsString();
+                       throw $exc;
+               }
+       }
+        /**
+         * Insert into stock_goods from ACH and VEN
+         * @param type $p_array KEY : db => database conx, j_id => 
jrnx.j_id,goods=> f_id of the goods
+         * 'quant' => quantity ,'dir'=> d or c (c for sales OUT and d for 
purchase IN),'repo'=>r_id of the
+         * repository (stock_repository.r_id
+         */
+        static function insert_goods(&$p_cn,$p_array)
+        {
+            global $g_user;
+                       extract ($p_array);
+            if ($g_user->can_write_repo($repo) == false)
+                return false;
+
+            // Retrieve the good account for stock
+            $code = new Fiche($p_cn);
+            $code->get_by_qcode($goods);
+            $code_marchandise = $code->strAttribut(ATTR_DEF_STOCK);
+            if ($code_marchandise == NOTFOUND || $code_marchandise=='')
+                return false;
+
+            $exercice = $g_user->get_exercice();
+
+            if ($exercice == 0)
+                throw new Exception('Annee invalide erreur');
+
+            $Res = $p_cn->exec_sql("insert into stock_goods (
+                            j_id,
+                            f_id,
+                            sg_code,
+                            sg_quantity,
+                            sg_type,sg_exercice,r_id ) values 
($1,$2,$3,$4,$5,$6,$7)", array(
+                $p_array['j_id'],
+                $code->id,
+                $code_marchandise,
+                $p_array['quant'],
+                $p_array['dir'],
+                $exercice,
+                $p_array['repo']
+                    )
+            );
+           return $Res;
+    }
+    /**
+     * Return an array, used by Stock_Goods::input 
+     * @global type $cn
+     * @param type $p_array
+     * @throws Exception
+     */
+    function take_last_inventory($p_array)
+    {
+        global $cn;
+        $year=HtmlInput::default_value("p_exercice", "", $p_array);
+        $depot=HtmlInput::default_value("p_depot", "", $p_array);
+        if ($year=="")
+            throw new Exception(_('Inventaire invalide'), 10);
+        if ($depot=="")
+            throw new Exception(_('Dépôt invalide'), 20);
+
+        // compute state_exercice
+        $periode=new Periode($cn);
+        $periode->p_id=$cn->get_value("select min(p_id) from parm_periode 
where p_exercice=$1", array($year));
+        $first_day=$periode->first_day();
+
+        // compute array for stock
+        $array['state_exercice']=$first_day;
+        
+        $stock=new Stock($cn);
+        $rowid=$stock->build_tmp_table($array);
+
+        // compute first day of the next year
+        $next_year=$year+1;
+        $periode=new Periode($cn);
+        $periode->p_id=$cn->get_value("select min(p_id) from parm_periode 
where p_exercice=$1", array($next_year));
+        
+        if ($periode->p_id=="")
+            $array['p_date']="";
+        else
+            $array['p_date']=$periode->first_day();
+        
+        // Compute an array compatible with Stock_Goods::input
+        $array['p_motif']=_('Inventaire ').$year;
+        $array['p_depot']=$depot;
+        
+        $result=$cn->get_array("
+                select sg_code,sum(coalesce(s_qin,0)-coalesce(s_qout,0)) tot_
+                from tmp_stockgood_detail 
+                where 
+                s_id=$1 and r_id=$2 
+                group by sg_code",
+            array($rowid,$depot));
+        for ($e=0;$e< count($result);$e++) {
+            $array['sg_code'.$e]=$result[$e]['sg_code'];
+            $array['sg_quantity'.$e]=$result[$e]['tot_'];
+        }
+        $array['row']=$e;
+        return $array;
+        
+    }
+}
+
+?>
diff --git a/include/class/class_supplier.php b/include/class/class_supplier.php
new file mode 100644
index 0000000..4f008ee
--- /dev/null
+++ b/include/class/class_supplier.php
@@ -0,0 +1,78 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+// Copyright Author Dany De Bontridder address@hidden
+require_once NOALYSS_INCLUDE.'/constant.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_parm_code.php';
+require_once NOALYSS_INCLUDE.'/class/class_periode.php';
+require_once NOALYSS_INCLUDE.'/class/class_fiche.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_account_ledger.php';
+require_once NOALYSS_INCLUDE.'/lib/user_common.php';
+/*! \file
+ * \brief Derived from class fiche Supplier are a specific kind of card
+ */
+/*!
+ * \brief  class  Supplier are a specific kind of card
+ */
+
+// Use the view vw_supplier
+//
+class Supplier extends Fiche
+{
+
+    var $poste;      /*!< $poste poste comptable */
+    var $name;        /*!< $name name of the company */
+    var $street;      /*!< $street Street */
+    var $country;     /*!< $country Country */
+    var $cp;          /*!< $cp Zip code */
+    var $vat_number;  /*!< $vat_number vat number */
+
+    /*! \brief Constructor
+    /* only a db connection is needed */
+    function __construct($p_cn,$p_id=0)
+    {
+        $this->fiche_def_ref=FICHE_TYPE_FOURNISSEUR;
+        parent::__construct($p_cn,$p_id) ;
+
+    }
+    /*! \brief  Get all info contains in the view
+     *  thanks to the poste elt (account)
+    */
+    function get_by_account($p_poste=0)
+    {
+        $this->poste=($p_poste==0)?$this->poste:$p_poste;
+        $sql="select * from vw_supplier where poste_comptable=".$this->poste;
+        $Res=$this->cn->exec_sql($sql);
+        if ( Database::num_row($Res) == 0) return null;
+        // There is only _one_ row by supplier
+        $row=Database::fetch_array($Res,0);
+        $this->name=$row['name'];
+        $this->id=$row['f_id'];
+        $this->street=$row['rue'];
+        $this->cp=$row['code_postal'];
+        $this->country=$row['pays'];
+        $this->vat_number=$row['tva_num'];
+
+    }
+
+
+
+}
+
+?>
diff --git a/include/class/class_tag.php b/include/class/class_tag.php
new file mode 100644
index 0000000..81ce9c6
--- /dev/null
+++ b/include/class/class_tag.php
@@ -0,0 +1,115 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+// Copyright Author Dany De Bontridder address@hidden
+require_once NOALYSS_INCLUDE.'/database/class_tag_sql.php';
+
+class Tag
+{
+    function __construct($p_cn,$id=-1)
+    {
+        $this->cn=$p_cn;
+        $this->data=new Tag_SQL($p_cn,$id);
+    }
+    /**
+     * Show the list of available tag
+     * @return HTML
+     */
+    function show_list()
+    {
+        $ret=$this->data->seek(' order by t_tag');
+        if ( $this->cn->count($ret) == 0) return "";
+        require_once NOALYSS_INCLUDE.'/template/tag_list.php';
+    }
+    /**
+     * let select a tag to add
+     */
+    function select()
+    {
+        $ret=$this->data->seek(' order by t_tag');
+        require_once NOALYSS_INCLUDE.'/template/tag_select.php';
+    }
+    /**
+     * Display a inner window with the detail of a tag
+     */
+    function form_add()
+    {
+        $data=$this->data;
+        require_once NOALYSS_INCLUDE.'/template/tag_detail.php';
+    }
+    /**
+     * Show the tag you can add to a document
+     */
+    function show_form_add()
+    {
+        echo '<h2>'.' Ajout d\'un dossier (ou  tag)'.'</h2>';
+       
+        $this->form_add();
+    }
+    function save($p_array)
+    {
+        if ( trim($p_array['t_tag'])=="" ) return ;
+        $this->data->t_id=$p_array['t_id'];
+        $this->data->t_tag=  strip_tags($p_array['t_tag']);
+        $this->data->t_description=strip_tags($p_array['t_description']);
+        $this->data->save();
+    }
+    function remove($p_array)
+    {
+        $this->data->t_id=$p_array['t_id'];
+        $this->data->delete();
+    }
+    /**
+     * Show a button to select tag for Search
+     * @return HTML
+     */
+    static  function button_search($p_prefix)
+    {
+        $r="";
+        $r.=HtmlInput::button("choose_tag", "Etiquette", 
'onclick="search_display_tag('.Dossier::id().',\''.$p_prefix.'\')"', 
"smallbutton");
+        return $r;
+    }
+    /**
+     * let select a tag to add to the search
+     */
+    function select_search($p_prefix)
+    {
+        $ret=$this->data->seek(' order by t_tag');
+        require_once NOALYSS_INCLUDE.'/template/tag_search_select.php';
+    }
+    /**
+     * In the screen search add this data to the cell
+     */
+    function update_search_cell($p_prefix) {
+        echo '<span id="sp_'.$p_prefix.$this->data->t_id.'" style="border:1px 
solid black;margin-right:5px;">';
+        echo h($this->data->t_tag);
+        echo HtmlInput::hidden($p_prefix.'tag[]', $this->data->t_id);
+        $js=sprintf("$('sp_".$p_prefix.$this->data->t_id."').remove();");
+        echo HtmlInput::anchor( SMALLX, "javascript:void(0)", 
"onclick=\"$js\"", ' class="smallbutton " style="padding:0px;display:inline" ');
+        echo '</span>';
+    }
+    /**
+     * clear the search cell
+     */
+    static function add_clear_button($p_prefix) {
+        $clear=HtmlInput::button('clear', 'X', 
'onclick="search_clear_tag('.Dossier::id().',\''.$p_prefix.'\');"', 
'smallbutton');
+        return $clear;
+    }
+}
+
+?>
diff --git a/include/class/class_todo_list.php 
b/include/class/class_todo_list.php
new file mode 100644
index 0000000..222531a
--- /dev/null
+++ b/include/class/class_todo_list.php
@@ -0,0 +1,415 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief the todo list is managed by this class
+ */
+
+require_once NOALYSS_INCLUDE.'/lib/function_javascript.php';
+
+/*!\brief
+ * This class manages the table todo_list
+ *
+ *
+ * Data Member :
+ * - $cn database connx
+ * - $variable
+ *    - id (todo_list.tl_id)
+ *    - date (todo_list.tl_Date)
+ *    - title (todo_list.title)
+ *    - desc (todo_list.tl_desc)
+ *    - owner (todo_list.use_id)
+ *
+ */
+class Todo_List
+{
+
+    private static $variable=array(
+                                 "id"=>"tl_id",
+                                 "date"=>"tl_date",
+                                 "title"=>"tl_title",
+                                 "desc"=>"tl_desc",
+                                 "owner"=>"use_login",
+                                 "is_public"=>"is_public");
+    private $cn;
+    private  $tl_id,$tl_date,$tl_title,$use_login,$is_public;
+
+    function __construct ($p_init)
+    {
+        $this->cn=$p_init;
+        $this->tl_id=0;
+        $this->tl_desc="";
+        $this->use_login=$_SESSION['g_user'];
+        $this->is_public="N";
+
+    }
+    public function get_parameter($p_string)
+    {
+        if ( array_key_exists($p_string,self::$variable) )
+        {
+            $idx=self::$variable[$p_string];
+            return $this->$idx;
+        }
+        else
+            throw new Exception("Attribut inexistant $p_string");
+    }
+    public function check($p_idx,&$p_value)
+    {
+        if ( strcmp ($p_idx, 'tl_id') == 0 )
+        {
+            if ( strlen($p_value) > 6 || isNumber ($p_value) == false) return 
false;
+        }
+        if ( strcmp ($p_idx, 'tl_date') == 0 )
+        {
+            if ( strlen(trim($p_value)) ==0 ||strlen($p_value) > 12 || isDate 
($p_value) == false) return false;
+        }
+        if ( strcmp ($p_idx, 'tl_title') == 0 )
+        {
+            $p_value=mb_substr($p_value,0,120) ;
+            return true;
+        }
+        if ( strcmp ($p_idx, 'tl_desc') == 0 )
+        {
+            $p_value=mb_substr($p_value,0,400) ;
+            return true;
+        }
+        return true;
+    }
+    public function set_parameter($p_string,$p_value)
+    {
+        if ( array_key_exists($p_string,self::$variable) )
+        {
+            $idx=self::$variable[$p_string];
+            if ($this->check($idx,$p_value) == true )      
$this->$idx=$p_value;
+        }
+        else
+            throw new Exception("Attribut inexistant $p_string");
+
+
+    }
+    public function get_info()
+    {
+        return var_export(self::$variable,true);
+    }
+    public function verify()
+    {
+        if ( isDate($this->tl_date) == false )
+        {
+                       $this->tl_date=date('d.m.Y');
+        }
+        return 0;
+    }
+    public function save()
+    {
+        if (  $this->get_parameter("id") == 0 )
+            $this->insert();
+        else
+            $this->update();
+    }
+
+    public function insert()
+    {
+        if ( $this->verify() != 0 ) return;
+        if (trim($this->tl_title)=='')
+            $this->tl_title=mb_substr(trim($this->tl_desc),0,30);
+
+        if (trim($this->tl_title)=='')
+        {
+            alert('La note est vide');
+            return;
+        }
+
+        /*  limit the title to 35 char */
+        $this->tl_title=mb_substr(trim($this->tl_title),0,30);
+
+        $sql="insert into todo_list 
(tl_date,tl_title,tl_desc,use_login,is_public) ".
+             " values (to_date($1,'DD.MM.YYYY'),$2,$3,$4,$5)  returning tl_id";
+        $res=$this->cn->exec_sql(
+                 $sql,
+                 array($this->tl_date,
+                       $this->tl_title,
+                       $this->tl_desc,
+                       $this->use_login,
+                     $this->is_public)
+             );
+        $this->tl_id=Database::fetch_result($res,0,0);
+
+    }
+
+    public function update()
+    {
+        if ( $this->verify() != 0 ) return;
+
+        if (trim($this->tl_title)=='')
+            $this->tl_title=mb_substr(trim($this->tl_desc),0,40);
+
+        if (trim($this->tl_title)=='')
+        {
+            
+            return;
+        }
+
+        /*  limit the title to 35 char */
+        $this->tl_title=mb_substr(trim($this->tl_title),0,40);
+
+        $sql="update todo_list set 
tl_title=$1,tl_date=to_date($2,'DD.MM.YYYY'),tl_desc=$3,is_public=$5 ".
+             " where tl_id = $4";
+        $res=$this->cn->exec_sql(
+                 $sql,
+                 array($this->tl_title,
+                       $this->tl_date,
+                       $this->tl_desc,
+                       $this->tl_id,
+                     $this->is_public)
+             );
+
+    }
+    /*!\brief load all the task
+     *\return an array of the existing tasks of the current user
+     */
+    public function load_all()
+    {
+        $sql="select tl_id, 
+                tl_title,
+                tl_desc,
+                to_char( tl_date,'DD.MM.YYYY') as tl_date,
+                is_public,
+                use_login
+             from todo_list 
+             where 
+                use_login=$1
+                or is_public = 'Y'
+                or tl_id in (select todo_list_id from todo_list_shared where 
use_login=$1)
+             order by tl_date::date desc";
+        $res=$this->cn->exec_sql(
+                 $sql,
+                 array($this->use_login));
+        $array=Database::fetch_all($res);
+        
+        return $array;
+    }
+    public function load()
+    {
+
+        $sql="select tl_id,tl_title,tl_desc,to_char( tl_date,'DD.MM.YYYY') as 
tl_date,is_public,use_login
+             from todo_list where tl_id=$1 ";
+
+        $res=$this->cn->exec_sql(
+                 $sql,
+                 array($this->tl_id)
+             );
+
+        if ( Database::num_row($res) == 0 ) return;
+        $row=Database::fetch_array($res,0);
+        foreach ($row as $idx=>$value)
+        {
+            $this->$idx=$value;
+        }
+
+    }
+    public function delete()
+    {
+        global $g_user;
+        if ( $this->use_login != $_SESSION['g_user'] && 
$g_user->check_action(SHARENOTEREMOVE)==0) return;
+        $sql="delete from todo_list where tl_id=$1 ";
+        $res=$this->cn->exec_sql($sql,array($this->tl_id));
+
+    }
+    /**
+     address@hidden transform into xml for ajax answer
+     */
+    public function toXML()
+    {
+        $id='<tl_id>'.$this->tl_id.'</tl_id>';
+        $title='<tl_title>'.escape_xml($this->tl_title).'</tl_title>';
+        $desc='<tl_desc>'.escape_xml($this->tl_desc).'</tl_desc>';
+        $date='<tl_date>'.$this->tl_date.'</tl_date>';
+        $ret='<data>'.$id.$title.$desc.$date.'</data>';
+        return $ret;
+    }
+    /**
+     * @brief set a note public
+     * @param $p_value is Y or N
+     */
+    public function set_is_public($p_value)
+    {
+        global $g_user;
+        if ($g_user->check_action(SHARENOTEPUBLIC) == 1 )
+        {
+            $this->is_public=$p_value;
+        }
+    }
+    /**
+     * @brief Insert a share for current note 
+     * in the table todo_list_shared
+     * @param string (use_login)
+     */
+    public function save_shared_with($p_array)
+    {
+        global $g_user;
+        if ($g_user->check_action(SHARENOTE) == 1 )
+        {
+            $this->cn->exec_sql('insert into todo_list_shared 
(todo_list_id,use_login) values ($1,$2)',
+                    array($this->tl_id,$p_array));
+            
+        }
+    }
+    /**
+     * @brief Insert a share for current note 
+     * in the table todo_list_shared
+     * The public shared note cannot be removed
+     * @param string (use_login)
+     */
+    public function remove_shared_with($p_array)
+    {
+          $this->cn->exec_sql('delete from todo_list_shared where todo_list_id 
= $1 and use_login=$2',
+                    array($this->tl_id,$p_array));
+    }
+
+    /**
+     * Display the note
+     * @return html string
+     */
+    function display()
+    {
+        ob_start();
+        $this->load();
+        include 'template/todo_list_display.php';
+        $ret=ob_get_clean();
+        
+        return $ret;
+    }
+    /**
+     * Highlight today
+     * @return string
+     */
+    function get_class()
+    {
+        $p_odd="";
+        $a=date('d.m.Y');
+        if ($a == $this->tl_date) $p_odd='highlight';
+        return $p_odd;
+    }
+    function display_row($p_odd,$with_tag='Y')
+    {
+        $r="";
+        $highlight=$this->get_class();
+        $p_odd=($highlight == "")?$p_odd:$highlight;
+        if ( $with_tag == 'Y') $r =  '<tr id="tr'.$this->tl_id.'" 
class="'.$p_odd.'">';
+        $r.=
+      '<td 
sorttable_customkey="'.format_date($this->tl_date,'DD.MM.YYYY','YYYYMMDD').'">'.
+                $this->tl_date.
+      '</td>'.
+      '<td>'.
+      '<a class="line" href="javascript:void(0)" 
onclick="todo_list_show(\''.$this->tl_id.'\')">'.
+      htmlspecialchars($this->tl_title).
+      '</a>'.
+       '</td>';
+        if ( $this->is_public == 'Y' && $this->use_login != 
$_SESSION['g_user'] )
+        { // This is a public note, cannot be removed
+            $r.= '<td></td>';
+        }
+        elseif ($this->use_login == $_SESSION['g_user'] )
+        {
+            // This a note the user owns
+            $r.=  '<td>'.
+         
HtmlInput::button('del','X','onClick="todo_list_remove('.$this->tl_id.')"','smallbutton').
+         '</td>';
+        }
+        else
+        { 
+            // this is a note shared by someone else
+            $r.=  '<td>'.
+                
HtmlInput::button('del','X','onClick="todo_list_remove_share('.$this->tl_id.',\''.$this->use_login.'\','.Dossier::id().')"','smallbutton').
+         '</td>';
+        }
+        
+      if ( $with_tag == 'Y')  $r .= '</tr>';
+        return $r;
+    }
+    static  function to_object ($p_cn,$p_array) 
+    {
+        $end=count($p_array);
+        $ret=array();
+        for ($i=0;$i < $end;$i++)
+        {
+            $t=new Todo_List($p_cn);
+            $t->tl_id=$p_array[$i]['tl_id'];
+            $t->tl_date=$p_array[$i]['tl_date'];
+            $t->tl_title=$p_array[$i]['tl_title'];
+            $t->tl_desc=$p_array[$i]['tl_desc'];
+            $t->is_public=$p_array[$i]['is_public'];
+            $t->use_login=$p_array[$i]['use_login'];
+            $ret[$i]=clone $t;
+        }
+        return $ret;
+    }
+    /**
+     * @brief display all the user to select the user with who we want to share
+     * the connected user is not shown
+     * @global type $g_user
+     */
+    function display_user()
+    {
+        global $g_user;
+        // Get array of user
+        $p_array=User::get_list(Dossier::id());
+        $dossier=Dossier::id();
+        include 'template/todo_list_list_user.php';
+        
+    }
+    /**
+     * return the todo_list_shared.id of the note, if nothing is found then
+     * return 0
+     * @param $p_login
+     * @return int
+     */
+    function is_shared_with($p_login)
+    {
+        $ret=$this->cn->get_value("select id from todo_list_shared where 
use_login=$1 and todo_list_id=$2",array($p_login,$this->tl_id));
+        if ($ret == "")return 0;
+        return $ret;
+    }
+    /**
+     * @brief Add a share with someone
+     * @param type $p_login
+     */
+    function add_share($p_login)
+    {
+        $this->cn->exec_sql("insert into 
todo_list_shared(todo_list_id,use_login) values 
($1,$2)",array($this->tl_id,$p_login));
+    }
+    /**
+     * @brief remove the share with someone
+     * @param type $p_login
+     */
+    function remove_share($p_login)
+    {
+        $this->cn->exec_sql("delete from todo_list_shared where todo_list_id = 
$1 and use_login  = $2 ",array($this->tl_id,$p_login));
+    }
+    /*!\brief static testing function
+     */
+    static function test_me()
+    {
+    }
+
+}
+
+
diff --git a/include/class/class_user.php b/include/class/class_user.php
new file mode 100644
index 0000000..5a1f705
--- /dev/null
+++ b/include/class/class_user.php
@@ -0,0 +1,1226 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+// Copyright Author Dany De Bontridder address@hidden
+/** 
+ * @file
+ * @brief Data & function about connected users
+ */
+
+/**
+ * @brief Data & function about connected users
+ *   
+ */
+
+require_once NOALYSS_INCLUDE.'/constant.php';
+require_once NOALYSS_INCLUDE.'/lib/user_common.php';
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
+
+class User
+{
+
+       var $id;
+       var $pass;
+       var $db;
+       var $admin;
+       var $valid;
+        var $first_name;
+        var $name;
+        var $active ;
+        var $login ;
+        var $password ;
+        var $email ;
+        
+       function User(&$p_cn, $p_id = -1)
+       {
+               // if p_id is not set then check the connected user
+               if ($p_id == -1)
+               {
+                       if (!isset($_SESSION['g_user']))
+                       {
+                               echo '<h2 class="error">' . _('Session 
expirée<br>Utilisateur déconnecté') . '</h2>';
+                               redirect('index.php', 1);
+                               exit();
+                       }
+
+                       $this->login =strtolower($_SESSION['g_user']);
+                       $this->pass = $_SESSION['g_pass'];
+                       $this->lang = (isset($_SESSION['g_lang'])) ? 
$_SESSION['g_lang'] : 'fr_FR.utf8';
+                       $this->valid = (isset($_SESSION['isValid'])) ? 1 : 0;
+                       $this->db = $p_cn;
+                       $this->id = -1;
+                       if (isset($_SESSION['g_theme']))
+                               $this->theme = $_SESSION['g_theme'];
+
+                       $this->admin = ( isset($_SESSION['use_admin']) ) ? 
$_SESSION['use_admin'] : 0;
+
+                       if (isset($_SESSION['use_name']))
+                               $this->name = $_SESSION['use_name'];
+                       if (isset($_SESSION['use_first_name']))
+                               $this->first_name = $_SESSION['use_first_name'];
+                       $this->load();
+               }
+               else // if p_id is set get data of another user
+               {
+                       $this->id = $p_id;
+                       $this->db = $p_cn;
+                       $this->load();
+               }
+       }
+
+       /**\brief load data from database.
+        * if this->id == -1, it is unknown so we have to retrieve it
+         from the database by the login
+        * return -1 if nothing is found
+        */
+
+       function load()
+       {
+               /* if this->id == -1, it is unknown so we have to retrieve it 
from
+                 the database thanks it login */
+               if ($this->id < 0)
+               {
+                       $sql_cond = "   where lower(use_login)=lower($1)";
+                       $sql_array = array($this->login);
+               }
+               else
+               {
+                       $sql_cond = "   where use_id=$1";
+                       $sql_array = array($this->id);
+               }
+               $sql = "select use_id,
+                            use_first_name,
+                            use_name,
+                            use_login,
+                            use_active,
+                            use_admin,
+                            use_pass,
+                            use_email
+                        from ac_users ";
+               $cn = new Database();
+               $Res = $cn->exec_sql($sql . $sql_cond, $sql_array);
+               if (($Max = Database::num_row($Res)) == 0)
+                       return -1;
+               $row = Database::fetch_array($Res, 0);
+               $this->id = $row['use_id'];
+               $this->first_name = $row['use_first_name'];
+               $this->last_name = $row['use_name'];
+               $this->name = $row['use_name'];
+               $this->active = $row['use_active'];
+               $this->login = $row['use_login'];
+               $this->admin = $row['use_admin'];
+               $this->password = $row['use_pass'];
+                $this->email=$row['use_email'];
+       }
+
+       function save()
+       {
+
+               $Sql = "update ac_users set use_first_name=$1, use_name=$2
+             ,use_active=$3,use_admin=$4,use_pass=$5 ,use_email = $7 where 
use_id=$6";
+               $cn = new Database();
+               $Res = $cn->exec_sql($Sql, array($this->first_name, 
$this->last_name, $this->active, $this->admin, $this->pass, 
$this->id,$this->email));
+       }
+        function insert()
+       {
+
+               $Sql = "INSERT INTO ac_users(
+                        use_first_name, use_name, use_login, use_active,  
+                        use_admin, use_pass, use_email)
+                            VALUES ($1, $2, $3, $4, $5, $6, $7) returning 
use_id";
+
+               $cn = new Database();
+               $this->id= $cn->get_value($Sql, array($this->first_name, 
$this->last_name, $this->login,1,0, $this->pass,$this->email));
+       }
+
+       /**
+        * \brief Check if user is active and exists in therepository
+        * Automatically redirect, it doesn't check if a user can access a 
folder
+        * \param $silent false, echo an error message and exit, true : exit 
without warning
+        * default is false
+        *
+         ++ */
+
+       function Check($silent = false, $from = '')
+       {
+
+               $res = 0;
+               $pass5 = md5($this->pass);
+
+               $cn = new Database();
+               $sql = "select ac_users.use_login,ac_users.use_active, 
ac_users.use_pass,
+             use_admin,use_first_name,use_name
+             from ac_users
+             where ac_users.use_id='$this->id'
+             and ac_users.use_active=1
+             and ac_users.use_pass='$pass5'";
+               $ret = $cn->exec_sql($sql);
+               $res = Database::num_row($ret);
+               if ($res > 0)
+               {
+                       $r = Database::fetch_array($ret, 0);
+                       $_SESSION['use_admin'] = $r['use_admin'];
+                       $_SESSION['use_name'] = $r['use_name'];
+                       $_SESSION['use_first_name'] = $r['use_first_name'];
+                       $_SESSION['isValid'] = 1;
+
+                       $this->admin = $_SESSION['use_admin'];
+                       $this->name = $_SESSION['use_name'];
+                       $this->first_name = $_SESSION['use_first_name'];
+                       $this->load_global_pref();
+               }
+               $sql = "insert into audit_connect 
(ac_user,ac_ip,ac_module,ac_url,ac_state) values ($1,$2,$3,$4,$5)";
+
+               if ($res == 0)
+               {
+                       $cn->exec_sql($sql, array($_SESSION['g_user'], 
$_SERVER["REMOTE_ADDR"], $from, $_SERVER['REQUEST_URI'], 'FAIL'));
+                       if (!$silent)
+                       {
+                               echo '<script> alert(\''._('Utilisateur ou mot 
de passe incorrect').'\')</script>';
+                               redirect('index.html');
+                       }
+                       $this->valid = 0;
+                       session_unset();
+                       exit - 1;
+               }
+               else
+               {
+                       if ($from == 'LOGIN')
+                               $cn->exec_sql($sql, array($_SESSION['g_user'], 
$_SERVER["REMOTE_ADDR"], $from, $_SERVER['REQUEST_URI'], 'SUCCESS'));
+                       $this->valid = 1;
+               }
+
+               return $ret;
+       }
+
+       /**
+         * \brief return  the access to a folder,
+        * \param $p_dossier id if it is == 0 then we take the value from 
$_SESSION
+        * \return the priv_priv
+        *          - X no access
+        *          - R has access (normal user)
+        
+        *
+        */
+
+       function get_folder_access($p_dossier = 0)
+       {
+
+               if ($p_dossier == 0)
+                       $p_dossier = dossier::id();
+               if ($this->admin == 1)          return 'R';
+               $cn = new Database();
+
+               $sql = "select 'R' from jnt_use_dos where use_id=$1 and 
dos_id=$2";
+
+               $res = $cn->get_value($sql, array($this->id, $p_dossier));
+                
+               if ($cn->get_affected()== 0) return 'X';
+               return $res;
+       }
+
+       /**
+         * \brief save the access of a folder
+        * \param $db_id the dossier id
+        * \param $priv boolean, true then it is granted, false it is removed
+        */
+
+       function set_folder_access($db_id, $priv)
+        {
+
+            $cn=new Database();
+            if ($priv)
+            {
+                // the access is granted
+                $jnt=$cn->get_value("select jnt_id from jnt_use_dos where 
dos_id=$1 and use_id=$2", array($db_id, $this->id));
+
+                if ($cn->size()==0)
+                {
+
+                    $Res=$cn->exec_sql("insert into jnt_use_dos(dos_id,use_id) 
values($1,$2)", array($db_id, $this->id));
+                }
+            } 
+            else 
+            {
+                // Access is revoked
+                $cn->exec_sql('delete from jnt_use_dos where use_id  = $1 and 
dos_id = $2 ', array($this->id, $db_id));
+            }
+        }
+
+    /**
+         * \brief check that a user is valid and the access to the folder
+        * \param $p_ledger the ledger to check
+        * \return the priv_priv
+        * - O only predefined operation
+        * - W write
+        * - R read only
+        * - X no access
+        *
+
+        *
+        */
+
+       function get_ledger_access($p_ledger)
+       {
+               if ($this->admin == 1 ||
+                               $this->is_local_admin(dossier::id()) == 1)
+                       return 'W';
+
+               $sql = "select uj_priv from user_sec_jrn where uj_login=$1 and 
uj_jrn_id=$2";
+               $res = $this->db->get_value($sql, array($this->login, 
$p_ledger));
+
+               if ($res == '')
+                       $res = 'X';
+               return $res;
+       }
+
+       /**
+        * \brief get all the available ledgers for the current user
+        * \param $p_type = ALL or the type of the ledger (ACH,VEN,FIN,ODS)
+        * \param $p_access =3 for Read or WRITE, 2  write, 1 for readonly
+        *  \return a double array of available ledgers
+         @verbatim
+         [0] => [jrn_def_id]
+         [jrn_def_type]
+         [jrn_def_name]
+         [jrn_def_class_deb]
+         [jrn_def_class_cred]
+         [jrn_type_id]
+         [jrn_desc]
+         [uj_priv]
+         @endverbatim
+        */
+
+       function get_ledger($p_type = 'ALL', $p_access = 3)
+       {
+               if ($this->admin != 1 && $this->is_local_admin() != 1)
+               {
+                       $sql_type = ($p_type == 'ALL') ? '' : "and 
jrn_def_type=upper('" . sql_string($p_type) . "')";
+                       switch ($p_access)
+                       {
+                               case 3:
+                                       $sql_access = " and uj_priv!= 'X'";
+                                       break;
+                               case 2:
+                                       $sql_access = " and uj_priv = 'W'";
+                                       break;
+
+                               case 1:
+                                       $sql_access = " and ( uj_priv = 'R' or 
uj_priv='W') ";
+                                       break;
+                       }
+
+                       $sql = "select jrn_def_id,jrn_def_type,
+                 
jrn_def_name,jrn_def_class_deb,jrn_def_class_cred,jrn_type_id,jrn_desc,uj_priv,
+                 jrn_deb_max_line,jrn_cred_max_line,jrn_def_description
+                 from jrn_def join jrn_type on jrn_def_type=jrn_type_id
+                 join user_sec_jrn on uj_jrn_id=jrn_def_id
+                 where
+                 uj_login='" . $this->login . "'" .
+                                       $sql_type . $sql_access .
+                                       " order by jrn_Def_id";
+               }
+               else
+               {
+                       $sql_type = ($p_type == 'ALL') ? '' : "where 
jrn_def_type=upper('" . sql_string($p_type) . "')";
+                       $sql = "select 
jrn_def_id,jrn_def_type,jrn_def_name,jrn_def_class_deb,jrn_def_class_cred,jrn_deb_max_line,jrn_cred_max_line,
+                 jrn_type_id,jrn_desc,'W' as uj_priv,jrn_def_description
+                 from jrn_def join jrn_type on jrn_def_type=jrn_type_id
+                 $sql_type
+                 order by jrn_Def_name";
+               }
+               $res = $this->db->exec_sql($sql);
+               if (Database::num_row($res) == 0)
+                       return null;
+               $array = Database::fetch_all($res);
+               return $array;
+       }
+
+       /**
+         * \brief return an sql condition for filtering the permitted ledger
+        * \param $p_type = ALL or the type of the ledger (ACH,VEN,FIN,ODS)
+        * \param $p_access =3 for READ or WRITE, 2 READ and write, 1 for 
readonly
+        *
+        * \return sql condition like = jrn_def_id in (...)
+        */
+
+       function get_ledger_sql($p_type = 'ALL', $p_access = 3)
+       {
+               $aLedger = $this->get_ledger($p_type, $p_access);
+               if (empty($aLedger))
+                       return ' jrn_def_id < 0 ';
+               $sql = " jrn_def_id in (";
+               foreach ($aLedger as $row)
+               {
+                       $sql.=$row['jrn_def_id'] . ',';
+               }
+               $sql.='-1)';
+               return $sql;
+       }
+
+       /**
+        * \brief  Check if an user is an admin
+        *
+        * \return 1 for yes 0 for no
+        */
+
+       function Admin()
+       {
+            $this->admin = 0;
+               if ($this->login != 'phpcompta')
+               {
+                       $pass5 = md5($this->pass);
+                       $sql = "select use_admin from ac_users where 
use_login=$1
+                 and use_active=1  ";
+
+                       $cn = new Database();
+                       $res = $cn->exec_sql($sql, array($this->login));
+                       if (Database::num_row($res) == 0)
+                               throw  new Exception(__FILE__ . " " . __LINE__ 
. " aucun resultat");
+                       $this->admin = Database::fetch_result($res, 0);
+               }
+               else
+                       $this->admin = 1;
+
+               return $this->admin;
+       }
+
+       /**
+        * \brief  Set the selected periode in the user's preferences
+        *
+        * \param $p_periode periode
+        * \param     - $p_user
+        *
+        */
+
+       function set_periode($p_periode)
+       {
+               $sql = "update user_local_pref set parameter_value='$p_periode' 
where user_id='$this->id' and parameter_type='PERIODE'";
+               $Res = $this->db->exec_sql($sql);
+       }
+
+       private function set_default_periode()
+       {
+
+               /* get the first periode */
+               $sql = 'select min(p_id) as pid from parm_periode where 
p_closed = false and p_start = (select min(p_start) from parm_periode)';
+               $Res = $this->db->exec_sql($sql);
+
+               $pid = Database::fetch_result($Res, 0, 0);
+               /* if all the periode are closed, then we use the last closed 
period */
+               if ($pid == null)
+               {
+                       $sql = 'select min(p_id) as pid from parm_periode where 
p_start = (select max(p_start) from parm_periode)';
+                       $Res2 = $this->db->exec_sql($sql);
+                       $pid = Database::fetch_result($Res2, 0, 0);
+                       if ($pid == null)
+                       {
+                               throw  new Exception( _("Aucune période 
trouvéee !!!"));
+                       }
+
+                       $pid = Database::fetch_result($Res2, 0, 0);
+               }
+
+               $sql = sprintf("insert into user_local_pref 
(user_id,parameter_value,parameter_type)
+                     values ('%s','%d','PERIODE')", $this->id, $pid);
+               $Res = $this->db->exec_sql($sql);
+       }
+
+       /**
+        * \brief  Get the default periode from the user's preferences
+        *
+        * \return the default periode
+        *
+        *
+        */
+
+       function get_periode()
+       {
+
+               $array = $this->get_preference();
+               if (!isset($array['PERIODE']))
+               {
+                       $this->set_default_periode();
+                       $array = $this->get_preference();
+               }
+               return $array['PERIODE'];
+       }
+
+       /**
+         * 
+         * \brief return the mini rapport to display on the welcome page
+        * \return 0 if nothing if found or the report to display 
(formdef.fr_id)
+        */
+
+       function get_mini_report()
+       {
+               $array = $this->get_preference();
+               $fr_id = (isset($array['MINIREPORT'])) ? $array['MINIREPORT'] : 
0;
+               return $fr_id;
+       }
+
+       /**\brief set the mini rapport to display on the welcome page
+        */
+
+       function set_mini_report($p_id)
+       {
+               $count = $this->db->get_value("select count(*) from 
user_local_pref where user_id=$1 and parameter_type=$2", array($this->id, 
'MINIREPORT'));
+               if ($count == 1)
+               {
+                       $sql = "update user_local_pref set parameter_value=$1 
where user_id=$2 and parameter_type='MINIREPORT'";
+                       $Res = $this->db->exec_sql($sql, array($p_id, 
$this->id));
+               }
+               else
+               {
+                       $sql = "insert into user_local_pref 
(user_id,parameter_type,parameter_value)" .
+                                       "values($1,'MINIREPORT',$2)";
+                       $Res = $this->db->exec_sql($sql, array($this->id, 
$p_id));
+               }
+       }
+        /**
+         * Save the preference , the scope is global, the settings are saved
+         * into account_repository
+         * @param $key THEME,  LANG , PAGESIZE
+         * @param $value value of the key
+         */
+
+       function save_global_preference($key, $value)
+       {
+               $repo = new Database();
+               $count = $repo->get_value("select count(*)
+           from
+           user_global_pref
+           where
+           parameter_type=$1 and user_id=$2", array($key, $this->login));
+               if ($count == 1)
+               {
+                       $repo->exec_sql("update user_global_pref set 
parameter_value=$1
+               where parameter_type=$2 and user_id=$3", array($value, $key, 
$this->login));
+               }
+               elseif ($count == 0)
+               {
+                       $repo->exec_sql("insert into 
user_global_pref(user_id,parameter_type,parameter_value)
+               values($1,$2,$3)", array($this->login, $key, $value));
+               }
+       }
+
+       /**
+        * \brief  Get the default user's preferences
+        * \return array of (parameter_type => parameter_value)
+        */
+
+       function get_preference()
+       {
+               $sql = "select parameter_type,parameter_value from 
user_local_pref where user_id=$1";
+               $Res = $this->db->exec_sql($sql, array($this->id));
+               $l_array = array();
+               for ($i = 0; $i < Database::num_row($Res); $i++)
+               {
+                       $row = Database::fetch_array($Res, $i);
+                       $type = $row['parameter_type'];
+                       $l_array[$type] = $row['parameter_value'];
+               }
+
+
+               return $l_array;
+       }
+
+       /**
+        * Check if an user can access a module, return 1 if yes, otherwise 0
+        * record in audit log
+         * This function works only if user is connected to a Folder
+        * @param string $p_module menu_ref.me_code
+        */
+       function check_module($p_module)
+       {
+               $acc = $this->db->get_value("select count(*) from v_all_menu 
where p_id = $1
+                and me_code=$2", array($this->get_profile(), $p_module));
+               if ($acc == 0)
+               {
+                       $this->audit("FAIL", $p_module);
+                       return 0;
+               }
+               $this->audit("SUCCESS", $p_module);
+               return 1;
+       }
+
+       /**
+        * \brief  Check if an user is allowed to do an action
+        * \param p_action_id
+        * \return
+        *      - 0 no priv
+        *      - 1 priv granted
+        * @see constant.security.php
+        */
+
+       function check_action($p_action_id)
+       {
+               /*  save it into the log */
+               global $audit;
+               if ($this->Admin() == 1)
+                       return 1;
+               if ($this->is_local_admin(dossier::id()) == 1)
+                       return 1;
+
+               $Res = $this->db->exec_sql(
+                               "select * from user_sec_act where ua_login=$1 
and ua_act_id=$2", array($this->login, $p_action_id));
+               $Count = Database::num_row($Res);
+               if ($Count == 0)
+               {
+                       if (isset($audit) && $audit == true)
+                       {
+                               $cn = new Database();
+                               $sql = "insert into audit_connect 
(ac_user,ac_ip,ac_module,ac_url,ac_state) values ($1,$2,$3,$4,$5)";
+                               $cn->exec_sql($sql, array($_SESSION['g_user'], 
$_SERVER["REMOTE_ADDR"], $p_action_id, $_SERVER['REQUEST_URI'], 'FAIL'));
+                       }
+                       return 0;
+               }
+               if ($Count == 1)
+                       return 1;
+               echo "<H2 class=\"error\"> Action Invalide !!! $Count select * 
from user_sec_act where ua_login='$p_login' and ua_act_id=$p_action_id </H2>";
+               exit();
+       }
+
+       /**
+        * \brief  Get the global preferences from user_global_pref
+        *        in the account_repository db
+        *
+        * \note set $SESSION[g_variable]
+        */
+
+       function load_global_pref()
+       {
+               $cn = new Database();
+               // Load everything in an array
+               $Res = $cn->exec_sql("select parameter_type,parameter_value from
+                            user_global_pref
+                            where user_id='" . $this->login . "'");
+               $Max = Database::num_row($Res);
+               if ($Max == 0)
+               {
+                       $this->insert_default_global_pref();
+                       $this->load_global_pref();
+                       return;
+               }
+               // Load value into array
+               $line = array();
+               for ($i = 0; $i < $Max; $i++)
+               {
+                       $row = Database::fetch_array($Res, $i);
+                       $type = $row['parameter_type'];
+                       $line[$type] = $row['parameter_value'];
+                       ;
+               }
+               // save array into g_ variable
+               $array_pref = array('g_theme' => 'THEME', 'g_pagesize' => 
'PAGESIZE', 'g_topmenu' => 'TOPMENU', 'g_lang' => 'LANG');
+               foreach ($array_pref as $name => $parameter)
+               {
+                       if (!isset($line[$parameter]))
+                       {
+                               $this->insert_default_global_pref($parameter);
+                               $this->load_global_pref();
+                               return;
+                       }
+                       $_SESSION[$name] = $line[$parameter];
+               }
+       }
+
+       /**
+        * \brief  insert default pref
+        *        if no parameter are given insert all the existing
+        *        parameter otherwise only the requested
+        * \param $p_type parameter's type or nothing
+        * \param $p_value parameter value
+        *
+        */
+
+       function insert_default_global_pref($p_type = "", $p_value = "")
+       {
+
+               $default_parameter = array("THEME" => "classic",
+                       "PAGESIZE" => "50",
+                       'TOPMENU' => 'TEXT',
+                       'LANG' => 'fr_FR.utf8');
+               $cn = new Database();
+               $Sql = "insert into 
user_global_pref(user_id,parameter_type,parameter_value)
+             values ('%s','%s','%s')";
+               if ($p_type == "")
+               {
+                       foreach ($default_parameter as $name => $value)
+                       {
+                               $Insert = sprintf($Sql, $this->login, $name, 
$value);
+                               $cn->exec_sql($Insert);
+                       }
+               }
+               else
+               {
+                       $value = ($p_value == "") ? $default_parameter[$p_type] 
: $p_value;
+                       $Insert = sprintf($Sql, $this->login, $p_type, $value);
+                       $cn->exec_sql($Insert);
+               }
+       }
+
+       /**
+        * \brief  update default pref
+        *           if value is not given then use the default value
+        *
+        * \param $p_type parameter's type
+        * \param $p_value parameter's value value of the type
+        */
+
+       function update_global_pref($p_type, $p_value = "")
+       {
+               $default_parameter = array("THEME" => "classic",
+                       "PAGESIZE" => "50",
+                       "LANG" => 'fr_FR.utf8',
+                       'TOPMENU' => 'SELECT');
+               $cn = new Database();
+               $Sql = "update user_global_pref set parameter_value=$1
+             where parameter_type=$2 and
+             user_id=$3";
+               $value = ($p_value == "") ? $default_parameter[$p_type] : 
$p_value;
+               $cn->exec_sql($Sql, array($value, $p_type, $this->login));
+       }
+
+//end function
+       /**\brief Return the year of current Periode
+        *        it is the parm_periode.p_exercice col
+        *        if an error occurs return 0
+        */
+
+       function get_exercice()
+       {
+               $sql = "select p_exercice from parm_periode where p_id=" . 
$this->get_periode();
+               $Ret = $this->db->exec_sql($sql);
+               if (Database::num_row($Ret) == 1)
+               {
+                       $r = Database::fetch_array($Ret, 0);
+                       return $r['p_exercice'];
+               }
+               else
+                       return 0;
+       }
+
+       /**\brief Check if the user can access
+        * otherwise warn and exit
+        * \param $p_action requested action
+        * \param $p_js = 1 javascript, or 0 just a text
+        * \return nothing the program exits automatically
+        */
+
+       function can_request($p_action, $p_js = 0)
+       {
+               if ($this->check_action($p_action) == 0)
+               {
+                       $this->audit('FAIL');
+                       if ($p_js == 1)
+                       {
+                               echo "<script>";
+                               echo "alert ('Cette action ne vous est pas 
autorisée. Contactez votre responsable');";
+                               echo "</script>";
+                       }
+                       else
+                       {
+                               echo '<div class="redcontent">';
+                               echo '<h2 class="error"> Cette action ne vous 
est pas autorisée Contactez votre responsable</h2>';
+                               echo '</div>';
+                       }
+                       exit(-1);
+               }
+       }
+
+       /**
+        address@hidden Check if the user can print (in menu_ref 
p_type_display=p)
+        *      otherwise warn and exit
+        * @param $p_action requested action
+        * @return nothing the program exits automatically
+        */
+       function check_print($p_action)
+       {
+               global $audit, $cn;
+               $this->audit('AUDIT', $p_action);
+               if ($this->Admin() == 1)
+                       return 1;
+               
+               $res = $cn->get_value("select count(*) from profile_menu
+                       join profile_user using (p_id)
+                       where user_name=$1 and me_code=$2 ", 
array($this->login, $p_action));
+               return $res;
+       }
+
+       /**\brief Check if the user can print (in menu_ref p_type_display=p)
+        * otherwise warn and exit
+        * \param $p_action requested action
+        * \return nothing the program exits automatically
+        */
+
+       function can_print($p_action, $p_js = 0)
+       {
+               if ($this->check_print($p_action) == 0)
+               {
+                       $this->audit('FAIL');
+                       if ($p_js == 1)
+                       {
+                               echo "<script>";
+                               echo "alert ('Cette action ne vous est pas 
autorisée. Contactez votre responsable');";
+                               echo "</script>";
+                       }
+                       else
+                       {
+                               echo '<div class="redcontent">';
+                               echo '<h2 class="error"> Cette action ne vous 
est pas autorisée Contactez votre responsable</h2>';
+                               echo '</div>';
+                       }
+                       exit(-1);
+               }
+       }
+
+       /**
+        * \brief  Check if an user is an local administrator
+         * @deprecated since version 6.7
+        *
+        *
+        * \param $p_dossier : dossier_id
+        *
+        * \return
+        *      - 0 if no
+        *      - 1 if yes
+        *
+        */
+
+       function is_local_admin($p_dossier = -1)
+       {
+            if ($p_dossier==-1)
+            {
+                $p_dossier=dossier::id();
+            }
+
+            if ($this->login=='admin')
+            {
+                return 1;
+            }
+            else
+            {
+                return 0;
+            }
+        }
+       /**
+        address@hidden return array of available repository
+        *
+        * @param $p_access  R for read W for write
+        * @return an array
+        */
+       function get_available_repository($p_access='R')
+       {
+                $profile=$this->get_profile();
+                $r=array();
+               if ($p_access=='R')
+               {
+                       $r=$this->db->get_array("select distinct u.r_id,r_name
+                from
+                                       profile_sec_repository as u
+                                       join stock_repository as s 
on(u.r_id=s.r_id)
+                where
+                p_id =$1
+                and ur_right='W'
+                               order by 2
+                               ",array($profile));
+               }
+               if ($p_access == 'W')
+               {
+                        $r=$this->db->get_array("select distinct u.r_id,r_name
+                from
+                                       profile_sec_repository as u
+                                       join stock_repository as s 
on(u.r_id=s.r_id)
+                where
+                p_id =$1 order by 2
+               ",array($profile));
+               }
+               return $r;
+       }
+       /**
+        * \brief return an array with all the active users who can access 
+         *  $p_dossier including the global admin. 
+         *  The user must be activated
+        *
+        * \param $p_dossier dossier
+        * \return an array of user's  object
+        *  array indices
+        *    - use_id (id )
+        *    - use_login (login of the user)
+        *    - use_name
+        *    - use_first_name
+        *
+        * \exception throw an exception if nobody can access
+        */
+
+       static function get_list($p_dossier)
+       {
+               $sql = "select distinct 
use_id,use_login,use_first_name,use_name from ac_users
+             left outer join  jnt_use_dos using (use_id)
+             where
+              (dos_id=$1 and use_active=1) or (use_active=1 and use_admin=1)
+              order by use_login,use_name";
+
+
+               $repo = new Database();
+               $array = $repo->get_array($sql, array($p_dossier));
+               if ($repo->size() == 0)
+                       throw new Exception('Error inaccessible folder');
+               return $array;
+       }
+
+       /**
+        * \brief check the access of an user on a ledger
+        *
+        * \param $p_jrn the ledger id
+        * \return
+        * - O only predefined operation
+        * - W write
+        * - R read only
+        * - X no access
+        *
+        */
+
+       function check_jrn($p_jrn)
+       {
+               return $this->get_ledger_access($p_jrn);
+       }
+
+       /**
+         * \brief check if an user can access a folder, if he cannot display a 
dialog box
+        * and exit
+        * \param the folder if
+        * \param $silent false, echo an error message and exit, true : exit 
without warning
+        * default is false
+        * \return
+        *  - L for administrator (local and global)
+        *  - X no access
+        *  - R regular user
+        */
+
+       function check_dossier($p_dossier_id, $silent = false)
+       {
+               $this->Admin();
+               if ($this->admin == 1 || $this->is_local_admin($p_dossier_id) 
== 1)
+                       return 'L';
+               $cn = new Database();
+
+               $dossier = $cn->get_value("select 'R' from jnt_use_dos where 
dos_id=$1 and use_id=$2", array($p_dossier_id, $this->id));
+               $dossier = ($dossier == '') ? 'X' : $dossier;
+               if ($dossier == 'X')
+               {
+                       $this->audit('FAIL', "Access folder ");
+                       if (!$silent)
+                       {
+                               alert(_('Dossier non accessible'));
+                               exit();
+                       }
+               }
+               return $dossier;
+       }
+
+       /**
+        * @brief return the first date and the last date of the current 
exercice for the current user
+        * @return and array ([0] => start_date,[1] => end_date)
+        */
+       function get_limit_current_exercice()
+       {
+               $current_exercice = $this->get_exercice();
+               $periode = new Periode($this->db);
+               list($per_start, $per_end) = 
$periode->get_limit($current_exercice);
+               $start = $per_start->first_day();
+               $end = $per_end->last_day();
+               return array($start, $end);
+       }
+
+       /**
+        * \brief   Show all the available folder  for the users
+        *          at the login page. For the special case 'E'
+        *          go directly to extension and bypasse the dashboard
+        * \param $p_user user
+        * \param $p_admin 1 if admin
+        *
+        * \return table in HTML
+        *
+        */
+
+       function show_dossier($p_filtre = "")
+       {
+               $p_array = $this->get_available_folder($p_filtre);
+
+               $result = "";
+               
+               $result.="<TABLE id=\"folder\" class=\"result\">";
+                $result.="<tr>";
+                $result.="<th>";
+                $result.=_("Id");
+                $result.="</th>";
+                $result.="<th>";
+                $result.=_("Nom");
+                $result.="</th>";
+                $result.="<th>";
+                $result.=_("Description");
+                $result.="</th>";
+                $result.="</tr>";
+                if ($p_array == 0) {
+                    $result.="<tr>";
+                    $result.='<td style="width:auto" colspan=3>';
+                    $result.=_("Aucun dossier disponible");
+                    $result.='</td>';
+                    $result.="</tr>";
+                    return $result;
+                }
+                
+               for ($i = 0; $i < sizeof($p_array); $i++)
+               {
+
+                       $id = $p_array[$i]['dos_id'];
+                       $name = $p_array[$i]['dos_name'];
+                       $desc = $p_array[$i]['dos_description'];
+                       if ($i % 2 == 0)
+                               $tr = "odd";
+                       else
+                               $tr = "even";
+                       $target = "do.php?gDossier=$id";
+
+                       $result.="<TR class=\"$tr\">";
+
+                       $result.=td($id, ' class="num" ');
+                       $result.="<TD class=\"$tr\">";
+                       $result.="<A class=\"dossier\" HREF=\"$target\">";
+                       $result.= "  <B>" . h($name) . "</B>";
+                       $result.="</A>";
+                       $result.="</TD>";
+                       $desc = ($desc == "") ? "<i>Aucune description</i>" : 
h($desc);
+                       $desc = "<A class=\"dossier\" 
HREF=\"$target\">$desc</A>";
+                       $result.="<TD class=\"$tr\" >" . $desc;
+                       $result.="</TD>";
+                       $result.="</TR>";
+               }
+               $result.="</TABLE>";
+               return $result;
+       }
+
+       /**
+        * \brief   Get all the available folders
+        *          for the users, checked with the security
+        *
+        * \param  $p_user user login
+        * \param  $p_admin 1 if admin
+        * \return array containing
+        *       - ac_dossier.dos_id
+        *       - ac_dossier.dos_name
+        *       - ac_dossier.dos_description
+        *
+        */
+
+       function get_available_folder($p_filter = "")
+       {
+               $cn = new Database();
+               $filter = "";
+               if ($this->admin == 0)
+               {
+                       // show only available folders
+                       // if user is not an admin
+                       $Res = $cn->exec_sql("select distinct 
dos_id,dos_name,dos_description 
+                            from ac_users
+                            natural join jnt_use_dos
+                            natural join  ac_dossier
+                            where
+                            use_login= $1
+                            and use_active = 1
+                            and ( dos_name ~* $2 or dos_description ~* $2 )
+                            order by dos_name", array($this->login, 
$p_filter));
+               }
+               else
+               {
+                       $Res = $cn->exec_sql("select distinct 
dos_id,dos_name,dos_description from ac_dossier
+             where   dos_name ~* $1 or dos_description ~* $1 order by 
dos_name", array($p_filter));
+               }
+               require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+
+               $max = Database::num_row($Res);
+               if ($max == 0)
+                       return 0;
+
+               for ($i = 0; $i < $max; $i++)
+               {
+                       $array[] = Database::fetch_array($Res, $i);
+               }
+               return $array;
+       }
+
+       function audit($action = 'AUDIT', $p_module = "")
+       {
+               global $audit;
+               if ($audit)
+               {
+                       if ($p_module == "" && isset($_REQUEST['ac']))
+                       {
+                               $p_module = $_REQUEST['ac'];
+                       }
+                       $cn = new Database();
+                       if (isset($_REQUEST['gDossier']))
+                               $p_module.= " dossier : " . 
$_REQUEST['gDossier'];
+                       $sql = "insert into audit_connect 
(ac_user,ac_ip,ac_module,ac_url,ac_state) values ($1,$2,$3,$4,$5)";
+
+                       $cn->exec_sql($sql, array(
+                               $_SESSION['g_user'],
+                               $_SERVER["REMOTE_ADDR"],
+                               $p_module,
+                               $_SERVER['REQUEST_URI'],
+                               $action));
+               }
+       }
+
+       function save_profile($p_id)
+       {
+               $count = $this->db->get_value("select count(*) from 
profile_user where user_name=$1", array($this->login));
+               if ($count == 0)
+               {
+                       $this->db->exec_sql("insert into 
profile_user(p_id,user_name)
+                                                               values 
($1,$2)", array($p_id, $this->login));
+               }
+               else
+               {
+                       $this->db->exec_sql("update profile_user set p_id=$1 
where user_name=$2", array($p_id, $this->login));
+               }
+       }
+        /**
+         *return the profile (p_id)
+         * @return profile.p_id
+         */
+       function get_profile()
+       {
+               $profile = $this->db->get_value("select p_id from profile_user 
where
+                               lower(user_name)=lower($1)", 
array($this->login));
+               return $profile;
+       }
+        /**
+         * Check if the current user can add an action in the profile given
+         * in parameter
+         * @param type $p_profile profile.p_id = action_gestion.ag_dest
+         * @return boolean
+         */
+        function can_add_action($p_profile)
+        {
+            $r=$this->db->get_value (' select count(*) 
+                from user_sec_action_profile
+                where p_granted=$1
+                and p_id=$2',
+                    array($this->get_profile(),$p_profile));
+            if ($r == 0 ) 
+            {
+                return false;
+            } 
+            return true;
+        }
+        /**
+         *Check if the profile of the user can write for this profile
+         * @param  $dtoc action_gestion.ag_id
+         * @return true if he can write otherwise false
+         */
+       function can_write_action($dtoc)
+       {
+            if ( $this->Admin() == 1 ) return true;
+               $profile = $this->get_profile();
+                    $r = $this->db->get_value(" select count(*) from 
action_gestion where ag_id=$1 and ag_dest in
+                               (select p_granted from user_sec_action_profile 
where ua_right='W' and p_id=$2) ", array($dtoc, $profile));
+               if ($r == 0)
+                       return false;
+               return true;
+       }
+
+        /**
+         *Check if the profile of the user can write for this profile
+         * @param  $dtoc action_gestion.ag_id
+         * @return true if he can write otherwise false
+         */
+       function can_read_action($dtoc)
+       {
+                if ( $this->Admin() == 1 ) return true;
+               $profile = $this->get_profile();
+               $r = $this->db->get_value(" select count(*) from action_gestion 
where ag_id=$1 and (ag_dest in
+                               (select p_granted from user_sec_action_profile 
where p_id=$2) or ag_owner=$3)", array($dtoc, $profile, $this->login));
+               if ($r == 0)
+                       return false;
+               return true;
+       }
+        /**
+         *Check if the profile of the user can write for this repository
+         * @param  $p_repo stock_repository.r_id
+         * @return true if he can write otherwise false
+         */
+        function can_write_repo($p_repo)
+        {
+            if ( $this->Admin() == 1 ) return true;
+            $profile=$this->get_profile();
+            $r=$this->db->get_value("select count(*)
+                from profile_sec_repository
+                where
+                r_id=$1
+                and p_id =$2
+                and ur_right='W'",array($p_repo,$profile));
+            if ( $r==0)
+                return false;
+            return true;
+        }
+       /**
+         *Check if the profile of the user can read for this repository
+         * @param  $p_repo stock_repository.r_id
+         * @return true if he read write otherwise false
+         */
+        function can_read_repo($p_repo)
+        {
+            if ( $this->Admin() == 1 ) return true;
+            $profile=$this->get_profile();
+            $r=$this->db->get_value("select count(*)
+                from profile_sec_repository
+                where
+                r_id=$1
+                and p_id =$2
+               ",array($p_repo,$profile));
+            if ( $r==0)
+                return false;
+            return true;
+        }
+   function save_password($p_pass1, $p_pass2) {
+        if ($p_pass1 == $p_pass2) {
+            $repo = new Database();
+            $l_pass = md5($_POST['pass_1']);
+            $repo->exec_sql("update ac_users set use_pass=$1 where 
use_login=$2", array($l_pass, $_SESSION['g_user']));
+            $_SESSION['g_pass'] = $_POST['pass_1'];
+        } else {
+            alert(_("Les mots de passe ne correspondent pas. Mot de passe 
inchangé"));
+        }
+    }
+    /**
+     * Save the password from PREFERENCE MODULE
+     * @param type $p_email
+     */
+    function save_email($p_email)
+    {
+        $repo=new Database();
+        $repo->exec_sql("update ac_users set use_email=$1 where use_login=$2", 
array($p_email, $_SESSION['g_user']));
+    }
+}
+
+?>
diff --git a/include/class_acc_account.php b/include/class_acc_account.php
deleted file mode 100644
index 960dd26..0000000
--- a/include/class_acc_account.php
+++ /dev/null
@@ -1,233 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-// Copyright Author Dany De Bontridder address@hidden
-/*! \file
- * \brief Manage the account
- */
-/*!
- * \brief Manage the account from the table tmp_pcmn
- */
-require_once NOALYSS_INCLUDE.'/class_iselect.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-
-class Acc_Account
-{
-    var $db;          /*!< $db database connection */
-    static private $variable = array("value"=>'pcm_val',
-                                     'type'=>'pcm_type',
-                                     'parent'=>'pcm_val_parent',
-                                     'libelle'=>'pcm_lib');
-    private  $pcm_val;
-    private  $pcm_type;
-    private  $pcm_parent;
-    private  $pcm_lib;
-    static public $type=array(
-                            array('label'=>'Actif','value'=>'ACT'),
-                            array('label'=>'Passif','value'=>'PAS'),
-                            array('label'=>'Actif c. 
inverse','value'=>'ACTINV'),
-                            array('label'=>'Passif 
c.inverse','value'=>'PASINV'),
-                            array('label'=>'Produit','value'=>'PRO'),
-                            array('label'=>'Produit 
Inverse','value'=>'PROINV'),
-                            array('label'=>'Charge','value'=>'CHA'),
-                            array('label'=>'Charge Inverse','value'=>'CHAINV'),
-                            array('label'=>'Non defini','value'=>'CON')
-                        );
-
-    function __construct ($p_cn,$p_id=0)
-    {
-        $this->db=$p_cn;
-        $this->pcm_val=$p_id;
-    }
-    public function get_parameter($p_string)
-    {
-        if ( array_key_exists($p_string,self::$variable) )
-        {
-            $idx=self::$variable[$p_string];
-            return $this->$idx;
-        }
-        else
-            throw new Exception (__FILE__.":".__LINE__._('Erreur attribut 
inexistant'));
-    }
-
-    function set_parameter($p_string,$p_value)
-    {
-        if ( array_key_exists($p_string,self::$variable) )
-        {
-            $idx=self::$variable[$p_string];
-            if ($this->check($idx,$p_value) == true )      
$this->$idx=$p_value;
-        }
-        else
-            throw new Exception (__FILE__.":".__LINE__._('Erreur attribut 
inexistant'));
-
-
-    }
-    /*!\brief Return the name of a account
-     *        it doesn't change any data member
-     * \return string with the pcm_lib
-     */
-    function get_lib()
-    {
-        $ret=$this->db->exec_sql(
-                 "select pcm_lib from tmp_pcmn where
-                 pcm_val=$1",array($this->pcm_val));
-        if ( Database::num_row($ret) != 0)
-        {
-            $r=Database::fetch_array($ret);
-            $this->pcm_lib=$r['pcm_lib'];
-        }
-        else
-        {
-            $this->pcm_lib=_("Poste inconnu");
-        }
-        return $this->pcm_lib;
-    }
-    /*!\brief Check that the value are valid
-     *\return true if all value are valid otherwise false
-     */
-    function check ($p_member='',$p_value='')
-    {
-        // if there is no argument we check all the member
-        if ($p_member == '' && $p_value== '' )
-        {
-            foreach (self::$variable as $l=>$k)
-            {
-                $this->check($k,$this->$k);
-            }
-        }
-        else
-        {
-            // otherwise we check only the value
-            if ( strcmp ($p_member,'pcm_val') == 0 )
-            {
-                    return true;
-            }
-            else if ( strcmp ($p_member,'pcm_val_parent') == 0 )
-            {
-                    return true;
-            }
-            else if ( strcmp ($p_member,'pcm_lib') == 0 )
-            {
-                return true;
-            }
-            else if ( strcmp ($p_member,'pcm_type') == 0 )
-            {
-                foreach (self::$type as $l=>$k)
-                {
-                    if ( strcmp ($k['value'],$p_value) == 0 ) return true;
-
-                }
-                throw new Exception(_('type de compte incorrect ').$p_value);
-            }
-            throw new Exception (_('Donnee member inconnue ').$p_member);
-        }
-
-    }
-    /*!\brief Get all the value for this object from the database
-     *        the data member are set
-     * \return false if this account doesn't exist otherwise true
-     */
-    function load()
-    {
-        $ret=$this->db->exec_sql("select pcm_lib,pcm_val_parent,pcm_type from
-                                 tmp_pcmn where 
pcm_val=$1",array($this->pcm_val));
-        $r=Database::fetch_all($ret);
-
-        if ( ! $r ) return false;
-        $this->pcm_lib=$r[0]['pcm_lib'];
-        $this->pcm_val_parent=$r[0]['pcm_val_parent'];
-        $this->pcm_type=$r[0]['pcm_type'];
-        return true;
-
-    }
-    function form($p_table=true)
-    {
-        $wType=new ISelect();
-        $wType->name='p_type';
-        $wType->value=self::$type;
-
-        if ( ! $p_table )
-        {
-            $ret='    <TR>
-                 <TD>
-                 <INPUT TYPE="TEXT" NAME="p_val" SIZE=7>
-                 </TD>
-                 <TD>
-                 <INPUT TYPE="TEXT" NAME="p_lib" size=50>
-                 </TD>
-                 <TD>
-                 <INPUT TYPE="TEXT" NAME="p_parent" size=5>
-                 </TD>
-                 <TD>';
-
-            $ret.=$wType->input().'</TD>';
-            return $ret;
-        }
-        else
-        {
-            $ret='<TABLE><TR>';
-            $ret.=sprintf ('<TD>'._('Numéro de classe').' </TD><TD><INPUT 
TYPE="TEXT" name="p_val" value="%s"></TD>',$this->pcm_val);
-            $ret.="</TR><TR>";
-            $ret.=sprintf('<TD>'._('Libellé').' </TD><TD><INPUT TYPE="TEXT" 
size="70" NAME="p_lib" value="%s"></TD>',h($this->pcm_lib));
-            $ret.= "</TR><TR>";
-            $ret.=sprintf ('<TD>'._('Classe Parent').'</TD><TD><INPUT 
TYPE="TEXT" name="p_parent" value="%s"></TD>',$this->pcm_val_parent);
-            $ret.='</tr><tr>';
-            $wType->selected=$this->pcm_type;
-            $ret.="<td> Type de poste </td>";
-            $ret.= '<td>'.$wType->input().'</td>';
-            $ret.="</TR> </TABLE>";
-            $ret.=dossier::hidden();
-
-            return $ret;
-        }
-    }
-    function count($p_value)
-    {
-        $sql="select count(*) from tmp_pcmn where pcm_val=$1";
-        return $this->db->get_value($sql,array($p_value));
-    }
-    /*!\brief for developper only during test */
-    static function test_me()
-    {
-        $cn=new Database(dossier::id());
-
-    }
-    /**
-     address@hidden update an accounting, but you can update pcm_val only if
-     * this accounting has never been used before  */
-    function update($p_old)
-    {
-        if (strcmp(trim($p_old), trim($this->pcm_val)) !=0 )
-        {
-            $count=$this->db->get_value('select count(*) from jrnx where 
j_poste=$1',
-                                        array($p_old)
-                                       );
-            if ($count != 0)
-                throw new Exception(_('Impossible de changer la valeur: poste 
déjà utilisé'));
-        }
-        $this->pcm_lib=mb_substr($this->pcm_lib,0,150);
-        $this->check();
-        $sql="update tmp_pcmn set pcm_val=$1, 
pcm_lib=$2,pcm_val_parent=$3,pcm_type=$4 where pcm_val=$5";
-        $Ret=$this->db->exec_sql($sql,array($this->pcm_val,
-                                            $this->pcm_lib,
-                                            $this->pcm_val_parent,
-                                            $this->pcm_type,
-                                            $p_old));
-    }
-}
diff --git a/include/class_acc_account_ledger.php 
b/include/class_acc_account_ledger.php
deleted file mode 100644
index ebf8f2b..0000000
--- a/include/class_acc_account_ledger.php
+++ /dev/null
@@ -1,657 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-// Copyright Author Dany De Bontridder address@hidden
-/*! \file
- * \brief Manage the account
- */
-/*!
- * \brief Manage the account from the table jrn, jrnx or tmp_pcmn
- */
-require_once NOALYSS_INCLUDE.'/class_ihidden.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-
-class Acc_Account_Ledger
-{
-    var $db;          /*!< $db database connection */
-    var $id;          /*!< $id poste_id (pcm_val)*/
-    var $label;       /*!< $label label of the poste */
-    var $parent;      /*!< $parent parent account */
-    var $row;         /*!< $row double array see get_row */
-    var $tot_deb;    /*!< value set by  get_row */
-    var $tot_cred;    /*!< value by  get_row */
-    function __construct ($p_cn,$p_id)
-    {
-        $this->db=$p_cn;
-        $this->id=$p_id;
-    }
-    /**
-     address@hidden get the row thanks the resource
-     address@hidden double array 
(j_date,deb_montant,cred_montant,description,jrn_name,j_debit,jr_internal)
-     *         (tot_deb,tot_credit)
-     */
-    private function get_row_sql($Res)
-    {
-        $array=array();
-        $tot_cred=0.0;
-        $tot_deb=0.0;
-        $Max=Database::num_row($Res);
-        if ( $Max == 0 ) return null;
-        for ($i=0;$i<$Max;$i++)
-        {
-            $array[]=Database::fetch_array($Res,$i);
-            if ($array[$i]['j_debit']=='t')
-            {
-                $tot_deb+=$array[$i]['deb_montant'] ;
-            }
-            else
-            {
-                $tot_cred+=$array[$i]['cred_montant'] ;
-            }
-        }
-        $this->row=$array;
-        $this->tot_deb=$tot_deb;
-        $this->tot_cred=$tot_cred;
-        return array($array,$tot_deb,$tot_cred);
-
-    }
-    /*!
-     * \brief  Get data for accounting entry between 2 periode
-     *
-     * \param  $p_from periode from
-     * \param  $p_to   end periode
-     * \return double array 
(j_date,deb_montant,cred_montant,description,jrn_name,j_debit,jr_internal)
-     *         (tot_deb,tot_credit
-     *
-     */
-    function get_row($p_from,$p_to)
-    {
-        $periode=sql_filter_per($this->db,$p_from,$p_to,'p_id','jr_tech_per');
-
-        $Res=$this->db->exec_sql("select distinct 
j_id,jr_id,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,j_date,".
-                                 "case when j_debit='t' then j_montant else 0 
end as deb_montant,".
-                                 "case when j_debit='f' then j_montant else 0 
end as cred_montant,".
-                                 " jr_comment as description,jrn_def_name as 
jrn_name,".
-                                 "j_debit, jr_internal,jr_pj_number ".
-                                 " from jrnx left join jrn_def on 
jrn_def_id=j_jrn_def ".
-                                 " left join jrn on jr_grpt_id=j_grpt".
-                                 " where j_poste=".$this->id." and ".$periode.
-                                 " order by j_date");
-        return $this->get_row_sql($Res);
-    }
-    /*!
-     * \brief  Get data for accounting entry between 2 date
-     *
-     * \param  $p_from date from
-     * \param  $p_to   end date
-     *\param $let 0 means all rows, 1 only lettered, 2 only unlettered
-        * \param $solded 0 means all account, 1 means only accounts with a 
saldo <> 0
-     *\note the data are filtered by the access of the current user
-     * \return double array 
(j_date,deb_montant,cred_montant,description,jrn_name,j_debit,jr_internal)
-     *         (tot_deb,tot_credit
-     *
-     */
-    function get_row_date($p_from,$p_to,$let=0,$solded=0)
-    {
-        global $g_user;
-        $filter_sql=$g_user->get_ledger_sql('ALL',3);
-        $sql_let='';
-        switch ($let)
-        {
-        case 0:
-                break;
-        case 1:
-            $sql_let=' and j_id in (select j_id from letter_cred union select 
j_id from letter_deb)';
-            break;
-        case '2':
-            $sql_let=' and j_id not in (select j_id from letter_cred union 
select j_id from letter_deb) ';
-            break;
-        }
-       if ( $solded == 1)
-         {
-           $filter=str_replace('jrn_def_id','jr_def_id',$filter_sql);
-           $bal_sql="select sum(amount_deb) as s_deb,sum(amount_cred) as 
s_cred, j_poste
-                               from                                            
(select case when j_debit='t' then j_montant else 0 end as amount_deb,
-                                                               case when 
j_debit='f' then j_montant else 0 end as amount_cred,
-                                                               j_poste
-                                                               from jrnx join 
jrn on (j_grpt = jr_grpt_id)
-                                                               where
-                                                               j_poste=$1 and
-                                                               $filter and
-                                                               ( 
to_date($2,'DD.MM.YYYY') <= j_date and
-                                  to_date($3,'DD.MM.YYYY') >= j_date  )) as 
signed_amount
-                                               group by j_poste
-                                               ";
-           $r=$this->db->get_array($bal_sql,array($this->id,$p_from,$p_to));
-           if ( $this->db->count() == 0 ) return array();
-           if ($r[0]['s_deb']==$r[0]['s_cred']) return array();
-         }
-        $Res=$this->db->exec_sql("select  jr_id,to_char(j_date,'DD.MM.YYYY') 
as j_date_fmt,j_date,".
-                                 "case when j_debit='t' then j_montant else 0 
end as deb_montant,".
-                                 "case when j_debit='f' then j_montant else 0 
end as cred_montant,".
-                                 " case when j_text is null or j_text = '' 
then jr_comment 
-                                   else jr_comment||' '||j_text  end
-                as description,jrn_def_name as jrn_name,".
-                                 "j_debit, jr_internal,jr_pj_number,
-                                                                
coalesce(comptaproc.get_letter_jnt(j_id),-1) as letter ".
-                                 ",pcm_lib ".
-                                
",jr_tech_per,p_exercice,jrn_def_name,jrn_def_code".
-                                 " from jrnx left join jrn_def on 
(jrn_def_id=j_jrn_def )".
-                                 " left join jrn on (jr_grpt_id=j_grpt)".
-                                 " left join tmp_pcmn on (j_poste=pcm_val)".
-                                " left join parm_periode on (p_id=jr_tech_per) 
".
-                                 " where j_poste=$1 and ".
-                                 " ( to_date($2,'DD.MM.YYYY') <= j_date and ".
-                                 "   to_date($3,'DD.MM.YYYY') >= j_date )".
-                                 " and $filter_sql  $sql_let ".
-                                 " order by 
j_date,substring(jr_pj_number,'[0-9]+$') asc",array($this->id,$p_from,$p_to));
-        return $this->get_row_sql($Res);
-    }
-
-
-    /*!\brief Return the name of a account
-     *        it doesn't change any data member
-     * \return string with the pcm_lib
-     */
-    function get_name()
-    {
-        $ret=$this->db->exec_sql(
-                 "select pcm_lib from tmp_pcmn where
-                 pcm_val=$1",array($this->id));
-        if ( Database::num_row($ret) != 0)
-        {
-            $r=Database::fetch_array($ret);
-            $this->name=$r['pcm_lib'];
-        }
-        else
-        {
-            $this->name="Poste inconnu";
-        }
-        return $this->name;
-    }
-    /*!\brief check if the poste exist in the tmp_pcmn
-     *\return the number of line (normally 1 or 0)
-     */
-    function do_exist()
-    {
-        $sql="select pcm_val from tmp_pcmn where pcm_val= $1";
-        $ret=$this->db->exec_sql($sql,array($this->id));
-        return Database::num_row($ret) ;
-    }
-    /*!\brief Get all the value for this object from the database
-     *        the data member are set
-     * \return false if this account doesn't exist otherwise true
-     */
-    function load()
-    {
-        $ret=$this->db->exec_sql("select pcm_lib,pcm_val_parent from
-                                 tmp_pcmn where pcm_val=$1",array($this->id));
-        $r=Database::fetch_all($ret);
-
-        if ( ! $r ) return false;
-        $this->label=$r[0]['pcm_lib'];
-        $this->parent=$r[0]['pcm_val_parent'];
-        return true;
-
-    }
-    /*!\brief Get all the value for this object from the database
-     *        the data member are set
-     * \return false if this account doesn't exist otherwise true
-     */
-    function get()
-    {
-        echo "OBSOLETE Acc_Account_Ledger->get(), a remplacer par 
Acc_Account_Ledger->load()";
-        return $this->load();
-    }
-
-    /*!
-     * \brief  give the balance of an account
-     *
-     * \return
-     *      balance of the account
-     *
-     */
-    function get_solde($p_cond=" true ")
-    {
-        $Res=$this->db->exec_sql("select sum(deb) as sum_deb, sum(cred) as 
sum_cred from
-                                 ( select j_poste,
-                                 case when j_debit='t' then j_montant else 0 
end as deb,
-                                 case when j_debit='f' then j_montant else 0 
end as cred
-                                 from jrnx join tmp_pcmn on j_poste=pcm_val
-                                 where
-                                 j_poste::text like ('$this->id'::text) and
-                                 $p_cond
-                                 ) as m  ");
-        $Max=Database::num_row($Res);
-        if ($Max==0) return 0;
-        $r=Database::fetch_array($Res,0);
-
-        return abs($r['sum_deb']-$r['sum_cred']);
-    }
-    /*!
-     * \brief   give the balance of an account
-     * \return
-     *      balance of the account
-     *
-     */
-    function get_solde_detail($p_cond="")
-    {
-
-        if ( $p_cond != "") $p_cond=" and ".$p_cond;
-        $sql="select sum(deb) as sum_deb, sum(cred) as sum_cred from
-             ( select j_poste,
-             case when j_debit='t' then j_montant else 0 end as deb,
-             case when j_debit='f' then j_montant else 0 end as cred
-             from jrnx
-             where
-             j_poste::text like ('$this->id'::text)
-             $p_cond
-             ) as m  ";
-
-        $Res=$this->db->exec_sql($sql);
-        $Max=Database::num_row($Res);
-
-        if ($Max==0)
-        {
-            return array('debit'=>0,
-                         'credit'=>0,
-                         'solde'=>0)     ;
-        }
-        $r=Database::fetch_array($Res,0);
-// if p_start is < p_end the query returns null to avoid any problem
-// we set it to 0
-        if ($r['sum_deb']=='')
-            $r['sum_deb']=0.0;
-        if ($r['sum_cred']=='')
-            $r['sum_cred']=0.0;
-
-        return array('debit'=>$r['sum_deb'],
-                     'credit'=>$r['sum_cred'],
-                     'solde'=>abs(bcsub($r['sum_deb'],$r['sum_cred'])));
-    }
-    /*!
-     * \brief isTva tell is a poste is used for VAT
-     * \param none
-     *
-     *
-     * \return 1 is Yes otherwise 0
-     */
-    function isTVA()
-    {
-        // Load TVA array
-        $a_TVA=$this->db->get_array('select tva_poste
-                                    from tva_rate');
-        foreach ( $a_TVA as $line_tva)
-        {
-            if ( $line_tva['tva_poste']  == '' )
-                continue;
-            list($tva_deb,$tva_cred)=explode(',',$line_tva['tva_poste']);
-            if ( $this->id == $tva_deb ||
-                    $this->id == $tva_cred )
-            {
-                return 1;
-            }
-        }
-        return 0;
-
-    }
-    /*!
-     * \brief HtmlTable, display a HTML of a poste for the asked period
-     * \param $p_array array for filter
-     * \param $let lettering of operation 0
-     * \return -1 if nothing is found otherwise 0
-     */
-    function HtmlTable($p_array=null,$let=0 , $from_div=0)
-    {
-        if ( $p_array==null)$p_array=$_REQUEST;
-        $this->get_name();
-        list($array,$tot_deb,$tot_cred)=$this->get_row_date( 
$p_array['from_periode'],
-                                                            
$p_array['to_periode'],$let
-                                                           );
-
-        if ( count($this->row ) == 0 )
-            return -1;
-
-        $rep="";
-
-        echo '<h2 class="title">'.$this->id." ".$this->name.'</h2>';
-        if ( $from_div == 0)
-                       echo "<TABLE class=\"resultfooter\" 
style=\"border-collapse:separate;margin:1%;width:98%;;border-spacing:0px 
5px\">";
-               else
-                       echo "<TABLE class=\"resultfooter\" 
style=\"border-collapse:separate;margin:1%;width:98%;;border-spacing:0px 
2px\">";
-        echo '<tbody>';
-        echo "<TR>".
-        "<TH style=\"text-align:left\"> Date</TH>".
-        "<TH style=\"text-align:left\"> n° de pièce </TH>".
-        "<TH style=\"text-align:left\"> Code interne </TH>".
-        "<TH style=\"text-align:left\"> Description </TH>".
-        "<TH style=\"text-align:right\"> D&eacute;bit  </TH>".
-        "<TH style=\"text-align:right\"> Cr&eacute;dit </TH>".
-        th('Prog.','style="text-align:right"').
-        th('Let.','style="text-align:right"');
-        "</TR>"
-        ;
-        $progress=0;$sum_deb=0;$sum_cred=0;
-       bcscale(2);
-       $old_exercice="";
-       $idx=0;
-        foreach ( $this->row as $op )
-        {
-            $vw_operation = sprintf('<A class="detail" 
style="text-decoration:underline;color:red" 
HREF="javascript:modifyOperation(\'%s\',\'%s\')" >%s</A>', $op['jr_id'], 
dossier::id(), $op['jr_internal']);
-            $let = '';
-                       $html_let = "";
-                       if ($op['letter'] != -1)
-                       {
-                               $let = strtoupper(base_convert($op['letter'], 
10, 36));
-                               $html_let = 
HtmlInput::show_reconcile($from_div, $let);
-                       }
-                       $tmp_diff=bcsub($op['deb_montant'],$op['cred_montant']);
-
-           /*
-            * reset prog. balance to zero if we change of exercice
-            */
-           if ( $old_exercice != $op['p_exercice'])
-             {
-               if ( $old_exercice != '')
-                 {
-                   $progress=bcsub($sum_deb,$sum_cred);
-                       $side="&nbsp;".$this->get_amount_side($progress);
-                   echo "<TR class=\"highlight\">".
-                     "<TD>$old_exercice</TD>".
-                     td('').
-                     "<TD></TD>".
-                     "<TD>Totaux</TD>".
-                     "<TD style=\"text-align:right\">".nbm($sum_deb)."</TD>".
-                     "<TD style=\"text-align:right\">".nbm($sum_cred)."</TD>".
-                     td(nbm(abs($progress)).$side,'style="text-align:right"').
-                     td('').
-                     "</TR>";
-                   $sum_cred=0;
-                   $sum_deb=0;
-                   $progress=0;
-
-                 }
-             }
-           $progress=bcadd($progress,$tmp_diff);
-               $side="&nbsp;".$this->get_amount_side($progress);
-           $sum_cred=bcadd($sum_cred,$op['cred_montant']);
-           $sum_deb=bcadd($sum_deb,$op['deb_montant']);
-               if ($idx%2 == 0) $class='class="odd"'; else $class=' 
class="even"';
-               $idx++;
-
-           echo "<TR $class name=\"tr_" . $let . "_" . $from_div . "\">" .
-                       "<TD>".smaller_date(format_date($op['j_date']))."</TD>".
-             td(h($op['jr_pj_number'])).
-             "<TD>".$vw_operation."</TD>".
-             "<TD>".h($op['description'])."</TD>".
-             "<TD style=\"text-align:right\">".nbm($op['deb_montant'])."</TD>".
-             "<TD 
style=\"text-align:right\">".nbm($op['cred_montant'])."</TD>".
-             td(nbm(abs($progress)).$side,'style="text-align:right"').
-
-             td($html_let, ' style="color:red;text-align:right"') .
-                       "</TR>";
-           $old_exercice=$op['p_exercice'];
-        }
-        echo '<tfoot>';
-        $solde_type=($sum_deb>$sum_cred)?"solde débiteur":"solde créditeur";
-        $diff=bcsub($sum_deb,$sum_cred);
-               $side="&nbsp;".$this->get_amount_side($diff);
-        echo "<TR class=\"highlight\">".
-        "<TD >Totaux</TD><td></td>".
-        "<TD ></TD>".
-        "<TD></TD>".
-         "<TD  style=\"text-align:right\">".nbm($sum_deb)."</TD>".
-         "<TD  style=\"text-align:right\">".nbm($sum_cred)."</TD>".
-         "<TD style=\"text-align:right\">".nbm(abs($diff)).$side."</TD>".
-
-        "</TR>";
-       echo   "<tr><TD>$solde_type</TD><td></td>".
-         "<TD style=\"text-align:right\">".nbm(abs($diff))."</TD>".
-        "</TR>";
-        echo '</tfoot>';
-        echo '</tbody>';
-
-        echo "</table>";
-
-        return;
-    }
-       /**
-        * return the letter C if amount is > 0, D if < 0 or =
-        * @param type $p_amount
-        * @return string
-        */
-       function get_amount_side($p_amount)
-               {
-                       if ($p_amount == 0)
-                               return "=";
-                       if ($p_amount < 0)
-                               return "C";
-                       if ($p_amount > 0)
-                               return "D";
-               }
-    /*!
-     * \brief Display HTML Table Header (button)
-     *
-     * \return none
-     */
-    static function HtmlTableHeader($actiontarget="poste")
-    {
-      switch($actiontarget)
-       {
-       case 'poste':
-         $action_csv='CSV:postedetail';
-         $action_pdf='PDF:postedetail';
-         break;
-       case 'gl_comptes':
-         $action_csv='CSV:glcompte';
-         $action_pdf='PDF:glcompte';
-         break;
-       default:
-         throw new Exception(" Fonction HtmlTableHeader argument actiontarget 
invalid");
-       }
-        $hid=new IHidden();
-
-        echo "<table  >";
-        echo '<TR>';
-        
$str_ople=(isset($_REQUEST['ople']))?HtmlInput::hidden('ople',$_REQUEST['ople']):'';
-       if ($actiontarget=='poste')
-         {
-           echo '<TD><form method="GET" ACTION="">'.
-             dossier::hidden().
-             HtmlInput::submit('bt_other',"Autre poste").
-             
$hid->input("type","poste").$hid->input('ac',$_REQUEST['ac'])."</form></TD>";
-         }
-
-
-        echo '<TD><form method="GET" ACTION="export.php">'.
-        dossier::hidden().
-        HtmlInput::submit('bt_pdf',"Export PDF").
-        HtmlInput::hidden('act',$action_pdf).
-        $hid->input("type","poste").$str_ople.
-        $hid->input('p_action','impress').
-        $hid->input("from_periode",$_REQUEST['from_periode']).
-        $hid->input("to_periode",$_REQUEST['to_periode'])
-         ;
-
-       if ( isset($_REQUEST['letter'] )) echo HtmlInput::hidden('letter','2');
-       if ( isset($_REQUEST['solded'] )) echo HtmlInput::hidden('solded','1');
-
-       if (isset($_REQUEST['from_poste']))
-         echo HtmlInput::hidden('from_poste',$_REQUEST['from_poste']);
-
-       if (isset($_REQUEST['to_poste']))
-         echo HtmlInput::hidden('to_poste',$_REQUEST['to_poste']);
-
-        if (isset($_REQUEST['poste_id']))
-         echo HtmlInput::hidden("poste_id",$_REQUEST['poste_id']);
-
-        if (isset($_REQUEST['poste_fille']))
-            echo $hid->input('poste_fille','on');
-        if (isset($_REQUEST['oper_detail']))
-            echo $hid->input('oper_detail','on');
-
-        echo "</form></TD>";
-
-        echo '<TD><form method="GET" ACTION="export.php">'.
-        dossier::hidden().
-        HtmlInput::submit('bt_csv',"Export CSV").
-       HtmlInput::hidden('act',$action_csv).
-        $hid->input("type","poste").$str_ople.
-        $hid->input('p_action','impress').
-        $hid->input("from_periode",$_REQUEST['from_periode']).
-         $hid->input("to_periode",$_REQUEST['to_periode']);
-
-       if (isset($_REQUEST['from_poste']))
-         echo HtmlInput::hidden('from_poste',$_REQUEST['from_poste']);
-
-       if (isset($_REQUEST['to_poste']))
-         echo HtmlInput::hidden('to_poste',$_REQUEST['to_poste']);
-
-        if (isset($_REQUEST['poste_id']))
-         echo HtmlInput::hidden("poste_id",$_REQUEST['poste_id']);
-
-       if ( isset($_REQUEST['letter'] )) echo HtmlInput::hidden('letter','2');
-       if ( isset($_REQUEST['solded'] )) echo HtmlInput::hidden('solded','1');
-
-        if (isset($_REQUEST['poste_fille']))
-            echo $hid->input('poste_fille','on');
-        if (isset($_REQUEST['oper_detail']))
-            echo $hid->input('oper_detail','on');
-        if (isset($_REQUEST['poste_id'])) echo 
$hid->input("poste_id",$_REQUEST['poste_id']);
-
-        echo "</form></TD>";
-       echo "</form></TD>";
-       echo '<td style="vertical-align:top">';
-       echo HtmlInput::print_window();
-       echo '</td>';
-       echo '</tr>';
-        echo "</table>";
-
-
-    }
-    /*!
-     * \brief verify that the poste belong to a ledger
-     *
-     * \return 0 ok,  -1 no
-     */
-    function belong_ledger($p_jrn)
-    {
-        $filter=$this->db->get_value("select jrn_def_class_cred from jrn_def 
where jrn_def_id=$p_jrn");
-        if ( trim ($filter) == '')
-            return 0;
-
-        $valid_cred=explode(" ",$filter);
-        $sql="select count(*) as poste from tmp_pcmn where ";
-        // Creation query
-        $or="";
-        $SqlFilter="";
-        foreach ( $valid_cred as $item_cred)
-        {
-            if ( strlen (trim($item_cred)))
-            {
-                if ( strstr($item_cred,"*") == true )
-                {
-                    $item_cred=strtr($item_cred,"*","%");
-                    $SqlItem="$or pcm_val::text like 
'".sql_string($item_cred)."'";
-                    $or="  or ";
-                }
-                else
-                {
-                    $SqlItem="$or pcm_val::text = '".sql_string($item_cred)."' 
";
-                    $or="  or ";
-                }
-                $SqlFilter=$SqlFilter.$SqlItem;
-            }
-        }//foreach
-        $sql.=$SqlFilter." and pcm_val::text='".sql_string($this->id)."'";
-        $max=$this->db->get_value($sql);
-        if ($max > 0 )
-            return 0;
-        else
-            return -1;
-    }
-    /*!\brief With the id of the ledger, get the col jrn_def_class_deb
-     *\param $p_jrn jrn_id
-     *\return array of value, or an empty array if nothing is found
-     *\note
-     *\see
-     */
-    function get_account_ledger($p_jrn)
-    {
-        $l=new Acc_Ledger($this->db,$p_jrn);
-        $row=$l->get_propertie();
-        if ( strlen(trim($row['jrn_def_class_deb'])) == 0 ) return array();
-        $valid_account=explode(" ",$row['jrn_def_class_deb']);
-        return $valid_account;
-    }
-    /*!\brief build a sql statement thanks a array found with 
get_account_ledger
-     *
-     *\param $p_jrn jrn_id
-     *\return an emty string if nothing is found or a valid SQL statement like
-    \code
-    pcm_val like ... or pcm_val like ...
-    \endcode
-     *\note
-     *\see get_account_ledger
-     */
-    function build_sql_account($p_jrn)
-    {
-        $array=$this->get_account_ledger($p_jrn);
-        if ( empty($array) ) return "";
-        $sql="";
-        foreach ( $array as $item_cred)
-        {
-            if ( strlen (trim($item_cred))>0 )
-            {
-                if ( strstr($item_cred,"*") == true )
-                {
-                    $item_cred=strtr($item_cred,"*","%");
-                    $sql_tmp=" pcm_val::text like '$item_cred' or";
-                }
-                else
-                {
-                    $sql_tmp=" pcm_val::text = '$item_cred' or";
-                }
-                $sql.=$sql_tmp;
-            }
-        }//foreach
-        /* remove the last or */
-        $sql=substr($sql,0,strlen($sql)-2);
-        return $sql;
-    }
-       /**
-        * Find the id of the cards which are using the current account
-         * 
-        * @return an array of f_id
-        */
-       function find_card()
-       {
-               $sql="select f_id from fiche_detail where ad_id=$1 and 
ad_value=$2";
-               
$account=$this->db->get_array($sql,array(ATTR_DEF_ACCOUNT,$this->id));
-               return $account;
-       }
-    static function test_me()
-    {
-        $cn=new Database(dossier::id());
-        $a=new Acc_Account_Ledger($cn,550);
-        echo ' Journal 4 '.$a->belong_ledger(4);
-        return $a->belong_ledger(4);;
-
-    }
-}
diff --git a/include/class_acc_balance.php b/include/class_acc_balance.php
deleted file mode 100644
index 654bdd2..0000000
--- a/include/class_acc_balance.php
+++ /dev/null
@@ -1,284 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-// Copyright Author Dany De Bontridder address@hidden
-/*! \file
- * \brief Class for manipulating data to print the balance of account
- */
-/*!
- * \brief Class for manipulating data to print the balance of account
- */
-require_once NOALYSS_INCLUDE.'/class_acc_account.php';
-
-class Acc_Balance
-{
-    var $db;       /*! < database connection */
-    var $row;     /*! < row for ledger*/
-    var $jrn;                                          /*!< idx of a table of 
ledger create by user->get_ledger */
-    var $from_poste;                           /*!< from_poste  filter on the 
post */
-    var $to_poste;                             /*!< to_poste filter on the 
post*/
-    var $unsold;                               /**= 0) */
-    function Acc_Balance($p_cn)
-    {
-        $this->db=$p_cn;
-        $this->jrn=null;
-        $from_poste="";
-        $to_poste="";
-       $unsold=false;
-    }
-
-
-    /*!
-     * \brief retrieve all the row from the ledger in the range of a periode
-     * \param $p_from_periode start periode (p_id)
-     * \param $p_to_periode end periode (p_id)
-     * \param $p_previous_exc previous exercice 1= yes default =0
-     *
-     * \return a double array
-     *     array of
-     *         - $a['poste']
-     *         - $a['label']
-     *         - $a['sum_deb']
-     *         - $a['sum_cred']
-     *         - $a['solde_deb']
-     *         - $a['solde_cred']
-     */
-    function get_row($p_from_periode,$p_to_periode,$p_previous_exc=0)
-    {
-        global $g_user;
-        // filter on requested periode
-        
$per_sql=sql_filter_per($this->db,$p_from_periode,$p_to_periode,'p_id','j_tech_per');
-
-
-        $and="";
-        $jrn="";
-        $from_poste="";
-        $to_poste="";
-        /* if several ledgers are asked then we filter here  */
-        if ($this->jrn!== null)
-        {
-            /**
-             address@hidden
-             address@hidden the get_ledger here is not valid and useless we 
just need a list of the 
-             * asked ledgers
-             */
-
-            $jrn="  j_jrn_def in (";
-            $comma='';
-            for ($e=0;$e<count($this->jrn);$e++)
-            {
-                $jrn.=$comma.$this->jrn[$e];
-                $comma=',';
-            }
-            $jrn.=')';
-            $and=" and ";
-        }
-
-        if ( strlen(trim($this->from_poste)) != 0 && $this->from_poste!=-1  )
-        {
-            $from_poste=" $and j_poste::text >= '".$this->from_poste."'";
-            $and=" and ";
-        }
-        if ( strlen(trim($this->to_poste)) != 0   && $this->to_poste!=-1 )
-        {
-            $to_poste=" $and j_poste::text <= '".$this->to_poste."'";
-            $and=" and ";
-        }
-        $filter_sql=$g_user->get_ledger_sql('ALL',3);
-        
-        switch ($p_previous_exc)
-        {
-            case 0:
-                // build query
-                $sql="select j_poste as poste,sum(deb) as sum_deb, sum(cred) 
as sum_cred from
-                     ( select j_poste,
-                     case when j_debit='t' then j_montant else 0 end as deb,
-                     case when j_debit='f' then j_montant else 0 end as cred
-                     from jrnx join tmp_pcmn on (j_poste=pcm_val)
-                     left join parm_periode on (j_tech_per = p_id)
-                     join jrn_def on (j_jrn_def=jrn_def_id)
-                     where
-                     $jrn $from_poste $to_poste
-                     $and $filter_sql
-                     and
-                     $per_sql ) as m group by 1 order by 1";
-                break;
-            case 1:
-                /*
-                 * retrieve balance previous exercice
-                 */
-                $periode=new Periode($this->db);
-                $previous_exc=$periode->get_exercice($p_from_periode)-1;
-                try {
-                    
list($previous_start,$previous_end)=$periode->get_limit($previous_exc);
-               
-                        
$per_sql_previous=sql_filter_per($this->db,$previous_start->p_id,$previous_end->p_id,'p_id','j_tech_per');
-                        $sql="
-                            with m as 
-                                ( select j_poste,sum(deb) as sdeb,sum(cred) as 
scred
-                                from 
-                                (select j_poste, 
-                                    case when j_debit='t' then j_montant else 
0 end as deb, 
-                                    case when j_debit='f' then j_montant else 
0 end as cred 
-                                    from jrnx 
-                                    join tmp_pcmn on (j_poste=pcm_val) 
-                                    left join parm_periode on (j_tech_per = 
p_id) 
-                                    join jrn_def on (j_jrn_def=jrn_def_id) 
-                                    where
-                                                             $jrn $from_poste 
$to_poste
-                                    $and $filter_sql and $per_sql
-                                    ) as sub_m group by j_poste order by 
j_poste ) , 
-                            p as ( select j_poste,sum(deb) as sdeb,sum(cred) 
as scred 
-                                from 
-                                    (select j_poste, 
-                                        case when j_debit='t' then j_montant 
else 0 end as deb, 
-                                        case when j_debit='f' then j_montant 
else 0 end as cred 
-                                        from jrnx join tmp_pcmn on 
(j_poste=pcm_val) 
-                                        left join parm_periode on (j_tech_per 
= p_id) 
-                                        join jrn_def on (j_jrn_def=jrn_def_id) 
-                                        where 
-                                       $jrn $from_poste $to_poste
-                                    $and $filter_sql and $per_sql_previous)  
as sub_p group by j_poste order by j_poste)
-                            select coalesce(m.j_poste,p.j_poste) as poste
-                                                                
,coalesce(m.sdeb,0) as sum_deb
-                                                                , 
coalesce(m.scred,0) as sum_cred 
-                                                                
,coalesce(p.sdeb,0) as sum_deb_previous
-                                                                , 
coalesce(p.scred,0) as sum_cred_previous from m full join p on 
(p.j_poste=m.j_poste)
-                                             order by poste";
-                       
-                 } catch (Exception $exc) {
-                    $p_previous_exc=0;
-                    /*
-                     * no previous exercice
-                     */
-                     $sql="select upper(j_poste::text) as poste,sum(deb) as 
sum_deb, sum(cred) as sum_cred from
-                     ( select j_poste,
-                     case when j_debit='t' then j_montant else 0 end as deb,
-                     case when j_debit='f' then j_montant else 0 end as cred
-                     from jrnx join tmp_pcmn on (j_poste=pcm_val)
-                     left join parm_periode on (j_tech_per = p_id)
-                     join jrn_def on (j_jrn_def=jrn_def_id)
-                     where
-                     $jrn $from_poste $to_poste
-                     $and $filter_sql
-                     and
-                     $per_sql ) as m group by poste order by poste";
-                }
-                break;
-                           
-        }
-        $cn=clone $this->db;
-        $Res=$this->db->exec_sql($sql);
-        $tot_cred=  0.0;
-        $tot_deb=  0.0;
-        $tot_deb_saldo=0.0;
-        $tot_cred_saldo=0.0;
-        $tot_cred_previous=  0.0;
-        $tot_deb_previous=  0.0;
-        $tot_deb_saldo_previous=0.0;
-        $tot_cred_saldo_previous=0.0;
-        $M=$this->db->size();
-
-        // Load the array
-        for ($i=0; $i <$M;$i++)
-        {
-            $r=$this->db->fetch($i);
-            $poste=new Acc_Account($cn,$r['poste']);
-
-            $a['poste']=$r['poste'];
-            $a['label']=mb_substr($poste->get_lib(),0,40);
-            $a['sum_deb']=round($r['sum_deb'],2);
-            $a['sum_cred']=round($r['sum_cred'],2);
-            $a['solde_deb']=round(( $a['sum_deb']  >=  $a['sum_cred'] )? 
$a['sum_deb']- $a['sum_cred']:0,2);
-            $a['solde_cred']=round(( $a['sum_deb'] <=  $a['sum_cred'] 
)?$a['sum_cred']-$a['sum_deb']:0,2);
-            if ($p_previous_exc==1)
-            {
-                $a['sum_deb_previous']=round($r['sum_deb_previous'],2);
-                $a['sum_cred_previous']=round($r['sum_cred_previous'],2);
-                $a['solde_deb_previous']=round(( $a['sum_deb_previous']  >=  
$a['sum_cred_previous'] )? $a['sum_deb_previous']- $a['sum_cred_previous']:0,2);
-                $a['solde_cred_previous']=round(( $a['sum_deb_previous'] <=  
$a['sum_cred_previous'] )?$a['sum_cred_previous']-$a['sum_deb_previous']:0,2);
-                $tot_cred_previous+=  $a['sum_cred_previous'];
-                $tot_deb_previous+= $a['sum_deb_previous'];
-                $tot_deb_saldo_previous+= $a['solde_deb_previous'];
-                $tot_cred_saldo_previous+= $a['solde_cred_previous'];
-            }
-           if ($p_previous_exc==0 && $this->unsold==true && 
$a['solde_cred']==0 && $a['solde_deb']==0) continue;
-           if ($p_previous_exc==1 && $this->unsold==true && 
$a['solde_cred']==0 && $a['solde_deb']==0 && $a['solde_cred_previous']==0 && 
$a['solde_deb_previous']==0) continue;
-            $array[$i]=$a;
-            $tot_cred+=  $a['sum_cred'];
-            $tot_deb+= $a['sum_deb'];
-            $tot_deb_saldo+= $a['solde_deb'];
-            $tot_cred_saldo+= $a['solde_cred'];
-
-
-        }//for i
-        // Add the saldo
-        $i+=1;
-        $a['poste']="";
-        $a['label']="Totaux ";
-        $a['sum_deb']=$tot_deb;
-        $a['sum_cred']=$tot_cred;
-        $a['solde_deb']=$tot_deb_saldo;
-        $a['solde_cred']=$tot_cred_saldo;
-        if ($p_previous_exc==1) {
-            $a['sum_deb_previous']=$tot_deb_previous;
-            $a['sum_cred_previous']=$tot_cred_previous;
-            $a['solde_deb_previous']=$tot_deb_saldo_previous;
-            $a['solde_cred_previous']=$tot_cred_saldo_previous;
-        }
-        $array[$i]=$a;
-        $this->row=$array;
-        return $array;
-
-    }
-    /**
-     * set the $this->jrn to the cat
-     * @todo Cette function semble ne pas fonctionner correctement
-     */
-    function filter_cat($p_array)
-    {
-        if ( empty($p_array) )
-        {
-            $this->jrn=null;
-            return;
-        }
-        /* get the list of jrn of the cat. */
-
-        $array=Acc_Ledger::array_cat();
-        $jrn=array();
-        for ($e=0;$e<count($array);$e++)
-        {
-            if ( isset($p_array[$e]))
-            {
-                $t_a=$this->db->get_array('select jrn_def_id from jrn_def 
where jrn_def_type=$1',array($array[$e]['cat']));
-                for ( $f=0;$f < count($t_a);$f++) 
$this->jrn[]=$t_a[$f]['jrn_def_id'];
-            }
-        }
-
-    }
-    static function test_me ()
-    {
-        require 'class_user.php';
-        global $g_user;
-        $cn=new Database(dossier::id());
-        $g_user=new User($cn);
-        $a=new Acc_Balance($cn);
-        $a->get_row(163, 175, 1);
-        var_dump($a);
-    }
-}
diff --git a/include/class_acc_bilan.php b/include/class_acc_bilan.php
deleted file mode 100644
index 18bff4c..0000000
--- a/include/class_acc_bilan.php
+++ /dev/null
@@ -1,729 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief this class handle the different bilan, from the table bilan
- *
- */
-require_once NOALYSS_INCLUDE.'/class_iselect.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-require_once NOALYSS_INCLUDE.'/class_impress.php';
-require_once NOALYSS_INCLUDE.'/header_print.php';
-require_once NOALYSS_INCLUDE.'/class_acc_account_ledger.php';
-
-/*!
- * \brief this class handle the different bilan, from the table bilan, parse 
the form and replace
- * in the template
- */
-class Acc_Bilan
-{
-    var $db;                                           /*!< database 
connection */
-    var $b_id;                                 /*!< id of the bilan 
(bilan.b_id) */
-    var $from;                                 /*!< from periode */
-    var $to;                                   /*!< end periode */
-
-    function Acc_Bilan($p_cn)
-    {
-        $this->db=$p_cn;
-    }
-    /*!
-     * \brief return a string with the form for selecting the periode and
-     * the type of bilan
-     * \param $p_filter_year filter on a year
-     *
-     * \return a string
-     */
-    function display_form($p_filter_year="")
-    {
-        $r="";
-        $r.=dossier::hidden();
-        $r.= '<TABLE>';
-
-        $r.='<TR>';
-// filter on the current year
-        $w=new ISelect();
-        $w->table=1;
-
-        $periode_start=$this->db->make_array("select 
p_id,to_char(p_start,'DD-MM-YYYY') from parm_periode $p_filter_year order by 
p_start,p_end");
-
-        $periode_end=$this->db->make_array("select 
p_id,to_char(p_end,'DD-MM-YYYY') from parm_periode $p_filter_year order by 
p_end,p_start");
-
-        $w->label=_("Depuis");
-        $w->value=$this->from;
-        $w->selected=$this->from;
-        $r.= td($w->input('from_periode',$periode_start));
-        $w->label=_(" jusque ");
-        $w->value=$this->to;
-        $w->selected=$this->to;
-        $r.= td($w->input('to_periode',$periode_end));
-        $r.= "</TR>";
-        $r.="<tr>";
-        $mod=new ISelect();
-        $mod->table=1;
-        $mod->value=$this->db->make_array("select b_id, b_name from bilan 
order by b_name");
-        $mod->label=_("Choix du bilan");
-        $r.=td($mod->input('b_id'));
-        $r.="</tr>";
-        $r.= '</TABLE>';
-        return $r;
-    }
-    /**
-     * @brief check and warn if an accound has the wrong saldo
-     * @param $p_message legend of the fieldset
-     * @param $p_type type of the Acccount ACT actif, ACTINV...
-     * @param $p_type the saldo must debit or credit
-     */
-    private function warning($p_message,$p_type,$p_deb)
-    {
-        $sql="select pcm_val,pcm_lib from tmp_pcmn where pcm_type='$p_type'";
-        $res=$this->db->exec_sql($sql);
-        if ( Database::num_row($res) ==0 )
-            return;
-        $count=0;
-        $nRow=Database::num_row($res);
-
-        $ret="";
-        $obj=new Acc_Account_Ledger($this->db,0);
-        for ($i=0;$i<$nRow;$i++)
-        {
-
-            $line=Database::fetch_array($res,$i);
-            /* set the periode filter */
-            
$sql=sql_filter_per($this->db,$this->from,$this->to,'p_id','j_tech_per');
-            $obj->id=$line['pcm_val'];
-
-            $solde=$obj->get_solde_detail($sql);
-            $solde_signed=bcsub($solde['debit'],$solde['credit']);
-
-            if (
-                ($solde_signed < 0 && $p_deb == 'D' ) ||
-                ($solde_signed > 0 && $p_deb == 'C' )
-            )
-            {
-                $ret.= '<li> 
'.HtmlInput::history_account($line['pcm_val'],'Anomalie pour le compte 
'.$line['pcm_val'].' '.h($line['pcm_lib']).
-                       "  D: ".$solde['debit'].
-                       "  C: ".$solde['credit']." diff ".$solde['solde']);
-                $count++;
-            }
-
-        }
-
-        echo '<fieldset>';
-        echo '<legend>'.$p_message.'</legend>';
-        if ( $count <> 0 )
-        {
-            echo '<ol>'.$ret.'</ol>';
-            echo '<span class="error">'._("Nbres anomalies").' : 
'.$count.'</span>';
-        }
-        else
-            echo _("Pas d'anomalie détectée");
-        echo '</fieldset>';
-
-
-    }
-    /*!\brief verify that the saldo is good for the type of account */
-    function verify()
-    {
-               bcscale(2);
-        echo '<h3>'._("Comptes normaux").'</h3>';
-        $this->warning(_('Actif avec un solde crediteur'),'ACT','D');
-        $this->warning(_('Passif avec un solde debiteur'),'PAS','C');
-        $this->warning(_('Compte de resultat : Charge avec un solde 
crediteur'),'CHA','D');
-        $this->warning(_('Compte de resultat : produit avec un solde 
debiteur'),'PRO','C');
-        echo '<hr>';
-        echo '<h3>'._("Comptes inverses").' </h3>';
-        $this->warning(_('Compte inverse : actif avec un solde 
debiteur'),'ACTINV','C');
-        $this->warning(_('Compte inverse : passif avec un solde 
crediteur'),'PASINV','D');
-        $this->warning(_('Compte inverse : Charge avec un solde 
debiteur'),'CHAINV','C');
-        $this->warning(_('Compte inverse : produit avec un solde 
crediteur'),'PROINV','D');
-        echo '<h3'._("Solde").' </h3>';
-        /* set the periode filter */
-        
$sql_periode=sql_filter_per($this->db,$this->from,$this->to,'p_id','j_tech_per');
-        /* debit Actif */
-        $sql="select sum(j_montant) from jrnx join tmp_pcmn on 
(j_poste=pcm_val)".
-             " where j_debit='t' and (pcm_type='ACT' or pcm_type='ACTINV')";
-        $sql.="and $sql_periode";
-        $debit_actif=$this->db->get_value($sql);
-
-        /* Credit Actif */
-        $sql="select sum(j_montant) from jrnx join tmp_pcmn on 
(j_poste=pcm_val)".
-             " where j_debit='f' and (pcm_type='ACT' or pcm_type='ACTINV')";
-
-        $sql.="and $sql_periode";
-
-        $credit_actif=$this->db->get_value($sql);
-        $total_actif=abs(bcsub($debit_actif,$credit_actif));
-        echo '<table >';
-        echo tr(td(_('Total 
actif')).td($total_actif,'style="text-align:right"'));
-
-        /* debit passif */
-        $sql="select sum(j_montant) from jrnx join tmp_pcmn on 
(j_poste=pcm_val)".
-             " where j_debit='t' and (pcm_type='PAS' or pcm_type='PASINV') ";
-        $sql.="and $sql_periode";
-
-        $debit_passif=$this->db->get_value($sql);
-
-        /* Credit Actif */
-        $sql="select sum(j_montant) from jrnx join tmp_pcmn on 
(j_poste=pcm_val)".
-             " where j_debit='f' and (pcm_type='PAS' or pcm_type='PASINV') ";
-        $sql.="and $sql_periode";
-        $credit_passif=$this->db->get_value($sql);
-        $total_passif=abs(bcsub($debit_passif,$credit_passif));
-
-        /* diff actif / passif */
-        echo tr(td(_('Total 
passif')).td($total_passif,'style="text-align:right"'));
-        if ( $total_actif != $total_passif )
-        {
-            $diff=bcsub($total_actif,$total_passif);
-            echo tr(td(' Difference Actif - Passif 
').td($diff,'style="text-align:right"'),'style="font-weight:bolder"');
-        }
-
-        /* debit charge */
-        $sql="select sum(j_montant) from jrnx join tmp_pcmn on 
(j_poste=pcm_val)".
-             " where j_debit='t' and (pcm_type='CHA' or pcm_type='CHAINV')";
-        $sql.="and $sql_periode";
-        $debit_charge=$this->db->get_value($sql);
-
-        /* Credit charge */
-        $sql="select sum(j_montant) from jrnx join tmp_pcmn on 
(j_poste=pcm_val)".
-             " where j_debit='f' and (pcm_type='CHA' or pcm_type='CHAINV')";
-        $sql.="and $sql_periode";
-        $credit_charge=$this->db->get_value($sql);
-        $total_charge=abs(bcsub($debit_charge,$credit_charge));
-        echo tr(td(_('Total charge 
')).td($total_charge,'style="text-align:right"'));
-
-
-        /* debit prod */
-        $sql="select sum(j_montant) from jrnx join tmp_pcmn on 
(j_poste=pcm_val)".
-             " where j_debit='t' and (pcm_type='PRO' or pcm_type='PROINV')";
-        $sql.="and $sql_periode";
-        $debit_pro=$this->db->get_value($sql);
-
-        /* Credit prod */
-        $sql="select sum(j_montant) from jrnx join tmp_pcmn on 
(j_poste=pcm_val)".
-             " where j_debit='f' and (pcm_type='PRO' or pcm_type='PROINV')";
-        $sql.="and $sql_periode";
-        $credit_pro=$this->db->get_value($sql);
-        $total_pro=abs(bcsub($debit_pro,$credit_pro));
-        echo tr(td(_('Total 
produit')).td($total_pro,'style="text-align:right"'));
-
-        $diff=bcsub($total_pro,$total_charge);
-
-        echo tr( td(_("Difference Produit - 
Charge"),'style="padding-right:20px"').td($diff,'style="text-align:right"'),'style="font-weight:bolder"');
-        echo '</table>';
-    }
-    /*!
-     * \brief get data from the $_GET
-     *
-     */
-    function get_request_get()
-    {
-        $this->b_id=(isset($_GET['b_id']))?$_GET['b_id']:"";
-        $this->from=( isset ($_GET['from_periode']))?$_GET['from_periode']:-1;
-        $this->to=( isset ($_GET['to_periode']))?$_GET['to_periode']:-1;
-    }
-    /*!\brief load from the database the document data  */
-    function load()
-    {
-        try
-        {
-            if ( $this->b_id=="")
-                throw new Exception(_("le formulaire id n'est pas donnee"));
-
-            $sql="select b_name,b_file_template,b_file_form,lower(b_type) as 
b_type from bilan where".
-                 " b_id = ".$this->b_id;
-            $res=$this->db->exec_sql($sql);
-
-            if ( Database::num_row($res)==0)
-                throw new Exception (_('Aucun enregistrement trouve'));
-            $array=Database::fetch_array($res,0);
-            foreach ($array as $name=>$value)
-            $this->$name=$value;
-
-        }
-        catch(Exception $Ex)
-        {
-            echo $Ex->getMessage();
-            throw $Ex;
-        }
-    }
-    /*!\brief open the file of the form */
-    /*\return an handle to this file */
-    function file_open_form()
-    {
-        $form=fopen($this->b_file_form,'r');
-        if ( $form == false)
-        {
-            echo 'Cannot Open';
-           throw new Exception(_('Echec ouverture fichier 
'.$this->b_file_form));
-        }
-        return $form;
-    }
-    /*!\brief open the file with the template */
-    /*\return an handle to this file */
-    function file_open_template()
-    {
-        $templ=fopen($this->b_file_template,'r');
-        if ( $templ == false)
-        {
-            echo 'Cannot Open';
-              throw new Exception(_('Echec ouverture fichier 
'.$this->b_file_template));
-        }
-        return $templ;
-
-    }
-    /*!
-     * \brief Compute all the formula
-     * \param $p_handle the handle to the file
-     * \param
-     * \param
-     *
-     *
-     * \return
-     */
-    function compute_formula($p_handle)
-    {
-        while (! feof ($p_handle))
-        {
-            $buffer=trim(fgets($p_handle));
-            // $a=(Impress::check_formula($buffer)  == true)?"$buffer 
ok<br>":'<font color="red">'.'Pas ok '.$buffer."</font><br>";
-            // echo $a;
-            // blank line are skipped
-            if (strlen(trim($buffer))==0)
-                continue;
-            // skip comment
-            if ( strpos($buffer,'#') === true )
-                continue;
-            // buffer contains a formula A$=....
-            // We need to eval it
-            
$a=Impress::parse_formula($this->db,"$buffer",$buffer,$this->from,$this->to,false);
-            $b=str_replace("$","\$this->",$a);
-            if ( eval("$b;") === false )
-                echo_debug(__FILE__,__LINE__,"Code failed with $b");
-
-
-        }// end read form line per line
-    }
-    /*!\brief generate the ods document
-    * \param the handle to the template file
-    * \return the xml
-    address@hidden
-    * Sur une seule ligne il y a plusieurs données, donc il y a plusieurs 
boucles, pour les autres documents
-    * cela devrait être fait aussi, actuellement ces documents, n'acceptent 
qu'une formule par ligne.
-    address@hidden
-    * Pas de header dans les entêtes car n'est pas compris dans le document 
qu'on utilise
-    */
-    function generate_odt()
-    {
-        // create a temp directory in /tmp to unpack file and to parse it
-        $dirname=tempnam($_ENV['TMP'],'bilan_');
-
-
-        unlink($dirname);
-        mkdir ($dirname);
-        chdir($dirname);
-
-        
$file_base=dirname($_SERVER['SCRIPT_FILENAME']).DIRECTORY_SEPARATOR.$this->b_file_template;
-        $work_file=basename($file_base);
-        if ( copy ($file_base,$work_file) == false )
-        {
-            echo _("erreur Ouverture fichier");
-              throw new Exception(_('Echec ouverture fichier '.$file_base));
-        }
-        ob_start();
-       /* unzip the document */
-       $zip = new Zip_Extended;
-       if ($zip->open($work_file) === TRUE)
-         {
-           $zip->extractTo($dirname.DIRECTORY_SEPARATOR);
-           $zip->close();
-         } else
-         {
-           echo __FILE__.":".__LINE__."cannot unzip model ".$filename;
-         }
-
-       ob_end_clean();
-        unlink($work_file);
-        // remove the zip file
-        $p_file=fopen('content.xml','r');
-
-        if ( $p_file == false)
-        {
-             throw new Exception(_('Echec ouverture fichier '.$p_file));
-        }
-
-        $r="";
-        $regex="/&lt;&lt;\\$[A-Z]*[0-9]*&gt;&gt;/";
-        $lt="&lt;";
-        $gt="&gt;";
-       $header_txt=header_txt($this->db);
-
-        while ( !feof($p_file) )
-        {
-            $line_rtf=fgets($p_file);
-
-            /*
-            * replace the header tag, doesn't work if inside header
-            */
-            
$line_rtf=preg_replace('/&lt;&lt;header&gt;&gt;/',$header_txt,$line_rtf);
-
-
-            // the line contains the magic <<
-            $tmp="";
-
-
-           while (preg_match_all($regex,$line_rtf,$f2) > 0 )
-             {
-                // the f2 array contains all the magic << in the line
-                foreach ($f2 as $f2_array)
-                 {
-                   foreach ($f2_array as $f2_str)
-                     {
-                       $to_remove=$f2_str;
-                       $f2_value=str_replace("&lt;","",$f2_str);
-                       $f2_value=str_replace("&gt;","",$f2_value);
-                       $f2_value=str_replace("$","",$f2_value);
-
-
-
-                       // check for missing variables and labels (N vars)
-                       if( ! isset($this->$f2_value))
-                         {
-
-                           $a = "!!".$f2_value."!!";
-                           if( substr($f2_value, 0, 1) == "N" )
-                             {
-                               $ret = $this->db->get_array("SELECT pcm_lib AS 
acct_name FROM tmp_pcmn WHERE pcm_val::text LIKE ".
-                                                           " substr($1, 
2)||'%' ORDER BY pcm_val ASC LIMIT 1",array($f2_value));
-                               if($ret[0]['acct_name'])
-                                 {
-                                   $a = $ret[0]['acct_name'];
-                                   $a=str_replace('<','&lt;',$a);
-                                   $a=str_replace('>','&gt;',$a);
-                                 }
-                             }
-                         }
-                       else
-                         {
-                           $a=$this->$f2_value;
-                         }
-                       if ( $a=='-0' ) $a=0;
-
-                       /*  allow numeric cel in ODT for the formatting and 
formula */
-                       if ( is_numeric($a) )
-                         {
-                           
$searched='office:value-type="string"><text:p>'.$f2_str;
-                           $replaced='office:value-type="float" 
office:value="'.$a.'"><text:p>'.$f2_str;
-                           $line_rtf=str_replace($searched, $replaced, 
$line_rtf);
-                         }
-
-
-                       $line_rtf=str_replace($f2_str,$a,$line_rtf);
-
-                     }// foreach end
-                 } // foreach
-             } // preg_match_all
-            $r.=$line_rtf;
-
-        }// odt file is read
-
-        return $r;
-
-    }
-
-    /*!
-     * \brief generate the plain  file (rtf,txt, or html)
-     * \param the handle to the template file
-     */
-    function generate_plain($p_file)
-    {
-        $r="";
-        if ( $this->b_type=='html')
-        {
-            $lt='&lt;';
-            $gt='&gt;';
-           $pattern='/&lt;&lt;header&gt;&gt;/';
-        }
-        else
-        {
-            $lt='<';
-            $gt='>';
-           $pattern='/<<header>>/';
-        }
-
-       $header_txt=header_txt($this->db);
-
-        while ( !feof($p_file) )
-        {
-            $line_rtf=fgets($p_file);
-
-            $line_rtf=preg_replace($pattern,$header_txt,$line_rtf);
-
-
-            // the line contains the magic <<
-            if 
(preg_match_all("/".$lt.$lt."\\$[a-zA-Z]*[0-9]*".$gt.$gt."/",$line_rtf,$f2) > 0)
-            {
-                // DEBUG
-                //    echo $r.'<br>';
-                // the f2 array contains all the magic << in the line
-                foreach ($f2 as $f2_str)
-                {
-                    // DEBUG
-                    // echo "single_f2 = $f2_str <br>";
-                    // replace single_f2 by its value
-                    $f2_value=str_replace($lt,"",$f2_str);
-                    $f2_value=str_replace($gt,"",$f2_value);
-                    $f2_value=str_replace("$","",$f2_value);
-                   $f2_value=$f2_value[0];
-
-                    // check for missing variables and labels (N vars)
-                    if( ! isset($this->$f2_value))
-                    {
-                        $a = "!!".$f2_value."!!";
-                        if( substr($f2_value, 0, 1) == "N" )
-                        {
-                            $ret = $this->db->get_array("SELECT pcm_lib AS 
acct_name FROM tmp_pcmn WHERE ".
-                                                        " pcm_val::text LIKE 
substr($1, 2)||'%' ORDER BY pcm_val ASC LIMIT 1",
-                                                        array($f2_value));
-                            if($ret[0]['acct_name'])
-                            {
-                                /* for rtf we have the string to put it in 
latin1 */
-                                $a = utf8_decode($ret[0]['acct_name']);
-                            }
-                        }
-                    }
-                    else
-                    {
-                        // DEBUG
-                        //echo "f2_value=$f2_value";
-                        //               $a=${"$f2_value"};
-                        $a=$this->$f2_value;
-                    }
-                    // DEBUG      echo " a = $a";
-                    if ( $a=='-0' ) $a=0;
-                    $line_rtf=str_replace($f2_str,$a,$line_rtf);
-
-                }// foreach end
-            }
-            $r.=$line_rtf;
-
-        }// rtf file is read
-        // DEBUG
-        //  fwrite($out,$r);
-
-        return $r;
-
-
-
-
-    }
-    /*!\brief generate the document and send it to the browser
-     */
-    function generate()
-    {
-        // Load the data
-        $this->load();
-        // Open the files
-        $form=$this->file_open_form();
-
-        // Compute all the formula and add the value to this
-        $this->compute_formula($form);
-        fclose($form);
-        // open the form
-        $templ=$this->file_open_template();
-        switch ($this->b_type)
-        {
-        case 'rtf':
-            $result=$this->generate_plain($templ);
-            $this->send($result);
-            break;
-        case 'txt':
-            $result=$this->generate_plain($templ);
-            $this->send($result);
-        case 'html':
-            $result=$this->generate_plain($templ);
-            $this->send($result);
-
-            break;
-        case 'odt':
-        case 'ods':
-            $result=$this->generate_odt($templ);
-            $this->send($result);
-            break;
-
-        }
-        fclose($templ);
-    }
-    /*!\brief send the result of generate plain to the browser
-     * \param $p_result is the string returned by generate_...
-     */
-    function send($p_result)
-    {
-        switch ($this->b_type)
-        {
-        case 'rtf':
-            // A rtf file is generated
-            header('Content-type: application/rtf');
-            header('Content-Disposition: attachment; 
filename="'.$this->b_name.'.rtf"');
-            echo $p_result;
-            break;
-
-        case 'txt':
-            // A txt file is generated
-            header('Content-type: application/txt');
-            header('Content-Disposition: attachment; 
filename="'.$this->b_name.'.txt"');
-
-            echo $p_result;
-            break;
-        case 'html':
-            // A txt file is generated
-            header('Content-type: application/html');
-            header('Content-Disposition: attachment; 
filename="'.$this->b_name.'.html"');
-
-            echo $p_result;
-            break;
-        case 'odt':
-        case 'ods':
-            header("Pragma: public");
-            header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
-            header("Cache-Control: must-revalidate");
-            if ( $this->b_type == 'odt' )
-            {
-                header('Content-type: 
application/vnd.oasis.opendocument.text');
-                header('Content-Disposition: 
attachment;filename="'.$this->b_name.'.odt"',FALSE);
-            }
-            if ( $this->b_type == 'ods' )
-            {
-                header('Content-type: 
application/vnd.oasis.opendocument.spreadsheet');
-                header('Content-Disposition: 
attachment;filename="'.$this->b_name.'.ods"',FALSE);
-            }
-            
-            header("Accept-Ranges: bytes");
-            ob_start();
-            // save the file in a temp folder
-            // create a temp directory in /tmp to unpack file and to parse it
-            
$dirname=tempnam($_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.'tmp','bilan_');
-
-
-            unlink($dirname);
-            mkdir ($dirname);
-            chdir($dirname);
-            // create a temp directory in /tmp to unpack file and to parse it
-            
$file_base=dirname($_SERVER['SCRIPT_FILENAME']).DIRECTORY_SEPARATOR.$this->b_file_template;
-            $work_file=basename($file_base);
-            if ( copy ($file_base,$work_file) == false )
-            {
-                throw new Exception ( _("Ouverture fichier impossible"));
-            }
-           /*
-            * unzip the document
-            */
-            ob_start();
-           $zip = new Zip_Extended;
-           if ($zip->open($work_file) === TRUE)
-             {
-               $zip->extractTo($dirname.DIRECTORY_SEPARATOR);
-               $zip->close();
-             }
-           else
-             {
-               echo __FILE__.":".__LINE__."cannot unzip model ".$filename;
-             }
-
-            // Remove the file we do  not need anymore
-            unlink ($work_file);
-
-
-            // replace the file
-            $p_file=fopen($dirname.DIRECTORY_SEPARATOR.'content.xml','wb');
-            if ( $p_file == false )
-            {
-                  throw new Exception ( _("erreur Ouverture fichier").' 
content.xml');
-
-            }
-            $a=fwrite($p_file,$p_result);
-            if ( $a==false)
-            {
-                throw new Exception ( _("erreur écriture fichier").' 
content.xml');
-            }
-            // repack
-           $zip = new Zip_Extended;
-            $res = $zip->open($this->b_name.".".$this->b_type, 
ZipArchive::CREATE);
-            if($res !== TRUE)
-             {
-               throw new Exception (__FILE__.":".__LINE__."cannot recreate 
zip");
-             }
-           $zip->add_recurse_folder($dirname.DIRECTORY_SEPARATOR);
-           $zip->close();
-
-            ob_end_clean();
-            fclose($p_file);
-            
$fdoc=fopen($dirname.DIRECTORY_SEPARATOR.$this->b_name.'.'.$this->b_type,'r');
-            if ( $fdoc == false )
-            {
-                  throw new Exception   (_("erreur Ouverture fichier"));
-            }
-            $buffer=fread 
($fdoc,filesize($dirname.DIRECTORY_SEPARATOR.$this->b_name.'.'.$this->b_type));
-            echo $buffer;
-
-            break;
-            // and send
-        }
-
-    }
-    static function test_me()
-    {
-
-        if ( isset($_GET['result']))
-        {
-            ob_start();
-            $cn=new Database(dossier::id());
-            $a=new Acc_Bilan($cn);
-            $a->get_request_get();
-
-            $a->load();
-            $form=$a->file_open_form();
-            $a->compute_formula($form);
-            fclose($form);
-            // open the form
-            $templ=$a->file_open_template();
-            $r=$a->generate_odt($templ);
-            fclose($templ);
-            ob_end_clean();
-
-            $a->send($r);
-        }
-        else
-        {
-            $cn=new Database(dossier::id());
-            $a=new Acc_Bilan($cn);
-            $a->get_request_get();
-
-            echo '<form method="get">';
-            echo $a->display_form();
-           echo 
HtmlInput::hidden('test_select',$_GET['test_select']).dossier::hidden();
-           echo HtmlInput::submit('result','Sauve');
-            echo '</form>';
-        }
-    }
-}
-
diff --git a/include/class_acc_ledger.php b/include/class_acc_ledger.php
deleted file mode 100644
index 5326cf7..0000000
--- a/include/class_acc_ledger.php
+++ /dev/null
@@ -1,3958 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-// Copyright Author Dany De Bontridder address@hidden
-require_once NOALYSS_INCLUDE.'/class_iselect.php';
-require_once NOALYSS_INCLUDE.'/class_icard.php';
-require_once NOALYSS_INCLUDE.'/class_ispan.php';
-require_once NOALYSS_INCLUDE.'/class_ihidden.php';
-require_once NOALYSS_INCLUDE.'/class_idate.php';
-require_once NOALYSS_INCLUDE.'/class_itext.php';
-require_once NOALYSS_INCLUDE.'/class_icheckbox.php';
-require_once NOALYSS_INCLUDE.'/class_iperiod.php';
-require_once NOALYSS_INCLUDE.'/class_fiche.php';
-require_once NOALYSS_INCLUDE.'/class_user.php';
-require_once  NOALYSS_INCLUDE.'/class_dossier.php';
-require_once  NOALYSS_INCLUDE.'/class_anc_operation.php';
-require_once  NOALYSS_INCLUDE.'/class_acc_operation.php';
-require_once  NOALYSS_INCLUDE.'/class_acc_account_ledger.php';
-require_once  NOALYSS_INCLUDE.'/class_pre_op_advanced.php';
-require_once  NOALYSS_INCLUDE.'/class_acc_reconciliation.php';
-require_once  NOALYSS_INCLUDE.'/class_periode.php';
-require_once  NOALYSS_INCLUDE.'/class_gestion_purchase.php';
-require_once  NOALYSS_INCLUDE.'/class_gestion_sold.php';
-require_once  NOALYSS_INCLUDE.'/class_acc_account.php';
-require_once NOALYSS_INCLUDE.'/ac_common.php';
-require_once NOALYSS_INCLUDE.'/class_inum.php';
-require_once NOALYSS_INCLUDE.'/class_lettering.php';
-require_once NOALYSS_INCLUDE.'/class_sort_table.php';
-require_once NOALYSS_INCLUDE.'/class_jrn_def_sql.php';
-require_once NOALYSS_INCLUDE.'/class_acc_payment.php';
-/** \file
- * @brief Class for jrn,  class acc_ledger for manipulating the ledger
- */
-
-/** @brief Class for jrn,  class acc_ledger for manipulating the ledger
- *
- */
-
-class Acc_Ledger extends jrn_def_sql
-{
-
-       var $id;   /**< jrn_def.jrn_def_id */
-       var $name;   /**< jrn_def.jrn_def_name */
-       var $db;   /**< database connextion */
-       var $row;   /**< row of the ledger */
-       var $type;   /**< type of the ledger ACH ODS FIN
-         VEN or GL */
-       var $nb;   /**< default number of rows by
-         default 10 */
-
-       /**
-        * @param $p_cn database connexion
-        * @param $p_id jrn.jrn_def_id
-        */
-       function __construct($p_cn, $p_id)
-       {
-               $this->id = $p_id;
-               $this->name = &$this->jrn_def_name;
-               $this->jrn_def_id = &$this->id;
-               $this->db = $p_cn;
-               $this->row = null;
-               $this->nb = MAX_ARTICLE;
-       }
-
-       function get_last_pj()
-       {
-               if ($this->db->exist_sequence("s_jrn_pj" . $this->id))
-               {
-                       $ret = $this->db->get_array("select 
last_value,is_called from s_jrn_pj" . $this->id);
-                       $last = $ret[0]['last_value'];
-                       /**
-                        * \note  With PSQL sequence , the last_value column is 
1 when before   AND after the first call, to make the difference between them
-                        * I have to check whether the sequence has been 
already called or not */
-                       if ($ret[0]['is_called'] == 'f')
-                               $last--;
-                       return $last;
-               }
-               else
-                       $this->db->create_sequence("s_jrn_pj" . $this->id);
-               return 0;
-       }
-
-       /**
-        * @brief Return the type of a ledger (ACH,VEN,ODS or FIN) or GL
-        *
-        */
-
-       function get_type()
-       {
-               if ($this->id == 0)
-               {
-                       $this->name = _(" Tous les journaux");
-                       $this->type = "GL";
-                       return "GL";
-               }
-
-               $Res = $this->db->exec_sql("select jrn_def_type from " .
-                               " jrn_def where jrn_def_id=" .
-                               $this->id);
-               $Max = Database::num_row($Res);
-               if ($Max == 0)
-                       return null;
-               $ret = Database::fetch_array($Res, 0);
-               $this->type = $ret['jrn_def_type'];
-               return $ret['jrn_def_type'];
-       }
-
-       /**
-        * let you delete a operation
-        * @note by cascade it will delete also in
-        * - jrnx
-        * - stock
-        * - quant_purchase
-        * - quant_fin
-        * - quant_sold
-        * - operation_analytique
-        * - letter
-        * - reconciliation
-        * @bug the attached document is not deleted
-         * @bug Normally it should be named delete_operation, cause the id is 
the ledger_id
-         * (jrn_def_id) and not the operation id
-        */
-       function delete()
-       {
-               if ($this->id == 0)
-                       return;
-               $grpt_id = $this->db->get_value('select jr_grpt_id from jrn 
where jr_id=$1', array($this->jr_id));
-               if ($this->db->count() == 0)
-                       return;
-               $this->db->exec_sql('delete from jrnx where j_grpt=$1', 
array($grpt_id));
-               $this->db->exec_sql('delete from jrn where jr_id=$1', 
array($this->jr_id));
-       }
-
-       /**
-        * Display warning contained in an array
-        * @return string with error message
-        */
-       function display_warning($pa_msg, $p_warning)
-       {
-               $str = '<p class="notice"> ' . $p_warning;
-               $str.="<ol class=\"notice\">";
-               for ($i = 0; $i < count($pa_msg); $i++)
-               {
-                       $str.="<li>" . $pa_msg[$i] . "</li>";
-               }
-               $str.='</ol>';
-               $str.='</p>';
-               return $str;
-       }
-
-       /**
-        * reverse the operation by creating the opposite one,
-        * the result is to avoid it
-        * it must be done in
-        * - jrn
-        * - jrnx
-        * - quant_fin
-        * - quant_sold
-        * - quant_purchase
-        * - stock
-        * - ANC
-        * @param $p_date is the date of the reversed op
-        * @exception if date is invalid or other prob
-        * @note automatically create a reconciliation between operation
-        * You must set the ledger_id $this->jrn_def_id
-         * This function should be in operation or call an acc_operation object
-         * 
-        */
-       function reverse($p_date)
-       {
-               global $g_user;
-               try
-               {
-                       $this->db->start();
-                       if (!isset($this->jr_id) || $this->jr_id == '')
-                               throw new Exception(_("this->jr_id is not set 
ou opération inconnue"));
-
-                       /* check if the date is valid */
-                       if (isDate($p_date) == null)
-                               throw new Exception(_('Date invalide') . 
$p_date);
-
-                       // if the operation is in a closed or centralized period
-                       // the operation is voided thanks the opposite operation
-                       $grp_new = $this->db->get_next_seq('s_grpt');
-                       $seq = $this->db->get_next_seq("s_jrn");
-                       $p_internal = $this->compute_internal_code($seq);
-                       $this->jr_grpt_id = $this->db->get_value('select 
jr_grpt_id from jrn where jr_id=$1', array($this->jr_id));
-                       if ($this->db->count() == 0)
-                               throw new Exception(_("Cette opération n'existe 
pas"));
-                       $this->jr_internal = $this->db->get_value('select 
jr_internal from jrn where jr_id=$1', array($this->jr_id));
-                       if ($this->db->count() == 0 || trim($this->jr_internal) 
== '')
-                               throw new Exception(_("Cette opération n'existe 
pas"));
-
-                       /* find the periode thanks the date */
-                       $per = new Periode($this->db);
-                       $per->jrn_def_id = $this->id;
-                       $per->find_periode($p_date);
-
-                       if ($per->is_open() == 0)
-                               throw new Exception(_('PERIODE FERMEE'));
-
-
-
-
-
-                       // Mark the operation invalid into the ledger
-                       // to avoid to nullify twice the same op.
-                       $sql = "update jrn set jr_comment='extourne : 
'||jr_comment where jr_id=$1";
-                       $Res = $this->db->exec_sql($sql, array($this->jr_id));
-
-                       // Check return code
-                       if ($Res == false)
-                               throw new Exception(__FILE__ . __LINE__ . "sql 
a echoue [ $sql ]");
-
-                       //////////////////////////////////////////////////
-                       // Reverse in jrnx* tables
-                       //////////////////////////////////////////////////
-                       $a_jid = $this->db->get_array("select j_id,j_debit from 
jrnx where j_grpt=$1", array($this->jr_grpt_id));
-                       for ($l = 0; $l < count($a_jid); $l++)
-                       {
-                               $row = $a_jid[$l]['j_id'];
-                               // Make also the change into jrnx
-                               $sql = "insert into jrnx (
-                  j_date,j_montant,j_poste,j_grpt,
-                  
j_jrn_def,j_debit,j_text,j_internal,j_tech_user,j_tech_per,j_qcode
-                  ) select to_date($1,'DD.MM.YYYY'),j_montant,j_poste,$2,
-                  j_jrn_def,not (j_debit),j_text,$3,$4,$5,
-                  j_qcode
-                  from
-                  jrnx
-                  where   j_id=$6 returning j_id";
-                               $Res = $this->db->exec_sql($sql, array($p_date, 
$grp_new, $p_internal, $g_user->id, $per->p_id, $row));
-                               // Check return code
-                               if ($Res == false)
-                                       throw (new Exception(__FILE__ . 
__LINE__ . "SQL ERROR [ $sql ]"));
-                               $aj_id = $this->db->fetch(0);
-                               $j_id = $aj_id['j_id'];
-
-                               /* automatic lettering */
-                               $let = new Lettering($this->db);
-                               $let->insert_couple($j_id, $row);
-
-                               // reverse in QUANT_SOLD
-                               $Res = $this->db->exec_sql("INSERT INTO 
quant_sold(
-                                     qs_internal, qs_fiche, qs_quantite, 
qs_price, qs_vat,
-                                     qs_vat_code, qs_client, qs_valid, j_id)
-                                     SELECT $1, qs_fiche, qs_quantite*(-1), 
qs_price*(-1), qs_vat*(-1),
-                                     qs_vat_code, qs_client, qs_valid, $2
-                                     FROM quant_sold where j_id=$3", 
array($p_internal, $j_id, $row));
-
-                               if ($Res == false)
-                                       throw new Exception(__FILE__ . __LINE__ 
. "sql a echoue [ $sql ]");
-                               $Res = $this->db->exec_sql("INSERT INTO 
quant_purchase(
-                                     qp_internal, j_id, qp_fiche, qp_quantite, 
qp_price, qp_vat,
-                                     qp_vat_code, qp_nd_amount, qp_nd_tva, 
qp_nd_tva_recup, qp_supplier,
-                                     qp_valid, qp_dep_priv)
-                                     SELECT  $1, $2, qp_fiche, 
qp_quantite*(-1), qp_price*(-1), qp_vat*(-1),
-                                     qp_vat_code, qp_nd_amount*(-1), 
qp_nd_tva*(-1), qp_nd_tva_recup*(-1), qp_supplier,
-                                     qp_valid, qp_dep_priv*(-1)
-                                     FROM quant_purchase where j_id=$3", 
array($p_internal, $j_id, $row));
-
-                               if ($Res == false)
-                                       throw new Exception(__FILE__ . __LINE__ 
. "SQL ERROR [ $sql ]");
-                       }
-                       $sql = "insert into jrn (
-              jr_id,
-              jr_def_id,
-              jr_montant,
-              jr_comment,
-              jr_date,
-              jr_grpt_id,
-              jr_internal
-              ,jr_tech_per, jr_valid
-              )
-              select $1,jr_def_id,jr_montant,jr_comment,
-              to_date($2,'DD.MM.YYYY'),$3,$4,
-              $5, true
-              from
-              jrn
-              where   jr_id=$6";
-                               $Res = $this->db->exec_sql($sql, array($seq, 
$p_date, $grp_new, $p_internal, $per->p_id, $this->jr_id));
-                               // Check return code
-                               if ($Res == false)
-                                       throw (new Exception(__FILE__ . 
__LINE__ . "SQL ERROR [ $sql ]"));
-                       // reverse in QUANT_FIN table
-                       $Res = $this->db->exec_sql("  INSERT INTO quant_fin(
-                                 qf_bank,  qf_other, qf_amount,jr_id)
-                                 SELECT  qf_bank,  qf_other, qf_amount*(-1),$1
-                                 FROM quant_fin where jr_id=$2", array($seq, 
$this->jr_id));
-                       if ($Res == false)
-                               throw (new Exception(__FILE__ . __LINE__ . "SQL 
ERROR[ $sql ]"));
-
-                       // Add a "concerned operation to bound these op.together
-                       //
-        $rec = new Acc_Reconciliation($this->db);
-                       $rec->set_jr_id($seq);
-                       $rec->insert($this->jr_id);
-
-                       // Check return code
-                       if ($Res == false)
-                       {
-                               throw (new Exception(__FILE__ . __LINE__ . "SQL 
ERROR [ $sql ]"));
-                       }
-
-
-
-                       // the table stock must updated
-                       // also in the stock table
-                       $sql = "delete from stock_goods where sg_id = any ( 
select sg_id
-             from stock_goods natural join jrnx  where j_grpt=" . 
$this->jr_grpt_id . ")";
-                       $Res = $this->db->exec_sql($sql);
-                       if ($Res == false)
-                               throw (new Exception(__FILE__ . __LINE__ . "SQL 
ERROR [ $sql ]"));
-                        $this->db->commit();
-               }
-               catch (Exception $e)
-               {
-                       $this->db->rollback();
-                       throw $e;
-               }
-       }
-
-       /**
-        * @brief Return the name of a ledger
-        *
-        */
-
-       function get_name()
-       {
-               if ($this->id == 0)
-               {
-                       $this->name = _("Grand Livre");
-                       return $this->name;
-               }
-
-               $Res = $this->db->exec_sql("select jrn_def_name from " .
-                               " jrn_def where jrn_def_id=$1", 
array($this->id));
-               $Max = Database::num_row($Res);
-               if ($Max == 0)
-                       return null;
-               $ret = Database::fetch_array($Res, 0);
-               $this->name = $ret['jrn_def_name'];
-               return $ret['jrn_def_name'];
-       }
-
-       /** \function  get_row
-        * @brief  Get The data
-        *
-        *
-        * @paramp_from from periode
-        * @paramp_to to periode
-        * @paramp_limit starting line
-        * @paramp_offset number of lines
-        * \return Array with the asked data
-        *
-        */
-
-       function get_row($p_from, $p_to, $p_limit = -1, $p_offset = -1)
-       {
-               global $g_user;
-               $periode = sql_filter_per($this->db, $p_from, $p_to, 'p_id', 
'jr_tech_per');
-
-               $cond_limite = ($p_limit != -1) ? " limit " . $p_limit . " 
offset " . $p_offset : "";
-               // retrieve the type
-               $this->get_type();
-               // Grand livre == 0
-               if ($this->id != 0)
-               {
-                       $Res = $this->db->exec_sql("select jr_id,j_id,j_id as 
int_j_id,to_char(j_date,'DD.MM.YYYY') as j_date,
-                                     jr_internal,
-                                     case j_debit when 't' then 
j_montant::text else '   ' end as deb_montant,
-                                     case j_debit when 'f' then 
j_montant::text else '   ' end as cred_montant,
-                                     j_debit as debit,j_poste as 
poste,jr_montant , " .
-                                       "case when j_text='' or j_text is null 
then pcm_lib else j_text end as description,j_grpt as grp,
-                                     jr_comment||' ('||jr_internal||')'  as 
jr_comment,
-                                    jr_pj_number,
-                                     j_qcode,
-                                     jr_rapt as oc, j_tech_per as periode
-                                     from jrnx left join jrn on " .
-                                       "jr_grpt_id=j_grpt " .
-                                       " left join tmp_pcmn on pcm_val=j_poste 
" .
-                                       " where j_jrn_def=" . $this->id .
-                                       " and " . $periode . " order by 
j_date::date asc,substring(jr_pj_number,'[0-9]+$')::numeric asc,j_grpt,j_debit 
desc " .
-                                       $cond_limite);
-               }
-               else
-               {
-                       $Res = $this->db->exec_sql("select jr_id,j_id,j_id as 
int_j_id,to_char(j_date,'DD.MM.YYYY') as j_date,
-                                     jr_internal,
-                                     case j_debit when 't' then 
j_montant::text else '   ' end as deb_montant,
-                                     case j_debit when 'f' then 
j_montant::text else '   ' end as cred_montant,
-                                     j_debit as debit,j_poste as poste," .
-                                       "case when j_text='' or j_text is null 
then pcm_lib else j_text end as description,j_grpt as grp,
-                                     jr_comment||' ('||jr_internal||')' as 
jr_comment,
-                                    jr_pj_number,
-                                     jr_montant,
-                                     j_qcode,
-                                     jr_rapt as oc, j_tech_per as periode from 
jrnx left join jrn on " .
-                                       "jr_grpt_id=j_grpt left join tmp_pcmn 
on pcm_val=j_poste
-                                                                               
 join jrn_def on (jr_def_id=jrn_def_id)
-                                                                               
 where " .
-                                       $g_user->get_ledger_sql() . " and " .
-                                       "  " . $periode . " order by 
j_date::date,substring(jr_pj_number,'[0-9]+$') asc,j_grpt,j_debit desc   " .
-                                       $cond_limite);
-               }
-
-
-               $array = array();
-               $Max = Database::num_row($Res);
-               if ($Max == 0)
-                       return null;
-               $case = "";
-               $tot_deb = 0;
-               $tot_cred = 0;
-               $row = Database::fetch_all($Res);
-               for ($i = 0; $i < $Max; $i++)
-               {
-                       $fiche = new Fiche($this->db);
-                       $line = $row[$i];
-                       $mont_deb = ($line['deb_montant'] != 0) ? sprintf("% 
8.2f", $line['deb_montant']) : "";
-                       $mont_cred = ($line['cred_montant'] != 0) ? sprintf("% 
8.2f", $line['cred_montant']) : "";
-                       $jr_montant = ($line['jr_montant'] != 0) ? sprintf("% 
8.2f", $line['jr_montant']) : "";
-                       $tot_deb+=$line['deb_montant'];
-                       $tot_cred+=$line['cred_montant'];
-                       $tot_op = $line['jr_montant'];
-
-                       /* Check first if there is a quickcode */
-                       if (strlen(trim($line['description'])) == 0 && 
strlen(trim($line['j_qcode'])) != 0)
-                       {
-                               if ($fiche->get_by_qcode($line['j_qcode'], 
false) == 0)
-                               {
-                                       $line['description'] = 
$fiche->strAttribut(ATTR_DEF_NAME);
-                               }
-                       }
-                       if ($case != $line['grp'])
-                       {
-                               $case = $line['grp'];
-                               // for financial, we show if the amount is or 
not in negative
-                               if ($this->type == 'FIN')
-                               {
-                                       $amount = $this->db->get_value('select 
qf_amount from quant_fin where jr_id=$1', array($line['jr_id']));
-                                       /*  if nothing is found */
-                                       if ($this->db->count() == 0)
-                                               $tot_op = $jr_montant;
-                                       else if ($amount < 0)
-                                       {
-                                               $tot_op = $amount;
-                                       }
-                               }
-                               $array[] = array(
-                                       'jr_id' => $line['jr_id'],
-                                       'int_j_id' => $line['int_j_id'],
-                                       'j_id' => $line['j_id'],
-                                       'j_date' => $line['j_date'],
-                                       'internal' => $line['jr_internal'],
-                                       'deb_montant' => '',
-                                       'cred_montant' => ' ',
-                                       'description' => '<b><i>' . 
h($line['jr_comment']) . ' [' . $tot_op . '] </i></b>',
-                                       'poste' => $line['oc'],
-                                       'qcode' => $line['j_qcode'],
-                                       'periode' => $line['periode'],
-                                       'jr_pj_number' => $line 
['jr_pj_number']);
-
-                               $array[] = array(
-                                       'jr_id' => '',
-                                       'int_j_id' => $line['int_j_id'],
-                                       'j_id' => '',
-                                       'j_date' => '',
-                                       'internal' => '',
-                                       'deb_montant' => $mont_deb,
-                                       'cred_montant' => $mont_cred,
-                                       'description' => $line['description'],
-                                       'poste' => $line['poste'],
-                                       'qcode' => $line['j_qcode'],
-                                       'periode' => $line['periode'],
-                                       'jr_pj_number' => ''
-                               );
-                       }
-                       else
-                       {
-                               $array[] = array(
-                                       'jr_id' => $line['jr_id'],
-                                       'int_j_id' => $line['int_j_id'],
-                                       'j_id' => '',
-                                       'j_date' => '',
-                                       'internal' => '',
-                                       'deb_montant' => $mont_deb,
-                                       'cred_montant' => $mont_cred,
-                                       'description' => $line['description'],
-                                       'poste' => $line['poste'],
-                                       'qcode' => $line['j_qcode'],
-                                       'periode' => $line['periode'],
-                                       'jr_pj_number' => '');
-                       }
-               }
-               $this->row = $array;
-               $a = array($array, $tot_deb, $tot_cred);
-               return $a;
-       }
-
-       /** @brief  Get simplified row from ledger
-        *
-        * @param p_from periode
-        * @param p_to periode
-        * @param p_limit starting line
-        * @param p_offset number of lines
-        * @param trunc if data must be truncated (pdf export)
-        *
-        * \return an Array with the asked data
-        */
-
-       function get_rowSimple($p_from, $p_to, $trunc = 0, $p_limit = -1, 
$p_offset = -1)
-       {
-               global $g_user;
-               // Grand-livre : id= 0
-               //---
-               $jrn = ($this->id == 0 ) ? "and " . $g_user->get_ledger_sql() : 
"and jrn_def_id = " . $this->id;
-
-               $periode = sql_filter_per($this->db, $p_from, $p_to, 'p_id', 
'jr_tech_per');
-
-               $cond_limite = ($p_limit != -1) ? " limit " . $p_limit . " 
offset " . $p_offset : "";
-               //---
-               $sql = "
-             SELECT jrn.jr_id as jr_id ,
-             jrn.jr_id as num ,
-             jrn.jr_def_id as jr_def_id,
-             jrn.jr_montant as montant,
-             substr(jrn.jr_comment,1,35) as comment,
-             to_char(jrn.jr_date,'DD-MM-YYYY') as date,
-             to_char(jrn.jr_date_paid,'DD-MM-YYYY') as date_paid,
-             jr_pj_number,
-             jr_internal,
-             jrn.jr_grpt_id as grpt_id,
-             jrn.jr_pj_name as pj,
-             jrn_def_type,
-             jrn.jr_tech_per
-             FROM jrn join jrn_def on (jrn_def_id=jr_def_id)
-             WHERE $periode $jrn order by 
jr_date,substring(jrn.jr_pj_number,'[0-9]+$')::numeric asc  $cond_limite";
-
-               $Res = $this->db->exec_sql($sql);
-               $Max = Database::num_row($Res);
-               if ($Max == 0)
-               {
-                       return null;
-               }
-               $type = $this->get_type();
-               // for type ACH and Ven we take more info
-               if ($type == 'ACH' || $type == 'VEN')
-               {
-                       $a_ParmCode = $this->db->get_array('select 
p_code,p_value from parm_code');
-                       $a_TVA = $this->db->get_array('select 
tva_id,tva_label,tva_poste
-                                        from tva_rate where tva_rate != 0 
order by tva_rate,tva_label,tva_id ');
-                       for ($i = 0; $i < $Max; $i++)
-                       {
-                               $array[$i] = Database::fetch_array($Res, $i);
-                               $p = $this->get_detail($array[$i], $type, 
$trunc, $a_TVA, $a_ParmCode);
-                               if ($array[$i]['dep_priv'] != 0.0)
-                               {
-                                       $array[$i]['comment'].="(priv. " . 
$array[$i]['dep_priv'] . ")";
-                               }
-                       }
-               }
-               else
-               {
-                       $array = Database::fetch_all($Res);
-               }
-
-               return $array;
-       }
-
-// end function get_rowSimple
-
-       /**
-        * @brief guess what  the next pj should be
-        */
-
-       function guess_pj()
-       {
-               $prop = $this->get_propertie();
-               $pj_pref = $prop["jrn_def_pj_pref"];
-               $pj_seq = $this->get_last_pj() + 1;
-               return $pj_pref . $pj_seq;
-       }
-
-       /**
-        * @brief Show all the operation
-        * @param$sql is the sql stmt, normally created by build_search_sql
-        * @param$offset the offset
-        * @param$p_paid if we want to see info about payment
-         @code
-         // Example
-         // Build the sql
-         list($sql,$where)=$Ledger->build_search_sql($_GET);
-         // Count nb of line
-         $max_line=$this->db->count_sql($sql);
-
-         $step=$_SESSION['g_pagesize'];
-         $page=(isset($_GET['offset']))?$_GET['page']:1;
-         $offset=(isset($_GET['offset']))?$_GET['offset']:0;
-         // create the nav. bar
-         $bar=navigation_bar($offset,$max_line,$step,$page);
-         // show a part
-         list($count,$html)= $Ledger->list_operation($sql,$offset,0);
-         echo $html;
-         // show nav bar
-         echo $bar;
-
-         @endcode
-        * @see build_search_sql
-        * @see display_search_form
-        * @see search_form
-
-        * @return HTML string
-        */
-
-       public function list_operation_to_reconcile($sql,$p_target)
-       {
-               global $g_parameter, $g_user;
-               $gDossier = dossier::id();
-               $limit = " LIMIT ".MAX_RECONCILE;
-               // Sort
-               // Count
-               $count = $this->db->count_sql($sql);
-               // Add the limit
-               $sql.=" order by jr_date asc " . $limit;
-
-               // Execute SQL stmt
-               $Res = $this->db->exec_sql($sql);
-
-               //starting from here we can refactor, so that instead of 
returning the generated HTML,
-               //this function returns a tree structure.
-
-               $r = "";
-
-
-               $Max = Database::num_row($Res);
-
-               if ($Max == 0)
-                       return array(0, _("Aucun enregistrement trouvé"));
-                $r.=HtmlInput::hidden("target", $p_target);
-               $r.='<table class="result">';
-
-
-               $r.="<tr >";
-               $r.="<th>"._("Selection")."</th>";
-               $r.="<th>"._("Internal")."</th>";
-
-               if ($this->type == 'ALL')
-               {
-                       $r.=th(_('Journal'));
-               }
-
-               $r.='<th>'._("Date").'</th>';
-               $r.='<th>'._("Pièce").'</td>';
-               $r.=th(_('tiers'));
-               $r.='<th>'._("Description").'</th>';
-               $r.=th(_('Notes'), ' ');
-               $r.='<th>'._("Montant").'</th>';
-               $r.="<th>" . _('Concerne') . "</th>";
-               $r.="</tr>";
-               // Total Amount
-               $tot = 0.0;
-               $gDossier = dossier::id();
-               $str_dossier = Dossier::id();
-               for ($i = 0; $i < $Max; $i++)
-               {
-
-
-                       $row = Database::fetch_array($Res, $i);
-
-                       if ($i % 2 == 0)
-                               $tr = '<TR class="odd">';
-                       else
-                               $tr = '<TR class="even">';
-                       $r.=$tr;
-                       // Radiobox
-                       //
-
-                       $r.='<td><INPUT TYPE="CHECKBOX" name="jr_concerned' . 
$row['jr_id'] . '" ID="jr_concerned' . $row['jr_id'] . '" 
value="'.$row['quick_code'].'"> </td>';
-                       //internal code
-                       // button  modify
-                       $r.="<TD>";
-                       // If url contains
-                       //
-
-            $href = basename($_SERVER['PHP_SELF']);
-
-
-                       $r.=sprintf('<A class="detail" 
style="text-decoration:underline" 
HREF="javascript:modifyOperation(\'%s\',\'%s\')" >%s </A>', $row['jr_id'], 
$gDossier, $row['jr_internal']);
-                       $r.="</TD>";
-                       if ($this->type == 'ALL')
-                               $r.=td($row['jrn_def_name']);
-                       // date
-                       $r.="<TD>";
-                       $r.=$row['str_jr_date'];
-                       $r.="</TD>";
-
-                       // pj
-                       $r.="<TD>";
-                       $r.=$row['jr_pj_number'];
-                       $r.="</TD>";
-
-                       // Tiers
-                       $other = ($row['quick_code'] != '') ? '[' . 
$row['quick_code'] . '] ' . $row['name'] . ' ' . $row['first_name'] : '';
-                       $r.=td($other);
-                       // comment
-                       $r.="<TD>";
-                       $tmp_jr_comment = h($row['jr_comment']);
-                       $r.=$tmp_jr_comment;
-                       $r.="</TD>";
-                       $r.=td(h($row['n_text']), ' style="font-size:0.87em"');
-                       // Amount
-                       // If the ledger is financial :
-                       // the credit must be negative and written in red
-                       $positive = 0;
-
-                       // Check ledger type :
-                       if ($row['jrn_def_type'] == 'FIN')
-                       {
-                               $positive = $this->db->get_value("select 
qf_amount from quant_fin where jr_id=$1", array($row['jr_id']));
-                               if ($this->db->count() != 0)
-                                       $positive = ($positive < 0) ? 1 : 0;
-                       }
-                       $r.="<TD align=\"right\">";
-
-                       $r.=( $positive != 0 ) ? "<font color=\"red\">  - " . 
nbm($row['jr_montant']) . "</font>" : nbm($row['jr_montant']);
-                       $r.="</TD>";
-
-
-
-                       // Rapprochement
-                       $rec = new Acc_Reconciliation($this->db);
-                       $rec->set_jr_id($row['jr_id']);
-                       $a = $rec->get();
-                       $r.="<TD>";
-                       if ($a != null)
-                       {
-
-                               foreach ($a as $key => $element)
-                               {
-                                       $operation = new 
Acc_Operation($this->db);
-                                       $operation->jr_id = $element;
-                                       $l_amount = 
$this->db->get_value("select jr_montant from jrn " .
-                                                       " where 
jr_id=$element");
-                                       $r.= "<A class=\"detail\" 
HREF=\"javascript:modifyOperation('" . $element . "'," . $gDossier . ")\" > " . 
$operation->get_internal() . "[" . nbm($l_amount) . "]</A>";
-                               }//for
-                       }// if ( $a != null ) {
-                       $r.="</TD>";
-
-                       if ($row['jr_valid'] == 'f')
-                       {
-                               $r.="<TD>"._("Opération annulée")."</TD>";
-                       }
-                       // end row
-                       $r.="</tr>";
-               }
-               $r.='</table>';
-               return array($count, $r);
-       }
-
-       /**
-        * @brief Show all the operation
-        * @param$sql is the sql stmt, normally created by build_search_sql
-        * @param$offset the offset
-        * @param$p_paid if we want to see info about payment
-         \code
-         // Example
-         // Build the sql
-         list($sql,$where)=$Ledger->build_search_sql($_GET);
-         // Count nb of line
-         $max_line=$cn->count_sql($sql);
-
-         $step=$_SESSION['g_pagesize'];
-         $page=(isset($_GET['offset']))?$_GET['page']:1;
-         $offset=(isset($_GET['offset']))?$_GET['offset']:0;
-         // create the nav. bar
-         $bar=navigation_bar($offset,$max_line,$step,$page);
-         // show a part
-         list($count,$html)= $Ledger->list_operation($sql,$offset,0);
-         echo $html;
-         // show nav bar
-         echo $bar;
-
-         \endcode
-        * \see build_search_sql
-        * \see display_search_form
-        * \see search_form
-
-        * \return HTML string
-        */
-
-       public function list_operation($sql, $offset, $p_paid = 0)
-       {
-               global $g_parameter, $g_user;
-               bcscale(2);
-               $table = new Sort_Table();
-               $gDossier = dossier::id();
-               $amount_paid = 0.0;
-               $amount_unpaid = 0.0;
-               $limit = ($_SESSION['g_pagesize'] != -1) ? " LIMIT " . 
$_SESSION['g_pagesize'] : "";
-               $offset = ($_SESSION['g_pagesize'] != -1) ? " OFFSET " . 
Database::escape_string($offset) : "";
-               $order = "  order by jr_date_order asc,jr_internal asc";
-               // Sort
-               $url = "?" . CleanUrl();
-               $str_dossier = dossier::get();
-               $table->add(_("Date"), $url, 'order by jr_date 
asc,substring(jr_pj_number,\'[0-9]+$\')::numeric asc', 'order by  jr_date 
desc,substring(jr_pj_number,\'[0-9]+$\')::numeric desc', "da", "dd");
-               $table->add(_('Echeance'), $url, " order by  jr_ech asc", " 
order by  jr_ech desc", 'ea', 'ed');
-               $table->add(_('Paiement'), $url, " order by  jr_date_paid asc", 
" order by  jr_date_paid desc", 'eap', 'edp');
-               $table->add(_('Pièce'), $url, ' order by  
substring(jr_pj_number,\'[0-9]+$\')::numeric asc ', ' order by  
substring(jr_pj_number,\'[0-9]+$\')::numeric desc ', "pja", "pjd");
-               $table->add(_('Tiers'), $url, " order by  name asc", " order by 
 name desc", 'na', 'nd');
-               $table->add(_('Montant'), $url, " order by jr_montant asc", " 
order by jr_montant desc", "ma", "md");
-               $table->add(_("Description"), $url, "order by jr_comment asc", 
"order by jr_comment desc", "ca", "cd");
-
-               $ord = (!isset($_GET['ord'])) ? 'da' : $_GET['ord'];
-               $order = $table->get_sql_order($ord);
-
-               // Count
-               $count = $this->db->count_sql($sql);
-               // Add the limit
-               $sql.=$order . $limit . $offset;
-               // Execute SQL stmt
-               $Res = $this->db->exec_sql($sql);
-
-               //starting from here we can refactor, so that instead of 
returning the generated HTML,
-               //this function returns a tree structure.
-
-               $r = "";
-
-
-               $Max = Database::num_row($Res);
-
-               if ($Max == 0)
-                       return array(0, _("Aucun enregistrement trouvé"));
-
-               $r.='<table class="result">';
-
-
-               $r.="<tr >";
-               $r.="<th>"._("n° interne")."</th>";
-               if ($this->type == 'ALL')
-               {
-                       $r.=th('Journal');
-               }
-               $r.='<th>' . $table->get_header(0) . '</th>';
-               if ($p_paid != 0 ) $r.='<th>' . $table->get_header(1) . '</td>';
-               if ($p_paid != 0 ) $r.='<th>' . $table->get_header(2) . '</th>';
-               $r.='<th>' . $table->get_header(3) . '</th>';
-               $r.='<th>' . $table->get_header(4) . '</th>';
-               $r.='<th>' . $table->get_header(6) . '</th>';
-               $r.=th('Notes', ' style="width:15%"');
-               $r.='<th>' . $table->get_header(5) . '</th>';
-               // if $p_paid is not equal to 0 then we have a paid column
-               if ($p_paid != 0)
-               {
-                       $r.="<th> " . _('Payé') . "</th>";
-               }
-               $r.="<th>" . _('Concerne') . "</th>";
-               $r.="<th>" . _('Document') . "</th>";
-               $r.="</tr>";
-               // Total Amount
-               $tot = 0.0;
-               $gDossier = dossier::id();
-               for ($i = 0; $i < $Max; $i++)
-               {
-
-
-                       $row = Database::fetch_array($Res, $i);
-
-                       if ($i % 2 == 0)
-                               $tr = '<TR class="odd">';
-                       else
-                               $tr = '<TR class="even">';
-                       $r.=$tr;
-                       //internal code
-                       // button  modify
-                       $r.="<TD>";
-                       // If url contains
-                       //
-
-            $href = basename($_SERVER['PHP_SELF']);
-
-
-                       $r.=sprintf('<A class="detail" 
style="text-decoration:underline" 
HREF="javascript:modifyOperation(\'%s\',\'%s\')" >%s </A>', $row['jr_id'], 
$gDossier, $row['jr_internal']);
-                       $r.="</TD>";
-                       if ($this->type == 'ALL')
-                               $r.=td($row['jrn_def_name']);
-                       // date
-                       $r.="<TD>";
-                       $r.=$row['str_jr_date'];
-                       $r.="</TD>";
-                       // echeance
-                       if ($p_paid != 0 )
-                        {
-                            $r.="<TD>";
-                            $r.=$row['str_jr_ech'];
-                            $r.="</TD>";
-                            $r.="<TD>";
-                            $r.=$row['str_jr_date_paid'];
-                            $r.="</TD>";
-                        }
-
-                       // pj
-                       $r.="<TD>";
-                       $r.=$row['jr_pj_number'];
-                       $r.="</TD>";
-
-                       // Tiers
-                       $other = ($row['quick_code'] != '') ? '[' . 
$row['quick_code'] . '] ' . $row['name'] . ' ' . $row['first_name'] : '';
-                       $r.=td($other);
-                       // comment
-                       $r.="<TD>";
-                       $tmp_jr_comment = h($row['jr_comment']);
-                       $r.=$tmp_jr_comment;
-                       $r.="</TD>";
-                       $r.=td(h($row['n_text']), ' style="font-size:0.87em%"');
-                       // Amount
-                       // If the ledger is financial :
-                       // the credit must be negative and written in red
-                       $positive = 0;
-
-                       // Check ledger type :
-                       if ($row['jrn_def_type'] == 'FIN')
-                       {
-                               $positive = $this->db->get_value("select 
qf_amount from quant_fin where jr_id=$1", array($row['jr_id']));
-                               if ($this->db->count() != 0)
-                                       $positive = ($positive < 0) ? 1 : 0;
-                       }
-                       $r.="<TD align=\"right\">";
-                       $t_amount=$row['jr_montant'];
-                       if ($row['total_invoice'] != null && 
$row['total_invoice'] != $row['jr_montant'])
-                               $t_amount=$row['total_invoice'];
-                       $tot = ($positive != 0) ? bcsub($tot , $t_amount ): 
bcadd($tot , $t_amount);
-                       //STAN $positive always == 0
-                       if ($row [ 'jrn_def_type']=='FIN')
-                       {
-                               $r.=( $positive != 0 ) ? "<font color=\"red\">  
- " . nbm($t_amount) . "</font>" : nbm($t_amount);
-                       }
-                       else
-                       {
-                               $r.=( $t_amount <  0 ) ? "<font color=\"red\">  
" . nbm($t_amount) . "</font>" : nbm($t_amount);
-                       }
-                       $r.="</TD>";
-
-
-                       // Show the paid column if p_paid is not null
-                       if ($p_paid != 0)
-                       {
-                               $w = new ICheckBox();
-                               $w->name = "rd_paid" . $row['jr_id'];
-                               $w->selected = ($row['jr_rapt'] == 'paid') ? 
true : false;
-                               // if p_paid == 2 then readonly
-                               $w->readonly = ( $p_paid == 2) ? true : false;
-                               $h = new IHidden();
-                               $h->name = "set_jr_id" . $row['jr_id'];
-                               $r.='<TD>' . $w->input() . $h->input() . 
'</TD>';
-                               if ($row['jr_rapt'] == 'paid')
-                                       
$amount_paid=bcadd($amount_paid,$t_amount);
-                               else
-                                       
$amount_unpaid=bcadd($amount_unpaid,$t_amount);
-                       }
-
-                       // Rapprochement
-                       $rec = new Acc_Reconciliation($this->db);
-                       $rec->set_jr_id($row['jr_id']);
-                       $a = $rec->get();
-                       $r.="<TD>";
-                       if ($a != null)
-                       {
-
-                               foreach ($a as $key => $element)
-                               {
-                                       $operation = new 
Acc_Operation($this->db);
-                                       $operation->jr_id = $element;
-                                       $l_amount = 
$this->db->get_value("select jr_montant from jrn " .
-                                                       " where 
jr_id=$element");
-                                       $r.= "<A class=\"detail\" 
HREF=\"javascript:modifyOperation('" . $element . "'," . $gDossier . ")\" > " . 
$operation->get_internal() . "[" . nbm($l_amount) . "]</A>";
-                               }//for
-                       }// if ( $a != null ) {
-                       $r.="</TD>";
-
-                       if ($row['jr_valid'] == 'f')
-                       {
-                               $r.="<TD>"._("Opération annulée")."</TD>";
-                       }
-                       else
-                       {
-
-                       } // else
-                       //document
-                       if ($row['jr_pj_name'] != "")
-                       {
-                            
$r.='<td>'.HtmlInput::show_receipt_document($row['jr_id']).'</td>';
-                       }
-                       else
-                               $r.="<TD></TD>";
-
-                       // end row
-                       $r.="</tr>";
-               }
-               $amount_paid = round($amount_paid, 4);
-               $amount_unpaid = round($amount_unpaid, 4);
-               $tot = round($tot, 4);
-               $r.="<TR>";
-               $r.='<TD COLSPAN="5">Total</TD>';
-               $r.='<TD ALIGN="RIGHT">' . nbm($tot) . "</TD>";
-               $r.="</tr>";
-               if ($p_paid != 0)
-               {
-                       $r.="<TR>";
-                       $r.='<TD COLSPAN="5">'._("Payé").'</TD>';
-                       $r.='<TD ALIGN="RIGHT">' . nbm($amount_paid) . "</TD>";
-                       $r.="</tr>";
-                       $r.="<TR>";
-                       $r.='<TD COLSPAN="5">'._("Non payé").'</TD>';
-                       $r.='<TD ALIGN="RIGHT">' . nbm($amount_unpaid) . 
"</TD>";
-                       $r.="</tr>";
-               }
-               $r.="</table>";
-
-               return array($count, $r);
-       }
-
-       /**
-        * @brief get_detail gives the detail of row
-        * this array must contains at least the field
-        *       <ul>
-        *       <li> montant</li>
-        *       <li> grpt_id
-        *       </ul>
-        * the following field will be added
-        *       <ul>
-        *       <li> HTVA
-        *       <li> TVAC
-        *       <li> TVA array with
-        *          <ul>
-        *          <li> field 0 idx
-        *          <li> array containing tva_id,tva_label and tva_amount
-        *          </ul>
-        *       </ul>
-        *
-        * @paramp_array the structure is set in get_rowSimple, this array is
-        *        modified,
-        * @param $trunc if the data must be truncated, usefull for pdf export
-        * @paramp_jrn_type is the type of the ledger (ACH or VEN)
-        * @param $a_TVA TVA Array (default null)
-        * @param $a_ParmCode Array (default null)
-        * \return p_array
-        */
-
-       function get_detail(&$p_array, $p_jrn_type, $trunc = 0, $a_TVA = null, 
$a_ParmCode = null)
-       {
-            bcscale(2);
-            
-               if ($a_TVA == null)
-               {
-                       //Load TVA array
-                       $a_TVA = $this->db->get_array('select 
tva_id,tva_label,tva_poste
-                                        from tva_rate where tva_rate != 0 
order by tva_rate,tva_label,tva_id');
-               }
-               if ($a_ParmCode == null)
-               {
-                       //Load Parm_code
-                       $a_ParmCode = $this->db->get_array('select 
p_code,p_value from parm_code');
-               }
-               // init
-               $p_array['client'] = "";
-               $p_array['TVAC'] = 0;
-               $p_array['TVA'] = array();
-               $p_array['AMOUNT_TVA'] = 0.0;
-               $p_array['dep_priv'] = 0;
-               $p_array['dna'] = 0;
-               $p_array['tva_dna'] = 0;
-               $p_array['tva_np'] = 0;
-               $dep_priv = 0.0;
-                
-               //
-               // Retrieve data from jrnx
-               $sql = "select j_id,j_poste,j_montant, j_debit,j_qcode from 
jrnx where " .
-                               " j_grpt=" . $p_array['grpt_id'];
-               $Res2 = $this->db->exec_sql($sql);
-               $data_jrnx = Database::fetch_all($Res2);
-               $c = 0;
-
-               // Parse data from jrnx and fill diff. field
-               foreach ($data_jrnx as $code)
-               {
-                       $idx_tva = 0;
-                       $poste = new Acc_Account_Ledger($this->db, 
$code['j_poste']);
-
-                       // if card retrieve name if the account is not a VAT 
account
-                       if (strlen(trim($code['j_qcode'])) != 0 && 
$poste->isTva() == 0)
-                       {
-                               $fiche = new Fiche($this->db);
-                               $fiche->get_by_qcode(trim($code['j_qcode']), 
false);
-                               $fiche_def_id = $fiche->get_fiche_def_ref_id();
-                               // Customer or supplier
-                               if ($fiche_def_id == FICHE_TYPE_CLIENT ||
-                                               $fiche_def_id == 
FICHE_TYPE_FOURNISSEUR
-                                        ||$fiche_def_id == FICHE_TYPE_ADM_TAX)
-                               {
-                                       $p_array['TVAC'] = $code['j_montant'];
-
-                                       $p_array['client'] = ($trunc == 0) ? 
$fiche->getName() : mb_substr($fiche->getName(), 0, 20);
-                                       $p_array['reversed'] = false;
-                                       if ($fiche_def_id == FICHE_TYPE_CLIENT 
&& $code['j_debit'] == 'f')
-                                       {
-                                               $p_array['reversed'] = true;
-                                               $p_array['TVAC']*=-1;
-                                       }
-                                       if ($fiche_def_id == FICHE_TYPE_ADM_TAX 
&& $code['j_debit'] == 'f')
-                                       {
-                                               $p_array['reversed'] = true;
-                                               $p_array['TVAC']*=-1;
-                                       }
-                                       if ($fiche_def_id == 
FICHE_TYPE_FOURNISSEUR && $code['j_debit'] == 't')
-                                       {
-                                               $p_array['reversed'] = true;
-                                               $p_array['TVAC']*=-1;
-                                       }
-                               }
-                               else
-                               {
-                                       // if we use the ledger ven / ach for 
others card than supplier and customer
-                                       if ($fiche_def_id != FICHE_TYPE_VENTE &&
-                                                       $fiche_def_id != 
FICHE_TYPE_ACH_MAR &&
-                                                       $fiche_def_id != 
FICHE_TYPE_ACH_SER  &&
-                                                       $fiche_def_id != 
FICHE_TYPE_ACH_MAT
-                                           )                                   
             
-                                       {
-                                               $p_array['TVAC'] = 
$code['j_montant'];
-
-                                               $p_array['client'] = ($trunc == 
0) ? $fiche->getName() : mb_substr($fiche->getName(), 0, 20);
-                                               $p_array['reversed'] = false;
-                                               if ($p_jrn_type == 'ACH' && 
$code['j_debit'] == 't')
-                                               {
-                                                       $p_array['reversed'] = 
true;
-                                                       $p_array['TVAC']*=-1;
-                                               }
-                                               if ($p_jrn_type == 'VEN' && 
$code['j_debit'] == 'f')
-                                               {
-                                                       $p_array['reversed'] = 
true;
-                                                       $p_array['TVAC']*=-1;
-                                               }
-                                       }
-                               }
-                       }
-                       // if TVA, load amount, tva id and rate in array
-                       foreach ($a_TVA as $line_tva)
-                       {
-                               list($tva_deb, $tva_cred) = explode(',', 
$line_tva['tva_poste']);
-                               if ($code['j_poste'] == $tva_deb ||
-                                               $code['j_poste'] == $tva_cred)
-                               {
-
-                                       // For the reversed operation
-                                       if ($p_jrn_type == 'ACH' && 
$code['j_debit'] == 'f')
-                                       {
-                                               $code['j_montant'] = -1 * 
$code['j_montant'];
-                                       }
-                                       if ($p_jrn_type == 'VEN' && 
$code['j_debit'] == 't')
-                                       {
-                                               $code['j_montant'] = -1 * 
$code['j_montant'];
-                                       }
-
-                                       
$p_array['AMOUNT_TVA']+=$code['j_montant'];
-
-                                       $p_array['TVA'][$c] = array($idx_tva, 
array($line_tva['tva_id'], $line_tva['tva_label'], $code['j_montant']));
-                                       $c++;
-
-                                       $idx_tva++;
-                               }
-                       }
-
-                       // isDNA
-                       // If operation is reversed then  amount are negatif
-                       /* if ND */
-                       if ($p_array['jrn_def_type'] == 'ACH')
-                       {
-                               $purchase = new Gestion_Purchase($this->db);
-                               $purchase->search_by_jid($code['j_id']);
-                               $purchase->load();
-                               $dep_priv+=$purchase->qp_dep_priv;
-                               $p_array['dep_priv'] = $dep_priv;
-                                
$p_array['dna']=bcadd($p_array['dna'],$purchase->qp_nd_amount);
-                                
$p_array['tva_dna']=bcadd($p_array['tva_dna'],bcadd($purchase->qp_nd_tva,$purchase->qp_nd_tva_recup));
-                                
$p_array['tva_np']=bcadd($purchase->qp_vat_sided,$p_array['tva_np']);
-                       }
-                       if ($p_array['jrn_def_type'] == 'VEN') {
-                            $sold=new gestion_sold($this->db);
-                            $sold->search_by_jid($code['j_id']);
-                            $sold->load();
-                            
$p_array['tva_np']=bcadd($sold->qs_vat_sided,$p_array['tva_np']);
-                        }
-                        
-                        
-               }
-               $p_array['TVAC'] = sprintf('% 10.2f', $p_array['TVAC'] );
-               $p_array['HTVA'] = sprintf('% 10.2f', $p_array['TVAC'] - 
$p_array['AMOUNT_TVA']-$p_array['tva_dna']);
-               $r = "";
-               $a_tva_amount = array();
-               // inline TVA (used for the PDF)
-               foreach ($p_array['TVA'] as $linetva)
-               {
-                       foreach ($a_TVA as $tva)
-                       {
-                               if ($tva['tva_id'] == $linetva[1][0])
-                               {
-                                       $a = $tva['tva_id'];
-                                       $a_tva_amount[$a] = $linetva[1][2];
-                               }
-                       }
-               }
-               foreach ($a_TVA as $line_tva)
-               {
-                       $a = $line_tva['tva_id'];
-                       if (isset($a_tva_amount[$a]))
-                       {
-                               $tmp = sprintf("% 10.2f", $a_tva_amount[$a]);
-                               $r.="$tmp";
-                       }
-                       else
-                               $r.=sprintf("% 10.2f", 0);
-               }
-               $p_array['TVA_INLINE'] = $r;
-
-               return $p_array;
-       }
-
-// retrieve data from jrnx
-       /**
-        * @brief  Get the properties of a journal
-        *
-        * \return an array containing properties
-        *
-        */
-
-       function get_propertie()
-       {
-               if ($this->id == 0)
-                       return;
-
-               $Res = $this->db->exec_sql("select 
jrn_Def_id,jrn_def_name,jrn_def_class_deb,jrn_def_class_cred,jrn_def_type,
-                                 
jrn_deb_max_line,jrn_cred_max_line,jrn_def_ech,jrn_def_ech_lib,jrn_def_code,
-                                 
jrn_def_fiche_deb,jrn_def_fiche_cred,jrn_def_pj_pref
-                                 from jrn_Def
-                                 where jrn_def_id=$1", array($this->id));
-               $Count = Database::num_row($Res);
-               if ($Count == 0)
-               {
-                       echo '<DIV="redcontent"><H2 class="error">' . 
_('Parametres journaux non trouves') . '</H2> </DIV>';
-                       return null;
-               }
-               return Database::fetch_array($Res, 0);
-       }
-
-       /** \function GetDefLine
-        * @brief Get the number of lines of a journal
-        * @param$p_cred deb or cred
-        *
-        * \return an integer
-        */
-
-       function GetDefLine()
-       {
-               $sql_cred = 'jrn_deb_max_line';
-               $sql = "select jrn_deb_max_line as value from jrn_def where 
jrn_def_id=$1";
-               $r = $this->db->exec_sql($sql, array($this->id));
-               $Res = Database::fetch_all($r);
-               if (sizeof($Res) == 0)
-                       return 1;
-               return $Res[0]['value'];
-       }
-
-       /**
-        * @brief get the saldo of a ledger for a specific period
-        * @param$p_from start period
-        * @param$p_to end period
-        */
-
-       function get_solde($p_from, $p_to)
-       {
-               $ledger = "";
-               if ($this->id != 0)
-               {
-                       $ledger = " and j_jrn_def = " . $this->id;
-               }
-
-               $periode = sql_filter_per($this->db, $p_from, $p_to, 'p_id', 
'j_tech_per');
-               $sql = 'select j_montant as montant,j_debit as deb from jrnx 
where '
-                               . $periode . $ledger;
-
-               $ret = $this->db->exec_sql($sql);
-               $array = Database::fetch_all($ret);
-               $deb = 0.0;
-               $cred = 0.0;
-               foreach ($array as $line)
-               {
-
-                       if ($line['deb'] == 't')
-                               $deb+=$line['montant'];
-                       else
-                               $cred+=$line['montant'];
-               }
-               $response = array($deb, $cred);
-               return $response;
-       }
-
-       /**
-        * @brief Show a select list   of the ledgers you can access in
-        * writing, reading or simply accessing.
-        * @param$p_type = ALL or the type of the ledger (ACH,VEN,FIN,ODS)
-        * @param$p_access =3 for READ and WRITE, 2 for write and 1 for readonly
-        * \return     object HtmlInput select
-        */
-
-       function select_ledger($p_type = "ALL", $p_access = 3)
-       {
-               global $g_user;
-               $array = $g_user->get_ledger($p_type, $p_access);
-
-               if ($array == null)
-                       return null;
-               $idx = 0;
-               $ret = array();
-
-               foreach ($array as $value)
-               {
-                       $ret[$idx]['value'] = $value['jrn_def_id'];
-                       $ret[$idx]['label'] = h($value['jrn_def_name']);
-                       $idx++;
-               }
-
-               $select = new ISelect();
-               $select->name = 'p_jrn';
-               $select->value = $ret;
-               $select->selected = $this->id;
-               return $select;
-       }
-
-       /**
-        * @brief retrieve the jrn_def_fiche and return them into a array
-        *        index deb, cred
-        * \param
-        * \param
-        * \param
-        *
-        *
-        * \return return an array ('deb'=> ,'cred'=>)
-        */
-
-       function get_fiche_def()
-       {
-               $sql = "select jrn_def_fiche_deb as deb,jrn_def_fiche_cred as 
cred " .
-                               " from jrn_def where " .
-                               " jrn_def_id = $1 ";
-
-               $r = $this->db->exec_sql($sql, array($this->id));
-
-               $res = Database::fetch_all($r);
-               if (empty($res))
-                       return null;
-
-               return $res[0];
-       }
-
-       /**
-        * @brief retrieve the jrn_def_class_deb and return it
-        *
-        *
-        * \return return an string
-        */
-
-       function get_class_def()
-       {
-               $sql = "select jrn_def_class_deb  " .
-                               " from jrn_def where " .
-                               " jrn_def_id = $1";
-
-               $r = $this->db->exec_sql($sql, array($this->id));
-
-               $res = Database::fetch_all($r);
-
-               if (empty($res))
-                       return null;
-
-               return $res[0];
-       }
-
-       /**
-        * @brief show the result of the array to confirm
-        * before inserting
-        * @param$p_array array from the form
-        * \return string
-        */
-
-       function confirm($p_array, $p_readonly = false)
-       {
-               global $g_parameter;
-               $msg = array();
-               if (!$p_readonly)
-                       $msg = $this->verify($p_array);
-               $this->id = $p_array['p_jrn'];
-               if (empty($p_array))
-                       return 'Aucun r&eacute;sultat';
-               $anc = null;
-               extract($p_array);
-               $lPeriode = new Periode($this->db);
-               if ($this->check_periode() == true)
-               {
-                       $lPeriode->p_id = $period;
-               }
-               else
-               {
-                       $lPeriode->find_periode($e_date);
-               }
-               $total_deb = 0;
-               $total_cred = 0;
-               bcscale(2);
-
-               $ret = "";
-               if (!empty($msg))
-               {
-                       $ret.=$this->display_warning($msg, _("Attention : il 
vaut mieux utiliser les fiches que les postes comptables"));
-               }
-               $ret.="<table >";
-               $ret.="<tr><td>" . _('Date') . " : </td><td>$e_date</td></tr>";
-               /* display periode */
-               $date_limit = $lPeriode->get_date_limit();
-               $ret.='<tr> ' . td(_('Période Comptable')) . 
td($date_limit['p_start'] . '-' . $date_limit['p_end']) . '</tr>';
-               $ret.="<tr><td>" . _('Libellé') . " </td><td>" . h($desc) . 
"</td></tr>";
-               $ret.="<tr><td>" . _('PJ Num') . " </td><td>" . h($e_pj) . 
"</td></tr>";
-               $ret.='</table>';
-               $ret.="<table class=\"result\">";
-               $ret.="<tr>";
-               $ret.="<th>" . _('Quick Code ou ');
-               $ret.=_("Poste") . " </th>";
-               $ret.="<th style=\"text-align:left\"> " . _("Libellé") . " 
</th>";
-               $ret.="<th style=\"text-align:right\">" . _("Débit") . "</th>";
-               $ret.="<th style=\"text-align:right\">" . _("Crédit") . "</th>";
-               /* if we use the AC */
-               if ($g_parameter->MY_ANALYTIC != 'nu')
-               {
-                       $anc = new Anc_Plan($this->db);
-                       $a_anc = $anc->get_list();
-                       $x = count($a_anc);
-                       /* set the width of the col */
-                       $ret.='<th colspan="' . $x . '" 
style="width:auto;text-align:center" >' . _('Compt. Analytique') . '</th>';
-
-                       /* add hidden variables pa[] to hold the value of pa_id 
*/
-                       $ret.=Anc_Plan::hidden($a_anc);
-               }
-               $ret.="</tr>";
-
-               $ret.=HtmlInput::hidden('e_date', $e_date);
-               $ret.=HtmlInput::hidden('desc', $desc);
-               $ret.=HtmlInput::hidden('period', $lPeriode->p_id);
-               $ret.=HtmlInput::hidden('e_pj', $e_pj);
-               $ret.=HtmlInput::hidden('e_pj_suggest', $e_pj_suggest);
-               $mt = microtime(true);
-               $ret.=HtmlInput::hidden('mt', $mt);
-               // For predefined operation
-               $ret.=HtmlInput::hidden('e_comm', $desc);
-               $ret.=HtmlInput::hidden('jrn_type', $this->get_type());
-               $ret.=HtmlInput::hidden('p_jrn', $this->id);
-               $ret.=HtmlInput::hidden('nb_item', $nb_item);
-               if ($this->with_concerned == true)
-               {
-                       $ret.=HtmlInput::hidden('jrn_concerned', 
$jrn_concerned);
-               }
-               $ret.=dossier::hidden();
-               $count = 0;
-               for ($i = 0; $i < $nb_item; $i++)
-               {
-                       if ($p_readonly == true)
-                       {
-                               if (!isset(${'qc_' . $i}))
-                                       ${'qc_' . $i} = '';
-                               if (!isset(${'poste' . $i}))
-                                       ${'poste' . $i} = '';
-                               if (!isset(${'amount' . $i}))
-                                       ${'amount' . $i} = '';
-                       }
-                        $class=($i%2==0)?' class="even" ':' class="odd" ';
-                       $ret.="<tr $class> ";
-                       if (trim(${'qc_' . $i}) != "")
-                       {
-                               $oqc = new Fiche($this->db);
-                               $oqc->get_by_qcode(${'qc_' . $i}, false);
-                               $strPoste = $oqc->strAttribut(ATTR_DEF_ACCOUNT);
-                               $ret.="<td>" .
-                                               ${'qc_' . $i} . ' - ' .
-                                               
$oqc->strAttribut(ATTR_DEF_NAME) . HtmlInput::hidden('qc_' . $i, ${'qc_' . $i}) 
.
-                                               '</td>';
-                       }
-
-                       if (trim(${'qc_' . $i}) == "" && trim(${'poste' . $i}) 
!= "")
-                       {
-                               $oposte = new Acc_Account_Ledger($this->db, 
${'poste' . $i});
-                               $strPoste = $oposte->id;
-                               $ret.="<td>" . h(${"poste" . $i} . " - " .
-                                                               
$oposte->get_name()) . HtmlInput::hidden('poste' . $i, ${'poste' . $i}) .
-                                               '</td>';
-                       }
-
-                       if (trim(${'qc_' . $i}) == "" && trim(${'poste' . $i}) 
== "")
-                               continue;
-                       $ret.="<td>" . h(${"ld" . $i}) . HtmlInput::hidden('ld' 
. $i, ${'ld' . $i}) ; 
-                        $ret .=(isset(${"ck$i"})) ? HtmlInput::hidden('ck' . 
$i, ${'ck' . $i}) : "";
-                        $ret .=        "</td>";
-                       if (isset(${"ck$i"}))
-                       {
-                               $ret.="<td class=\"num\">" . nbm(${"amount" . 
$i}) . HtmlInput::hidden('amount' . $i, ${'amount' . $i}) . "</td>" . td("");
-                               $total_deb = bcadd($total_deb, ${'amount' . 
$i});
-                       }
-                       else
-                       {
-                               $ret.=td("") . "<td class=\"num\">" . 
nbm(${"amount" . $i}) . HtmlInput::hidden('amount' . $i, ${'amount' . $i}) . 
"</td>";
-                               $total_cred = bcadd($total_cred, ${"amount" . 
$i});
-                       }
-                       /*$ret.="<td>";
-                       $ret.=(isset(${"ck$i"})) ? HtmlInput::hidden('ck' . $i, 
${'ck' . $i}) : "";
-                       $ret.="</td>";*/
-                       // CA
-
-                       if ($g_parameter->MY_ANALYTIC != 'nu') // use of AA
-                       {
-                               if (preg_match("/^[6,7]+/", $strPoste) == 1)
-                               {
-                                       // show form
-                                       $op = new Anc_Operation($this->db);
-                                       $null = ($g_parameter->MY_ANALYTIC == 
'op') ? 1 : 0;
-                                       $p_array['pa_id'] = $a_anc;
-                                       /* op is the operation it contains 
either a sequence or a jrnx.j_id */
-                                       $ret.=HtmlInput::hidden('op[]=', $i);
-
-                                       $ret.='<td style="text-align:center">';
-                                       $read = ($p_readonly == true) ? 0 : 1;
-                                       $ret.=$op->display_form_plan($p_array, 
$null, $read, $count, round(${'amount' . $i}, 2));
-                                       $ret.='</td>';
-                                       $count++;
-                               }
-                       }
-
-
-
-                       $ret.="</tr>";
-               }
-               $ret.=tr(td('') . td(_('Totaux')) . td($total_deb, 
'class="num"') . td($total_cred, 'class="num"'), 'class="highlight"');
-               $ret.="</table>";
-               if ($g_parameter->MY_ANALYTIC != 'nu' && $p_readonly == false)
-                       $ret.='<input type="button" class="button" value="' . 
_('verifie Imputation Analytique') . '" onClick="verify_ca(\'\');">';
-               return $ret;
-       }
-       function get_min_row()
-       {
-               $row=$this->db->get_value("select jrn_deb_max_line from jrn_def 
where jrn_def_id=$1",array($this->id));
-               return $row;
-       }
-       /**
-        * @brief Show the form to encode your operation
-        * @param$p_array if you correct or use a predef operation (default = 
null)
-        * @param$p_readonly 1 for readonly 0 for writable (default 0)
-        address@hidden if ledger not found
-        * \return a string containing the form
-        */
-
-       function input($p_array = null, $p_readonly = 0)
-       {
-               global $g_parameter, $g_user;
-               $this->nb=$this->get_min_row();
-               if ($p_readonly == 1)
-                       return $this->confirm($p_array);
-
-               if ($p_array != null)
-                       extract($p_array);
-               $add_js = "";
-               if ($g_parameter->MY_PJ_SUGGEST == 'Y')
-               {
-                       $add_js = "update_pj();";
-               }
-               if ($g_parameter->MY_DATE_SUGGEST=='Y')
-               {
-                       $add_js.='get_last_date();';
-               }
-               $add_js.='update_row("quick_item");';
-               $ret = "";
-               if ($g_user->check_action(FICADD) == 1)
-               {
-                       /* Add button */
-                       $f_add_button = new IButton('add_card');
-                       $f_add_button->label = _('Créer une nouvelle fiche');
-                       $f_add_button->set_attribute('ipopup', 'ipop_newcard');
-                       $f_add_button->set_attribute('jrn', $this->id);
-                       $f_add_button->javascript = " 
this.jrn=\$('p_jrn').value;select_card_type(this);";
-                       $f_add_button->input();
-               }
-               $wLedger = $this->select_ledger('ODS', 2);
-               if ($wLedger == null)
-                       throw new Exception(_('Pas de journal disponible'));
-               $wLedger->javascript = 
"onChange='update_name();update_predef(\"ods\",\"t\",\"".$_REQUEST['ac']."\");$add_js'";
-               $label = " Journal " . HtmlInput::infobulle(2);
-
-               $ret.=$label . $wLedger->input();
-
-
-               // Load the javascript
-               //
-        $ret.="<table>";
-               $ret.= '<tr ><td colspan="2" style="width:auto">';
-               $wDate = new IDate('e_date');
-               $wDate->readonly = $p_readonly;
-               $e_date = (isset($e_date) && trim($e_date) != '') ? $e_date : 
'';
-               $wDate->value = $e_date;
-
-               $ret.=_("Date") . ' : ' . $wDate->input();
-               $ret.= '</td>';
-               /* insert periode if needed */
-               // Periode
-               //--
-               if ($this->check_periode() == true)
-               {
-                       $l_user_per = $g_user->get_periode();
-                       $def = (isset($periode)) ? $periode : $l_user_per;
-
-                       $period = new IPeriod("period");
-                       $period->user = $g_user;
-                       $period->cn = $this->db;
-                       $period->value = $def;
-                       $period->type = OPEN;
-                       try
-                       {
-                               $l_form_per = $period->input();
-                       }
-                       catch (Exception $e)
-                       {
-                               if ($e->getCode() == 1)
-                               {
-                                       echo _("Aucune période ouverte");
-                                       exit();
-                               }
-                       }
-                       $label = HtmlInput::infobulle(3);
-                       $f_periode = _("Période comptable") . " $label " . 
$l_form_per;
-                       $ret.=td($f_periode);
-               }
-               $wPJ = new IText('e_pj');
-               $wPJ->readonly = false;
-               $wPJ->size = 10;
-
-               /* suggest PJ ? */
-               $default_pj = '';
-               if ($g_parameter->MY_PJ_SUGGEST == 'Y')
-               {
-                       $default_pj = $this->guess_pj();
-               }
-               $wPJ->value = (isset($e_pj)) ? $e_pj : $default_pj;
-               $ret.= '</tr>';
-               $ret.='<tr >';
-               $ret.='<td colspan="2" style="width:auto"> ' . _('Pièce') . ' : 
' . $wPJ->input();
-               $ret.=HtmlInput::hidden('e_pj_suggest', $default_pj);
-               $ret.= '</tr>';
-               $ret.= '</td>';
-
-               $ret.= '<tr>';
-               $ret.='<td colspan="2" style="width:auto">';
-               $ret.=_('Libellé');
-               $wDescription = new IText('desc');
-               $wDescription->readonly = $p_readonly;
-               $wDescription->size = "50";
-               $wDescription->value = (isset($desc)) ? $desc : '';
-
-               $ret.=$wDescription->input();
-               $ret.= '</td>';
-               $ret.='</tr>';
-
-               $ret.= '</table>';
-               $nb_row = (isset($nb_item) ) ? $nb_item : $this->nb;
-
-               $ret.=HtmlInput::hidden('nb_item', $nb_row);
-               $ret.=dossier::hidden();
-
-               $ret.=dossier::hidden();
-
-               $ret.=HtmlInput::hidden('jrn_type', $this->get_type());
-               $info = HtmlInput::infobulle(0);
-               $info_poste = HtmlInput::infobulle(9);
-               if ($g_user->check_action(FICADD) == 1)
-                       $ret.=$f_add_button->input();
-               $ret.='<table id="quick_item" 
style="position:float;width:100%">';
-               $ret.='<tr>' .
-                               '<th style="text-align:left">Quickcode' . $info 
. '</th>' .
-                               '<th style="text-align:left">' . _('Poste') . 
$info_poste . '</th>' .
-                               '<th style="text-align:left">' . _('Libellé') . 
'</th>' .
-                               '<th style="text-align:left">' . _('Montant') . 
'</th>' .
-                               '<th style="text-align:left">' . _('Débit') . 
'</th>' .
-                               '</tr>';
-
-
-               for ($i = 0; $i < $nb_row; $i++)
-               {
-                       // Quick Code
-                       $quick_code = new ICard('qc_' . $i);
-                       $quick_code->set_dblclick("fill_ipopcard(this);");
-                       $quick_code->set_attribute('ipopup', 'ipopcard');
-
-                       // name of the field to update with the name of the card
-                       $quick_code->set_attribute('label', "ld" . $i);
-
-                       // name of the field to update with the name of the card
-                       $quick_code->set_attribute('typecard', 'filter');
-
-                       // Add the callback function to filter the card on the 
jrn
-                       $quick_code->set_callback('filter_card');
-                       $quick_code->set_function('fill_data');
-                       $quick_code->javascript = sprintf(' 
onchange="fill_data_onchange(\'%s\');" ', $quick_code->name);
-
-                       $quick_code->value = (isset(${'qc_' . $i})) ? ${'qc_' . 
$i} : "";
-                       $quick_code->readonly = $p_readonly;
-                        
-                       $label = '';
-                       if ($quick_code->value != '')
-                       {
-                               $Fiche = new Fiche($this->db);
-                               $Fiche->get_by_qcode($quick_code->value);
-                               $label = $Fiche->strAttribut(ATTR_DEF_NAME);
-                       }
-
-
-                       // Account
-                       $poste = new IPoste();
-                       $poste->name = 'poste' . $i;
-                       $poste->set_attribute('jrn', $this->id);
-                       $poste->set_attribute('ipopup', 'ipop_account');
-                       $poste->set_attribute('label', 'ld' . $i);
-                       $poste->set_attribute('account', 'poste' . $i);
-                       $poste->set_attribute('dossier', Dossier::id());
-
-                       $poste->value = (isset(${'poste' . $i})) ? ${"poste" . 
$i} : ''
-                       ;
-                       $poste->dbl_click_history();
-
-                       $poste->readonly = $p_readonly;
-
-                       if ($poste->value != '')
-                       {
-                               $Poste = new Acc_Account($this->db);
-                               $Poste->set_parameter('value', $poste->value);
-                               $label = $Poste->get_lib();
-                       }
-
-                       // Description of the line
-                       $line_desc = new IText();
-                       $line_desc->name = 'ld' . $i;
-                       $line_desc->size = 30;
-                       $line_desc->value = (isset(${"ld" . $i})) ? ${"ld" . 
$i} :
-                                       $label;
-
-                       // Amount
-                       $amount = new INum();
-                       $amount->size = 10;
-                       $amount->name = 'amount' . $i;
-                       $amount->value = (isset(${'amount' . $i})) ? ${"amount" 
. $i} : ''
-                       ;
-                       $amount->readonly = $p_readonly;
-                       $amount->javascript = ' 
onChange="format_number(this);checkTotalDirect()"';
-                       // D/C
-                       $deb = new ICheckBox();
-                       $deb->name = 'ck' . $i;
-                       $deb->selected = (isset(${'ck' . $i})) ? true : false;
-                       $deb->readonly = $p_readonly;
-                       $deb->javascript = ' onChange="checkTotalDirect()"';
-
-                       $ret.='<tr>';
-                       $ret.='<td>' . $quick_code->input() . 
$quick_code->search() . '</td>';
-                       $ret.='<td>' . $poste->input() .
-                                       '<script> 
document.getElementById(\'poste' . $i . '\').onblur=function(){ if 
(trim(this.value) !=\'\') {document.getElementById(\'qc_' . $i . 
'\').value="";}}</script>' .
-                                       '</td>';
-                       $ret.='<td>' . $line_desc->input() . '</td>';
-                       $ret.='<td>' . $amount->input() . '</td>';
-                       $ret.='<td>' . $deb->input() . '</td>';
-                       $ret.='</tr>';
-                       // If readonly == 1 then show CA
-               }
-               $ret.='</table>';
-               if (isset($this->with_concerned) && $this->with_concerned == 
true)
-               {
-                       $oRapt = new Acc_Reconciliation($this->db);
-                       $w = $oRapt->widget();
-                       $w->name = 'jrn_concerned';
-                       $w->value = (isset($jrn_concerned)) ? $jrn_concerned : 
"";
-                       $ret.="R&eacute;conciliation/rapprochements : " . 
$w->input();
-               }
-               $ret.= create_script("$('".$wDate->id."').focus()");
-               return $ret;
-       }
-
-       /**
-        * @brief
-        * check if the current ledger is closed
-        * \return 1 for yes, otherwise 0
-        * \see Periode::is_closed
-        */
-
-       function is_closed($p_periode)
-       {
-               $per = new Periode($this->db);
-               $per->set_jrn($this->id);
-               $per->set_periode($p_periode);
-               $ret = $per->is_closed();
-               return $ret;
-       }
-
-       /**
-        * @brief verify that the operation can be saved
-        * @param$p_array array of data same layout that the $_POST from 
show_form
-        *
-        *
-        * \throw  the getcode  value is 1 incorrect balance,  2 date
-        * invalid, 3 invalid amount,  4 the card is not in the range of
-        * permitted card, 5 not in the user's period, 6 closed period
-        *
-        */
-
-       function verify($p_array)
-       {
-            if (is_array($p_array ) == false || empty($p_array))
-                    throw new Exception ("Array empty");
-        /*
-         * Check needed value
-         */
-        check_parameter($p_array,'p_jrn,e_date');
-        
-               extract($p_array);
-               global $g_user;
-               $tot_cred = 0;
-               $tot_deb = 0;
-               $msg = array();
-
-               /* check if we can write into this ledger */
-               if ($g_user->check_jrn($p_jrn) != 'W')
-                       throw new Exception(_('Accès interdit'), 20);
-
-               /* check for a double reload */
-               if (isset($mt) && $this->db->count_sql('select jr_mt from jrn 
where jr_mt=$1', array($mt)) != 0)
-                       throw new Exception('Double Encodage', 5);
-
-               // Check the periode and the date
-               if (isDate($e_date) == null)
-               {
-                       throw new Exception('Date invalide', 2);
-               }
-               $periode = new Periode($this->db);
-               /* find the periode  if we have enabled the check_periode */
-               if ($this->check_periode() == false)
-               {
-                       $periode->find_periode($e_date);
-               }
-               else
-               {
-                       $periode->p_id = $period;
-                       list ($min, $max) = $periode->get_date_limit();
-                       if (cmpDate($e_date, $min) < 0 ||
-                                       cmpDate($e_date, $max) > 0)
-                               throw new Exception(_('Date et periode ne 
correspondent pas'), 6);
-               }
-
-
-
-               // Periode ferme
-               if ($this->is_closed($periode->p_id) == 1)
-               {
-                       throw new Exception('Periode fermee', 6);
-               }
-               /* check if we are using the strict mode */
-               if ($this->check_strict() == true)
-               {
-                       /* if we use the strict mode, we get the date of the 
last
-                         operation */
-                       $last_date = $this->get_last_date();
-                       if ($last_date != null && cmpDate($e_date, $last_date) 
< 0)
-                               throw new Exception(_('Vous utilisez le mode 
strict la dernière operation est la date du ')
-                                               . $last_date . ' ' . _('vous ne 
pouvez pas encoder à une date antérieure'), 15);
-               }
-
-               for ($i = 0; $i < $nb_item; $i++)
-               {
-                       $err = 0;
-
-                       // Check the balance
-                       if (!isset(${'amount' . $i}))
-                               continue;
-
-                       $amount = round(${'amount' . $i}, 2);
-                       $tot_deb+=(isset(${'ck' . $i})) ? $amount : 0;
-                       $tot_cred+=(!isset(${'ck' . $i})) ? $amount : 0;
-
-                       // Check if the card is permitted
-                       if (isset(${'qc_' . $i}) && trim(${'qc_' . $i}) != "")
-                       {
-                               $f = new Fiche($this->db);
-                               $f->quick_code = ${'qc_' . $i};
-                               if ($f->belong_ledger($p_jrn) < 0)
-                                       throw new Exception("La fiche 
quick_code = " .
-                                                       $f->quick_code . " 
n'est pas dans ce journal", 4);
-                               if (strlen(trim(${'qc_' . $i})) != 0 && 
isNumber(${'amount' . $i}) == 0)
-                                       throw new Exception('Montant invalide', 
3);
-
-                               $strPoste = $f->strAttribut(ATTR_DEF_ACCOUNT);
-                               if ($strPoste == '')
-                                       throw new Exception(sprintf(_("La fiche 
%s n'a pas de poste comptable"), ${"qc_" . $i}));
-
-                               $p = new Acc_Account_Ledger($this->db, 
$strPoste);
-                               if ($p->do_exist() == 0)
-                                       throw new Exception(_('Poste Inexistant 
pour la fiche [' . ${'qc_' . $i} . ']'), 4);
-                       }
-
-                       // Check if the account is permitted
-                       if (isset(${'poste' . $i}) && strlen(trim(${'poste' . 
$i})) != 0)
-                       {
-                               $p = new Acc_Account_Ledger($this->db, 
${'poste' . $i});
-                               if ($p->belong_ledger($p_jrn) < 0)
-                                       throw new Exception(_("Le poste") . " " 
. $p->id . " " . _("n'est pas dans ce journal"), 5);
-                               if (strlen(trim(${'poste' . $i})) != 0 && 
isNumber(${'amount' . $i}) == 0)
-                                       throw new Exception(_('Poste invalide 
[' . ${'poste' . $i} . ']'), 3);
-                               if ($p->do_exist() == 0)
-                                       throw new Exception(_('Poste Inexistant 
[' . ${'poste' . $i} . ']'), 4);
-                               $card_id = $p->find_card();
-                               if (!empty($card_id))
-                               {
-                                       $str_msg = " Le poste " . $p->id . " 
appartient à " . count($card_id) . " fiche(s) dont :";
-                                       $max = (count($card_id) > 
MAX_COMPTE_CARD) ? MAX_COMPTE_CARD : count($card_id);
-                                       for ($x = 0; $x < $max; $x++)
-                                       {
-                                               $card = new Fiche($this->db, 
$card_id[$x]['f_id']);
-                                               
$str_msg.=HtmlInput::card_detail($card->strAttribut(ATTR_DEF_QUICKCODE), 
$card->strAttribut(ATTR_DEF_NAME), 
'style="color:red;display:inline;text-decoration:underline"');
-                                               $str_msg.=" ";
-                                       }
-                                       $msg[] = $str_msg;
-                               }
-                       }
-               }
-               $tot_deb = round($tot_deb, 4);
-               $tot_cred = round($tot_cred, 4);
-               if ($tot_deb != $tot_cred)
-               {
-                       throw new Exception(_("Balance incorrecte ") . " debit 
= $tot_deb credit=$tot_cred ", 1);
-               }
-
-               return $msg;
-       }
-
-       /**
-        * @brief compute the internal code of the saved operation and set the 
$this->jr_internal to
-        *  the computed value
-        *
-        * @param$p_grpt id in jr_grpt_
-        *
-        * \return string internal_code
-        *      -
-        *
-        */
-
-       function compute_internal_code($p_grpt)
-       {
-               if ($this->id == 0)
-                       return;
-               $num = $this->db->get_next_seq('s_internal');
-               $atype = $this->get_propertie();
-               $type = substr($atype['jrn_def_code'], 0, 1);
-               $internal_code = sprintf("%s%06X", $type, $num);
-               $this->jr_internal = $internal_code;
-               return $internal_code;
-       }
-
-       /**
-        * @brief save the operation into the jrnx,jrn, ,
-        *  CA and pre_def
-        * @param$p_array
-        *
-        * \return array with [0] = false if failed otherwise true, [1] error
-        * code
-        */
-
-       function save($p_array = null)
-       {
-               if ($p_array == null)
-                       throw new Exception('save cannot use a empty array');
-               global $g_parameter;
-               extract($p_array);
-               try
-               {
-                       $msg = $this->verify($p_array);
-                       if (!empty($msg))
-                       {
-                               echo $this->display_warning($msg, _("Attention 
: il vaut mieux utiliser les fiches que les postes comptables "));
-                       }
-                       $this->db->start();
-
-                       $seq = $this->db->get_next_seq('s_grpt');
-                       $internal = $this->compute_internal_code($seq);
-
-                       $group = $this->db->get_next_seq("s_oa_group");
-                       $tot_amount = 0;
-                       $tot_deb = 0;
-                       $tot_cred = 0;
-                       $oPeriode = new Periode($this->db);
-                       $check_periode = $this->check_periode();
-                       if ($check_periode == false)
-                       {
-                               $oPeriode->find_periode($e_date);
-                       }
-                       else
-                       {
-                               $oPeriode->id = $period;
-                       }
-
-                       $count = 0;
-                       for ($i = 0; $i < $nb_item; $i++)
-                       {
-                               if (!isset(${'qc_' . $i}) && !isset(${'poste' . 
$i}))
-                                       continue;
-                               $acc_op = new Acc_Operation($this->db);
-                               $quick_code = "";
-                               // First we save the jrnx
-                               if (isset(${'qc_' . $i}))
-                               {
-                                       $qc = new Fiche($this->db);
-                                       $qc->get_by_qcode(${'qc_' . $i}, false);
-                                       $sposte = 
$qc->strAttribut(ATTR_DEF_ACCOUNT);
-                                       /*  if there are 2 accounts take 
following the deb or cred */
-                                       if (strpos($sposte, ',') != 0)
-                                       {
-                                               $array = explode(",", $sposte);
-                                               $poste = (isset(${'ck' . $i})) 
? $array[0] : $array[1];
-                                       }
-                                       else
-                                       {
-                                               $poste = $sposte;
-                                               if ($poste == '')
-                                                       throw new 
Exception(sprintf(_("La fiche %s n'a pas de poste comptable"), ${"qc_" . $i}));
-                                       }
-                                       $quick_code = ${'qc_' . $i};
-                               }
-                               else
-                               {
-                                       $poste = ${'poste' . $i};
-                               }
-
-                               $acc_op->date = $e_date;
-                               // compute the periode is do not check it
-                               if ($check_periode == false)
-                                       $acc_op->periode = $oPeriode->p_id;
-                               $acc_op->desc = null;
-                               if (strlen(trim(${'ld' . $i})) != 0)
-                                       $acc_op->desc = ${'ld' . $i};
-                               $acc_op->amount = round(${'amount' . $i}, 2);
-                               $acc_op->grpt = $seq;
-                               $acc_op->poste = $poste;
-                               $acc_op->jrn = $this->id;
-                               $acc_op->type = (isset(${'ck' . $i})) ? 'd' : 
'c';
-                               $acc_op->qcode = $quick_code;
-                               $j_id = $acc_op->insert_jrnx();
-                               $tot_amount+=round($acc_op->amount, 2);
-                               $tot_deb+=($acc_op->type == 'd') ? 
$acc_op->amount : 0;
-                               $tot_cred+=($acc_op->type == 'c') ? 
$acc_op->amount : 0;
-                               if ($g_parameter->MY_ANALYTIC != "nu")
-                               {
-                                       if (preg_match("/^[6,7]+/", $poste) == 
1)
-                                       {
-
-                                               // for each item, insert into 
operation_analytique */
-                                               $op = new 
Anc_Operation($this->db);
-                                               $op->oa_group = $group;
-                                               $op->j_id = $j_id;
-                                               $op->oa_date = $e_date;
-                                               $op->oa_debit = ($acc_op->type 
== 'd' ) ? 't' : 'f';
-                                               $op->oa_description = $desc;
-                                               $op->save_form_plan($p_array, 
$count, $j_id);
-                                               $count++;
-                                       }
-                               }
-                       }// loop for each item
-                       $acc_end = new Acc_Operation($this->db);
-                       $acc_end->amount = $tot_deb;
-                       if ($check_periode == false)
-                               $acc_end->periode = $oPeriode->p_id;
-                       $acc_end->date = $e_date;
-                       $acc_end->desc = $desc;
-                       $acc_end->grpt = $seq;
-                       $acc_end->jrn = $this->id;
-                       $acc_end->mt = $mt;
-                       $jr_id = $acc_end->insert_jrn();
-                       $this->jr_id = $jr_id;
-                       if ($jr_id == false)
-                               throw new Exception(_('Balance incorrecte'));
-                       $acc_end->pj = $e_pj;
-
-                       /* if e_suggest != e_pj then do not increment sequence 
*/
-                       if (strcmp($e_pj, $e_pj_suggest) == 0 && 
strlen(trim($e_pj)) != 0)
-                       {
-                               $this->inc_seq_pj();
-                       }
-
-                       $this->pj = $acc_end->set_pj();
-
-                       $this->db->exec_sql("update jrn set jr_internal='" . 
$internal . "' where " .
-                                       " jr_grpt_id = " . $seq);
-                       $this->internal = $internal;
-                       // Save now the predef op
-                       //------------------------
-                        if (isset ($opd_name) && trim($opd_name) != "" ){
-                               $opd = new Pre_Op_Advanced($this->db);
-                               $opd->get_post();
-                               $opd->save();
-                       }
-
-                       if (isset($this->with_concerned) && 
$this->with_concerned == true)
-                       {
-                               $orap = new acc_reconciliation($this->db);
-                               $orap->jr_id = $jr_id;
-
-                               $orap->insert($jrn_concerned);
-                       }
-                        /**
-                         * Save the file is any
-                         */
-                        if (isset($_FILES["pj"]))
-                        {
-                            $this->db->save_upload_document($seq);
-                        }
-                       
-               }
-               catch (Exception $a)
-               {
-                       throw $a;
-               }
-               catch (Exception $e)
-               {
-                       $this->db->rollback();
-                       echo _('OPERATION ANNULEE ');
-                       echo '<hr>';
-                       echo __FILE__ . __LINE__ . $e->getMessage();
-                       exit();
-               }
-               $this->db->commit();
-               return true;
-       }
-
-       /**
-        * @brief get all the data from request and build the object
-        */
-
-       function get_request()
-       {
-               $this->id = $_REQUEST['p_jrn'];
-       }
-
-       /**
-        * @brief retrieve the next number for this type of ledger
-        * @paramp_cn connx
-        * @paramp_type ledger type
-        *
-        * \return the number
-        *
-        *
-        */
-
-       static function next_number($p_cn, $p_type)
-       {
-
-               $Ret = $p_cn->count_sql("select * from jrn_def where 
jrn_def_type='" . $p_type . "'");
-               return $Ret + 1;
-       }
-
-       /**
-        * @brief get the first ledger
-        * @paramthe type
-        * \return the j_id
-        */
-
-       public function get_first($p_type, $p_access = 3)
-       {
-               global $g_user;
-               $all = $g_user->get_ledger($p_type, $p_access);
-               return $all[0];
-       }
-
-       /**
-        * @brief Update the paiment  in the list of operation
-        * @param$p_array is normally $_GET
-        */
-
-       function update_paid($p_array)
-       {
-               // reset all the paid flag because the checkbox is post only
-               // when checked
-               foreach ($p_array as $name => $paid)
-               {
-                       list($ad) = sscanf($name, "set_jr_id%d");
-                       if ($ad == null)
-                               continue;
-                       $sql = "update jrn set jr_rapt='' where jr_id=$ad";
-                       $Res = $this->db->exec_sql($sql);
-               }
-               // set a paid flag for the checked box
-               foreach ($p_array as $name => $paid)
-               {
-                       list ($id) = sscanf($name, "rd_paid%d");
-                       if ($id == null)
-                               continue;
-
-                       $sql = "update jrn set jr_rapt='paid' where jr_id=$id";
-                       $Res = $this->db->exec_sql($sql);
-               }
-       }
-
-       function update_internal_code($p_internal)
-       {
-               if (!isset($this->grpt_id))
-                       throw new Exception(('ERREUR ' . __FILE__ . ":" . 
__LINE__));
-               $Res = $this->db->exec_sql("update jrn set jr_internal='" . 
$p_internal . "' where " .
-                               " jr_grpt_id = " . $this->grpt_id);
-       }
-        /**
-         * Return an array of default card for the ledger type given 
-         * 
-         * @param $p_ledger_type VEN ACH ODS or FIN
-         * @param $p_side   D for Debit or C for credit or NA No Applicable
-         */
-        function get_default_card($p_ledger_type,$p_side)
-        {
-            $array=array();
-            $fiche_def_ref=new Fiche_Def_Ref($this->db);
-            // ----- for FINANCIAL  ----
-            if ($p_ledger_type =='FIN')
-            {
-                $array=$fiche_def_ref->get_by_modele(FICHE_TYPE_CLIENT);
-                $array=array_merge ( $array , 
$fiche_def_ref->get_by_modele(FICHE_TYPE_FOURNISSEUR));
-                $array=array_merge ( $array , 
$fiche_def_ref->get_by_modele(FICHE_TYPE_FIN));
-                $array=array_merge ( $array , 
$fiche_def_ref->get_by_modele(FICHE_TYPE_ADM_TAX));
-                $array=array_merge ( $array , 
$fiche_def_ref->get_by_modele(FICHE_TYPE_EMPL));
-                
-            }
-            // --- for miscellaneous ----
-            if ($p_ledger_type == 'ODS')
-            {
-                $result=$this->db->get_array('select fd_id from fiche_def');
-                for ($i = 0;$i<count($result);$i++ )
-                {
-                    $array[$i]=$result[$i]['fd_id'];
-                }
-            }
-            if ($p_side == 'D')
-            {
-                switch($p_ledger_type) 
-                {
-                    case 'VEN':
-                        
$array=$fiche_def_ref->get_by_modele(FICHE_TYPE_CLIENT);
-                        break;
-                    case 'ACH':
-                        
$array=$fiche_def_ref->get_by_modele(FICHE_TYPE_ACH_SER);
-                        $array=array_merge ($array, 
$fiche_def_ref->get_by_modele(FICHE_TYPE_ACH_MAR));
-                        $array=array_merge 
($array,$fiche_def_ref->get_by_modele(FICHE_TYPE_ACH_MAT));
-                        break;
-                    default :
-                        throw new Exception(_('get_default_card p_ledger_side 
is invalide ['.$p_ledger_type.']'));
-                    
-                }
-            } elseif ($p_side == 'C')
-            {
-                 switch($p_ledger_type) 
-                {
-                    case 'VEN':
-                        $array=$fiche_def_ref->get_by_modele(FICHE_TYPE_VENTE);
-                        break;
-                    case 'ACH':
-                        $array=  array_merge($array, 
$fiche_def_ref->get_by_modele(FICHE_TYPE_ADM_TAX));
-                        $array=  array_merge($array, 
$fiche_def_ref->get_by_modele(FICHE_TYPE_FOURNISSEUR));
-                        break;
-                    default :
-                        throw new Exception(_('get_default_card p_ledger_side 
is invalide ['.$p_ledger_type.']'));
-                    
-                }
-            }
-            return $array;
-            /*
-            $return=array();
-            $return = array_values($array);
-            for ($i = 0;$i<count($array);$i++ )
-            {
-                $return[$i]=$array[$i]['fd_id'];
-            }
-            return $return;
-             * 
-             */
-        }
-       /**
-        * @brief retrieve all the card for this type of ledger, make them
-        * into a string separated by comma
-        * @paramnone
-        * \return all the card or null is nothing is found
-        */
-
-       function get_all_fiche_def()
-       {
-               $sql = "select jrn_def_fiche_deb as deb,jrn_def_fiche_cred as 
cred " .
-                               " from jrn_def where " .
-                               " jrn_def_id = $1 ";
-
-               $r = $this->db->exec_sql($sql, array($this->id));
-
-               $res = Database::fetch_all($r);
-               if (empty($res))
-                       return null;
-               $card = "";
-               $comma = '';
-               foreach ($res as $item)
-               {
-                       if (strlen(trim($item['deb'])) != 0)
-                       {
-                               $card.=$comma . $item['deb'];
-                               $comma = ',';
-                       }
-                       if (strlen(trim($item['cred'])) != '')
-                       {
-                               $card.=$comma . $item['cred'];
-                               $comma = ',';
-                       }
-               }
-
-               return $card;
-       }
-
-       /**
-        * @brief get the saldo of an exercice, used for the opening of a folder
-        * @param$p_exercice is the exercice we want
-        * \return an array
-        * index =
-        * - solde (debit > 0 ; credit < 0)
-        * - j_poste
-        * - j_qcode
-        */
-
-       function get_saldo_exercice($p_exercice)
-       {
-               $sql = "select sum(a.montant) as solde, j_poste, j_qcode
-             from
-             (select j_id, case when j_debit='t' then j_montant
-             else j_montant * (-1) end  as montant
-             from jrnx) as a
-             join jrnx using (j_id)
-             join parm_periode on (j_tech_per = p_id )
-             where
-             p_exercice=$1
-             and j_poste::text not like '7%'
-             and j_poste::text not like '6%'
-             group by j_poste,j_qcode
-             having (sum(a.montant) != 0 )";
-               $res = $this->db->get_array($sql, array($p_exercice));
-               return $res;
-       }
-
-       /**
-        * @brief Check if a Dossier is using the strict mode or not
-        * \return true if we are using the strict_mode
-        */
-
-       function check_strict()
-       {
-               global $g_parameter;
-               if ($g_parameter->MY_STRICT == 'Y')
-                       return true;
-               if ($g_parameter->MY_STRICT == 'N')
-                       return false;
-               throw  new Exception("Valeur invalid " . __FILE__ . ':' . 
__LINE__);
-       }
-
-       /**
-        * @brief Check if a Dossier is using the check on the periode, if true 
than the user has to enter the date
-        * and the periode, it is a security check
-        * \return true if we are using the double encoding (date+periode)
-        */
-
-       function check_periode()
-       {
-               global $g_parameter;
-               if ($g_parameter->MY_CHECK_PERIODE == 'Y')
-                       return true;
-               if ($g_parameter->MY_CHECK_PERIODE == 'N')
-                       return false;
-               throw  new Exception("Valeur invalid " . __FILE__ . ':' . 
__LINE__);
-       }
-
-       /**
-        * @brief get the date of the last operation
-        */
-
-       function get_last_date()
-       {
-               if ($this->id == 0)
-                       throw new Exception(__FILE__ . ":" . __LINE__ . 
"Journal incorrect ");
-               $sql = "select to_char(max(jr_date),'DD.MM.YYYY') from jrn 
where jr_def_id=$1";
-               $date = $this->db->get_value($sql, array($this->id));
-               return $date;
-       }
-
-       /**
-        * @brief retrieve the jr_id thanks the internal code, do not change
-        * anything to the current object
-        * @paramthe internal code
-        * \return the jr_id or 0 if not found
-        */
-
-       function get_id($p_internal)
-       {
-               $sql = 'select jr_id from jrn where jr_internal=$1';
-               $value = $this->db->get_value($sql, array($p_internal));
-               if ($value == '')
-                       $value = 0;
-               return $value;
-       }
-
-       /**
-        * @brief create the invoice and saved it as attachment to the
-        * operation,
-        * @param$internal is the internal code
-        * @param$p_array is normally the $_POST
-        * \return a string
-        */
-
-       function create_document($internal, $p_array)
-       {
-               extract($p_array);
-               $doc = new Document($this->db);
-               $doc->f_id = $e_client;
-               $doc->md_id = $gen_doc;
-               $doc->ag_id = 0;
-                $p_array['e_pj']=$this->pj;
-               $filename="";
-               $doc->Generate($p_array,$p_array['e_pj']);
-               // Move the document to the jrn
-               $doc->MoveDocumentPj($internal);
-               // Update the comment with invoice number, if the comment is 
empty
-               if (!isset($e_comm) || strlen(trim($e_comm)) == 0)
-               {
-                       $sql = "update jrn set jr_comment=' document " . 
$doc->d_number . "' where jr_internal='$internal'";
-                       $this->db->exec_sql($sql);
-               }
-               return h($doc->d_name . ' (' . $doc->d_filename . ')');
-       }
-
-       /**
-        * @brief check if the payment method is valid
-        * @param$e_mp is the value and $e_mp_qcode is the quickcode
-        * \return nothing throw an Exception
-        */
-
-       public function check_payment($e_mp, $e_mp_qcode)
-       {
-               /*   Check if the "paid by" is empty, */
-               if ($e_mp != 0)
-               {
-                       /* the paid by is not empty then check if valid */
-                       $empl = new Fiche($this->db);
-                       $empl->get_by_qcode($e_mp_qcode);
-                       if ($empl->empty_attribute(ATTR_DEF_ACCOUNT) == true)
-                       {
-                               throw new Exception(_("Celui qui paie n' a pas 
de poste comptable"), 20);
-                       }
-                       /* get the account and explode if necessary */
-                       $sposte = $empl->strAttribut(ATTR_DEF_ACCOUNT);
-                       // if 2 accounts, take only the debit one for customer
-                       if (strpos($sposte, ',') != 0)
-                       {
-                               $array = explode(',', $sposte);
-                               $poste_val = $array[0];
-                       }
-                       else
-                       {
-                               $poste_val = $sposte;
-                       }
-                       $poste = new Acc_Account_Ledger($this->db, $poste_val);
-                       if ($poste->load() == false)
-                       {
-                               throw new Exception(sprintf(_("Pour la fiche %s 
le poste comptable [%s] n'existe pas"),$empl->quick_code,$poste->id  ), 9);
-                       }
-               }
-       }
-
-       /**
-        * @brief increment the sequence for the pj */
-
-       function inc_seq_pj()
-       {
-               $sql = "select nextval('s_jrn_pj" . $this->id . "')";
-               $this->db->exec_sql($sql);
-       }
-
-       /**
-        * @brief return a HTML string with the form for the search
-        * @param $p_type if the type of ledger possible 
values=ALL,VEN,ACH,ODS,FIN
-        * @param $all_type_ledger
-        *       values :
-        *         - 1 means all the ledger of this type
-        *         - 0 No have the "Tous les journaux" availables
-        * @param $div is the div (for reconciliation)
-        * @return a HTML String without the tag FORM or DIV
-        *
-        * @see build_search_sql
-        * @see display_search_form
-        * @see list_operation
-        */
-
-       function search_form($p_type, $all_type_ledger = 1, $div = "")
-       {
-            global $g_user;
-            $r="";
-                $bledger_param=  json_encode(array(
-                    'dossier'=>$_REQUEST['gDossier'],
-                    'type'=>$p_type,
-                    'all_type'=>$all_type_ledger,
-                    'div'=>$div
-                    ));
-                
-                $bledger_param=  str_replace('"', "'", $bledger_param);
-                $bledger=new ISmallButton('l');
-                $bledger->label=_("choix des journaux");
-                $bledger->javascript=" show_ledger_choice($bledger_param)";
-                $f_ledger=$bledger->input();
-                $hid_jrn="";
-                if ( isset ($_REQUEST[$div.'nb_jrn']) ){
-                    for ($i=0;$i < $_REQUEST[$div.'nb_jrn'];$i++) {
-                        if ( isset ($_REQUEST[$div."r_jrn"][$i]))
-                            
$hid_jrn.=HtmlInput::hidden($div.'r_jrn['.$i.']',$_REQUEST[$div."r_jrn"][$i]);
-                    }
-                    
$hid_jrn.=HtmlInput::hidden($div.'nb_jrn',$_REQUEST[$div.'nb_jrn']);
-                } else {
-                    $hid_jrn=HtmlInput::hidden($div.'nb_jrn',0);
-                }
-                /* Compute date for exercice */
-                $period = $g_user->get_periode();
-                $per = new Periode($this->db, $period);
-               $exercice = $per->get_exercice();
-               list($per_start, $per_end) = $per->get_limit($exercice);
-               $date_end = $per_end->last_day();
-                $date_start=$per_start->first_day();
-                        
-               /* widget for date_start */
-               $f_date_start = new IDate('date_start');
-               /* all periode or only the selected one */
-               if (isset($_REQUEST['date_start']))
-               {
-                       $f_date_start->value = $_REQUEST['date_start'];
-               }
-               else
-               {
-                        $f_date_start->value=$date_start;
-               }
-
-               /* widget for date_end */
-               $f_date_end = new IDate('date_end');
-               /* all date or only the selected one */
-               if (isset($_REQUEST['date_end']))
-               {
-                       $f_date_end->value = $_REQUEST['date_end'];
-               }
-               else
-               {
-                       $f_date_end->value = $date_end;
-               }
-                /* widget for date term */
-                $f_date_paid_start=new IDate('date_paid_start');
-                $f_date_paid_end=new IDate('date_paid_end');
-                
-                
$f_date_paid_start->value=(isset($_REQUEST['date_paid_start']))?$_REQUEST['date_paid_start']:'';
-                
$f_date_paid_end->value=(isset($_REQUEST['date_paid_end']))?$_REQUEST['date_paid_end']:'';
-                
-               /* widget for desc */
-               $f_descript = new IText('desc');
-               $f_descript->size = 40;
-               if (isset($_REQUEST['desc']))
-               {
-                       $f_descript->value = $_REQUEST['desc'];
-               }
-
-               /* widget for amount */
-               $f_amount_min = new INum('amount_min');
-               $f_amount_min->value = (isset($_REQUEST['amount_min'])) ? 
abs($_REQUEST['amount_min']) : 0;
-               $f_amount_max = new INum('amount_max');
-               $f_amount_max->value = (isset($_REQUEST['amount_max'])) ? 
abs($_REQUEST['amount_max']) : 0;
-
-               /* input quick code */
-               $f_qcode = new ICard('qcode' . $div);
-
-               $f_qcode->set_attribute('typecard', 'all');
-               /*        $f_qcode->set_attribute('p_jrn','0');
-
-                 $f_qcode->set_callback('filter_card');
-                */
-               $f_qcode->set_dblclick("fill_ipopcard(this);");
-               // Add the callback function to filter the card on the jrn
-               //$f_qcode->set_callback('filter_card');
-               $f_qcode->set_function('fill_data');
-               $f_qcode->javascript = sprintf(' 
onchange="fill_data_onchange(%s);" ', $f_qcode->name);
-               $f_qcode->value = (isset($_REQUEST['qcode' . $div])) ? 
$_REQUEST['qcode' . $div] : '';
-
-               /*        $f_txt_qcode=new IText('qcode');
-                 
$f_txt_qcode->value=(isset($_REQUEST['qcode']))?$_REQUEST['qcode']:'';
-                */
-
-               /* input poste comptable */
-               $f_accounting = new IPoste('accounting');
-               $f_accounting->value = (isset($_REQUEST['accounting'])) ? 
$_REQUEST['accounting'] : '';
-               if ($this->id == -1)
-                       $jrn = 0;
-               else
-                       $jrn = $this->id;
-               $f_accounting->set_attribute('jrn', $jrn);
-               $f_accounting->set_attribute('ipopup', 'ipop_account');
-               $f_accounting->set_attribute('label', 'ld');
-               $f_accounting->set_attribute('account', 'accounting');
-               $info = HtmlInput::infobulle(13);
-
-               $f_paid = new ICheckbox('unpaid');
-               $f_paid->selected = (isset($_REQUEST['unpaid'])) ? true : false;
-
-               $r.=dossier::hidden();
-               $r.=HtmlInput::hidden('ledger_type', $this->type);
-               $r.=HtmlInput::hidden('ac', $_REQUEST['ac']);
-               ob_start();
-               require_once NOALYSS_INCLUDE.'/template/ledger_search.php';
-               $r.=ob_get_contents();
-               ob_end_clean();
-               return $r;
-       }
-
-       /**
-        * @brief this function will create a sql stmt to use to create the 
list for
-        * the ledger,
-        * @param$p_array is usually the $_GET,
-        * @param$p_order the order of the row
-        * @param$p_where is the sql condition if not null then the $p_array 
will not be used
-        * \note the p_action will be used to filter the ledger but gl means ALL
-        * struct array $p_array
-         \verbatim
-         (
-         [gDossier] => 13
-         [p_jrn] => -1
-         [date_start] =>
-         [date_end] =>
-         [amount_min] => 0
-         [amount_max] => 0
-         [desc] =>
-         [search] => Rechercher
-         [p_action] => ven
-         [sa] => l
-         )
-         \endverbatim
-        * \return an array with a valid sql statement, an the where clause => 
array[sql] array[where]
-        * \see list_operation
-        * \see display_search_form
-        * \see search_form
-        */
-
-       public function build_search_sql($p_array, $p_order = "", $p_where = "")
-       {
-               $sql = "select jr_id    ,
-             jr_montant,
-             substr(jr_comment,1,60) as jr_comment,
-             to_char(jr_ech,'DD.MM.YY') as str_jr_ech,
-             to_char(jr_date,'DD.MM.YY') as str_jr_date,
-             jr_date as jr_date_order,
-             jr_grpt_id,
-             jr_rapt,
-             jr_internal,
-             jrn_def_id,
-             jrn_def_name,
-             jrn_def_ech,
-             jrn_def_type,
-             jr_valid,
-             jr_tech_per,
-             jr_pj_name,
-             p_closed,
-             jr_pj_number,
-             n_text,
-            case
-            when jrn_def_type='VEN' then
-                (select ad_value from fiche_detail where ad_id=1
-                and f_id=(select max(qs_client) from quant_sold join jrnx 
using (j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))
-           when jrn_def_type = 'ACH' then
-               (select ad_value from fiche_detail where ad_id=1
-               and f_id=(select max(qp_supplier) from quant_purchase join jrnx 
using (j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))
-           when jrn_def_type = 'FIN' then
-               (select ad_value from fiche_detail where ad_id=1
-               and f_id=(select qf_other from quant_fin where 
quant_fin.jr_id=x.jr_id))
-           end as name,
-          case
-            when jrn_def_type='VEN' then (select ad_value from fiche_detail 
where ad_id=32 and f_id=(select max(qs_client) from quant_sold join jrnx using 
(j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))
-           when jrn_def_type = 'ACH' then (select ad_value from fiche_detail 
where ad_id=32 and f_id=(select max(qp_supplier) from quant_purchase join jrnx 
using (j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))
-           when jrn_def_type = 'FIN' then (select ad_value from fiche_detail 
where ad_id=32 and f_id=(select qf_other from quant_fin where 
quant_fin.jr_id=x.jr_id))
-           end as first_name,
-           case
-            when jrn_def_type='VEN' then (select ad_value from fiche_detail 
where ad_id=23 and f_id=(select max(qs_client) from quant_sold join jrnx using 
(j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))
-           when jrn_def_type = 'ACH' then (select ad_value from fiche_detail 
where ad_id=23 and f_id=(select max(qp_supplier) from quant_purchase join jrnx 
using (j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))
-           when jrn_def_type = 'FIN' then (select ad_value from fiche_detail 
where ad_id=23 and f_id=(select qf_other from quant_fin where 
quant_fin.jr_id=x.jr_id))
-           end as quick_code,
-           case
-            when jrn_def_type='VEN' then
-                    (select sum(qs_price)+sum(vat) from
-                               (select qs_internal,qs_price,case when 
qs_vat_sided<>0 then 0 else qs_vat end as vat from quant_sold where 
qs_internal=X.jr_internal) as ven_invoice
-                         )
-           when jrn_def_type = 'ACH' then
-                       (
-                               select 
sum(qp_price)+sum(vat)+sum(qp_nd_tva)+sum(qp_nd_tva_recup)
-                               from
-                                (select 
qp_internal,qp_price,qp_nd_tva,qp_nd_tva_recup,qp_vat-qp_vat_sided as vat from 
quant_purchase where qp_internal=X.jr_internal) as invoice_purchase
-                       )
-               else null
-               end as total_invoice,
-            jr_date_paid,
-            to_char(jr_date_paid,'DD.MM.YY') as str_jr_date_paid
-             from
-             jrn as X left join jrn_note using(jr_id)
-             join jrn_def on jrn_def_id=jr_def_id
-             join parm_periode on p_id=jr_tech_per";
-
-               if (!empty($p_array))
-                       extract($p_array);
-
-                if (isset($op) ) 
-                    $r_jrn = (isset(${$op."r_jrn"})) ? ${$op."r_jrn"} : -1;
-                else
-                {
-                    $r_jrn = (isset($r_jrn)) ? $r_jrn : -1;
-                    
-                }
-
-               /* if no variable are set then give them a default
-                * value */
-               if ($p_array == null || empty($p_array) || !isset($amount_min))
-               {
-                       $amount_min = 0;
-                       $amount_max = 0;
-
-                       $desc = '';
-                       $qcode = (isset($qcode)) ? $qcode : "";
-                       if (isset($qcodesearch_op))
-                               $qcode = $qcodesearch_op;
-                       $accounting = (isset($accounting)) ? $accounting : "";
-                       $periode = new Periode($this->db);
-                       $g_user = new User($this->db);
-                       $p_id = $g_user->get_periode();
-                       if ($p_id != null)
-                       {
-                               list($date_start, $date_end) = 
$periode->get_date_limit($p_id);
-                       }
-               }
-
-               /* if p_jrn : 0 if means all ledgers, if -1 means all ledger of 
this
-                *  type otherwise only one ledger */
-               $fil_ledger = '';
-               $fil_amount = '';
-               $fil_date = '';
-               $fil_desc = '';
-               $fil_sec = '';
-               $fil_qcode = '';
-               $fil_account = '';
-               $fil_paid = '';
-                $fil_date_paid='';
-
-               $and = '';
-               $g_user = new User($this->db);
-               $p_action = $ledger_type;
-               if ($p_action == '')
-                       $p_action = 'ALL';
-               if ($r_jrn == -1)
-               {
-
-                       /* from compta.php the p_action is quick_writing 
instead of ODS  */
-                       if ($p_action == 'quick_writing')
-                               $p_action = 'ODS';
-
-
-                       $fil_ledger = $g_user->get_ledger_sql($p_action, 3);
-                       $and = ' and ';
-               }
-               else
-               {
-
-                       if ($p_action == 'quick_writing')
-                               $p_action = 'ODS';
-
-                       $aLedger = $g_user->get_ledger($p_action, 3);
-                       $fil_ledger = '';
-                       $sp = '';
-                       for ($i = 0; $i < count($r_jrn); $i++)
-                       {
-                                if (isset($r_jrn[$i]) )
-                               {
-                                    $a=$r_jrn[$i];
-                                   $fil_ledger.=$sp . $a;
-                                    $sp = ',';
-                               }
-                       }
-                       $fil_ledger = ' jrn_def_id in (' . $fil_ledger . ')';
-                       $and = ' and ';
-
-                       /* no ledger selected */
-                       if ($sp == '')
-                       {
-                               $fil_ledger = '';
-                               $and = '';
-                       }
-               }
-
-               /* format the number */
-               $amount_min = abs(toNumber($amount_min));
-               $amount_max = abs(toNumber($amount_max));
-               if ($amount_min > 0 && isNumber($amount_min))
-               {
-                       $fil_amount = $and . ' jr_montant >=' . $amount_min;
-                       $and = ' and ';
-               }
-               if ($amount_max > 0 && isNumber($amount_max))
-               {
-                       $fil_amount.=$and . ' jr_montant <=' . $amount_max;
-                       $and = ' and ';
-               }
-               /* 
-------------------------------------------------------------------------- *
-                * if both amount are the same then we need to search into the 
detail
-                * and we reset the fil_amount
-                * 
-------------------------------------------------------------------------- */
-               if (isNumber($amount_min) &&
-                               isNumber($amount_max) &&
-                               $amount_min > 0 &&
-                               bccomp($amount_min, $amount_max, 2) == 0)
-               {
-                        $fil_amount = $and . ' ( ';
- 
-                        // Look in detail
-                       $fil_amount .= 'jr_grpt_id in ( select distinct j_grpt 
from jrnx where j_montant = ' . $amount_min . ') ';
-
-                       //and the total operation
-                       $fil_amount .= ' or ';
-                       $fil_amount .= ' jr_montant = '.$amount_min;
-
-                      $fil_amount .= ')';
-                      $and = " and ";
-               }
-               // date
-               if (isset($date_start) && isDate($date_start) != null)
-               {
-                       $fil_date = $and . " jr_date >= to_date('" . 
$date_start . "','DD.MM.YYYY')";
-                       $and = " and ";
-               }
-               if (isset($date_end) && isDate($date_end) != null)
-               {
-                       $fil_date.=$and . " jr_date <= to_date('" . $date_end . 
"','DD.MM.YYYY')";
-                       $and = " and ";
-               }
-               // date paiement
-               if (isset($date_paid_start) && isDate($date_paid_start) != null)
-               {
-                       $fil_date_paid = $and . " jr_date_paid >= to_date('" . 
$date_paid_start . "','DD.MM.YYYY')";
-                       $and = " and ";
-               }
-               if (isset($date_paid_end) && isDate($date_paid_end) != null)
-               {
-                       $fil_date_paid.=$and . " jr_date_paid <= to_date('" . 
$date_paid_end . "','DD.MM.YYYY')";
-                       $and = " and ";
-               }
-               // comment
-               if (isset($desc) && $desc != null)
-               {
-                       $desc = sql_string($desc);
-                       $fil_desc = $and . " ( upper(jr_comment) like upper('%" 
. $desc . "%') or upper(jr_pj_number) like upper('%" . $desc . "%') " .
-                                       " or upper(jr_internal)  like upper('%" 
. $desc . "%')
-                          or jr_grpt_id in (select j_grpt from jrnx where 
j_text ~* '" . $desc . "')
-                          or jr_id in (select jr_id from jrn_info where 
ji_value is not null and ji_value ~* '$desc')
-                          )";
-                       $and = " and ";
-               }
-               //    Poste
-               if (isset($accounting) && $accounting != null)
-               {
-                       $fil_account = $and . "  jr_grpt_id in (select j_grpt
-                         from jrnx where j_poste::text like '" . 
sql_string($accounting) . "%' )  ";
-                       $and = " and ";
-               }
-               // Quick Code
-               if (isset($qcodesearch_op))
-                       $qcode = $qcodesearch_op;
-               if (isset($qcode) && $qcode != null)
-               {
-                       $fil_qcode = $and . "  jr_grpt_id in ( select j_grpt 
from
-                       jrnx where trim(j_qcode) = upper(trim('" . 
sql_string($qcode) . "')))";
-                       $and = " and ";
-               }
-
-               // Only the unpaid
-               if (isset($unpaid))
-               {
-                       $fil_paid = $and . SQL_LIST_UNPAID_INVOICE;
-                       $and = " and ";
-               }
-
-               $g_user = new User(new Database());
-               $g_user->Check();
-               $g_user->check_dossier(dossier::id());
-
-               if ($g_user->admin == 0 && $g_user->is_local_admin() == 0)
-               {
-                       $fil_sec = $and . " jr_def_id in ( select uj_jrn_id " .
-                                       " from user_sec_jrn where " .
-                                       " uj_login='" . $_SESSION['g_user'] . 
"'" .
-                                       " and uj_priv in ('R','W'))";
-               }
-               $where = $fil_ledger . $fil_amount . $fil_date . $fil_desc . 
$fil_sec . $fil_amount . $fil_qcode . $fil_paid . $fil_account.$fil_date_paid;
-               $sql.=" where " . $where;
-               return array($sql, $where);
-       }
-
-       /**
-        * @brief return a html string with the search_form
-        * \return a HTML string with the FORM
-        * \see build_search_sql
-        * \see search_form
-        * \see list_operation
-        */
-
-       function display_search_form()
-       {
-               $r = '';
-               $type = $this->type;
-
-               if ($type == "")
-                       $type = 'ALL';
-               $r.='<div id="search_form" style="display:none">';
-               $r.=HtmlInput::anchor_hide('&#10761;', 
'$(\'search_form\').style.display=\'none\';');
-               $r.=h2('Recherche','class="title"');
-               $r.='<FORM METHOD="GET">';
-               $r.=$this->search_form($type);
-               $r.=HtmlInput::submit('search', _('Rechercher'));
-               $r.=HtmlInput::hidden('ac', $_REQUEST['ac']);
-
-               /*  when called from commercial.php some hidden values are 
needed */
-               if (isset($_REQUEST['sa']))
-                       $r.= HtmlInput::hidden("sa", $_REQUEST['sa']);
-               if (isset($_REQUEST['sb']))
-                       $r.= HtmlInput::hidden("sb", $_REQUEST['sb']);
-               if (isset($_REQUEST['sc']))
-                       $r.= HtmlInput::hidden("sc", $_REQUEST['sc']);
-               if (isset($_REQUEST['f_id']))
-                       $r.=HtmlInput::hidden("f_id", $_REQUEST['f_id']);
-
-               $r.='</FORM>';
-
-               $r.='</div>';
-               $button = new IButton('tfs');
-               $button->label = _("Filtrer");
-               $button->javascript = "toggleHideShow('search_form','tfs');";
-
-               $r.=$button->input();
-               return $r;
-       }
-
-       /**
-        * @brief return the last p_limit operation into an array
-        * @param$p_limit is the max of operation to return
-        * \return $p_array of Follow_Up object
-        */
-
-       function get_last($p_limit)
-       {
-               global $g_user;
-               $filter_ledger = $g_user->get_ledger_sql('ALL', 3);
-               $filter_ledger = str_replace('jrn_def_id', 'jr_def_id', 
$filter_ledger);
-               $sql = "
-                       select 
jr_id,jr_pj_number,jr_date,to_char(jr_date,'DD.MM.YYYY') as 
jr_date_fmt,jr_montant, jr_comment,jr_internal,jrn_def_code
-                       from jrn
-                       join jrn_def on (jrn_def_id=jr_def_id)
-                        where $filter_ledger
-                       order by jr_date desc , 
substring(jr_pj_number,'[0-9]+$')::numeric desc limit $p_limit";
-               $array = $this->db->get_array($sql);
-               return $array;
-       }
-
-       /**
-        * @brief retreive the jr_grpt_id from a ledger
-        * @param $p_what the column to seek
-        *    possible values are
-        *   - internal
-        * @param $p_value the value of the col.
-        */
-       function search_group($p_what, $p_value)
-       {
-               switch ($p_what)
-               {
-                       case 'internal':
-                               return $this->db->get_value('select jr_grpt_id 
from jrn where jr_internal=$1', array($p_value));
-               }
-       }
-
-       /**
-        * @brief retrieve operation from  jrn
-        * @param $p_from periode (id)
-        * @param $p_to periode (id)
-        * @return an array
-        */
-       function get_operation($p_from, $p_to)
-       {
-               global $g_user;
-               $jrn = ($this->id == 0) ? 'and ' . $g_user->get_ledger_sql() : 
' and jr_def_id = ' . $this->id;
-               $sql = "select jr_id as id ,jr_internal as internal, " .
-                               "jr_pj_number as pj,jr_grpt_id," .
-                               " to_char(jr_date,'DDMMYY') as date_fmt, " .
-                               " jr_comment as comment, jr_montant as montant 
," .
-                               " jr_grpt_id,jr_def_id" .
-                               " from jrn join jrn_def on 
(jr_def_id=jrn_def_id) where  " .
-                               " jr_date >= (select p_start from parm_periode 
where p_id = $1)
-                                and  jr_date <= (select p_end from 
parm_periode where p_id  = $2)" .
-                               '  ' . $jrn . ' order by 
jr_date,substring(jr_pj_number,\'[0-9]+$\')::numeric asc';
-               $ret = $this->db->get_array($sql, array($p_from, $p_to));
-               return $ret;
-       }
-
-       /**
-        * @brief return the used VAT code with a rate > 0
-        * @return an array of tva_id,tva_label,tva_poste
-        */
-       public function existing_vat()
-       {
-               if ($this->type == 'ACH')
-               {
-                       $array = $this->db->get_array("select 
tva_id,tva_label,tva_poste from tva_rate where tva_rate != 0.0000 " .
-                                       " and  exists (select qp_vat_code from 
quant_purchase
-                                        where  qp_vat_code=tva_id and  exists 
(select j_id from jrnx where j_jrn_def = $1)) order by tva_id", 
array($this->id));
-               }
-               if ($this->type == 'VEN')
-               {
-                       $array = $this->db->get_array("select 
tva_id,tva_label,tva_poste from tva_rate where tva_rate != 0.0000 " .
-                                       " and  exists (select qs_vat_code from 
quant_sold
-                                        where  qs_vat_code=tva_id and  exists 
(select j_id from jrnx where j_jrn_def = $1)) order by tva_id", 
array($this->id));
-               }
-               return $array;
-       }
-
-       /**
-        * @brief get the amount of vat for a given jr_grpt_id from the table
-        * quant_purchase
-        * @param the jr_grpt_id
-        * @return array price=htva, [1] =  vat,
-        * @note
-        * @see
-         @code
-         array
-         'price' => string '91.3500' (length=7)
-         'vat' => string '0.0000' (length=6)
-         'priv' => string '0.0000' (length=6)
-         'tva_nd_recup' => string '0.0000' (length=6)
-
-         @endcode
-        */
-       function get_other_amount($p_jr_id)
-       {
-               if ($this->type == 'ACH')
-               {
-                       $array = $this->db->get_array('select sum(qp_price) as 
price,sum(qp_vat) as vat ' .
-                                       
',sum(coalesce(qp_nd_amount,0)+coalesce(qp_dep_priv,0)) as priv' .
-                                       
',sum(coalesce(qp_nd_tva_recup,0)+coalesce(qp_nd_tva,0)) as tva_nd' .
-                                       ',sum(qp_vat_sided)  as tva_np' .
-                                       '  from quant_purchase join jrnx 
using(j_id)
-                                        where  j_grpt=$1 ', array($p_jr_id));
-                       $ret = $array[0];
-               }
-               if ($this->type == 'VEN')
-               {
-                       $array = $this->db->get_array('select sum(qs_price) as 
price,sum(qs_vat) as vat ' .
-                                       ',0 as priv' .
-                                       ',0 as tva_nd' .
-                                        ',sum(qs_vat_sided)  as tva_np' .
-                                       '  from quant_sold join jrnx using(j_id)
-                                        where  j_grpt=$1 ', array($p_jr_id));
-                       $ret = $array[0];
-               }
-               return $ret;
-       }
-
-       /**
-        * @brief get the amount of vat for a given jr_grpt_id from the table
-        * quant_purchase
-        * @param the jr_grpt_id
-        * @return array of sum_vat, tva_label
-        * @note
-        * @see
-         @code
-
-         @endcode
-        */
-       function vat_operation($p_jr_id)
-       {
-               if ($this->type == 'ACH')
-               {
-                       $array = $this->db->get_array('select 
coalesce(sum(qp_vat),0) as sum_vat,tva_id
-                                        from quant_purchase as p right join 
tva_rate on (qp_vat_code=tva_id)  join jrnx using(j_id)
-                                        where tva_rate !=0.0 and j_grpt=$1 
group by tva_id', array($p_jr_id));
-               }
-               if ($this->type == 'VEN')
-               {
-                       $array = $this->db->get_array('select 
coalesce(sum(qs_vat),0) as sum_vat,tva_id
-                                        from quant_sold as p right join 
tva_rate on (qs_vat_code=tva_id)  join jrnx using(j_id)
-                                        where tva_rate !=0.0 and j_grpt=$1 
group by tva_id', array($p_jr_id));
-               }
-               return $array;
-       }
-
-       /**
-        * @brief retrieve amount of previous periode
-        * @param $p_to frmo the start of the exercise until $p_to
-        * @return $array with vat, price,other_amount
-        * @note
-        * @see
-         @code
-         array
-         'price' => string '446.1900' (length=8)
-         'vat' => string '21.7600' (length=7)
-         'priv' => string '0.0000' (length=6)
-         'tva_nd_recup' => string '0.0000' (length=6)
-         'tva' =>
-         array
-         0 =>
-         array
-         'sum_vat' => string '13.7200' (length=7)
-         'tva_id' => string '1' (length=1)
-         1 =>
-         array
-         'sum_vat' => string '8.0400' (length=6)
-         'tva_id' => string '3' (length=1)
-         2 =>
-         array
-         'sum_vat' => string '0.0000' (length=6)
-         'tva_id' => string '4' (length=1)
-
-         @endcode
-        */
-       function previous_amount($p_to)
-       {
-               /* get the first periode of exercise */
-               $periode = new Periode($this->db, $p_to);
-               $exercise = $periode->get_exercice();
-               list ($min, $max) = $periode->get_limit($exercise);
-                // transform min into date
-                $min_date=$min->first_day();
-                // transform $p_to  into date
-                $periode_max=new Periode($this->db,$p_to);
-                $max_date=$periode_max->first_day();
-                bcscale(2);
-               // min periode
-               if ($this->type == 'ACH')
-               {
-                       /*  get all amount exclude vat */
-                       $sql = "select coalesce(sum(qp_price),0) as price" .
-                                       " ,coalesce(sum(qp_vat),0) as vat " .
-                                       ',coalesce(sum(qp_dep_priv),0) as priv' 
.
-                                       ',coalesce(sum(qp_vat_sided),0) as 
reversed' .
-                                       
',coalesce(sum(qp_nd_tva_recup),0)+coalesce(sum(qp_nd_tva),0) as tva_nd' .
-                                       ',coalesce(sum(qp_vat_sided),0) as 
tva_np' .
-                                       '  from quant_purchase join jrnx 
using(j_id) ' .
-                                       " where j_date >= 
to_date($1,'DD.MM.YYYY') and j_date < to_date($2,'DD.MM.YYYY') ".
-                                ' and j_jrn_def = $3';
-                       $array = $this->db->get_array($sql, array($min_date, 
$max_date,$this->id));
-
-                       $ret = $array[0];
-                       /* retrieve all vat code */
-                       $array = $this->db->get_array("select 
coalesce(sum(qp_vat),0) as sum_vat,tva_id
-                                        from quant_purchase as p right join 
tva_rate on (qp_vat_code=tva_id)  join jrnx using(j_id)
-                                        where tva_rate !=0 and  j_date >= 
to_date($1,'DD.MM.YYYY') and j_date < to_date($2,'DD.MM.YYYY') 
-                                        and j_jrn_def = $3
-                                        group by tva_id", 
-                                array($min_date, $max_date,$this->id));
-                       $ret['tva'] = $array;
-               }
-               if ($this->type == 'VEN')
-               {
-                       /*  get all amount exclude vat */
-                       $sql = "select coalesce(sum(qs_price),0) as price" .
-                                       " ,coalesce(sum(qs_vat),0) as vat " .
-                                       ',0 as priv' .
-                                       ',0 as tva_nd' .
-                                        ',coalesce(sum(qs_vat_sided),0) as 
tva_np' .
-                                       '  from quant_sold join jrnx 
using(j_id) ' .
-                                       " where j_date >= 
to_date($1,'DD.MM.YYYY') and j_date < to_date($2,'DD.MM.YYYY') ".
-                                ' and j_jrn_def = $3';
-                       $array = $this->db->get_array($sql, array($min_date, 
$max_date,$this->id));
-                       $ret = $array[0];
-                       /* retrieve all vat code */
-                       $array = $this->db->get_array("select 
coalesce(sum(qs_vat),0) as sum_vat,tva_id
-                                        from quant_sold as p right join 
tva_rate on (qs_vat_code=tva_id)  join jrnx using(j_id)
-                                        where tva_rate !=0 and
-                                        j_date >= to_date($1,'DD.MM.YYYY') and 
j_date < to_date($2,'DD.MM.YYYY') 
-                                        and j_jrn_def = $3
-                                        group by tva_id", array($min_date, 
$max_date,$this->id));
-                       $ret['tva'] = $array;
-               }
-                if ($this->type=="FIN") 
-                {
-                        
-                    /* find the quick code of this ledger */
-                    $ledger=new Acc_Ledger_Fin($this->db,$this->id);
-                    $qcode=$ledger->get_bank();
-                    $bank_card=new Fiche($this->db,$qcode);
-                    
-                    /*add the amount from Opening Writing                  */
-                    $cond=sprintf(" j_jrn_def <> %d  and j_date >= 
to_date('%s','DD.MM.YYYY') and j_date < to_date('%s','DD.MM.YYYY') 
",$this->id,$min_date,$max_date);
-                    $saldo = $bank_card->get_bk_balance ($cond);
-                    $ret['amount']=bcsub($saldo['debit'],$saldo['credit']);
-                }
-               return $ret;
-       }
-
-       
////////////////////////////////////////////////////////////////////////////////
-       // TEST MODULE
-       
////////////////////////////////////////////////////////////////////////////////
-       /**
-        * @brief this function is intended to test this class
-        */
-       static function test_me($pCase = '')
-       {
-               if ($pCase == '')
-               {
-                       echo Acc_Reconciliation::$javascript;
-                       html_page_start();
-                       $cn = new Database(dossier::id());
-                       $_SESSION['g_user'] = 'phpcompta';
-                       $_SESSION['g_pass'] = 'phpcompta';
-
-                       $id = (isset($_REQUEST['p_jrn'])) ? $_REQUEST['p_jrn'] 
: -1;
-                       $a = new Acc_Ledger($cn, $id);
-                       $a->with_concerned = true;
-                       // Vide
-                       echo '<FORM method="post">';
-                       echo $a->select_ledger()->input();
-                       echo HtmlInput::submit('go', 'Test it');
-                       echo '</form>';
-                       if (isset($_POST['go']))
-                       {
-                               echo "Ok ";
-                               echo '<form method="post">';
-                               echo $a->show_form();
-                               echo HtmlInput::submit('post_id', 'Try me');
-                               echo '</form>';
-                               // Show the predef operation
-                               // Don't forget the p_jrn
-                               echo '<form>';
-                               echo dossier::hidden();
-                               echo '<input type="hidden" value="' . $id . '" 
name="p_jrn">';
-                               $op = new Pre_operation($cn);
-                               $op->p_jrn = $id;
-                               $op->od_direct = 't';
-                               if ($op->count() != 0)
-                               {
-                                       echo HtmlInput::submit('use_opd', 
'Utilisez une opération pr&eacute;d&eacute;finie',"","smallbutton");
-                                       echo $op->show_button();
-                               }
-                               echo '</form>';
-                               exit('test_me');
-                       }
-
-                       if (isset($_POST['post_id']))
-                       {
-
-                               echo '<form method="post">';
-                               echo $a->show_form($_POST, 1);
-                               echo HtmlInput::button('add', 'Ajout d\'une 
ligne', 'onClick="quick_writing_add_row()"');
-                               echo HtmlInput::submit('save_it', _("Sauver"));
-                               echo '</form>';
-                               exit('test_me');
-                       }
-                       if (isset($_POST['save_it']))
-                       {
-                               print 'saving';
-                               $array = $_POST;
-                               $array['save_opd'] = 1;
-                               try
-                               {
-                                       $a->save($array);
-                               }
-                               catch (Exception $e)
-                               {
-                                       alert($e->getMessage());
-                                       echo '<form method="post">';
-
-                                       echo $a->show_form($_POST);
-                                       echo HtmlInput::submit('post_id', 'Try 
me');
-                                       echo '</form>';
-                               }
-                               return;
-                       }
-                       // The GET at the end because automatically repost when 
you don't
-                       // specify the url in the METHOD field
-                       if (isset($_GET['use_opd']))
-                       {
-                               $op = new Pre_op_advanced($cn);
-                               $op->set_od_id($_REQUEST['pre_def']);
-                               //$op->p_jrn=$id;
-
-                               $p_post = $op->compute_array();
-
-                               echo '<FORM method="post">';
-
-                               echo $a->show_form($p_post);
-                               echo HtmlInput::submit('post_id', 'Use 
predefined operation');
-                               echo '</form>';
-                               return;
-                       }
-               }// if case = ''
-               
///////////////////////////////////////////////////////////////////////////
-               // search
-               if ($pCase == 'search')
-               {
-                       html_page_start();
-                       $cn = new Database(dossier::id());
-                       $ledger = new Acc_Ledger($cn, 0);
-                       $_SESSION['g_user'] = 'phpcompta';
-                       $_SESSION['g_pass'] = 'phpcompta';
-                       echo $ledger->search_form('ALL');
-               }
-               
///////////////////////////////////////////////////////////////////////////
-               // reverse
-               // Give yourself the var and check in your tables
-               
///////////////////////////////////////////////////////////////////////////
-               if ($pCase == 'reverse')
-               {
-                       $cn = new Database(dossier::id());
-                       $jr_internal = 'OD-01-272';
-                       try
-                       {
-                               $cn->start();
-                               $jrn_def_id = $cn->get_value('select jr_def_id 
from jrn where jr_internal=$1', array($jr_internal));
-                               $ledger = new Acc_Ledger($cn, $jrn_def_id);
-                               $ledger->jr_id = $cn->get_value('select jr_id 
from jrn where jr_internal=$1', array($jr_internal));
-
-                               echo "Ouvrez le fichier " . __FILE__ . " à la 
ligne " . __LINE__ . " pour changer jr_internal et vérifier le résultat de 
l'extourne";
-
-                               $ledger->reverse('01.07.2010');
-                       }
-                       catch (Exception $e)
-                       {
-                               $cn->rollback();
-                               var_dump($e);
-                       }
-                       $cn->commit();
-               }
-       }
-
-       /**
-        * create an array of the existing cat, to be used in a checkbox form
-        *
-        */
-       static function array_cat()
-       {
-               $r = array(
-                       array('cat' => 'VEN', 'name' => _("Journaux de vente")),
-                       array('cat' => 'ACH', 'name' => _("Journaux d'achat")),
-                       array('cat' => 'FIN', 'name' => _("Journaux 
Financier")),
-                       array('cat' => 'ODS', 'name' => _("Journaux 
d'Opérations diverses"))
-               );
-               return $r;
-       }
-
-       /**
-        * Retrieve the third : supplier for purchase, customer for sale, bank 
for fin,
-        * @param $p_jrn_type type of the ledger FIN, VEN ACH or ODS
-        */
-       function get_tiers($p_jrn_type, $jr_id)
-       {
-               if ($p_jrn_type == 'ODS')
-                       return ' ';
-               $tiers = '';
-               switch ($p_jrn_type)
-               {
-                       case 'VEN':
-                               $tiers = $this->db->get_value('select 
max(qs_client) from quant_sold join jrnx using (j_id) join jrn on 
(jr_grpt_id=j_grpt) where jrn.jr_id=$1', array($jr_id));
-                               break;
-                       case 'ACH':
-                               $tiers = $this->db->get_value('select 
max(qp_supplier) from quant_purchase join jrnx using (j_id) join jrn on 
(jr_grpt_id=j_grpt) where jrn.jr_id=$1', array($jr_id));
-
-                               break;
-                       case 'FIN':
-                               $tiers = $this->db->get_value('select qf_other 
from quant_fin where jr_id=$1', array($jr_id));
-                               break;
-               }
-               if ($this->db->count() == 0)
-                       return '';
-               $name = $this->db->get_value('select ad_value from fiche_detail 
where ad_id=1 and f_id=$1', array($tiers));
-               $first_name = $this->db->get_value('select ad_value from 
fiche_detail where ad_id=32 and f_id=$1', array($tiers));
-               return $name . ' ' . $first_name;
-       }
-
-       /**
-        * @brief listing of all ledgers
-        * @return HTML string
-        */
-       function listing()
-       {
-               $str_dossier = dossier::get();
-               $base_url = "?" . dossier::get() . "&ac=" . $_REQUEST['ac'];
-
-               $r = "";
-                $r.=_('Filtre')." 
".HtmlInput::filter_table("cfgledger_table_id", "0", "1");
-               $r.='<TABLE id="cfgledger_table_id" class="vert_mtitle">';
-               $r.='<TR><TD class="first"><A HREF="' . $base_url . '&sa=add">' 
. _('Ajout journal') . ' </A></TD></TR>';
-               $ret = $this->db->exec_sql("select distinct 
jrn_def_id,jrn_def_name,
-                       jrn_def_class_deb,jrn_def_class_cred,jrn_def_type
-                       from jrn_def order by jrn_def_name");
-               $Max = Database::num_row($ret);
-
-
-               for ($i = 0; $i < $Max; $i++)
-               {
-                       $l_line = Database::fetch_array($ret, $i);
-                       $url = $base_url . "&sa=detail&p_jrn=" . 
$l_line['jrn_def_id'];
-                       $r.=sprintf('<TR><TD><A HREF="%s">%s</A></TD></TR>', 
$url, h($l_line['jrn_def_name']).' ('.$l_line['jrn_def_type'].')');
-               }
-               $r.= "</TABLE>";
-               return $r;
-       }
-
-       /**
-        * display detail of a ledger
-        *
-        */
-       function display_ledger()
-       {
-               if ($this->load() == -1)
-               {
-                       throw new Exception(_("Journal n'existe pas"), -1);
-               }
-               $type = $this->jrn_def_type;
-               $name = $this->jrn_def_name;
-               $code = $this->jrn_def_code;
-                $str_add_button="";
-               /* widget for searching an account */
-               $wSearch = new IPoste();
-               $wSearch->set_attribute('ipopup', 'ipop_account');
-               $wSearch->set_attribute('account', 'p_jrn_class_deb');
-               $wSearch->set_attribute('no_overwrite', '1');
-               $wSearch->set_attribute('noquery', '1');
-               $wSearch->table = 3;
-               $wSearch->name = "p_jrn_class_deb";
-               $wSearch->size = 20;
-               $wSearch->value = $this->jrn_def_class_deb;
-               $search = $wSearch->input();
-
-               $wPjPref = new IText();
-               $wPjPref->name = 'jrn_def_pj_pref';
-               $wPjPref->value = $this->jrn_def_pj_pref;
-               $pj_pref = $wPjPref->input();
-
-               $wPjSeq = new INum();
-               $wPjSeq->value = 0;
-               $wPjSeq->name = 'jrn_def_pj_seq';
-               $pj_seq = $wPjSeq->input();
-               $last_seq = $this->get_last_pj();
-               $name = $this->jrn_def_name;
-
-               $hidden = HtmlInput::hidden('p_jrn', $this->id);
-               $hidden.= HtmlInput::hidden('sa', 'detail');
-               $hidden.= dossier::hidden();
-               $hidden.=HtmlInput::hidden('p_jrn_deb_max_line', 10);
-               $hidden.=HtmlInput::hidden('p_ech_lib', 'echeance');
-               $hidden.=HtmlInput::hidden('p_jrn_type', $type);
-
-               $min_row = new INum("min_row",$this->jrn_deb_max_line);
-               $min_row->prec=0;
-                
-                $description=new ITextarea('p_description');
-                $description->style='class="itextarea" style="margin:0px;"';
-                $description->value=$this->jrn_def_description;
-                $str_description=$description->input();
-
-               /* Load the card */
-               $card = $this->get_fiche_def();
-               $rdeb = explode(',', $card['deb']);
-               $rcred = explode(',', $card['cred']);
-               /* Numbering (only FIN) */
-               $num_op = new ICheckBox('numb_operation');
-               if ($this->jrn_def_num_op == 1)
-                       $num_op->selected = true;
-               /* bank card */
-               $qcode_bank = '';
-               if ($type == 'FIN')
-               {
-                       $f_id = $this->jrn_def_bank;
-                       if (isNumber($f_id) == 1)
-                       {
-                               $fBank = new Fiche($this->db, $f_id);
-                               $qcode_bank = $fBank->get_quick_code();
-                       }
-               }
-               $new = 0;
-               $cn = $this->db;
-               echo $hidden;
-               require_once NOALYSS_INCLUDE.'/template/param_jrn.php';
-       }
-
-       /**
-        * Verify before update
-        *
-        * @param type $array
-        *   'p_jrn' => string '3' (length=1)
-         'sa' => string 'detail' (length=6)
-         'gDossier' => string '82' (length=2)
-         'p_jrn_deb_max_line' => string '10' (length=2)
-         'p_ech_lib' => string 'echeance' (length=8)
-         'p_jrn_type' => string 'ACH' (length=3)
-         'p_jrn_name' => string 'Achat' (length=5)
-         'jrn_def_pj_pref' => string 'ACH' (length=3)
-         'jrn_def_pj_seq' => string '0' (length=1)
-         'FICHECRED' =>
-         array
-         0 => string '4' (length=1)
-         'FICHEDEB' =>
-         array
-         0 => string '7' (length=1)
-         1 => string '5' (length=1)
-         2 => string '13' (length=2)
-         'update' => string 'Sauve' (length=5
-        * @exception is throw is test are not valid
-        */
-       function verify_ledger($array)
-       {
-               extract($array);
-               try
-               {
-                       if (isNumber($p_jrn) == 0)
-                               throw new Exception("Id invalide");
-                       if (isNumber($p_jrn_deb_max_line) == 0)
-                               throw new Exception(_("Nombre de ligne 
incorrect"));
-                       if (trim($p_jrn_name) == "")
-                               throw new Exception("Nom de journal invalide");
-                       if ($this->db->get_value("select count(*) from jrn_def 
where jrn_def_name=$1 and jrn_Def_id<>$2", array($p_jrn_name, $p_jrn)) > 0)
-                               throw new Exception(_("Un journal avec ce nom 
existe déjà"));
-                       if ($p_jrn_type == 'FIN')
-                       {
-                               $a = new Fiche($this->db);
-                               $result = 
$a->get_by_qcode(trim(strtoupper($_POST['bank'])), false);
-                               if ($result == 1)
-                                       throw new Exception(_("Aucun compte en 
banque n'est donné"));
-                       }
-                        if ($p_jrn_type == "-1") {
-                            throw new Exception(_('Choix du type de journal 
est obligatoire'));
-                        }
-               }
-               catch (Exception $e)
-               {
-                       throw $e;
-               }
-       }
-
-       /**
-        * update a ledger
-        * @param type $array  normally post
-        * @see verify_ledger
-        */
-       function update($array = '')
-       {
-               if ($array == null)
-                       throw new Exception('save cannot use a empty array');
-
-               extract($array);
-               $this->jrn_def_id = $p_jrn;
-               $this->jrn_def_name = $p_jrn_name;
-               $this->jrn_def_ech_lib = $p_ech_lib;
-               $this->jrn_def_max_line_deb = 
($p_jrn_deb_max_line<1)?1:$p_jrn_deb_max_line;
-               $this->jrn_def_type = $p_jrn_type;
-               $this->jrn_def_pj_pref = $jrn_def_pj_pref;
-               $this->jrn_def_fiche_deb = (isset($FICHEDEB)) ? join($FICHEDEB, 
',') : "";
-               $this->jrn_deb_max_line=($min_row<1)?1:$min_row;
-               $this->jrn_def_description=$p_description;
-               switch ($this->jrn_def_type)
-               {
-                       case 'ACH':
-                       case 'VEN':
-                               $this->jrn_def_fiche_cred = (isset($FICHECRED)) 
? join($FICHECRED, ',') : '';
-                               break;
-                       case 'ODS':
-                               $this->jrn_def_class_deb = $p_jrn_class_deb;
-                               $this->jrn_def_fiche_cred=null;
-                               break;
-                       case 'FIN':
-                               $a = new Fiche($this->db);
-                               $result = 
$a->get_by_qcode(trim(strtoupper($_POST['bank'])), false);
-                               $bank = $a->id;
-                               $this->jrn_def_bank = $bank;
-                               if ($result == -1)
-                                       throw new Exception(_("Aucun compte en 
banque n'est donné"));
-                               $this->jrn_def_num_op = 
(isset($numb_operation)) ? 1 : 0;
-                               break;
-               }
-
-               parent::update();
-               //Reset sequence if needed
-               if ($jrn_def_pj_seq != 0)
-               {
-                       $Res = $this->db->alter_seq("s_jrn_pj" . $p_jrn, 
$jrn_def_pj_seq);
-               }
-       }
-
-       function input_paid()
-       {
-               $r = '';
-               $r.='<div id="payment"> ';
-               $r.='<h2> ' . _('Payé par') . ' </h2>';
-               $mp = new Acc_Payment($this->db);
-               $mp->set_parameter('ledger_source', $this->id);
-               $r.=$mp->select();
-               $r.='</div>';
-               return $r;
-       }
-
-       /**
-        * display screen to enter a new ledger
-        */
-       function input_new()
-       {
-            $retry=HtmlInput::default_value_post("sa", "");
-//            if ( $retry == "add") {
-                $default_type=HtmlInput::default_value_post("p_jrn_type", -1);
-                
$previous_jrn_def_pj_pref=HtmlInput::default_value_post("jrn_def_pj_pref","");
-                
$previous_p_description=HtmlInput::default_value_post("p_description","");
-                
$previous_p_jrn_name=HtmlInput::default_value_post('p_jrn_name','');
-                $previous_p_jrn_type = 
HtmlInput::default_value_post("p_jrn_type","");
-//            }
-                global $g_user;
-                $f_add_button=new ISmallButton('add_card');
-                $f_add_button->label=_('Créer une nouvelle fiche');
-                $f_add_button->tabindex=-1;
-                $f_add_button->set_attribute('jrn',-1);
-                $f_add_button->javascript=" 
this.jrn=-1;select_card_type({type_cat:4});";
-
-                $str_add_button="";
-                if ($g_user->check_action(FICADD)==1)
-                {
-                        $str_add_button=$f_add_button->input();
-                }
-               $wSearch = new IPoste();
-               $wSearch->table = 3;
-               $wSearch->set_attribute('ipopup', 'ipop_account');
-               $wSearch->set_attribute('account', 'p_jrn_class_deb');
-               $wSearch->set_attribute('no_overwrite', '1');
-               $wSearch->set_attribute('noquery', '1');
-
-               $wSearch->name = "p_jrn_class_deb";
-               $wSearch->size = 20;
-
-               $search = $wSearch->input();
-                // default for ACH
-                $default_deb_purchase = $this->get_default_card('ACH', 'D');
-                $default_cred_purchase = $this->get_default_card('ACH', 'C');
-                
-                // default for VEN
-                $default_deb_sale      = $this->get_default_card('VEN', 'D');
-                $default_cred_sale     = $this->get_default_card('VEN', 'C');
-                
-                // default for FIN
-                $default_fin           = $this->get_default_card("FIN", "");
-                
-                //default ods
-                $default_ods          = $this->get_default_card("ODS", "");
-                
-               /* construct all the hidden */
-               $hidden = HtmlInput::hidden('p_jrn', -1);
-               $hidden.= HtmlInput::hidden('p_action', 'jrn');
-               $hidden.= HtmlInput::hidden('sa', 'add');
-               $hidden.= dossier::hidden();
-               $hidden.=HtmlInput::hidden('p_jrn_deb_max_line', 10);
-               $hidden.=HtmlInput::hidden('p_ech_lib', 'echeance');
-
-               /* properties of the ledger */
-               $name = $previous_p_jrn_name;
-               $code = "";
-               $wType = new ISelect();
-                $a_jrn= $this->db->make_array("select '-1',' -- "._("choix du 
type de journal")." -- ' union select jrn_type_id,jrn_desc from jrn_type");
-                $wType->selected='-1';
-               $wType->value =$a_jrn;
-               $wType->name = "p_jrn_type";
-               $wType->id= "p_jrn_type_select_id";
-                $wType->javascript=' onchange="show_ledger_div()"';
-                $wType->selected=$default_type;
-               $type = $wType->input();
-               $rcred = $rdeb = array();
-                $wPjPref = new IText();
-               $wPjPref->name = 'jrn_def_pj_pref';
-                $wPjPref->value=$previous_jrn_def_pj_pref;
-               $pj_pref = $wPjPref->input();
-               $pj_seq = '';
-               $last_seq = 0;
-               $new = 1;
-                $description=new ITextarea('p_description');
-                $description->style='class="itextarea" style="margin:0px;"';
-                $description->value=$previous_p_description;
-                $str_description=$description->input();
-               /* bank card */
-               $qcode_bank = '';
-               /* Numbering (only FIN) */
-               $num_op = new ICheckBox('numb_operation');
-               echo dossier::hidden();
-               echo HtmlInput::hidden('ac', $_REQUEST['ac']);
-                echo $hidden;
-                
-               $cn = $this->db;
-               $min_row = new INum("min_row",MAX_ARTICLE);
-               $min_row->prec=0;
-               require_once NOALYSS_INCLUDE.'/template/param_jrn.php';
-       }
-
-       /**
-        * Insert a new ledger
-        * @param type $array normally $_POST
-        * @see verify_ledger
-        */
-       function save_new($array)
-       {
-               $this->load();
-               extract($array);
-               $this->jrn_def_id = -1;
-               $this->jrn_def_name = $p_jrn_name;
-               $this->jrn_def_ech_lib = $p_ech_lib;
-               $this->jrn_def_max_line_deb = $p_jrn_deb_max_line;
-               $this->jrn_def_type = $p_jrn_type;
-               $this->jrn_def_pj_pref = $jrn_def_pj_pref;
-               $this->jrn_def_fiche_deb = (isset($FICHEDEB)) ? join($FICHEDEB, 
',') : "";
-               $this->jrn_deb_max_line=$min_row;
-               $this->jrn_def_code = sprintf("%s%02d", 
trim(substr($this->jrn_def_type, 0, 1)), Acc_Ledger::next_number($this->db, 
$this->jrn_def_type));
-                $this->jrn_def_description=$p_description;
-               switch ($this->jrn_def_type)
-               {
-                       case 'ACH':
-                       case 'VEN':
-                               $this->jrn_def_fiche_cred = (isset($FICHECRED)) 
? join($FICHECRED, ',') : '';
-
-                               break;
-                       case 'ODS':
-                               $this->jrn_def_class_deb = $p_jrn_class_deb;
-                               $this->jrn_def_fiche_cred = null;
-                               break;
-                       case 'FIN':
-                               $a = new Fiche($this->db);
-                               $result = 
$a->get_by_qcode(trim(strtoupper($_POST['bank'])), false);
-                               $bank = $a->id;
-                               $this->jrn_def_bank = $bank;
-                               if ($result == -1)
-                                       throw new Exception(_("Aucun compte en 
banque n'est donné"));
-                               $this->jrn_def_num_op = 
(isset($numb_operation)) ? 1 : 0;
-                               break;
-               }
-
-               parent::insert();
-       }
-
-       /**
-        * delete a ledger IF is not already used
-        * @exeption : cannot delete
-        */
-       function delete_ledger()
-       {
-               try
-               {
-                       if ($this->db->get_value("select count(jr_id) from jrn 
where jr_def_id=$1", array($this->jrn_def_id)) > 0)
-                               throw new Exception(_("Impossible d'effacer un 
journal qui contient des opérations"));
-                       parent::delete();
-               }
-               catch (Exception $e)
-               {
-                       throw $e;
-               }
-       }
-        /**
-         * Get operation from the ledger type before, after or with the 
-         * given date . The array is filtered by the ledgers granted to the 
-         * user
-         * @global type $g_user
-         * @param $p_date Date (d.m.Y)
-         * @param $p_ledger_type VEN ACH 
-         * @param type $sql_op < > or =
-         * @return array from jrn (jr_id, jr_internal, jr_date, 
jr_comment,jr_pj_number,jr_montant)
-         * @throws Exception
-         */
-       function get_operation_date($p_date,$p_ledger_type,$sql_op)
-       {
-               global $g_user;
-               switch ($p_ledger_type)
-               {
-                       case 'ACH':
-                               $filter=$g_user->get_ledger_sql('ACH',3);
-                               break;
-                       case 'VEN':
-                               $filter=$g_user->get_ledger_sql('VEN',3);
-                               break;
-                       default:
-                               throw new Exception ('Ledger_type invalid : 
'.$p_ledger_type);
-               }
-
-
-               $sql = "select jr_id, jr_internal, jr_date, 
jr_comment,jr_pj_number,jr_montant
-                               from jrn
-                               join jrn_def on (jrn_def_id=jr_def_id)
-                               where
-                               jr_ech is not null
-                               and jr_ech $sql_op to_date($1,'DD.MM.YYYY')
-                               and coalesce (jr_rapt,'xx') <> 'paid'
-                               and $filter
-                               ";
-               $array=$this->db->get_array($sql,array($p_date));
-               return $array;
-       }
-       /**
-        * @brief get info from supplier to pay today
-        */
-       function get_supplier_now()
-       {
-               $array=$this->get_operation_date(Date('d.m.Y'), 'ACH', '=');
-               return $array;
-       }
-       /**
-        * @brief get info from supplier not yet paid
-        */
-       function get_supplier_late()
-       {
-               $array=$this->get_operation_date(Date('d.m.Y'), 'ACH', '<');
-               return $array;
-       }
-       /**
-        * @brief get info from customer to pay today
-        */
-       function get_customer_now()
-       {
-               $array=$this->get_operation_date(Date('d.m.Y'), 'VEN', '=');
-               return $array;
-       }
-       /**
-        * @brief get info from customer not yet paid
-        */
-       function get_customer_late()
-       {
-               $array=$this->get_operation_date(Date('d.m.Y'), 'VEN', '<');
-               return $array;
-       }
-        function convert_from_follow($p_ag_id)
-        {
-            global $g_user;
-            if (isNumber($p_ag_id)==0) return null;
-            if (! $g_user->can_read_action($p_ag_id)) die (_('Action non 
accessible'));
-            $array=array();
-            
-            // retrieve info from action_gestion
-            $tiers_id=$this->db->get_value('select f_id_dest from 
action_gestion where ag_id=$1',array($p_ag_id));
-            if ( $this->db->size() !=0 )
-                $qcode=$this->db->get_value('select j_qcode from 
vw_poste_qcode where f_id=$1',array($tiers_id));
-            else
-                $qcode="";
-            
-            $comment=$this->db->get_value('select ag_title from action_gestion 
where ag_id=$1',array($p_ag_id));
-            $array['e_client']=$qcode;
-            $array['e_comm']=$comment;
-            
-            // retrieve info from action_detail
-            $a_item=$this->db->get_array('select 
f_id,ad_text,ad_pu,ad_quant,ad_tva_id,ad_tva_amount,j_qcode 
-                    from 
-                  action_detail 
-                  left join vw_poste_qcode using(f_id)
-                  where
-                    ag_id=$1',array($p_ag_id));
-            
-            $array['nb_item']=($this->nb > 
count($a_item))?$this->nb:count($a_item);
-            for ($i=0;$i<count($a_item);$i++)
-            {
-                $array['e_march'.$i]=$a_item[$i]['j_qcode'];
-                $array['e_march'.$i.'_label']=$a_item[$i]['ad_text'];
-                $array['e_march'.$i.'_price']=$a_item[$i]['ad_pu'];
-                $array['e_march'.$i.'_tva_id']=$a_item[$i]['ad_tva_id'];
-                
$array['e_march'.$i.'_tva_amount']=$a_item[$i]['ad_tva_amount'];
-                $array['e_quant'.$i]=$a_item[$i]['ad_quant'];
-                
-            }
-            return $array;
-                       
-        }
-        /**
-         * Retrieve the label of an accounting
-         * @param $p_value tmp_pcmn.pcm_val
-         * @return string
-         */
-        protected function find_label($p_value)
-        {
-            $lib=$this->db->get_value('select pcm_lib from tmp_pcmn where 
pcm_val=$1',array($p_value));
-            return $lib;
-        }
-        /**
-         * Let you select the repository before confirming a sale or a 
purchase.
-         * Returns an empty string if the company doesn't use stock
-         * @brief Let you select the repository before confirming a sale or a 
purchase.
-         * @global type $g_parameter check if company is using stock
-         * @param type $p_readonly 
-         * @param type $p_repo
-         * @return string
-         */
-        public function select_depot($p_readonly, $p_repo)
-        {
-            global $g_parameter;
-            $r=($p_readonly==false)?'<div id="repo_div_id" 
style="height:185px;height:10rem;">':'<div id="repo_div_id" >';
-            // Show the available repository
-            if ($g_parameter->MY_STOCK=='Y')
-            {
-                $sel=HtmlInput::select_stock($this->db, 'repo', 'W');
-                $sel->readOnly=$p_readonly;
-                if ($p_readonly==true)
-                    $sel->selected=$p_repo;
-                $r.="<p class=\"decale\">"._('Dans le dépôt')." : ";
-                $r.=$sel->input();
-                $r.='</p>';
-            } else
-            {
-                $r.='<span class="notice">'.'Stock non utilisé'.'</span>';
-            }
-            $r.='</div>';
-            return $r;
-            
-        }
-        /**
-         * Create a button to encode a new operation into the same ledger
-         * @return string
-         */
-        function button_new_operation()
-        {
-            
$url=http_build_query(array('ac'=>$_REQUEST['ac'],'gDossier'=>$_REQUEST['gDossier'],'p_jrn'=>$_REQUEST['p_jrn']));
-            $button = HtmlInput::button_anchor(_("Nouvelle opération"), 
'do.php?'.$url);
-            return '<p>'.$button.'</p>';
-        }
-
-}
-?>
\ No newline at end of file
diff --git a/include/class_acc_ledger_fin.php b/include/class_acc_ledger_fin.php
deleted file mode 100644
index 61e40c5..0000000
--- a/include/class_acc_ledger_fin.php
+++ /dev/null
@@ -1,1143 +0,0 @@
-<?php
-
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/**\file
- * \brief the class Acc_Ledger_Fin inherits from Acc_Ledger, this
- * object permit to manage the financial ledger
- */
-require_once NOALYSS_INCLUDE.'/class_idate.php';
-require_once NOALYSS_INCLUDE.'/class_icard.php';
-require_once NOALYSS_INCLUDE.'/class_ispan.php';
-require_once NOALYSS_INCLUDE.'/class_itext.php';
-require_once NOALYSS_INCLUDE.'/class_iconcerned.php';
-require_once NOALYSS_INCLUDE.'/class_ifile.php';
-require_once NOALYSS_INCLUDE.'/class_ihidden.php';
-require_once NOALYSS_INCLUDE.'/class_iselect.php';
-require_once NOALYSS_INCLUDE.'/class_acc_ledger.php';
-require_once NOALYSS_INCLUDE.'/ac_common.php';
-require_once NOALYSS_INCLUDE.'/class_acc_reconciliation.php';
-
-class Acc_Ledger_Fin extends Acc_Ledger
-{
-
-       function __construct($p_cn, $p_init)
-       {
-               parent::__construct($p_cn, $p_init);
-               $this->type = 'FIN';
-       }
-
-       /**
-         * Verify that the data are correct before inserting or confirming
-         * @brief verify the data 
-        * @param an array (usually $_POST)
-        * @return String
-        * @throw Exception on error occurs
-        */
-
-       public function verify($p_array)
-       {
-               global $g_user;
-                if (is_array($p_array ) == false || empty($p_array))
-                    throw new Exception ("Array empty");
-               /*
-                * Check needed value
-                */
-                check_parameter($p_array,'p_jrn');
-
-                
-               extract($p_array);
-               /* check for a double reload */
-               if (isset($mt) && $this->db->count_sql('select jr_mt from jrn 
where jr_mt=$1', array($mt)) != 0)
-                       throw new Exception(_('Double Encodage'), 5);
-
-               /* check if we can write into this ledger */
-               if ($g_user->check_jrn($p_jrn) != 'W')
-                       throw new Exception(_('Accès interdit'), 20);
-
-               /* check if there is a bank account linked to the ledger */
-               $bank_id = $this->get_bank();
-
-               if ($this->db->count() == 0)
-                       throw new Exception("Ce journal n'a pas de compte en 
banque, allez dans paramètre->journal pour régler cela");
-               /* check if the accounting of the bank is correct */
-               $fBank = new Fiche($this->db, $bank_id);
-               $bank_accounting = $fBank->strAttribut(ATTR_DEF_ACCOUNT);
-               if (trim($bank_accounting) == '')
-                       throw new Exception('Le poste comptable du compte en 
banque de ce journal est invalide');
-
-               /* check if the account exists */
-               $poste = new Acc_Account_Ledger($this->db, $bank_accounting);
-               if ($poste->load() == false)
-                       throw new Exception('Le poste comptable du compte en 
banque de ce journal est invalide');
-               if ($chdate != 1 && $chdate != 2) throw new Exception ('Le 
choix de date est invalide');
-               if ( $chdate == 1 )
-               {
-                       /*  check if the date is valid */
-                       if (isDate($e_date) == null)
-                       {
-                               throw new Exception('Date invalide', 2);
-                       }
-                       $oPeriode = new Periode($this->db);
-                       if ($this->check_periode() == false)
-                       {
-                               $periode = $oPeriode->find_periode($e_date);
-                       }
-                       else
-                       {
-                               $oPeriode->p_id = $periode;
-                               list ($min, $max) = $oPeriode->get_date_limit();
-                               if (cmpDate($e_date, $min) < 0 ||
-                                               cmpDate($e_date, $max) > 0)
-                                       throw new Exception(_('Date et periode 
ne correspondent pas'), 6);
-                       }
-
-                       /* check if the periode is closed */
-                       if ($this->is_closed($periode) == 1)
-                       {
-                               throw new Exception(_('Periode fermee'), 6);
-                       }
-
-                       /* check if we are using the strict mode */
-                       if ($this->check_strict() == true)
-                       {
-                               /* if we use the strict mode, we get the date 
of the last
-                               operation */
-                               $last_date = $this->get_last_date();
-                               if ($last_date != null && cmpDate($e_date, 
$last_date) < 0)
-                                       throw new Exception(_('Vous utilisez le 
mode strict la dernière operation est à la date du ')
-                                                       . $last_date . _(' vous 
ne pouvez pas encoder à une date antérieure'), 15);
-                       }
-               }
-
-               $acc_pay = new Acc_Operation($this->db);
-
-               $nb = 0;
-               $tot_amount = 0;
-               //----------------------------------------
-               // foreach item
-               //----------------------------------------
-               for ($i = 0; $i < $nb_item; $i++)
-               {
-                       if (strlen(trim(${'e_other' . $i})) == 0)
-                               continue;
-                       /* check if amount are numeric and */
-                       if (isNumber(${'e_other' . $i . '_amount'}) == 0)
-                               throw new Exception('La fiche ' . ${'e_other' . 
$i} . 'a un montant invalide [' . ${'e_other' . $i . '_amount'} . ']', 6);
-
-                       /* compute the total */
-                       $tot_amount+=round(${'e_other' . $i . '_amount'}, 2);
-                       /* check if all card has a ATTR_DEF_ACCOUNT */
-                       $fiche = new Fiche($this->db);
-                       $fiche->get_by_qcode(${'e_other' . $i});
-                       if ($fiche->empty_attribute(ATTR_DEF_ACCOUNT) == true)
-                               throw new Exception('La fiche ' . ${'e_other' . 
$i} . 'n\'a pas de poste comptable', 8);
-
-                       $sposte = $fiche->strAttribut(ATTR_DEF_ACCOUNT);
-                       // if 2 accounts, take only the debit one for customer
-                       if (strpos($sposte, ',') != 0)
-                       {
-                               $array = explode(',', $sposte);
-                               $poste_val = $array[1];
-                       }
-                       else
-                       {
-                               $poste_val = $sposte;
-                       }
-                       /* The account exists */
-                       $poste = new Acc_Account_Ledger($this->db, $poste_val);
-                       if ($poste->load() == false)
-                       {
-                               throw new Exception('Pour la fiche ' . 
${'e_other' . $i} . ' le poste comptable [' . $poste->id . 'n\'existe pas', 9);
-                       }
-                       /* Check if the card belong to the ledger */
-                       $fiche = new Fiche($this->db);
-                       $fiche->get_by_qcode(${'e_other' . $i});
-                       if ($fiche->belong_ledger($p_jrn, 'deb') != 1)
-                               throw new Exception('La fiche ' . ${'e_other' . 
$i} . 'n\'est pas accessible à ce journal', 10);
-                       if ($chdate == 2)
-                       {
-                               {/*  check if the date is valid */
-                                       if (isDate(${'dateop' . $i}) == null)
-                                       {
-                                               throw new Exception('Date 
invalide', 2);
-                                       }
-                                       $oPeriode = new Periode($this->db);
-                                       if ($this->check_periode() == false)
-                                       {
-                                               $periode = 
$oPeriode->find_periode(${'dateop' . $i});
-                                       }
-                                       else
-                                       {
-                                               $oPeriode->p_id = $periode;
-                                               list ($min, $max) = 
$oPeriode->get_date_limit();
-                                               if (cmpDate(${'dateop' . $i}, 
$min) < 0 ||
-                                                               
cmpDate(${'dateop' . $i}, $max) > 0)
-                                                       throw new 
Exception(_('Date et periode ne correspondent pas'), 6);
-                                       }
-
-                                       /* check if the periode is closed */
-                                       if ($this->is_closed($periode) == 1)
-                                       {
-                                               throw new Exception(_('Periode 
fermee'), 6);
-                                       }
-
-                                       /* check if we are using the strict 
mode */
-                                       if ($this->check_strict() == true)
-                                       {
-                                               /* if we use the strict mode, 
we get the date of the last
-                                                 operation */
-                                               $last_date = 
$this->get_last_date();
-                                               if ($last_date != null && 
cmpDate(${'dateop' . $i}, $last_date) < 0)
-                                                       throw new 
Exception(_('Vous utilisez le mode strict la dernière operation est à la date 
du ')
-                                                                       . 
$last_date . _(' vous ne pouvez pas encoder à une date antérieure'), 15);
-                                       }
-                               }
-                       }
-                       $nb++;
-               }
-               if ($nb == 0)
-                       throw new Exception('Il n\'y a aucune opération', 12);
-
-               /* Check if the last_saldo and first_saldo are correct */
-               if (strlen(trim($last_sold)) != 0 && isNumber($last_sold) &&
-                               strlen(trim($first_sold)) != 0 && 
isNumber($first_sold))
-               {
-                       $diff = $last_sold - $first_sold;
-                       $diff = round($diff, 2) - round($tot_amount, 2);
-                       if ($first_sold != 0 && $last_sold != 0)
-                       {
-                               if ($diff != 0)
-                                       throw new Exception('Le montant de 
l\'extrait est incorrect' .
-                                                       $tot_amount . ' extrait 
' . $diff, 13);
-                       }
-               }
-       }
-
-       /**\brief
-        * \param $p_array contains the value usually it is $_POST
-        * \return string with html code
-        * \note the form tag are not  set here
-        */
-
-       function input($p_array = null, $notused = 0)
-       {
-               global $g_parameter, $g_user;
-               if ($p_array != null)
-                       extract($p_array);
-
-               $pview_only = false;
-
-               $min_article=$this->get_min_row();
-
-               $f_add_button = new IButton('add_card');
-               $f_add_button->label = _('Créer une nouvelle fiche');
-               $f_add_button->set_attribute('ipopup', 'ipop_newcard');
-               $f_add_button->set_attribute('jrn', $this->id);
-               $f_add_button->javascript = " 
this.jrn=\$('p_jrn').value;select_card_type(this);";
-               $str_add_button = ($g_user->check_action(FICADD) == 1) ? 
$f_add_button->input() : "";
-
-               // The first day of the periode
-               $pPeriode = new Periode($this->db);
-               list ($l_date_start, $l_date_end) = 
$pPeriode->get_date_limit($g_user->get_periode());
-               if ($g_parameter->MY_DATE_SUGGEST == 'Y')
-                       $op_date = (!isset($e_date) ) ? $l_date_start : $e_date;
-               else
-                       $op_date = (!isset($e_date) ) ? '' : $e_date;
-
-               $r = "";
-
-               $r.=dossier::hidden();
-               $f_legend = 'Banque, caisse';
-               //  Date
-               //--
-               $Date = new IDate("e_date", $op_date);
-               $Date->setReadOnly($pview_only);
-               $f_date = $Date->input();
-               $f_period = '';
-               if ($this->check_periode() == true)
-               {
-                       // Periode
-                       //--
-                       $l_user_per = (isset($periode)) ? $periode : 
$g_user->get_periode();
-                       $period = new IPeriod();
-                       $period->cn = $this->db;
-                       $period->type = OPEN;
-                       $period->value = $l_user_per;
-                       $period->user = $g_user;
-                       $period->name = 'periode';
-                       try
-                       {
-                               $l_form_per = $period->input();
-                       }
-                       catch (Exception $e)
-                       {
-                               if ($e->getCode() == 1)
-                               {
-                                       throw  new Exception(_("Aucune période 
ouverte"));
-                                       
-                               }
-                       }
-                       $label = HtmlInput::infobulle(3);
-                       $f_period = "Période comptable $label" . $l_form_per;
-               }
-
-               // Ledger (p_jrn)
-               //--
-               
$onchange="update_bank();ajax_saldo('first_sold');update_name();update_row('fin_item');";
-
-               if ($g_parameter->MY_DATE_SUGGEST == 'Y')
-                       $onchange .= 'get_last_date();';
-               if ($g_parameter->MY_PJ_SUGGEST=='Y')
-                       $onchange .= 'update_pj();';
-
-               $add_js = 'onchange="'.$onchange.'"';
-               $wLedger = $this->select_ledger('FIN', 2);
-               if ($wLedger == null)
-                       throw  new Exception(_('Pas de journal disponible'));
-
-               $wLedger->javascript = $add_js;
-
-               $label = " Journal " . HtmlInput::infobulle(2);
-               $f_jrn = $label . $wLedger->input();
-
-
-               // retrieve bank name, code and account from the 
jrn_def.jrn_def_bank
-
-               $f_bank = '<span id="bkname">' . $this->get_bank_name() . 
'</span>';
-               if ($this->bank_id == "")
-               {
-                       echo h2("Journal de banque non configuré " . 
$this->get_name(), ' class="error"');
-                       echo '<span class="error"> vous devez donner à ce 
journal un compte en banque (fiche), modifiez dans CFGLED</span>';
-                       alert("Journal de banque non configuré " . 
$this->get_name());
-               }
-
-               $f_legend_detail = 'Opérations financières';
-               //--------------------------------------------------
-               // Saldo begin end
-               //-------------------------------------------------
-               // Extrait
-               $default_pj = '';
-               if ($g_parameter->MY_PJ_SUGGEST == 'Y')
-               {
-                       $default_pj = $this->guess_pj();
-               }
-               $wPJ = new IText('e_pj');
-               $wPJ->readonly = false;
-               $wPJ->size = 10;
-               $wPJ->value = (isset($e_pj)) ? $e_pj : $default_pj;
-
-               $f_extrait = $wPJ->input() . HtmlInput::hidden('e_pj_suggest', 
$default_pj);
-               $label = HtmlInput::infobulle(7);
-
-               $first_sold = (isset($first_sold)) ? $first_sold : "";
-               $wFirst = new INum('first_sold', $first_sold);
-
-               $last_sold = isset($last_sold) ? $last_sold : "";
-               $wLast = new INum('last_sold', $last_sold);
-
-
-               $max = (isset($nb_item)) ? $nb_item : $min_article;
-
-               $r.= HtmlInput::hidden('nb_item', $max);
-               //--------------------------------------------------
-               // financial operation
-               //-------------------------------------------------
-
-               $array = array();
-               // Parse each " tiers"
-               for ($i = 0; $i < $max; $i++)
-               {
-                       $tiers = (isset(${"e_other" . $i})) ? ${"e_other" . $i} 
: "";
-
-                       $tiers_amount = (isset(${"e_other$i" . "_amount"})) ? 
round(${"e_other$i" . "_amount"}, 2) : 0;
-
-                       $tiers_comment = (isset(${"e_other$i" . "_comment"})) ? 
${"e_other$i" . "_comment"} : "";
-
-                       $operation_date=new IDate("dateop".$i);
-                       
$operation_date->value=(isset(${'dateop'.$i}))?${'dateop'.$i}:"";
-                       $array[$i]['dateop']=$operation_date->input();
-                       ${"e_other$i" . "_amount"} = (isset(${"e_other$i" . 
"_amount"})) ? ${"e_other$i" . "_amount"} : 0;
-
-                       $W1 = new ICard();
-                       $W1->label = "";
-                       $W1->name = "e_other" . $i;
-                       $W1->id = "e_other" . $i;
-                       $W1->value = $tiers;
-                       $W1->extra = 'deb';  // credits
-                       $W1->typecard = 'deb';
-                        $W1->style=' style = "vertical-align:65%"';
-                       $W1->set_dblclick("fill_ipopcard(this);");
-                       $W1->set_attribute('ipopup', 'ipopcard');
-
-                       // name of the field to update with the name of the card
-                       $W1->set_attribute('label', 'e_other_name' . $i);
-                       // name of the field to update with the name of the card
-                       $W1->set_attribute('typecard', 'filter');
-                       // Add the callback function to filter the card on the 
jrn
-                       $W1->set_callback('filter_card');
-                       $W1->set_function('fill_data');
-                       $W1->javascript = sprintf(' 
onchange="fill_data_onchange(\'%s\');" ', $W1->name);
-                       $W1->readonly = $pview_only;
-                       $array[$i]['qcode'] = $W1->input();
-                       $array[$i]['search'] = $W1->search();
-
-                       // Card name
-                       //
-                        $card_name = "";
-                       if ($tiers != "")
-                       {
-                               $fiche = new Fiche($this->db);
-                               $fiche->get_by_qcode($tiers);
-                               $card_name = $this->db->get_value("Select 
ad_value from fiche_detail where ad_id=$1 and f_id=$2", array(ATTR_DEF_NAME, 
$fiche->id));
-                       }
-
-                       $wcard_name = new IText("e_other_name" . $i, 
$card_name);
-                       $wcard_name->id=$wcard_name->name;
-                       $wcard_name->readOnly = true;
-                       $array[$i]['cname'] = $wcard_name->input();
-
-                       // Comment
-                       $wComment = new IText("e_other$i" . "_comment", 
$tiers_comment);
-
-                       $wComment->size = 35;
-                       $wComment->setReadOnly($pview_only);
-                       $array[$i]['comment'] = $wComment->input();
-                       // amount
-                       $wAmount = new INum("e_other$i" . "_amount", 
$tiers_amount);
-
-                       $wAmount->size = 7;
-                       $wAmount->setReadOnly($pview_only);
-                       $array[$i]['amount'] = $wAmount->input();
-                       // concerned
-                       ${"e_concerned" . $i} = (isset(${"e_concerned" . $i})) 
? ${"e_concerned" . $i} : ""
-                       ;
-                       $wConcerned = new IConcerned("e_concerned" . $i, 
${"e_concerned" . $i});
-                        $wConcerned->tiers="e_other" . $i;
-                       $wConcerned->setReadOnly($pview_only);
-                       $wConcerned->amount_id = "e_other" . $i . "_amount";
-
-                       $wConcerned->paid = 'paid';
-                       $array[$i]['concerned'] = $wConcerned->input();
-               }
-
-               ob_start();
-               require_once NOALYSS_INCLUDE.'/template/form_ledger_fin.php';
-               $r.=ob_get_contents();
-               ob_end_clean();
-               $r.= create_script("$('".$Date->id."').focus()");
-
-               return $r;
-       }
-
-       /**\brief show the summary before inserting into the database, it
-        * calls the function for adding a attachment. The function verify
-        * should be called before
-        * \param $p_array an array usually is $_POST
-        * \return string with code html
-        */
-
-       public function confirm($p_array, $p_nothing = 0)
-       {
-               global $g_parameter,$g_user;
-               $r = "";
-               bcscale(2);
-               extract($p_array);
-               $pPeriode = new Periode($this->db);
-               if ($this->check_periode() == true)
-               {
-                       $pPeriode->p_id = $periode;
-               }
-               else
-               {
-                       if (isDate($e_date) != null) {
-                               $pPeriode->find_periode($e_date);
-                       } else {
-                               $pPeriode->p_id=$g_user->get_periode();
-                       }
-               }
-
-               list ($l_date_start, $l_date_end) = $pPeriode->get_date_limit();
-               $exercice = $pPeriode->get_exercice();
-               $r.='';
-               $r.='<fieldset><legend>Banque, caisse </legend>';
-               $r.= '<div id="jrn_name_div">';
-               $r.='<h2 id="jrn_name" style="display:inline">' . 
$this->get_name() . '</h2>';
-               $r.= '</div>';
-               $r.='<TABLE  width="100%">';
-               //  Date
-               //--
-               $r.="<tr>";
-               if ( $chdate == 1 ) $r.='<td> Date : </td><td>' . $e_date;
-               // Periode
-               //--
-               $r.="<td>";
-               $r.="Période comptable </td><td>";
-               $r.=$l_date_start . ' - ' . $l_date_end;
-               $r.="</td>";
-               $r.="</tr>";
-               // Ledger (p_jrn)
-               //--
-               $r.='<tr>';
-               $r.='<td> Journal </td>';
-               $this->id = $p_jrn;
-               $r.='<td>';
-               $r.=h($this->get_name());
-               $r.='</td>';
-               $r.='</tr>';
-
-               //retrieve bank name
-               $bk_id = $this->get_bank();
-
-               $fBank = new Fiche($this->db, $bk_id);
-               $e_bank_account_label = $this->get_bank_name();
-
-               $filter_year = "  j_tech_per in (select p_id from parm_periode 
where  p_exercice='" . $exercice . "')";
-
-               $acc_account = new Acc_Account_Ledger($this->db, 
$fBank->strAttribut(ATTR_DEF_ACCOUNT));
-               $asolde= $acc_account->get_solde_detail($filter_year);
-               $deb=$asolde['debit'];
-               $cred=$asolde['credit'];
-               $solde=  bcsub($deb, $cred);
-               $new_solde=$solde;
-
-               $r.="<TR><td colspan=\"4\"> Banque ";
-               $r.=$e_bank_account_label;
-
-               $r.="</TABLE>";
-
-               $r.='</fieldset>';
-
-               $r.='<div class="myfieldset"><h1 class="legend">Extrait de 
compte</h1>';
-               //--------------------------------------------------
-               // Saldo begin end
-               //-------------------------------------------------
-               $r.='<table>';
-               $r.='<tr>';
-               // Extrait
-               //--
-               $r.=tr('<td> Numéro d\'extrait</td>' . td(h($e_pj)));
-               $r.='<tr><td >Solde début extrait </td>';
-               $r.='<td style="num">' . nbm($first_sold) . '</td></tr>';
-               $r.='<tr><td>Solde fin extrait </td>';
-               $r.='<td style="num">' . nbm($last_sold) . '</td></tr>';
-               $r.='</table>';
-
-               $r.='<h1 class="legend">Opérations financières</h1>';
-               //--------------------------------------------------
-               // financial operation
-               //-------------------------------------------------
-               $r.='<TABLE style="width:100%" id="fin_item">';
-               $r.="<TR>";
-               if ($chdate==2) $r.='<th>Date</th>';
-               $r.="<th style=\"width:auto;text-align:left\" 
colspan=\"2\">Nom</TH>";
-               $r.="<th style=\"text-align:left\" >Commentaire</TH>";
-               $r.="<th style=\"text-align:right\">Montant</TH>";
-               $r.='<th colspan="2"> Op. Concern&eacute;e(s)</th>';
-
-               /* if we use the AC */
-               if ($g_parameter->MY_ANALYTIC != 'nu')
-               {
-                       $anc = new Anc_Plan($this->db);
-                       $a_anc = $anc->get_list();
-                       $x = count($a_anc);
-                       /* set the width of the col */
-                       $r.='<th colspan="' . $x . '">' . _('Compt. 
Analytique') . '</th>';
-
-                       /* add hidden variables pa[] to hold the value of pa_id 
*/
-                       $r.=Anc_Plan::hidden($a_anc);
-               }
-               $r.="</TR>";
-               // Parse each " tiers"
-               $tot_amount = 0;
-               //--------------------------------------------------
-               // For each items
-               //--------------------------------------------------
-               for ($i = 0; $i < $nb_item; $i++)
-               {
-
-                       $tiers = (isset(${"e_other" . $i})) ? ${"e_other" . $i} 
: ""
-                       ;
-
-                       if (strlen(trim($tiers)) == 0)
-                               continue;
-                       $tiers_label = "";
-                       $tiers_amount = round(${"e_other$i" . "_amount"}, 2);
-                       $tot_amount = bcadd($tot_amount, $tiers_amount);
-                       $tiers_comment = h(${"e_other$i" . "_comment"});
-                       // If $tiers has a value
-                       $fTiers = new Fiche($this->db);
-                       $fTiers->get_by_qcode($tiers);
-
-                       $tiers_label = $fTiers->strAttribut(ATTR_DEF_NAME);
-
-                       $r.="<TR>";
-                       if ($chdate==2) $r.=td(${"dateop".$i});
-                       $r.="<td>" . ${'e_other' . $i} . "</TD>";
-                       // label
-                       $r.='<TD style="width:25%;border-bottom:1px dotted 
grey;">';
-                       $r.=$fTiers->strAttribut(ATTR_DEF_NAME);
-                       $r.='</td>';
-                       // Comment
-                       $r.='<td style="width:40%">' . $tiers_comment . '</td>';
-                       // amount
-                       $r.='<td class="num">' . nbm($tiers_amount) . '</td>';
-                       // concerned
-                       $r.='<td style="text-align:center">';
-                       if (${"e_concerned" . $i} != '')
-                       {
-                               $jr_internal = $this->db->get_array("select 
jr_internal from jrn where jr_id in (" . ${"e_concerned" . $i} . ")");
-                               $comma="";
-                               for ($x = 0; $x < count($jr_internal); $x++)
-                               {
-                                       
$r.=$comma.HtmlInput::detail_op(${"e_concerned" . $i}, 
$jr_internal[$x]['jr_internal']);
-                                       $comma=" , ";
-                               }
-                       }
-                       $r.='</td>';
-                       // encode the pa
-                       if ($g_parameter->MY_ANALYTIC != 'nu' && 
preg_match("/^[6,7]/", $fTiers->strAttribut(ATTR_DEF_ACCOUNT)) == 1) // use of 
AA
-                       {
-                               // show form
-                               $anc_op = new Anc_Operation($this->db);
-                               $null = ($g_parameter->MY_ANALYTIC == 'op') ? 1 
: 0;
-                               $r.='<td>';
-                               $p_mode = 1;
-                               $p_array['pa_id'] = $a_anc;
-                               /* op is the operation it contains either a 
sequence or a jrnx.j_id */
-                               $r.=HtmlInput::hidden('op[]=', $i);
-                               $r.=$anc_op->display_form_plan($p_array, $null, 
$p_mode, $i, $tiers_amount);
-                               $r.='</td>';
-                       }
-
-                       $r.='</TR>';
-               }
-               $r.="</TABLE>";
-
-               // saldo
-               $r.='<br>Ancien solde = ' . $solde;
-               $new_solde+=$tot_amount;
-               $r.='<br>Nouveau solde = ' . $new_solde;
-               $r.='<br>Difference =' . $tot_amount;
-               // check for upload piece
-               $file = new IFile();
-
-               $r.="<br>Ajoutez une pi&egrave;ce justificative ";
-               $r.=$file->input("pj", "");
-
-               $r.='</div>';
-               //--------------------------------------------------
-               // Hidden variables
-               //--------------------------------------------------
-               $r.=dossier::hidden();
-               $r.=HtmlInput::hidden('p_jrn', $this->id);
-               $r.=HtmlInput::hidden('nb_item', $nb_item);
-               $r.=HtmlInput::hidden('last_sold', $last_sold);
-               $r.=HtmlInput::hidden('first_sold', $first_sold);
-               $r.=HtmlInput::hidden('e_pj', $e_pj);
-               $r.=HtmlInput::hidden('e_pj_suggest', $e_pj_suggest);
-               $r.=HtmlInput::hidden('e_date', $e_date);
-               $mt = microtime(true);
-               $r.=HtmlInput::hidden('mt', $mt);
-
-               if (isset($periode))
-                       $r.=HtmlInput::hidden('periode', $periode);
-               $r.=dossier::hidden();
-               $r.=HtmlInput::hidden('sa', 'n','chdate');
-               for ($i = 0; $i < $nb_item; $i++)
-               {
-                       $tiers = (isset(${"e_other" . $i})) ? ${"e_other" . $i} 
: ""                    ;
-                       $r.=HtmlInput::hidden('e_other' . $i, $tiers);
-                       $r.=HtmlInput::hidden('e_other' . $i, $tiers);
-                       $r.=HtmlInput::hidden('e_other' . $i . '_comment', 
${'e_other' . $i . '_comment'});
-                       $r.=HtmlInput::hidden('e_other' . $i . '_amount', 
${'e_other' . $i . '_amount'});
-                       $r.=HtmlInput::hidden('e_concerned' . $i, 
${'e_concerned' . $i});
-                       $r.=HtmlInput::hidden('dateop' . $i, ${'dateop' . $i});
-                       $r.=HtmlInput::hidden('chdate' , $chdate);
-               }
-
-               return $r;
-       }
-
-       /**\brief save the data into the database, included the attachment,
-        * and the reconciliations
-        * \param $p_array usually $_POST
-        * \return string with HTML code
-        */
-
-       public function insert($p_array = null)
-       {
-               global $g_parameter;
-               bcscale(2);
-               $internal_code = "";
-               $oid = 0;
-               extract($p_array);
-               $ret = '';
-               // Debit = banque
-               $bank_id = $this->get_bank();
-               $fBank = new Fiche($this->db, $bank_id);
-               $e_bank_account = $fBank->strAttribut(ATTR_DEF_QUICKCODE);
-               // Get the saldo
-               $pPeriode = new Periode($this->db);
-               $sposte = $fBank->strAttribut(ATTR_DEF_ACCOUNT);
-               // if 2 accounts, take only the debit one for customer
-               if (strpos($sposte, ',') != 0)
-               {
-                       $array = explode(',', $sposte);
-                       $poste_val = $array[0];
-               }
-               else
-               {
-                       $poste_val = $sposte;
-               }
-
-               $acc_account = new Acc_Account_Ledger($this->db, $poste_val);
-
-               // If date = deposit date
-               if ($chdate == 1 )
-               {
-                       if ($this->check_periode() == true)
-                       {
-                               $pPeriode->p_id = $periode;
-                       }
-                       else
-                       {
-                               $pPeriode->find_periode($e_date);
-                       }
-                       $exercice = $pPeriode->get_exercice();
-                       $filter_year = "  j_tech_per in (select p_id from 
parm_periode where  p_exercice='" . $exercice . "')";
-                       $asolde= $acc_account->get_solde_detail($filter_year);
-                       $deb=$asolde['debit'];
-                       $cred=$asolde['credit'];
-                       $solde=  bcsub($deb, $cred);
-                       $new_solde=$solde;
-               }
-
-
-
-
-
-               try
-               {
-                       $this->db->start();
-                       $amount = 0.0;
-                       $idx_operation = 0;
-                       $ret = '<table class="result" >';
-                       $ret.=tr(th('Date').th('n° interne') . th('Quick Code') 
. th('Nom') . th('Libellé') . th('Montant', ' style="text-align:right"'));
-                       // Credit = goods
-                       $get_solde=true;
-                       for ($i = 0; $i < $nb_item; $i++)
-                       {
-                               // insert it into the database
-                               // and quit the loop ?
-                               if (strlen(trim(${"e_other$i"})) == 0)
-                                       continue;
-
-                               if ( $chdate == 2 ) $e_date=${'dateop'.$i};
-                               // if date is date of operation
-                               if ($chdate == 2 && $get_solde )
-                               {
-                                       $get_solde=false;
-                                       if ($this->check_periode() == true)
-                                       {
-                                               $pPeriode->p_id = $periode;
-                                       }
-                                       else
-                                       {
-                                               
$pPeriode->find_periode($e_date);
-                                       }
-                                       $exercice = $pPeriode->get_exercice();
-                                       $filter_year = "  j_tech_per in (select 
p_id from parm_periode where  p_exercice='" . $exercice . "')";
-                                       $solde = 
$acc_account->get_solde($filter_year);
-                                       $new_solde = $solde;
-                               }
-                               $fPoste = new Fiche($this->db);
-                               $fPoste->get_by_qcode(${"e_other$i"});
-
-                               // round it
-                               ${"e_other$i" . "_amount"} = 
round(${"e_other$i" . "_amount"}, 2);
-
-
-
-                               $amount+=${"e_other$i" . "_amount"};
-                               // Record a line for the bank
-                               // Compute the j_grpt
-                               $seq = $this->db->get_next_seq('s_grpt');
-
-                               $acc_operation = new Acc_Operation($this->db);
-                               $acc_operation->date = $e_date;
-                               $sposte = 
$fPoste->strAttribut(ATTR_DEF_ACCOUNT);
-                               // if 2 accounts
-                               if (strpos($sposte, ',') != 0)
-                               {
-                                       $array = explode(',', $sposte);
-                                       if (${"e_other$i" . "_amount"} < 0)
-                                               $poste_val = $array[1];
-                                       else
-                                               $poste_val = $array[0];
-                               }
-                               else
-                               {
-                                       $poste_val = $sposte;
-                               }
-
-
-                               $acc_operation->poste = $poste_val;
-                               $acc_operation->amount = ${"e_other$i" . 
"_amount"} * (-1);
-                               $acc_operation->grpt = $seq;
-                               $acc_operation->jrn = $p_jrn;
-                               $acc_operation->type = 'd';
-
-                               if (isset($periode))
-                                       $tperiode = $periode;
-                               else
-                               {
-                                       $per = new Periode($this->db);
-                                       $tperiode = $per->find_periode($e_date);
-                               }
-                               $acc_operation->periode = $tperiode;
-                               $acc_operation->qcode = ${"e_other" . $i};
-                               $j_id = $acc_operation->insert_jrnx();
-
-                               $acc_operation = new Acc_Operation($this->db);
-                               $acc_operation->date = $e_date;
-                               $sposte = $fBank->strAttribut(ATTR_DEF_ACCOUNT);
-
-                               // if 2 accounts
-                               if (strpos($sposte, ',') != 0)
-                               {
-                                       $array = explode(',', $sposte);
-                                       if (${"e_other$i" . "_amount"} < 0)
-                                               $poste_val = $array[1];
-                                       else
-                                               $poste_val = $array[0];
-                               }
-                               else
-                               {
-                                       $poste_val = $sposte;
-                               }
-
-                               $acc_operation->poste = $poste_val;
-                               $acc_operation->amount = ${"e_other$i" . 
"_amount"};
-                               $acc_operation->grpt = $seq;
-                               $acc_operation->jrn = $p_jrn;
-                               $acc_operation->type = 'd';
-                               $acc_operation->periode = $tperiode;
-                               $acc_operation->qcode = $e_bank_account;
-                               $acc_operation->insert_jrnx();
-
-
-                               if (sql_string(${"e_other$i" . "_comment"}) == 
null)
-                               {
-                                       // if comment is blank set a default one
-                                       $comment = "  compte : " . 
$fBank->strAttribut(ATTR_DEF_NAME) . ' a ' .
-                                                       
$fPoste->strAttribut(ATTR_DEF_NAME);
-                               }
-                               else
-                               {
-                                       $comment = ${'e_other' . $i . 
'_comment'};
-                               }
-
-
-                               $acc_operation = new Acc_Operation($this->db);
-                               $acc_operation->jrn = $p_jrn;
-                               $acc_operation->amount = abs(${"e_other$i" . 
"_amount"});
-                               $acc_operation->date = $e_date;
-                               $acc_operation->desc = $comment;
-                               $acc_operation->grpt = $seq;
-                               $acc_operation->periode = $tperiode;
-                               $acc_operation->mt = $mt;
-                               $idx_operation++;
-                               $acc_operation->pj = '';
-
-                               if (trim($e_pj) != '' && 
$this->numb_operation() == true)
-                                       $acc_operation->pj = $e_pj . 
str_pad($idx_operation, 3, 0, STR_PAD_LEFT);
-
-                               if (trim($e_pj) != '' && 
$this->numb_operation() == false)
-                                       $acc_operation->pj = $e_pj;
-
-                               $jr_id = $acc_operation->insert_jrn();
-                               //        $acc_operation->set_pj();
-                               $this->db->exec_sql('update jrn set 
jr_pj_number=$1 where jr_id=$2', array($acc_operation->pj, $jr_id));
-                               $internal = $this->compute_internal_code($seq);
-
-
-                               if (trim(${"e_concerned" . $i}) != "")
-                               {
-                                       if (strpos(${"e_concerned" . $i}, ',') 
!= 0)
-                                       {
-                                               $aRapt = explode(',', 
${"e_concerned" . $i});
-                                               foreach ($aRapt as $rRapt)
-                                               {
-                                                       // Add a "concerned 
operation to bound these op.together
-                                                       //
-                                                        $rec = new 
Acc_Reconciliation($this->db);
-                                                       $rec->set_jr_id($jr_id);
-
-                                                       if (isNumber($rRapt) == 
1)
-                                                       {
-                                                               
$rec->insert($rRapt);
-                                                       }
-                                               }
-                                       }
-                                       else
-                                       if (isNumber(${"e_concerned" . $i}) == 
1)
-                                       {
-                                               $rec = new 
Acc_Reconciliation($this->db);
-                                               $rec->set_jr_id($jr_id);
-                                               
$rec->insert(${"e_concerned$i"});
-                                       }
-                               }
-
-                               // Set Internal code
-                               $this->grpt_id = $seq;
-                               /**
-                                * save also into quant_fin
-                                */
-                               $this->insert_quant_fin($fBank->id, $jr_id, 
$fPoste->id, ${"e_other$i" . "_amount"});
-
-                               if ($g_parameter->MY_ANALYTIC != "nu")
-                               {
-                                       // for each item, insert into 
operation_analytique */
-                                       $op = new Anc_Operation($this->db);
-                                       $op->oa_group = 
$this->db->get_next_seq("s_oa_group"); /* for analytic */
-                                       $op->j_id = $j_id;
-                                       $op->oa_date = $e_date;
-                                       $op->oa_debit = 'f';
-                                       $op->oa_description = 
sql_string($comment);
-                                       $op->save_form_plan($_POST, $i, $j_id);
-                               }
-
-
-                               $this->update_internal_code($internal);
-
-                               $js_detail = HtmlInput::detail_op($jr_id, 
$internal);
-                               // Compute display
-                               $row = td($e_date).td($js_detail) . 
td(${"e_other$i"}) . td($fPoste->strAttribut(ATTR_DEF_NAME)) . td(${"e_other" . 
$i . "_comment"}) . td(nbm(${"e_other$i" . "_amount"}), 'class="num"');
-                                $class=($i%2==0)?' class="even" ':' 
class="odd" ';
-                               $ret.=tr($row,$class);
-
-
-                               if ($i == 0)
-                               {
-                                       // first record we upload the files and
-                                       // keep variable to update other row of 
jrn
-                                       if (isset($_FILES))
-                                               $oid = 
$this->db->save_upload_document($seq);
-                               }
-                               else
-                               {
-                                       if ($oid != 0)
-                                       {
-                                            $this->db->exec_sql("update jrn 
set jr_pj=$1 , jr_pj_name=$2,
-                                            jr_pj_type=$3  where 
jr_grpt_id=$4",
-                                                
array($oid,$_FILES['pj']['name'] ,$_FILES['pj']['type'],$seq));
-                                       }
-                               }
-                       } // for nbitem
-                       // increment pj
-                       if (strlen(trim($e_pj)) != 0)
-                       {
-                               $this->inc_seq_pj();
-                       }
-                       $ret.='</table>';
-               }
-               catch (Exception $e)
-               {
-                       $r = '<span class="error">' .
-                       'Erreur dans l\'enregistrement ' .
-                       __FILE__ . ':' . __LINE__ . ' ' .
-                       $e->getMessage();
-                       $this->db->rollback();
-                       throw new Exception($r);
-               }
-               $this->db->commit();
-               $r = "";
-               $r.="<br>Ancien solde " . nbm($solde);
-               $new_solde = bcadd($new_solde, $amount);
-               $r.="<br>Nouveau solde " . nbm($new_solde);
-               $ret.=$r;
-               return $ret;
-       }
-
-       /**\brief display operation of a FIN ledger
-        * \return html code into a string
-        */
-
-       function show_ledger()
-       {
-               global $g_user;
-               echo dossier::hidden();
-               $hid = new IHidden();
-
-               $hid->name = "p_action";
-               $hid->value = "bank";
-               echo $hid->input();
-
-
-               $hid->name = "sa";
-               $hid->value = "l";
-               echo $hid->input();
-
-
-               $w = new ISelect();
-               // filter on the current year
-               $filter_year = " where p_exercice='" . $g_user->get_exercice() 
. "'";
-
-               $periode_start = $this->db->make_array("select 
p_id,to_char(p_start,'DD-MM-YYYY') from parm_periode $filter_year order by 
p_start,p_end", 1);
-               // User is already set User=new User($this->db);
-               $current = (isset($_GET['p_periode'])) ? $_GET['p_periode'] : 
-1;
-               $w->selected = $current;
-
-               echo '<form>';
-               echo 'Période  ' . $w->input("p_periode", $periode_start);
-               $wLedger = $this->select_ledger('fin', 3);
-
-               if ($wLedger == null)
-                       throw  new Exception(_('Pas de journal disponible'));
-
-               if (count($wLedger->value) > 1)
-               {
-                       $aValue = $wLedger->value;
-                       $wLedger->value[0] = array('value' => -1, 'label' => 
_('Tous les journaux financiers'));
-                       $idx = 1;
-                       foreach ($aValue as $a)
-                       {
-                               $wLedger->value[$idx] = $a;
-                               $idx++;
-                       }
-               }
-
-
-
-               echo 'Journal ' . $wLedger->input();
-               $w = new ICard();
-               $w->noadd = 'no';
-               $w->jrn = $this->id;
-               $qcode = (isset($_GET['qcode'])) ? $_GET['qcode'] : "";
-               echo dossier::hidden();
-               echo HtmlInput::hidden('p_action', 'bank');
-               echo HtmlInput::hidden('sa', 'l');
-               $w->name = 'qcode';
-               $w->value = $qcode;
-               $w->label = '';
-               $this->type = 'FIN';
-               $all = $this->get_all_fiche_def();
-               $w->extra = $all;
-               $w->extra2 = 'QuickCode';
-               $sp = new ISpan();
-               echo $sp->input("qcode_label", "", $qcode);
-               echo $w->input();
-
-               echo HtmlInput::submit('gl_submit', _('Rechercher'));
-               echo '</form>';
-
-               // Show list of sell
-               // Date - date of payment - Customer - amount
-               if ($current != -1)
-               {
-                       $filter_per = " and jr_tech_per=" . $current;
-               }
-               else
-               {
-                       $filter_per = " and jr_tech_per in (select p_id from 
parm_periode where p_exercice::integer=" .
-                                       $g_user->get_exercice() . ")";
-               }
-               /* security  */
-               if ($this->id != -1)
-                       $available_ledger = " and jr_def_id= " . $this->id . " 
and " . $g_user->get_ledger_sql();
-               else
-                       $available_ledger = " and " . $g_user->get_ledger_sql();
-               // Show list of sell
-               // Date - date of payment - Customer - amount
-               $sql = SQL_LIST_ALL_INVOICE . $filter_per . " and 
jr_def_type='FIN'" .
-                               " $available_ledger";
-               $step = $_SESSION['g_pagesize'];
-               $page = (isset($_GET['offset'])) ? $_GET['page'] : 1;
-               $offset = (isset($_GET['offset'])) ? $_GET['offset'] : 0;
-
-               $l = "";
-
-               // check if qcode contains something
-               if ($qcode != "")
-               {
-                       // add a condition to filter on the quick code
-                       $l = " and jr_grpt_id in (select j_grpt from jrnx where 
j_qcode=upper('$qcode')) ";
-               }
-
-               list($max_line, $list) = ListJrn($this->db, "where 
jrn_def_type='FIN' $filter_per $l $available_ledger "
-                               , null, $offset, 0);
-               $bar = navigation_bar($offset, $max_line, $step, $page);
-
-               echo "<hr> $bar";
-               echo $list;
-               echo "$bar <hr>";
-       }
-
-       /**
-        * return a string with the bank account, name and quick_code
-        */
-       function get_bank_name()
-       {
-               $this->bank_id = $this->db->get_value('select jrn_def_bank from 
jrn_def where jrn_def_id=$1', array($this->id));
-               $fBank = new Fiche($this->db, $this->bank_id);
-               $e_bank_account = " : " . $fBank->strAttribut(ATTR_DEF_BQ_NO);
-               $e_bank_name = " : " . $fBank->strAttribut(ATTR_DEF_NAME);
-               $e_bank_qcode = ": " . $fBank->strAttribut(ATTR_DEF_QUICKCODE);
-               return $e_bank_qcode . $e_bank_name . $e_bank_account;
-       }
-
-       /**
-        * return the fiche_id of the bank
-        */
-       function get_bank()
-       {
-               $bank_id = $this->db->get_value('select jrn_def_bank from 
jrn_def where jrn_def_id=$1', array($this->id));
-               return $bank_id;
-       }
-
-       /**
-        * return true is we numbere each operation
-        */
-       function numb_operation()
-       {
-               $a = $this->db->get_value('select jrn_def_num_op from jrn_def 
where jrn_def_id=$1', array($this->id));
-               if ($a == 1)
-                       return true;
-               return false;
-       }
-
-       /**
-        * insert into the quant_fin table
-        * @param $bank_id is the f_id of the bank
-        * @param $jr_id is the jrn.jr_id of the operation
-        * @param $other is the f_id of the benefit
-        * @param $amount is the amount
-        */
-       function insert_quant_fin($p_bankid, $p_jrid, $p_otherid, $p_amount)
-       {
-               $sql = "INSERT INTO quant_fin(qf_bank, jr_id, qf_other, 
qf_amount)
-                   VALUES ($1, $2, $3, $4);";
-
-               $this->db->exec_sql($sql, array($p_bankid, $p_jrid, $p_otherid, 
round($p_amount, 2)));
-       }
-
-}
diff --git a/include/class_acc_ledger_info.php 
b/include/class_acc_ledger_info.php
deleted file mode 100644
index 398ff94..0000000
--- a/include/class_acc_ledger_info.php
+++ /dev/null
@@ -1,216 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-// Copyright Author Dany De Bontridder address@hidden
-require_once  NOALYSS_INCLUDE.'/class_dossier.php';
-require_once  NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/ac_common.php';
-
-/*!\file
- * \brief Manage additional info for Accountancy
- */
-
-/*!
- * \brief Manage the additionnal info for operation (from jrn), when an 
invoice is generated, 
- * the order or other info are going to be stored and used in the detail.
- * this class maps the table jrn_info
- */
-class Acc_Ledger_Info
-{
-    var $cn;    /*!< connection */
-    var $ji_id;    /*!< primary key */
-    var $id_type;    /*!< type id */
-    var $jr_id;    /*!< primary key of the table jrn */
-    var $ji_value;     /*!< value for this */
-    function __construct($p_cn,$p_ji_id=0)
-    {
-        $this->cn=$p_cn;
-        $this->ji_id=$p_ji_id;
-    }
-    function insert()
-    {
-        if ( ! isset ($this->jr_id) ||
-                ! isset ($this->ji_value) ||
-                ! isset ($this->id_type ) )
-        {
-            echo 'Appel incorrecte '.__FILE__.__LINE__;
-            var_dump($this);
-            throw new Exception(_('appel incorrect'));
-        }
-        try
-        {
-            $sql=$this->cn->exec_sql('insert into 
jrn_info(jr_id,id_type,ji_value) values ($1,$2,$3)'.
-                                     ' returning ji_id ',
-                                     array 
($this->jr_id,$this->id_type,$this->ji_value)
-                                    );
-            $this->ji_id=Database::fetch_result($sql,0,0);
-        }
-        catch (Exception $e)
-        {
-            echo "Echec sauvegarde info additionnelles";
-            throw $e;
-        }
-    }
-    function update()
-    {
-        if ( ! isset ($this->jr_id) ||
-                ! isset ($this->ji_value) ||
-                ! isset ($this->jr_id ) )
-        {
-            echo 'Appel incorrecte '.__FILE__.__LINE__;
-            var_dump($this);
-            throw  new Exception('appel incorrect');
-        }
-        try
-        {
-            $sql=$this->exec_sql('update jrn_info set jr_id=$1 
,id_type=$2,ji_value=$3 where ji_id=$4)'.
-                                 array 
($this->jr_id,$this->id_type,$this->ji_value,$this->ji_id)
-                                );
-        }
-        catch (Exception $e)
-        {
-            $this->cn->rollback();
-            echo "Echec sauvegarde info additionnelles";
-            throw $e;
-        }
-    }
-    function load()
-    {
-        $sql="select jr_id,id_type,ji_value from jrn_info where 
ji_id=".$this->ji_id;
-        $r=$this->cn->exec_sql($sql);
-        if (Database::num_row ($r) > 0 )
-        {
-            $this->from_array(Database::fetch_array($r,0));
-            return 0;
-        }
-        else
-        {
-            return 1;
-        }
-
-    }
-    function from_array($p_array)
-    {
-        foreach ($p_array as $col=>$value)
-        {
-            $this->$col=$value;
-        }
-    }
-    function set_id($p_ji_id)
-    {
-        $this->$ji_id=$p_ji_id;
-    }
-    function set_jrn_id($p_id)
-    {
-        $this->jr_id=$p_id;
-    }
-    function set_type($p_id)
-    {
-        $this->id_type=$p_id;
-    }
-    function set_value($p_id)
-    {
-        $this->ji_value=$p_id;
-    }
-    /*!\brief load all the jrn_info thanks the jr_id
-     * \return an array of object
-     */
-    function load_all()
-    {
-        if ( ! isset ($this->jr_id) )
-        {
-            echo "jr_id is not set ".__FILE__.__LINE__;
-            throw new Exception('Error : jr_id not set');
-        }
-
-        $sql="select ji_id from jrn_info where jr_id=".$this->jr_id;
-        $r=$this->cn->exec_sql($sql);
-        if (Database::num_row($r) == 0 )
-            return array();
-        $array=Database::fetch_all($r);
-        $ret=array();
-        foreach ($array as $row)
-        {
-            $o=new Acc_Ledger_Info($this->cn,$row['ji_id']);
-            $o->load();
-            $ret[]=clone $o;
-        }
-        return $ret;
-
-    }
-    function count()
-    {
-        $sql="select ji_id from jrn_info where jr_id=".$this->jr_id;
-        return $this->cn->count_sql($sql);
-    }
-    function search_id_internal($p_internal)
-    {
-        $sql="select jr_id from jrn where jr_internal='$p_internal'";
-        $r=$this->cn->exec_sql($sql);
-        if (Database::num_row($r) > 0 )
-        {
-            $this->jr_id=Database::fetch_result($r,0,0);
-            return $this->jr_id;
-        }
-        else
-        {
-            $this->jr_id=-1;
-            return $this->jr_id;
-        }
-    }
-    /**
-     address@hidden save all extra information in once, called by compta_ven 
and compta_ach
-     address@hidden $p_jr_id is the jrn.jr_id concerned, 
-     address@hidden $p_array is the array with the data usually it is $_POST
-     address@hidden will change this->jr_id
-     address@hidden compta_ven.inc.php compta_ach.inc.php
-     */
-    function save_extra($p_jr_id,$p_array)
-    {
-        $this->jr_id=$p_jr_id;
-        if (strlen(trim($p_array['bon_comm'] )) != 0 )
-        {
-            $this->set_type('BON_COMMANDE');
-            $this->set_value($p_array['bon_comm']);
-            $this->insert();
-        }
-        if (strlen(trim($p_array['other_info'] )) != 0 )
-        {
-            $this->set_type('OTHER');
-            $this->set_value($p_array['other_info']);
-            $this->insert();
-        }
-    }
-    static function test_me()
-    {
-        echo "Dossier = ".Dossier::id();
-        $cn=new Database(Dossier::id());
-        $a=new Acc_Ledger_Info($cn);
-        $a->jr_id=3;
-        $a->id_type='BON_COMMANDE';
-        $a->ji_value='BON';
-        var_dump($a);
-        $a->insert();
-
-        $a->set_jrn_id(7);
-        $a->set_type('OTHER');
-        $a->set_value('Autre test');
-        $a->insert();
-    }
-}
diff --git a/include/class_acc_ledger_purchase.php 
b/include/class_acc_ledger_purchase.php
deleted file mode 100644
index 2036366..0000000
--- a/include/class_acc_ledger_purchase.php
+++ /dev/null
@@ -1,1790 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief class for the purchase, herits from acc_ledger
- */
-require_once NOALYSS_INCLUDE.'/class_iselect.php';
-require_once NOALYSS_INCLUDE.'/class_icard.php';
-require_once NOALYSS_INCLUDE.'/class_ispan.php';
-require_once NOALYSS_INCLUDE.'/class_ihidden.php';
-require_once NOALYSS_INCLUDE.'/class_iperiod.php';
-require_once NOALYSS_INCLUDE.'/class_idate.php';
-require_once NOALYSS_INCLUDE.'/class_itext.php';
-require_once NOALYSS_INCLUDE.'/class_ifile.php';
-require_once NOALYSS_INCLUDE.'/class_acc_ledger.php';
-require_once NOALYSS_INCLUDE.'/class_acc_compute.php';
-require_once NOALYSS_INCLUDE.'/class_anc_operation.php';
-require_once NOALYSS_INCLUDE.'/user_common.php';
-require_once NOALYSS_INCLUDE.'/class_acc_parm_code.php';
-require_once NOALYSS_INCLUDE.'/class_acc_payment.php';
-require_once NOALYSS_INCLUDE.'/ac_common.php';
-require_once NOALYSS_INCLUDE.'/class_itva_popup.php';
-require_once NOALYSS_INCLUDE.'/class_acc_ledger_info.php';
-require_once NOALYSS_INCLUDE.'/class_acc_ledger_fin.php';
-require_once NOALYSS_INCLUDE.'/class_stock_goods.php';
-
-/*!\brief Handle the ledger of purchase,
- *
- *
- */
-class  Acc_Ledger_Purchase extends Acc_Ledger
-{
-    function __construct ($p_cn,$p_init)
-    {
-        $this->type='ACH';
-        parent::__construct($p_cn,$p_init);
-    }
-    /*!\brief verify that the data are correct before inserting or confirming
-     *\param an array (usually $_POST)
-     *\return String
-     *\throw Exception if an error occurs
-     */
-    public function verify($p_array)
-    {
-        global $g_parameter,$g_user;
-        
-        if (is_array($p_array ) == false || empty($p_array))
-                    throw new Exception ("Array empty");
-        /*
-         * Check needed value
-         */
-        check_parameter($p_array,'p_jrn,e_date,e_client');
-
-        extract ($p_array);
-        /* check if we can write into this ledger */
-        if ( $g_user->check_jrn($p_jrn) != 'W' )
-            throw new Exception (_('Accès interdit'),20);
-
-
-        /* check for a double reload */
-        if (  isset($mt) && $this->db->count_sql('select jr_mt from jrn where 
jr_mt=$1',array($mt)) != 0 )
-            throw new Exception (_('Double Encodage'),5);
-
-        /* check if there is a customer */
-        if ( strlen(trim($e_client)) == 0 )
-            throw new Exception(_('Vous n\'avez pas donné de fournisseur'),11);
-
-        /*  check if the date is valid */
-        if ( isDate($e_date) == null )
-        {
-            throw new Exception(_('Date invalide'), 2);
-        }
-        $oPeriode=new Periode($this->db);
-        if ( $this->check_periode() == false)
-        {
-            $tperiode=$oPeriode->find_periode($e_date);
-        }
-        else
-        {
-            $tperiode=$period;
-            $oPeriode->p_id=$tperiode;
-            /* check that the datum is in the choosen periode */
-            list ($min,$max)=$oPeriode->get_date_limit($tperiode);
-            if ( cmpDate($e_date,$min) < 0 ||
-                    cmpDate($e_date,$max) > 0)
-                throw new Exception(_('Date et periode ne correspondent 
pas'),6);
-        }
-        /* check if the periode is closed */
-        if ( $this->is_closed($tperiode)==1 )
-        {
-            throw new Exception(_('Periode fermee'),6);
-        }
-
-        /* check if we are using the strict mode */
-        if( $this->check_strict() == true)
-        {
-            /* if we use the strict mode, we get the date of the last
-            operation */
-            $last_date=$this->get_last_date();
-            if ( $last_date != null  && cmpDate($e_date,$last_date) < 0 )
-                throw new Exception(_('Vous utilisez le mode strict la 
dernière operation est à la date du ')
-                                    .$last_date._(' vous ne pouvez pas encoder 
à une '.
-                                                  ' date antérieure dans ce 
journal'),13);
-
-        }
-
-        /* check the account */
-        $fiche=new Fiche($this->db);
-        $fiche->get_by_qcode($e_client);
-
-        if ( $fiche->empty_attribute(ATTR_DEF_ACCOUNT) == true)
-            throw new Exception(_('La fiche ').$e_client._('n\'a pas de poste 
comptable'),8);
-
-        /* get the account and explode if necessary */
-        $sposte=$fiche->strAttribut(ATTR_DEF_ACCOUNT);
-        // if 2 accounts, take only the credit one for supplier
-        if ( strpos($sposte,',') != 0 )
-        {
-            $array=explode(',',$sposte);
-            $poste_val=$array[1];
-        }
-        else
-        {
-            $poste_val=$sposte;
-        }
-
-        /* The account exists */
-        $poste=new Acc_Account_Ledger($this->db,$poste_val);
-        if ( $poste->load() == false )
-        {
-            throw new Exception(_('Pour la fiche ').$e_client._(' le poste 
comptable [').$poste->id.'] '._('n\'existe pas'),9);
-        }
-        /* Check if the card belong to the ledger */
-        $fiche=new Fiche ($this->db);
-        $fiche->get_by_qcode($e_client,'cred');
-        if ( $fiche->belong_ledger($p_jrn) !=1 )
-            throw new Exception(_('La fiche ').$e_client._('n\'est pas 
accessible à ce journal'),10);
-
-        $nb=0;
-        //------------------------------------------------------
-        // The "Paid By"  check
-        //------------------------------------------------------
-        if ($e_mp != 0 ) $this->check_payment($e_mp,${"e_mp_qcode_".$e_mp});
-
-
-        //----------------------------------------
-        // foreach item
-        //----------------------------------------
-        for ($i=0;$i< $nb_item;$i++)
-        {
-            if ( strlen(trim(${'e_march'.$i}))== 0) continue;
-            /* check if amount are numeric and */
-            if ( isNumber(${'e_march'.$i.'_price'}) == 0 )
-                throw new Exception(_('La fiche ').${'e_march'.$i}._('a un 
montant invalide').' ['.${'e_march'.$i}.']',6);
-            if ( isNumber(${'e_quant'.$i}) == 0 )
-                throw new Exception(_('La fiche ').${'e_march'.$i}._('a une 
quantité invalide').' ['.${'e_quant'.$i}.']',7);
-
-            // Check if the given tva id is valid
-            if ( $g_parameter->MY_TVA_USE=='Y')
-            {
-                if (${'e_march'.$i.'_tva_id'} == 0 )
-                    throw new Exception(_('La fiche ').${'e_march'.$i}._('a un 
code tva invalide').' ['.${'e_march'.$i.'_tva_id'}.']',13);
-                $tva_rate=new Acc_Tva($this->db);
-                $tva_rate->set_parameter('id',${'e_march'.$i.'_tva_id'});
-
-                if ( $tva_rate->load() != 0 )
-                    throw new Exception(_('La fiche ').${'e_march'.$i}._('a un 
code tva invalide').' ['.${'e_march'.$i.'_tva_id'}.']',13);
-               /*
-                * check if the accounting for VAT are valid
-                */
-               $a_poste=explode(',',$tva_rate->tva_poste);
-
-               if (
-                   $this->db->get_value('select count(*) from tmp_pcmn where 
pcm_val=$1',array($a_poste[0])) == 0 ||
-                   $this->db->get_value('select count(*) from tmp_pcmn where 
pcm_val=$1',array($a_poste[1])) == 0 )
-                 throw new Exception(_(" La TVA ".$tva_rate->tva_label." 
utilise des postes comptables inexistants"));
-
-            }
-            /* check if all card has a ATTR_DEF_ACCOUNT*/
-            $fiche=new Fiche($this->db);
-            $fiche->get_by_qcode(${'e_march'.$i});
-            if ( $fiche->empty_attribute(ATTR_DEF_ACCOUNT) == true)
-                throw new Exception(_('La fiche ').${'e_march'.$i}._('n\'a pas 
de poste comptable'),8);
-
-            /* get the account and explode if necessary */
-            $sposte=$fiche->strAttribut(ATTR_DEF_ACCOUNT);
-            // if 2 accounts, take only the  debit
-            if ( strpos($sposte,',') != 0 )
-            {
-                $array=explode(',',$sposte);
-                $poste_val=$array[0];
-            }
-            else
-            {
-                $poste_val=$sposte;
-            }
-
-            /* The account exists */
-            $poste=new Acc_Account_Ledger($this->db,$poste_val);
-            if ( $poste->load() == false )
-            {
-                throw new Exception(_('Pour la fiche ').${'e_march'.$i}._(' le 
poste comptable').' ['.$poste->id._('n\'existe pas'),9);
-            }
-            /* Check if the card belong to the ledger */
-            $fiche=new Fiche ($this->db);
-            $fiche->get_by_qcode(${'e_march'.$i});
-            if ( $fiche->belong_ledger($p_jrn,'deb') !=1 )
-                throw new Exception(_('La fiche ').${'e_march'.$i}._('n\'est 
pas accessible à ce journal'),10);
-            /**
-             * we have to check also if the different accountings exist
-             "ATTR_DEF_DEP_PRIV"
-             "ATTR_DEF_DEPENSE_NON_DEDUCTIBLE"
-             "ATTR_DEF_TVA_NON_DEDUCTIBLE"
-             "ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP"
-            */
-            foreach (array(
-                          
array(ATTR_DEF_DEPENSE_NON_DEDUCTIBLE,'DNA',ATTR_DEF_ACCOUNT_ND),
-                          
array(ATTR_DEF_DEP_PRIV,'DEP_PRIV',ATTR_DEF_ACCOUNT_ND_PERSO),
-                          
array(ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP,'TVA_DED_IMPOT',ATTR_DEF_ACCOUNT_ND_TVA),
-                          
array(ATTR_DEF_TVA_NON_DEDUCTIBLE,'TVA_DNA',ATTR_DEF_ACCOUNT_ND_TVA_ND)) as 
$key)
-             {
-                if ( ! $fiche->empty_attribute($key[0]) &&  
$fiche->empty_attribute($key[2]))
-                 {
-                    $a=new Acc_Parm_Code($this->db,$key[1]);
-                    if ( $this->db->count_sql('select pcm_val from tmp_pcmn 
where pcm_val=$1',array($a->p_value))==0)
-                     throw new Exception ($key[1]._("ce code n'a pas de poste 
comptable, créez ce poste : [".$a->p_value."]"));
-                 }
-               if ( ! $fiche->empty_attribute($key[0]) &&  ! 
$fiche->empty_attribute($key[2]))
-                 {
-                   $nd_str=$fiche->strAttribut($key[2]);
-                   if ( $nd_str != '')
-                     {
-                       $poste_nd=new Acc_Account_Ledger($this->db,$nd_str);
-                       if ( $poste_nd->load() == false)
-                         {
-                           $nd_msg=sprintf(_("Pour la fiche %s, le compte 
contrepartie %s n'existe pas"),
-                                           $fiche->getName(),$poste_nd->id);
-                           $nd_msg=h($nd_msg);
-                           throw new Exception ($nd_msg);
-                         }
-                     }
-                 }
-             }
-           $nb++;
-        }
-
-        if ( $nb == 0 )
-            throw new Exception(_('Il n\'y a aucune marchandise'),12);
-
-    }
-    /**
-     * Compute the ND amount thanks the attribute of the concerned card. The 
object 
-     * $p_nd_amount will changed
-     * 
-     * @param Acc_Compute $p_nd_amount object with ND amount
-     * @param Fiche $p_fiche Concerned Card (purchase items)
-     * @param type $p_tva_bot 0 TVA on one side, 1 TVA on both side
-     */
-    private function compute_no_deductible(Acc_Compute $p_nd_amount, Fiche 
$p_fiche)
-    {
-        if (!$p_fiche->empty_attribute(ATTR_DEF_DEPENSE_NON_DEDUCTIBLE))
-        {
-            $p_nd_amount->amount_nd_rate = 
$p_fiche->strAttribut(ATTR_DEF_DEPENSE_NON_DEDUCTIBLE);
-            $p_nd_amount->compute_nd();
-        }
-        if (!$p_fiche->empty_attribute(ATTR_DEF_TVA_NON_DEDUCTIBLE) )
-        {
-            $p_nd_amount->nd_vat_rate = 
$p_fiche->strAttribut(ATTR_DEF_TVA_NON_DEDUCTIBLE);
-            $p_nd_amount->compute_nd_vat();
-        }
-        if (!$p_fiche->empty_attribute(ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP) )
-        {
-            $p_nd_amount->nd_ded_vat_rate = 
$p_fiche->strAttribut(ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP);
-            $p_nd_amount->compute_ndded_vat();
-        }
-
-        if (!$p_fiche->empty_attribute(ATTR_DEF_DEP_PRIV))
-        {
-            $p_nd_amount->amount_perso_rate = 
$p_fiche->strAttribut(ATTR_DEF_DEP_PRIV);
-            $p_nd_amount->compute_perso();
-        }
-
-    }
-
-    /**
-     * Insert into JRNX the No Deductible amount and into Analytic Accountancy 
for the ND VAT
-     * @param Acc_Compute $p_nd_amount content ND amount
-     * @param Fiche $p_fiche Card of the Service
-     * @param type $p_tva_both  0 if TVA is normal or 1 if on both side
-     * @param type $p_tot_debit total debit
-     * @param $p_acc_operation Acc_Operation for inserting into jrnx
-     * @param $p_group group for AC
-     * @param $idx row number
-     * 
-     * @see Acc_Ledger_Purchase::insert
-     */
-    private function insert_no_deductible(Acc_Compute $p_nd_amount, Fiche 
$p_fiche, $p_tva_both,&$p_tot_debit,Acc_Operation 
$p_acc_operation,$p_group,$idx)
-    {
-        global $g_parameter;
-        if ($p_acc_operation->jrnx_id == 0) {
-            throw new Exception(__FILE__.__LINE__.'invalid 
acc_operation.j_id');
-        }
-        $source_j_id=$p_acc_operation->jrnx_id ;
-        /*
-         * Save all the no deductible
-         *     
ATTR_DEF_ACCOUNT_ND_TVA,ATTR_DEF_ACCOUNT_ND_TVA_ND,ATTR_DEF_ACCOUNT_ND_PERSO,ATTR_DEF_ACCOUNT_ND
-         */
-        if ($p_nd_amount->amount_nd_rate != 0)
-        {
-            $dna_default = new Acc_Parm_Code($this->db, 'DNA');
-
-            /* save op. */
-            if (!$p_fiche->empty_attribute(ATTR_DEF_ACCOUNT_ND))
-            {
-                $dna = $p_fiche->strAttribut(ATTR_DEF_ACCOUNT_ND);
-            } else
-            {
-                $dna = $dna_default->p_value;
-            }
-            $dna = ($dna == '') ? $dna_default->p_value : $dna;
-
-            $p_acc_operation->type = 'd';
-            $p_acc_operation->amount = $p_nd_amount->amount_nd;
-            $p_acc_operation->poste = $dna;
-            $p_acc_operation->qcode = '';
-            $p_acc_operation->desc=$this->find_label($dna)." ND 
".$p_fiche->strAttribut(ATTR_DEF_QUICKCODE);
-            if ($p_nd_amount->amount_nd > 0)
-                $p_tot_debit = bcadd($p_tot_debit, $p_nd_amount->amount_nd );
-            $j_id = $p_acc_operation->insert_jrnx();
-        }
-        /*
-         * ATTR_DEF_ACCOUNT_ND_PERSO
-         */
-        if ($p_nd_amount->amount_perso != 0)
-        {
-            $dna_default = new Acc_Parm_Code($this->db, 'DEP_PRIV');
-
-            /* save op. */
-            $p_acc_operation->type = 'd';
-            if (!$p_fiche->empty_attribute(ATTR_DEF_ACCOUNT_ND_PERSO))
-            {
-                $dna = $p_fiche->strAttribut(ATTR_DEF_ACCOUNT_ND_PERSO);
-            } else
-            {
-                $dna = $dna_default->p_value;
-            }
-            $dna = ($dna == '') ? $dna_default->p_value : $dna;
-
-            $p_acc_operation->amount = $p_nd_amount->amount_perso ;
-            $p_acc_operation->poste = $dna;
-            $p_acc_operation->qcode = '';
-            $p_acc_operation->desc=$this->find_label($dna)." ND_PRIV 
".$p_fiche->strAttribut(ATTR_DEF_QUICKCODE);
-            if ($p_nd_amount->amount_perso> 0)
-                $p_tot_debit = bcadd($p_tot_debit, $p_nd_amount->amount_perso);
-            $j_id = $p_acc_operation->insert_jrnx();
-        }
-        if ($p_nd_amount->nd_vat != 0)
-        {
-            $dna_default = new Acc_Parm_Code($this->db, 'TVA_DNA');
-
-            /* save op. */
-            $p_acc_operation->type = 'd';
-            $p_acc_operation->qcode = '';
-            if (!$p_fiche->empty_attribute(ATTR_DEF_ACCOUNT_ND_TVA_ND) )
-            {
-                $dna = $p_fiche->strAttribut(ATTR_DEF_ACCOUNT_ND_TVA_ND);
-            } else
-            {
-                $dna = $dna_default->p_value;
-            }
-            $dna = ($dna == '') ? $dna_default->p_value : $dna;
-
-            $p_acc_operation->amount = $p_nd_amount->nd_vat;
-            $p_acc_operation->poste = $dna;
-            $p_acc_operation->desc=$this->find_label($dna)." ND_TVA 
".$p_fiche->strAttribut(ATTR_DEF_QUICKCODE);
-            $j_id = $p_acc_operation->insert_jrnx();
-            if ( $g_parameter->MY_ANALYTIC != "nu" )
-            {
-                $op=new Anc_Operation($this->db);
-                $op->oa_group=$p_group;
-                $op->j_id=$j_id;
-                $op->oa_date=$p_acc_operation->date;
-
-                $op->oa_debit='t';
-                $op->oa_description=sql_string('ND_TVA');
-                $op->oa_jrnx_id_source=$source_j_id;
-                
$op->save_form_plan_vat_nd($_POST,$idx,$j_id,$p_nd_amount->nd_vat,$p_acc_operation->jrnx_id);
-            }
-            if ($p_nd_amount->nd_vat> 0)
-                $p_tot_debit = bcadd($p_tot_debit, $p_nd_amount->nd_vat);
-            
-        }
-        if ($p_nd_amount->nd_ded_vat != 0)
-        {
-            $dna_default = new Acc_Parm_Code($this->db, 'TVA_DED_IMPOT');
-            /* save op. */
-            if (!$p_fiche->empty_attribute(ATTR_DEF_ACCOUNT_ND_TVA) )
-            {
-                $dna = $p_fiche->strAttribut(ATTR_DEF_ACCOUNT_ND_TVA);
-            } else
-            {
-                $dna = $dna_default->p_value;
-            }
-            $dna = ($dna == '') ? $dna_default->value : $dna;
-
-
-
-            $p_acc_operation->type = 'd';
-            $p_acc_operation->qcode = '';
-            $p_acc_operation->amount = $p_nd_amount->nd_ded_vat;
-            $p_acc_operation->poste = $dna;
-            $p_acc_operation->desc=$this->find_label($dna)." DED_TVA 
".$p_fiche->strAttribut(ATTR_DEF_QUICKCODE);
-            if ($p_nd_amount->nd_ded_vat > 0)
-                $p_tot_debit = bcadd($p_tot_debit, $p_nd_amount->nd_ded_vat);
-            $j_id = $p_acc_operation->insert_jrnx();
-           if ( $g_parameter->MY_ANALYTIC != "nu" )
-            {
-                $op=new Anc_Operation($this->db);
-                $op->oa_group=$p_group;
-                $op->j_id=$j_id;
-                $op->oa_date=$p_acc_operation->date;
-
-                $op->oa_debit='t';
-                $op->oa_description=sql_string('DED_TVA ');
-                $op->oa_jrnx_id_source=$source_j_id;
-                
$op->save_form_plan_vat_nd($_POST,$idx,$j_id,$p_nd_amount->nd_ded_vat);
-            }
-        }
-    }
-
-    /*!\brief insert into the database, it calls first the verify function
-     * change the value of this->jr_id and this->jr_internal.
-     * It generates the document and save the middle of payment, if 
'gen_invoice is set
-     * and e_mp
-     *\param $p_array is usually $_POST or a predefined operation
-    \code
-     Array
-    (
-
-      [e_client] =>BELGACOM
-      [nb_item] =>9
-      [p_jrn] =>3
-      [period] =>117
-      [e_comm] =>Frais de téléphone
-      [e_date] =>01.09.2009
-      [e_ech] =>
-      [jrn_type] =>ACH
-      [e_pj] =>ACH53
-      [e_pj_suggest] =>ACH53
-      [mt] =>1265318941.39
-      [e_mp] =>0
-      [e_march0] =>TEL
-      [e_march0_price] =>63.6700
-      [e_march0_tva_id] =>1
-      [e_march0_tva_amount] =>13.3700
-      [e_quant0] =>1.000
-      ...
-      [bon_comm] =>
-      [other_info] =>
-      [record] =>Enregistrement
-    )
-    \endcode
-     *\return string
-     *\note throw an Exception
-     */
-    public function insert($p_array=null)
-    {
-        global $g_parameter;
-        extract ($p_array);
-        $this->verify($p_array) ;
-
-        $group=$this->db->get_next_seq("s_oa_group"); /* for analytic */
-        $seq=$this->db->get_next_seq('s_grpt');
-        $this->id=$p_jrn;
-
-        $internal=$this->compute_internal_code($seq);
-        $this->internal=$internal;
-
-        $cust=new Fiche($this->db);
-        $cust->get_by_qcode($e_client);
-        $sposte=$cust->strAttribut(ATTR_DEF_ACCOUNT);
-        // if 2 accounts, take only the credit Supplier
-        if ( strpos($sposte,',') != 0 )
-        {
-            $array=explode(',',$sposte);
-            $poste=$array[1];
-        }
-        else
-        {
-            $poste=$sposte;
-        }
-
-        $oPeriode=new Periode($this->db);
-        $check_periode=$this->check_periode();
-
-        if ( $check_periode == true )
-            $tperiode=$period;
-        else
-            $tperiode=$oPeriode->find_periode($e_date);
-
-        bcscale(4);
-        try
-        {
-            $tot_amount=0;
-            $tot_tva=0;
-            $tot_debit=0;
-            $this->db->start();
-            $tot_nd=0;
-            $tot_perso=0;
-            $tot_tva_nd=0;
-            $tot_tva_ndded=0;
-            $tot_tva_reversed=0;
-                       $tva=array();
-            /* Save all the items without vat and no deductible vat and 
expense*/
-            for ($i=0;$i< $nb_item;$i++)
-            {
-               $n_both=0;
-                if ( strlen(trim(${'e_march'.$i})) == 0 ) continue;
-
-                /* First we save all the items without vat */
-                $fiche=new Fiche($this->db);
-                $fiche->get_by_qcode(${"e_march".$i});
-               $tva_both=0;
-                /* tva */
-                if ($g_parameter->MY_TVA_USE=='Y')
-                {
-                    $idx_tva=${'e_march'.$i.'_tva_id'};
-                    $oTva=new Acc_Tva($this->db);
-                    $oTva->set_parameter('id',$idx_tva);
-                    $oTva->load();
-                    $tva_both=$oTva->get_parameter("both_side");
-                }
-                /* -- Create acc_operation -- */
-                $acc_operation=new Acc_Operation($this->db);
-                $acc_operation->date=$e_date;
-                $acc_operation->grpt=$seq;
-                $acc_operation->jrn=$p_jrn;
-                $acc_operation->type='d';
-                $acc_operation->periode=$tperiode;
-                $acc_operation->qcode="";
-                
-                
-                /* We have to compute all the amount thanks Acc_Compute */
-                
$amount=round(bcmul(${'e_march'.$i.'_price'},${'e_quant'.$i}),2);
-                
-                $acc_amount=new Acc_Compute();
-                $acc_amount->check=false;
-                $acc_amount->set_parameter('amount',$amount);
-                
-                // Compute VAT or take the given one
-                if ( $g_parameter->MY_TVA_USE=='Y')
-                {
-                    
$acc_amount->set_parameter('amount_vat_rate',$oTva->get_parameter('rate'));
-                    if ( strlen(trim(${'e_march'.$i.'_tva_amount'})) ==0 || 
${'e_march'.$i.'_tva_amount'} == 0)
-                    {
-                        $acc_amount->compute_vat();
-
-                    }
-                    else
-                    {
-                        $acc_amount->amount_vat= ${'e_march'.$i.'_tva_amount'};
-
-                    }
-                   $tot_tva=bcadd($tot_tva,$acc_amount->amount_vat);
-                }
-
-               
-                /* compute ND */
-                $save_amount_vat=$acc_amount->amount_vat;
-                $this->compute_no_deductible($acc_amount, $fiche);
-                $acc_amount->correct();
-                // TVA which avoid 
-                $acc_amount->amount_unpaid=($tva_both == 1 ) ? 
$save_amount_vat :0 ;
-                
$tot_tva_reversed=bcadd($tot_tva_reversed,$acc_amount->amount_unpaid);
-                
-
-              
-                $tot_amount=round(bcadd($tot_amount,$amount),2);
-
-                /* get the account and explode if necessary */
-                $sposte=$fiche->strAttribut(ATTR_DEF_ACCOUNT);
-                // if 2 accounts, take only the debit one for customer
-                if ( strpos($sposte,',') != 0 )
-                {
-                    $array=explode(',',$sposte);
-                    $poste_val=$array[0];
-                }
-                else
-                {
-                    $poste_val=$sposte;
-                }
-                if ( $g_parameter->MY_UPDLAB=='Y')
-                    $acc_operation->desc=strip_tags(${"e_march".$i."_label"});
-                else
-                    $acc_operation->desc=null;
-                $acc_operation->poste=$poste_val;
-                $acc_operation->amount=$acc_amount->amount;
-                $acc_operation->qcode=${"e_march".$i};
-                if( $acc_amount->amount > 0 ) 
$tot_debit=bcadd($tot_debit,$acc_amount->amount);
-                $j_id=$acc_operation->insert_jrnx();
-                
-                /* insert ND */
-                $this->insert_no_deductible($acc_amount, $fiche, $tva_both, 
$tot_debit,$acc_operation,$group,$i);
-
-                
-                /* Compute sum vat */
-                if ( $g_parameter->MY_TVA_USE=='Y')
-                {
-                    $tva_item=$acc_amount->amount_vat;
-
-                    if (isset($tva[$idx_tva] ) )
-                        $tva[$idx_tva]=bcadd($tva[$idx_tva],$tva_item);
-                    else
-                        $tva[$idx_tva]=$tva_item;
-
-                }
-                /* Save the stock */
-                /* if the quantity is < 0 then the stock increase (return of
-                 *  material)
-                 */
-                $nNeg=(${"e_quant" . $i}< 0) ? -1 : 1;
-
-                // always save quantity but in withStock we can find
-                // what card need a stock management
-                if ( $g_parameter->MY_STOCK='Y'&& isset ($repo))
-                {
-                    $dir=(${'e_quant'.$i} < 0 ) ? 'c':'d';
-                    
Stock_Goods::insert_goods($this->db,array('j_id'=>$j_id,'goods'=>${'e_march'.$i},'quant'=>$nNeg*${'e_quant'.$i},'dir'=>$dir,'repo'=>$repo))
 ;
-                }
-
-                if ( $g_parameter->MY_ANALYTIC != "nu" )
-                {
-                    // for each item, insert into operation_analytique */
-                    $op=new Anc_Operation($this->db);
-                    $op->oa_group=$group;
-                    $op->j_id=$j_id;
-                    $op->oa_date=$e_date;
-                    $op->oa_debit='t';
-                    $op->oa_description=sql_string($e_comm);
-                    $op->save_form_plan($_POST,$i,$j_id);
-                }
-                // insert into quant_purchase
-                //-----
-                if ( $g_parameter->MY_TVA_USE=='Y')
-                {
-
-                    $r=$this->db->exec_sql("select insert_quant_purchase ".
-                                           "(null".
-                                           ",".$j_id.           /* 2 */
-                                           ",'".${"e_march".$i}."'". /* 3 */
-                                           ",".${"e_quant".$i}.",".  /* 4 */
-                                           round($amount,2).          /* 5 */
-                                           ",".$acc_amount->amount_vat. /* 6 */
-                                           ",".$oTva->get_parameter('id'). /* 
7 */
-                                           ",".$acc_amount->amount_nd.     /* 
8 */
-                                           ",".$acc_amount->nd_vat.         /* 
9 */
-                                           ",".$acc_amount->nd_ded_vat.    /* 
10 */
-                                           ",".$acc_amount->amount_perso.  /* 
11 */ 
-                                           ",'".$e_client."',". 
$acc_amount->amount_unpaid.")");            /* 12 */
-
-                }
-                else
-                {
-                    $r=$this->db->exec_sql("select insert_quant_purchase ".
-                                           "(null".
-                                           ",".$j_id.
-                                           ",'".${"e_march".$i}."'".
-                                           ",".${"e_quant".$i}.",".
-                                           round($amount,2).
-                                           ",0".
-                                           ",null".
-                                           ",".$acc_amount->amount_nd.
-                                           ",0".
-                                           ",".$acc_amount->nd_ded_vat.
-                                           ",".$acc_amount->amount_perso.
-                                           
",'".$e_client."',".$acc_amount->amount_unpaid.")");
-
-
-                }
-
-            }       // end loop : save all items
-            /*  save total customer */
-            $cust_amount=round(bcadd($tot_amount,$tot_tva),2);
-            $acc_operation=new Acc_Operation($this->db);
-            $acc_operation->date=$e_date;
-            $acc_operation->poste=$poste;
-            $acc_operation->amount=$cust_amount-$tot_tva_reversed;
-            $acc_operation->grpt=$seq;
-            $acc_operation->jrn=$p_jrn;
-            $acc_operation->type='c';
-            $acc_operation->periode=$tperiode;
-            $acc_operation->qcode=${"e_client"};
-            if ( $cust_amount < 0 )
-                               $tot_debit=bcadd($tot_debit,abs($cust_amount));
-            $let_client=$acc_operation->insert_jrnx();
-            
-
-            if ( $g_parameter->MY_TVA_USE=='Y')
-            {
-                /* save all vat
-                 * $i contains the tva_id and value contains the vat amount
-                 */
-                foreach ($tva as $i => $value)
-                {
-                    $oTva=new Acc_Tva($this->db);
-                    $oTva->set_parameter('id',$i);
-                    $oTva->load();
-
-                    $poste_vat=$oTva->get_side('d');
-
-                    $cust_amount=bcadd($tot_amount,$tot_tva);
-                    $acc_operation=new Acc_Operation($this->db);
-                    $acc_operation->date=$e_date;
-                    $acc_operation->poste=$poste_vat;
-                    $acc_operation->amount=$value;
-                    $acc_operation->grpt=$seq;
-                    $acc_operation->jrn=$p_jrn;
-                    $acc_operation->type='d';
-                    $acc_operation->periode=$tperiode;
-                    if ( $value > 0 ) $tot_debit=bcadd($tot_debit,abs($value));
-                    $acc_operation->insert_jrnx();
-                    // if TVA is on both side, we deduce it immediately
-                    if ( $oTva->get_parameter("both_side")==1)
-                    {
-                        $poste_vat=$oTva->get_side('c');
-                        $cust_amount=bcadd($tot_amount,$tot_tva);
-                        $cust_amount=bcsub($tot_amount,$tot_tva_reversed);
-                        $acc_operation=new Acc_Operation($this->db);
-                        $acc_operation->date=$e_date;
-                        $acc_operation->poste=$poste_vat;
-                        $acc_operation->amount=$tot_tva_reversed;
-                        $acc_operation->grpt=$seq;
-                        $acc_operation->jrn=$p_jrn;
-                        $acc_operation->type='c';
-                        $acc_operation->periode=$tperiode;
-                        $acc_operation->insert_jrnx();
-                       if ( $value < 0 ) 
$tot_debit=bcadd($tot_debit,abs($value));
-                    }
-
-                }
-            }
-            /* insert into jrn */
-            $acc_operation=new Acc_Operation($this->db);
-            $acc_operation->date=$e_date;
-            $acc_operation->echeance=$e_ech;
-            $acc_operation->amount=abs(round($tot_debit,2));
-            $acc_operation->desc=$e_comm;
-            $acc_operation->grpt=$seq;
-            $acc_operation->jrn=$p_jrn;
-            $acc_operation->periode=$tperiode;
-            $acc_operation->pj=$e_pj;
-            $acc_operation->mt=$mt;
-            $this->jr_id=$acc_operation->insert_jrn();
-            $this->pj=$acc_operation->set_pj();
-
-            // Set Internal code
-            $this->grpt_id=$seq;
-            $this->update_internal_code($internal);
-            /* update quant_purchase */
-            $this->db->exec_sql('update quant_purchase set qp_internal = $1 
where j_id in (select j_id from jrnx where j_grpt=$2)',
-                                array($internal,$seq));
-
-            /**= e_pj then do not increment sequence */
-            if ( strcmp($e_pj,$e_pj_suggest) == 0 && strlen(trim($e_pj)) != 0 )
-            {
-                $this->inc_seq_pj();
-            }
-
-            /* Save the attachment */
-            if ( isset ($_FILES))
-            {
-                if ( sizeof($_FILES) != 0 )
-                    $this->db->save_upload_document($seq);
-            }
-            $str_file="";
-            /* Generate an document  and save it into the database (Note de 
frais only)
-             */
-            if ( isset($_POST['gen_invoice']) )
-            {
-                $ref_doc= $this->create_document($internal,$p_array);
-                $this->doc='<A class="line" 
HREF="show_pj.php?'.dossier::get().'&jr_grpt_id='.$seq.'&jrn='.$this->id.'">'.$ref_doc.'</A>';
-            }
-
-            //----------------------------------------
-            // Save the payer
-            //----------------------------------------
-            if ( $e_mp != 0 )
-            {
-                /* mp */
-                $mp=new Acc_Payment($this->db,$e_mp);
-                $mp->load();
-
-                /* fiche */
-                if ($mp->get_parameter('qcode') == '')
-                    $fqcode=${'e_mp_qcode_'.$e_mp};
-                else
-                    $fqcode=$mp->get_parameter('qcode');
-
-                $acfiche = new Fiche($this->db);
-                $acfiche->get_by_qcode($fqcode);
-
-                /* jrnx */
-                $acseq=$this->db->get_next_seq('s_grpt');
-                $acjrn=new 
Acc_Ledger($this->db,$mp->get_parameter('ledger_target'));
-                $acinternal=$acjrn->compute_internal_code($acseq);
-
-                /* Insert paid by  */
-                $acc_pay=new Acc_Operation($this->db);
-                $acc_pay->date=$e_date;
-
-                /* get the account and explode if necessary */
-                $sposte=$acfiche->strAttribut(ATTR_DEF_ACCOUNT);
-                // if 2 accounts, take only the debit one for customer
-                if ( strpos($sposte,',') != 0 )
-                {
-                    $array=explode(',',$sposte);
-                    $poste_val=$array[1];
-                }
-                else
-                {
-                    $poste_val=$sposte;
-                }
-
-                $famount=bcsub($cust_amount,$acompte);
-                $acc_pay->poste=$poste_val;
-                $acc_pay->qcode=$fqcode;
-                $acc_pay->amount=abs(round($famount,2));
-                $acc_pay->desc='';
-                $acc_pay->grpt=$acseq;
-                $acc_pay->jrn=$mp->get_parameter('ledger_target');
-                $acc_pay->periode=$tperiode;
-               $acc_pay->type=($famount>=0)?'c':'d';
-                $acc_pay->insert_jrnx();
-
-                /* Insert supplier  */
-                $acc_pay=new Acc_Operation($this->db);
-                $acc_pay->date=$e_date;
-                $acc_pay->poste=$poste;
-                $acc_pay->qcode=$e_client;
-                $acc_pay->amount=abs(round($famount,2));
-                $acc_pay->desc='';
-                $acc_pay->grpt=$acseq;
-                $acc_pay->jrn=$mp->get_parameter('ledger_target');
-                $acc_pay->periode=$tperiode;
-                               $acc_pay->type=($famount>=0)?'d':'c';
-                $let_other=$acc_pay->insert_jrnx();
-
-                /* insert into jrn */
-                $acc_pay->mt=$mt;
-                               $acc_pay->desc=(!isset($e_comm_paiement) || 
strlen(trim($e_comm_paiement)) == 0) ?$e_comm:$e_comm_paiement;
-                $mp_jr_id=$acc_pay->insert_jrn();
-                $acjrn->grpt_id=$acseq;
-                $acjrn->update_internal_code($acinternal);
-
-                $r1=$this->get_id($internal);
-                $r2=$this->get_id($acinternal);
-
-               /*
-                * add lettering
-                */
-               $oletter=new Lettering($this->db);
-               $oletter->insert_couple($let_client,$let_other);
-
-                /* set the flag paid */
-                $Res=$this->db->exec_sql("update jrn set jr_rapt='paid' where 
jr_id=$1",array($r1));
-
-                /* Reconcialiation */
-                $rec=new Acc_Reconciliation($this->db);
-                $rec->set_jr_id($r1);
-                $rec->insert($r2);
-               /*
-                * save also into quant_fin
-                */
-
-               /* get ledger property */
-               $ledger=new Acc_Ledger_Fin($this->db,$acc_pay->jrn);
-               $prop=$ledger->get_propertie();
-
-               /* if ledger is FIN then insert into quant_fin */
-               if ( $prop['jrn_def_type'] == 'FIN' )
-                 {
-                   
$ledger->insert_quant_fin($acfiche->id,$mp_jr_id,$cust->id,bcmul($famount,-1));
-                 }
-
-
-            }
-        }//end try
-        catch (Exception $e)
-        {
-            echo '<span class="error">'.
-            'Erreur dans l\'enregistrement '.
-            __FILE__.':'.__LINE__.' '.
-            $e->getMessage().$e->getTraceAsString();
-
-            $this->db->rollback();
-            throw  new Exception($e);
-        }
-        $this->db->commit();
-        return $internal;
-    }
-
-    /*!\brief display the form for entering data for invoice
-     *\param $p_array is null or you can put the predef operation or the $_POST
-    \code
-    array
-    'sa' => string 'n' (length=1)
-    'p_action' => string 'ach' (length=3)
-    'gDossier' => string '28' (length=2)
-    'e_client' => string 'ASEKURA' (length=7)
-    'nb_item' => string '9' (length=1)
-    'p_jrn' => string '3' (length=1)
-    'period' => string '126' (length=3)
-    'e_comm' => string 'descriptio' (length=10)
-    'e_date' => string '01.05.2010' (length=10)
-    'e_ech' => string '' (length=0)
-    'jrn_type' => string 'ACH' (length=3)
-    'e_pj' => string 'ACH37' (length=5)
-    'e_pj_suggest' => string 'ACH37' (length=5)
-    'mt' => string '1273759434.5701' (length=15)
-    'e_mp' => string '0' (length=1)
-    'e_march0' => string 'DOC' (length=3)
-    'e_march0_price' => string '2000' (length=4)
-    'e_march0_tva_id' => string '3' (length=1)
-    'e_march0_tva_amount' => string '120' (length=3)
-    'e_quant0' => string '1' (length=1)
-    'gen_invoice' => string 'on' (length=2)
-    'gen_doc' => string '7' (length=1)
-    'bon_comm' => string '' (length=0)
-    'other_info' => string '' (length=0)
-    'correct' => string 'Corriger' (length=8)
-    \endcode
-     *\return HTML string
-     */
-    public function input($p_array=null,$p_readonly=0)
-    {
-        global $g_parameter,$g_user;
-        if ( $p_array != null ) extract($p_array);
-
-        $flag_tva=$g_parameter->MY_TVA_USE;
-        /* Add button */
-        $f_add_button=new IButton('add_card');
-        $f_add_button->label=_('Créer une nouvelle fiche');
-               $f_add_button->tabindex=-1;
-        $f_add_button->set_attribute('jrn',$this->id);
-        $f_add_button->javascript=" 
this.jrn=\$('p_jrn').value;select_card_type(this);";
-
-        $str_add_button="";
-        if ($g_user->check_action(FICADD)==1)
-        {
-                $str_add_button=$f_add_button->input();
-        }
-        // The first day of the periode
-        $oPeriode=new Periode($this->db);
-        list 
($l_date_start,$l_date_end)=$oPeriode->get_date_limit($g_user->get_periode());
-        if (  $g_parameter->MY_DATE_SUGGEST=='Y' )
-            $op_date=( ! isset($e_date) ) ?$l_date_start:$e_date;
-        else
-            $op_date=( ! isset($e_date) ) ?'':$e_date;
-
-        $e_ech=(isset($e_ech))?$e_ech:"";
-        $e_comm=(isset($e_comm))?$e_comm:"";
-
-        $r="";
-        $r.=dossier::hidden();
-        $f_legend_detail=_("Détail articles achetés");
-
-        //  Date
-        //--
-        $Date=new IDate();
-        $Date->setReadOnly(false);
-        $Date->table=1;
-        $Date->tabindex=1;
-        $f_date=$Date->input("e_date",$op_date);
-        // Payment limit
-        //--
-        $Echeance=new IDate();
-        $Echeance->setReadOnly(false);
-        $Echeance->tabindex=2;
-        $label=HtmlInput::infobulle(4);
-        $f_echeance=$Echeance->input('e_ech',$e_ech,'Echéance'.$label);
-        $f_periode="";
-        if ($this->check_periode() == true)
-        {
-            // Periode
-            //--
-            $l_user_per=$g_user->get_periode();
-            $def=(isset($periode))?$periode:$l_user_per;
-
-            $period=new IPeriod("period");
-            $period->user=$g_user;
-            $period->cn=$this->db;
-            $period->value=$def;
-            $period->type=OPEN;
-            try
-            {
-                $l_form_per=$period->input();
-            }
-            catch (Exception $e)
-            {
-                if ($e->getCode() == 1 )
-                {
-                    throw new Exception( _("Aucune période ouverte"));
-                }
-            }
-
-            $r.="<td>";
-            $label=HtmlInput::infobulle(3);
-            $f_periode=_("Période comptable")." $label ".$l_form_per;
-        }
-        // Ledger (p_jrn)
-        //--
-        /* if we suggest the next pj, then we need a javascript */
-        $add_js="";
-        if ( $g_parameter->MY_PJ_SUGGEST=='Y')
-        {
-            $add_js="update_pj();";
-        }
-               if ($g_parameter->MY_DATE_SUGGEST == 'Y')
-               {
-                       $add_js.='get_last_date();';
-               }
-               $add_js.='update_name();';
-               $add_js.='update_pay_method();';
-               $add_js.='update_row("sold_item");';
-
-               $wLedger=$this->select_ledger('ACH',2);
-        if ($wLedger == null) throw  new Exception(_('Pas de journal 
disponible'));
-        
$wLedger->javascript="onChange='update_predef(\"ach\",\"f\",\"".$_REQUEST['ac']."\");$add_js'";
-        $wLedger->table=1;
-        $f_jrn=$wLedger->input();
-
-        // Comment
-        //--
-        $Commentaire=new IText();
-        $Commentaire->table=0;
-        $Commentaire->setReadOnly(false);
-        $Commentaire->size=60;
-        $Commentaire->tabindex=3;
-        $label=HtmlInput::infobulle(1) ;
-        $f_desc=$Commentaire->input("e_comm",h($e_comm));
-
-        // PJ
-        //--
-        /* suggest PJ ? */
-        $default_pj='';
-        if ( $g_parameter->MY_PJ_SUGGEST=='Y')
-        {
-            $default_pj=$this->guess_pj();
-        }
-
-        $pj=new IText();
-        $pj->value=(isset($e_pj))?$e_pj:$default_pj;
-
-
-        $pj->table=0;
-        $pj->name="e_pj";
-        $pj->size=10;
-        $pj->readonly=false;
-
-        $f_pj=$pj->input().HtmlInput::hidden('e_pj_suggest',$default_pj);
-
-        // Display the customer
-        //--
-        $fiche='cred';
-
-        // Save old value and set a new one
-        //--
-        $e_client=( isset ($e_client) )?$e_client:"";
-        $e_client_label="&nbsp;";//str_pad("",100,".");
-
-
-        // retrieve e_client_label
-        //--
-
-        if ( strlen(trim($e_client)) !=  0)
-        {
-            $fClient=new Fiche($this->db);
-            $fClient->get_by_qcode($e_client);
-            $e_client_label=$fClient->strAttribut(ATTR_DEF_NAME).' '.
-                            ' Adresse : 
'.$fClient->strAttribut(ATTR_DEF_ADRESS).' '.
-                            $fClient->strAttribut(ATTR_DEF_CP).' '.
-                            $fClient->strAttribut(ATTR_DEF_CITY).' ';
-
-
-        }
-
-        $W1=new ICard();
-        $W1->label=_("Fournisseur ").HtmlInput::infobulle(0) ;
-        $W1->name="e_client";
-        $W1->tabindex=3;
-        $W1->value=$e_client;
-        $W1->table=0;
-        $W1->set_dblclick("fill_ipopcard(this);");
-        $W1->set_attribute('ipopup','ipopcard');
-
-        // name of the field to update with the name of the card
-        $W1->set_attribute('label','e_client_label');
-        // name of the field to update with the name of the card
-        $W1->set_attribute('typecard','cred');
-
-        // Add the callback function to filter the card on the jrn
-        $W1->set_callback('filter_card');
-        $W1->set_function('fill_data');
-        $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
-                                $W1->name);
-        $f_client_qcode=$W1->input();
-        $client_label=new ISpan();
-        $client_label->table=0;
-        $f_client=$client_label->input("e_client_label",$e_client_label);
-        $f_client_bt=$W1->search();
-
-
-        // Record the current number of article
-
-        $e_comment=(isset($e_comment))?$e_comment:"";
-               $p_article= ( isset ($nb_item))?$nb_item:$this->get_min_row();
-        $max=($p_article < 
$this->get_min_row())?$this->get_min_row():$p_article;
-
-        $Hid=new IHidden();
-               $r.=$Hid->input("nb_item",$p_article);
-
-        // For each article
-        //--
-        for ($i=0;$i< $max ;$i++)
-        {
-            // Code id, price & vat code
-            //--
-            $march=(isset(${"e_march$i"}))?${"e_march$i"}:""                   
;
-            
$march_price=(isset(${"e_march".$i."_price"}))?${"e_march".$i."_price"}:""
-                         ;
-            /* use vat */
-            if ( $g_parameter->MY_TVA_USE=='Y')
-            {
-                
$march_tva_id=(isset(${"e_march$i"."_tva_id"}))?${"e_march$i"."_tva_id"}:"";
-                
$march_tva_amount=(isset(${"e_march$i"."_tva_amount"}))?${"e_march$i"."_tva_amount"}:"";
-            }
-
-
-
-            
$march_label=(isset(${"e_march".$i."_label"}))?${"e_march".$i."_label"}:"";
-            // retrieve the tva label and name
-            //--
-            if ( strlen(trim($march))!=0  && strlen(trim($march_label))==0 )
-            {
-                $fMarch=new Fiche($this->db);
-                $fMarch->get_by_qcode($march);
-                $march_label=$fMarch->strAttribut(ATTR_DEF_NAME);
-                /* vat use */
-                if ( ! isset($march_tva_id) && $g_parameter->MY_TVA_USE=='Y' )
-                    $march_tva_id=$fMarch->strAttribut(ATTR_DEF_TVA);
-            }
-            // Show input
-            //--
-            $W1=new ICard();
-            $W1->label="";
-            $W1->name="e_march".$i;
-            $W1->value=$march;
-            $W1->table=1;
-            $W1->set_dblclick("fill_ipopcard(this);");
-            $W1->set_attribute('ipopup','ipopcard');
-
-            $W1->set_attribute('typecard','deb');
-
-            // name of the field to update with the name of the card
-            $W1->set_attribute('label','e_march'.$i.'_label');
-            // name of the field with the price
-            $W1->set_attribute('purchase','e_march'.$i.'_price'); /* 
autocomplete */
-            $W1->set_attribute('price','e_march'.$i.'_price');    /* via 
search */
-
-            // name of the field with the TVA_ID
-            $W1->set_attribute('tvaid','e_march'.$i.'_tva_id');
-            // Add the callback function to filter the card on the jrn
-            $W1->set_callback('filter_card');
-            $W1->set_function('fill_data');
-            $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
-                                    $W1->name);
-            $W1->readonly=false;
-            $array[$i]['quick_code']=$W1->input();
-            $array[$i]['bt']=$W1->search();
-
-            $array[$i]['hidden']='';
-            // For computing we need some hidden field for holding the value
-            if ( $g_parameter->MY_TVA_USE=='Y')
-            {
-                $array[$i]['hidden'].=HtmlInput::hidden('tva_march'.$i,0);
-            }
-
-            if ( $g_parameter->MY_TVA_USE=='Y')
-                $tvac=new INum('tvac_march'.$i);
-            else
-                $tvac=new IHidden('tvac_march'.$i);
-
-            $tvac->readOnly=1;
-            $tvac->value=0;
-            $array[$i]['tvac']=$tvac->input();
-
-            $htva=new INum('htva_march'.$i);
-            $htva->readOnly=1;
-
-            $htva->value=0;
-            $array[$i]['htva']=$htva->input();
-
-            if ( $g_parameter->MY_UPDLAB == 'Y')
-            {
-                $Span=new IText("e_march".$i."_label");
-                $Span->css_size="100%";
-            } else
-            {
-                $Span=new ISpan("e_march".$i."_label");
-            }
-            $Span->value=$march_label;
-            $Span->setReadOnly(false);
-            // card's name, price
-            //--
-            
$array[$i]['denom']=$Span->input("e_march".$i."_label",$march_label);
-            // price
-            $Price=new INum();
-            $Price->setReadOnly(false);
-            $Price->size=9;
-            
$Price->javascript="onBlur='format_number(this);clean_tva($i);compute_ledger($i)'";
-            $array[$i]['pu']=$Price->input("e_march".$i."_price",$march_price);
-            if ( $g_parameter->MY_TVA_USE=='Y')
-            {
-
-                // vat label
-                //--
-                $Tva=new ITva_Popup($this->db);
-                
$Tva->js="onblur=\"format_number(this);onChange=clean_tva($i);compute_ledger($i)\"";
-                $Tva->in_table=true;
-                $Tva->set_attribute('compute',$i);
-                $Tva->value=$march_tva_id;
-                $array[$i]['tva']=$Tva->input("e_march$i"."_tva_id");
-
-                // Tva_amount
-
-                // price
-                $Tva_amount=new INum();
-                $Tva_amount->setReadOnly(false);
-                $Tva_amount->size=9;
-                
$Tva_amount->javascript="onBlur='format_number(this);compute_ledger($i)'";
-                
$array[$i]['amount_tva']=$Tva_amount->input("e_march".$i."_tva_amount",$march_tva_amount);
-            }
-            // quantity
-            //--
-            $quant=(isset(${"e_quant$i"}))?${"e_quant$i"}:"1"
-                   ;
-            $Quantity=new INum();
-            $Quantity->setReadOnly(false);
-            $Quantity->size=9;
-            
$Quantity->javascript="onChange=format_number(this);clean_tva($i);compute_ledger($i)";
-            $array[$i]['quantity']=$Quantity->input("e_quant".$i,$quant);
-
-        }
-        $f_type=_('Fournisseur');
-
-        ob_start();
-        require_once NOALYSS_INCLUDE.'/template/form_ledger_detail.php';
-        $r.=ob_get_contents();
-        ob_end_clean();
-
-        // Set correctly the REQUEST param for jrn_type
-        $r.= HtmlInput::hidden('jrn_type','ACH');
-        $r.= HtmlInput::button('add_item',_('Ajout article'),      ' 
onClick="ledger_add_row()"');
-
-
-
-        /* if we suggest the pj n# the run the script */
-        if ( $g_parameter->MY_PJ_SUGGEST=='Y')
-        {
-            $r.='<script> update_pj();</script>';
-        }
-               // set focus on date
-               $r.= create_script("$('".$Date->id."').focus()");
-        return $r;
-    }
-
-    /address@hidden show the summary of the operation and propose to save it
-     address@hidden array contains normally $_POST. It proposes also to save
-     * the Analytic accountancy
-        * @param $p_summary true to confirm false, show only the result in RO
-     address@hidden string
-     */
-    function confirm($p_array,$p_summary=false)
-    {
-        global $g_parameter;
-        extract ($p_array);
-
-               // we don't need to verify if we need only a feedback
-        if ( ! $p_summary )
-                       $this->verify($p_array) ;
-
-               $anc=null;
-        // to show a select list for the analytic
-        // if analytic is op (optionnel) there is a blank line
-
-        bcscale(4);
-        $client=new Fiche($this->db);
-        $client->get_by_qcode($e_client,true);
-
-        $client_name=h($client->getName().
-                       ' '.$client->strAttribut(ATTR_DEF_ADRESS).' '.
-                       $client->strAttribut(ATTR_DEF_CP).' '.
-                       $client->strAttribut(ATTR_DEF_CITY));
-        $lPeriode=new Periode($this->db);
-        if ($this->check_periode() == true)
-        {
-            $lPeriode->p_id=$period;
-        }
-        else
-        {
-            $lPeriode->find_periode($e_date);
-        }
-        $date_limit=$lPeriode->get_date_limit();
-        $r="";
-        $r.='<TABLE>';
-        if ( $p_summary ) {
-            $jr_id=$this->db->get_value('select jr_id from jrn where 
jr_internal=$1',array($this->internal));
-            $r.="<tr>";
-            $r.='<td>';
-            $r.=_('Détail opération ');
-            $r.='</td>';
-            $r.='<td>';
-            $r.=sprintf ('<a class="line" style="display:inline" 
href="javascript:modifyOperation(%d,%d)">%s</a>',
-                    $jr_id,dossier::id(),$this->internal);
-            $r.='</td>';
-            $r.="</tr>";
-        }
-        $r.='<tr>';
-         if ( ! $p_summary) {
-            $r.='<td>' . _('Numéro Pièce') .'</td><td>'. hb($e_pj) . '</td>';
-        } else {
-            
-             if ( strcmp($this->pj,$e_pj) != 0 )
-            {
-                $r.='<td>' . _('Numéro Pièce') .'</td><td>'. hb($this->pj) . 
-                        '<span class="notice"> '._('Attention numéro pièce 
existante, elle a du être adaptée').'</span></td>';
-            } else {
-                $r.='<td>' . _('Numéro Pièce') .'</td><td>'. hb($this->pj) . 
'</td>';
-            }
-        }
-        $r.='</tr>';
-        $r.='<td> ' . _('Date') . '</td><td> ' . hb($e_date) . '</td>';
-        $r.='</tr>';
-        $r.='<tr>';
-        $r.='<td>' . _('Echeance') . '</td><td> ' . hb($e_ech) . '</td>';
-        $r.='</tr>';
-       
-     
-        $r.='<tr>';
-        $r.='<td> ' . _('Période Comptable') . '</td><td> ' .hb( 
$date_limit['p_start'] . '-' . $date_limit['p_end']) . '</td>';
-        $r.='</tr>';
-        $r.='<tr>';
-        $r.='<td> ' . _('Journal') . '</td><td> ' . hb($this->get_name()) . 
'</td>';
-        $r.='</tr>';
-        $r.='<tr>';
-        $r.='<td> ' . _('Libellé') . '</td><td> ' . hb($e_comm) . '</td>';
-        $r.='</tr>';
-        $r.='<tr>';
-        
-        $r.='<tr>';
-        $r.='<td> ' . _('Fournisseur') . '</td><td> ' . hb($e_client . ':' . 
$client_name) . '</td>';
-        $r.='</tr>';
-        $r.='</table>';
-        $r.='<h2>' . _('Détail articles achetés') . '</h2>';
-        $r.='<p class="decale">';
-        $r.='<table class="result" >';
-        $r.='<TR>';
-        $r.="<th>" . _('Code') . "</th>";
-        $r.="<th>" . _('Dénomination') . "</th>";
-        $r.="<th style=\"text-align:right\">" . _('prix') . "</th>";
-        $r.="<th style=\"text-align:right\">" . _('quantité') . "</th>";
-
-
-        if ($g_parameter->MY_TVA_USE == 'Y') {
-            $r.="<th style=\"text-align:right\">" . _('tva') . "</th>";
-            $r.='<th style="text-align:right"> ' . _('Montant TVA') . '</th>';
-            $r.='<th style="text-align:right">' . _('Montant HTVA') . '</th>';
-            $r.='<th style="text-align:right">' . _('Montant TVAC') . '</th>';
-        } else {
-            $r.='<th style="text-align:right">' . _('Montant') . '</th>';
-        }
-
-        /* if we use the AC */
-        if ($g_parameter->MY_ANALYTIC!='nu')
-        {
-            $anc=new Anc_Plan($this->db);
-            $a_anc=$anc->get_list();
-            $x=count($a_anc);
-            /* set the width of the col */
-            $r.='<th colspan="'.$x.'">'._('Compt. Analytique').'</th>';
-
-            /* add hidden variables pa[] to hold the value of pa_id */
-            $r.=Anc_Plan::hidden($a_anc);
-        }
-
-        $r.='</tr>';
-        $tot_amount=0.0;
-        $tot_tva=0.0;
-        //--
-        // For each item
-        //--
-        for ($i = 0; $i < $nb_item;$i++)
-        {
-                       $tot_row=0;
-            if ( strlen(trim(${"e_march".$i})) == 0 ) continue;
-
-            /* retrieve information for card */
-            $fiche=new Fiche($this->db);
-            $fiche->get_by_qcode(${"e_march".$i});
-            if ( $g_parameter->MY_UPDLAB=='Y')
-                $fiche_name=h(${"e_march".$i."_label"});
-            else
-                $fiche_name=$fiche->strAttribut (ATTR_DEF_NAME);
-            $amount=bcmul(${"e_march".$i."_price"},${'e_quant'.$i});
-            if ( $g_parameter->MY_TVA_USE=='Y')
-            {
-                $idx_tva=${"e_march".$i."_tva_id"};
-                $oTva=new Acc_Tva($this->db);
-                $oTva->set_parameter('id',$idx_tva);
-                $oTva->load();
-                $op=new Acc_Compute();
-
-                $op->set_parameter("amount",$amount);
-                
$op->set_parameter('amount_vat_rate',$oTva->get_parameter('rate'));
-                $op->compute_vat();
-                $tva_computed=$op->get_parameter('amount_vat');
-                //----- if tva_amount is not given we compute the vat ----
-                if ( strlen (trim (${'e_march'.$i.'_tva_amount'})) == 0)
-                {
-                    $tva_item=$op->get_parameter('amount_vat');
-                }
-                else
-                    $tva_item=round(${'e_march'.$i.'_tva_amount'},2);
-
-                if (isset($tva[$idx_tva] ) )
-                    $tva[$idx_tva]=bcadd($tva_item,$tva[$idx_tva]);
-                else
-                    $tva[$idx_tva]=$tva_item;
-               
-               
-                
-            }
-            $tot_amount=round(bcadd($tot_amount,$amount),2);
-            $tot_row=round(bcadd($tot_row,$amount),2);
-            $r.='<tr>';
-            $r.='<td>';
-            $r.=${"e_march".$i};
-            $r.='</td>';
-            $r.='<TD style="border-bottom:1px dotted grey;">';
-            $r.=$fiche_name;
-            $r.='</td>';
-            $r.='<td class="num">';
-            $r.=nbm(${"e_march".$i."_price"});
-            $r.='</td>';
-            $r.='<td class="num">';
-            $r.=nbm(${"e_quant".$i});
-            $r.='</td>';
-            $both_side=0;
-            if ($g_parameter->MY_TVA_USE == 'Y')
-            {
-                $r.='<td class="num">';
-                $r.=$oTva->get_parameter('label');
-                $both_side=$oTva->get_parameter("both_side");
-                if ( $both_side == 0) {
-                    $tot_row=bcadd($tot_row,$tva_item);
-                    $tot_tva=round(bcadd($tva_item,$tot_tva),2);
-                }
-                $r.='</td>';
-                /* warning if tva_computed and given are not the
-                   same */
-                $css_void_tva=($both_side == 
1)?'style="text-decoration:line-through"':'';
-                if ( bcsub($tva_item,$tva_computed) != 0 && ! ($tva_item == 0 
&& $both_side == 1))
-                {
-
-                                        $r.='<td style="background-color:red" 
class="num" '.$css_void_tva.'>';
-                                        $r.=HtmlInput::infobulle(28);
-                                         $r.='<a href="#" class="error" 
style="display:inline" title="'. _("Attention Différence entre TVA calculée et 
donnée").'">'
-                                                       .nbm($tva_item).'<a>';
-                }
-                else{
-                        $r.='<td  class="num" '.$css_void_tva.'>';
-                        $r.=nbm($tva_item);
-                }
-                $r.='</td>';
-                $r.='<td class="num"> ';
-                $r.=nbm(round($amount,2));
-                $r.='</td>';
-            }
-            $r.='<td class="num">';
-            $r.=nbm(round($tot_row,2));
-            $r.='</td>';
-            // encode the pa
-            if ( $g_parameter->MY_ANALYTIC!='nu') // use of AA
-            {
-                // show form
-                $anc_op=new Anc_Operation($this->db);
-                $null=($g_parameter->MY_ANALYTIC=='op')?1:0;
-                $r.='<td>';
-                $p_mode=($p_summary==false)?1:0;
-                $p_array['pa_id']=$a_anc;
-                /* op is the operation it contains either a sequence or a 
jrnx.j_id */
-                $r.=HtmlInput::hidden('op[]=',$i);
-                
$r.=$anc_op->display_form_plan($p_array,$null,$p_mode,$i,$amount);
-                $r.='</td>';
-            }
-
-
-            $r.='</tr>';
-
-        }
-        // Add the sum
-        $decalage=($g_parameter->MY_TVA_USE == 
'Y')?'<td></td><td></td><td></td><td></td>':'<td></td>';
-         $tot = round(bcadd($tot_amount, $tot_tva), 2);
-        $tot_tva=nbm($tot_tva);
-        $tot=nbm($tot);
-        $str_tot=_('Totaux');
-        $tot_amount=nbm($tot_amount);
-        $r.=<<<EOF
-<tr class="highlight">
-    {$decalage}            
-     <td>
-                {$str_tot}
-     </td>
-    <td class="num">
-        {$tot_tva}
-    </td>
-    <td class="num">
-        {$tot_amount}
-    </td>
-    <td class="num">
-        {$tot}
-    </td>
-EOF;
-
-        $r.='</table>';
-        $r.='</p>';
-        if ( $g_parameter->MY_ANALYTIC!='nu' && !$p_summary) // use of AA
-            $r.='<input type="button" class="button" value="'._('Vérifiez 
imputation analytique').'" onClick="verify_ca(\'\');">';
-        
-        $r.=(! $p_summary )?'<div id="total_div_id" >':'<div>';
-        $r.='<h2>Totaux</h2>';
-        /* use VAT */
-        if ($g_parameter->MY_TVA_USE == 'Y') {
-            $r.='<table>';
-            $r.='<tr><td>Total HTVA</td>';
-            $r.=td(hb($tot_amount ),'class="num"');
-            foreach ($tva as $i => $value) {
-                $oTva->set_parameter('id', $i);
-                $oTva->load();
-
-                $r.='<tr><td>  TVA ' . $oTva->get_parameter('label').'</td>';
-                $r.=td(hb(nbm($tva[$i])),'class="num"');
-            }
-            $r.='<tr>'.td(_('Total TVA')).td(hb($tot_tva),'class="num"');
-            $r.='<tr>'.td(_('Total TVAC')).td(hb($tot),'class="num"');
-            $r.='</table>';
-        } else {
-            $r.='<br>Total '.hb($tot);
-        }
-        $r.='</div>';
-        /*  Add hidden */
-        $r.=HtmlInput::hidden('e_client',$e_client);
-        $r.=HtmlInput::hidden('nb_item',$nb_item);
-        $r.=HtmlInput::hidden('p_jrn',$p_jrn);
-        if ( isset($period))
-            $r.=HtmlInput::hidden('period',$period);
-        $r.=HtmlInput::hidden('e_comm',$e_comm);
-        $r.=HtmlInput::hidden('e_date',$e_date);
-        $r.=HtmlInput::hidden('e_ech',$e_ech);
-        $r.=HtmlInput::hidden('jrn_type',$jrn_type);
-        $r.=HtmlInput::hidden('e_pj',$e_pj);
-        $r.=HtmlInput::hidden('e_pj_suggest',$e_pj_suggest);
-        $mt=microtime(true);
-        $r.=HtmlInput::hidden('mt',$mt);
-
-        $e_mp=(isset($e_mp))?$e_mp:0;
-        $r.=HtmlInput::hidden('e_mp',$e_mp);
-        /* Paid by */
-        /* if the paymethod is not 0 and if a quick code is given */
-
-
-        for ($i=0;$i < $nb_item;$i++)
-        {
-            $r.=HtmlInput::hidden("e_march".$i,${"e_march".$i});
-            if (isset (${"e_march".$i."_label"})) 
$r.=HtmlInput::hidden("e_march".$i."_label",${"e_march".$i."_label"});
-            
$r.=HtmlInput::hidden("e_march".$i."_price",${"e_march".$i."_price"});
-            if ( $g_parameter->MY_TVA_USE=='Y' )
-            {
-                
$r.=HtmlInput::hidden("e_march".$i."_tva_id",${"e_march".$i."_tva_id"});
-                $r.=HtmlInput::hidden('e_march'.$i.'_tva_amount', 
${'e_march'.$i.'_tva_amount'});
-            }
-            $r.=HtmlInput::hidden("e_quant".$i,${"e_quant".$i});
-
-        }
-
-        /**
-         * 
-         */
-        if ( $e_mp!=0 && strlen (trim (${'e_mp_qcode_'.$e_mp})) != 0 )
-        {
-            $r.=HtmlInput::hidden('e_mp_qcode_'.$e_mp,${'e_mp_qcode_'.$e_mp});
-            $r.=HtmlInput::hidden('acompte',$acompte);
-                       
$r.=HtmlInput::hidden('e_comm_paiement',$e_comm_paiement);
-            /* needed for generating a invoice */
-           $r.=HtmlInput::hidden('qcode_benef', ${'e_mp_qcode_' . $e_mp});
-                       $fname = new Fiche($this->db);
-                       $fname->get_by_qcode(${'e_mp_qcode_' . $e_mp});
-            $r.='<h2>' . _("Payé par")." " . ${'e_mp_qcode_' . $e_mp} .
-                    " " . $fname->getName() . '</h2> ' . '<p class="decale">' 
. _('Déduction acompte ') . h($acompte) . '</p>' .
-                    _('Libellé :') . h($e_comm_paiement) ;
-            $r.='<br>';
-            $r.='<br>';
-        }
-        // check for upload piece
-
-        return $r;
-    }
-
-    /*!\brief the function extra info allows to
-     * - add a attachment
-     * - generate an invoice
-     * - insert extra info
-     *\return html string
-     */
-    public function extra_info()
-    {
-        $r="";
-        $r = '<div id="facturation_div_id" style="height:185px;height:10rem">';
-        $r.='<p class="decale">';
-        // check for upload piece
-        $file=new IFile();
-        $file->table=0;
-        $r.=_("Ajoutez une pièce justificative ");
-        $r.=$file->input("pj","");
-
-        if ( $this->db->count_sql("select md_id,md_name from document_modele 
where md_affect='ACH'") > 0 )
-        {
-
-            $r.=_('ou générer un document').' <input type="checkbox" 
name="gen_invoice" >';
-            // We propose to generate  the fee note
-            $doc_gen=new ISelect();
-            $doc_gen->name="gen_doc";
-            $doc_gen->value=$this->db->make_array(
-                                "select md_id,md_name ".
-                                " from document_modele where md_affect='ACH'");
-            $r.=$doc_gen->input().'<br>';
-        }
-        $r.='<br>';
-        $obj=new IText();
-        $r.=_('Numero de bon de commande : ').$obj->input('bon_comm').'<br>';
-        $r.=_('Autre information : ').$obj->input('other_info').'<br>';
-        $r.='</p>';
-        $r.='</div>';
-        return $r;
-    }
-
-
-    /**
-     * @brief update the payment
-     * @todo to remove, obsolete
-     * @deprecated
-     */
-    function show_unpaid_deprecated()
-    {
-        // Show list of unpaid sell
-        // Date - date of payment - Customer - amount
-        // Nav. bar
-        $step=$_SESSION['g_pagesize'];
-        $page=(isset($_GET['offset']))?$_GET['page']:1;
-        $offset=(isset($_GET['offset']))?$_GET['offset']:0;
-
-
-        $sql=SQL_LIST_UNPAID_INVOICE_DATE_LIMIT." and jr_def_id=".$this->id ;
-        list($max_line,$list)=$this->list_operation($sql,null,$offset,1);
-        $sql=SQL_LIST_UNPAID_INVOICE." and jr_def_id=".$this->id ;
-        list($max_line2,$list2)=$this->list_operation($sql,null,$offset,1);
-
-        // Get the max line
-        $m=($max_line2>$max_line)?$max_line2:$max_line;
-        $bar2=navigation_bar($offset,$m,$step,$page);
-
-        echo $bar2;
-        echo '<h2 class="info"> '._('Echeance dépassée').' </h2>';
-        echo $list;
-        echo  '<h2 class="info"> '._('Non Payée').' </h2>';
-        echo $list2;
-        echo $bar2;
-        // Add hidden parameter
-        $hid=new IHidden();
-
-        echo '<hr>';
-
-        if ( $m != 0 )
-            echo HtmlInput::submit('paid',_('Mise à jour paiement'));
-
-
-    }
-    /**
-     * Retrieve data from the view v_detail_purchase
-     * @global  $g_user connected user
-     * @param $p_from jrn.jr_tech_per from 
-     * @param type $p_end jrn.jr_tech_per to
-     * @return type
-     */
-    function get_detail_purchase($p_from,$p_end)
-    {
-        global $g_user;
-        // Journal valide
-        if ( $this->id == 0 ) die (__FILE__.":".__LINE__." Journal invalide");
-        
-        // Securite
-        if ( $g_user->get_ledger_access($this->id) == 'X' ) return null;
-        
-        // get the data from the view
-        $sql = "select * 
-                from v_detail_purchase
-                 where 
-                jr_def_id = $1 
-                and  jr_date >= (select p_start from parm_periode where p_id = 
$2) 
-               and  jr_date <= (select p_end from parm_periode where p_id  = 
$3) "
-                .' order by 
jr_date,substring(jr_pj_number,\'[0-9]+$\')::numeric asc ';
-        $ret = $this->db->exec_sql($sql, array($this->id,$p_from, $p_end));
-        return $ret;
-    }
-    /**
-     * @brief compute an array with the heading cells for the
-     * details, used for the export in CSV
-     * @return array
-     */
-    static function heading_detail_purchase()
-    {
-        $array['jr_id'] = _('Numéro opération');
-        $array['jr_date'] = _('Date');
-        $array['jr_date_paid'] = _('Date paiement');
-        $array['jr_ech'] = _('Date échéance');
-        $array['jr_tech_per'] = _('Période');
-        $array['jr_comment'] = _('Libellé');
-        $array['jr_pj_number'] = _('Pièce');
-        $array['jr_internal'] = _('Interne');
-        $array['jr_def_id'] = _('Code journal');
-        $array['j_poste'] = _('Poste');
-        $array['j_text'] = _('Commentaire');
-        $array['j_qcode'] = _('Code Item');
-        $array['item_card'] = _('N° fiche');
-        $array['item_name'] = _('Nom fiche');
-        $array['qp_supplier'] = _('N° fiche fournisseur');
-        $array['tiers_name'] = _('Nom fournisseur');
-        $array['quick_code'] = _('Code fournisseur');
-        $array['tva_label'] = _('Nom TVA');
-        $array['tva_comment'] = _('Commentaire TVA');
-        $array['tva_both_side'] = _('TVA annulée');
-        $array['vat_sided'] = _('TVA Non Payé');
-        $array['vat_code'] = _('Code TVA');
-        $array['vat'] = _('Montant TVA');
-        $array['price'] = _('Total HTVA');
-        $array['quantity'] = _('quantité');
-        $array['price_per_unit'] = _('PU');
-        $array['non_ded_amount'] = _('Montant ND');
-        $array['non_ded_tva'] = _('Montant TVA ND');
-        $array['non_ded_tva_recup'] = _('TVA récup.');
-        $array['htva'] = _('HTVA Opération');
-        $array['tot_vat'] = _('TVA Opération');
-        $array['tot_tva_np'] = _('TVA NP opération');
-        return $array;
-    }
-
-}
-
-
-
-
-
diff --git a/include/class_acc_ledger_sold.php 
b/include/class_acc_ledger_sold.php
deleted file mode 100644
index 0e8d45e..0000000
--- a/include/class_acc_ledger_sold.php
+++ /dev/null
@@ -1,1374 +0,0 @@
-<?php
-
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/* !\file
- * \brief class for the sold, herits from acc_ledger
- */
-require_once NOALYSS_INCLUDE.'/class_iselect.php';
-require_once NOALYSS_INCLUDE.'/class_icard.php';
-require_once NOALYSS_INCLUDE.'/class_ispan.php';
-require_once NOALYSS_INCLUDE.'/class_ihidden.php';
-require_once NOALYSS_INCLUDE.'/class_idate.php';
-require_once NOALYSS_INCLUDE.'/class_itext.php';
-require_once NOALYSS_INCLUDE.'/class_ifile.php';
-require_once NOALYSS_INCLUDE.'/class_acc_ledger.php';
-require_once NOALYSS_INCLUDE.'/class_acc_compute.php';
-require_once NOALYSS_INCLUDE.'/class_anc_operation.php';
-require_once NOALYSS_INCLUDE.'/user_common.php';
-require_once NOALYSS_INCLUDE.'/class_acc_payment.php';
-require_once NOALYSS_INCLUDE.'/ac_common.php';
-require_once NOALYSS_INCLUDE.'/class_own.php';
-require_once NOALYSS_INCLUDE.'/class_itva_popup.php';
-require_once NOALYSS_INCLUDE.'/class_acc_ledger_fin.php';
-require_once NOALYSS_INCLUDE.'/class_stock_goods.php';
-require_once NOALYSS_INCLUDE.'/class_acc_ledger.php';
-
-/* !\brief Handle the ledger of sold,
- *
- * @exception throw an exception is something is wrong
- */
-
-class Acc_Ledger_Sold extends Acc_Ledger {
-
-    function __construct($p_cn, $p_init) {
-        parent::__construct($p_cn, $p_init);
-        $this->type = 'VEN';
-    }
-
-    /* !\brief verify that the data are correct before inserting or confirming
-     * \param an array (usually $_POST)
-     * \return String
-     * \throw Exception if an error occurs
-     */
-
-    public function verify($p_array) {
-        global $g_parameter, $g_user;
-        
-        if (is_array($p_array ) == false || empty($p_array))
-                    throw new Exception ("Array empty");
-        
-        extract($p_array);
-        
-        /*
-         * Check needed value
-         */
-        check_parameter($p_array,'p_jrn,e_date,e_client');
-
-        /* check for a double reload */
-        if (isset($mt) && $this->db->count_sql('select jr_mt from jrn where 
jr_mt=$1', array($mt)) != 0)
-            throw new Exception(_('Double Encodage'), 5);
-
-        /* check if we can write into this ledger */
-        if ($g_user->check_jrn($p_jrn) != 'W')
-            throw new Exception(_('Accès interdit'), 20);
-
-        /* check if there is a customer */
-        if (strlen(trim($e_client)) == 0)
-            throw new Exception(_('Vous n\'avez pas donné de client'), 11);
-
-        /*  check if the date is valid */
-        if (isDate($e_date) == null) {
-            throw new Exception(_('Date invalide'), 2);
-        }
-
-        $oPeriode = new Periode($this->db);
-        if ($this->check_periode() == true) {
-            $tperiode = $period;
-            /* check that the datum is in the choosen periode */
-            $oPeriode->p_id = $period;
-            list ($min, $max) = $oPeriode->get_date_limit();
-
-            if (cmpDate($e_date, $min) < 0 ||
-                    cmpDate($e_date, $max) > 0)
-                throw new Exception(_('Date et periode ne correspondent pas'), 
6);
-        }
-        else {
-            $per = new Periode($this->db);
-            $tperiode = $per->find_periode($e_date);
-        }
-
-        /* check if the periode is closed */
-        if ($this->is_closed($tperiode) == 1) {
-            throw new Exception(_('Periode fermee'), 6);
-        }
-        /* check if we are using the strict mode */
-        if ($this->check_strict() == true) {
-            /* if we use the strict mode, we get the date of the last
-              operation */
-            $last_date = $this->get_last_date();
-            if ($last_date != null && cmpDate($e_date, $last_date) < 0)
-                throw new Exception(_('Vous utilisez le mode strict la 
dernière operation est date du ')
-                . $last_date . _(' vous ne pouvez pas encoder à une date 
antérieure'), 13);
-        }
-
-
-        $fiche = new Fiche($this->db);
-        $fiche->get_by_qcode($e_client);
-        if ($fiche->empty_attribute(ATTR_DEF_ACCOUNT) == true)
-            throw new Exception(_('La fiche ') . $e_client . _('n\'a pas de 
poste comptable'), 8);
-
-        /* get the account and explode if necessary */
-        $sposte = $fiche->strAttribut(ATTR_DEF_ACCOUNT);
-        // if 2 accounts, take only the debit one for customer
-        if (strpos($sposte, ',') != 0) {
-            $array = explode(',', $sposte);
-            $poste_val = $array[0];
-        } else {
-            $poste_val = $sposte;
-        }
-        /* The account exists */
-
-        $poste = new Acc_Account_Ledger($this->db, $poste_val);
-
-        if ($poste->load() == false) {
-            throw new Exception(_('Pour la fiche ') . $e_client . _(' le poste 
comptable [') . $poste->id . _('] n\'existe pas'), 9);
-        }
-
-        /* Check if the card belong to the ledger */
-        $fiche = new Fiche($this->db);
-        $fiche->get_by_qcode($e_client, 'deb');
-        if ($fiche->belong_ledger($p_jrn) != 1)
-            throw new Exception(_('La fiche ') . $e_client . _('n\'est pas 
accessible à ce journal'), 10);
-
-        $nb = 0;
-
-        //----------------------------------------
-        // foreach item
-        //----------------------------------------
-        for ($i = 0; $i < $nb_item; $i++) {
-            if (strlen(trim(${'e_march' . $i})) == 0)
-                continue;
-            /* check if amount are numeric and */
-            if (isNumber(${'e_march' . $i . '_price'}) == 0)
-                throw new Exception(_('La fiche ') . ${'e_march' . $i} . _('a 
un montant invalide [') . ${'e_march' . $i} . ']', 6);
-            if (isNumber(${'e_quant' . $i}) == 0)
-                throw new Exception(_('La fiche ') . ${'e_march' . $i} . _('a 
une quantité invalide [') . ${'e_quant' . $i} . ']', 7);
-            /* check if all card has a ATTR_DEF_ACCOUNT */
-            $fiche = new Fiche($this->db);
-            $fiche->get_by_qcode(${'e_march' . $i});
-            if ($fiche->empty_attribute(ATTR_DEF_ACCOUNT) == true)
-                throw new Exception(_('La fiche ') . ${'e_march' . $i} . 
_('n\'a pas de poste comptable'), 8);
-
-            // Check if the given tva id is valid
-            if ($g_parameter->MY_TVA_USE == 'Y') {
-                if (isNumber(${'e_march' . $i . '_tva_id'}) == 0)
-                    throw new Exception(_('La fiche ') . ${'e_march' . $i} . 
_('a un code tva invalide') . ' [' . ${'e_march' . $i . '_tva_id'} . ']', 13);
-                $tva_rate = new Acc_Tva($this->db);
-                $tva_rate->set_parameter('id', ${'e_march' . $i . '_tva_id'});
-                if ($tva_rate->load() != 0)
-                    throw new Exception(_('La fiche ') . ${'e_march' . $i} . 
_('a un code tva invalide') . ' [' . ${'e_march' . $i . '_tva_id'} . ']', 13);
-
-                /*
-                 * check if the accounting for VAT are valid
-                 */
-                $a_poste = explode(',', $tva_rate->tva_poste);
-
-                if (
-                        $this->db->get_value('select count(*) from tmp_pcmn 
where pcm_val=$1', array($a_poste[0])) == 0 ||
-                        $this->db->get_value('select count(*) from tmp_pcmn 
where pcm_val=$1', array($a_poste[1])) == 0)
-                    throw new Exception(_(" La TVA " . $tva_rate->tva_label . 
" utilise des postes comptables inexistants"));
-            }
-            // if 2 accounts, take only the credit one
-            /* The account exists */
-            $sposte = $fiche->strAttribut(ATTR_DEF_ACCOUNT);
-
-            if (strpos($sposte, ',') != 0) {
-                $array = explode(',', $sposte);
-                $poste_val = $array[1];
-            } else {
-                $poste_val = $sposte;
-            }
-            $poste = new Acc_Account_Ledger($this->db, $poste_val);
-            if ($poste->load() == false) {
-                throw new Exception(_('Pour la fiche ') . ${'e_march' . $i} . 
_(' le poste comptable [') . $poste->id . _('n\'existe pas'), 9);
-            }
-            /* Check if the card belong to the ledger */
-            $fiche = new Fiche($this->db);
-            $fiche->get_by_qcode(${'e_march' . $i});
-            if ($fiche->belong_ledger($p_jrn, 'cred') != 1)
-                throw new Exception(_('La fiche ') . ${'e_march' . $i} . 
_('n\'est pas accessible à ce journal'), 10);
-            $nb++;
-        }
-        if ($nb == 0)
-            throw new Exception(_('Il n\'y a aucune marchandise'), 12);
-        //------------------------------------------------------
-        // The "Paid By"  check
-        //------------------------------------------------------
-
-        if ($e_mp != 0) {
-            $this->check_payment($e_mp, ${"e_mp_qcode_" . $e_mp});
-        }
-    }
-
-    /* !\brief insert into the database, it calls first the verify function,
-     * change the value of this->jr_id and this->jr_internal
-     * * It generates the document if gen_invoice is set and save the middle 
of payment if any ($e_mp)
-     *
-     * \param $p_array is usually $_POST or a predefined operation
-     * \return string
-     * \note throw an Exception
-     */
-
-    public function insert($p_array = null) {
-        global $g_parameter;
-        extract($p_array);
-        $this->verify($p_array);
-
-        $group = $this->db->get_next_seq("s_oa_group"); /* for analytic */
-        $seq = $this->db->get_next_seq('s_grpt');
-        $this->id = $p_jrn;
-        $internal = $this->compute_internal_code($seq);
-        $this->internal = $internal;
-
-        $oPeriode = new Periode($this->db);
-        $check_periode = $this->check_periode();
-
-        if ($check_periode == true)
-            $tperiode = $period;
-        else
-            $tperiode = $oPeriode->find_periode($e_date);
-
-        $cust = new Fiche($this->db);
-        $cust->get_by_qcode($e_client);
-        $sposte = $cust->strAttribut(ATTR_DEF_ACCOUNT);
-
-        // if 2 accounts, take only the debit one for the customer
-        //
-        if (strpos($sposte, ',') != 0) {
-            $array = explode(',', $sposte);
-            $poste = $array[0];
-        } else {
-            $poste = $sposte;
-        }
-
-        bcscale(4);
-        try {
-            $tot_amount = 0;
-            $tot_tva = 0;
-            $tot_debit = 0;
-            $this->db->start();
-            $tva = array();
-            /* Save all the items without vat */
-            for ($i = 0; $i < $nb_item; $i++) {
-                $n_both = 0;
-                if (strlen(trim(${'e_march' . $i})) == 0)
-                    continue;
-
-                /* First we save all the items without vat */
-                $fiche = new Fiche($this->db);
-                $fiche->get_by_qcode(${"e_march" . $i});
-                $amount = bcmul(${'e_march' . $i . '_price'}, ${'e_quant' . 
$i});
-                $tot_amount = round(bcadd($tot_amount, $amount),2);
-                $acc_operation = new Acc_Operation($this->db);
-                $acc_operation->date = $e_date;
-                $sposte = $fiche->strAttribut(ATTR_DEF_ACCOUNT);
-
-                // if 2 accounts, take only the credit one
-                if (strpos($sposte, ',') != 0) {
-                    $array = explode(',', $sposte);
-                    $poste_val = $array[1];
-                } else {
-                    $poste_val = $sposte;
-                }
-
-                $acc_operation->poste = $poste_val;
-                $acc_operation->amount = $amount;
-                $acc_operation->grpt = $seq;
-                $acc_operation->jrn = $p_jrn;
-                $acc_operation->type = 'c';
-                $acc_operation->periode = $tperiode;
-                if ($g_parameter->MY_UPDLAB == 'Y')
-                    $acc_operation->desc = strip_tags(${"e_march" . $i . 
"_label"});
-                else
-                    $acc_operation->desc = null;
-
-                $acc_operation->qcode = ${"e_march" . $i};
-                if ($amount < 0)
-                    $tot_debit = bcadd($tot_debit, abs($amount));
-
-                $j_id = $acc_operation->insert_jrnx();
-
-                if ($g_parameter->MY_TVA_USE == 'Y') {
-                    /* Compute sum vat */
-                    $oTva = new Acc_Tva($this->db);
-                    $idx_tva = ${'e_march' . $i . '_tva_id'};
-                    $tva_item = ${'e_march' . $i . '_tva_amount'};
-                    $oTva->set_parameter("id", $idx_tva);
-                    $oTva->load();
-                    /* if empty then we need to compute it */
-                    if (trim($tva_item) == '' || ${'e_march'.$i.'_tva_amount'} 
== 0) {
-                        /* retrieve tva */
-                        $l = new Acc_Tva($this->db, $idx_tva);
-                        $l->load();
-                        $tva_item = bcmul($amount, $l->get_parameter('rate'));
-                    }
-                    if (isset($tva[$idx_tva]))
-                        $tva[$idx_tva]+=$tva_item;
-                    else
-                        $tva[$idx_tva] = $tva_item;
-                    if ($oTva->get_parameter("both_side") == 0) {
-                        $tot_tva = round(bcadd($tva_item, $tot_tva), 2);
-                    } else {
-                        $n_both = $tva_item;
-                        if ($n_both < 0)
-                            $tot_debit = bcadd($tot_debit, abs($n_both));
-                    }
-                }
-
-                /* Save the stock */
-                /* if the quantity is < 0 then the stock increase (return of
-                 *  material)
-                 */
-                $nNeg = (${"e_quant" . $i} < 0) ? -1 : 1;
-
-                // always save quantity but in withStock we can find
-                // what card need a stock management
-                if ($g_parameter->MY_STOCK = 'Y' && isset($repo))
-                {
-                    $dir=(${'e_quant'.$i} < 0 ) ? 'd':'c';
-                    Stock_Goods::insert_goods($this->db, array('j_id' => 
$j_id, 'goods' => ${'e_march' . $i}, 'quant' => $nNeg * ${'e_quant' . $i}, 
'dir' => $dir, 'repo' => $repo));
-                }
-
-
-                if ($g_parameter->MY_ANALYTIC != "nu") {
-                    // for each item, insert into operation_analytique */
-                    $op = new Anc_Operation($this->db);
-                    $op->oa_group = $group;
-                    $op->j_id = $j_id;
-                    $op->oa_date = $e_date;
-                    $op->oa_debit = 'f';
-                    $op->oa_description = sql_string($e_comm);
-                    $op->save_form_plan($_POST, $i, $j_id);
-                }
-                if ($g_parameter->MY_TVA_USE == 'Y') {
-                    /* save into quant_sold */
-                    $r = $this->db->exec_sql("select insert_quant_sold 
($1,$2,$3,$4,$5,$6,$7,$8,$9)", array(null, /* 1 */
-                        $j_id, /* 2 */
-                        ${'e_march' . $i}, /* 3 */
-                        ${'e_quant' . $i}, /* 4 */
-                        round($amount, 2), /* 5 */
-                        $tva_item, /* 6 */
-                        $idx_tva, /* 7 */
-                        $e_client, /* 8 */
-                        $n_both));
-                } else {
-                    $r = $this->db->exec_sql("select insert_quant_sold 
($1,$2,$3,$4,$5,$6,$7,$8,$9) ", array(null, /* 1 */
-                        $j_id, /* 2 */
-                        ${'e_march' . $i}, /* 3 */
-                        ${'e_quant' . $i}, /* 4 */
-                        $amount, // 5
-                        0,
-                        null,
-                        $e_client,
-                        0));
-                }  // if ( $g_parameter->MY_TVA_USE=='Y') {
-            }// end loop : save all items
-
-            /*  save total customer */
-            $cust_amount = bcadd($tot_amount, $tot_tva);
-            $acc_operation = new Acc_Operation($this->db);
-            $acc_operation->date = $e_date;
-            $acc_operation->poste = $poste;
-            $acc_operation->amount = $cust_amount;
-            $acc_operation->grpt = $seq;
-            $acc_operation->jrn = $p_jrn;
-            $acc_operation->type = 'd';
-            $acc_operation->periode = $tperiode;
-            $acc_operation->qcode = ${"e_client"};
-            if ($cust_amount > 0)
-                $tot_debit = bcadd($tot_debit, $cust_amount);
-            $let_tiers = $acc_operation->insert_jrnx();
-
-
-            /** save all vat
-             * $i contains the tva_id and value contains the vat amount
-             * if if ($g_parameter->MY_TVA_USE == 'Y' )
-             */
-            if ($g_parameter->MY_TVA_USE == 'Y') {
-                foreach ($tva as $i => $value) {
-                    $oTva = new Acc_Tva($this->db);
-                    $oTva->set_parameter('id', $i);
-                    $oTva->load();
-
-                    $poste_vat = $oTva->get_side('c');
-
-                    $cust_amount = bcadd($tot_amount, $tot_tva);
-                    $acc_operation = new Acc_Operation($this->db);
-                    $acc_operation->date = $e_date;
-                    $acc_operation->poste = $poste_vat;
-                    $acc_operation->amount = $value;
-                    $acc_operation->grpt = $seq;
-                    $acc_operation->jrn = $p_jrn;
-                    $acc_operation->type = 'c';
-                    $acc_operation->periode = $tperiode;
-                    if ($value < 0)
-                        $tot_debit = bcadd($tot_debit, abs($value));
-                    $acc_operation->insert_jrnx();
-
-                    // if TVA is on both side, we deduce it immediately
-                    if ($oTva->get_parameter("both_side") == 1) {
-                        $poste_vat = $oTva->get_side('d');
-                        $cust_amount = bcadd($tot_amount, $tot_tva);
-                        $acc_operation = new Acc_Operation($this->db);
-                        $acc_operation->date = $e_date;
-                        $acc_operation->poste = $poste_vat;
-                        $acc_operation->amount = $value;
-                        $acc_operation->grpt = $seq;
-                        $acc_operation->jrn = $p_jrn;
-                        $acc_operation->type = 'd';
-                        $acc_operation->periode = $tperiode;
-                        $acc_operation->insert_jrnx();
-                        $tot_debit = bcadd($tot_debit, $value);
-                        $n_both = $value;
-                    }
-                }
-            } // if ($g_parameter->MY_TVA_USE=='Y')
-            /* insert into jrn */
-            $acc_operation = new Acc_Operation($this->db);
-            $acc_operation->date = $e_date;
-            $acc_operation->echeance = $e_ech;
-            $acc_operation->amount = abs(round($tot_debit, 2));
-            $acc_operation->desc = $e_comm;
-            $acc_operation->grpt = $seq;
-            $acc_operation->jrn = $p_jrn;
-            $acc_operation->periode = $tperiode;
-            $acc_operation->pj = $e_pj;
-            $acc_operation->mt = $mt;
-
-            $this->jr_id = $acc_operation->insert_jrn();
-
-            $this->pj = $acc_operation->set_pj();
-
-            /*             * = e_pj then do not increment sequence */
-            /* and e_pj is not null */
-            if (strcmp($e_pj, $e_pj_suggest) == 0 && strlen(trim($e_pj)) != 0) 
{
-                $this->inc_seq_pj();
-            }
-
-            $this->db->exec_sql("update jrn set jr_internal='" . $internal . 
"' where " .
-                    " jr_grpt_id = " . $seq);
-
-            /* update quant_sold */
-            $this->db->exec_sql('update quant_sold set qs_internal = $1 where 
j_id in (select j_id from jrnx where j_grpt=$2)', array($internal, $seq));
-
-            /* Save the attachment or generate doc */
-            if (isset($_FILES['pj'])) {
-                if (strlen(trim($_FILES['pj']['name'])) != 0)
-                    $this->db->save_upload_document($seq);
-                else
-                /* Generate an invoice and save it into the database */
-                if (isset($_POST['gen_invoice'])) {
-                    $file = $this->create_document($internal, $p_array);
-                    $this->doc='<A class="line" HREF="show_pj.php?' . 
dossier::get() . '&jr_grpt_id=' . $seq . '&jrn=' . $this->id . '">' . $file . 
'</A>';
-                }
-            }
-            //----------------------------------------
-            // Save the payer
-            //----------------------------------------
-            if ($e_mp != 0) {
-                /* mp */
-                $mp = new Acc_Payment($this->db, $e_mp);
-                $mp->load();
-
-                /* fiche */
-                $fqcode = ${'e_mp_qcode_' . $e_mp};
-                $acfiche = new Fiche($this->db);
-                $acfiche->get_by_qcode($fqcode);
-
-                /* jrnx */
-                $acseq = $this->db->get_next_seq('s_grpt');
-                $acjrn = new Acc_Ledger($this->db, 
$mp->get_parameter('ledger_target'));
-                $acinternal = $acjrn->compute_internal_code($acseq);
-
-                /* Insert paid by  */
-                $acc_pay = new Acc_Operation($this->db);
-                $acc_pay->date = $e_date;
-                /* get the account and explode if necessary */
-                $sposte = $acfiche->strAttribut(ATTR_DEF_ACCOUNT);
-                // if 2 accounts, take only the debit one for customer
-                if (strpos($sposte, ',') != 0) {
-                    $array = explode(',', $sposte);
-                    $poste_val = $array[0];
-                } else {
-                    $poste_val = $sposte;
-                }
-                $famount = bcsub($cust_amount, $acompte);
-                $acc_pay->poste = $poste_val;
-                $acc_pay->qcode = $fqcode;
-                $acc_pay->amount = abs(round($famount, 2));
-                $acc_pay->desc = null;
-
-                $acc_pay->grpt = $acseq;
-                $acc_pay->jrn = $mp->get_parameter('ledger_target');
-                $acc_pay->periode = $tperiode;
-                $acc_pay->type = ($famount >= 0) ? 'd' : 'c';
-                $acc_pay->insert_jrnx();
-
-                /* Insert supplier  */
-                $acc_pay = new Acc_Operation($this->db);
-                $acc_pay->date = $e_date;
-                $acc_pay->poste = $poste;
-                $acc_pay->qcode = $e_client;
-                $acc_pay->amount = abs(round($famount, 2));
-                $acc_pay->desc = null;
-                $acc_pay->grpt = $acseq;
-                $acc_pay->jrn = $mp->get_parameter('ledger_target');
-                $acc_pay->periode = $tperiode;
-                $acc_pay->type = ($famount >= 0) ? 'c' : 'd';
-                $let_other = $acc_pay->insert_jrnx();
-
-                /* insert into jrn */
-                $acc_pay->mt = $mt;
-                $acjrn->grpt_id = $acseq;
-                $acc_pay->desc = (!isset($e_comm_paiement) || 
strlen(trim($e_comm_paiement)) == 0) ? $e_comm : $e_comm_paiement;
-                $mp_jr_id = $acc_pay->insert_jrn();
-                $acjrn->update_internal_code($acinternal);
-
-                $r1 = $this->get_id($internal);
-                $r2 = $this->get_id($acinternal);
-
-                /*
-                 * add lettering
-                 */
-                $oletter = new Lettering($this->db);
-                $oletter->insert_couple($let_tiers, $let_other);
-
-
-                /* set the flag paid */
-                $Res = $this->db->exec_sql("update jrn set jr_rapt='paid' 
where jr_id=$1", array($r1));
-
-                /* Reconcialiation */
-                $rec = new Acc_Reconciliation($this->db);
-                $rec->set_jr_id($r1);
-                $rec->insert($r2);
-
-
-                /*
-                 * save also into quant_fin
-                 */
-
-                /* get ledger property */
-                $ledger = new Acc_Ledger_Fin($this->db, $acc_pay->jrn);
-                $prop = $ledger->get_propertie();
-
-                /* if ledger is FIN then insert into quant_fin */
-                if ($prop['jrn_def_type'] == 'FIN') {
-                    $ledger->insert_quant_fin($acfiche->id, $mp_jr_id, 
$cust->id, bcmul($famount, 1));
-                }
-            }
-        } catch (Exception $e) {
-            echo '<span class="error">' .
-            'Erreur dans l\'enregistrement ' .
-            __FILE__ . ':' . __LINE__ . ' ' .
-            $e->getMessage();
-            echo $e->getTrace();
-
-            $this->db->rollback();
-            throw new Exception ($e);
-        }
-        $this->db->commit();
-
-        return $internal;
-    }
-
-    /* !
-     * @brief show the summary of the operation and propose to save it
-     * @param array contains normally $_POST. It proposes also to save
-     * the Analytic accountancy
-     * @param $p_summary false for the feedback, true to show the summary
-     * @return string
-     *
-     */
-
-    function confirm($p_array, $p_summary = false) {
-        global $g_parameter;
-        extract($p_array);
-
-        // don't need to verify for a summary
-        if (!$p_summary)
-            $this->verify($p_array);
-        $anc = null;
-        // to show a select list for the analytic & VAT USE
-        // if analytic is op (optionnel) there is a blank line
-
-        bcscale(4);
-        $client = new Fiche($this->db);
-        $client->get_by_qcode($e_client, true);
-
-        $client_name = $client->getName() .
-                ' ' . $client->strAttribut(ATTR_DEF_ADRESS) . ' ' .
-                $client->strAttribut(ATTR_DEF_CP) . ' ' .
-                $client->strAttribut(ATTR_DEF_CITY);
-        $lPeriode = new Periode($this->db);
-        if ($this->check_periode() == true) {
-            $lPeriode->p_id = $period;
-        } else {
-            $lPeriode->find_periode($e_date);
-        }
-        $date_limit = $lPeriode->get_date_limit();
-        $r = "";
-        
-        $r.='<TABLE>';
-        if ( $p_summary ) {
-            $jr_id=$this->db->get_value('select jr_id from jrn where 
jr_internal=$1',array($this->internal));
-            $r.="<tr>";
-            $r.='<td>';
-            $r.=_('Détail opération ');
-            $r.='</td>';
-            $r.='<td>';
-            $r.=sprintf ('<a class="line" style="display:inline" 
href="javascript:modifyOperation(%d,%d)">%s</a>',
-                    $jr_id,dossier::id(),$this->internal);
-            $r.='</td>';
-            $r.="</tr>";
-        }
-        $r.='<tr>';
-        if ( ! $p_summary) {
-            $r.='<td>' . _('Numéro Pièce') .'</td><td>'. hb($e_pj) . '</td>';
-        } else {
-            
-             if ( strcmp($this->pj,$e_pj) != 0 )
-            {
-                $r.='<td>' . _('Numéro Pièce') .'</td><td>'. hb($this->pj) . 
-                        '<span class="notice"> '._('Attention numéro pièce 
existante, elle a du être adaptée').'</span></td>';
-            } else {
-                $r.='<td>' . _('Numéro Pièce') .'</td><td>'. hb($this->pj) . 
'</td>';
-            }
-        }
-        $r.='</tr>';
-        $r.='<tr>';
-        $r.='<td> ' . _('Date') . '</td><td> ' . hb($e_date) . '</td>';
-        $r.='</tr>';
-        $r.='<tr>';
-        $r.='<td>' . _('Echeance') . '</td><td> ' . hb($e_ech) . '</td>';
-        $r.='</tr>';
-        $r.='<tr>';
-        $r.='<td> ' . _('Période Comptable') . '</td><td> ' .hb( 
$date_limit['p_start'] . '-' . $date_limit['p_end']) . '</td>';
-        $r.='</tr>';
-        $r.='<tr>';
-        $r.='<td> ' . _('Journal') . '</td><td> ' . hb($this->get_name()) . 
'</td>';
-        $r.='</tr>';
-        $r.='<tr>';
-        $r.='<td> ' . _('Libellé') . '</td><td> ' . hb($e_comm) . '</td>';
-        $r.='</tr>';
-        
-        $r.='<tr>';
-        $r.='<td> ' . _('Client') . '</td><td> ' . hb($e_client . ':' . 
$client_name) . '</td>';
-        $r.='</tr>';
-        $r.='</table>';
-        $r.='<h2>' . _('Détail articles vendus') . '</h2>';
-        $r.='<p class="decale">';
-        $r.='<table class="result" >';
-        $r.='<TR>';
-        $r.="<th>" . _('Code') . "</th>";
-        $r.="<th>" . _('Dénomination') . "</th>";
-        $r.="<th style=\"text-align:right\">" . _('prix') . "</th>";
-        $r.="<th style=\"text-align:right\">" . _('quantité') . "</th>";
-
-
-        if ($g_parameter->MY_TVA_USE == 'Y') {
-            $r.="<th style=\"text-align:right\">" . _('tva') . "</th>";
-            $r.='<th style="text-align:right"> ' . _('Montant TVA') . '</th>';
-            $r.='<th style="text-align:right">' . _('Montant HTVA') . '</th>';
-            $r.='<th style="text-align:right">' . _('Montant TVAC') . '</th>';
-        } else {
-            $r.='<th style="text-align:right">' . _('Montant') . '</th>';
-        }
-        /* if we use the AC */
-        if ($g_parameter->MY_ANALYTIC != 'nu') {
-            $anc = new Anc_Plan($this->db);
-            $a_anc = $anc->get_list();
-            $x = count($a_anc);
-            /* set the width of the col */
-            $r.='<th colspan="' . $x . '">' . _('Compt. Analytique') . '</th>';
-
-            /* add hidden variables pa[] to hold the value of pa_id */
-            $r.=Anc_Plan::hidden($a_anc);
-        }
-        $r.='</tr>';
-        $tot_amount = 0.0;
-        $tot_tva = 0.0;
-        for ($i = 0; $i < $nb_item; $i++) {
-            if (strlen(trim(${"e_march" . $i})) == 0)
-                continue;
-
-            /* retrieve information for card */
-            $fiche = new Fiche($this->db);
-            $fiche->get_by_qcode(${"e_march" . $i});
-            if ($g_parameter->MY_UPDLAB == 'Y')
-                $fiche_name = h(${"e_march" . $i . "_label"});
-            else
-                $fiche_name = $fiche->strAttribut(ATTR_DEF_NAME);
-            if ($g_parameter->MY_TVA_USE == 'Y') {
-                $oTva = new Acc_Tva($this->db);
-                $idx_tva = ${"e_march" . $i . "_tva_id"};
-
-                $oTva->set_parameter('id', $idx_tva);
-                $oTva->load();
-            }
-            $op = new Acc_Compute();
-            $amount = bcmul(${"e_march" . $i . "_price"}, ${'e_quant' . $i});
-            $op->set_parameter("amount", $amount);
-            if ($g_parameter->MY_TVA_USE == 'Y') {
-                $op->set_parameter('amount_vat_rate', 
$oTva->get_parameter('rate'));
-                $op->compute_vat();
-                $tva_computed = $op->get_parameter('amount_vat');
-                $tva_item = ${"e_march" . $i . "_tva_amount"};
-                if (isset($tva[$idx_tva]))
-                    $tva[$idx_tva]+=$tva_item;
-                else
-                    $tva[$idx_tva] = $tva_item;
-                $tot_tva = round(bcadd($tva_item, $tot_tva), 2);
-            }
-            $tot_amount = round(bcadd($tot_amount, $amount), 2);
-
-            $r.='<tr>';
-            $r.='<td>';
-            $r.=${"e_march" . $i};
-            $r.='</td>';
-            $r.='<TD style="border-bottom:1px dotted grey;">';
-            $r.=$fiche_name;
-            $r.='</td>';
-            $r.='<td class="num">';
-            $r.=nbm(${"e_march" . $i . "_price"});
-            $r.='</td>';
-            $r.='<td class="num">';
-            $r.=nbm(${"e_quant" . $i});
-            $r.='</td>';
-            $both_side=0;
-            if ($g_parameter->MY_TVA_USE == 'Y') {
-                $r.='<td class="num">';
-                $r.=$oTva->get_parameter('label');
-                $r.='</td>';
-                $both_side=$oTva->get_parameter("both_side");
-                /* warning if tva_computed and given are not the
-                  same */
-                if (bcsub($tva_item, $tva_computed) != 0 && ! ($tva_item == 0 
&& $both_side == 1)) {
-                    $r.='<td style="background-color:red" class="num">';
-                    $r.=HtmlInput::infobulle(28);
-                    $r.='<a href="#" class="error" style="display:inline" 
title="' . _("Attention Différence entre TVA calculée et donnée") . '">'
-                            . nbm($tva_item) . '<a>';
-                } else {
-                    $r.='<td  class="num">';
-                    $r.=nbm($tva_item);
-                }
-                $r.='</td>';
-                $r.='<td class="num">';
-                $r.=nbm($amount);
-                $r.='</td>';
-                $tot_row = bcadd($tva_item, $amount);
-                $r.=td(nbm($tot_row), 'class="num"');
-            } else {
-                $r.='<td class="num">';
-                $r.=nbm($amount);
-                $r.='</td>';
-            }
-            // encode the pa
-            if ($g_parameter->MY_ANALYTIC != 'nu') { // use of AA
-                // show form
-                $anc_op = new Anc_Operation($this->db);
-                $null = ($g_parameter->MY_ANALYTIC == 'op') ? 1 : 0;
-                $r.='<td>';
-                $p_mode = ($p_summary == false) ? 1 : 0;
-                $p_array['pa_id'] = $a_anc;
-                /* op is the operation it contains either a sequence or a 
jrnx.j_id */
-                $r.=HtmlInput::hidden('op[]=', $i);
-                $r.=$anc_op->display_form_plan($p_array, $null, $p_mode, $i, 
$amount);
-                $r.='</td>';
-            }
-
-
-            $r.='</tr>';
-        } // end loop item
-        //
-        // Add the sum
-        $decalage=($g_parameter->MY_TVA_USE == 
'Y')?'<td></td><td></td><td></td><td></td>':'<td></td>';
-         $tot = round(bcadd($tot_amount, $tot_tva), 2);
-        $tot_tva=nbm($tot_tva);
-        $tot=nbm($tot);
-        $str_tot=_('Totaux');
-        $tot_amount=nbm($tot_amount);
-        $r.=<<<EOF
-<tr class="highlight">
-    {$decalage}            
-     <td>
-                {$str_tot}
-     </td>
-    <td class="num">
-        {$tot_tva}
-    </td>
-    <td class="num">
-        {$tot_amount}
-    </td>
-    <td class="num">
-        {$tot}
-    </td>
-EOF;
-
-        $r.='</table>';
-        $r.='</p>';
-        if ($g_parameter->MY_ANALYTIC != 'nu' && ! $p_summary) // use of AA
-            $r.='<input type="button" class="button" value="' . _('Vérifiez 
Imputation Analytique') . '" onClick="verify_ca(\'\');">';
-        $r.=(! $p_summary )?'<div id="total_div_id" >':'<div>';
-        $r.='<h2>Totaux</h2>';
-       
-        /* use VAT */
-        if ($g_parameter->MY_TVA_USE == 'Y') {
-            $r.='<table>';
-            $r.='<tr><td>Total HTVA</td>';
-            $r.=td(hb($tot_amount ),'class="num"');
-            foreach ($tva as $i => $value) {
-                $oTva->set_parameter('id', $i);
-                $oTva->load();
-
-                $r.='<tr><td>  TVA ' . $oTva->get_parameter('label').'</td>';
-                $r.=td(hb(nbm($tva[$i])),'class="num"');
-            }
-            $r.='<tr>'.td(_('Total TVA')).td(hb($tot_tva),'class="num"');
-            $r.='<tr>'.td(_('Total TVAC')).td(hb($tot),'class="num"');
-            $r.='</table>';
-        } else {
-            $r.='<br>Total '.hb($tot);
-        }
-        $r.='</div>';
-        /*  Add hidden */
-        $r.=HtmlInput::hidden('e_client', $e_client);
-        $r.=HtmlInput::hidden('nb_item', $nb_item);
-        $r.=HtmlInput::hidden('p_jrn', $p_jrn);
-        $mt = microtime(true);
-        $r.=HtmlInput::hidden('mt', $mt);
-
-        if (isset($period))
-            $r.=HtmlInput::hidden('period', $period);
-        /* \todo comment les types hidden gérent ils des contenus avec des 
quotes, double quote ou < > ??? */
-        $r.=HtmlInput::hidden('e_comm', $e_comm);
-        $r.=HtmlInput::hidden('e_date', $e_date);
-        $r.=HtmlInput::hidden('e_ech', $e_ech);
-        $r.=HtmlInput::hidden('e_pj', $e_pj);
-        $r.=HtmlInput::hidden('e_pj_suggest', $e_pj_suggest);
-
-        $e_mp = (isset($e_mp)) ? $e_mp : 0;
-        $r.=HtmlInput::hidden('e_mp', $e_mp);
-        
-        if ( isset($repo) )  {
-            // Show the available repository
-            $r.= $this->select_depot($p_summary,$repo);
-        }
-
-        /* if the paymethod is not 0 and if a quick code is given */
-        if ($e_mp != 0 && strlen(trim(${'e_mp_qcode_' . $e_mp})) != 0) {
-            $r.=HtmlInput::hidden('e_mp_qcode_' . $e_mp, ${'e_mp_qcode_' . 
$e_mp});
-            $r.=HtmlInput::hidden('acompte', $acompte);
-            $r.=HtmlInput::hidden('e_comm_paiement', $e_comm_paiement);
-            /* needed for generating a invoice */
-            $r.=HtmlInput::hidden('qcode_benef', ${'e_mp_qcode_' . $e_mp});
-
-            $fname = new Fiche($this->db);
-            $fname->get_by_qcode(${'e_mp_qcode_' . $e_mp});
-            $r.='<h2>' . "Payé par " . ${'e_mp_qcode_' . $e_mp} .
-                    " " . $fname->getName() . '</h2> ' . '<p class="decale">' 
. _('Déduction acompte ') . h($acompte) . '</p>' .
-                    _('Libellé :') . h($e_comm_paiement) ;
-            $r.='<br>';
-        }
-
-        $r.=HtmlInput::hidden('jrn_type', $jrn_type);
-        for ($i = 0; $i < $nb_item; $i++) {
-            $r.=HtmlInput::hidden("e_march" . $i, ${"e_march" . $i});
-            if (isset(${"e_march" . $i . "_label"}))
-                $r.=HtmlInput::hidden("e_march" . $i . "_label", ${"e_march" . 
$i . "_label"});
-            $r.=HtmlInput::hidden("e_march" . $i . "_price", ${"e_march" . $i 
. "_price"});
-            if ($g_parameter->MY_TVA_USE == 'Y') {
-                $r.=HtmlInput::hidden("e_march" . $i . "_tva_id", ${"e_march" 
. $i . "_tva_id"});
-                $r.=HtmlInput::hidden("e_march" . $i . "_tva_amount", 
${"e_march" . $i . "_tva_amount"});
-            }
-            $r.=HtmlInput::hidden("e_quant" . $i, ${"e_quant" . $i});
-        }
-        return $r;
-    }
-
-    /* !\brief the function extra info allows to
-     * - add a attachment
-     * - generate an invoice
-     * - insert extra info
-     * \return string
-     */
-
-    public function extra_info() {
-        $r = '<div id="facturation_div_id" style="height:185px;height:10rem">';
-        // check for upload piece
-        $file = new IFile();
-        $file->table = 0;
-        $r.='<p class="decale">';
-        $r.=_("Ajoutez une pièce justificative ");
-        $r.=$file->input("pj", "");
-
-        if ($this->db->count_sql("select md_id,md_name from document_modele 
where md_affect='VEN'") > 0) {
-
-
-            $r.=_('ou générer une facture') . ' <input type="checkbox" 
name="gen_invoice" CHECKED>';
-            // We propose to generate  the invoice and some template
-            $doc_gen = new ISelect();
-            $doc_gen->name = "gen_doc";
-            $doc_gen->value = $this->db->make_array(
-                    "select md_id,md_name " .
-                    " from document_modele where md_affect='VEN'");
-            $r.=$doc_gen->input() . '<br>';
-        }
-        $r.='<br>';
-        $obj = new IText();
-        $r.=_('Numero de bon de commande : ') . $obj->input('bon_comm') . 
'<br>';
-        $r.=_('Autre information : ') . $obj->input('other_info') . '<br>';
-        $r.='</p>';
-        $r.='</div>';
-        return $r;
-    }
-
-    /**
-     * @brief update the payment
-     * @deprecated
-     * 
-     */
-
-    function show_unpaid() {
-        // Show list of unpaid sell
-        // Date - date of payment - Customer - amount
-        // Nav. bar
-        $step = $_SESSION['g_pagesize'];
-        $page = (isset($_GET['offset'])) ? $_GET['page'] : 1;
-        $offset = (isset($_GET['offset'])) ? $_GET['offset'] : 0;
-
-
-        $sql = SQL_LIST_UNPAID_INVOICE_DATE_LIMIT . " and jr_def_id=" . 
$this->id;
-        list($max_line, $list) = ListJrn($this->db, $sql, null, $offset, 1);
-        $sql = SQL_LIST_UNPAID_INVOICE . " and jr_def_id=" . $this->id;
-        list($max_line2, $list2) = ListJrn($this->db, $sql, null, $offset, 1);
-
-        // Get the max line
-        $m = ($max_line2 > $max_line) ? $max_line2 : $max_line;
-        $bar2 = navigation_bar($offset, $m, $step, $page);
-
-        echo $bar2;
-        echo '<h2 class="info"> ' . _('Echeance dépassée') . ' </h2>';
-        echo $list;
-        echo '<h2 class="info"> ' . _('Non Payée') . ' </h2>';
-        echo $list2;
-        echo $bar2;
-        // Add hidden parameter
-        $hid = new IHidden();
-
-        echo '<hr>';
-
-        if ($m != 0)
-            echo HtmlInput::submit('paid', _('Mise à jour paiement'));
-    }
-
-    /* !\brief display the form for entering data for invoice,
-     * \param $p_array is null or you can put the predef operation or the 
$_POST
-     *
-     * \return HTML string
-     */
-
-    function input($p_array = null, $p_readonly = 0) {
-        global $g_parameter, $g_user;
-        if ($p_array != null)
-            extract($p_array);
-
-        $flag_tva = $g_parameter->MY_TVA_USE;
-        /* Add button */
-        $f_add_button = new IButton('add_card');
-        $f_add_button->tabindex = -1;
-        $f_add_button->label = _('Créer une nouvelle fiche');
-        $f_add_button->set_attribute('ipopup', 'ipop_newcard');
-        $f_add_button->set_attribute('jrn', $this->id);
-        $f_add_button->javascript = "this.jrn=\$('p_jrn').value; 
select_card_type(this);";
-
-        $f_add_button2 = new IButton('add_card2');
-        $f_add_button2->tabindex = -1;
-        $f_add_button2->label = _('Créer une nouvelle fiche');
-        $f_add_button2->set_attribute('ipopup', 'ipop_newcard');
-        $f_add_button2->set_attribute('filter', $this->get_all_fiche_def());
-        //    $f_add_button2->set_attribute('jrn',$this->id);
-        $f_add_button2->javascript = " 
this.jrn=\$('p_jrn').value;select_card_type(this);";
-
-        $str_add_button = "";
-        $str_add_button2 = "";
-        if ($g_user->check_action(FICADD) == 1) {
-            $str_add_button = $f_add_button->input();
-            $str_add_button2 = $f_add_button2->input();
-        }
-        // The first day of the periode
-        $oPeriode = new Periode($this->db);
-        list ($l_date_start, $l_date_end) = 
$oPeriode->get_date_limit($g_user->get_periode());
-        if ($g_parameter->MY_DATE_SUGGEST == 'Y')
-            $op_date = (!isset($e_date) ) ? $l_date_start : $e_date;
-        else
-            $op_date = (!isset($e_date) ) ? '' : $e_date;
-
-
-        $e_ech = (isset($e_ech)) ? $e_ech : "";
-        $e_comm = (isset($e_comm)) ? $e_comm : "";
-
-        $r = '';
-        $r.=dossier::hidden();
-        $f_legend = _('Client');
-
-        $Echeance = new IDate();
-        $Echeance->setReadOnly(false);
-
-        $Echeance->tabindex = 2;
-        $label = HtmlInput::infobulle(4);
-        $f_echeance = $Echeance->input('e_ech', $e_ech, _('Echéance') . 
$label);
-        $Date = new IDate();
-        $Date->setReadOnly(false);
-
-        $f_date = $Date->input("e_date", $op_date);
-
-        $f_periode = '';
-        // Periode
-        //--
-        if ($this->check_periode() == true) {
-            $l_user_per = $g_user->get_periode();
-            $def = (isset($periode)) ? $periode : $l_user_per;
-
-            $period = new IPeriod("period");
-            $period->user = $g_user;
-            $period->cn = $this->db;
-            $period->value = $def;
-            $period->type = OPEN;
-            try {
-                $l_form_per = $period->input();
-            } catch (Exception $e) {
-                if ($e->getCode() == 1) {
-                    throw new Exception( _("Aucune période ouverte") );
-                }
-            }
-            $label = HtmlInput::infobulle(3);
-            $f_periode = '<td>' . _("Période comptable") . "</td> <td> $label 
" . $l_form_per . '</td>';
-        }
-        /* if we suggest the next pj, then we need a javascript */
-        $add_js = "";
-        if ($g_parameter->MY_PJ_SUGGEST == 'Y') {
-            $add_js = "update_pj();";
-        }
-        if ($g_parameter->MY_DATE_SUGGEST == 'Y') {
-            $add_js.='get_last_date();';
-        }
-        $add_js.='update_name();';
-        $add_js.='update_pay_method();';
-        $add_js.='update_row("sold_item");';
-
-        $wLedger = $this->select_ledger('VEN', 2);
-        if ($wLedger == null)
-            throw new Exception(_('Pas de journal disponible'));
-        $wLedger->table = 1;
-        $wLedger->javascript = 
"onChange='update_predef(\"ven\",\"f\",\"".$_REQUEST['ac']."\");$add_js'";
-        $wLedger->label = " Journal " . HtmlInput::infobulle(2);
-
-        $f_jrn = $wLedger->input();
-
-        $Commentaire = new IText();
-        $Commentaire->table = 0;
-        $Commentaire->setReadOnly(false);
-        $Commentaire->size = 60;
-        $Commentaire->tabindex = 3;
-
-        $label = HtmlInput::infobulle(1);
-
-        $f_desc = $Commentaire->input("e_comm", h($e_comm)) ;
-        // PJ
-        //--
-        /* suggest PJ ? */
-        $default_pj = '';
-        if ($g_parameter->MY_PJ_SUGGEST == 'Y') {
-            $default_pj = $this->guess_pj();
-        }
-
-        $pj = new IText();
-
-        $pj->table = 0;
-        $pj->name = "e_pj";
-        $pj->size = 10;
-        $pj->value = (isset($e_pj)) ? $e_pj : $default_pj;
-        $f_pj = $pj->input() . HtmlInput::hidden('e_pj_suggest', $default_pj);
-        // Display the customer
-        //--
-        $fiche = 'deb';
-
-        // Save old value and set a new one
-        //--
-        $e_client = ( isset($e_client) ) ? $e_client : "";
-        $e_client_label = "&nbsp;"; //str_pad("",100,".");
-        // retrieve e_client_label
-        //--
-
-        if (strlen(trim($e_client)) != 0) {
-            $fClient = new Fiche($this->db);
-            $fClient->get_by_qcode($e_client);
-            $e_client_label = $fClient->strAttribut(ATTR_DEF_NAME) . ' ' .
-                    ' Adresse : ' . $fClient->strAttribut(ATTR_DEF_ADRESS) . ' 
' .
-                    $fClient->strAttribut(ATTR_DEF_CP) . ' ' .
-                    $fClient->strAttribut(ATTR_DEF_CITY) . ' ';
-        }
-
-        $W1 = new ICard();
-        $W1->label = "Client " . HtmlInput::infobulle(0);
-        $W1->name = "e_client";
-        $W1->tabindex = 3;
-        $W1->value = $e_client;
-        $W1->table = 0;
-        $W1->set_dblclick("fill_ipopcard(this);");
-        $W1->set_attribute('ipopup', 'ipopcard');
-
-        // name of the field to update with the name of the card
-        $W1->set_attribute('label', 'e_client_label');
-        // name of the field to update with the name of the card
-        $W1->set_attribute('typecard', 'deb');
-
-        // Add the callback function to filter the card on the jrn
-        $W1->set_callback('filter_card');
-        $W1->set_function('fill_data');
-        $W1->javascript = sprintf(' onchange="fill_data_onchange(\'%s\');" ', 
$W1->name);
-        $f_client_qcode = $W1->input();
-        $client_label = new ISpan();
-        $client_label->table = 0;
-        $f_client = $client_label->input("e_client_label", $e_client_label);
-        $f_client_bt = $W1->search();
-
-
-        // Record the current number of article
-        $Hid = new IHidden();
-        $p_article = ( isset($nb_item)) ? $nb_item : $this->get_min_row();
-        $r.=$Hid->input("nb_item", $p_article);
-        $max = ($p_article < $this->get_min_row()) ? $this->get_min_row() : 
$p_article;
-
-
-        $f_legend_detail = _("Détail articles vendus");
-
-        // For each article
-        //--
-        for ($i = 0; $i < $max; $i++) {
-            // Code id, price & vat code
-            //--
-            $march = (isset(${"e_march$i"})) ? ${"e_march$i"} : "";
-            $march_price = (isset(${"e_march" . $i . "_price"})) ? ${"e_march" 
. $i . "_price"} : ""  ;
-            if ($flag_tva == 'Y') {
-                $march_tva_id = (isset(${"e_march$i" . "_tva_id"})) ? 
${"e_march$i" . "_tva_id"} : "";
-                $march_tva_amount = (isset(${"e_march$i" . "_tva_amount"})) ? 
${"e_march$i" . "_tva_amount"} : "";
-            }
-            $march_label = (isset(${"e_march" . $i . "_label"})) ? ${"e_march" 
. $i . "_label"} : "";
-
-            // retrieve the tva label and name
-            //--
-            if (strlen(trim($march)) != 0 && strlen(trim($march_label)) == 0) {
-                $fMarch = new Fiche($this->db);
-                $fMarch->get_by_qcode($march);
-                $march_label = $fMarch->strAttribut(ATTR_DEF_NAME);
-                if ($flag_tva == 'Y') {
-                    if (!(isset(${"e_march$i" . "_tva_id"})))
-                        $march_tva_id = $fMarch->strAttribut(ATTR_DEF_TVA);
-                }
-            }
-            // Show input
-            //--
-            $W1 = new ICard();
-            $W1->label = "";
-            $W1->name = "e_march" . $i;
-            $W1->value = $march;
-            $W1->table = 1;
-            $W1->set_attribute('typecard', 'cred');
-            $W1->set_dblclick("fill_ipopcard(this);");
-            $W1->set_attribute('ipopup', 'ipopcard');
-
-            // name of the field to update with the name of the card
-            $W1->set_attribute('label', 'e_march' . $i . '_label');
-            // name of the field with the price
-            $W1->set_attribute('price', 'e_march' . $i . '_price');
-            // name of the field with the TVA_ID
-            $W1->set_attribute('tvaid', 'e_march' . $i . '_tva_id');
-            // Add the callback function to filter the card on the jrn
-            $W1->set_callback('filter_card');
-            $W1->set_function('fill_data');
-            $W1->javascript = sprintf(' onchange="fill_data_onchange(\'%s\');" 
', $W1->name);
-
-            $W1->readonly = false;
-
-            $array[$i]['quick_code'] = $W1->input();
-            $array[$i]['bt'] = $W1->search();
-            // For computing we need some hidden field for holding the value
-            $array[$i]['hidden'] = '';
-            if ($flag_tva == 'Y')
-                $array[$i]['hidden'].=HtmlInput::hidden('tva_march' . $i, 0);
-
-            $htva = new INum('htva_march' . $i);
-            $htva->readOnly = 1;
-            $htva->value = 0;
-            $array[$i]['htva'] = $htva->input();
-
-            if ($g_parameter->MY_TVA_USE == 'Y')
-                $tvac = new INum('tvac_march' . $i);
-            else
-                $tvac = new IHidden('tvac_march' . $i);
-
-            $tvac->readOnly = 1;
-            $tvac->value = 0;
-            $array[$i]['tvac'] = $tvac->input();
-
-            if ($g_parameter->MY_UPDLAB == 'Y') {
-                $Span = new IText("e_march" . $i . "_label");
-
-                $Span->css_size = "100%";
-            } else {
-                $Span = new ISpan("e_march" . $i . "_label");
-            }
-            $Span->value = $march_label;
-            $Span->setReadOnly(false);
-            // card's name, price
-            //--
-            $array[$i]['denom'] = $Span->input("e_march" . $i . "_label", 
$march_label);
-            // price
-            $Price = new INum();
-            $Price->setReadOnly(false);
-            $Price->size = 9;
-            $Price->javascript = 
"onBlur='format_number(this);clean_tva($i);compute_ledger($i)'";
-            $array[$i]['pu'] = $Price->input("e_march" . $i . "_price", 
$march_price);
-            $array[$i]['tva'] = '';
-            $array[$i]['amount_tva'] = '';
-            // if tva is not needed then no tva field
-            if ($flag_tva == 'Y') {
-                // vat label
-                //--
-                $Tva = new ITva_Popup($this->db);
-                $Tva->in_table = true;
-                $Tva->set_attribute('compute', $i);
-
-                $Tva->js = 'onblur="format_number(this);clean_tva(' . $i . 
');compute_ledger(' . $i . ')"';
-                $Tva->value = $march_tva_id;
-                $array[$i]['tva'] = $Tva->input("e_march$i" . "_tva_id");
-                // vat amount
-                //--
-                $wTva_amount = new INum();
-                $wTva_amount->readOnly = false;
-                $wTva_amount->size = 6;
-                $wTva_amount->javascript = 
"onBlur='format_number(this);compute_ledger($i)'";
-                $array[$i]['amount_tva'] = $wTva_amount->input("e_march" . $i 
. "_tva_amount", $march_tva_amount);
-            }
-            // quantity
-            //--
-            $quant = (isset(${"e_quant$i"})) ? ${"e_quant$i"} : "1"
-            ;
-            $Quantity = new INum();
-            $Quantity->setReadOnly(false);
-            $Quantity->size = 8;
-            $Quantity->javascript = 
"onChange='format_number(this);clean_tva($i);compute_ledger($i)'";
-            $array[$i]['quantity'] = $Quantity->input("e_quant" . $i, $quant);
-        }// foreach article
-        $f_type = _('Client');
-
-
-        ob_start();
-        require_once NOALYSS_INCLUDE.'/template/form_ledger_detail.php';
-        $r.=ob_get_contents();
-        ob_end_clean();
-
-
-
-        // Set correctly the REQUEST param for jrn_type
-        $r.=HtmlInput::hidden('jrn_type', 'VEN');
-
-        $r.=HtmlInput::button('add_item', _('Ajout article'), ' 
onClick="ledger_add_row()"');
-        $r.= create_script("$('" . $Date->id . "').focus()");
-        return $r;
-    }
-    /**
-     * Retrieve data from the view v_detail_sale
-     * @global  $g_user connected user
-     * @param $p_from jrn.jr_tech_per from 
-     * @param type $p_end jrn.jr_tech_per to
-     * @return type
-     */
-    function get_detail_sale($p_from,$p_end)
-    {
-        global $g_user;
-        // Journal valide
-        if ( $this->id == 0 ) die (__FILE__.":".__LINE__." Journal invalide");
-        
-        // Securite
-        if ( $g_user->get_ledger_access($this->id) == 'X' ) return null;
-        
-        // get the data from the view
-        $sql = "select * 
-                from v_detail_sale
-                 where 
-                jr_def_id = $1 
-                and  jr_date >= (select p_start from parm_periode where p_id = 
$2) 
-               and  jr_date <= (select p_end from parm_periode where p_id  = 
$3) "
-                .' order by 
jr_date,substring(jr_pj_number,\'[0-9]+$\')::numeric asc ';
-        $ret = $this->db->exec_sql($sql, array($this->id,$p_from, $p_end));
-        return $ret;
-    }
-    /**
-     * @brief compute an array with the heading cells for the
-     * details, used for the export in CSV
-     * @return array
-     */
-    static function heading_detail_sale()
-    {
-        $array['jr_id'] = _('Numéro opération');
-        $array['jr_date'] = _('Date');
-        $array['jr_date_paid'] = _('Date paiement');
-        $array['jr_ech'] = _('Date échéance');
-        $array['jr_tech_per'] = _('Période');
-        $array['jr_comment'] = _('Libellé');
-        $array['jr_pj_number'] = _('Pièce');
-        $array['jr_internal'] = _('Interne');
-        $array['jr_def_id'] = _('Code journal');
-        $array['j_poste'] = _('Poste');
-        $array['j_text'] = _('Commentaire');
-        $array['j_qcode'] = _('Code Item');
-        $array['item_card'] = _('N° fiche');
-        $array['item_name'] = _('Nom fiche');
-        $array['qs_client'] = _('N° fiche fournisseur');
-        $array['tiers_name'] = _('Nom fournisseur');
-        $array['quick_code'] = _('Code fournisseur');
-        $array['tva_label'] = _('Nom TVA');
-        $array['tva_comment'] = _('Commentaire TVA');
-        $array['tva_both_side'] = _('TVA annulée');
-        $array['vat_sided'] = _('TVA Non Payé');
-        $array['vat_code'] = _('Code TVA');
-        $array['vat'] = _('Montant TVA');
-        $array['price'] = _('Total HTVA');
-        $array['quantity'] = _('quantité');
-        $array['price_per_unit'] = _('PU');
-        $array['htva'] = _('HTVA Opération');
-        $array['tot_vat'] = _('TVA Opération');
-        return $array;
-    }
-    /* !\brief test function
-     */
-
-    static function test_me($p_string = '') {
-        $cn = new Database(dossier::id());
-        $a = new Acc_Ledger_Sold($cn, 2);
-        echo $a->input();
-    }
-    
-        }
-
diff --git a/include/class_acc_operation.php b/include/class_acc_operation.php
deleted file mode 100644
index 1de6fc4..0000000
--- a/include/class_acc_operation.php
+++ /dev/null
@@ -1,716 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief  this file match the tables jrn & jrnx the purpose is to
- *   remove or save accountant writing to these table.
- */
-require_once NOALYSS_INCLUDE.'/class_user.php';
-require_once NOALYSS_INCLUDE.'/class_acc_ledger.php';
-
-/*! \brief  this file match the tables jrn & jrnx the purpose is to
- *   remove or save accountant writing to these table.
- *
- */
-class Acc_Operation
-{
-    var $db;                           /*!< database connx */
-    var $jr_id;        /*!< pk of jrn */
-    var $jrn_id;                       /*!< jrn_def_id */
-    var $debit;                        /*!< debit or credit */
-    var $user;                 /*!< current user */
-    var $jrn;                  /*!< the ledger to use */
-    var $poste;                        /*!< account  */
-    var $date;                 /*!< the date */
-    var $periode;                      /*!< periode to use */
-    var $amount;                       /*!< amount of the operatoin */
-    var $grpt;                 /*!< the group id */
-    var $date_paid;
-    /*!
-     * \brief constructor set automatically the attributes user and periode
-     * \param $p_cn the databse connection
-     */
-    function __construct($p_cn)
-    {
-        global $g_user;
-        $this->db=$p_cn;
-        $this->qcode="";
-        $this->user=$_SESSION['g_user'];
-        $this->periode=$g_user->get_periode();
-        $this->jr_id=0;
-    }
-    /**
-     address@hidden retrieve the grpt_id from jrn for a jr_id
-     address@hidden jrn.jr_grpt_id or an empty string if not found
-     */
-    function seek_group()
-    {
-        $ret=$this->db->get_value('select jr_grpt_id from jrn where jr_id=$1',
-                                  array($this->jr_id));
-        return $ret;
-    }
-    /**
-     address@hidden  Insert into the table Jrn
-     *The needed data are :
-     * - this->date
-     * - this->amount
-     * - this->poste
-     * - this->grpt
-     * - this->jrn
-     * - this->type ( debit or credit)
-     * - this->user
-     * - this->periode
-     * - this->qcode
-     * - this->desc optional
-     address@hidden if the amount is less than 0 then side changes, for 
example debit becomes
-     *a credit and vice versa
-     address@hidden jrnx.j_id
-     */
-
-    function insert_jrnx()
-    {
-      if ( $this->poste == "") { return false; throw new  Exception 
(__FILE__.':'.__LINE__.' Poste comptable vide');}
-        /* for negative amount the operation is reversed */
-        if ( $this->amount < 0 )
-        {
-            $this->type=($this->type=='d')?'c':'d';
-        }
-        $this->amount=abs($this->amount);
-        $debit=($this->type=='c')?'false':'true';
-        $this->desc=(isset($this->desc))?$this->desc:'';
-        $Res=$this->db->exec_sql("select insert_jrnx
-                                 
($1::text,abs($2)::numeric,$3::account_type,$4::integer,$5::integer,$6::bool,$7::text,$8::integer,upper($9),$10::text)",
-                                 array(
-                                     $this->date, //$1
-                                     round($this->amount,2), //$2
-                                     $this->poste, //$3
-                                     $this->grpt, //$4
-                                     $this->jrn, //$5
-                                     $debit, //$6
-                                     $this->user, //$7
-                                     $this->periode, //$8
-                                     $this->qcode, // $9
-                                     $this->desc)); //$10
-        if ( $Res===false) return $Res;
-        $this->jrnx_id=$this->db->get_current_seq('s_jrn_op');
-        return $this->jrnx_id;
-
-    }
-    /*!\brief set the pj of a operation in jrn. the jr_id must be set
-     *\note if the jr_id it fails
-     */
-    function set_pj()
-    {
-        if ( strlen(trim($this->pj)) == 0 )
-        {
-            $sql="update jrn set jr_pj_number=$1 where jr_id=$2";
-            $this->db->exec_sql($sql,array(null,$this->jr_id));
-            return '';
-        }
-        /* is pj uniq ? */
-        if ( $this->db->count_sql("select jr_id from jrn where jr_pj_number=$1 
and jr_def_id=$2",
-                                  array($this->pj,$this->jrn)
-                                 ) == 0 )
-        {
-            $sql="update jrn set jr_pj_number=$1 where jr_id=$2";
-            $this->db->exec_sql($sql,array($this->pj,$this->jr_id));
-        }
-        else
-        {
-            /* get pref */
-            $pref=$this->db->get_value("select jrn_def_pj_pref from jrn_def 
where jrn_def_id=$1",
-                                       array($this->jrn));
-            /*  try another seq */
-            $flag=0;
-            $limit=100;
-            while ( $flag == 0 )
-            {
-                /*  limit the search to $limit */
-                if ( $limit < 1 )
-                {
-                    $this->pj='';
-                    $flag=2;
-                    break;
-                }
-
-                $seq=$this->db->get_next_seq('s_jrn_pj'.$this->jrn);
-                $this->pj=$pref.$seq;
-
-                /* check if the new pj numb exist */
-                $c=$this->db->count_sql("select jr_id from jrn where 
jr_pj_number=$1 and jr_def_id=$2",
-                                        array($this->pj,$this->jrn)
-                                       );
-                if ( $c == 0 )
-                {
-                    $flag=1;
-                    break;
-                }
-                $limit--;
-            }
-            /* a pj numb is found */
-            if ( $flag == 1 )
-            {
-                $sql="update jrn set jr_pj_number=$1 where jr_id=$2";
-                $this->db->exec_sql($sql,array($this->pj,$this->jr_id));
-            }
-        }
-        return $this->pj;
-    }
-
-    /*!
-     *\brief  Insert into the table Jrn, the amount is computed from jrnx 
thanks the
-     *        group id ($p_grpt)
-     *
-     * \return  sequence of jr_id
-     *
-     */
-
-    function insert_jrn()
-    {
-        $p_comment=$this->desc;
-
-        $diff=$this->db->get_value("select check_balance 
($1)",array($this->grpt));
-        if ( $diff != 0 )
-        {
-
-            echo "Erreur : balance incorrecte :diff = $diff";
-            return false;
-        }
-
-        $echeance=( isset( $this->echeance) && strlen(trim($this->echeance)) 
!= 0)?$this->echeance:null;
-        if ( ! isset($this->mt) )
-        {
-            $this->mt=microtime(true);
-        }
-        // if amount == -1then the triggers will throw an error
-        //
-        $Res=$this->db->exec_sql("insert into jrn 
(jr_def_id,jr_montant,jr_comment,".
-                                 "jr_date,jr_ech,jr_grpt_id,jr_tech_per,jr_mt) 
  values (".
-                                 "$1,$2,$3,".
-                                 
"to_date($4,'DD.MM.YYYY'),to_date($5,'DD.MM.YYYY'),$6,$7,$8)",
-                                 array ($this->jrn, $this->amount,$p_comment,
-                                        
$this->date,$echeance,$this->grpt,$this->periode,$this->mt)
-                                );
-        if ( $Res == false)  return false;
-        $this->jr_id=$this->db->get_current_seq('s_jrn');
-        return $this->jr_id;
-    }
-    /*!
-     * \brief  Return the internal value, the property jr_id must be set before
-     *
-     * \return  null si aucune valeur de trouv
-     *
-     */
-    function get_internal()
-    {
-        if ( ! isset($this->jr_id) )
-            throw new Exception('jr_id is not set',1);
-        $Res=$this->db->exec_sql("select jr_internal from jrn where 
jr_id=".$this->jr_id);
-        if ( Database::num_row($Res) == 0 ) return null;
-        $l_line=Database::fetch_array($Res);
-        $this->jr_internal= $l_line['jr_internal'];
-        return $this->jr_internal;
-    }
-    /*!\brief search an operation thankx it internal code
-     * \param internal code
-     * \return 0 ok -1 nok
-     */
-    function seek_internal($p_internal)
-    {
-        $res=$this->db->exec_sql('select jr_id from jrn where jr_internal=$1',
-                                 array($p_internal));
-        if ( Database::num_row($Res) == 0 ) return -1;
-        $this->jr_id=Database::fetch_result($Res,0,0);
-        return 0;
-    }
-    /*!\brief retrieve data from jrnx
-      *\note the data are filtered by the access of the current user
-     * \return an array
-     */
-    function get_jrnx_detail()
-    {
-        global $g_user;
-        $filter_sql=$g_user->get_ledger_sql('ALL',3);
-        $filter_sql=str_replace('jrn_def_id','jr_def_id',$filter_sql);
-        if ( $this->jr_id==0 ) return;
-        $sql=" select  jr_date,j_qcode,j_poste,j_montant,jr_internal,case when 
j_debit = 'f' then 'C' else 'D' end as debit,jr_comment as description,
-             
vw_name,pcm_lib,j_debit,coalesce(comptaproc.get_letter_jnt(j_id),-1) as 
letter,jr_def_id ".
-             " from jrnx join jrn on (jr_grpt_id=j_grpt)
-             join tmp_pcmn on (j_poste=pcm_val)
-             left join vw_fiche_attr on (j_qcode=quick_code)
-             where
-             jr_id=$1 and $filter_sql order by j_debit desc";
-        $res=$this->db->exec_sql($sql,array($this->jr_id));
-        if ( Database::num_row ($res) == 0 ) return array();
-        $all=Database::fetch_all($res);
-        return $all;
-    }
-    /*!\brief add a comment to the line (jrnx.j_text) */
-    function update_comment($p_text)
-    {
-        $sql="update jrnx set j_text=$1 where j_id=$2";
-        $this->db->exec_sql($sql,array($p_text,$this->jrnx_id));
-    }
-    /*!\brief add a comment to the operation (jrn.jr_text) */
-    function operation_update_comment($p_text)
-    {
-        $sql="update jrn set jr_comment=$1 where jr_id=$2";
-        $this->db->exec_sql($sql,array($p_text,$this->jr_id));
-    }
-    /*!\brief add a limit of payment to the operation (jrn.jr_ech) */
-    function operation_update_date_limit($p_text)
-    {
-        if ( isDate($p_text) == null )
-        {
-            $p_text=null;
-        }
-        $sql="update jrn set jr_ech=to_date($1,'DD.MM.YYYY') where jr_id=$2";
-        $this->db->exec_sql($sql,array($p_text,$this->jr_id));
-    }
-    /*!\brief return the jrn_def_id from jrn */
-    function get_ledger()
-    {
-        $sql="select jr_def_id from jrn where jr_id=$1";
-        $row=$this->db->get_value($sql,array($this->jr_id));
-        return $row;
-    }
-    /*!\brief display_jrnx_detail : get the data from get_jrnx_data and
-       return a string with HTML code
-     * \param table(=0 no code for table,1 code for table,2 code for CSV)
-
-    */
-    function display_jrnx_detail($p_table)
-    {
-        $show=$this->get_jrnx_detail();
-
-        $r='';
-        $r_notable='';
-        $csv="";
-        foreach ($show as $l)
-        {
-            $border="";
-            if ( $l['j_poste'] == $this->poste || ($l['j_qcode']==$this->qcode 
&& trim($this->qcode) != ''))
-                $border=' class="highlight"';
-            $r.='<tr '.$border.'>';
-            $r.='<td>';
-            $a=$l['j_qcode'];
-            
-            $r_notable.=$a;
-            $r.=$a;
-            $csv.='"'.$a.'";';
-            $r.='</td>';
-
-            $r.='<td  '.$border.'>';
-            $a=$l['j_poste'];
-            $r_notable.=$a;
-            $r.=$a;
-            $csv.='"'.$a.'";';
-            $r.='</td>';
-
-            $r.='<td  '.$border.'>';
-            //       $a=($l['vw_name']=="")?$l['j_qcode']:$l['pcm_lib'];
-            $a=(strlen(trim($l['j_qcode']))==0)?$l['pcm_lib']:$l['vw_name'];
-            $r_notable.=$a;
-            $r.=h($a);
-            $csv.='"'.$a.'";';
-            $r.='</td>';
-
-            $r.='<td  '.$border.'>';
-            $a=$l['j_montant'];
-            $r_notable.=$a;
-            $r.=$a;
-            $csv.=$a.';';
-            $r.='</td>';
-
-            $r.='<td  '.$border.'>';
-            $a=$l['debit'];
-            $r_notable.=$a;
-            $r.=$a;
-            $csv.='"'.$a.'"';
-
-            $csv.="\r\n";
-            $r.='</td>';
-            $r.='<td  '.$border.'>';
-            $a=($l['letter']!=-1)?$l['letter']:'';
-            $r_notable.=$a;
-            $r.=$a;
-            $csv.='"'.$a.'"';
-
-            $csv.="\r\n";
-            $r.='</td>';
-
-
-            $r.='</tr>';
-        }
-        switch ($p_table)
-        {
-        case 1:
-            return $r;
-            break;
-        case 0:
-            return $r_notable;
-            break;
-        case 2:
-            return $csv;
-        }
-        return "ERROR PARAMETRE";
-    }
-    /*!
-     * @brief  Get data from jrnx where p_grpt=jrnx(j_grpt)
-     *
-     * @param connection
-     * @return array of 3 elements
-     *  - First Element is an array
-    @verbatim
-    Array
-    (
-        [op_date] => 01.12.2009
-        [class_cred0] => 7000008
-        [mont_cred0] => 8880.0000
-        [op_cred0] => 754
-        [text_cred0] =>
-        [jr_internal] => 23VEN-01-302
-        [comment] =>
-        [ech] =>
-        [jr_id] => 302
-        [jr_def_id] => 2
-        [class_deb0] => 4000005
-        [mont_deb0] => 10744.8000
-        [text_deb0] =>
-        [op_deb0] => 755
-        [class_cred1] => 4511
-        [mont_cred1] => 1864.8000
-        [op_cred1] => 756
-        [text_cred1] =>
-    )
-    @endverbatim
-     *  - Second  : number of line with debit
-     *  - Third  : number of line with credit
-     */
-    function get_data ($p_grpt)
-    {
-        $Res=$this->db->exec_sql("select
-                                 to_char(j_date,'DD.MM.YYYY') as j_date,
-                                 j_text,
-                                 j_debit,
-                                 j_poste,
-                                 coalesce(j_qcode,'-') as qcode,
-                                 j_montant,
-                                 j_id,
-                                 jr_comment,
-                                 to_char(jr_ech,'DD.MM.YYYY') as jr_ech,
-                                 to_char(jr_date,'DD.MM.YYYY') as jr_date,
-                                 jr_id,jr_internal,jr_def_id,jr_pj
-                                 from jrnx inner join jrn on j_grpt=jr_grpt_id 
where j_grpt=$1",array($p_grpt));
-        $MaxLine=Database::num_row($Res);
-        if ( $MaxLine == 0 ) return null;
-        $deb=0;
-        $cred=0;
-        for ( $i=0; $i < $MaxLine; $i++)
-        {
-
-            $l_line=Database::fetch_array($Res,$i);
-            $l_array['op_date']=$l_line['j_date'];
-            if ( $l_line['j_debit'] == 't' )
-            {
-                $l_class=sprintf("class_deb%d",$deb);
-                $l_montant=sprintf("mont_deb%d",$deb);
-                $l_text=sprintf("text_deb%d",$deb);
-                $l_qcode=sprintf("qcode_deb%d",$deb);
-                $l_array[$l_class]=$l_line['j_poste'];
-                $l_array[$l_montant]=$l_line['j_montant'];
-                $l_array[$l_text]=$l_line['j_text'];
-                $l_array[$l_qcode]=$l_line['qcode'];
-                $l_id=sprintf("op_deb%d",$deb);
-                $l_array[$l_id]=$l_line['j_id'];
-                $deb++;
-            }
-            if ( $l_line['j_debit'] == 'f' )
-            {
-                $l_class=sprintf("class_cred%d",$cred);
-                $l_montant=sprintf("mont_cred%d",$cred);
-                $l_array[$l_class]=$l_line['j_poste'];
-                $l_array[$l_montant]=$l_line['j_montant'];
-                $l_id=sprintf("op_cred%d",$cred);
-                $l_array[$l_id]=$l_line['j_id'];
-                $l_text=sprintf("text_cred%d",$cred);
-                $l_array[$l_text]=$l_line['j_text'];
-                $l_qcode=sprintf("qcode_cred%d",$cred);
-                $l_array[$l_qcode]=$l_line['qcode'];
-                $cred++;
-            }
-            $l_array['jr_internal']=$l_line['jr_internal'];
-            $l_array['comment']=$l_line['jr_comment'];
-            $l_array['ech']=$l_line['jr_ech'];
-            $l_array['jr_id']=$l_line['jr_id'];
-            $l_array['jr_def_id']=$l_line['jr_def_id'];
-        }
-        return array($l_array,$deb,$cred);
-    }
-    /**
-    address@hidden retrieve data from jrnx and jrn
-    address@hidden return an object
-    address@hidden
-    address@hidden
-    @code
-
-    @endcode
-    */
-    function get()
-    {
-        $ret=new Acc_Misc($this->db,$this->jr_id);
-        $ret->get();
-        return $ret;
-    }
-    /**
-     address@hidden retrieve data from the table QUANT_*
-     address@hidden return an object or null if there is no
-     * data from the QUANT table
-     address@hidden Acc_Sold Acc_Purchase Acc_Fin Acc_Detail Acc_Misc
-     */
-    function get_quant()
-    {
-        $ledger_id=$this->get_ledger();
-        if ( $ledger_id=='') throw new Exception(_('Journal non trouvé'));
-        $oledger=new Acc_Ledger($this->db,$ledger_id);
-
-        // retrieve info from jrn_info
-
-
-        switch($oledger->get_type())
-        {
-        case 'VEN':
-            $ret=new Acc_Sold($this->db,$this->jr_id);
-            break;
-        case 'ACH':
-            $ret=new Acc_Purchase($this->db,$this->jr_id);
-            break;
-        case 'FIN':
-            $ret=new Acc_Fin($this->db,$this->jr_id);
-            break;
-        default:
-                       $ret=new Acc_Misc($this->db,$this->jr_id);
-                       break;
-        }
-        $ret->get();
-        if ( empty($ret->det->array))
-        {
-            $ret=new Acc_Misc($this->db,$this->jr_id);
-            $ret->get();
-        }
-        $ret->get_info();
-        return $ret;
-    }
-    /**
-     * @brief retrieve info from the jrn_info, create 2 new arrays
-     * obj->info->command and obj->info->other
-     * the columns are the idx
-     */
-    function get_info()
-    {
-        $this->info=new stdClass();
-        // other info
-        $array=$this->db->get_value("select ji_value from jrn_info where
-            jr_id=$1 and id_type=$2",array($this->jr_id,'OTHER'));
-        $this->info->other= $array;
-
-        // Bon de commande
-        $array=$this->db->get_value("select ji_value from jrn_info where
-            jr_id=$1 and id_type=$2",array($this->jr_id,'BON_COMMANDE'));
-        $this->info->command=  $array;
-
-    }
-    /**
-     * Save into jrn_info
-     * @param $p_info msg to save
-     * @param $p_type is OTHER or BON_COMMAND
-     */
-    function save_info($p_info,$p_type)
-    {
-        if ( ! in_array($p_type,array('OTHER','BON_COMMANDE'))) return;
-        if (trim($p_info)=="") {
-            $this->db->exec_sql('delete from jrn_info where jr_id=$1 and 
id_type=$2',array($this->jr_id,$p_type));
-            return;
-        }
-        $exist=$this->db->get_value('select count(ji_id) from jrn_info where 
jr_id=$1 and id_type=$2',array($this->jr_id,$p_type));
-        if ( $exist == "0" ) {
-            //insert into jrn_info
-            $this->db->exec_sql('insert into jrn_info(jr_id,id_type,ji_value) 
values ($1,$2,$3)',
-                    array($this->jr_id,$p_type,$p_info));
-        } elseif ( $exist == 1) {
-            //update
-            $this->db->exec_sql('update jrn_info set ji_value=$3 where 
jr_id=$1 and id_type=$2',
-                    array($this->jr_id,$p_type,$p_info));
-        }
-    }
-    
-    function insert_related_action($p_string)
-    {
-        if ($p_string == "") return;
-        $a_action=explode(',',$p_string);
-        for ($i=0;$i<count($a_action);$i++)
-        {
-            $action = new Follow_Up($this->db,$a_action[$i]);
-            $action->operation=$this->jr_id;
-            $action->insert_operation();
-        }
-    }
-    static function test_me()
-    {
-        $_SESSION['g_user']='phpcompta';
-        $_SESSION['g_pass']='dany';
-        global $g_user;
-        $cn=new Database(dossier::id());
-        $g_user=new User($cn);
-        $a=new Acc_Operation($cn);
-        $a->jr_id=1444;
-        $b=$a->get_quant();
-        var_dump($b);
-    }
-}
-/////////////////////////////////////////////////////////////////////////////
-class Acc_Detail extends Acc_Operation
-{
-    function __construct($p_cn,$p_jrid=0)
-    {
-        parent::__construct($p_cn);
-        $this->jr_id=$p_jrid;
-        $this->det=new stdClass();
-    }
-    /**
-     address@hidden retrieve some common data from jrn as
-     * the datum, the comment,payment limit...
-     */
-    function get()
-    {
-        $sql="SELECT jr_id, jr_def_id, jr_montant, jr_comment, jr_date, 
jr_grpt_id,
-             jr_internal, jr_tech_date, jr_tech_per, jrn_ech, jr_ech, 
jr_rapt,jr_ech,
-             jr_valid, jr_opid, jr_c_opid, jr_pj, jr_pj_name, jr_pj_type,
-             jr_pj_number, jr_mt,jr_rapt,jr_date_paid
-             FROM jrn where jr_id=$1";
-        $array=$this->db->get_array($sql,array($this->jr_id));
-        if ( count($array) == 0 ) throw new Exception('Aucune ligne trouvée');
-        foreach ($array[0] as $key=>$val)
-        {
-            $this->det->$key=$val;
-        }
-       $sql="select n_text from jrn_note where jr_id=$1";
-       $this->det->note=$this->db->get_value($sql,array($this->jr_id));
-       $this->det->note=strip_tags($this->det->note);
-    }
-}
-/////////////////////////////////////////////////////////////////////////////
-/**
- address@hidden this class manage data from the JRNX and JRN
- * table
- address@hidden Data member are the column of the table
- */
-class Acc_Misc extends Acc_Detail
-{
-    var $signature;            /*!< signature of the obj ODS */
-    var $array;                /*!< an array containing the data from JRNX */
-    function __construct($p_cn,$p_jrid=0)
-    {
-        parent::__construct($p_cn,$p_jrid);
-        $this->signature='ODS';
-        $this->det=new stdClass();
-    }
-    function get()
-    {
-        parent::get();
-        $sql="SELECT j_id, j_date, j_montant, j_poste, j_grpt, j_rapt, 
j_jrn_def,
-             j_debit, j_text, j_centralized, j_internal, j_tech_user, 
j_tech_date,
-             j_tech_per, j_qcode
-             FROM jrnx where j_grpt = $1 order by j_debit desc,j_poste";
-        
$this->det->array=$this->db->get_array($sql,array($this->det->jr_grpt_id));
-    }
-}
-/////////////////////////////////////////////////////////////////////////////
-/**
- address@hidden this class manage data from the QUANT_SOLD
- * table
- address@hidden Data member are the column of the table
- */
-class Acc_Sold extends Acc_Detail
-{
-    function __construct($p_cn,$p_jrid=0)
-    {
-        parent::__construct($p_cn,$p_jrid);
-        $this->signature='VEN';
-        $this->det=new stdClass();
-    }
-    function get()
-    {
-        parent::get();
-        $sql="SELECT qs_id, qs_internal, qs_fiche, qs_quantite, qs_price, 
qs_vat,
-             qs_vat_code, qs_client, qs_valid, j_id,j_text,qs_vat_sided
-             FROM quant_sold  join jrnx using(j_id) where j_grpt=$1";
-        
$this->det->array=$this->db->get_array($sql,array($this->det->jr_grpt_id));
-    }
-    
-}
-/////////////////////////////////////////////////////////////////////////////
-/**
- address@hidden this class manage data from the QUANT_PURCHASE
- * table
- address@hidden Data member are the column of the table
-
- */
-class Acc_Purchase extends Acc_Detail
-{
-    function __construct($p_cn,$p_jrid=0)
-    {
-        parent::__construct($p_cn,$p_jrid);
-        $this->signature='ACH';
-    }
-
-    function get()
-    {
-        parent::get();
-        $sql="SELECT qp_id, qp_internal, j_id, qp_fiche, qp_quantite, 
qp_price, qp_vat,
-             qp_vat_code, qp_nd_amount, qp_nd_tva, qp_nd_tva_recup, 
qp_supplier,
-             qp_valid, qp_dep_priv,j_text,qp_vat_sided
-             FROM quant_purchase  join jrnx using(j_id) where j_grpt=$1";
-        
$this->det->array=$this->db->get_array($sql,array($this->det->jr_grpt_id));
-    }
-}
-/////////////////////////////////////////////////////////////////////////////
-/**
- address@hidden this class manage data from the QUANT_FIN
- * table
- address@hidden Data member are the column of the table
- */
-class Acc_Fin extends Acc_Detail
-{
-    function __construct($p_cn,$p_jrid=0)
-    {
-        parent::__construct($p_cn,$p_jrid);
-        $this->signature='FIN';
-    }
-
-    function get()
-    {
-        parent::get();
-        $sql="SELECT qf_id, qf_bank, jr_id, qf_other, qf_amount
-             FROM quant_fin where jr_id = $1";
-        $this->det->array=$this->db->get_array($sql,array($this->jr_id));
-    }
-}
diff --git a/include/class_acc_parm_code.php b/include/class_acc_parm_code.php
deleted file mode 100644
index 21a4459..0000000
--- a/include/class_acc_parm_code.php
+++ /dev/null
@@ -1,182 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-// Copyright Author Dany De Bontridder address@hidden
-/*! \file
- * \brief Manage the table parm_code which contains the custom parameter
- * for the module accountancy
- */
-/*!
- * \brief Manage the table parm_code which contains the custom parameter
- * for the module accountancy
- */
-require_once NOALYSS_INCLUDE.'/class_itext.php';
-require_once NOALYSS_INCLUDE.'/class_acc_account_ledger.php';
-
-class Acc_Parm_Code
-{
-    var $db;        /*!< $db  database connection */
-    var $p_code;    /*!< $p_code  parm_code.p_code primary key */
-    var $p_value;   /*!< $p_value  parm_code.p_value  */
-    var $p_comment; /*!< $p_comment parm_code.p_comment */
-// constructor
-    function Acc_Parm_Code($p_cn,$p_id=-1)
-    {
-        $this->db=$p_cn;
-        $this->p_code=$p_id;
-        if ( $p_id != -1 )
-            $this->load();
-    }
-    /*!
-     **************************************************
-     * \brief  
-     *  Load all parmCode
-     *  return an array of Acc_Parm_Code object
-     *
-     * \return array
-     */
-
-    function load_all()
-    {
-        $sql="select * from parm_code order by p_code";
-        $Res=$this->db->exec_sql($sql);
-        $r= Database::fetch_all($Res);
-        $idx=0;
-        $array=array();
-
-        if ( $r === false ) return null;
-        foreach ($r as $row )
-        {
-            $o=new Acc_Parm_Code($this->db,$row['p_code']);
-            $array[$idx]=$o;
-            $idx++;
-        }
-
-        return $array;
-    }
-    /*!
-    **************************************************
-    * \brief  update a parm_object into the database
-    *        p_code is _not_ updatable
-    * \return
-    *     nothing
-    */
-    function save()
-    {
-        // if p_code=="" nothing to save
-        if ( $this->p_code== -1) return;
-        // check if the account exists
-        $acc=new Acc_Account_Ledger($this->db,$this->p_value);
-        if ( $acc->load() == false )
-        {
-            alert(_("Ce compte n'existe pas"));
-        }
-        else
-        {
-            $this->p_comment=sql_string($this->p_comment);
-            $this->p_value=sql_string($this->p_value);
-            $this->p_code=sql_string($this->p_code);
-            $sql="update parm_code set ".
-                 "p_comment='".$this->p_comment."'  ".
-                 ",p_value='".$this->p_value."'  ".
-                 "where p_code='".$this->p_code."'";
-            $Res=$this->db->exec_sql($sql);
-        }
-    }
-    /*!
-     **************************************************
-     * \brief  Display an object, with the <TD> tag
-     *        
-     * \return
-     *     string
-     */
-    function display()
-    {
-        $r="";
-        $r.= '<TD>'.$this->p_code.'</TD>';
-        $r.= '<TD>'.h($this->p_comment).'</TD>';
-        $r.= '<TD>'.$this->p_value.'</TD>';
-
-        return $r;
-    }
-    /*!
-     **************************************************
-     * \brief  Display a form to enter info about
-     *        a parm_code object with the <TD> tag
-     *    
-     * \return string
-     */
-    function form()
-    {
-        $comment=new IText();
-        $comment->name='p_comment';
-        $comment->value=$this->p_comment;
-        $comment->size=45;
-        $value=new IPoste();
-        $value->name='p_value';
-        $value->value=$this->p_value;
-        $value->size=7;
-        $value->set_attribute('ipopup','ipop_account');
-        $value->set_attribute('account','p_value');
-        $poste=new IText();
-        $poste->setReadOnly(true);
-        $poste->size=strlen($this->p_code)+1;
-        $poste->name='p_code';
-        $poste->value=$this->p_code;
-        $r="";
-        $r.='<tr>';
-        $r.='<td align="right"> Code </td>';
-        $r.= '<TD>'.$poste->input().'</TD>';
-        $r.='</tr>';
-        $r.='<tr>';
-        $r.='<td align="right"> Commentaire </td>';
-        $r.= '<TD>'.$comment->input().'</TD>';
-        $r.='</tr>';
-        $r.='<tr>';
-        $r.='<td align="right"> Poste comptable </td>';
-        $r.= '<TD>'.$value->input();
-        $r.='<span id="p_value_label"></span></td>';
-        $r.='</tr>';
-        $r.=Dossier::hidden();
-        return $r;
-
-    }
-
-    /*!
-     **************************************************
-     * \brief  
-     * Complete a parm_code object thanks the p_code 
-     *        
-     * \return array
-     */
-
-    function load()
-    {
-        if ( $this->p_code == -1 ) return "p_code non initialisé";
-        $sql='select * from parm_code where p_code=$1 ';
-
-        $Res=$this->db->exec_sql($sql,array($this->p_code));
-
-        if ( Database::num_row($Res) == 0 ) return 'INCONNU';
-        $row= Database::fetch_array($Res,0);
-        $this->p_value=$row['p_value'];
-        $this->p_comment=$row['p_comment'];
-
-    }
-
-}
diff --git a/include/class_acc_payment.php b/include/class_acc_payment.php
deleted file mode 100644
index 1cb9b60..0000000
--- a/include/class_acc_payment.php
+++ /dev/null
@@ -1,406 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief Handle the table mod_payment
- */
-require_once NOALYSS_INCLUDE.'/class_iselect.php';
-require_once NOALYSS_INCLUDE.'/class_icard.php';
-require_once NOALYSS_INCLUDE.'/class_ispan.php';
-require_once NOALYSS_INCLUDE.'/class_acc_ledger.php';
-require_once NOALYSS_INCLUDE.'/class_fiche.php';
-require_once NOALYSS_INCLUDE.'/class_fiche_def.php';
-require_once NOALYSS_INCLUDE.'/constant.php';
-/*!\brief Handle the table mod_payment
- *\note the private data member are accessed via
-  - mp_id  ==> id ( Primary key )
-  - mp_lib ==> lib (label)
-  - mp_jrn_def_id ==> ledger (Number of the ledger where to save)
-  - mp_fd_id ==> fiche_def (fiche class to use)
-  - mp_qcode ==> qcode (quick_code of the card)
- *
- */
-class Acc_Payment
-{
-
-    private static $variable=array("id"=>"mp_id",
-                                   "lib"=>"mp_lib",
-                                   "qcode"=>"mp_qcode",
-                                   "ledger_target"=>"mp_jrn_def_id",
-                                   "ledger_source"=>"jrn_def_id",
-                                   "fiche_def"=>"mp_fd_id");
-
-
-    private  $mp_lib;
-    private  $mp_qcode;
-    private  $mp_jrn_def_if;
-    private  $jrn_def_id;
-    private  $mp_fd_id;
-
-    function __construct ($p_cn,$p_init=0)
-    {
-        $this->cn=$p_cn;
-        $this->mp_id=$p_init;
-    }
-    public function get_parameter($p_string)
-    {
-        if ( array_key_exists($p_string,self::$variable) )
-        {
-            $idx=self::$variable[$p_string];
-            return $this->$idx;
-        }
-        else
-               {
-                       throw new Exception("Attribut inexistant $p_string");
-               }
-    }
-    public function set_parameter($p_string,$p_value)
-    {
-        if ( array_key_exists($p_string,self::$variable) )
-        {
-            $idx=self::$variable[$p_string];
-            $this->$idx=$p_value;
-        }
-        else
-            throw new Exception("Attribut inexistant $p_string");
-
-
-    }
-    public function get_info()
-    {
-        return var_export(self::$variable,true);
-    }
-    public function verify()
-    {
-        // Verify that the elt we want to add is correct
-    }
-    public function save()
-    {
-        /* please adapt */
-        if (  $this->get_parameter("id") == 0 )
-            $this->insert();
-        else
-            $this->update();
-    }
-
-    public function insert()
-    {
-        if ( $this->verify() != 0 ) return;
-        $sql='INSERT INTO mod_payment(
-             mp_lib, mp_jrn_def_id, mp_fd_id, mp_qcode,jrn_def_id)
-             VALUES ($1, $2, $3, upper($4),$5) returning mp_id';
-        $this->mp_id=$this->cn->exec_sql($sql,array(
-                                             $this->mp_lib,
-                                             $this->mp_jrn_def_id,
-                                             $this->mp_fd_id,
-                                             $this->mp_qcode,
-                                             $this->jrn_def_id));
-    }
-
-    public function update()
-    {
-        if ( $this->verify() != 0 ) return;
-
-        $sql="update mod_payment set 
mp_lib=$1,mp_qcode=$2,mp_jrn_def_id=$3,mp_fd_id=$4,jrn_def_id=$5 ".
-             " where mp_id = $6";
-        $res=$this->cn->exec_sql(
-                 $sql,
-                 array($this->mp_lib,
-                       $this->mp_qcode,
-                       $this->mp_jrn_def_id,
-                       $this->mp_fd_id,
-                       $this->jrn_def_id,
-                       $this->mp_id)
-             );
-        if ( strlen (trim($this->mp_jrn_def_id))==0)
-            $this->cn->exec_sql(
-                'update mod_payment '.
-                'set mp_jrn_def_id = null where mp_id=$1',
-                array($this->mp_id));
-        if ( strlen (trim($this->jrn_def_id))==0)
-            $this->cn->exec_sql(
-                'update mod_payment '.
-                'set mp_jrn_def_id = null where mp_id=$1',
-                array($this->mp_id));
-        if ( strlen (trim($this->mp_qcode))==0)
-            $this->cn->exec_sql(
-                'update mod_payment '.
-                'set mp_qcode = null where mp_id=$1',
-                array($this->mp_id));
-        if ( strlen (trim($this->mp_fd_id))==0)
-            $this->cn->exec_sql(
-                'update mod_payment '.
-                'set mp_fd_id = null where mp_id=$1',
-                array($this->mp_id));
-
-    }
-
-    public function load()
-    {
-        $sql='select mp_id,mp_lib,mp_fd_id,mp_jrn_def_id,mp_qcode,jrn_def_id 
from mod_payment '.
-             ' where mp_id = $1';
-        $res=$this->cn->exec_sql(
-                 $sql,
-                 array($this->mp_id)
-             );
-
-        if ( Database::num_row($res) == 0 ) return;
-        $row=Database::fetch_array($res,0);
-        foreach ($row as $idx=>$value)
-        {
-            $this->$idx=$value;
-        }
-
-    }
-    /**
-     address@hidden remove a middle of payment
-     */
-    public function delete()
-    {
-        $sql="delete from mod_payment where mp_id=$1";
-        $this->cn->exec_sql($sql,array($this->mp_id));
-    }
-    /*!\brief retrieve all the data for all ledgers
-     *\param non
-     *\return an array of row
-     */
-    public function get_all()
-    {
-        $sql='select mp_id,mp_lib '.
-             ' from mod_payment order by mp_lib';
-        $array=$this->cn->get_array($sql);
-        $ret=array();
-        if ( !empty($array) )
-        {
-            foreach ($array as $row)
-            {
-                $t=new Acc_Payment($this->cn,$row['mp_id']);
-                $t->load();
-                $ret[]=$t;
-            }
-        }
-        return $ret;
-    }
-    /*!\brief retrieve all the data for a ledger but filter on the
-     *valid record (jrn and fd not null
-     *\param non
-     *\return an array of row
-     */
-    public function get_valide()
-    {
-        $sql='select mp_id '.
-             ' from mod_payment '.
-             ' where jrn_def_id=$1 and mp_jrn_def_id is not null and '.
-             ' (mp_fd_id is not null or mp_qcode is not null)';
-        $array=$this->cn->get_array($sql,array($this->jrn_def_id));
-        $ret=array();
-        if ( !empty($array) )
-        {
-            foreach ($array as $row)
-            {
-                $t=new Acc_Payment($this->cn,$row['mp_id']);
-                $t->load();
-                $ret[]=$t;
-            }
-        }
-        return $ret;
-    }
-    /*!\brief return a string with a form (into a table)
-     *\param none
-     *\return a html string
-     */
-    public function form()
-    {
-       //label
-        $lib=new IText('mp_lib');
-        $lib->value=$this->mp_lib;
-               $f_lib=$lib->input();
-
-
-        $ledger_source=new ISelect('jrn_def_id');
-        $ledger_source->value=$this->cn->make_array("select 
jrn_def_id,jrn_Def_name from
-                              jrn_def where jrn_def_type  in ('ACH','VEN') 
order by jrn_def_name");
-               $ledger_source->selected=$this->jrn_def_id;
-        $f_source=$ledger_source->input();
-
-        // type of card
-        $tcard=new ISelect('mp_fd_id');
-        $tcard->value=$this->cn->make_array('select fd_id,fd_label from 
fiche_def join fiche_def_ref '.
-                                            ' using (frd_id) where frd_id in 
(25,4) order by fd_label');
-               $tcard->selected=$this->mp_fd_id;
-
-        $f_type_fiche=$tcard->input();
-        $ledger_record=new ISelect('mp_jrn_def_id');
-        $ledger_record->value=$this->cn->make_array("select 
jrn_def_id,jrn_Def_name from
-                              jrn_def where jrn_def_type  in ('ODS','FIN')");
-               $ledger_record->selected=$this->mp_jrn_def_id;
-        $f_ledger_record=$ledger_record->input();
-
-        // the card
-        $qcode=new ICard();
-        $qcode->noadd=true;
-        $qcode->name='mp_qcode';
-        $list=$this->cn->make_list('select fd_id from fiche_def where frd_id 
in (25,4)');
-        $qcode->typecard=$list;
-               $qcode->dblclick='fill_ipopcard(this);';
-               $qcode->value=$this->mp_qcode;
-
-        $f_qcode=$qcode->input();
-
-               $msg="Modification de ".$this->mp_lib;
-        ob_start();
-        require_once NOALYSS_INCLUDE.'/template/new_mod_payment.php';
-        $r=ob_get_contents();
-        ob_end_clean();
-        return $r;
-
-    }
-    /*!\brief show several lines with radio button to select the payment
-     *method we want to use, the $_POST['e_mp'] will be set
-     *\param none
-     *\return html string
-     */
-    public function select()
-    {
-        $r='';
-        $array=$this->get_valide();
-        $r.=HtmlInput::hidden('gDossier',dossier::id());
-
-        if ( empty($array)==false ) {
-            $acompte=new INum('acompte');
-            $acompte->value=0;
-            $r.=_(" Acompte à déduire");
-            $r.=$acompte->input();
-                       $r.='<p>';
-                       $e_comm_paiement=new IText('e_comm_paiement');
-                       $e_comm_paiement->table = 0;
-                       $e_comm_paiement->setReadOnly(false);
-                       $e_comm_paiement->size = 60;
-                       $e_comm_paiement->tabindex = 3;
-                       $r.=_(" Libellé du paiement");
-                       $r.=$e_comm_paiement->input();
-                       $r.='</p>';
-               }
-
-        $r.='<ol>';
-        $r.='<li ><input type="radio" name="e_mp" value="0" 
checked>'._('Paiement encodé plus tard');
-        if ( empty($array ) == false )
-        {
-            foreach ($array as $row)
-            {
-                $f='';
-                /* if the qcode is  null the propose a search button to select
-                   the card */
-                if ( $row->mp_qcode==NULL)
-                {
-                    $a=new ICard();
-                    $a->jrn=$row->mp_jrn_def_id;
-                                       
$a->set_attribute('typecard',$row->mp_fd_id);
-                    $a->name='e_mp_qcode_'.$row->mp_id;
-                    $a->set_dblclick("fill_ipopcard(this);");
-                    $a->set_callback('filter_card');
-                    $a->set_function('fill_data');
-                    $a->set_attribute('ipopup','ipopcard');
-                    $a->set_attribute('label',$a->name.'_label');
-
-                    $s=new ISpan();
-                    $s->name=$a->name.'_label';
-                    $f=_(" paiement par ").$a->input().$s->input();
-                }
-                else
-                {
-                    /* if the qcode is not null then add a hidden variable with
-                       the qcode */
-
-                    $fiche=new Fiche($this->cn);
-                    $fiche->get_by_qcode($row->mp_qcode);
-                    
$f=HtmlInput::hidden('e_mp_qcode_'.$row->mp_id,$row->mp_qcode);
-
-                    //   $f.=$fiche->strAttribut(ATTR_DEF_NAME);
-                }
-                $r.='<li><input type="radio" name="e_mp" 
value="'.$row->mp_id.'">';
-                $r.=$row->mp_lib.'  '.$f;
-
-            }
-        }
-        $r.='</ol>';
-        return $r;
-    }
-
-    /*!\brief convert an array into an Acc_Payment object
-     *\param array to convert
-     */
-    public function from_array($p_array)
-    {
-        
$idx=array('mp_id','mp_lib','mp_fd_id','mp_jrn_def_id','mp_qcode','jrn_def_id');
-        foreach ($idx as $l)
-        if (isset($p_array[$l])) $this->$l=$p_array[$l];
-    }
-    /**
-     address@hidden return an html with a form to add a new middle of payment
-     */
-    public function blank()
-    {
-        //label
-        $lib=new IText('mp_lib');
-        $f_lib=$lib->input();
-
-        $ledger_source=new ISelect('jrn_def_id');
-        $ledger_source->value=$this->cn->make_array("select 
jrn_def_id,jrn_Def_name from
-                              jrn_def where jrn_def_type  in ('ACH','VEN') 
order by jrn_def_name");
-        $f_source=$ledger_source->input();
-
-        // type of card
-        $tcard=new ISelect('mp_fd_id');
-        $tcard->value=$this->cn->make_array('select fd_id,fd_label from 
fiche_def join fiche_def_ref '.
-                                            ' using (frd_id) where frd_id in 
(25,4) order by fd_label');
-        $f_type_fiche=$tcard->input();
-        $ledger_record=new ISelect('mp_jrn_def_id');
-        $ledger_record->value=$this->cn->make_array("select 
jrn_def_id,jrn_Def_name from
-                              jrn_def where jrn_def_type  in ('ODS','FIN')");
-        $f_ledger_record=$ledger_record->input();
-
-        // the card
-        $qcode=new ICard();
-        $qcode->noadd=true;
-        $qcode->name='mp_qcode';
-        $list=$this->cn->make_list('select fd_id from fiche_def where frd_id 
in (25,4)');
-        $qcode->typecard=$list;
-               $qcode->dblclick='fill_ipopcard(this);';
-
-        $f_qcode=$qcode->input();
-               $msg="Ajout d'un nouveau moyen de paiement";
-        ob_start();
-        require_once NOALYSS_INCLUDE.'/template/new_mod_payment.php';
-        $r=ob_get_contents();
-        ob_end_clean();
-        return $r;
-    }
-    /*!\brief test function
-     */
-    static function test_me()
-    {
-
-    }
-
-}
-
-
diff --git a/include/class_acc_reconciliation.php 
b/include/class_acc_reconciliation.php
deleted file mode 100644
index 5127181..0000000
--- a/include/class_acc_reconciliation.php
+++ /dev/null
@@ -1,532 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- *   \brief class acc_reconciliation, this class is new and the code
- *   must use it
- *
- */
-require_once NOALYSS_INCLUDE.'/class_iconcerned.php';
-require_once  NOALYSS_INCLUDE.'/class_database.php';
-require_once  NOALYSS_INCLUDE.'/class_dossier.php';
-require_once NOALYSS_INCLUDE.'/class_lettering.php';
-
-/*! \brief new class for managing the reconciliation it must be used
- * instead of the function InsertRapt, ...
- *
- */
-class Acc_Reconciliation
-{
-    var $db;                   /*!< database connection */
-    var $jr_id;                        /*!< jr_id */
-
-    function   __construct($cn)
-    {
-        $this->db=$cn;
-        $this->jr_id=0;
-    }
-
-    function set_jr_id($jr_id)
-    {
-        $this->jr_id=$jr_id;
-    }
-    /*! \brief return a widget of type js_concerned
-     */
-    function widget()
-    {
-        $wConcerned=new IConcerned();
-        $wConcerned->extra=0; // with 0 javascript search from e_amount... 
field (see javascript)
-
-        return $wConcerned;
-
-    }
-    /*!
-     *\brief   Insert into jrn_rapt the concerned operations
-     *
-     * \param $jr_id2 (jrn.jr_id) => jrn_rapt.jra_concerned or a string
-     * like "jr_id2,jr_id3,jr_id4..."
-     *
-     * \return none
-     *
-     */
-    function insert($jr_id2)
-    {
-        if ( trim($jr_id2) == "" )
-            return;
-        if ( strpos($jr_id2,',') !== 0 )
-        {
-            $aRapt=explode(',',$jr_id2);
-            foreach ($aRapt as $rRapt)
-            {
-                if ( isNumber($rRapt) == 1 )
-                {
-                    $this->insert_rapt($rRapt);
-                }
-            }
-        }
-        else
-            if ( isNumber($jr_id2) == 1 )
-            {
-                $this->insert_rapt($jr_id2);
-            }
-    }
-
-    /*!
-     *\brief   Insert into jrn_rapt the concerned operations
-     * should not  be called directly, use insert instead
-     *
-     * \param $jr_id2 (jrn.jr_id) => jrn_rapt.jra_concerned
-     *
-     * \return none
-     *
-     */
-    function insert_rapt($jr_id2)
-    {
-        if ( isNumber($this->jr_id)  == 0 ||  isNumber($jr_id2) == 0 )
-        {
-            return false;
-        }
-        if ( $this->jr_id==$jr_id2)
-            return true;
-
-               if ( $this->db->count_sql("select jr_id from jrn where 
jr_id=".$this->jr_id)==0 )
-                               return false;
-               if ( $this->db->count_sql("select jr_id from jrn where 
jr_id=".$jr_id2)==0 )
-                               return false;
-
-        // verify if exists
-        if ( $this->db->count_sql(
-                    "select jra_id from jrn_rapt where 
jra_concerned=".$this->jr_id.
-                    " and jr_id=$jr_id2
-                    union
-                    select jra_id from jrn_rapt where jr_id=".$this->jr_id.
-                    " and jra_concerned=$jr_id2 ")
-                ==0)
-        {
-            // Ok we can insert
-            $Res=$this->db->exec_sql("insert into 
jrn_rapt(jr_id,jra_concerned) values ".
-                                    "(".$this->jr_id.",$jr_id2)");
-            // try to letter automatically same account from both operation
-            $this->auto_letter($jr_id2);
-            
-            // update date of paiement 
-----------------------------------------------------------------------
-            $source_type=$this->db->get_value("select substr(jr_internal,1,1) 
from jrn where jr_id=$1",array($this->jr_id));
-            $dest_type=$this->db->get_value("select substr(jr_internal,1,1) 
from jrn where jr_id=$1",array($jr_id2));
-            if (($source_type =='A' || $source_type=='V') && ($dest_type != 
'A' && $dest_type != 'V'))
-            {
-                // set the date on source
-                $date=$this->db->get_value('select jr_date from jrn where 
jr_id=$1',array($jr_id2));
-                if ( trim ($date) == '') $date=null;
-                $this->db->exec_sql('update jrn set jr_date_paid=$1 where 
jr_id=$2 and jr_date_paid is null ',array($date,$this->jr_id));
-            }
-            if (($source_type !='A' && $source_type !='V') && ($dest_type == 
'A' || $dest_type == 'V'))
-            {
-                // set the date on dest
-                $date=$this->db->get_value('select jr_date from jrn where 
jr_id=$1',array($this->jr_id));
-                if (trim($date) == '') $date=null;
-                $this->db->exec_sql('update jrn set jr_date_paid=$1 where 
jr_id=$2 and jr_date_paid is null ',array($date,$jr_id2));
-            }
-        }
-        return true;
-    }
-       /**
-        * @brief try to letter same card between $p_jrid and $this->jr_id
-        * @param jrn.jr_id $p_jrid  the operation to reconcile
-        */
-       function auto_letter($p_jrid)
-       {
-               // Try to find same card from both operation
-               $sql="select j1.f_id as fiche ,coalesce(j1.j_id,-1) as 
jrnx_id1,coalesce(j2.j_id,-1) as jrnx_id2,
-j1.j_poste as poste
-                               from jrnx as j1
-                                       join jrn as jr1 on 
(j1.j_grpt=jr1.jr_grpt_id)
-                                       join jrnx as j2 on 
(coalesce(j1.f_id,-1)=coalesce(j2.f_id,-1) and j1.j_poste=j2.j_poste)
-                                       join jrn as jr2 on 
(j2.j_grpt=jr2.jr_grpt_id)
-                               where
-                                       jr1.jr_id=$1
-                                       and
-                                       jr2.jr_id= $2";
-               $result=$this->db->get_array($sql,array($this->jr_id,$p_jrid));
-               if ( count($result) == 0)
-               {
-                       return;
-               }
-               for ($i=0;$i<count($result);$i++)
-               {
-                       if ( $result[$i]['fiche'] != -1)
-                       {
-                               $letter = new Lettering_Card($this->db);
-                               
$letter->insert_couple($result[$i]['jrnx_id1'],$result[$i]['jrnx_id2']);
-                       }
-                       else
-                       {
-                               $letter = new Lettering_Account($this->db);
-                               
$letter->insert_couple($result[$i]['jrnx_id1'],$result[$i]['jrnx_id2']);
-                       }
-               }
-
-       }
-
-       /*!
-     *\brief   Insert into jrn_rapt the concerned operations
-     *
-     * \param $this->jr_id (jrn.jr_id) => jrn_rapt.jr_id
-     * \param $jr_id2 (jrn.jr_id) => jrn_rapt.jra_concerned
-     *
-     * \return none
-     */
-    function remove($jr_id2)
-    {
-        if ( isNumber($this->jr_id)  == 0 or
-                isNumber($jr_id2) == 0 )
-        {
-            return;
-        }
-        // verify if exists
-        if ( $this->db->count_sql("select jra_id from jrn_rapt where ".
-                                  " jra_concerned=".$this->jr_id."  and 
jr_id=$jr_id2
-                                  union
-                                  select jra_id from jrn_rapt where 
jra_concerned=$jr_id2 ".
-                                  " and jr_id=".$this->jr_id) !=0)
-        {
-                       /**
-                        * remove also lettering between both operation
-                        */
-                       $sql = " delete from
-                                       jnt_letter
-                                       where jl_id in ( select jl_id from 
jnt_letter
-                                                                               
join letter_cred as lc using(jl_id)
-                                                                               
join letter_deb as ld using (jl_id)
-                                                                       where
-                                                                               
lc.j_id in (select j_id
-                                                                               
                        from jrnx join jrn on (j_grpt=jr_grpt_id)
-                                                                               
                        where jr_id in ($1,$2))
-                                                                               
or
-                                                                               
ld.j_id in (select j_id
-                                                                               
                        from jrnx join jrn on (j_grpt=jr_grpt_id)
-                                                                               
                        where jr_id in ($1,$2))
-
-
-
-                                                       )";
-                       $this->db->exec_sql($sql, array($jr_id2, $this->jr_id));
-                       // Ok we can delete
-                       $Res=$this->db->exec_sql("delete from jrn_rapt where ".
-                                     "(jra_concerned=$jr_id2 and 
jr_id=".$this->jr_id.") or
-                                     (jra_concerned=".$this->jr_id." and 
jr_id=$jr_id2) ");
-        }
-    }
-
-    /*!
-     *\brief   Return an array of the concerned operation
-     *
-     *
-     *\param database connection
-     * \return array if something is found or null
-     */
-    function get ( )
-    {
-        $sql=" select jr_id as cn from jrn_rapt where 
jra_concerned=".$this->jr_id.
-             " union ".
-             " select jra_concerned as cn from jrn_rapt where 
jr_id=".$this->jr_id;
-        $Res=$this->db->exec_sql($sql);
-
-        // If nothing is found return null
-        $n=Database::num_row($Res);
-
-        if ($n ==0 ) return null;
-
-        // put everything in an array
-        for ($i=0;$i<$n;$i++)
-        {
-            $l=Database::fetch_array($Res,$i);
-            $r[$i]=$l['cn'];
-        }
-        return $r;
-    }
-    function fill_info()
-    {
-        $sql="select 
jr_id,jr_date,jr_comment,jr_internal,jr_montant,jr_pj_number,jr_def_id,jrn_def_name,jrn_def_type
-             from jrn join jrn_def on (jrn_def_id=jr_def_id)
-             where jr_id=$1";
-        $a=$this->db->get_array($sql,array($this->jr_id));
-        return $a[0];
-    }
-    /**
-     address@hidden return array of not-reconciled operation
-    * Prepare and put in memory the SQL detail_quant
-    */
-    function get_not_reconciled()
-    {
-      $filter_date=$this->filter_date();
-      /* create ledger filter */
-      $sql_jrn=$this->ledger_filter();
-
-        $array=$this->db->get_array("select distinct jr_id,jr_date from jrn 
where $filter_date and $sql_jrn and jr_id not in (select jr_id from jrn_rapt 
union select jra_concerned from jrn_rapt) order by jr_date");
-        $ret=array();
-        for ($i=0;$i<count($array);$i++)
-        {
-            $this->jr_id=$array[$i]['jr_id'];
-            $ret[$i]['first']=$this->fill_info();
-        }
-        $this->db->prepare('detail_quant','select * from v_quant_detail where 
jr_id=$1');
-        return $ret;
-    }
-    /**
-     *Create a sql condition to filter by security and by asked ledger
-     * based on $this->a_jrn
-     address@hidden a valid sql stmt to include
-     address@hidden get_not_reconciled get_reconciled
-     */
-    function ledger_filter ()
-    {
-        global $g_user;
-        /* get the available ledgers for current user */
-        $sql=$g_user->get_ledger_sql('ALL',3);
-        $sql=str_replace('jrn_def_id','jr_def_id',$sql);
-        $r='';
-        /* filter by this->r_jrn */
-        if ($this->a_jrn != null )
-        {
-            $sep='';
-            $r='and jr_def_id in (';
-            foreach( $this->a_jrn as $key=>$value)
-            {
-                $r.=$sep.$value;
-                $sep=',';
-            }
-            $r.=')';
-        }
-        return $sql.'  '.$r;
-    }
-    /**
-     address@hidden return array of reconciled operation
-     * Prepare and put in memory the SQL detail_quant
-     address@hidden
-     address@hidden
-     address@hidden
-     @code
-
-     @endcode
-    */
-    function get_reconciled()
-    {
-      $filter_date=$this->filter_date();
-
-
-        /* create ledger filter */
-        $sql_jrn=$this->ledger_filter();
-
-        $array=$this->db->get_array("select distinct jr_id,jr_date from jrn 
where $filter_date and $sql_jrn and jr_id  in (select jr_id from jrn_rapt union 
select jra_concerned from jrn_rapt) order by jr_date");
-        $ret=array();
-        for ($i=0;$i<count($array);$i++)
-        {
-            $this->jr_id=$array[$i]['jr_id'];
-            $ret[$i]['first']=$this->fill_info();
-            $atmp=$this->get();
-            for ( $e=0;$e<count($atmp);$e++)
-            {
-                $this->jr_id=$atmp[$e];
-                $ret[$i]['depend'][$e]=$this->fill_info();
-            }
-        }
-        $this->db->prepare('detail_quant','select * from v_quant_detail where 
jr_id=$1');
-        return $ret;
-    }
-    /**
-     address@hidden
-     * Prepare and put in memory the SQL detail_quant
-     address@hidden
-     address@hidden
-     address@hidden
-     address@hidden
-    @code
-
-    @endcode
-     */
-    function get_reconciled_amount($p_equal=false)
-    {
-        $array=$this->get_reconciled();
-        $ret=array();
-        bcscale(2);
-        for ($i=0;$i<count($array);$i++)
-        {
-            $first_amount=$array[$i]['first']['jr_montant'];
-            $second_amount=0;
-            for ($e=0;$e<count($array[$i]['depend']);$e++)
-            {
-                
$second_amount=bcadd($second_amount,$array[$i]['depend'][$e]['jr_montant']);
-            }
-            if ( $p_equal &&  $first_amount==$second_amount)
-            {
-                $ret[]=$array[$i];
-            }
-            if ( ! $p_equal &&  $first_amount != $second_amount)
-            {
-                $ret[]=$array[$i];
-            }
-        }
-        return $ret;
-    }
-  /**
-   address@hidden create a string to filter thanks the date
-   address@hidden a sql string like jr_date > ... and jr_date < ....
-   address@hidden use the data member start_day and end_day
-   address@hidden get_reconciled get_not_reconciled
-   */
-    function filter_date()
-    {
-      global $g_user;
-      list($start,$end)=$g_user->get_limit_current_exercice();
-
-      if (isDate($this->start_day) ==null)
-       {
-         $this->start_day=$start;
-       }
-      if ( isDate($this->end_day) == null)
-       {
-         $this->end_day=$end;
-       }
-      $sql=" (jr_date >= to_date('".$this->start_day."','DD.MM.YYYY')
-               and jr_date <= to_date('".$this->end_day."','DD.MM.YYYY'))";
-      return $sql;
-
-    }
-    function show_detail($p_ret)
-    {
-        if (Database::num_row($p_ret)> 0)
-        {
-            echo '<tr class="odd">';
-            echo '<td></td>';
-            echo '<td colspan="5" style="border:1px solid black;width:auto">';
-            include 'template/impress_reconciliation_detail.php';
-            echo '</td>';
-            echo '</tr>';
-        }
-    }
-    /**
-     * Export to CSV
-     * @param type $p_choice 
-     * 
-     * @note must be set before calling
-     *    - $this->a_jrn       array of ledger
-     *    - $this->start_day start date
-     *    - $this->end_day end date
-     * @see Acc_Reconciliation::get_data
-     */
-    function export_csv($p_choice)
-    {
-        $array = $this->get_data($p_choice);
-        for ($i = 0; $i < count($array); $i++)
-        {
-            // ---------------------------------------
-            // first index has 2 arrays : first & depend[]
-            // ---------------------------------------
-
-            $first = $array[$i]['first'];
-            $a_depend = array();
-            if (isset($array[$i]['depend']))
-            {
-                $a_depend = $array[$i]['depend'];
-                //----- HEADER ----
-                if ($i == 0)
-                {
-                    printf('"n°";"Date";"internal";"libellé";"n° pièce";"nom 
journal";"type journal";"montant"');
-                    printf(';"<->";"Date";"internal";"libellé";"n° pièce";"nom 
journal";"type journal";"montant"' . "\n\r");
-                }
-            }
-            else
-            {
-                //----- HEADER ----
-                if ($i == 0)
-                {
-                    printf('"n°";"Date";"internal";"libellé";"n° pièce";"nom 
journal";"type journal";"montant"' . "\n\r");
-                }
-            }
-            // --------------------------
-            // Print First
-            // --------------------------
-            printf('%d;"%s";"%s";"%s";"%s";"%s";"%s";%f',$i, 
$first['jr_date'], $first['jr_internal'], $first['jr_comment'], 
$first['jr_pj_number'], $first['jrn_def_name'], $first['jrn_def_type'], 
$first['jr_montant']);
-            if (count($a_depend) > 0)
-            {
-                // --------------------------------------
-                // Print first depending operation
-                // --------------------------------------
-                $depend = $a_depend[0];
-                printf(';"<->";"%s";"%s";"%s";"%s";"%s";"%s";%f' . "\n\r", 
$depend['jr_date'], $depend['jr_internal'], $depend['jr_comment'], 
$depend['jr_pj_number'], $depend['jrn_def_name'], $depend['jrn_def_type'], 
$depend['jr_montant']);
-
-                // --------------------------------------
-                // print other depending operation if any
-                // --------------------------------------
-                for ($e = 1; $e < count($a_depend); $e++)
-                {
-                    $depend = $a_depend[$e];
-                    printf(';;;;;;;"<->";');
-                    printf('"%s";"%s";"%s";"%s";"%s";"%s";%f' . "\n\r", 
$depend['jr_date'], $depend['jr_internal'], $depend['jr_comment'], 
$depend['jr_pj_number'], $depend['jrn_def_name'], $depend['jrn_def_type'], 
$depend['jr_montant']);
-                }
-            }
-            else
-            {
-                printf("\n\r");
-            }
-        }
-    }
-
-    /**
-     * 
-     * @param type $p_choice
-     *       - 0 : operation reconcilied
-     *       - 1 : reconcilied with different amount
-     *       - 2 : reconcilied with same amount
-     *       - 3 : not reconcilied 
-     * @return $array
-     */
-    function get_data($p_choice)
-    {
-        switch ($p_choice)
-        {
-            case 0:
-                $array = $this->get_reconciled();
-                break;
-            case 1:
-                $array = $this->get_reconciled_amount(false);
-                break;
-            case 2:
-                $array = $this->get_reconciled_amount(true);
-                break;
-            case 3:
-                $array = $this->get_not_reconciled();
-                break;
-            default:
-                echo "Choix invalid";
-                throw new Exception("invalide");
-        }
-        return $array;
-    }
-
-    static function test_me()
-    {
-        $cn=new Database(dossier::id());
-        $rap=new Acc_Reconciliation($cn);
-        var_dump($rap->get_reconciled_amount('',false));
-    }
-
-}
diff --git a/include/class_acc_report.php b/include/class_acc_report.php
deleted file mode 100644
index b992d01..0000000
--- a/include/class_acc_report.php
+++ /dev/null
@@ -1,456 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-// Copyright Author Dany De Bontridder address@hidden
-/*! \file
- * \brief Create, view, modify and parse report
- */
-
-require_once NOALYSS_INCLUDE.'/class_itext.php';
-require_once NOALYSS_INCLUDE.'/class_ibutton.php';
-require_once NOALYSS_INCLUDE.'/class_acc_report_row.php';
-require_once NOALYSS_INCLUDE.'/class_impress.php';
-
-/*!
- * \brief Class rapport  Create, view, modify and parse report
- */
-
-class Acc_Report
-{
-
-    var $db;    /*!< $db database connx */
-    var $id;    /*!< $id formdef.fr_id */
-    var $name;  /*!< $name report's name */
-    var $aAcc_Report_row;              /*!< array of rapport_row */
-    var $nb;
-    /*!\brief  Constructor */
-    function __construct($p_cn,$p_id=0)
-    {
-        $this->db=$p_cn;
-        $this->id=$p_id;
-        $this->name='Nouveau';
-        $this->aAcc_Report_row=null;
-    }
-    /*!\brief Return the report's name
-     */
-    function get_name()
-    {
-        $ret=$this->db->exec_sql("select fr_label from formdef where 
fr_id=".$this->id);
-        if (Database::num_row($ret) == 0) return $this->name;
-        $a=Database::fetch_array($ret,0);
-        $this->name=$a['fr_label'];
-        return $this->name;
-    }
-    /*!\brief return all the row and parse formula
-     *        from a report
-     * \param $p_start start periode
-     * \param $p_end end periode
-     * \param $p_type_date type of the date : periode or calendar
-     */
-    function get_row($p_start,$p_end,$p_type_date)
-    {
-
-        $Res=$this->db->exec_sql("select fo_id ,
-                                 fo_fr_id,
-                                 fo_pos,
-                                 fo_label,
-                                 fo_formula,
-                                 fr_label from form
-                                 inner join formdef on fr_id=fo_fr_id
-                                 where fr_id =".$this->id.
-                                 "order by fo_pos");
-        $Max=Database::num_row($Res);
-        if ($Max==0)
-        {
-            $this->row=0;
-            return null;
-        }
-        $col=array();
-        for ($i=0;$i<$Max;$i++)
-        {
-            $l_line=Database::fetch_array($Res,$i);
-            $col[]=Impress::parse_formula($this->db,
-                                $l_line['fo_label'],
-                                $l_line['fo_formula'],
-                                $p_start,
-                                $p_end,
-                                true,
-                                $p_type_date
-                               );
-
-        } //for ($i
-        $this->row=$col;
-        return $col;
-    }
-    /*!
-     * \brief  Display a form for encoding a new report or update one
-     *
-     * \param $p_line number of line
-     *
-     */
-    function form($p_line=0)
-    {
-
-        $r="";
-        if ($p_line == 0 ) $p_line=count($this->aAcc_Report_row);
-        $r.= dossier::hidden();
-        $r.= HtmlInput::hidden('line',$p_line);
-        $r.= HtmlInput::hidden('fr_id',$this->id);
-        $wForm=new IText();
-        $r.="Nom du rapport : ";
-        $r.=$wForm->input('form_nom',$this->name);
-
-        $r.= '<TABLE id="rap1" width="100%">';
-        $r.= "<TR>";
-        $r.= "<TH> Position </TH>";
-        $r.= "<TH> Texte </TH>";
-        $r.= "<TH> Formule</TH>";
-
-        $r.= '</TR>';
-        $wName=new IText();
-        $wName->size=40;
-        $wPos=new IText();
-        $wPos->size=3;
-        $wForm=new IText();
-        $wForm->size=35;
-        for ( $i =0 ; $i < $p_line;$i++)
-        {
-
-            $r.= "<TR>";
-
-            $r.= "<TD>";
-            $wPos->value=( 
isset($this->aAcc_Report_row[$i]->fo_pos))?$this->aAcc_Report_row[$i]->fo_pos:$i+1;
-            $r.=$wPos->input("pos".$i);
-            $r.= '</TD>';
-
-
-            $r.= "<TD>";
-            $wName->value=( 
isset($this->aAcc_Report_row[$i]->fo_label))?$this->aAcc_Report_row[$i]->fo_label:"";
-            $r.=$wName->input("text".$i);
-            $r.= '</TD>';
-
-            $r.='<td>';
-            $search=new IPoste("form".$i);
-            $search->size=50;
-            $search->value=( 
isset($this->aAcc_Report_row[$i]->fo_formula))?$this->aAcc_Report_row[$i]->fo_formula:"";
-            $search->label=_("Recherche poste");
-            $search->set_attribute('gDossier',dossier::id());
-            $search->set_attribute('bracket',1);
-            $search->set_attribute('no_overwrite',1);
-            $search->set_attribute('noquery',1);
-            $search->set_attribute('account',$search->name);
-            $search->set_attribute('ipopup','ipop_card');
-
-            $r.=$search->input();
-            $r.='</td>';
-
-
-            $r.= "</TR>";
-        }
-
-        $r.= "</TABLE>";
-        $wButton=new IButton();
-        $wButton->javascript=" rapport_add_row('".dossier::id()."')";
-        $wButton->label="Ajout d'une ligne";
-        $r.=$wButton->input();
-        return $r;
-
-    }
-    /*!\brief save into form and form_def
-     */
-    function save()
-    {
-
-        if ( strlen(trim($this->name)) == 0 )
-            return;
-        if ( $this->id == 0 )
-            $this->insert();
-        else
-            $this->update();
-
-    }
-    function insert()
-    {
-        try
-        {
-            $this->db->start();
-            $ret_sql=$this->db->exec_sql(
-                         "insert into formdef (fr_label) values($1) returning 
fr_id",
-                         array($this->name)
-                     );
-            $this->id=Database::fetch_result($ret_sql,0,0);
-            $ix=1;
-            foreach ( $this->aAcc_Report_row as $row)
-            {
-                if ( strlen(trim($row->get_parameter("name"))) != 0 &&
-                        strlen(trim($row->get_parameter("formula"))) != 0 )
-                {
-                    
$ix=($row->get_parameter("position")!="")?$row->get_parameter("position"):$ix;
-                    $row->set_parameter("position",$ix);
-                    $ret_sql=$this->db->exec_sql(
-                                 "insert into form 
(fo_fr_id,fo_pos,fo_label,fo_formula)".
-                                 " values($1,$2,$3,$4)",
-                                 array($this->id,
-                                       $row->fo_pos,
-                                       $row->fo_label,
-                                       $row->fo_formula)
-                             );
-                }
-            }
-
-        }
-        catch (Exception $e)
-        {
-            $this->db->rollback();
-            echo $e->getMessage();
-        }
-        $this->db->commit();
-
-    }
-    function update()
-    {
-        try
-        {
-            $this->db->start();
-            $ret_sql=$this->db->exec_sql(
-                         "update formdef set fr_label=$1 where fr_id=$2",
-                         array($this->name,$this->id));
-            $ret_sql=$this->db->exec_sql(
-                         "delete from form where fo_fr_id=$1",
-                         array($this->id));
-            $ix=0;
-
-            foreach ( $this->aAcc_Report_row as $row)
-            {
-                if ( strlen(trim($row->get_parameter("name"))) != 0 &&
-                        strlen(trim($row->get_parameter("formula"))) != 0 )
-                {
-                    
$ix=($row->get_parameter("position")!="")?$row->get_parameter("position"):$ix;
-                    $row->set_parameter("position",$ix);
-                    $ret_sql=$this->db->exec_sql(
-                                 "insert into form 
(fo_fr_id,fo_pos,fo_label,fo_formula)".
-                                 " values($1,$2,$3,$4)",
-                                 array($this->id,
-                                       $row->fo_pos,
-                                       $row->fo_label,
-                                       $row->fo_formula)
-                             );
-                }
-            }
-
-
-        }
-        catch (Exception $e)
-        {
-            $this->db->rollback();
-            echo $e->getMessage();
-        }
-        $this->db->commit();
-    }
-    /*!\brief fill a form thanks an array, usually it is $_POST
-     *\param $p_array keys = fr_id, form_nom,textXX, formXX, posXX where
-        XX is an number
-     */
-    function from_array($p_array)
-    {
-        $this->id=(isset($p_array['fr_id']))?$p_array['fr_id']:0;
-        $this->name=(isset($p_array['form_nom']))?$p_array['form_nom']:"";
-        $ix=0;
-
-        $rr=new Acc_Report_Row();
-        $rr->set_parameter("form_id",$this->id);
-        $rr->set_parameter('database',$this->db);
-
-        $this->aAcc_Report_row=$rr->from_array($p_array);
-
-
-    }
-    /*!\brief the fr_id MUST be set before calling
-     */
-
-
-    function load()
-    {
-        $sql=$this->db->exec_sql(
-                 "select fr_label from formdef where fr_id=$1",
-                 array($this->id));
-        if ( Database::num_row($sql) == 0 ) return;
-        $this->name=Database::fetch_result($sql,0,0);
-        $sql=$this->db->exec_sql(
-                 "select fo_id,fo_pos,fo_label,fo_formula ".
-                 " from form ".
-                 " where fo_fr_id=$1 order by fo_pos",
-                 array($this->id));
-        $f=Database::fetch_all($sql);
-        $array=array();
-        if ( ! empty($f) )
-        {
-            foreach ($f as $r)
-            {
-                $obj=new Acc_Report_Row();
-                $obj->set_parameter("name",$r['fo_label']);
-                $obj->set_parameter("id",$r['fo_id']);
-                $obj->set_parameter("position",$r['fo_pos']);
-                $obj->set_parameter("formula",$r['fo_formula']);
-                $obj->set_parameter('database',$this->db);
-                $obj->set_parameter('form_id',$this->id);
-                $array[]=clone $obj;
-            }
-        }
-        $this->aAcc_Report_row=$array;
-
-    }
-    function delete()
-    {
-        $ret=$this->db->exec_sql(
-                 "delete from formdef where fr_id=$1",
-                 array($this->id)
-             );
-    }
-    /*!\brief get a list from formdef of all defined form
-     *
-     *\return array of object rapport
-     *
-     */
-    function get_list()
-    {
-        $sql="select fr_id,fr_label from formdef order by fr_label";
-        $ret=$this->db->exec_sql($sql);
-        if ( Database::num_row($ret) == 0 ) return array();
-        $array=Database::fetch_all($ret);
-        $obj=array();
-        foreach ($array as $row)
-        {
-            $tmp=new Acc_Report($this->db);
-            $tmp->id=$row['fr_id'];
-            $tmp->name=$row['fr_label'];
-            $obj[]=clone $tmp;
-        }
-        return $obj;
-    }
-    /*!\brief To make a SELECT button with the needed value, it is used
-     *by the SELECT widget
-     *\return string with html code
-     */
-    function make_array()
-    {
-        $sql=$this->db->make_array("select fr_id,fr_label from formdef order 
by fr_label");
-        return $sql;
-    }
-
-
-    /*!\brief write to a file the definition of a report
-     * \param p_file is the file name (default php://output)
-     */
-    function export_csv($p_file)
-    {
-        $this->load();
-
-        fputcsv($p_file,array($this->name));
-
-        foreach ($this->aAcc_Report_row as $row)
-        {
-            fputcsv($p_file,array($row->get_parameter("name"),
-                                  $row->get_parameter('position'),
-                                  $row->get_parameter('formula'))
-                   );
-        }
-
-    }
-    /*!\brief upload a definition of a report and insert it into the
-     * database
-     */
-    function upload()
-    {
-        if ( empty ($_FILES) ) return;
-        if ( strlen(trim($_FILES['report']['tmp_name'])) == 0 )
-        {
-            alert("Nom de fichier est vide");
-            return;
-        }
-        $file_report=tempnam('tmp','file_report');
-        if (  move_uploaded_file($_FILES['report']['tmp_name'],$file_report))
-        {
-            // File is uploaded now we can try to parse it
-            $file=fopen($file_report,'r');
-            $data=fgetcsv($file);
-            if ( empty($data) ) return;
-            $this->name=$data[0];
-            $array=array();
-            while($data=fgetcsv($file))
-            {
-                $obj=new Acc_Report_Row();
-                $obj->set_parameter("name",$data[0]);
-                $obj->set_parameter("id",0);
-                $obj->set_parameter("position",$data[1]);
-                $obj->set_parameter("formula",$data[2]);
-                $obj->set_parameter('database',$this->db);
-                $obj->set_parameter('form_id',0);
-                $array[]=clone $obj;
-            }
-            $this->aAcc_Report_row=$array;
-            $this->insert();
-        }
-    }
-    /**
-     address@hidden check if a report exist
-     address@hidden $p_id, optional, if given check the report with this fr_id
-     address@hidden return true if the report exist otherwise false
-     */
-    function exist($p_id=0)
-    {
-        $c=$this->id;
-        if ( $p_id != 0 ) $c=$p_id;
-        $ret=$this->db->exec_sql("select fr_label from formdef where 
fr_id=$1",array($c));
-        if (Database::num_row($ret) == 0) return false;
-        return true;
-    }
-    static function test_me()
-    {
-        $cn=new Database(dossier::id());
-        $a=new Acc_Report($cn);
-        print_r($a->get_list());
-        $array=array("text0"=>"test1",
-                     "form0"=>"7%",
-                     "text1"=>"test2",
-                     "form1"=>"6%",
-                     "fr_id"=>110,
-                     "form_nom"=>"Tableau"
-                    );
-        $a->from_array($array);
-        print_r($a);
-        echo '<form method="post">';
-        echo $a->form(10);
-
-        echo HtmlInput::submit('update','Enregistre');
-        /* Add a line should be a javascript see comptanalytic */
-        //  $r.= '<INPUT TYPE="submit" value="Ajoute une ligne" 
name="add_line">';
-        echo HtmlInput::submit('del_form','Efface ce rapport');
-        echo HtmlInput::hidden('test_select',$_REQUEST['test_select']);
-        echo "</FORM>";
-        if ( isset ($_POST['update']))
-        {
-            $b=new Acc_Report($cn);
-            $b->from_array($_POST);
-            echo '<hr>';
-            print_r($b);
-        }
-    }
-}
-
-?>
diff --git a/include/class_acc_tva.php b/include/class_acc_tva.php
deleted file mode 100644
index 7ce28ea..0000000
--- a/include/class_acc_tva.php
+++ /dev/null
@@ -1,202 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief this class is used for the table tva_rate
- */
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
-
-/*!\brief Acc_Tva is used for to map the table tva_rate
- * parameter are
-- private static $cn;  database connection
-- private static $variable=array("id"=>"tva_id",
-                "label"=>"tva_label",
-                "rate"=>"tva_rate",
-                "comment"=>"tva_comment",
-                "account"=>"tva_poste");
-
-*/
-class Acc_Tva
-{
-    private  $cn;              /*!< $cn database connection */
-    private static $variable=array("id"=>"tva_id",
-                                   "label"=>"tva_label",
-                                   "rate"=>"tva_rate",
-                                   "comment"=>"tva_comment",
-                                   "account"=>"tva_poste",
-                                    "both_side"=>'tva_both_side');
-
-    function __construct ($p_init,$p_tva_id=0)
-    {
-        $this->cn=$p_init;
-        $this->tva_id=$p_tva_id;
-        $this->poste="";
-    }
-    public function get_parameter($p_string)
-    {
-        if ( array_key_exists($p_string,self::$variable) )
-        {
-            $idx=self::$variable[$p_string];
-            return $this->$idx;
-        }
-
-        echo  (__FILE__.":".__LINE__.'Erreur attribut inexistant');
-    }
-    public function set_parameter($p_string,$p_value)
-    {
-        if ( array_key_exists($p_string,self::$variable) )
-        {
-            $idx=self::$variable[$p_string];
-            $this->$idx=$p_value;
-        }
-        else
-            throw new Exception("Attribut inexistant $p_string");
-
-
-    }
-    public function get_info()
-    {
-        return var_export(self::$variable,true);
-    }
-
-    public function verify()
-    {
-        // Verify that the elt we want to add is correct
-    }
-    public function save()
-    {
-
-        if (  $this->tva_id == 0 )
-            $this->insert();
-        else
-            $this->update();
-    }
-
-    public function insert()
-    {
-        if ( $this->verify() != 0 ) return;
-        $sql="select tva_insert($1,$2,$3,$4,$5)";
-
-        $res=$this->cn->exec_sql(
-                 $sql,
-                 array($this->tva_label,
-                       $this->tva_rate,
-                       $this->tva_comment,
-                       $this->tva_poste,
-                        $this->tva_both_side)
-             );
-        $this->tva_id=$this->cn->get_current_seq('s_tva');
-        $err=Database::fetch_result($res);
-    }
-
-    public function update()
-    {
-        if ( $this->verify() != 0 ) return;
-        $sql="update tva_rate set 
tva_label=$1,tva_rate=$2,tva_comment=$3,tva_poste=$4,tva_both_side=$5 ".
-             " where tva_id = $6";
-        $res=$this->cn->exec_sql(
-                 $sql,
-                 array($this->tva_label,
-                       $this->tva_rate,
-                       $this->tva_comment,
-                       $this->tva_poste,
-                       $this->tva_both_side,
-                       $this->tva_id)
-             );
-
-    }
-    /**
-     *Load the VAT,
-     address@hidden if the label is not found then we get an message error, so 
the best is probably
-     *to initialize the VAT object with default value
-     */
-    public function load()
-    {
-        $sql="select tva_id,tva_label,tva_rate, 
tva_comment,tva_poste,tva_both_side from tva_rate where tva_id=$1";
-        $res=$this->cn->exec_sql(
-                 $sql,
-                 array($this->tva_id)
-             );
-
-        if ( $this->cn->size() == 0 ) return -1;
-
-        $row=Database::fetch_array($res,0);
-        foreach ($row as $idx=>$value)
-        {
-            $this->$idx=$value;
-        }
-        return 0;
-    }
-    /*!\brief get the account of the side (debit or credit)
-     *\param $p_side is d or C
-     *\return the account to use
-     *\note call first load if tva_poste is empty
-     */
-    public function get_side($p_side)
-    {
-        if ( strlen($this->tva_poste) == 0 ) $this->load();
-        list($deb,$cred)=explode(",",$this->tva_poste);
-        switch ($p_side)
-        {
-        case 'd':
-                return $deb;
-            break;
-        case 'c':
-            return $cred;
-            break;
-        default:
-            throw (new Exception (__FILE__.':'.__LINE__." param est d ou c, on 
a recu [ $p_side ]"));
-        }
-    }
-    public function delete()
-    {
-        $sql="delete from tva_rate where tva_id=$1";
-        $res=$this->cn->exec_sql($sql,array($this->tva_id));
-    }
-    /*!\brief
-     * Test function
-     */
-    static function test_me()
-    {
-        $cn=new Database(dossier::id());
-        $a=new Acc_Tva($cn);
-        echo $a->get_info();
-        $a->set_parameter("id",1);
-        $a->load();
-        $a->set_parameter("id",0);
-        $a->set_parameter("rate","0.2222");
-        $a->set_parameter("label","test");
-        $a->save();
-        $a->load();
-        print_r($a);
-
-        $a->set_parameter("comment","un cht'it test");
-        $a->save();
-        $a->load();
-        print_r($a);
-
-        $a->delete();
-    }
-
-}
-
-/* test::test_me(); */
diff --git a/include/class_admin.php b/include/class_admin.php
deleted file mode 100644
index 0b0835f..0000000
--- a/include/class_admin.php
+++ /dev/null
@@ -1,58 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-// Copyright Author Dany De Bontridder address@hidden
-require_once NOALYSS_INCLUDE.'/constant.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_acc_parm_code.php';
-
-require_once NOALYSS_INCLUDE.'/class_fiche.php';
-require_once NOALYSS_INCLUDE.'/class_acc_account_ledger.php';
-require_once NOALYSS_INCLUDE.'/user_common.php';
-/*! \file
- * \brief Derived from class fiche Administration are a specific kind of card
- *        concerned only by official (or not) administration
- */
-/*!
- * \brief  class  admin are a specific kind of card
- */
-
-// Use the view vw_supplier
-//
-class Admin extends Fiche
-{
-
-    var $name;        /*!< $name name of the company */
-    var $street;      /*!< $street Street */
-    var $country;     /*!< $country Country */
-    var $cp;          /*!< $cp Zip code */
-    var $vat_number;  /*!< $vat_number vat number */
-
-    /*! \brief Constructor
-    /* only a db connection is needed */
-    function Admin($p_cn,$p_id=0)
-    {
-        $this->fiche_def_ref=FICHE_TYPE_ADM_TAX;
-        parent::__construct($p_cn,$p_id) ;
-    }
-
-
-
-}
-
-?>
diff --git a/include/class_anc_acc_link.php b/include/class_anc_acc_link.php
deleted file mode 100644
index fa802ff..0000000
--- a/include/class_anc_acc_link.php
+++ /dev/null
@@ -1,61 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief link between accountancy and analytic, like table but as a listing
- */
-require_once NOALYSS_INCLUDE.'/class_anc_print.php';
-
-class Anc_Acc_Link extends Anc_Print
-{
-  function __contruct($p_cn)
-  {
-    $this->cn=$p_cn;
-  }
-
-  /**
-   address@hidden get the parameters
-   */
-  function get_request()
-  {
-    parent::get_request();
-    $this->card_poste=HtmlInput::default_value('card_poste',1,$_GET);
-  }
-    function set_sql_filter()
-    {
-        $sql="";
-        $and=" and ";
-        if ( $this->from != "" )
-        {
-            $sql.="$and oa_date >= to_date('".$this->from."','DD.MM.YYYY')";
-        }
-        if ( $this->to != "" )
-        {
-            $sql.=" $and oa_date <= to_date('".$this->to."','DD.MM.YYYY')";
-        }
-
-        return $sql;
-
-    }
-
-
-}
-
diff --git a/include/class_anc_acc_list.php b/include/class_anc_acc_list.php
deleted file mode 100644
index 3b7c6a0..0000000
--- a/include/class_anc_acc_list.php
+++ /dev/null
@@ -1,545 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief
- */
-
-require_once NOALYSS_INCLUDE.'/class_anc_acc_link.php';
-
-class Anc_Acc_List extends Anc_Acc_Link
-{
-  /**
-   address@hidden display form to get the parameter
-   *  - card_poste 1 by card, 2 by account
-   *  - from_poste
-   *  - to_poste
-   *  - from from date
-   *  - to until date
-   *  - pa_id Analytic plan to use
-   */
-  function display_form($p_hidden='')
-  {
-    $r=parent::display_form($p_hidden);
-    $icard=new ISelect('card_poste');
-    $icard->value=array(
-                       array('value'=>1,'label'=>'Par fiche /Activité'),
-                       array('value'=>2,'label'=>'Par poste 
comptable/Activité'),
-                       array('value'=>3,'label'=>'Par activité/Fiche'),
-                       array('value'=>4,'label'=>'Par activité/Poste 
Comptable')
-
-                       );
-
-    $icard->selected=$this->card_poste;
-    $r.=$icard->input();
-    $r.=HtmlInput::request_to_hidden(array('ac'));
-    return $r;
-  }
- /**
-   * load the data
-   * does not return anything but give a value to this->aheader and this->arow
-   */
-  function load_anc_account()
-  {
-    $date=$this->set_sql_filter();
-    $date=($date != '')?"  $date":'';
-    $sql_from_poste=($this->from_poste!='')?" and  po.po_name >= 
upper('".Database::escape_string($this->from_poste)."')":'';
-    $sql_to_poste=($this->to_poste!='')?" and  po.po_name <= 
upper('".Database::escape_string($this->to_poste)."')":'';
-    $this->arow=$this->db->get_array("
- SELECT po.po_id, po.pa_id, po.po_name, po.po_description, sum(
-        CASE
-            WHEN operation_analytique.oa_debit = true THEN 
operation_analytique.oa_amount * (-1)::numeric
-            ELSE operation_analytique.oa_amount
-        END) AS sum_amount, jrnx.j_poste, tmp_pcmn.pcm_lib AS name
-   FROM operation_analytique
-   JOIN poste_analytique po USING (po_id)
-   JOIN jrnx USING (j_id)
-   JOIN tmp_pcmn ON jrnx.j_poste::text = tmp_pcmn.pcm_val::text ".
-"                                      where
-               pa_id=$1 ".$date.$sql_from_poste.$sql_to_poste."
-
-  GROUP BY po.po_id, po.po_name, po.pa_id, jrnx.j_poste, tmp_pcmn.pcm_lib, 
po.po_description
- HAVING sum(
-CASE
-    WHEN operation_analytique.oa_debit = true THEN 
operation_analytique.oa_amount * (-1)::numeric
-    ELSE operation_analytique.oa_amount
-END) <> 0::numeric  order by po_id,j_poste",array($this->pa_id));
-
-  }
-  /**
-   * load the data
-   * does not return anything but give a value to this->aheader and this->arow
-   */
-  function load_anc_card()
-  {
-    $date=$this->set_sql_filter();
-    $date=($date != '')?"  $date":'';
-    $sql_from_poste=($this->from_poste!='')?" and  po.po_name >= 
upper('".Database::escape_string($this->from_poste)."')":'';
-    $sql_to_poste=($this->to_poste!='')?" and  po.po_name <= 
upper('".Database::escape_string($this->to_poste)."')":'';
-    $this->arow=$this->db->get_array(" SELECT po.po_id, po.pa_id, po.po_name, 
po.po_description, sum(
-        CASE
-            WHEN operation_analytique.oa_debit = true THEN 
operation_analytique.oa_amount * (-1)::numeric
-            ELSE operation_analytique.oa_amount
-        END) AS sum_amount, jrnx.f_id, jrnx.j_qcode, ( SELECT 
fiche_detail.ad_value
-           FROM fiche_detail
-          WHERE fiche_detail.ad_id = 1 AND fiche_detail.f_id = jrnx.f_id) AS 
name
-   FROM operation_analytique
-   JOIN poste_analytique po USING (po_id)
-   JOIN jrnx USING (j_id) ".
-                                    " where pa_id=$1 
".$date.$sql_from_poste.$sql_to_poste
-                                    ."
-  GROUP BY po.po_id, po.po_name, po.pa_id, jrnx.f_id, jrnx.j_qcode, ( SELECT 
fiche_detail.ad_value
-   FROM fiche_detail
-  WHERE fiche_detail.ad_id = 1 AND fiche_detail.f_id = jrnx.f_id), 
po.po_description
- HAVING sum(
-CASE
-    WHEN operation_analytique.oa_debit = true THEN 
operation_analytique.oa_amount * (-1)::numeric
-    ELSE operation_analytique.oa_amount
-END) <> 0::numeric order by po_name,name",array($this->pa_id));
-
-  }
-
-  /**
-   * load the data
-   * does not return anything but give a value to this->aheader and this->arow
-   */
-  function load_poste()
-  {
-    $date=$this->set_sql_filter();
-    $date=($date != '')?"  $date":'';
-    $sql_from_poste=($this->from_poste!='')?" and  po.po_name >= 
upper('".Database::escape_string($this->from_poste)."')":'';
-    $sql_to_poste=($this->to_poste!='')?" and  po.po_name <= 
upper('".Database::escape_string($this->to_poste)."')":'';
-  $this->arow=$this->db->get_array("SELECT po.po_id, po.pa_id, po.po_name, 
po.po_description, sum(
-        CASE
-            WHEN operation_analytique.oa_debit = true THEN 
operation_analytique.oa_amount * (-1)::numeric
-            ELSE operation_analytique.oa_amount
-        END) AS sum_amount, jrnx.j_poste, tmp_pcmn.pcm_lib AS name
-   FROM operation_analytique
-   JOIN poste_analytique po USING (po_id)
-   JOIN jrnx USING (j_id)
-   JOIN tmp_pcmn ON jrnx.j_poste::text = tmp_pcmn.pcm_val::text ".
-"                                      where
-               pa_id=$1 ".$date.$sql_from_poste.$sql_to_poste."
-
-  GROUP BY po.po_id, po.po_name, po.pa_id, jrnx.j_poste, tmp_pcmn.pcm_lib, 
po.po_description
- HAVING sum(
-CASE
-    WHEN operation_analytique.oa_debit = true THEN 
operation_analytique.oa_amount * (-1)::numeric
-    ELSE operation_analytique.oa_amount
-END) <> 0::numeric  order by j_poste,po_name",array($this->pa_id));
-
-  }
-
-  /**
-   * load the data
-   * does not return anything but give a value to this->aheader and this->arow
-   */
-  function load_card()
-  {
-    $date=$this->set_sql_filter();
-    $date=($date != '')?"  $date":'';
-    $sql_from_poste=($this->from_poste!='')?" and  po.po_name >= 
upper('".Database::escape_string($this->from_poste)."')":'';
-    $sql_to_poste=($this->to_poste!='')?" and  po.po_name <= 
upper('".Database::escape_string($this->to_poste)."')":'';
-
-   $this->arow=$this->db->get_array(" SELECT po.po_id, po.pa_id, po.po_name, 
po.po_description, sum(
-        CASE
-            WHEN operation_analytique.oa_debit = true THEN 
operation_analytique.oa_amount * (-1)::numeric
-            ELSE operation_analytique.oa_amount
-        END) AS sum_amount, jrnx.f_id, jrnx.j_qcode, ( SELECT 
fiche_detail.ad_value
-           FROM fiche_detail
-          WHERE fiche_detail.ad_id = 1 AND fiche_detail.f_id = jrnx.f_id) AS 
name
-   FROM operation_analytique
-   JOIN poste_analytique po USING (po_id)
-   JOIN jrnx USING (j_id) ".
-                                    " where pa_id=$1 
".$date.$sql_from_poste.$sql_to_poste
-                                    ."
-  GROUP BY po.po_id, po.po_name, po.pa_id, jrnx.f_id, jrnx.j_qcode, ( SELECT 
fiche_detail.ad_value
-   FROM fiche_detail
-  WHERE fiche_detail.ad_id = 1 AND fiche_detail.f_id = jrnx.f_id), 
po.po_description
- HAVING sum(
-CASE
-    WHEN operation_analytique.oa_debit = true THEN 
operation_analytique.oa_amount * (-1)::numeric
-    ELSE operation_analytique.oa_amount
-END) <> 0::numeric order by name,po_name",array($this->pa_id));
-  }
-  /**
-   address@hidden display the button export CSV
-   address@hidden $p_hidden is a string containing hidden items
-   address@hidden html string
-   */
-  function show_button($p_hidden="")
-  {
-    $r="";
-    $r.= '<form method="GET" action="export.php"  style="display:inline">';
-    $r.= HtmlInput::hidden("act","CSV:AncAccList");
-    $r.= HtmlInput::hidden("to",$this->to);
-    $r.= HtmlInput::hidden("from",$this->from);
-    $r.= HtmlInput::hidden("pa_id",$this->pa_id);
-    $r.= HtmlInput::hidden("from_poste",$this->from_poste);
-    $r.= HtmlInput::hidden("to_poste",$this->to_poste);
-    $r.= HtmlInput::hidden("card_poste",$this->card_poste);
-
-    $r.= $p_hidden;
-    $r.= dossier::hidden();
-    $r.=HtmlInput::submit('bt_csv',"Export en CSV");
-    $r.= '</form>';
-    return $r;
-  }
-  function display_html()
-  {
-    bcscale(2);
-    if ( $this->check()  != 0)
-      {
-       alert('Désolé mais une des dates données n\'est pas valide');
-       return;
-      }
-    
//---------------------------------------------------------------------------
-    // Card  - Acc
-    
//---------------------------------------------------------------------------
-
-    if ( $this->card_poste=='1')
-      {
-       $this->load_card();
-
-       /*
-        * Show all the result
-        */
-       $tot_card=0;$prev='';
-       echo '<table class="result" style="margin-left:5px;margin-top:5px">';
-       $tot_glob=0;
-       for ($i=0;$i<count($this->arow);$i++)
-         {
-           if ( $i == 0 )
-             {
-               $prev=$this->arow[$i]['f_id'];
-               echo '<tr><td>'.HtmlInput::history_card 
($this->arow[$i]['f_id'],$this->arow[$i]['j_qcode'].' 
'.$this->arow[$i]['name'],' display:inline').'</td></tr>';
-             }
-           $style= ( $i % 2 == 0)?' class="odd" ':' class="even" ';
-           if ( $i != 0 && $prev != $this->arow[$i]['f_id'])
-             {
-               echo  td('Total');
-               echo td(nbm($tot_card),' class="num"');
-               echo '</tr>';
-               echo '<tr  
style="padding-top:5px"><td>'.HtmlInput::history_card($this->arow[$i]['f_id'],$this->arow[$i]['j_qcode'].'
 '.$this->arow[$i]['name'],' display:inline ').'</td></tr>';
-               $tot_card=0;
-               $prev = $this->arow[$i]['f_id'];
-             }
-
-           echo '<tr '.$style.'>';
-           $amount=$this->arow[$i]['sum_amount'];
-           if ($amount==null)$amount=0;
-
-           $tot_card=bcadd($tot_card,$amount);
-           $tot_glob=bcadd($tot_glob,$amount);
-           echo td($this->arow[$i]['po_name']."   ".
-                   
$this->arow[$i]['po_description'],'style="padding-left:10"');
-           echo td(nbm($amount),' class="num" ');
-           echo '</tr>';
-
-         }
-       echo '<tr>';
-       echo  td('Total');
-       echo td(nbm($tot_card),' class="num"');
-       echo '</tr>';
-
-       echo '</table>';
-       echo '<h2> Résultat global '.nbm($tot_glob).'</h2>';
-      }
-    
//---------------------------------------------------------------------------
-    // Accountancy - Analytic
-    
//---------------------------------------------------------------------------
-
-    if ( $this->card_poste=='2')
-      {
-       $this->load_poste();
-       /*
-        * Show all the result
-        */
-       $tot_card=0;$prev='';
-       echo '<table class="result" style="margin-left:20px;margin-top:5px">';
-       $tot_glob=0;
-       for ($i=0;$i<count($this->arow);$i++)
-         {
-           if ( $i == 0 )
-             {
-               $prev=$this->arow[$i]['j_poste'];
-               echo '<tr><td>'.HtmlInput::history_account 
($this->arow[$i]['j_poste'],$this->arow[$i]['j_poste'].' 
'.$this->arow[$i]['name'],' display:inline').'</td></tr>';
-             }
-           $style= ( $i % 2 == 0)?' class="odd" ':' class="even" ';
-           if ( $i != 0 && $prev != $this->arow[$i]['j_poste'])
-             {
-               echo  td('Total');
-               echo td(nbm($tot_card),' class="num"');
-               echo '</tr>';
-               echo '<tr  
style="padding-top:5px"><td>'.HtmlInput::history_account($this->arow[$i]['j_poste'],$this->arow[$i]['j_poste'].'
 '.$this->arow[$i]['name'],' display:inline ').'</td></tr>';
-               $tot_card=0;
-               $prev = $this->arow[$i]['j_poste'];
-             }
-
-           echo '<tr '.$style.'>';
-           $amount=$this->arow[$i]['sum_amount'];
-           if ($amount==null)$amount=0;
-
-           $tot_card=bcadd($tot_card,$amount);
-           $tot_glob=bcadd($tot_glob,$amount);
-
-
-           echo td($this->arow[$i]['po_name']."   ".
-                   
$this->arow[$i]['po_description'],'style="padding-left:10"');
-           echo td(nbm($amount),' class="num" ');
-           echo '</tr>';
-
-         }
-       echo '<tr>';
-       echo  td('Total');
-       echo td(nbm($tot_card),' class="num"');
-       echo '</tr>';
-
-       echo '</table>';
-       echo td(nbm($tot_card),' class="num"');
-      }
-    
//---------------------------------------------------------------------------
-    // Acc after card
-    
//---------------------------------------------------------------------------
-    if ( $this->card_poste=='3')
-      {
-       $this->load_anc_card();
-       /*
-        * Show all the result
-        */
-       $tot_card=0;$prev='';
-       echo '<table class="result" style="margin-left:20px;margin-top:5px">';
-       $tot_glob=0;
-       for ($i=0;$i<count($this->arow);$i++)
-         {
-           if ( $i == 0 )
-             {
-               $prev=$this->arow[$i]['po_id'];
-               echo '<tr><td>'.$this->arow[$i]['po_name']."  
".$this->arow[$i]['po_description'].'</td></tr>';
-
-             }
-           $style= ( $i % 2 == 0)?' class="odd" ':' class="even" ';
-           if ( $i != 0 && $prev != $this->arow[$i]['po_id'])
-             {
-               echo  td('Total');
-               echo td(nbm($tot_card),' class="num"');
-               echo '</tr>';
-               echo '<tr><td>'.$this->arow[$i]['po_name']."  
".$this->arow[$i]['po_description'].'</td></tr>';
-
-               $tot_card=0;
-               $prev = $this->arow[$i]['po_id'];
-             }
-
-           echo '<tr '.$style.'>';
-           $amount=$this->arow[$i]['sum_amount'];
-           if ($amount==null)$amount=0;
-
-           $tot_card=bcadd($tot_card,$amount);
-           $tot_glob=bcadd($tot_glob,$amount);
-           echo '<td style="padding-left:10">'.HtmlInput::history_card 
($this->arow[$i]['f_id'],$this->arow[$i]['j_qcode'].' 
'.$this->arow[$i]['name'],' display:inline').'</td>';
-
-           echo td(nbm($amount),' class="num" ');
-           echo '</tr>';
-
-         }
-       echo '<tr>';
-       echo  td('Total');
-       echo td(nbm($tot_card),' class="num"');
-       echo '</tr>';
-
-       echo '</table>';
-       echo td(nbm($tot_card),' class="num"');
-      }
-    
//---------------------------------------------------------------------------
-    // Analytic - Accountancy
-    
//---------------------------------------------------------------------------
-
-
-    if ( $this->card_poste=='4')
-      {
-       $this->load_anc_account();
-
-       /*
-        * Show all the result
-        */
-       $tot_card=0;$prev='';
-       echo '<table class="result" style="margin-left:20px;margin-top:5px">';
-       $tot_glob=0;
-       for ($i=0;$i<count($this->arow);$i++)
-         {
-           if ( $i == 0 )
-             {
-               $prev=$this->arow[$i]['po_id'];
-               echo '<tr><td>'.$this->arow[$i]['po_name']."  
".$this->arow[$i]['po_description'].'</td></tr>';
-             }
-           $style= ( $i % 2 == 0)?' class="odd" ':' class="even" ';
-           if ( $i != 0 && $prev != $this->arow[$i]['po_id'])
-             {
-               echo  td('Total');
-               echo td(nbm($tot_card),' class="num"');
-               echo '</tr>';
-
-               $tot_card=0;
-               $prev = $this->arow[$i]['po_id'];
-               echo '<tr><td>'.$this->arow[$i]['po_name']."  
".$this->arow[$i]['po_description'].'</td></tr>';
-
-             }
-
-           echo '<tr '.$style.'>';
-           $amount=$this->arow[$i]['sum_amount'];
-           if ($amount==null)$amount=0;
-
-           $tot_card=bcadd($tot_card,$amount);
-           $tot_glob=bcadd($tot_glob,$amount);
-           echo '<td style="padding-left:10">'.HtmlInput::history_account 
($this->arow[$i]['j_poste'],$this->arow[$i]['j_poste'].' 
'.$this->arow[$i]['name'],' display:inline').'</td>';
-           echo td(nbm($amount),' class="num" ');
-           echo '</tr>';
-
-         }
-       echo '<tr>';
-       echo  td('Total');
-       echo td(nbm($tot_card),' class="num"');
-       echo '</tr>';
-
-       echo '</table>';
-       echo '<h2> Résultat global '.nbm($tot_glob).'</h2>';
-      }
-
-  }
-  function export_csv()
-  {
-   bcscale(2);
-   if ( $this->check () != 0 ) {throw new Exception (_("date invalide"));}
-      
//---------------------------------------------------------------------------
-    // Card  - Acc
-    
//---------------------------------------------------------------------------
-
-    if ( $this->card_poste=='1')
-      {
-       $this->load_card();
-
-       /*
-        * Show all the result
-        */
-       $prev='';
-
-
-       for ($i=0;$i<count($this->arow);$i++)
-         {
-           printf('"%s";" %s"', 
$this->arow[$i]['j_qcode'],$this->arow[$i]['name']);
-
-           $amount=$this->arow[$i]['sum_amount'];
-           if ($amount==null)$amount=0;
-
-           printf(';"%s";" %s";',
-                  $this->arow[$i]['po_name'],
-                  $this->arow[$i]['po_description']);
-           printf("%s",nb($amount));
-           printf("\r\n");
-         }
-      }
-    
//---------------------------------------------------------------------------
-    // Accountancy - Analytic
-    
//---------------------------------------------------------------------------
-
-    if ( $this->card_poste=='2')
-      {
-       $this->load_poste();
-       /*
-        * Show all the result
-        */
-       for ($i=0;$i<count($this->arow);$i++)
-         {
-           printf('"%s";" %s"', 
$this->arow[$i]['j_poste'],$this->arow[$i]['name']);
-
-           $amount=$this->arow[$i]['sum_amount'];
-           if ($amount==null)$amount=0;
-
-           printf(';"%s";" %s";',
-                  $this->arow[$i]['po_name'],
-                  $this->arow[$i]['po_description']);
-           printf("%s",nb($amount));
-           printf("\r\n");
-
-
-         }
-
-      }
-    
//---------------------------------------------------------------------------
-    // Acc after card
-    
//---------------------------------------------------------------------------
-    if ( $this->card_poste=='3')
-      {
-       $this->load_anc_card();
-       /*
-        * Show all the result
-        */
-       for ($i=0;$i<count($this->arow);$i++)
-         {
-           printf('"%s";" %s";', 
$this->arow[$i]['po_name'],$this->arow[$i]['po_description']);
-
-           $amount=$this->arow[$i]['sum_amount'];
-           if ($amount==null)$amount=0;
-
-           printf('"%s";"%s";',
-                  $this->arow[$i]['j_qcode'],
-                  $this->arow[$i]['name']);
-           printf("%s",nb($amount));
-           printf("\r\n");
-
-
-         }
-      }
-    
//---------------------------------------------------------------------------
-    // Analytic - Accountancy
-    
//---------------------------------------------------------------------------
-
-
-    if ( $this->card_poste=='4')
-      {
-       $this->load_anc_account();
-
-       /*
-        * Show all the result
-        */
-       for ($i=0;$i<count($this->arow);$i++)
-         {
-           printf('"%s";"%s";', 
$this->arow[$i]['po_name'],$this->arow[$i]['po_description']);
-
-           $amount=$this->arow[$i]['sum_amount'];
-           if ($amount==null)$amount=0;
-
-           printf('"%s";"%s";',
-                  $this->arow[$i]['j_poste'],
-                  $this->arow[$i]['name']);
-           printf("%s",nb($amount));
-           printf("\r\n");
-
-
-         }
-      }
-
-
-
-
-  }
-
-}
\ No newline at end of file
diff --git a/include/class_anc_account.php b/include/class_anc_account.php
deleted file mode 100644
index 1d9da5f..0000000
--- a/include/class_anc_account.php
+++ /dev/null
@@ -1,349 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
-*\brief contains the object for the poste_analytique (table poste_analytique)
- */
-
-/*!\brief contains the object for the poste_analytique (table poste_analytique)
- *
- */
-require_once NOALYSS_INCLUDE.'/class_ihidden.php';
-require_once NOALYSS_INCLUDE.'/class_itext.php';
-require_once NOALYSS_INCLUDE.'/class_iselect.php';
-require_once NOALYSS_INCLUDE.'/class_ispan.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_anc_plan.php';
-
-class Anc_Account
-{
-    var $id; /*!<  $id is po_id */
-    var $name;         /*!< po_name */
-    var $pa_id;                /*!< pa_id fk to the plan_analytique(pa_id) */
-    var $amount;               /*!< po_amount just an amount  */
-    var $description;       /*!< po_description description of the post */
-    var $db;   /*!< database     connection*/
-    var $ga_id;                /*!< FK to the table groupe analytique */
-    function Anc_Account($p_db,$p_id=0)
-    {
-        $this->db=$p_db;
-        $this->id=$p_id;
-        $this->ga_id=null;
-    }
-    /*! \brief retrieve data from the database and
-     *        fill the object
-     * \param $p_where the where clause
-     */
-    private function fetch_from_db($p_where)
-    {
-        $sql="select po_id,
-             po_name ,
-             pa_id,
-             po_amount,
-             po_description,
-             ga_id
-             from poste_analytique
-             where ".
-             $p_where;
-
-        $ret=$this->db->exec_sql($sql);
-        if ( Database::num_row($ret) == 0 )return null;
-        $line=Database::fetch_array($ret);
-
-        $this->id=$line['po_id'];
-        $this->name=$line['po_name'];
-        $this->pa_id=$line['pa_id'];
-        $this->amount=$line['po_amount'];
-        $this->description=$line['po_description'];
-        $this->ga_id=$line['ga_id'];
-
-
-    }
-    function get_by_id()
-    {
-        $this->fetch_from_db("po_id=".$this->id);
-    }
-    /*!
-     * \brief retrieve data thanks the name
-     * \param $p_name name of the analytic account
-     *
-     */
-    function get_by_name($p_name)
-    {
-        $p_name=sql_string($p_name);
-        if ( $p_name == null )
-            $p_name=$this->name;
-
-        $this->fetch_from_db("po_name='".$p_name."'");
-        echo "id = ".$this->id;
-    }
-    function add()
-    {
-        $this->format_data();
-        if ( strlen($this->name) == 0)
-            return;
-        if ( $this->ga_id == null || strlen(trim($this->ga_id)) == 0 )
-            $ga_id=NULL;
-        else
-            $ga_id=$this->ga_id;
-        $sql="insert into poste_analytique (
-             po_name ,
-             pa_id,
-             po_amount,
-             po_description,
-             ga_id
-             ) values ($1,$2,$3,$4,$5)";
-
-        try
-        {
-            
$this->db->exec_sql($sql,array($this->name,$this->pa_id,$this->amount,$this->description,$ga_id));
-
-        }
-        catch (Exception $e)
-        {
-            if ( DEBUG ) print_r($e);
-            echo "<p class=\"notice\">Doublon : l'enregistrement n'est pas 
sauve</p>";
-        }
-
-    }
-    static function make_array_name($cn,$pa_id)
-    {
-        $a=$cn->make_array("select  po_name,po_name from poste_analytique ".
-                           " where ".
-                           " pa_id = $1 order by po_name ",0,array($pa_id));
-        return $a;
-    }
-    function update()
-    {
-        $this->format_data();
-        if ( strlen($this->name) == 0)
-            return;
-        $sql="update poste_analytique ".
-             " set po_name=$1".
-             " ,pa_id=$2".
-             " ,po_amount=$3".
-             " ,po_description=$4".
-             " ,ga_id=$5".
-             " where po_id=$6";
-        try
-        {
-            
$this->db->exec_sql($sql,array($this->name,$this->pa_id,$this->amount,
-                                           
$this->description,$this->ga_id,$this->id));
-        }
-        catch (Exception $e)
-        {
-            echo "<p class=\"notice\">Doublon : l'enregistrement n'est pas 
sauve</p>";
-        }
-
-    }
-    private function format_data()
-    {
-
-        $this->name=$this->name;
-        $this->pa_id=$this->pa_id;
-        $this->amount=$this->amount;
-        if (strlen($this->amount) == 0 )
-            $this->amount=0.0;
-        if ( isNumber($this->amount) ==0 )
-            $this->amount=0;
-
-        $this->description=$this->description;
-    }
-    function delete()
-    {
-        $sql="delete from poste_analytique where po_id=".$this->id;
-        $this->db->exec_sql($sql);
-    }
-    /*! 
-     * \brief return an array of object Poste_Analytique
-     *
-     */
-    function get_list()
-    {
-        $sql="select po_id,
-             po_name ,
-             pa_id,
-             po_amount,
-             po_description,
-             ga_id
-             from poste_analytique ".
-             "   order by po_name";
-
-        $ex=$this->db->exec_sql($sql);
-        $ret=Database::fetch_all($ex);
-        if ( $ret  == null )
-            return null;
-
-        $array=array();
-        foreach ($ret as $line)
-        {
-            $object=new Anc_Account($this->db);
-
-            $object->id=$line['po_id'];
-            $object->name=$line['po_name'];
-            $object->pa_id=$line['pa_id'];
-            $object->amount=$line['po_amount'];
-            $object->description=$line['po_description'];
-            $object->ga_id=$line['ga_id'];
-            $array[]=clone $object;
-        }
-
-        return $array;
-    }
-    function display_list()
-    {
-        $array=$this->get_list();
-        if ( empty($array) )
-        {
-            echo "Vide";
-            return;
-        }
-        foreach ($array as $line)
-        {
-            echo $line->id." / ".$line->name." / ".$line->description."/".
-            $line->amount." / ".$line->pa_id."/".$line->ga_id."<br>";
-        }
-    }
-    function debug()
-    {
-        echo "id ".$this->id."<br>";
-        echo "name ".$this->name."<br>";
-        echo "pa_id ".$this->pa_id."<br>";
-        echo "amount ".$this->amount."<br>";
-        echo "description ".$this->description."<br>";
-        echo "ga_id ".$this->ga_id."<br>";
-    }
-    function form()
-    {
-        $r='';
-        $wName=new IText("po_name",$this->name);
-        $wAmount=new INum("po_amount",$this->amount);
-        $wDescription=new IText("po_description",$this->description);
-        $aGroup_analytic=$this->db->make_array("select ga_id,ga_id from 
groupe_analytique where pa_id=".$this->pa_id,1);
-        if ( count($aGroup_analytic) > 1 )
-        {
-            $wGa_id=new ISelect("ga_id");
-            $wGa_id->value=$aGroup_analytic;
-            $wGa_id->selected=$this->ga_id;
-            $wGa_id->table=1;
-        }
-        else
-        {
-            $wGa_id=new ISpan();
-        }
-        $pa=new Anc_Plan($this->db,$this->pa_id);
-        $pa->get();
-        $wPaName=new IText("",$pa->name);
-        $wPaName->table=1;
-        $wPaName->readOnly=true;
-
-        $wName->table=1;
-        $wAmount->table=1;
-        $wDescription->table=1;
-        $r.=HtmlInput::hidden("pa_id",$this->pa_id);
-        $r.=HtmlInput::hidden("po_id",$this->id);
-
-        $r.="<table>";
-
-        $r.="<tr>";
-        $r.=td(_('Nom'));
-        $r.=$wName->input();
-        $r.="</tr>";
-
-        $r.="<tr>";
-        $r.=td(_('Montant'));
-        $r.=$wAmount->input();
-        $r.="</tr>";
-
-
-        $r.="<tr>";
-        $r.=td(_('Description'));
-        $r.=$wDescription->input();
-        $r.="</tr>";
-
-        $r.="<tr>";
-        $r.=td(_('Plan Analytique'));
-        $r.=$wPaName->input();
-        $r.="</tr>";
-
-        $r.="<tr>";
-        $r.=td(_('Groupe'));
-        $r.=$wGa_id->input();
-        $r.="</tr>";
-
-        $r.="</table>";
-        return $r;
-
-    }
-    function get_from_array($p_array)
-    {
-        $this->name=(isset ($p_array['po_name']))?$p_array['po_name']:"";
-        $this->description=(isset 
($p_array['po_description']))?$p_array['po_description']:"";
-        $this->pa_id=(isset ($p_array['pa_id']))?$p_array['pa_id']:"";
-        $this->amount=(isset ($p_array['po_amount']))?$p_array['po_amount']:0;
-        $this->id=(isset ($p_array['po_id']))?$p_array['po_id']:-1;
-        //    $this->ga_id=(isset($p_array['ga_id']) && $p_array['ga_id'] == 
"-1" )?null:2;
-        $this->ga_id=(isset($p_array['ga_id']) && $p_array['ga_id'] != "-1" 
)?$p_array['ga_id']:null;
-    }
-    static function test_me()
-    {
-        $cn=new Database(dossier::id());
-        $pa_id=$cn->get_value("select max(pa_id) from plan_analytique");
-        $o=new Anc_Account($cn);
-        echo "<h1>Poste_Analytique</h1>";
-        echo "<h2>get_list</h2>";
-        $ee=$o->get_list();
-        print_r($ee);
-        //var_dump($ee);
-
-        echo "<h2>Add some </h2>";
-        $o->pa_id=$pa_id;
-        $o->name="test1";
-        $o->add();
-
-
-        $o->name="test2";
-        $o->add();
-
-        $o->name="test3";
-        $o->add();
-
-        $o->name="test4";
-        $o->add();
-
-        $o->name="test5";
-        $o->add();
-
-        echo "<h2> remove test1</h2>";
-        $o->get_by_name("test1");
-        $o->delete();
-        $o->display_list();
-
-        $o->get_by_name("test4");
-        echo "<hr>".$o->id."<hr>";
-        $o->name="Test Four";
-        $o->update();
-        $o->display_list();
-        $o->delete();
-        $o->display_list();
-    }
-}
-?>
diff --git a/include/class_anc_balance_double.php 
b/include/class_anc_balance_double.php
deleted file mode 100644
index 5574903..0000000
--- a/include/class_anc_balance_double.php
+++ /dev/null
@@ -1,579 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief
- *  Print the crossed balance between 2 plan
- */
-
-/*! \brief
- *  Print the crossed balance between 2 plan
- *
- */
-require_once NOALYSS_INCLUDE.'/class_iselect.php';
-require_once NOALYSS_INCLUDE.'/class_itext.php';
-require_once NOALYSS_INCLUDE.'/class_ibutton.php';
-require_once NOALYSS_INCLUDE.'/class_ihidden.php';
-require_once  NOALYSS_INCLUDE.'/class_anc_print.php';
-require_once  NOALYSS_INCLUDE.'/class_anc_plan.php';
-require_once NOALYSS_INCLUDE.'/class_pdf.php';
-
-class Anc_Balance_Double extends Anc_Print
-{
-    /*!
-     * \brief compute the html display
-     *
-     *
-     * \return string
-     */
-
-    function display_html ()
-    {
-        $r="";
-
-        $array=$this->load();
-        $odd=0;
-        if ( is_array($array) == false )
-        {
-            return $array;
-
-        }
-        $old="";
-        $tot_deb=0;
-        $tot_cred=0;
-
-        foreach ( $array as $row)
-        {
-            $odd++;
-
-            $r.=($odd%2==0)?'<tr class="odd">':'<tr class="even">';
-
-            if ( $old == $row['a_po_name'] )
-            {
-                $r.='<td></td>';
-            }
-            else
-            {
-
-                if ( $tot_deb != 0 || $tot_cred !=0 )
-                {
-                 $r.="<tr>".td('');
-                 $r.="<td>Total </td>".td(nbm($tot_deb),' 
class="num"').td(nbm($tot_cred),' class="num"');
-                    $s=abs($tot_deb-$tot_cred);
-                    $d=($tot_deb>$tot_cred)?'debit':'credit';
-                    $r.="<td class=\"num\">".nbm($s)."</td><td>$d</td>";
-                    $r.="</tr>";
-                }
-                $tot_deb=0;
-                $tot_cred=0;
-
-                // new
-                $r.="</table>";
-                $r.="<table class=\"result\" style=\"margin-bottom:3px\">";
-                $r.="<tr>";
-                $r.="<th style=\"width:30%\" >Poste comptable Analytique</th>";
-                $r.="<th style=\"width:30%\">Poste comptable Analytique</th>";
-                $r.="<th style=\"text-align:right\">D&eacute;bit</th>";
-                $r.="<th style=\"text-align:right\">Cr&eacute;dit</th>";
-                $r.="<th style=\"text-align:right\">Solde</th>";
-                $r.="<th>D/C</th>";
-                $r.="</tr>";
-               $r.='<tr>';
-                $r.=td($row['a_po_name'].' '.$row['a_po_description']);
-                $old=$row['a_po_name'];
-               $r.= '</tr>';
-               $r.= '<tr>';
-               $r.=td('');
-            }
-            $tot_deb+=$row['a_d'];
-            $tot_cred+=$row['a_c'];
-
-           $r.=td($row['b_po_name']." ".$row['b_po_description']);
-
-            $r.=td(nbm($row['a_d']),' class="num"');
-            $r.=td(nbm($row['a_c']),' class="num"');
-            $r.=td(nbm($row['a_solde']),' class="num"');
-            $r.=sprintf("<td>%s</td>",$row['a_debit']);
-            $r.="</tr>";
-        } /* end loop */
-
-        if ( $tot_deb != 0 || $tot_cred !=0 )
-        {
-         $r.="<tr>".td('');
-            $r.="<td>Total </td> <td ' class=\"num\"> ".nbm($tot_deb)." </td> 
<td ' class=\"num\">".nbm($tot_cred)."</td>";
-            $s=abs($tot_deb-$tot_cred);
-            $d=($tot_deb>$tot_cred)?'debit':'credit';
-            $r.=td(nbm($s),' class="num"')."<td>$d</td>";
-            $r.="</tr>";
-        }
-
-        $r.="</table>";
-       $r.=h2info('Résumé');
-        $r.='<table class="result">';
-       $r.='<tr>';
-       $r.=th('Po').
-         th('Nom').
-         th('Débit',' style="text-align:right"').
-         th('Crédit','style="text-align:right" ').
-         th('Solde',' style="text-align:right"');
-
-        $sum=$this->show_sum($array);
-       $tot_cred=0;$tot_deb=0;
-        foreach ($sum as $row)
-        {
-            $r.='<tr>';
-            $r.='<td>'.$row['poste'].'</td>';
-            $r.='<td>'.$row['desc'].'</td>';
-            $r.='<td class="num">'.nbm($row['debit']).'</td>';
-            $r.='<td class="num">'.nbm($row['credit']).'</td>';
-           $diff=bcsub($row['debit'],$row['credit']);
-           $tot_cred=bcadd($tot_cred,$row['credit']);
-           $tot_deb=bcadd($tot_deb,$row['debit']);
-
-           $r.=td(nbm($diff),' class="num" ');
-
-            $r.='<td>'.$row['dc'].'</td>';
-            $r.='</tr>';
-        }
-       $r.=td('');
-       $r.=td('total');
-       $r.=td(nbm($tot_deb),'class="num"');
-       $r.=td(nbm($tot_cred),'class="num"');
-       $solde=bcsub($tot_deb,$tot_cred);
-       $sign=($tot_cred<$tot_deb)?" - ":" + ";
-       $r.=td($sign.nbm($solde),'class="num" style="border:solid 1px 
blue;font-weight:bold"');
-       $r.='</tr>';
-        $r.='</table>';
-
-        return $r;
-    }
-    /*!
-     * \brief Display the result in pdf
-     *
-     * \return none
-     */
-    function display_pdf()
-    {
-        $array=$this->load();
-        if (empty($array))return;
-        $pdf=new PDF($this->db);
-        $pdf->Setdossierinfo(dossier::name());
-        $pdf->setTitle("Balance analytique",true);
-        $pdf->SetAuthor('NOALYSS');
-        $pdf->AliasNbPages();
-        $pdf->AddPage();
-
-        $pa=new Anc_Plan($this->db,$this->pa_id);
-        $pa->get();
-        $pb=new Anc_Plan($this->db,$this->pa_id2);
-        $pb->get();
-        $pdf->SetFont('DejaVu','B',9);
-        $pdf->Cell(0,7,sprintf("Balance croise plan %s %s ",
-                               $pa->name,
-                               $pb->name),1,0,'C');
-        $filtre_date="";
-        $filtre_pa="";
-        $filtre_pb="";
-
-        if ( $this->from !="" ||$this->to !="")
-            $filtre_date=sprintf("Filtre date  %s %s",
-                                 $this->from,
-                                 $this->to);
-        if ( $this->from_poste !="" ||$this->to_poste !="")
-            $filtre_pa=sprintf("Filtre poste plan1  %s %s",
-                               ($this->from_poste!="")?"de 
".$this->from_poste:" ",
-                               ($this->to_poste!="")?"jusque 
".$this->to_poste:"");
-
-        if ( $this->from_poste2 !="" ||$this->to_poste2 !="")
-            $filtre_pb=sprintf("Filtre poste plan2   %s  %s",
-                               ($this->from_poste2!="")?"de 
".$this->from_poste2:" ",
-                               ($this->to_poste2!="")?"jusque 
".$this->to_poste2:"");
-
-        $pdf->SetFont('DejaVu','',8);
-        $pdf->Cell(50,7,$filtre_date);
-        $pdf->Cell(50,7,$filtre_pa);
-        $pdf->Cell(50,7,$filtre_pb);
-        $pdf->Ln();
-
-        $pdf->SetFont('DejaVu','',6);
-        $pdf->Cell(20,7,'id','B');
-        $pdf->Cell(100,7,'Poste Comptable','B');
-        $pdf->Cell(20,7,'Débit','B',0,'L');
-        $pdf->Cell(20,7,'Crédit','B',0,'L');
-        $pdf->Cell(20,7,'Solde','B',0,'L');
-        $pdf->Cell(20,7,'D/C','B',0,'L');
-        $pdf->Ln();
-
-        for ($i=0;$i<count($array);$i++)
-        {
-            $row=$array[$i];
-            $pdf->Cell(20,6,$row['a_po_name'],0,0,'L');
-            $pdf->Cell(40,6,mb_substr($row['a_po_description'],0,31),0,0,'L');
-            $pdf->Cell(20,6,$row['b_po_name'],0,0,'L');
-            $pdf->Cell(40,6,mb_substr($row['b_po_description'],0,31),0,0,'L');
-            $pdf->Cell(20,6,$row['a_d'],0,0,'R');
-            $pdf->Cell(20,6,$row['a_c'],0,0,'R');
-            $pdf->Cell(20,6,$row['a_solde'],0,0,'R');
-            $pdf->Cell(20,6,$row['a_debit'],0,0,'C');
-            $pdf->Ln();
-        }
-
-        $sum=$this->show_sum($array);
-        $pdf->SetFont('DejaVu','B',8);
-        $pdf->Cell(70,6,'Somme',1,0,'C');
-        $pdf->Ln(5);
-        $pdf->SetFont('DejaVu','',6);
-
-        $pdf->Cell(20,7,'Poste');
-        $pdf->Cell(60,7,'Description','B');
-        $pdf->Cell(20,7,'Débit','B',0,'L');
-        $pdf->Cell(20,7,'Crédit','B',0,'L');
-        $pdf->Cell(20,7,'Solde','B',0,'L');
-        $pdf->Cell(20,7,'D/C','B',0,'L');
-        $pdf->Ln();
-
-        for ($i=0;$i<count($sum);$i++)
-        {
-            $row=$sum[$i];
-            $pdf->Cell(20,6,$row['poste'],0,0,'L');
-            $pdf->Cell(60,6,$row['desc'],0,0,'L');
-            $pdf->Cell(20,6,sprintf('%.2f',$row['debit']),0,0,'R');
-            $pdf->Cell(20,6,sprintf('%.2f',$row['credit']),0,0,'R');
-            $pdf->Cell(20,6,sprintf('%.2f',$row['solde']),0,0,'R');
-            $pdf->Cell(20,6,$row['dc'],0,0,'R');
-            $pdf->Ln();
-        }
-        $fDate=date('dmy-Hi');
-        $pdf->output('crossbalance-'.$fDate.'.pdf','D');
-    }
-
-
-    /*!
-     * \brief Compute the csv export
-     * \return string with the csv
-     */
-    function display_csv()
-    {
-        $r="";
-
-        $r.='"Poste comptable Analytique";';
-        $r.='"Poste comptable Analytique";';
-        $r.='"Debit";';
-        $r.='"Credit";';
-        $r.='"Solde";';
-        $r.='"D/C"';
-
-        $r.="\r\n";
-
-        $array=$this->load();
-        if ( is_array($array) == false )
-        {
-            return $array;
-
-        }
-        foreach ( $array as $row)
-        {
-
-            $r.=sprintf('"%s";',$row['a_po_name']);
-            $r.=sprintf('"%s";',$row['b_po_name']);
-            $r.=sprintf("%s;",nb($row['a_d']));
-            $r.=sprintf("%s;",nb($row['a_c']));
-            $r.=sprintf("%s;",nb($row['a_solde']));
-            $r.=sprintf('"%s"',$row['a_debit']);
-            $r.="\r\n";
-        }
-
-        return $r;
-
-    }
-    /*!
-     * \brief Compute  the form to display
-     * \param $p_hidden hidden tag to be included (gDossier,...)
-     *
-     *
-     * \return string containing the data
-     */
-    function display_form($p_string='')
-    {
-        $r=parent::display_form($p_string);
-        // show the second plan
-        $r.='<span style="padding:5px;margin:5px;border:2px double  
blue;display:block;">';
-        $plan=new Anc_Plan($this->db);
-        $plan_id=new ISelect("pa_id2");
-        $plan_id->value=$this->db->make_array("select pa_id, pa_name from 
plan_analytique order by pa_name");
-        $plan_id->selected=$this->pa_id2;
-        $r.= "Plan Analytique :".$plan_id->input();
-        $r.=HtmlInput::request_to_hidden(array('ac'));
-        $poste=new IText();
-        $poste->size=10;
-        $r.="Entre le poste ".$poste->input("from_poste2",$this->from_poste2);
-        $choose=new IButton();
-        $choose->name="Choix Poste";
-        $choose->label=_("Recherche");
-        
$choose->javascript="onClick=search_ca(".dossier::id().",'from_poste2','pa_id2')";
-        $r.=$choose->input();
-
-        $r.=" et le poste ".$poste->input("to_poste2",$this->to_poste2);
-        
$choose->javascript="onClick=search_ca(".dossier::id().",'to_poste2','pa_id2')";
-        $r.=$choose->input();
-        $r.='<span class="notice" style="display:block">'.
-            _('Selectionnez le plan qui vous int&eacute;resse avant de cliquer 
sur Recherche').
-            '</span>';
-
-        $r.='</span>';
-        $r.=HtmlInput::submit('Affiche', _('Rechercher'));
-        return $r;
-    }
-    /*!
-     * \brief Show the button to export in PDF or CSV
-     * \param $p_string hidden data to include in the form
-     *
-     *
-     * \return string with the button
-     */
-    function show_button($p_string="")
-    {
-        $r="";
-        $r.= '<form method="GET" action="export.php" style="display:inline">';
-        $r.= $p_string;
-        $r.= HtmlInput::hidden("to",$this->to);
-        $r.= HtmlInput::hidden("act","PDF:AncBalDouble");
-        $r.= HtmlInput::hidden("from",$this->from);
-        $r.= HtmlInput::hidden("pa_id",$this->pa_id);
-        $r.= HtmlInput::hidden("from_poste",$this->from_poste);
-        $r.= HtmlInput::hidden("to_poste",$this->to_poste);
-        $r.= HtmlInput::hidden("pa_id2",$this->pa_id2);
-        $r.= HtmlInput::hidden("from_poste2",$this->from_poste2);
-        $r.= HtmlInput::hidden("to_poste2",$this->to_poste2);
-        $r.=dossier::hidden();
-        $r.=HtmlInput::submit('bt_pdf',"Export en PDF");
-        $r.= '</form>';
-
-        $r.= '<form method="GET" action="export.php"  style="display:inline">';
-        $r.= HtmlInput::hidden("to",$this->to);
-        $r.= HtmlInput::hidden("act","CSV:AncBalDouble");
-        $r.= HtmlInput::hidden("from",$this->from);
-        $r.= HtmlInput::hidden("pa_id",$this->pa_id);
-        $r.= HtmlInput::hidden("from_poste",$this->from_poste);
-        $r.= HtmlInput::hidden("to_poste",$this->to_poste);
-        $r.= HtmlInput::hidden("pa_id2",$this->pa_id2);
-        $r.= HtmlInput::hidden("from_poste2",$this->from_poste2);
-        $r.= HtmlInput::hidden("to_poste2",$this->to_poste2);
-        $r.= $p_string;
-        $r.= dossier::hidden();
-        $r.=HtmlInput::submit('bt_csv',"Export en CSV");
-        $r.= '</form>';
-        return $r;
-
-    }
-    /*!
-     * \brief complete the object with the data in $_REQUEST
-     */
-    function get_request()
-    {
-        parent::get_request();
-        
$this->from_poste2=(isset($_REQUEST['from_poste2']))?$_REQUEST['from_poste2']:"";
-        
$this->to_poste2=(isset($_REQUEST['to_poste2']))?$_REQUEST['to_poste2']:"";
-        $this->pa_id2=(isset($_REQUEST['pa_id2']))?$_REQUEST['pa_id2']:"";
-
-    }
-    /*!
-     * \brief load the data from the database
-     *
-     * \return array
-     */
-    function load()
-    {
-        $filter_poste="";
-        $and="";
-        if ( $this->from_poste != "" )
-        {
-            $filter_poste.=" $and upper(pa.po_name)>= 
upper('".Database::escape_string($this->from_poste)."')";
-            $and=" and ";
-
-        }
-        if ( $this->to_poste != "" )
-        {
-            $filter_poste.=" $and upper(pa.po_name)<= 
upper('".Database::escape_string($this->to_poste)."')";
-            $and=" and ";
-        }
-
-        if ( $this->from_poste2 != "" )
-        {
-            $filter_poste.=" $and upper(pb.po_name)>= 
upper('".Database::escape_string($this->from_poste2)."')";
-            $and=" and ";
-        }
-        if ( $this->to_poste2 != "" )
-        {
-            $filter_poste.=" $and upper(pb.po_name)<= 
upper('".Database::escape_string($this->to_poste2)."')";
-            $and=" and ";
-        }
-        if ( $filter_poste != "")
-            $filter_poste=" where ".$filter_poste;
-
-        $sql="
-             select  a_po_id ,
-             pa.po_name as a_po_name,
-             pa.po_description as a_po_description,
-             pb.po_description as b_po_description,
-
-             b_po_id,
-             pb.po_name as b_po_name,
-             sum(a_oa_amount_c) as a_c,
-             sum(a_oa_amount_d) as a_d
-             from (select
-                       a.j_id,
-             a.po_id as a_po_id,
-             b.po_id as b_po_id,
-             case when a.oa_debit='t' then a.oa_amount else 0 end as 
a_oa_amount_d,
-             case when a.oa_debit='f' then a.oa_amount else 0 end as 
a_oa_amount_c
-             from
-             operation_analytique as a join operation_analytique as b on 
(a.j_id=b.j_id and a.oa_row=b.oa_row)
-               join poste_analytique as poa on (a.po_id=poa.po_id)
-               join poste_analytique as pob on (b.po_id=pob.po_id)
-             where poa.pa_id=".
-             $this->pa_id."
-             and pob.pa_id=".$this->pa_id2."  ".$this->set_sql_filter()."
-             ) as m join poste_analytique as pa on ( a_po_id=pa.po_id)
-             join poste_analytique as pb on (b_po_id=pb.po_id)
-
-             $filter_poste
-
-             group by 
a_po_id,b_po_id,pa.po_name,pa.po_description,pb.po_name,pb.po_description
-             order by 2;
-             ";
-
-
-        $res=$this->db->exec_sql($sql);
-        $this->has_data=Database::num_row($res);
-        if ( Database::num_row($res) == 0 )
-            return null;
-        $a=array();
-        $count=0;
-        $array=Database::fetch_all($res);
-        foreach ($array as $row)
-        {
-            $a[$count]['a_po_id']=$row['a_po_id'];
-            $a[$count]['a_d']=$row['a_d'];
-            $a[$count]['a_c']=$row['a_c'];
-            $a[$count]['b_po_id']=$row['b_po_id'];
-
-            $a[$count]['a_po_name']=$row['a_po_name'];
-            $a[$count]['a_po_description']=$row['a_po_description'];
-            $a[$count]['b_po_name']=$row['b_po_name'];
-            $a[$count]['b_po_description']=$row['b_po_description'];
-            $a[$count]['a_solde']=abs($row['a_d']-$row['a_c']);
-            $a[$count]['a_debit']=($row['a_d']>$row['a_c'])?"debit":"credit";
-
-            $count++;
-        }
-        return $a;
-
-
-    }
-
-
-    /*!
-     * \brief add extra lines  with sum of each account
-     * \param $p_array array returned by load()
-     */
-    function show_sum ($p_array)
-    {
-        $tot_deb=0;
-        $tot_cred=0;
-        $old="";
-        $first=true;
-        $array=array();
-        foreach ( $p_array as $row)
-        {
-
-            if ( $old != $row['a_po_name'] && $first==false )
-
-            {
-                $s=abs($tot_deb-$tot_cred);
-                $d=($tot_deb>$tot_cred)?'debit':'credit';
-                $array[]=array('poste'=>$old,'desc'=>$old_desc
-                                                    
,'debit'=>$tot_deb,'credit'=>$tot_cred,
-                               'solde'=>$s,'dc'=>$d);
-
-                $tot_deb=0;
-                $tot_cred=0;
-
-                $old=$row['a_po_name'];
-                $old_desc=$row['a_po_description'];
-            }
-
-            if ( $first )
-            {
-                $first=false;
-                $old=$row['a_po_name'];
-                $old_desc=$row['a_po_description'];
-            }
-
-            $tot_deb+=$row['a_d'];
-            $tot_cred+=$row['a_c'];
-
-
-        }
-        $s=abs($tot_deb-$tot_cred);
-        $d=($tot_deb>$tot_cred)?'debit':'credit';
-        $array[]=array('poste'=>$old,'desc'=>$old_desc
-                      ,'debit'=>$tot_deb,'credit'=>$tot_cred,
-
-                       'solde'=>$s,'dc'=>$d);
-
-
-        return $array;
-
-    }
-    /*!
-     * \brief for testing and debuggind the class
-     *        it must never be called from production system, it is
-     *        intended only for developpers
-     * \param
-     * \param
-     * \param
-     *
-     *
-     * \return none
-     */
-    static function test_me()
-    {
-        $a=new Database(dossier::id());
-
-        $bal=new Anc_Balance_Double($a);
-        $bal->get_request();
-
-        echo '<form method="GET">';
-
-        echo $bal->display_form();
-        echo '</form>';
-        if ( isset($_GET['result']))
-        {
-            echo $bal->show_button("","");
-            echo "<h1>HTML</h1>";
-            echo $bal->display_html();
-            echo "<h1>CSV</h1>";
-            echo $bal->display_csv();
-
-        }
-    }
-}
diff --git a/include/class_anc_balance_simple.php 
b/include/class_anc_balance_simple.php
deleted file mode 100644
index 9dd563d..0000000
--- a/include/class_anc_balance_simple.php
+++ /dev/null
@@ -1,311 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
-  \brief manage the simple balance for CA, inherit from balance_ca
- */
-
-require_once NOALYSS_INCLUDE.'/class_ihidden.php';
-require_once  NOALYSS_INCLUDE.'/class_anc_print.php';
-require_once  NOALYSS_INCLUDE.'/class_anc_plan.php';
-require_once  NOALYSS_INCLUDE.'/ac_common.php';
-require_once NOALYSS_INCLUDE.'/class_pdf.php';
-require_once  NOALYSS_INCLUDE.'/header_print.php';
-/*! \brief manage the simple balance for CA, inherit from balance_ca
- *
- */
-
-class Anc_Balance_Simple extends Anc_Print
-{
-
-    /*!
-     * \brief load the data from the database
-     *
-     * \return array
-     */
-    function load()
-    {
-        $filter=$this->set_sql_filter();
-        // sum debit
-
-        $sql="select m.po_id,sum(deb) as sum_deb,sum(cred) as sum_cred,";
-        $sql.=" po_name||'  '||coalesce(po_description,'') as po_name";
-        $sql.=" from ";
-        $sql.=" (select po_id,case when oa_debit='t' then oa_amount else 0 end 
as deb,";
-        $sql.="case when oa_debit='f' then oa_amount else 0 end as cred ";
-        $sql.=" from operation_analytique join poste_analytique using(po_id)";
-        $sql.=(empty($filter) == false)?" where ".$filter:"";
-        $sql.=" ) as m join poste_analytique using (po_id)";
-        $sql.=" where pa_id=".$this->pa_id;
-        $sql.=" group by po_id,po_name,po_description";
-        $sql.=" order by po_id";
-        $res=$this->db->exec_sql($sql);
-
-        if ( Database::num_row($res) == 0 ) {
-            $this->has_data=0;
-            return null;
-        }
-        $a=array();
-        $count=0;
-        $array=Database::fetch_all($res);
-        foreach ($array as $row)
-        {
-            $a[$count]['po_id']=$row['po_id'];
-            $a[$count]['sum_deb']=$row['sum_deb'];
-            $a[$count]['sum_cred']=$row['sum_cred'];
-            $a[$count]['po_name']=$row['po_name'];
-            $a[$count]['solde']=abs($row['sum_deb']-$row['sum_cred']);
-            
$a[$count]['debit']=($row['sum_deb']>$row['sum_cred'])?"debit":"credit";
-            $count++;
-        }
-        $this->has_data=$count;
-        return $a;
-
-
-    }
-    /*!
-     * \brief Set the filter (account_date)
-     *
-     * \return return the string to add to load
-     */
-
-
-    function set_sql_filter()
-    {
-        $sql="";
-        $and="";
-        if ( $this->from != "" )
-        {
-            $sql.=" oa_date >= to_date('".$this->from."','DD.MM.YYYY')";
-            $and=" and ";
-        }
-        if ( $this->to != "" )
-        {
-            $sql.=" $and oa_date <= to_date('".$this->to."','DD.MM.YYYY')";
-            $and=" and ";
-        }
-        if ( $this->from_poste != "" )
-        {
-            $sql.=" $and upper(po_name)>= upper('".$this->from_poste."')";
-            $and=" and ";
-        }
-        if ( $this->to_poste != "" )
-        {
-            $sql.=" $and upper(po_name)<= upper('".$this->to_poste."')";
-            $and=" and ";
-        }
-        return $sql;
-
-    }
-    /*!
-     * \brief compute the html display
-     *
-     *
-     * \return string
-     */
-    function display_html()
-    {
-        $r="<table class=\"result\">";
-        $r.="<tr>";
-        $r.="<th>Poste comptable Analytique</th>";
-        $r.="<th>D&eacute;bit</th>";
-        $r.="<th>Cr&eacute;dit</th>";
-        $r.="<th>Solde</th>";
-        $r.="<th>D/C</th>";
-        $r.="</tr>";
-
-        $array=$this->load();
-        $odd=0;
-        if ( is_array($array) == false )
-        {
-            return $array;
-
-        }
-        foreach ( $array as $row)
-        {
-            $odd++;
-
-            $r.=($odd%2==0)?'<tr class="odd">':'<tr class="even">';
-            // the name and po_id
-            //   $r.=sprintf("<td>%s</td>",$row['po_id']);
-            $r.=sprintf("<td align=\"left\">%s</td>",h($row['po_name']));
-            $r.=td(nbm($row['sum_deb']),' class="num"');
-            $r.=td(nbm($row['sum_cred']),' class="num"');
-            $r.=td(nbm($row['solde']),' class="num"');
-            $deb=($row['sum_deb'] > $row['sum_cred'])?"D":"C";
-            $deb=($row['solde'] == 0 )?'':$deb;
-            $r.=sprintf("<td>%s</td>",$deb);
-            $r.="</tr>";
-        }
-        $r.="</table>";
-        return $r;
-    }
-    /*!
-     * \brief Compute  the form to display
-     * \param $p_hidden hidden tag to be included (gDossier,...)
-     *
-     *
-     * \return string containing the data
-     */
-    function display_form($p_string="")
-    {
-        $r=parent::display_form($p_string);
-
-        $r.= HtmlInput::submit('Affiche', _('Rechercher'));
-
-        return $r;
-    }
-
-    /*!
-     * \brief Display the result in pdf
-     *
-     * \return none
-     */
-    function display_pdf()
-    {
-        $array=$this->load();
-        $pdf=new PDFBalance_Simple($this->db);
-        
$pdf->set_info($this->from_poste,$this->to_poste,$this->from,$this->to);
-        $pdf->AliasNbPages();
-        $pdf->AddPage();
-        $pdf->setTitle("Balance analytique",true);
-
-        $pdf->SetFont('DejaVu','',6);
-        for ($i=0;$i<count($array);$i++)
-        {
-            $row=$array[$i];
-            $pdf->Cell(20,6,$row['po_id'],0,0,'L');
-            $pdf->Cell(90,6,$row['po_name'],0,0,'L');
-            $pdf->Cell(20,6,sprintf('%s',nbm($row['sum_deb'])),0,0,'R');
-            $pdf->Cell(20,6,sprintf('%s',nbm($row['sum_cred'])),0,0,'R');
-            $pdf->Cell(20,6,sprintf('%s',nbm($row['solde'])),0,0,'R');
-            $pdf->Cell(20,6,$row['debit'],0,0,'R');
-            $pdf->Ln();
-        }
-        $fDate=date('dmy-Hi');
-        $pdf->output('simple-balance-'.$fDate.'.pdf','D');
-
-    }
-    /*!
-     * \brief Compute the csv export
-     * \return string with the csv
-     */
-    function display_csv()
-    {
-        $array=$this->load();
-        if ( is_array($array) == false )
-        {
-            return $array;
-
-        }
-        $r="";
-        foreach ( $array as $row)
-        {
-            // the name and po_id
-            $solde=($row['sum_cred']>$row['sum_deb'])?'C':'D';
-            $solde=($row['sum_cred']==$row['sum_deb'])?'':$solde;
-            $r.=sprintf("'%s';",$row['po_id']);
-            $r.=sprintf("'%s';",$row['po_name']);
-            $r.=sprintf("%s;",nb($row['sum_deb']));
-            $r.=sprintf("%s;",nb($row['sum_cred']));
-            $r.=sprintf("%s;",nb($row['solde']));
-            $r.=sprintf("'%s'",$row['debit']);
-            $r.="\r\n";
-        }
-        return $r;
-
-    }
-    /*!
-     * \brief Show the button to export in PDF or CSV
-     * \param $url_csv url of the csv
-     * \param $url_pdf url of the pdf
-     * \param $p_string hidden data to include in the form
-     *
-     *
-     * \return string with the button
-     */
-    function show_button($p_string="")
-    {
-        $r="";
-        $r.= '<form method="GET" action="export.php" style="display:inline">';
-        $r.= $p_string;
-        $r.= dossier::hidden();
-        $r.= HtmlInput::hidden("to",$this->to);
-        $r.= HtmlInput::hidden("act","PDF:AncBalSimple");
-
-        $r.= HtmlInput::hidden("from",$this->from);
-        $r.= HtmlInput::hidden("pa_id",$this->pa_id);
-        $r.= HtmlInput::hidden("from_poste",$this->from_poste);
-        $r.= HtmlInput::hidden("to_poste",$this->to_poste);
-        $r.=HtmlInput::submit('bt_pdf',"Export en PDF");
-        $r.= '</form>';
-
-        $r.= '<form method="GET" action="export.php"  style="display:inline">';
-        $r.= HtmlInput::hidden("act","CSV:AncBalSimple");
-        $r.= HtmlInput::hidden("to",$this->to);
-        $r.= HtmlInput::hidden("from",$this->from);
-        $r.= HtmlInput::hidden("pa_id",$this->pa_id);
-        $r.= HtmlInput::hidden("from_poste",$this->from_poste);
-        $r.= HtmlInput::hidden("to_poste",$this->to_poste);
-        $r.= $p_string;
-        $r.= dossier::hidden();
-        $r.=HtmlInput::submit('bt_csv',"Export en CSV");
-        $r.= '</form>';
-        return $r;
-    }
-
-    /*!
-     * \brief for testing and debuggind the class
-     *        it must never be called from production system, it is
-     *        intended only for developpers
-     * \param
-     * \param
-     * \param
-     *
-     *
-     * \return none
-     */
-    static  function test_me ()
-    {
-        // call the page with ?gDossier=14
-        $a=new Database(dossier::id());
-
-        $bal=new Anc_Balance_Simple($a);
-        $bal->get_request();
-
-        echo '<form method="GET">';
-
-        echo $bal->display_form();
-        echo '</form>';
-        if ( isset($_GET['result']))
-        {
-            echo $bal->show_button("","");
-            echo "<h1>HTML</h1>";
-            echo $bal->display_html();
-            echo "<h1>CSV</h1>";
-            echo $bal->display_csv();
-            /*         echo "<h1>pdf</h1>"; */
-            /*         echo $bal->display_pdf(); */
-
-        }
-
-    }
-}
diff --git a/include/class_anc_grandlivre.php b/include/class_anc_grandlivre.php
deleted file mode 100644
index 452da71..0000000
--- a/include/class_anc_grandlivre.php
+++ /dev/null
@@ -1,309 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief show the Grand Livre for analytic
- */
-require_once NOALYSS_INCLUDE.'/class_anc_print.php';
-require_once NOALYSS_INCLUDE.'/class_impress.php';
-
-class Anc_GrandLivre extends Anc_Print
-{
-    
-    function set_sql_filter()
-    {
-        $sql="";
-        $and=" and ";
-        if ( $this->from != "" )
-        {
-            $sql.="$and oa_date >= to_date('".$this->from."','DD.MM.YYYY')";
-        }
-        if ( $this->to != "" )
-        {
-            $sql.=" $and oa_date <= to_date('".$this->to."','DD.MM.YYYY')";
-        }
-
-        return $sql;
-
-    }
-      /*!
-     * \brief load the data from the database
-     *
-     * \return array
-     */
-    function load()
-    {
-      $filter_date=$this->set_sql_filter();
-      $cond_poste='';
-      if ($this->from_poste != "" )
-            $cond_poste=" and upper(po_name) >= 
upper('".$this->from_poste."')";
-        if ($this->to_poste != "" )
-            $cond_poste.=" and upper(po_name) <= upper('".$this->to_poste."')";
-        $pa_id_cond="";
-        if ( isset ( $this->pa_id) && $this->pa_id !='')
-            $pa_id_cond= "pa_id=".$this->pa_id." and";
-        $array=$this->db->get_array("  select oa_id,
-       po_name,
-       oa_description,
-       po_description,
-       oa_debit,
-       to_char(oa_date,'DD.MM.YYYY') as oa_date,
-       oa_amount,
-       oa_group,
-       j_id ,
-       jr_internal,
-       jr_id,
-       jr_comment,
-       j_poste,
-       jrnx.f_id,
-       ( select ad_value from fiche_Detail where f_id=jrnx.f_id and ad_id=23) 
as qcode,
-        jr_pj_number
-       from operation_analytique as B join poste_analytique using(po_id)
-       left join jrnx using (j_id)
-       left join jrn on  (j_grpt=jr_grpt_id)
-             where $pa_id_cond oa_amount <> 0.0  $cond_poste  $filter_date
-       order by po_name,oa_date::date,qcode,j_poste");
-        $this->has_data=count($array);
-        return $array;
-    }
-
-       function load_csv()
-    {
-      $filter_date=$this->set_sql_filter();
-      $cond_poste='';
-      if ($this->from_poste != "" )
-            $cond_poste=" and upper(po_name) >= 
upper('".$this->from_poste."')";
-        if ($this->to_poste != "" )
-            $cond_poste.=" and upper(po_name) <= upper('".$this->to_poste."')";
-        $pa_id_cond="";
-        if ( isset ( $this->pa_id) && $this->pa_id !='')
-            $pa_id_cond= "pa_id=".$this->pa_id." and";
-        $array=$this->db->get_array("  select
-       po_name,
-       to_char(oa_date,'DD.MM.YYYY') as oa_date,
-       j_poste,
-       ( select ad_value from fiche_Detail where f_id=jrnx.f_id and ad_id=23) 
as qcode,
-       jr_comment,
-        jr_pj_number,
-       jr_internal,
-        oa_row,
-       case when oa_debit='t' then 'D' else 'C' end,
-       oa_amount
-       from operation_analytique as B join poste_analytique using(po_id)
-       left join jrnx using (j_id)
-       left join jrn on  (j_grpt=jr_grpt_id)
-             where $pa_id_cond oa_amount <> 0.0  $cond_poste $filter_date
-       order by po_name,oa_date::date,qcode,j_poste");
-
-
-        return $array;
-    }
-    /* !
-     * \brief Show the button to export in PDF all the receipt
-     * 
-     * \param $p_string extra hidden value
-     * \return string with the button
-     */
-
-    function button_export_pdf($p_string = "")
-    {
-        if (CONVERT_GIF_PDF <> 'NOT' && PDFTK <> 'NOT')
-        {
-            $r = "";
-            $r.= HtmlInput::hidden("to", $this->to);
-            $r.= HtmlInput::hidden("from", $this->from);
-            $r.= HtmlInput::hidden("pa_id", $this->pa_id);
-            $r.= HtmlInput::hidden("from_poste", $this->from_poste);
-            $r.= HtmlInput::hidden("to_poste", $this->to_poste);
-            $r.= HtmlInput::hidden("act","PDF:AncReceipt");
-
-            $r.= $p_string;
-            $r.= dossier::hidden();
-            $r.=HtmlInput::submit('bt_receipt_anal_pdf', _("Export des pièces 
en PDF"));
-        } 
-        else 
-        {
-            
-            $r = "";
-            $msg = _("Les extensions pour convertir en pdf ne sont pas 
installées");
-            $r = HtmlInput::button("bt_receipt_anal", _('Export des pièces en 
PDF'), sprintf('onclick="alert(\'%s\')"',$msg));
-        }
-        return $r;
-    }
-   /*!
-     * \brief compute the html display
-     *
-     *
-     * \return string
-     */
-
-    function display_html()
-   {
-        $r = "";
-        //---Html
-        $array = $this->load();
-        if (is_array($array) == false || empty($array))
-        {
-            return 0;
-        }
-        $r.= '<table class="result" style="width:100%">';
-        $ix = 0;
-        $prev = 'xx';
-        $idx = 0;
-        $tot_deb = $tot_cred = 0;
-
-       bcscale(2);
-        foreach ($array as $row)
-        {
-            if ($prev != $row['po_name'])
-            {
-                if ($ix > 0)
-                {
-                    $r.='<tr>';
-                    $tot_solde = bcsub($tot_cred, $tot_deb);
-                    $sign = " ".($tot_solde > 0) ? 'C' : 'D';
-                   $r.=td('') . td('') . td('');
-                    $r.=td('') . td('') . td('') . td('') . td('') . 
td(nbm($tot_deb), ' class="num"') . td(nbm($tot_cred), ' class="num"') . 
td(nbm($tot_solde) . $sign, ' class="num notice"');
-                }
-                $r.='<tr>' . '<td colspan="7" style="width:auto">' . '<h2>' . 
h($row['po_name'] . ' ' . $row['po_description']) . '</td></tr>';
-                $r.= '<tr>' .
-                        '<th>' . '</th>' .
-                        '<th>' . _('Date') . '</th>' .
-                        '<th>' . _('Poste') . '</th>' .
-                        '<th>' . _('Quick_code') . '</th>' .
-                        '<th>' . _('Libellé') . '</th>' .
-                        '<th>' . '</th>' .
-                        '<th>' . _('Pièce') . '</th>' .
-                        '<th>' . _('Interne') . '</th>' .
-                        '<th style="text-align:right">' . _('Débit') . '</th>' 
.
-                        '<th style="text-align:right">' . _('Crédit') . 
'</th>' .
-                        '<th style="text-align:right">' . _('Prog.') . '</th>' 
.
-                        '</tr>';
-
-                $tot_deb = $tot_cred = 0;
-                $prev = $row['po_name'];
-                $ix++;
-            }
-            $class = ($idx % 2 == 0) ? 'even' : 'odd';
-            $idx++;
-            $r.='<tr class="' . $class . '">';
-            $detail = ($row['jr_id'] != null) ? 
HtmlInput::detail_op($row['jr_id'], $row['jr_internal']) : '';
-            $post_detail = ($row['j_poste'] != null) ? 
HtmlInput::history_account($row['j_poste'], $row['j_poste']) : '';
-            $card_detail = ($row['f_id'] != null) ? 
HtmlInput::history_card($row['f_id'], $row['qcode']) : '';
-            $amount_deb = ($row['oa_debit'] == 't') ? $row['oa_amount'] : 0;
-            $amount_cred = ($row['oa_debit'] == 'f') ? $row['oa_amount'] : 0;
-            $tot_deb = bcadd($tot_deb, $amount_deb);
-            $tot_cred = bcadd($tot_cred, $amount_cred);
-            $tot_solde=bcsub($tot_cred,$tot_deb);
-
-            /*
-             * Checked button
-             */
-            $str_ck = "";
-            $str_document = "";
-            if ($row['jr_id'] != null)
-            {
-                /*
-                 * Get receipt info  
-                 */
-                $str_document = 
HtmlInput::show_receipt_document($row['jr_id']);
-                if ($str_document != "")
-                {
-                    $ck = new ICheckBox('ck[]', $row['jr_id']);
-                    $str_ck = $ck->input();
-                }
-            }
-
-            $r.=
-                    '<td>' . $str_ck . '</td>' .
-                    '<td>' . $row['oa_date'] . '</td>' .
-                    td($post_detail) .
-                    td($card_detail) .
-                    td($row['jr_comment']) .
-                    '<td>' . $str_document . '</td>' .
-                    td($row['jr_pj_number']) .
-                    '<td>' . $detail . '</td>' .
-                    '<td class="num">' . nbm($amount_deb) . '</td>' .
-                    '<td class="num">' . nbm($amount_cred). '</td>'.
-                    '<td class="num">' . nbm($tot_solde). '</td>';
-            $r.= '</tr>';
-        }
-        $r.='<tr>';
-        $tot_solde = bcsub($tot_cred, $tot_deb);
-        $sign = ($tot_solde > 0) ? 'C' : 'D';
-       $r.=td('') . td('') . td('');
-        $r.=td('') . td('') . td('') . td('') . td('') . td(nbm($tot_deb), ' 
class="num"') . td(nbm($tot_cred), ' class="num"') . td(nbm($tot_solde) . 
$sign, '  class="num notice"');
-
-        $r.= '</table>';
-        return $r;
-    }
-      /*!
-     * \brief Show the button to export in PDF or CSV
-     * \param $url_csv url of the csv
-     * \param $url_pdf url of the pdf
-     * \param $p_string hidden data to include in the form
-     *
-     *
-     * \return string with the button
-     */
-    function show_button($p_string="")
-    {
-        $r="";
-        $r.= '<form method="GET" action="export.php"  style="display:inline">';
-        $r.= HtmlInput::hidden("act","CSV:AncGrandLivre");
-        $r.= HtmlInput::hidden("to",$this->to);
-        $r.= HtmlInput::hidden("from",$this->from);
-        $r.= HtmlInput::hidden("pa_id",$this->pa_id);
-        $r.= HtmlInput::hidden("from_poste",$this->from_poste);
-        $r.= HtmlInput::hidden("to_poste",$this->to_poste);
-        $r.= $p_string;
-        $r.= dossier::hidden();
-        $r.=HtmlInput::submit('bt_csv',"Export en CSV");
-        $r.= '</form>';
-        return $r;
-    }
-    function display_csv()
-    {
-        $r="";
-        //---Html
-        $array=$this->load_csv();
-        if ( is_array($array) == false )
-        {
-            return $array;
-
-        }
-
-        $ix=0;$prev='xx';
-       $tot_deb=$tot_cred=0;
-        $aheader=array();
-        $aheader[]=array("title"=>'Imp. Analytique','type'=>'string');
-        $aheader[]=array("title"=>'Date','type'=>'string');
-        $aheader[]=array("title"=>'Poste','type'=>'string');
-        $aheader[]=array("title"=>'Quick_Code','type'=>'string');
-        $aheader[]=array("title"=>'libelle','type'=>'string');
-        $aheader[]=array("title"=>'Pièce','type'=>'string');
-        $aheader[]=array("title"=>'Num.interne','type'=>'string');
-        $aheader[]=array("title"=>'row','type'=>'num');
-        $aheader[]=array("title"=>'Debit','type'=>'string');
-        $aheader[]=array("title"=>'Credit','type'=>'num');
-        Impress::array_to_csv($array, $aheader);
-    }
-}
diff --git a/include/class_anc_group.php b/include/class_anc_group.php
deleted file mode 100644
index daff410..0000000
--- a/include/class_anc_group.php
+++ /dev/null
@@ -1,260 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief class for the group of the analytic account
- *
- */
-require_once  NOALYSS_INCLUDE.'/class_database.php';
-require_once  NOALYSS_INCLUDE.'/constant.php';
-require_once  NOALYSS_INCLUDE.'/class_dossier.php';
-require_once NOALYSS_INCLUDE.'/class_anc_print.php';
-
-/*! \brief class for the group of the analytic account
- *
- */
-class Anc_Group extends Anc_Print
-{
-    var $db;
-    var $ga_id;
-    var $ga_description;
-    var $pa_id;
-
-    function __construct ( $p_cn )
-    {
-        $this->db=$p_cn;
-        $this->ga_id=null;
-        $this->ga_description=null;
-        $this->pa_id=null;
-    }
-    /*!
-     * \brief insert into the database  an object
-     * \return message with error otherwise an empty string
-     */
-
-    function insert()
-    {
-        if (strlen ($this->ga_id) > 10 )            return '<span 
class="notice">'.
-                _('Taille de la code trop long maximum 10 
caractères').'</span>';
-        $sql=" insert into groupe_analytique (ga_id,ga_description,pa_id) 
values ('%s','%s',%d)";
-        $sql=sprintf($sql,Database::escape_string($this->ga_id),
-                     Database::escape_string($this->ga_description),
-                     $this->pa_id);
-        try
-        {
-            $this->db->exec_sql($sql);
-        }
-        catch (Exception $a)
-        {
-            return '<span class="notice">Doublon !!</span>';
-        }
-        return "";
-    }
-    /*!
-     * \brief remove from the database
-     */
-
-    function remove()
-    {
-        $this->ga_id=str_replace(' ','',$this->ga_id);
-        $this->ga_id=strtoupper($this->ga_id);
-        $sql=" delete from groupe_analytique where 
ga_id='".Database::escape_string($this->ga_id)."'";
-
-        $this->db->exec_sql($sql);
-    }
-
-    /*!
-     * \brief load from the database and make an object
-     */
-    function load()
-    {
-        $sql="select ga_id, ga_description,pa_id from groupe_analytique where".
-             " ga_id = ".$this->ga_id;
-        $res=$this->db->exec_sql($sql);
-        $array=Database::fetch_all($res);
-        if ( ! empty($array) )
-        {
-            $this->ga_id=$array['ga_id'];
-            $this->ga_description=$array['ga_description'];
-            $this->pa_id=$array['pa_id'];
-        }
-    }
-
-    /*!
-     * \brief fill the object thanks an array
-     * \param array
-     */
-    function get_from_array($p_array)
-    {
-        $this->ga_id=$p_array['ga_id'];
-        $this->pa_id=$p_array['pa_id'];
-        $this->ga_description=$p_array['ga_description'];
-    }
-    function myList()
-    {
-        $sql=" select ga_id,groupe_analytique.pa_id,pa_name,ga_description ".
-             " from groupe_analytique ".
-             " join plan_analytique using (pa_id)";
-        $r=$this->db->exec_sql($sql);
-        $array=Database::fetch_all($r);
-        $res=array();
-        if ( ! empty($array))
-        {
-            foreach ($array as $m )
-            {
-                $obj= new Anc_Group($this->db);
-                $obj->get_from_array($m);
-                $obj->pa_name=$m['pa_name'];
-                $res[]=clone $obj;
-            }
-        }
-        return $res;
-    }
-
-    function set_sql_filter()
-    {
-        $sql="";
-        $and="and ";
-        if ( $this->from != "" )
-        {
-            $sql.=" $and  oa_date >= to_date('".$this->from."','DD.MM.YYYY')";
-            $and=" and ";
-        }
-        if ( $this->to != "" )
-        {
-            $sql.=" $and oa_date <= to_date('".$this->to."','DD.MM.YYYY')";
-            $and=" and ";
-        }
-        if ( $this->from_poste != "" )
-        {
-            $sql.=" $and upper(po_name)>= upper('".$this->from_poste."')";
-            $and=" and ";
-        }
-        if ( $this->to_poste != "" )
-        {
-            $sql.=" $and upper(po_name)<= upper('".$this->to_poste."')";
-            $and=" and ";
-        }
-        return $sql;
-
-    }
-
-    function get_result()
-    {
-      $filter_date=$this->set_sql_filter();
-
-      $sql="with m as (select po_id,
-       po_name,
-       ga_id,
-       case when  oa_debit = 't' then oa_amount
-       else 0
-       end  as amount_deb,
-       case when oa_debit = 'f' then oa_amount
-       else 0
-       end as amount_cred,
-       oa_date
-       from operation_analytique
-join poste_analytique using (po_id)
-where pa_id=$1 $filter_date )
-select sum(amount_cred) as sum_cred, sum(amount_deb)as 
sum_deb,po_name,ga_id,ga_description
-from m left join groupe_analytique using (ga_id)
-group by ga_id,po_name,ga_description
-order by ga_description,po_name";
-      $ret=$this->db->get_array($sql,array($this->pa_id));
-
-      return $ret;
-    }
-
-    function display_html()
-    {
-      if ( $this->check()  != 0)
-       {
-         alert('Désolé mais une des dates données n\'est pas valide');
-         return;
-       }
-
-      $array=$this->get_result();
-      if ( empty ($array) ) return "";
-      require_once NOALYSS_INCLUDE.'/template/anc_balance_group.php';
-
-
-    }
-  /**
-   address@hidden display the button export CSV
-   address@hidden $p_hidden is a string containing hidden items
-   address@hidden html string
-   */
-  function show_button($p_hidden="")
-  {
-    $r="";
-    $r.= '<form method="GET" action="export.php"  style="display:inline">';
-    $r.= HtmlInput::hidden("act","CSV:AncBalGroup");
-    $r.= HtmlInput::hidden("to",$this->to);
-    $r.= HtmlInput::hidden("from",$this->from);
-    $r.= HtmlInput::hidden("pa_id",$this->pa_id);
-    $r.= HtmlInput::hidden("from_poste",$this->from_poste);
-    $r.= HtmlInput::hidden("to_poste",$this->to_poste);
-    $r.= $p_hidden;
-    $r.= dossier::hidden();
-    $r.=HtmlInput::submit('bt_csv',"Export en CSV");
-    $r.= '</form>';
-    return $r;
-  }
-  function export_csv()
-  {
-    $array=$this->get_result();
-    printf('"groupe";"activité";"débit";"credit";"solde"');
-    printf("\r\n");
-    bcscale(2);
-    for ($i=0;$i<count($array);$i++)
-      {
-       printf('"%s";"%s";%s;%s;%s',
-              $array[$i]['ga_id'],
-              $array[$i]['po_name'],
-              nb($array[$i]['sum_deb']),
-              nb($array[$i]['sum_cred']),
-              nb(bcsub($array[$i]['sum_cred'],$array[$i]['sum_deb']))
-              );
-       printf("\r\n");
-      }
-  }
-    static function test_me()
-    {
-
-        $cn=new Database(dossier::id());
-        print_r($cn);
-        $o=new Anc_Group($cn);
-        $r=$o->myList();
-        print_r($r);
-        echo '<hr>';
-        print_r($o);
-        $o->ga_id="DD' dd dDD";
-        $o->ga_description="Test 1";
-        $o->remove();
-        //    $o->insert();
-        $o->ga_id="DD";
-        $o->ga_description="Test 1";
-        $o->remove();
-
-        $r=$o->myList();
-        print_r($r);
-    }
-}
diff --git a/include/class_anc_group_operation.php 
b/include/class_anc_group_operation.php
deleted file mode 100644
index 502a9cc..0000000
--- a/include/class_anc_group_operation.php
+++ /dev/null
@@ -1,278 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- *  \brief group of object operations, used for misc operation
- */
-
-/*! \brief group of object operations, used for misc operation
- *
- */
-require_once NOALYSS_INCLUDE.'/class_idate.php';
-require_once NOALYSS_INCLUDE.'/class_itext.php';
-require_once NOALYSS_INCLUDE.'/class_iselect.php';
-require_once NOALYSS_INCLUDE.'/class_icheckbox.php';
-require_once  NOALYSS_INCLUDE.'/class_anc_operation.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once  NOALYSS_INCLUDE.'/class_anc_plan.php';
-require_once  NOALYSS_INCLUDE.'/class_dossier.php';
-
-class Anc_Group_Operation
-{
-    var $db;   /*!< database connection */
-    var  $id;  /*!< oa_group, a group contains
-                          several rows of
-                          operation_analytique linked by the
-                          group id */
-
-    var $a_operation;                                          /*!< array of 
operations */
-    var $date;                                                 /*!< date of 
the operations */
-    var $pa_id;                                                        /*!< 
the concerned pa_id */
-
-    /*!\brief constructor */
-    function  Anc_Group_Operation($p_cn,$p_id=0)
-    {
-        $this->db=$p_cn;
-        $this->id=$p_id;
-        $this->date=date("d.m.Y");
-        $this->nMaxRow=10;
-    }
-    /*!\brief add several rows */
-    function add()
-    {
-
-        $amount=0;
-        try
-        {
-            $this->db->start();
-            foreach ($this->a_operation as $row)
-            {
-                $add=round($row->oa_amount,2);
-                $add=($row->oa_debit=='t')?$add:$add*(-1);
-                $amount+=round($add,2);
-                $row->add();
-            }
-            if ( $amount != 0 ) throw new Exception (_('Operation non 
equilibrée'));
-        }
-        catch (Exception $e)
-        {
-            echo $e->getTrace();
-            $this->db->rollback();
-            throw new Exception($e);
-        }
-        $this->db->commit();
-    }
-    /*!\brief show a form for the operation (several rows)
-     * \return the string containing the form but without the form tag
-     *
-     */
-    function form($p_readonly=0)
-    {
-        $wDate=new IDate("pdate",$this->date);
-        $wDate->table=1;
-        $wDate->size=10;
-        $wDate->readonly=$p_readonly;
-
-        $wDescription=new IText("pdesc");
-        $wDescription->table=0;
-        $wDescription->size=80;
-        $wDescription->readonly=$p_readonly;
-        // Show an existing operation
-        //
-        if ( isset ($this->a_operation[0]))
-        {
-            $wDate->value=$this->a_operation[0]->oa_date;
-            $wDescription->value=$this->a_operation[0]->oa_description;
-        }
-
-        $ret="";
-
-        $ret.='<table style="result"   >';
-
-        $ret.="<TR>".$wDate->input()."</tr>";
-        $ret.='<tr><td>Description</td>'.
-              '<td colspan="3">'.
-              $wDescription->input()."</td></tr>";
-        $Plan=new Anc_Plan($this->db);
-        $aPlan=$Plan->get_list();
-        
$max=(count($this->a_operation)<$this->nMaxRow)?$this->nMaxRow:count($this->a_operation);
-        $ret.='</table><table  id="ago" style="width: 100%;">';
-        /* show 10 rows */
-        $ret.="<tr>";
-        foreach ($aPlan as $d)
-        {
-            $idx=$d['id'];
-            /* array of possible value for the select */
-            $aPoste[$idx]=$this->db->make_array("select po_id as value,".
-                                                " 
po_name||':'||coalesce(po_description,'-') as label ".
-                                                " from poste_analytique ".
-                                                " where pa_id = ".$idx.
-                                                " order by po_name ");
-
-            $ret.="<th> Poste </th>";
-        }
-        $ret.="<th></th>".
-              "<th> Montant</th>".
-              "<th>D&eacute;bit</th>".
-              "</tr>";
-
-        for ($i = 0;$i < $max;$i++)
-        {
-            $ret.="<tr>";
-
-            foreach ($aPlan as $d)
-            {
-                $idx=$d['id'];
-                // init variable
-                $wSelect=new ISelect("pop".$i."plan".$idx);
-                $wSelect->value=$aPoste[$idx];
-                $wSelect->size=12;
-
-                $wSelect->readOnly=$p_readonly;
-                if ( isset($this->a_operation[$i]))
-                {
-                    $wSelect->selected=$this->a_operation[$i]->po_id;
-                }
-                $ret.=td($wSelect->input());
-            }
-            $wAmount=new INum("pamount$i",0.0);
-            $wAmount->size=12;
-            $wAmount->table=1;
-            $wAmount->javascript=" 
onChange=format_number(this);caod_checkTotal()";
-            $wAmount->readOnly=$p_readonly;
-
-            $wDebit=new ICheckBox("pdeb$i");
-            $wDebit->readOnly=$p_readonly;
-            $wDebit->javascript=" onChange=caod_checkTotal()";
-            if ( isset ($this->a_operation[$i]))
-            {
-                $wSelect->selected=$this->a_operation[$i]->po_id;
-                $wAmount->value=$this->a_operation[$i]->oa_amount;
-                $wDebit->value=$this->a_operation[$i]->oa_debit;
-                if ( $wDebit->value=='t')
-                {
-                    $wDebit->selected=true;
-                }
-
-            }
-
-            // build the table
-
-            $ret.="<TD></TD>";
-            $ret.=$wAmount->input();
-            $ret.=td($wDebit->input());
-
-            $ret.="</tr>";
-        }
-        $ret.="</table>";
-        if ( $p_readonly==false)
-        {
-            $add_row=new IButton('Ajouter');
-            $add_row->label=_('Ajouter une ligne');
-            $add_row->javascript='anc_add_row(\'ago\');';
-            $ret.=HtmlInput::hidden('nbrow',$max);
-
-            $ret.=$add_row->input();
-        }
-        return $ret;
-    }
-    /*!\brief fill row from $_POST data
-     *
-     */
-    function get_from_array($p_array)
-    {
-        $Plan=new Anc_Plan($this->db);
-        $aPlan=$Plan->get_list();
-
-
-        for ( $i = 0;$i <$p_array['nbrow'];$i++)
-        {
-            foreach ($aPlan as $d)
-            {
-                $idx=$d['id'];
-                $p=new Anc_Operation($this->db);
-                $p->oa_amount=$p_array["pamount$i"];
-
-                $p->oa_description=$p_array["pdesc"];
-                $p->oa_date=$p_array['pdate'];
-                $p->j_id=0;
-                $p->oa_debit=(isset ($p_array["pdeb$i"]))?'t':'f';
-                $p->oa_group=0;
-
-                $p->po_id=$p_array["pop$i"."plan".$idx];
-                $p->pa_id=$idx;
-                $this->a_operation[]=clone $p;
-            }
-        }
-    }
-    /*!\brief save the group of operation but only if the amount is
-       balanced  */
-    function save()
-    {
-        $this->db->start();
-        try
-        {
-            $oa_group=$this->db->get_next_seq('s_oa_group');
-            for ($i=0;$i<count($this->a_operation);$i++)
-            {
-                $this->a_operation[$i]->oa_group=$oa_group;
-                $this->a_operation[$i]->add();
-            }
-        }
-        catch (Exception $ex)
-        {
-            echo '<span class="error">'.
-            'Erreur dans l\'enregistrement '.
-            __FILE__.':'.__LINE__.' '.
-            $ex->getMessage();
-            $p_cn->rollback();
-            throw new Exception("Erreur ".$ex->getMessage());
-
-        }
-        $this->db->commit();
-    }
-    /*!\brief show the form */
-    function show()
-    {
-        return $this->form(1);
-    }
-    static function test_me()
-    {
-        $dossier=dossier::id();
-        $cn=new Database($dossier);
-
-        if ( isset($_POST['go']))
-        {
-            $b=new Anc_Group_Operation($cn);
-            $b->get_from_array($_POST);
-            return;
-        }
-
-        $a=new Anc_Group_Operation($cn);
-        echo '<form method="post">';
-        echo $a->form();
-        echo dossier::hidden();
-        echo '<input type="submit" name="go">';
-        echo '</form>';
-
-    }
-
-}
diff --git a/include/class_anc_key.php b/include/class_anc_key.php
deleted file mode 100644
index 587178a..0000000
--- a/include/class_anc_key.php
+++ /dev/null
@@ -1,354 +0,0 @@
-<?php
-
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-// Copyright (2014) Author Dany De Bontridder address@hidden
-
-/**
- * @file
- * @brief Class to manage distribution keys for Analytic accountancy
- * 
- */
-require_once NOALYSS_INCLUDE.'/class_anc_key_sql.php';
-
-class Anc_Key
-{
-
-    private $key; /* !  the distribution key */
-    /**
-     * Return the number of keys available.
-     *  Return the number of keys available for the ledger given in parameter
-     * 
-     * @global $cn database connection
-     * @param $p_jrn number of the ledger (jrn_def.jrn_def_id
-     * @return number of available keys
-     */
-    static function key_avaiable($p_jrn)
-    {
-        global $cn;
-        $count=$cn->get_value (' select count(*) 
-            from key_distribution_ledger 
-            join key_distribution using (kd_id)
-            where
-            jrn_def_id=$1', array($p_jrn));
-        return $count;
-    }
-    function __construct($p_id=-1)
-    {
-        global $cn;
-        $this->key=new Anc_Key_SQL($cn, $p_id);
-        $this->a_ledger=null;
-        $this->a_activity=null;
-        $this->a_row=null;
-    }
-
-    /**
-     * @brief display list of available keys
-     * @param $p_amount   amount to distribute
-     * @param $p_target   target to update
-     * @param $p_ledger   is the jrn_def_id
-     */
-    static function display_choice($p_amount, $p_target,$p_ledger)
-    {
-        global $cn;
-        $a_key=$cn->get_array(' select kd_id,
-                kd_name,
-                kd_description
-                from
-                key_distribution
-                join key_distribution_ledger using (kd_id)
-                where
-                jrn_def_id=$1',
-                array(
-                    $p_ledger
-                ));
-        if (empty($a_key))
-        {
-            echo _('Aucune clef disponible');
-            echo _('Allez dans ANCKEY pour en ajouter pour ce journal');
-        }
-        include 'template/anc_key_display_choice.php';
-    }
-
-    /**
-     * @brief display a  list of keys, choose one to modify it
-     * 
-     */
-    static function display_list()
-    {
-        global $cn;
-        $a_key=$cn->get_array('select b.kd_id,b.kd_name,b.kd_description,
-                (select sum(ke_percent) from key_distribution_detail as a 
where a.kd_id=b.kd_id) as distrib 
-                from key_distribution as b order by b.kd_name');
-        if (empty($a_key))
-        {
-            echo _('Aucune clef disponible');
-        }
-        include 'template/anc_key_display_list.php';
-    }
-
-    /**
-     * @brief Show the detail for a key distribution and let you change it
-     * for adding or update
-     */
-    function input()
-    {
-        global $cn;
-
-        $plan=$cn->get_array('
-     select 
-     pa_id,
-     pa_name , 
-     pa_description 
-     from 
-       plan_analytique 
-     order by pa_name');
-        $count_max=count($plan);
-
-        $a_row=$cn->get_array('select ke_id,ke_row,ke_percent from 
key_distribution_detail 
-         where
-         kd_id=$1 order by ke_row', array($this->key->getp('id')));
-
-        require_once NOALYSS_INCLUDE.'/template/anc_key_input.php';
-    }
-
-    /**
-     * @brief verify that data are ok
-     * @param type $p_array
-     */
-    function verify($p_array)
-    {
-        $a_percent=$p_array['percent'];
-        if (count($a_percent)==0)
-        {
-            throw new Exception(_('Aucune répartition'));
-        }
-        $tot_percent=0;
-        bcscale(4);
-        for ($i=0; $i<count($a_percent); $i++)
-        {
-            $tot_percent=bcadd($tot_percent, $a_percent[$i]);
-        }
-        if ($tot_percent >100)
-        {
-            throw new Exception(_('Le total ne vaut pas 100, total calculé = 
').$tot_percent);
-        }
-        if ($p_array['name_key']=='') {
-            throw new Exception (_('Le nom ne peut être vide'));
-        }
-    }
-
-    /**
-     * @brief save the data of a repartition key.
-     * @param received an array
-     * index :
-     *   - key_id : key_distribution.kd_id
-     *   - row : array of key_distribution.ke_id (row
-     *   - pa : array of plan_analytic.pa_id (column)
-     *   - po_id : double array, 
-     *              first index is the row
-     *              second  index is the first plan, the second the second 
plan...(column)
-     *   - percent array, one per row
-     *   - jrn : array of available ledgers
-     * @note  if po_id == -1 then it is replaced by null, this why the pa_id 
is needed : to identify
-     *  the column
-     * @verbatim
-     
-        'key_id' => string '1' (length=1)
-        'row' => 
-          array
-            0 => string '1' (length=1)
-            1 => string '2' (length=1)
-            2 => string '3' (length=1)
-        'pa' => 
-          array
-            0 => string '1' (length=1)
-            1 => string '2' (length=1)
-        'po_id' => 
-          array
-            0 => 
-              array
-                0 => string '1' (length=1)
-                1 => string '8' (length=1)
-            1 => 
-              array
-                0 => string '2' (length=1)
-                1 => string '-1' (length=2)
-            2 => 
-              array
-                0 => string '3' (length=1)
-                1 => string '8' (length=1)
-        'percent' => 
-          array
-            0 => string '50.0000' (length=7)
-            1 => string '20.0000' (length=7)
-            2 => string '30.0000' (length=7)
-        'jrn' => 
-          array
-            0 => string '3' (length=1)
-            1 => string '2' (length=1)
-      @endverbatim
-     * 
-     */
-    function save($p_array)
-    {
-        global $cn;
-        $this->verify($p_array);
-        $cn->start();
-        // for each row
-        $a_row=$p_array['row'];
-        $a_ledger=HtmlInput::default_value("jrn",array(),$p_array);
-        $a_percent=$p_array['percent'];
-        $a_po_id=$p_array['po_id'];
-        $a_plan=$p_array['pa'];
-        try
-        {
-            $this->key->setp('name',$p_array['name_key']);
-            $this->key->setp('description',$p_array['description_key']);
-            $this->key->save();
-            for ($i=0; $i<count($a_row); $i++)
-            {
-                //save key_distribution_row
-                $key_row=new Anc_Key_Detail_SQL($cn);
-                $key_row->setp('id', $a_row[$i]);
-                $key_row->setp('key', $this->key->getp('id'));
-                $key_row->setp('row', $i+1);
-                $key_row->setp('percent', $a_percent[$i]);
-                $key_row->save();
-                //
-                // Save each activity + percent
-                $cn->exec_sql('delete from key_distribution_activity where 
ke_id=$1', array($key_row->getp('id')));
-
-                // Don't save row with 0 %
-                if ($a_percent[$i]==0)
-                {
-                    $key_row->delete();
-                    continue;
-                }
-                for ($j=0; $j<count($a_po_id[$i]); $j++)
-                {
-                    $activity=new Anc_Key_Activity_SQL($cn);
-                    $activity->setp('detail', $key_row->ke_id);
-                    $value=($a_po_id[$i][$j]==-1)?null:$a_po_id[$i][$j];
-                    $activity->setp('activity', $value);
-                    $activity->setp('plan',$a_plan[$j]);
-                    $activity->save();
-                }
-            }
-            // delete all from key_distribution_ledger
-            $cn->exec_sql('delete from key_distribution_ledger where 
kd_id=$1', array($this->key->getp('id')));
-            for ($k=0; $k<count($a_ledger); $k++)
-            {
-                $ledger=new Anc_Key_Ledger_SQL($cn);
-                $ledger->kd_id=$this->key->getp('id');
-                $ledger->jrn_def_id=$a_ledger[$k];
-                $ledger->save();
-            }
-            
-            $cn->commit();
-        }
-        catch (Exception $e)
-        {
-            if ( DEBUG ) { echo $e->getTraceAsString(); var_dump($_POST);} 
else { echo _('erreur');}
-            $cn->rollback();
-        }
-    }
-    /**
-     * @brief Call the Anc_Operation::display_form_plan with the right amounts.
-     * This function compute the array and amount to pass to the 
Anc_Operation::display_form_plan
-     * and replace the current table of activity with the value computed from 
the key.
-     * 
-     * @global $cn database connection
-     * @param $p_target Table to be replaced
-     * @param $p_amount amount to distribute among activities
-     */
-    function fill_table($p_target,$p_amount)
-    {
-        global $cn;
-        /* number is the index of the plan, he's computed from p_target */
-        $number=preg_replace('/det[0-9]/', '', $p_target);
-        $number=str_replace('t', '', $number);
-        $number=str_replace('popup', '', $number);
-        
-        $op[$number]=$p_amount;
-        $array['op']=$op;
-        $a_plan=$cn->get_array('select pa_id from plan_analytique order by 
pa_id');
-        for ($i=0;$i < count($a_plan);$i++)
-        {
-            $array['pa_id'][$i]=$a_plan[$i]['pa_id'];
-        }
-        
-        $a_poste=$cn->get_array('select po_id,ke_percent,pa_id,ke_row
-                 from key_distribution_activity 
-                 join key_distribution_detail using (ke_id)  
-                 where
-                 kd_id=$1
-                 order by ke_row,pa_id',
-                 array($this->key->getp('id')));
-
-        for ($i=0;$i< count($a_poste);$i++)
-        {
-            
$hplan[$number][$i]=($a_poste[$i]['po_id']==null)?-1:$a_poste[$i]['po_id'];
-        }
-        $array['hplan']=$hplan;
-        
-         $a_amount=$cn->get_array("select distinct ke_row,ke_percent 
-                 from key_distribution_activity 
-                 join key_distribution_detail using (ke_id) 
-                 where
-                    kd_id=$1
-                    and pa_id=$2
-                 order by ke_row",
-                 array($this->key->getp('id'),$a_plan[0]['pa_id']));
-         bcscale(2);
-        for ($i=0;$i< count($a_amount);$i++)
-        {
-            $val[$number][$i]=bcmul($p_amount,$a_amount[$i]['ke_percent'])/100;
-        }
-        $array['val']=$val;
-               
-        $anc_operation=new Anc_Operation($cn);
-        echo $anc_operation->display_form_plan($array, 1, 1, $number, 
$p_amount,'',false);
-        
-    }
-    /**
-     address@hidden show a form for adding a key + button to display it
-     * 
-     */
-    static function key_add()
-    {
-        $key=new Anc_Key();
-        $key->key->setp('name',_('Nouvelle clef'));
-        $key->key->setp('description',_('Description de la nouvelle clef'));
-        ?>
-<input type="button" class="smallbutton" value="<?php echo  _('Ajout')?>" 
onclick="$('key_add_div_id').show()">
-<div id="key_add_div_id" style="display: none">
-<?php
-        $key->input();
-        echo '</div>';
-        
-    }
-    /**
-     address@hidden delete the distribution key 
-     */
-    function delete ()
-    {
-        $this->key->delete();
-    }
-}
diff --git a/include/class_anc_key_sql.php b/include/class_anc_key_sql.php
deleted file mode 100644
index 07be1ed..0000000
--- a/include/class_anc_key_sql.php
+++ /dev/null
@@ -1,159 +0,0 @@
-<?php
-
-/*
- * Copyright (C) 2014 Dany De Bontridder <address@hidden>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
- */
-
-/**
- * @file
- * @brief Class to manage distribution keys for SQL.  
- *
- */
-require_once NOALYSS_INCLUDE.'/class_noalyss_sql.php';
-
-
-/**
- * @brief Manage the table key_distribution.
- */
-class Anc_Key_SQL extends Noalyss_SQL
-{
-
-    function __construct($p_cn, $p_id = -1)
-    {
-        $this->table = "public.key_distribution";
-        $this->primary_key = "kd_id";
-
-        $this->name = array(
-            "id" => "kd_id",
-            "name"=>"kd_name",
-            "description"=>"kd_description"
-        );
-
-        $this->type = array(
-            "kd_id" => "numeric",
-            "kd_name" => "text",
-            "kd_description" => "text"
-        );
-
-        $this->default = array(
-            "kd_id" => "auto"
-        );
-       // PHPUNIT seems to have a problem with this line
-       //global $cn;
-
-        parent::__construct($p_cn, $p_id);
-    }
-
-}
-/**
- * @brief manage table key_distribution_ledger
- */
-class Anc_Key_Ledger_SQL extends Noalyss_SQL
-{
-       function __construct(&$p_cn, $p_id = -1)
-    {
-        $this->table = "public.key_distribution_ledger";
-        $this->primary_key = "kl_id";
-
-        $this->name = array(
-            "id" => "kl_id",
-            "key"=>"kd_id",
-            "ledger"=>"jrn_def_id"
-        );
-
-        $this->type = array(
-            "kl_id" => "numeric",
-            "kd_id" => "numeric",
-            "jrn_def_id" => "numeric"
-        );
-
-        $this->default = array(
-            "kl_id" => "auto"
-        );
-        // PHPUNIT seems to have a problem with this line
-       //global $cn;
-
-        parent::__construct($p_cn, $p_id);
-    } 
-}
-/**
- * @brief manage table key_distribution_detail
- */
-class Anc_Key_Detail_SQL extends Noalyss_SQL
-{
-       function __construct(&$p_cn, $p_id = -1)
-    {
-          
-        $this->table = "public.key_distribution_detail";
-        $this->primary_key = "ke_id";
-
-        $this->name = array(
-            "id" => "ke_id",
-            "key"=>"kd_id",
-            "row"=>"ke_row",
-            "percent"=>"ke_percent"
-        );
-
-        $this->type = array(
-            "ke_id" => "numeric",
-            "kd_id" => "numeric",
-            "ke_row" => "numeric",
-            "ke_percent" => "numeric"
-        );
-
-        $this->default = array(
-            "ke_id" => "auto"
-        );
-       // PHPUNIT seems to have a problem with this line
-       //global $cn;
-       
-
-        parent::__construct($p_cn, $p_id);
-    } 
-}
-/**
- * @brief manage table key_distribution_activity
- */
-class Anc_Key_Activity_SQL extends Noalyss_SQL
-{
-       function __construct($p_cn, $p_id = -1)
-    {
-        $this->table = "public.key_distribution_activity";
-        $this->primary_key = "ka_id";
-
-        $this->name = array(
-            "id" => "ka_id",
-            "detail"=>"ke_id",
-            "activity"=>"po_id",
-            "plan"=>"pa_id"
-        );
-
-        $this->type = array(
-            "ka_id" => "numeric",
-            "ke_id" => "numeric",
-            "po_id" => "numeric",
-            "pa_id" => "numeric"
-           
-        );
-
-        $this->default = array(
-            "ka_id" => "auto"
-        );
-
-        parent::__construct($p_cn, $p_id);
-    } 
-}
\ No newline at end of file
diff --git a/include/class_anc_listing.php b/include/class_anc_listing.php
deleted file mode 100644
index 93c1a3f..0000000
--- a/include/class_anc_listing.php
+++ /dev/null
@@ -1,216 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief definition of Anc_Listing
- */
-
-require_once NOALYSS_INCLUDE.'/class_ihidden.php';
-require_once  NOALYSS_INCLUDE.'/class_anc_plan.php';
-require_once  NOALYSS_INCLUDE.'/class_anc_print.php';
-require_once  NOALYSS_INCLUDE.'/class_anc_operation.php';
-/*!
- * \brief manage the CA listing
- *
- * \return
- */
-
-class Anc_Listing extends Anc_Print
-{
-    function display_form($p_string="")
-    {
-        echo '<form method="get">';
-        $r=parent::display_form($p_string);
-        $r.=HtmlInput::submit('result', _('Rechercher'));
-        $r.= '</form>';
-        return $r;
-
-    }
-    /*!
-     * \brief complete the object with the data in $_REQUEST
-     */
-
-    function get_request()
-    {
-        parent::get_request();
-        $this->pa_id=(isset($_REQUEST['pa_id']))?$_REQUEST['pa_id']:"";
-    }
-    /*!
-     * \brief compute the html display
-     *
-     *
-     * \return string
-     */
-
-    function display_html()
-    {
-        $idx=0;
-        $r="";
-        //---Html
-        $array=$this->load();
-        if ( is_array($array) == false ||  empty($array) )
-        {
-            return 0;
-        }
-        $r.= '<table class="result" style="width=100%">';
-        $r.= '<tr>'.
-             '<th>'._('Date').'</th>'.
-             '<th>'._('Poste').'</th>'.
-             '<th>'._('Quick_code').'</th>'.
-             '<th>'._('Analytique').'</th>'.
-         th(_('Description')).
-             '<th>'._('libelle').'</th>'.
-             '<th>'._('Num.interne').'</th>'.
-             '<th>'._('Montant').'</th>'.
-             '<th>'._('D/C').'</th>'.
-             '</tr>';
-        foreach ( $array as $row )
-        {
-            $class=($idx%2==0)?'even':'odd';
-            $idx++;
-            $r.= '<tr class="'.$class.'">';
-           $detail=($row['jr_id'] != 
null)?HtmlInput::detail_op($row['jr_id'],$row['jr_internal']):'';
-           $post_detail=($row['j_poste'] != 
null)?HtmlInput::history_account($row['j_poste'],$row['j_poste']):'';
-           $card_detail=($row['f_id'] != 
null)?HtmlInput::history_card($row['f_id'],$row['qcode']):'';
-
-            $r.=
-                '<td>'.$row['oa_date'].'</td>'.
-             td($post_detail).
-             td($card_detail).
-             '<td>'.h($row['po_name']).'</td>'.
-             '<td>'.h($row['oa_description']).'</td>'.
-             td($row['jr_comment']).
-             '<td>'.$detail.'</td>'.
-             '<td class="num">'.nbm($row['oa_amount']).'</td>'.
-                '<td>'.(($row['oa_debit']=='f')?'CREDIT':'DEBIT').'</td>';
-            $r.= '</tr>';
-        }
-        $r.= '</table>';
-        return $r;
-    }
-    /*!
-     * \brief load the data from the database
-     *
-     * \return array
-     */
-    function load()
-    {
-        $op=new Anc_Operation ($this->db);
-        $op->pa_id=$this->pa_id;
-        
$array=$op->get_list($this->from,$this->to,$this->from_poste,$this->to_poste);
-        if (! $array ) 
-        {
-            $this->has_data=0;
-        }
-        else 
-        {
-            $this->has_data=count($array);
-        }
-        return $array;
-    }
-    /*!
-     * \brief Compute the csv export
-     * \return string with the csv
-     */
-
-    function display_csv()
-    {
-        
$array=$this->load($this->from,$this->to,$this->from_poste,$this->to_poste);
-        if ( empty($array) == true )
-        {
-            return $array;
-
-        }
-        $r="";
-        foreach ( $array as $row)
-        {
-            // the name and po_id
-            $r.=sprintf('"%s";',$row['oa_date']);
-            $r.=sprintf('"%s";',$row['j_poste']);
-            $r.=sprintf('"%s";',$row['qcode']);
-            $r.=sprintf('"%s";',$row['po_name']);
-            $r.=sprintf('"%s";',$row['oa_description']);
-            $r.=sprintf('"%s";',$row['oa_description']);
-
-            $r.=sprintf("%12.2f;",$row['oa_amount']);
-            $r.=sprintf("'%s'",(($row['oa_debit']=='f')?'CREDIT':'DEBIT'));
-            $r.="\r\n";
-        }
-        return $r;
-
-    }
-
-    /*!
-     * \brief show the export button to pdf and CSV
-     * \param $p_string string containing some HTML tag as hidden field
-     * \param
-     * \param
-     *
-     *
-     * \return string containing the html code
-     */
-    function show_button($p_string='')
-    {
-        $r="";
-        $submit=HtmlInput::submit('','');
-        $hidden=new IHidden();
-        /* for the export in PDF
-         * Not yet needed, the html print should be enough
-        $r.= '<form method="GET" action="ca_list_pdf.php" 
style="display:inline">';
-        $r.= $p_string;
-        $r.= dossier::hidden();
-        $r.= $hidden->input("to",$this->to);
-        $r.= $hidden->input("from",$this->from);
-        $r.= $hidden->input("pa_id",$this->pa_id);
-        $r.= $hidden->input("from_poste",$this->from_poste);
-        $r.= $hidden->input("to_poste",$this->to_poste);
-        $r.=HtmlInput::submit('bt_pdf',"Export en PDF");
-        $r.= '</form>';
-        */
-
-        $r.= '<form method="GET" action="export.php"  style="display:inline">';
-        $r.= HtmlInput::hidden("to",$this->to);
-        $r.= HtmlInput::hidden("from",$this->from);
-        $r.= HtmlInput::hidden("pa_id",$this->pa_id);
-        $r.= HtmlInput::hidden("from_poste",$this->from_poste);
-        $r.= HtmlInput::hidden("to_poste",$this->to_poste);
-       $r.=HtmlInput::hidden('act','CSV:AncList');
-        $r.=HtmlInput::hidden('ac',$_REQUEST['ac']);
-        $r.= $p_string;
-        $r.= dossier::hidden();
-        $r.=HtmlInput::submit('bt_csv',"Export en CSV");
-        $r.= '</form>';
-        return $r;
-
-    }
-    /*!
-     * \brief debugging and test function for dev. only
-     * \param
-     * \param
-     * \param
-     *
-     *
-     * \return
-     */
-    static  function test_me()
-    {
-    }
-}
diff --git a/include/class_anc_operation.php b/include/class_anc_operation.php
deleted file mode 100644
index 20c90cc..0000000
--- a/include/class_anc_operation.php
+++ /dev/null
@@ -1,964 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- *\brief definition of Anc_Operation
- */
-require_once NOALYSS_INCLUDE.'/class_ibutton.php';
-require_once NOALYSS_INCLUDE.'/class_ihidden.php';
-require_once NOALYSS_INCLUDE.'/class_iselect.php';
-require_once NOALYSS_INCLUDE.'/class_itext.php';
-require_once NOALYSS_INCLUDE.'/class_anc_plan.php';
-require_once  NOALYSS_INCLUDE.'/user_common.php';
-
-/*! \brief this class is used to show the form for entering an
- *   operation only FOR analytic operation
- *   to save it, to display or to get a list from a certain period
- *
- */
-class Anc_Operation
-{
-    var $db;   /*!< database connection */
-    var $row;  /*!< array of row for one operation*/
-    var $list; /*!< array of all operation */
-    var $id;   /*!< = oa_id (one row) */
-    var $po_id;        /*!< poste analytique */
-    var $oa_amount;    /*!< amount for one row */
-    var $oa_description;       /*!< comment for one row */
-    var $oa_debit;     /*!< true for debit or false */
-    var $j_id;         /*!< foreign key to a jrnx operation
-                                      (or null if none */
-    var $oa_group;   /*!< group of operation  */
-    var $oa_date;         /*!< equal to j_date if j_id is not    null */
-    var $pa_id;        /*!< the plan analytique id */
-    /**
-     * In the case, the amount comes from a ND VAT, the variable
-     * contents the jrnx.j_id of the source which was used to compute 
-     * the amount
-     */
-    var $oa_jrnx_id_source; 
-    /**
-     * @brief signed of the amount
-     */
-    var $oa_positive;
-    var $in_div; /*< name of the div if any, default empty string*/
-    /*!\brief constructor
-     *
-     */
-    function Anc_Operation ($p_cn,$p_id=0)
-    {
-        $this->db=$p_cn;
-        $this->id=$p_id;
-        $this->oa_jrnx_id_source=null;
-        $this->oa_positive='Y';
-        $this->has_data=0;
-        $this->in_div="";
-    }
-    /*!\brief add a row  to the table operation_analytique
-     * \note if $this->oa_group if 0 then a sequence id will be computed for
-     * the oa_group, if $this->j_id=0 then it will be null
-     *
-     */
-    function add($p_seq=0)
-    {
-
-        if ( $this->oa_group == 0)
-        {
-            $this->oa_group=$this->db->get_next_seq('s_oa_group');
-        }
-
-        if ( $this->j_id == 0 )
-        {
-            $this->j_id=null;
-        } else {
-            // must be the same side than the operation
-            if ( $this->oa_jrnx_id_source == null)
-            {
-                $side=$this->db->get_value('select j_debit from jrnx where 
j_id=$1',
-                    array($this->j_id));
-            } else 
-            {
-                $side=$this->db->get_value('select j_debit from jrnx where 
j_id=$1',
-                    array($this->oa_jrnx_id_source));
-            }
-            $this->oa_debit=$side;
-        }
-
-
-        // we don't save null operations
-        if ( $this->oa_amount == 0 || $this->po_id==-1)
-            return;
-        
-        if ( $this->oa_amount< 0) 
-        {
-            // if negatif must be oa_positive='N'
-            $this->oa_positive='N';
-            $this->oa_debit=($this->oa_debit=='t')?'f':'t';
-        }
-        
-        $oa_row=(isset($this->oa_row))?$this->oa_row:null;
-        $sql="insert into operation_analytique (
-             po_id, 
-             oa_amount,
-             oa_description,
-             oa_debit,
-             oa_group,
-             j_id,
-             oa_date,
-             oa_row,
-             oa_jrnx_id_source,
-             oa_positive
-             ) values ($1,$2,$3,$4,$5,$6,to_date($7,'DD.MM.YYYY'),$8,$9,$10)";
-
-        $this->db->exec_sql($sql,array(
-                $this->po_id, // 1
-                abs($this->oa_amount), //2
-                $this->oa_description, //3
-                $this->oa_debit, //4
-                $this->oa_group, //5
-                $this->j_id, //6
-                $this->oa_date, //7
-                $oa_row, //8
-                $this->oa_jrnx_id_source, //8
-                $this->oa_positive
-                ));
-
-    }
-    /*!\brief delete a row from the table operation_analytique
-     * \note be carefull : do not delete a row when we have a group
-     */
-    function delete()
-    {
-        $sql="delete from operation_analytique where oa_id=$1";
-
-        $this->db->exec_sql($sql,array($this->oa_id));
-    }
-
-    /*!\brief get a list of row from a certain periode
-     */
-    function get_list($p_from,$p_to,$p_from_poste="",$p_to_poste="")
-    {
-        $cond="";
-        $cond_poste="";
-
-        if ($p_from!="")
-            $cond="and (jr_date >= to_date('$p_from','DD.MM.YYYY')  or oa_date 
>= to_date('$p_from','DD.MM.YYYY') )";
-        if ( $p_to!="" )
-            $cond.="and (jr_date <=to_date('$p_to','DD.MM.YYYY') or  oa_date 
<=to_date('$p_to','DD.MM.YYYY')) ";
-
-        if ($p_from_poste != "" )
-            $cond_poste=" and upper(po_name) >= upper('".$p_from_poste."')";
-        if ($p_to_poste != "" )
-            $cond_poste.=" and upper(po_name) <= upper('".$p_to_poste."')";
-        $pa_id_cond="";
-        if ( isset ( $this->pa_id) && $this->pa_id !='')
-            $pa_id_cond= "pa_id=".$this->pa_id." and";
-       $sql="
-        
-       select oa_id,
-       po_name,
-       oa_description,
-       po_description,
-       oa_debit,
-       (case when jr_date is not null then to_char(jr_date,'DD.MM.YYYY') else 
to_char(oa_date,'DD.MM.YYYY') end )  as oa_date,
-       oa_amount,
-       oa_group,
-       j_id ,
-       jr_internal,
-       jr_id,
-       jr_comment,
-       j_poste,
-       jrnx.f_id,
-       ( select ad_value from fiche_Detail where f_id=jrnx.f_id and ad_id=23) 
as qcode,
-        jr_pj_number
-       from operation_analytique as B join poste_analytique using(po_id)
-       left join jrnx using (j_id)
-       left join jrn on  (j_grpt=jr_grpt_id)
-             where $pa_id_cond oa_amount <> 0.0 $cond $cond_poste
-       order by jr_date,oa_group,oa_debit desc,oa_id";
-
-        $RetSql=$this->db->exec_sql($sql);
-        $array=Database::fetch_all($RetSql);
-        return $array;
-    }
-
-    /*\brief show the HTML table for the operation
-     */
-    function html_table($p_from)
-    {
-        if ($p_from=="")
-        {
-            $from="";
-            $to="";
-        }
-        else
-        {
-            $p=new Periode($this->db);
-            list($from,$to)=$p->get_date_limit($p_from);
-        }
-
-        $array=$this->get_list($from,$to);
-        if ( empty($array)  )
-            return "Pas d'enregistrement trouv&eacute;";
-
-        // navigation_bar
-        $step=$_SESSION['g_pagesize'];
-        $page=(isset($_GET['offset']))?$_GET['page']:1;
-        $offset=(isset($_GET['offset']))?$_GET['offset']:0;
-        $bar=navigation_bar($offset+1,count($array),$step,$page);
-
-        if ( $step !=-1)
-            $view=array_splice($array,$offset,$step);
-        else
-            $view=$array;
-
-        $gDossier=dossier::id();
-        $ret="";
-        $ret.=$bar;
-
-        $count=0;
-        $group=0;
-        $oldgroup=0;
-        $oldjrid=0;
-
-        foreach ($view as $row)
-        {
-            $group=$row['oa_group'];
-            if ( $group !=$oldgroup )
-            {
-                if ( $oldgroup!=0 )
-                {
-
-                    $efface=new IButton();
-                    
$efface->javascript="anc_remove_operation(".$gDossier.",".$oldgroup.")";
-                    $efface->name="Efface";
-                    $efface->label="Efface";
-                    $ret.="<td>".$efface->input()."</td>";
-
-                    $this->oa_group=$oldgroup;
-                    $jr_id=$this->get_jrid();
-
-                    if ( $jr_id != 0)
-                    {
-                        // get the old jr_id
-                        $detail=new IButton();
-                        $detail->javascript="viewOperation($jr_id,$gDossier)";
-                        $detail->name="Detail";
-                        $detail->label="Detail";
-                        $ret.="<td>".$detail->input()."</td>";
-                    }
-                    $ret.='</table>';
-
-                }
-                $ret.='<table id="'.$row['oa_group'].'" class="result">';
-
-                $ret.="<tr class=\"highlight\">".
-                      td($row['oa_date']).
-                      "<td>".
-                      HtmlInput::detail_op($row['jr_id'],  
h($row['oa_description']." ".$row['jr_pj_number'])).
-                      "</td>".
-                        td();
-
-                $ret.="<td>".
-                      "Groupe id : ".$row['oa_group'].
-                      "</td>".
-
-                $oldgroup=$group;
-
-            }
-
-            $class=($count%2==0)?"odd":"even";
-            $count++;
-            $cred= ( $row['oa_debit'] == 'f')?"CREDIT":"DEBIT";
-            $ret.="<tr class=\"$class\">";
-            $ret.= "<td>".
-                   h($row['po_name']).
-                   "</td>";
-
-           $ret.=td(h($row['po_description']));
-
-            $ret.='<td class="num">'.  nbm($row['oa_amount']).
-                  "</td>".
-                  "<td>".
-                  $cred.
-                  "</td>".
-
-                  "</tr>";
-        }
-
-
-        $efface=new IButton();
-        $efface->javascript="anc_remove_operation("."$gDossier,".$oldgroup.")";
-        $efface->name="Efface";
-        $efface->label="Efface";
-        $ret.="<td>".$efface->input()."</td>";
-        // get the old jr_id
-        $this->oa_group=$oldgroup;
-        $jr_id=$this->get_jrid();
-        if ( $jr_id != 0 )
-        {
-            $detail=new IButton();
-            $detail->javascript="modifyOperation($jr_id,'".$gDossier."')";
-            $detail->name="Detail";
-            $detail->label="Detail";
-            $ret.="<td>".$detail->input()."</td>";
-        }
-        $ret.='</table>';
-        $ret.=$bar;
-        return $ret;
-    }
-    /*!\brief retrieve an operation thanks a jrnx.j_id
-     * \param the jrnx.j_id
-     * \return null if nothing is found other an array
-     */
-    function get_by_jid($p_jid)
-    {
-        $array=array();
-        $a_plan=$this->db->get_array('select pa_id from plan_analytique order 
by pa_id');
-        $res=array();
-        /*
-         * For one oa_row
-         */
-        $a_rowcount=$this->db->get_array("select distinct  oa_row "
-                ." from operation_analytique where j_id=$1 order by oa_row", 
array($p_jid));
-
-        for ($i=0; $i<count($a_rowcount); $i++)
-        {
-            /*
-             * Get one row as template for filling the missing 
-             */
-            $a_existing=$this->db->get_array('
-                    select distinct oa_id,
-                     po_id,
-                     oa_amount,
-                     oa_description,
-                     oa_debit,
-                     j_id,
-                     oa_group,
-                     oa_date,
-                     pa_id,
-                     oa_row,
-                     oa_positive
-                     from operation_analytique join poste_analytique using 
(po_id)
-                     where
-                     j_id=$1 and oa_row = $2 
-                     order by j_id,oa_row', 
-                    array($p_jid, $a_rowcount[$i]['oa_row']));
-            
-            // the first row we found will be the template
-            $template=$a_existing[0];
-            /*
-             * For each plan
-             */
-            for ($j=0; $j<count($a_plan); $j++)
-            {
-                /*
-                 * Fetch the row with this pa_id, oa_row, max : 1 row
-                 */
-                $a_fetch=$this->db->get_array('
-                    select distinct oa_id,
-                     po_id,
-                     oa_amount,
-                     oa_description,
-                     oa_debit,
-                     j_id,
-                     oa_group,
-                     oa_date,
-                     pa_id,
-                     oa_row,
-                     oa_positive
-                     from operation_analytique join poste_analytique using 
(po_id)
-                     where
-                     j_id=$1 and oa_row = $2  and pa_id=$3', array($p_jid,
-                    $a_rowcount[$i]['oa_row'],
-                    $a_plan[$j]['pa_id']
-                        )
-                );
-                if (count($a_fetch)==0)
-                {
-                    $a_fetch=$template;
-                    $a_fetch['pa_id']=$a_plan[$j]['pa_id'];
-                    $a_fetch['po_id']=-1;
-                    $a_fetch['oa_id']='';
-                    $res[]=$a_fetch;
-                }
-                else
-                if (count($a_fetch)==1)
-                {
-                    $res[]=$a_fetch[0];
-                }
-            }
-        }
-
-        foreach ($res as $row)
-        {
-            $a=new Anc_Operation($this->db);
-            foreach ($row as $attr=> $value)
-            {
-                $a->$attr=$row[$attr];
-            }
-            $array[]=clone $a;
-        }
-
-
-        return $array;
-    }
-
-    /*!\brief modify an op from modify_op.php
-     *
-     */
-    function update_from_jrnx($p_po_id)
-    {
-        $a=$this->get_by_jid($this->j_id);
-        if ( $a == null )
-        {
-            // retrieve data from jrnx
-            $sql="select jr_date,j_montant,j_debit from jrnx ".
-                 " join jrn on (jr_grpt_id = j_grpt) ".
-                 "where j_id=".$this->j_id;
-            $res=$this->db->exec_sql($sql);
-            if (Database::num_row($res) == 0 ) return;
-            $row=Database::fetch_array($res,0);
-            $this->oa_amount=$row['j_amount'];
-            $this->oa_date=$row['jr_date'];
-            $this->oa_debit=$row['j_debit'];
-            $this->oa_description=$row['jr_comment'];
-            $this->add();
-        }
-        else
-        {
-            foreach ($a as $row )
-            {
-                if ( $row->pa_id == $this->pa_id )
-                {
-                    $row->po_id=$p_po_id;
-                    $row->update();
-                }
-            }
-        }
-    }
-    /*!\brief retrieve the jr_id thanks the oa_group */
-    function get_jrid()
-    {
-        $sql="select distinct jr_id from jrn join jrnx on (j_grpt=jr_grpt_id) 
join operation_analytique using (j_id) where j_id is not null and 
oa_group=".$this->oa_group;
-        $res=$this->db->exec_sql($sql);
-        if ( Database::num_row($res) == 0 ) return 0;
-        $ret=Database::fetch_all($res);
-        return $ret[0]['jr_id'];
-    }
-    /*\brief this function get the balance for a certain period
-     *\param $p_from from date (accountancy period)
-     *\param $p_to to dat  (accountancy period)
-     *\param  $p_plan_id the plan id
-     */
-    function get_balance($p_from,$p_to,$p_plan_id)
-    {
-        // for the operation connected to jrnx
-        $cond=sql_filter_per($this->db,$p_from,$p_to,'p_id','j_date');
-        $sql="select oa_id, po_id, oa_amount, oa_debit, j_date from jrnx join 
operation_analytique using (j_id)
-             join poste_analytique using (po_id)
-             where
-             $cond and j_id is not null and pa_id=$p_plan_id";
-
-        // OD
-        $cond=sql_filter_per($this->db,$p_from,$p_to,'p_id','oa_date');
-        $sql="union select oa_id, po_id, oa_amount, oa_debit,oa_date from
-             operation_analytique
-             join poste_analytique using (po_id)
-             where j_id is null and
-             $cond and pa_id=$p_plan_id ";
-        try
-        {
-            $res=$this->db->exec_sql($sql);
-            $array=Database::fetch_all($res);
-        }
-        catch (Exception $e)
-        {
-            var_dump($e);
-        }
-    }
-    /*!\brief display the form for PA
-     *\param $p_array contains POST (or GET) data (val[] hplan[][] op[])
-     * \param $p_null = 1 if PA optional otherwise 0 mandatory
-     * \param $p_mode == form 1 ==> read/write otherwise 0==>readonly
-     * \param $p_seq number of the row
-     * \param $p_amount amount
-     * \param $p_id operation is detailled in a HTML popup, if several
-     *  are opened, the tableid MUST be different. So we need to use a new 
parameter
-     * \param $p_add_button true, show the button, false don't display them
-     * \see save_form_plan
-    @note
-    - op is an array containing the line number
-    - pa_id is an array of the existing array
-    - hplan is an array of the POSTE ANALYTIQUE id used, the size of hplan 
from 0 to x,
-    x can be bigger than the number of plan id
-    - val contains the amount by row inside the table. One operation (j_id) 
you can have several rows
-    @code
-    0 =>
-      array
-        'op' => int 200
-    'pa_id' =>
-      array
-        0 => string '14' (length=2)
-        1 => string '15' (length=2)
-    'hplan' =>
-      array
-        1 =>
-          array
-            0 => string '25' (length=2)
-            1 => string '26' (length=2)
-    'val' =>
-      array
-        1 =>
-          array
-            0 => string '100.0000' (length=8)
-
-    @endcode
-     */
-    function 
display_form_plan($p_array,$p_null,$p_mode,$p_seq,$p_amount,$p_id='',$p_add_button=true)
-    {
-        if ( $p_array != null)
-            extract ($p_array);
-        $result="";
-        $plan=new Anc_Plan($this->db);
-        $a_plan=$plan->get_list(" order by pa_id ");
-        if ( empty ($a_plan) ) return "";
-        $table_id="t".$p_seq;
-        $hidden=new IHidden();
-
-               $readonly=($p_mode==1)?false:true;
-
-        $result.=$hidden->input('amount_'.$table_id,$p_amount);
-        if ( $p_mode==1 )
-            $result.='<table id="'.$p_id.$table_id.'">';
-        else
-            $result.='<table>';
-        $result.="<tr>".$plan->header()."<th>montant</th></tr>";
-
-        /* compute the number of rows */
-        $nb_row=(isset($val[$p_seq]))?count($val[$p_seq]):1;
-        $count=0;
-
-        $remain=abs($p_amount);
-        $ctrl_remain="remain".$this->in_div.$table_id;
-
-        for ( $i=0; $i < $nb_row;$i++)
-        {
-            $result.='<tr>';
-
-            foreach ($a_plan as $r_plan)
-            {
-
-                $array=$this->db->make_array(
-                           "select po_id as value,".
-                           " html_quote(po_name) as label from 
poste_analytique ".
-                           " where pa_id = ".$r_plan['id'].
-                           " order by po_name",$p_null);
-                $select =new ISelect("hplan[".$p_seq."][]",$array);
-                $select->table=0;
-                // view only or editables
-                if (  $p_mode==1 )
-                {
-                    // editable
-                    $select->readonly=false;
-                    if ( isset($hplan) && isset($hplan[$p_seq][$count]) ){
-                        $select->selected=$hplan[$p_seq][$count];
-
-                                       }
-                }
-                else
-                {
-                                       if ( isset($hplan) && 
isset($hplan[$p_seq][$count]) ){
-                        $select->selected=$hplan[$p_seq][$count];
-                                       }
-                    // view only
-                    $select->readOnly=true;
-                }
-                if ($p_mode==1)
-                    $result.='<td>'.$select->input().'</td>';
-                else
-                    $result.='<td>'.$select->display().'</td>';
-                $count++;
-
-
-            }
-            $value=new INum();
-           
$value->javascript='onchange="format_number(this);anc_refresh_remain(\''.$this->in_div.$table_id.'\',\''.$p_seq.'\')"';
-            $value->name="val[".$p_seq."][]";
-            $value->size=6;
-            
$value->value=(isset($val[$p_seq][$i]))?$val[$p_seq][$i]:abs($p_amount);
-            $value->readOnly=($p_mode==1)?false:true;
-            $remain=bcsub($remain,$value->value);
-            $result.='<td>'.$value->input().'</td>';
-
-            $result.="</tr>";
-        }
-
-        $result.="</table>";
-
-        if ($p_add_button && $p_mode == 1)
-        {
-            $style_remain=($remain==0)?'style="color:green"':' 
style="color:red"';
-            $result.=" Reste à imputer =  ".
-                     '<span class="remain" '.$style_remain.' 
id="'.$ctrl_remain.'">'.
-                            $remain.'</span>';
-            // add a button to add a row
-            $button=new IButton();
-            $button->javascript="add_row('".$p_id."$table_id',$p_seq);";
-            $button->name="js".$p_id.$p_seq;
-            $button->label=_("Nouvelle ligne");
-
-            $result.="<br>".$button->input();
-            /**
-             * Add a button for distribution key
-             * 
-             */
-            $ledger=HtmlInput::default_value_post("p_jrn", 0);
-            if ($ledger==0) {
-                $ledger=$this->db->get_value('select j_jrn_def from jrnx where 
j_id=$1',array($this->j_id));
-            }
-            $gDossier=Dossier::id();
-            $button_key=new IButton();
-            
$button_key->javascript="anc_key_choice(".$gDossier.",'".$p_id."$table_id',$p_amount,'".$ledger."');";
-            $button_key->name="js".$p_id.$p_seq;
-            $button_key->label=_("Clef");
-            $result .= $button_key->input();
-
-        }
-
-        return $result;
-    }
-    /**
-     * Save the ND VAT with prorata
-     * 
-     * @param $p_array usually $_POST
-     * @param $p_item item of the form
-     * @param $p_j_id jrnx.j_id concerned writing
-     * @param $p_nd amount nd vat
-     * @see Anc_Operation::save_form_plan_vat_nd
-     * @return type
-     */
-    function save_form_plan_vat_nd($p_array,$p_item,$p_j_id,$p_nd)
-    {
-        bcscale(4);
-        extract($p_array);
-       if (! isset ($hplan) ) return;
-        
-        if ( ! isset(${'amount_t'.$p_item}) )
-            throw new Exception ('amount not set');
-        
-        $tot=0;
-        /* variable for in array
-           pa_id array of existing pa_id
-           hplan double array with the pa_id (column)
-           val double array by row with amount
-           op contains sequence
-           p_item is used to identify what op is concerned
-        */
-        /* echo "j_id = $j_id p_item = $p_item 
hplan=".var_export($hplan[$p_item],true)." val = 
".var_export($val[$p_item],true).'<br>'; */
-        /* for each row */
-        //   for ($i=0;$i<count($val[$p_item]);$i++) {
-        $idx_pa_id=0;
-        $row=0;
-        $a_Anc_Operation=array();
-        // foreach col PA
-        for ($e=0;$e<count($hplan[$p_item]);$e++)
-        {
-            if ( $idx_pa_id == count($pa_id))
-            {
-                $idx_pa_id=0;
-                $row++;
-            }
-            if ($hplan[$p_item][$e] != -1 && $val[$p_item][$row] != '')
-            {
-                $op=new Anc_Operation($this->db);
-                $op->po_id=$hplan[$p_item][$e];
-                $op->oa_group=$this->oa_group;
-                $op->j_id=$p_j_id;
-                $ratio=bcdiv($val[$p_item][$row],${"amount_t".$p_item});
-                $amount=  bcmul($p_nd, $ratio);
-                $op->oa_amount=round($amount,2);
-                $op->oa_debit=$this->oa_debit;
-                $op->oa_date=$this->oa_date;
-
-                $op->oa_description=$this->oa_description;
-                $op->oa_row=$row;
-                $op->oa_jrnx_id_source=$this->oa_jrnx_id_source;
-                $a_Anc_Operation[]=clone $op;
-            }
-            $idx_pa_id++;
-        }
-        $nb_op=count($a_Anc_Operation);
-        bcscale(2);
-        for ($i=0;$i<$nb_op;$i++)
-        {
-            $tot=bcadd($tot,$a_Anc_Operation[$i]->oa_amount);
-        }
-        if ( $tot != $p_nd )
-        {
-            $diff=  bcsub($tot, $p_nd);
-            
$a_Anc_Operation[0]->oa_amount=bcsub($a_Anc_Operation[0]->oa_amount,$diff);
-        }
-        for ($i=0;$i<$nb_op;$i++)
-        {
-            $a_Anc_Operation[$i]->add();
-        }
-    }
-    /*!\brief it called for each item, the data are taken from $p_array
-     *  data and set before in this.
-     * \param $p_item if the item nb for each item (purchase or selling
-     *  merchandise)
-     * \param $p_array structure
-     * \verbatim
-      nb_tA A is the number of the item it contains the number of
-              rows of CA for this card
-      valAlR amount for the CA (item A row R)
-      ta_AoCrow_R contains the value of the pa_id and po_id for this
-                  row with the form pa_id_po_id %d_%d
-     *\endverbatim
-     * \attention The idea is one j_id matches several oa_id,
-     *  serveral data are set before the call :
-     *   -j_id
-     *   -oa_debit
-     *   -oa_group
-     *   -oa_date
-     *   -oa_description
-     *
-     */
-    function save_form_plan($p_array,$p_item,$p_j_id)
-    {
-        extract($p_array);
-       if (! isset ($hplan) ) return;
-        /* variable for in array
-           pa_id array of existing pa_id
-           hplan double array with the pa_id (column)
-           val double array by row with amount
-           op contains sequence
-           p_item is used to identify what op is concerned
-        */
-        /* echo "j_id = $j_id p_item = $p_item 
hplan=".var_export($hplan[$p_item],true)." val = 
".var_export($val[$p_item],true).'<br>'; */
-        /* for each row */
-        //   for ($i=0;$i<count($val[$p_item]);$i++) {
-        $idx_pa_id=0;
-        $row=0;
-        // foreach col PA
-        for ($e=0;$e<count($hplan[$p_item]);$e++)
-        {
-            if ( $idx_pa_id == count($pa_id))
-            {
-                $idx_pa_id=0;
-                $row++;
-            }
-            if ($hplan[$p_item][$e] != -1 && $val[$p_item][$row] != '')
-            {
-                $op=new Anc_Operation($this->db);
-                $op->po_id=$hplan[$p_item][$e];
-                $op->oa_group=$this->oa_group;
-                $op->j_id=$p_j_id;
-                $op->oa_amount=$val[$p_item][$row];
-                $op->oa_debit=$this->oa_debit;
-                $op->oa_date=$this->oa_date;
-
-                $op->oa_description=$this->oa_description;
-                $op->oa_row=$row;
-                $op->add();
-            }
-            $idx_pa_id++;
-        }
-        // }
-    }
-
-    /**
-    address@hidden save a whole form from a update box
-    address@hidden $p_array  for ALL j_id
-    address@hidden
-    address@hidden
-    address@hidden save_form_plan to_request
-    @code
-
-    @endcode
-    */
-    function save_update_form($p_array)
-    {
-        extract($p_array);
-        for ($i = 0; $i < count($op); $i++)
-        {
-            /* clean operation_analytique */
-            $this->db->exec_sql('delete from operation_analytique where 
j_id=$1', array($op[$i]));
-
-            /* get missing data for adding */
-            $a_missing = $this->db->get_array("select 
to_char(jr_date,'DD.MM.YYYY') 
-                    as mdate,j_montant,j_debit,jr_comment ,j_poste
-                    from jrnx join jrn on (j_grpt=jr_grpt_id) where j_id=$1", 
array($op[$i]));
-            $missing = $a_missing[0];
-           
-            $this->oa_description = $missing['jr_comment'];
-            $this->j_id = $op[$i];
-            $group = $this->db->get_next_seq("s_oa_group"); /* for analytic */
-            $this->oa_group = $group;
-            $this->oa_date = $missing['mdate'];
-            $this->save_form_plan($p_array, $i, $op[$i]);
-            
-            // There is ND VAT amount
-            $a_nd = $this->db->get_array('select j_id from operation_analytique
-                where oa_jrnx_id_source=$1', array($op[$i]));
-            if (count($a_nd) > 0)
-            {
-                // for each ND VAT amount
-                for ($e=0;$e<count($a_nd);$e++)
-                {
-                    $this->db->exec_sql('delete from operation_analytique 
where j_id=$1', array($a_nd[$e]['j_id']));
-                    /* get missing data for adding */
-                    $a_missing_vat = $this->db->get_array("select 
to_char(jr_date,'DD.MM.YYYY') as mdate,j_montant,j_debit,jr_comment from jrnx 
join jrn on (j_grpt=jr_grpt_id) where j_id=$1", array($a_nd[$e]['j_id']));
-                    $missing_vat = $a_missing_vat[0];
-                    $this->oa_debit = 't';
-                    $this->oa_description = $missing_vat['jr_comment'];
-                    $this->j_id = $op[$i];
-                    $group = $this->db->get_next_seq("s_oa_group"); /* for 
analytic */
-                    $this->oa_group = $group;
-                    $this->oa_date = $missing_vat['mdate'];
-                    $this->oa_jrnx_id_source=$op[$i];
-                    $p_array['amount_t'.$i]=$missing['j_montant'];
-                    $this->save_form_plan_vat_nd($p_array, $i, 
$a_nd[$e]['j_id'],$missing_vat['j_montant']);
-                }
-            }
-        }
-    }
-
-    /*\brief transform a array of operation into a array usage by
-     *display_form_plan & save_form_plan
-     *\param $p_array array of operation
-     *\param $p_line line
-     *\return an array complying with \see save_form_plan
-     */
-    function to_request ($p_array,$p_line)
-    {
-        $result=array();
-        $result[]=array('op'=>$this->j_id);
-        $pa_id=array();
-
-        /* First add the pa_id */
-        for ($i=0;$i < count($p_array);$i++)
-        {
-            if ( in_array($p_array[$i]->pa_id,$pa_id)==false)
-                $pa_id[]=$p_array[$i]->pa_id;
-        }
-        $result['pa_id']=$pa_id;
-
-        /* add the hplan */
-        $seq=0;
-        for ($i=0;$i < count($p_array);$i++)
-        {
-            $hplan[$p_line][$i]=$p_array[$i]->po_id;
-        }
-        $result['hplan']=$hplan;
-        /* Add the amount */
-        $idx_pa=0;
-        $jrn_def=$this->db->get_value('select jrn_def_type from jrnx join 
jrn_def on (j_jrn_def=jrn_def_id) where j_id=$1',array($this->j_id));
-        for ($i=0;$i < count($p_array);$i++)
-        {
-            
-            /*
-             * For the bank, negatif are always on the debit and positif on 
the credit
-             */
-            if ( $jrn_def != 'FIN')
-            {
-                
$val[$p_line][$p_array[$i]->oa_row]=($p_array[$i]->oa_positive=='Y')?$p_array[$i]->oa_amount:($p_array[$i]->oa_amount*(-1));
-            }
-            else
-            {
-                $val[$p_line][$p_array[$i]->oa_row]=$p_array[$i]->oa_amount;
-            }
-        }
-        $result['val']=$val;
-        return $result;
-    }
-    /*!
-     * \brief delete from operation_analytique
-     * \param $p_jid the operation_analytique.j_id field
-     *
-     * \return none
-     */
-    function delete_by_jid($p_jid)
-    {
-        $sql="delete from operation_analytique where j_id=$p_jid";
-        $this->db->exec_sql($sql);
-    }
-    /*\brief Display a table with analytic accounting in
-     *       detail of operation
-     address@hidden $this->j_id must be set
-     *\param $p_mode 0 = readonly or 1=writable
-     *\param $p_amount amount
-     *\param $p_id unique id
-     address@hidden display_form_plan
-     *\return string to display
-     */
-    function display_table($p_mode,$p_amount,$p_id)
-    {
-        static $seq=-1;                /* first seq == 0 */
-        $seq++;
-
-        $array=$this->get_by_jid($this->j_id) ;
-        if ( $array != null )
-        {
-            $request=$this->to_request($array,$seq);
-            return 
"<td>".$this->display_form_plan($request,1,$p_mode,$seq,$p_amount,$p_id)."</td>";
-        }
-        else
-        {
-            return 
'<td>'.$this->display_form_plan(null,1,$p_mode,$seq,$p_amount,$p_id)."</TD>";
-        }
-        return "";
-
-    }
-///////////////////////////////////////////////////////////////////////////
-// TEST
-///////////////////////////////////////////////////////////////////////////
-    /*\brief test the class
-     *\param
-     *\param
-     *\return
-     */
-    function test_me()
-    {
-        $cn=new Database(dossier::id());
-        $anco=new Anc_Operation($cn);
-        $j_id=200;
-        $anco->j_id=$j_id;
-        $array=$anco->get_by_jid($j_id);
-        $a=$anco->to_request($array,1);
-        echo '<form>';
-        echo dossier::hidden();
-        echo HtmlInput::hidden('j_id',$j_id);
-        echo HtmlInput::hidden('test_select',$_REQUEST['test_select']);
-        echo $anco->display_table(1,15002,0);
-        echo '<input type="submit" name="save">';
-        echo '</form>';
-        if ( isset($_REQUEST['save']))
-        {
-            echo "to_save";
-            var_dump($_REQUEST);
-        }
-        var_dump($a);
-
-    }
-
-}
diff --git a/include/class_anc_plan.php b/include/class_anc_plan.php
deleted file mode 100644
index ab6646b..0000000
--- a/include/class_anc_plan.php
+++ /dev/null
@@ -1,248 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief Concerns the Analytic plan (table plan_analytique)
- */
-
-/*! \brief
- *  Concerns the Analytic plan (table plan_analytique)
- */
-require_once NOALYSS_INCLUDE.'/class_itext.php';
-require_once NOALYSS_INCLUDE.'/class_ihidden.php';
-require_once NOALYSS_INCLUDE.'/constant.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_anc_account.php';
-require_once  NOALYSS_INCLUDE.'/class_dossier.php';
-
-class Anc_Plan
-{
-    var $db; /*!<database connection */
-    var $name;                                         /*!< name 
plan_analytique.pa_name */
-    var $description;                          /*!< description of the PA 
plan_analytique.pa_description*/
-    var $id;                                           /*!< id = 
plan_analytique.pa_id */
-
-    function Anc_Plan($p_cn,$p_id=0)
-    {
-        $this->db=$p_cn;
-        $this->id=$p_id;
-        $this->name="";
-        $this->description="";
-        $this->get();
-    }
-    /*!\brief get the list of all existing PA
-     * \return an array of PA (not object)
-     *
-     */
-    function get_list($p_order=" order by pa_name")
-    {
-        $array=array();
-        $sql="select pa_id as id,pa_name as name,".
-             "pa_description as description from plan_analytique $p_order";
-        $ret=$this->db->exec_sql($sql);
-        $array=Database::fetch_all($ret);
-        return $array;
-    }
-
-    function get()
-    {
-        if ( $this->id==0) return;
-
-        $sql="select pa_name,pa_description from plan_analytique where 
pa_id=".$this->id;
-        $ret= $this->db->exec_sql($sql);
-        if ( Database::num_row($ret) == 0)
-        {
-            return;
-        }
-        $a=  Database::fetch_array($ret,0);
-        $this->name=$a['pa_name'];
-        $this->description=$a['pa_description'];
-
-    }
-
-    function delete()
-    {
-        if ( $this->id == 0 ) return;
-        $this->db->exec_sql("delete from plan_analytique where 
pa_id=".$this->id);
-    }
-
-    function update()
-    {
-        if ( $this->id==0) return;
-        $name=sql_string($this->name);
-        if ( strlen($name) == 0)
-            return;
-
-        $description=sql_string($this->description);
-        $this->db->exec_sql("update plan_analytique set pa_name=$1,
-                            pa_description=$2 where 
pa_id=$3",array($name,$description,$this->id));
-    }
-
-    function add()
-    {
-        $name=sql_string($this->name);
-        if ( strlen($name) == 0)
-            return;
-        if ( $this->isAppend() == false) return;
-        $description=sql_string($this->description);
-        $this->db->exec_sql("insert into 
plan_analytique(pa_name,pa_description)".
-                            " values (".
-                            "'".$name."',".
-                            "'".$description."')");
-        $this->id=$this->db->get_current_seq('plan_analytique_pa_id_seq');
-
-    }
-    function form()
-    {
-
-        $wName=new IText('pa_name',$this->name);
-
-        $wName->table=1;
-        $wDescription=new IText('pa_description',$this->description);
-        $wDescription->table=1;
-        $wId=new IHidden("pa_id",$this->id);
-        $ret="<TABLE>";
-        $ret.='<tr>'.td(_('Nom')).$wName->input().'</tr>';
-        $ret.="<tr>".td(_('Description')).$wDescription->input()."</tr>";
-        $ret.="</table>";
-        $ret.=$wId->input();
-        return $ret;
-    }
-    function isAppend()
-    {
-        $count=$this->db->get_value("select count(pa_id) from 
plan_analytique");
-
-        if ( $count > 10 )
-            return false;
-        else
-            return true;
-    }
-    /*!\brief get all the poste related to the current
-     *        Analytic plan
-     * \return an array of Poste_analytic object
-     */
-    function get_poste_analytique($p_order="")
-    {
-        $sql="select po_id,po_name from poste_analytique where 
pa_id=".$this->id." $p_order";
-        $r=$this->db->exec_sql($sql);
-        $ret=array();
-        if ( Database::num_row($r) == 0 )
-            return $ret;
-
-        $all=Database::fetch_all($r);
-        foreach ($all as $line)
-        {
-            $obj=new Anc_Account($this->db,$line['po_id']);
-            $obj->get_by_id();
-            $ret[]=clone $obj;
-        }
-        return $ret;
-    }
-    /*!\brief show the header for a table for PA
-     * \return string like <th>name</th>...
-     */
-    function header()
-    {
-        $res="";
-        $a_plan=$this->get_list(" order by pa_id");
-        if ( empty($a_plan)) return "";
-        foreach ($a_plan as $r_plan)
-        {
-            $res.="<th>".h($r_plan['name'])."</th>";
-        }
-        return $res;
-    }
-    function count()
-    {
-        $a=$this->db->count_sql("select pa_id from plan_analytique");
-        return $a;
-    }
-    function exist()
-    {
-        $a=$this->db->count_sql("select pa_id from plan_analytique where 
pa_id=".
-                                Database::escape_string($this->pa_id));
-
-        return ($a==0)?false:true;
-
-    }
-    /**
-    address@hidden return an HTML string containing hidden input type to
-    * hold the differant PA_ID
-    address@hidden $p_array contains a array, it is the result of the fct
-    * Anc_Plan::get_list
-    address@hidden html string
-    address@hidden Anc_Plan::get_list
-    */
-    static function hidden($p_array)
-    {
-        $r='';
-        for ($i_anc=0;$i_anc <count($p_array);$i_anc++)
-        {
-            $r.=HtmlInput::hidden('pa_id[]',$p_array[$i_anc]['id']);
-        }
-        return $r;
-    }
-    static function test_me()
-    {
-        $cn=new Database(dossier::id());
-        echo "<h1>Plan analytique : test</h1>";
-        echo "clean";
-        $cn->exec_sql("delete from plan_analytique");
-
-        $p=new Anc_Plan($cn);
-        echo "<h2>Add</h2>";
-        $p->name="Nouveau 1";
-        $p->description="C'est un test";
-        echo "Add<hr>";
-        $p->add();
-        $p->name="Nouveau 2";
-        $p->add();
-        $pa_id=$p->id;
-        echo $p->id."/";
-        $p->name="Nouveau 3";
-        $p->add();
-        echo $p->id."/";
-
-
-        $p->name="Nouveau 4";
-        $p->add();
-        echo $p->id;
-
-        echo "<h2>get</h2>";
-        $p->get();
-        var_dump($p);
-        echo "<h2>Update</h2> ";
-        $p->name="Update ";
-        $p->description="c'est change";
-        $p->update();
-        $p->get();
-        var_dump($p);
-        echo "<h2>get_list</h2>";
-        $a=$p->get_list();
-        var_dump($a);
-        echo "<h2>delete </h2>";
-        $p->delete();
-
-
-    }
-}
-
-?>
diff --git a/include/class_anc_print.php b/include/class_anc_print.php
deleted file mode 100644
index f9fc3e5..0000000
--- a/include/class_anc_print.php
+++ /dev/null
@@ -1,224 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- *  \brief this class is the mother class for the CA printing
- */
-
-/*! \brief this class is the mother class for the CA printing
- *
- *
- */
-require_once NOALYSS_INCLUDE.'/class_idate.php';
-require_once NOALYSS_INCLUDE.'/class_itext.php';
-require_once NOALYSS_INCLUDE.'/class_ihidden.php';
-require_once NOALYSS_INCLUDE.'/class_iselect.php';
-require_once NOALYSS_INCLUDE.'/class_ibutton.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/constant.php';
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-require_once  NOALYSS_INCLUDE.'/class_anc_plan.php';
-require_once NOALYSS_INCLUDE.'/class_ianccard.php';
-class Anc_Print
-{
-    var $db;                                           /*!< $db database 
connection */
-    var $to;                                           /*!< $to start date */
-    var $from;                                         /*!< $from end date */
-    var $from_poste;                           /*!< $from_poste from poste  */
-    var $to_poste;                             /*!< $to_poste to the poste */
-
-    function Anc_Print($p_cn)
-    {
-        $this->db=$p_cn;
-        $this->from="";
-        $this->to="";
-        $this->from_poste="";
-        $this->to_poste="";
-        $this->has_data=0;
-
-    }
-    /*!
-     * \brief complete the object with the data in $_REQUEST
-     */
-    function get_request()
-    {
-        if ( isset($_REQUEST['from']))
-            $this->from=$_REQUEST['from'];
-
-        if ( isset($_REQUEST['to']))
-            $this->to=$_REQUEST['to'];
-
-        if ( isset($_REQUEST['from_poste']))
-            $this->from_poste=$_REQUEST['from_poste'];
-
-        if ( isset($_REQUEST['to_poste']))
-            $this->to_poste=$_REQUEST['to_poste'];
-        if ( isset($_REQUEST['pa_id']))
-            $this->pa_id=$_REQUEST['pa_id'];
-        else
-            $this->pa_id="";
-
-    }
-    /*!
-     * \brief Compute  the form to display
-     * \param $p_hidden hidden tag to be included (gDossier,...)
-     *
-     *
-     * \return string containing the data
-     */
-    function display_form($p_hidden="")
-    {
-        /* if there is no analytic plan return */
-        $pa=new Anc_Plan($this->db);
-        if ( $pa->count() == 0 )
-        {
-            echo '<div class="content">';
-            echo '<h2 class="error">'._('Aucun plan défini').'</h2>';
-            echo '</div>';
-            return;
-        }
-
-        $from=new IDate('from','from');
-        $from->size=10;
-        $from->value=$this->from;
-
-        $to=new IDate('to','to');
-        $to->value=$this->to;
-        $to->size=10;
-
-        $from_poste=new IAncCard('from_poste','from_poste');
-        $from_poste->size=10;
-        $from_poste->plan_ctl='pa_id';
-        $from_poste->value=$this->from_poste;
-
-        $to_poste=new IAncCard('to_poste','to_poste');
-        $to_poste->value=$this->to_poste;
-        $to_poste->size=10;
-
-        $hidden=new IHidden();
-        $r=dossier::hidden();
-        $r.=$hidden->input("result","1");
-        
-        $r.=HtmlInput::request_to_hidden(array('ac'));
-        $r.=$p_hidden;
-        $plan=new Anc_Plan($this->db);
-        $plan_id=new ISelect("pa_id");
-        $plan_id->value=$this->db->make_array("select pa_id, pa_name from 
plan_analytique order by pa_name");
-        $plan_id->selected=$this->pa_id;
-        $choose_from=new IButton();
-        $choose_from->name=_("Choix Poste");
-        $choose_from->label=_("Recherche");
-        
$choose_from->javascript="onClick=search_ca(".dossier::id().",'from_poste','pa_id')";
-        
-
-        $choose_to=new IButton();
-        $choose_to->name=_("Choix Poste");
-        $choose_to->label=_("Recherche");
-
-        
-        
$choose_to->javascript="onClick=search_ca(".dossier::id().",'to_poste','pa_id')";
-      
-        $r.=HtmlInput::request_to_hidden(array('ac'));
-        ob_start();
-        ?>
-<table>
-    <tr>
-        <td>
-            <?php 
-                echo _('Depuis') ;
-                echo HtmlInput::infobulle(37);
-            ?>
-        </td>
-        <td>
-            <?php 
-                echo $from->input(); 
-            ?>
-        </td>
-    </tr>
-    <tr>
-        <td>
-            <?php 
-                echo _('Jusque') ;
-                echo HtmlInput::infobulle(37);
-            ?>
-        </td>
-        <td>
-            <?php 
-                echo $to->input(); 
-            ?>
-        </td>
-    </tr>
-    
-</table>
-<span style="padding:5px;margin:5px;display:block;">
-    <?php echo _( "Plan Analytique :").$plan_id->input(); 
-        echo HtmlInput::infobulle(42);
-    ?>
-</span>
-
-<?php
-        $r.=ob_get_clean();
-        $r.=_("Entre l'activité ").$from_poste->input();
-        $r.=$choose_from->input();
-        $r.=_(" et l'activité ").$to_poste->input();
-        $r.=$choose_to->input();
-
-        $r.='</span>';
-        return $r;
-    }
-    /*!
-     * \brief Set the filter (account_date)
-     *
-     * \return return the string to add to load
-     */
-
-    function set_sql_filter()
-    {
-        $sql="";
-        $and=" and ";
-        if ( $this->from != "" )
-        {
-            $sql.="$and a.oa_date >= to_date('".$this->from."','DD.MM.YYYY')";
-        }
-        if ( $this->to != "" )
-        {
-            $sql.=" $and a.oa_date <= to_date('".$this->to."','DD.MM.YYYY')";
-        }
-
-        return $sql;
-
-    }
-  function check()
-  {
-
-    /*
-     * check date
-     */
-    if (($this->from != '' && isDate ($this->from) == 0)
-       ||
-       ($this->to != '' && isDate ($this->to) == 0))
-      return -1;
-
-    return 0;
-  }
-
-
-}
diff --git a/include/class_anc_table.php b/include/class_anc_table.php
deleted file mode 100644
index 877c836..0000000
--- a/include/class_anc_table.php
+++ /dev/null
@@ -1,329 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief object to show a table: link between accountancy and analytic
- */
-require_once NOALYSS_INCLUDE.'/class_anc_acc_link.php';
-
-class Anc_Table extends Anc_Acc_Link
-{
-  /**
-   address@hidden display form to get the parameter 
-   *  - card_poste 1 by card, 2 by account
-   *  - from_poste 
-   *  - to_poste
-   *  - from from date
-   *  - to until date
-   *  - pa_id Analytic plan to use
-   */
-  function display_form($p_hidden='')
-  {
-    $r=parent::display_form($p_hidden);
-    $icard=new ISelect('card_poste');
-    $icard->value=array(
-                       array('value'=>1,'label'=>'Par fiche'),
-                       array('value'=>2,'label'=>'Par poste comptable')
-                       );
-    $icard->selected=$this->card_poste;
-    $r.=$icard->input();
-    $r.=HtmlInput::request_to_hidden(array('ac'));
-    return $r;
-  }
-
-
-  /**
-   * load the data
-   * does not return anything but give a value to this->aheader and this->arow
-   */
-  function load_poste()
-  {
-    $sql_from_poste=($this->from_poste!='')?" and  po.po_name >= 
upper('".Database::escape_string($this->from_poste)."')":'';
-    $sql_to_poste=($this->to_poste!='')?" and  po.po_name <= 
upper('".Database::escape_string($this->to_poste)."')":'';
-    $this->db->exec_sql('create temporary table table_analytic as select * 
from comptaproc.table_analytic_account(\''.$this->from.'\',\''.$this->to.'\')');
-
-    $header="select distinct po_id,po_name  from table_analytic
-               where
-               pa_id=$1 ".$sql_from_poste.$sql_to_poste." order by po_name";
-    $this->aheader=$this->db->get_array($header,array($this->pa_id));
-    
-    $this->arow=$this->db->get_array("select distinct card_account,name
-               from table_analytic
-               where
-               pa_id=$1 ".$sql_from_poste.$sql_to_poste." order by 
card_account",array($this->pa_id));
-
-    $this->sql='select sum_amount from  table_analytic where card_account=$1 
and po_id=$2 and pa_id='.$this->pa_id.' '.$sql_from_poste.$sql_to_poste;
-  }
-
-  /**
-   * load the data
-   * does not return anything but give a value to this->aheader and this->arow
-   */
-  function load_card()
-  {
-    $sql_from_poste=($this->from_poste!='')?" and  po.po_name >= 
upper('".Database::escape_string($this->from_poste)."')":'';
-    $sql_to_poste=($this->to_poste!='')?" and  po.po_name <= 
upper('".Database::escape_string($this->to_poste)."')":'';
-    $this->db->exec_sql('create temporary table table_analytic as select * 
from comptaproc.table_analytic_card(\''.$this->from.'\',\''.$this->to.'\')');
-
-    $header="select distinct po_id,po_name from table_analytic
-               where
-               pa_id=$1 ".$sql_from_poste.$sql_to_poste." order by po_name";
-    $this->aheader=$this->db->get_array($header,array($this->pa_id));
-    
-    $this->arow=$this->db->get_array("select distinct f_id,card_account,name 
from  table_analytic 
-                       where
-               pa_id=$1 ".$sql_from_poste.$sql_to_poste." order by 
name",array($this->pa_id));
-    $this->sql='select sum_amount from table_analytic where f_id=$1 and 
po_id=$2 and pa_id='.$this->pa_id.' '.$sql_from_poste.$sql_to_poste;
-  }
-  /**
-   address@hidden display the button export CSV
-   address@hidden $p_hidden is a string containing hidden items
-   address@hidden html string
-   */  
-  function show_button($p_hidden)
-  {
-    $r="";
-    $r.= '<form method="GET" action="export.php"  style="display:inline">';
-    $r.= HtmlInput::hidden("act","CSV:AncTable");
-    $r.= HtmlInput::hidden("to",$this->to);
-    $r.= HtmlInput::hidden("from",$this->from);
-    $r.= HtmlInput::hidden("pa_id",$this->pa_id);
-    $r.= HtmlInput::hidden("from_poste",$this->from_poste);
-    $r.= HtmlInput::hidden("to_poste",$this->to_poste);
-    $r.= HtmlInput::hidden("card_poste",$this->card_poste);
-    $r.= $p_hidden;
-    $r.= dossier::hidden();
-    $r.=HtmlInput::submit('bt_csv',"Export en CSV");
-    $r.= '</form>';
-    return $r;
-  }
-  function display_html()
-  {
-    bcscale(2);
-    if ( $this->check()  != 0)
-      {
-       alert('Désolé mais une des dates données n\'est pas valide');
-       return;
-      }
-
-    if ( $this->card_poste=='1')
-      {
-       $this->load_card();
-
-       echo '<table class="result">';
-       echo '<tr>';
-       echo th('Fiche');
-       foreach ($this->aheader as $h)
-         {
-           echo '<th style="text-align:right">'.h($h['po_name']).'</th>';
-         }
-       echo th('Total',' style="text-align:right"');
-       echo '</tr>';
-       /*
-        * Show all the result
-        */
-       $tot_global=0;
-       for ($i=0;$i<count($this->arow);$i++)
-         {
-           $tr=($i%2==0)?'<tr class="even">':'<tr class="odd">';
-            echo $tr;
-           echo 
td(HtmlInput::history_card($this->arow[$i]['f_id'],$this->arow[$i]['card_account'].'
 '.$this->arow[$i]['name']));
-           $tot_row=0;
-           for ($x=0;$x<count($this->aheader);$x++)
-             {
-               
$amount=$this->db->get_value($this->sql,array($this->arow[$i]['f_id'],$this->aheader[$x]['po_id']));
-               if ($amount==null)$amount=0;
-               if ( isset($tot_col[$x]))
-                 {
-                   $tot_col[$x]=bcadd($tot_col[$x],$amount);
-                 }
-               else
-                 {
-                   $tot_col[$x]=$amount;
-                 }
-               echo td(nbm($amount),' class="num" ');
-               $tot_row=bcadd($tot_row,$amount);
-             }
-           echo td(nbm($tot_row),' class="num"');
-           $tot_global=bcadd($tot_global,$tot_row);
-           echo '</tr>';
-                   
-
-         }
-       echo '<tr>';
-       echo td('Totaux');
-       for ($i=0;$i<count($this->aheader);$i++)
-         {
-           echo td(nbm($tot_col[$i]),' class="num"');
-         }
-       echo td(nbm($tot_global),' class="num input_text notice" ');
-       echo '</tr>';
-       echo '</table>';
-      }
-    if ( $this->card_poste=='2')
-      {
-       $this->load_poste();
-
-       echo '<table class="result">';
-       echo '<tr>';
-       echo th('poste comptable ');
-       foreach ($this->aheader as $h)
-         {
-           echo '<th style="text-align:right">'.h($h['po_name']).'</th>';
-         }
-       echo th('Total',' style="text-align:right"');
-       echo '</tr>';
-       /*
-        * Show all the result
-        */
-       $tot_global=0;
-       for ($i=0;$i<count($this->arow);$i++)
-         {
-            $tr=($i%2==0)?'<tr class="even">':'<tr class="odd">';
-            echo $tr;
-            echo 
td(HtmlInput::history_account($this->arow[$i]['card_account'],$this->arow[$i]['card_account'].'
 '.$this->arow[$i]['name']));
-           $tot_row=0;
-           for ($x=0;$x<count($this->aheader);$x++)
-             {
-               
$amount=$this->db->get_value($this->sql,array($this->arow[$i]['card_account'],$this->aheader[$x]['po_id']));
-               if ($amount==null)$amount=0;
-               if ( isset($tot_col[$x]))
-                 {
-                   $tot_col[$x]=bcadd($tot_col[$x],$amount);
-                 }
-               else
-                 {
-                   $tot_col[$x]=$amount;
-                 }
-               echo td(nbm($amount),' class="num" ');
-               $tot_row=bcadd($tot_row,$amount);
-             }
-           echo td(nbm($tot_row),' class="num"');
-           $tot_global=bcadd($tot_global,$tot_row);
-           echo '</tr>';
-                   
-
-         }
-       echo '<tr>';
-
-       echo td('Totaux');
-       for ($i=0;$i<count($this->aheader);$i++)
-         {
-           echo td(nbm($tot_col[$i]),' class="num"');
-         }
-       echo td(nbm($tot_global),' class="num input_text notice" ');
-       echo '</tr>';
-       echo '</table>';
-
-      }
-
-  }
-  function export_csv()
-  {
-   bcscale(2);
-   if ( $this->check () != 0 ) {throw new Exception ( "DATE INVALIDE");}
-
-    if ( $this->card_poste=='1')
-      {
-       $this->load_card();
-
-       echo '"Fiche"';
-       foreach ($this->aheader as $h)
-         {
-           echo ';"'.$h['po_name'].'"';
-         }
-       echo ';"Total"';
-       printf("\r\n");
-       /*
-        * Show all the result
-        */
-
-       for ($i=0;$i<count($this->arow);$i++)
-         {
-
-           printf('"%s"',$this->arow[$i]['card_account'].' 
'.$this->arow[$i]['name']);
-           $tot_row=0;
-           for ($x=0;$x<count($this->aheader);$x++)
-             {
-               
$amount=$this->db->get_value($this->sql,array($this->arow[$i]['f_id'],$this->aheader[$x]['po_id']));
-               if ($amount==null)$amount=0;
-               if ( isset($tot_col[$x]))
-                 {
-                   $tot_col[$x]=bcadd($tot_col[$x],$amount);
-                 }
-               else
-                 {
-                   $tot_col[$x]=$amount;
-                 }
-               printf(";%s",nb($amount));
-               $tot_row=bcadd($tot_row,$amount);
-             }
-           printf(";%s",nb($tot_row));
-           printf("\r\n");
-                   
-
-         }
-      }
-    if ( $this->card_poste=='2')
-      {
-       $this->load_poste();
-
-       echo '"Poste"';
-       foreach ($this->aheader as $h)
-         {
-           echo ';"'.$h['po_name'].'"';
-         }
-       echo ';"Total"';
-       printf("\r\n");
-       /*
-        * Show all the result
-        */
-
-       for ($i=0;$i<count($this->arow);$i++)
-         {
-
-           printf('"%s"',$this->arow[$i]['card_account'].' 
'.$this->arow[$i]['name']);
-           $tot_row=0;
-           for ($x=0;$x<count($this->aheader);$x++)
-             {
-               
$amount=$this->db->get_value($this->sql,array($this->arow[$i]['card_account'],$this->aheader[$x]['po_id']));
-               if ($amount==null)$amount=0;
-               if ( isset($tot_col[$x]))
-                 {
-                   $tot_col[$x]=bcadd($tot_col[$x],$amount);
-                 }
-               else
-                 {
-                   $tot_col[$x]=$amount;
-                 }
-               printf(";%s",nb($amount));
-               $tot_row=bcadd($tot_row,$amount);
-             }
-           printf(";%s",nb($tot_row));
-           printf("\r\n");
-                   
-
-         }
-      }
-   
-  }
-
-}
\ No newline at end of file
diff --git a/include/class_anticipation.php b/include/class_anticipation.php
deleted file mode 100644
index e5ba8ce..0000000
--- a/include/class_anticipation.php
+++ /dev/null
@@ -1,452 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/**
- * @file
- * @brief  Manage the anticipation, prediction of sales, expense, bank...
- *
- */
-/**
- address@hidden Manage the anticipation of expense, sales,...
- address@hidden Forecast Forecast_Cat Forecast_Item
- *
- */
-require_once NOALYSS_INCLUDE.'/class_forecast.php';
-require_once NOALYSS_INCLUDE.'/class_forecast_cat.php';
-require_once NOALYSS_INCLUDE.'/class_forecast_item.php';
-require_once NOALYSS_INCLUDE.'/class_fiche.php';
-require_once NOALYSS_INCLUDE.'/class_acc_account_ledger.php';
-require_once NOALYSS_INCLUDE.'/class_periode.php';
-require_once NOALYSS_INCLUDE.'/class_impress.php';
-
-class Anticipation
-{
-    /* example private $variable=array("val1"=>1,"val2"=>"Seconde 
valeur","val3"=>0); */
-    private static $variable=array ("id"=>"f_id","name"=>"f_name");
-    private $cn;
-    var $cat; /*!< array of object categorie (forecast_cat)*/
-    var $item; /*< array of object item (forecast_item) */
-    /**
-     * @brief constructor
-     * @param $p_init Database object
-     */
-    function __construct ($p_init,$p_id=0)
-    {
-        $this->cn=$p_init;
-        $this->f_id=$p_id;
-    }
-    public function get_parameter($p_string)
-    {
-        if ( array_key_exists($p_string,self::$variable) )
-        {
-            $idx=self::$variable[$p_string];
-            return $this->$idx;
-        }
-        else
-            throw new Exception("Attribut inexistant $p_string");
-    }
-    public function set_parameter($p_string,$p_value)
-    {
-        if ( array_key_exists($p_string,self::$variable) )
-        {
-            $idx=self::$variable[$p_string];
-            $this->$idx=$p_value;
-        }
-        else
-            throw new Exception("Attribut inexistant $p_string");
-
-
-    }
-    public function get_info()
-    {
-        return var_export(self::$variable,true);
-    }
-    public function verify()
-    {
-        // Verify that the elt we want to add is correct
-        // the f_name must be unique (case insensitive)
-        return 0;
-    }
-    public function save()
-    {
-        /* please adapt */
-        if (  $this->get_parameter("id") == 0 )
-            $this->insert();
-        else
-            $this->update();
-    }
-
-    public function insert()
-    {
-        if ( $this->verify() != 0 ) return;
-    }
-
-    public function update()
-{}
-
-    public function load()
-    {}
-    /**
-     address@hidden Display the result of the forecast
-     address@hidden $p_periode
-     address@hidden HTML String with the code
-     */
-    public function display()
-    {
-               bcscale(4);
-        $forecast=new Forecast($this->cn,$this->f_id);
-        $forecast->load();
-        $str_name=h($forecast->get_parameter('name'));
-
-       $start=$forecast->get_parameter('start_date');
-       $end=$forecast->get_parameter('end_date');
-
-       if ( $start=='') throw new Exception (_('Période de début non 
valable'));
-       if ( $end=='') throw new Exception (_('Période de fin non valable'));
-
-       $per=new Periode($this->cn,$start);
-       $str_start=format_date($per->first_day());
-
-       $per=new Periode($this->cn,$end);
-       $str_end=format_date($per->last_day());
-
-
-        $r="";
-        $aCat=$this->cn->get_array('select fc_id,fc_desc from forecast_cat 
where f_id=$1 order by fc_order',array($this->f_id));
-        $aItem=array();
-        $aReal=array();
-        $poste=new Acc_Account_Ledger($this->cn,0);
-        $fiche=new Fiche($this->cn);
-        $aPeriode=$this->cn->get_array("select p_id,to_char(p_start,'MM.YYYY') 
as myear from parm_periode
-                                        where p_start >= (select p_start from 
parm_periode where p_id=$start)
-                                         and p_end <= (select p_end from 
parm_periode where p_id=$end)
-                                        order by p_start;");
-       $error=array();
-        for($j=0;$j<count($aCat);$j++)
-        {
-            $aItem[$j]=$this->cn->get_array('select 
fi_card,fi_account,fi_text,fi_amount,fi_debit from forecast_item where fc_id=$1 
 and fi_pid=0 order by fi_order ',array($aCat[$j]['fc_id']));
-            $aPerMonth[$j]=$this->cn->get_array('select 
fi_pid,fi_card,fi_account,fi_text,fi_amount,fi_debit from forecast_item where 
fc_id=$1 and fi_pid !=0 order by fi_order ',array($aCat[$j]['fc_id']));
-
-            /* compute the real amount for periode */
-            for($k=0;$k<count($aItem[$j]);$k++)
-            {
-                /* for each periode */
-                for ($l=0;$l<count($aPeriode);$l++)
-                {
-                    if ($aItem[$j][$k]['fi_account']=='')
-                    {
-                        $fiche->id=$aItem[$j][$k]['fi_card'];
-                        $amount=$fiche->get_solde_detail("j_tech_per = 
".$aPeriode[$l]['p_id']);
-                       if ($aItem[$j][$k]['fi_debit']=='C' && 
$amount['debit']>$amount['credit'])  $amount['solde']=$amount["solde"]*(-1);
-                       if ($aItem[$j][$k]['fi_debit']=='D' && 
$amount['debit']<$amount['credit'])  $amount['solde']=$amount["solde"]*(-1);
-
-                    }
-                    else
-                    {
-                        $poste->id=$aItem[$j][$k]['fi_account'];
-                       
$aresult=Impress::parse_formula($this->cn,"OK",$poste->id,$aPeriode[$l]['p_id'],$aPeriode[$l]['p_id']);
-                        $tmp_label=$aresult['desc'];
-                       $amount['solde']=$aresult['montant'];
-
-                       if ( $tmp_label != 'OK') $error[]="<li> 
".$aItem[$j][$k]['fi_text'].$poste->id.'</li>';
-                    }
-                    $aReal[$j][$k][$l]=$amount['solde'];
-                }
-            }
-
-        }
-        ob_start();
-        require_once NOALYSS_INCLUDE.'/template/forecast_result.php';
-        $r.=ob_get_contents();
-        ob_end_clean();
-        return $r;
-    }
-    public static function div()
-    {
-        $r='<div id="div_anti" style="display:none">';
-        $r.= '</div>';
-        return $r;
-    }
-    public function delete()
-    {}
-    /**
-     address@hidden Display a form for modifying the name or/and the category 
of an existing
-     * anticipation
-     address@hidden html string with the form
-     */
-    private function form_cat_mod()
-    {
-        global $g_user;
-        $a=new Forecast($this->cn,$this->f_id);
-        $a->load();
-        $name=new IText('an_name');
-        $name->value=$a->get_parameter("name");
-        $str_name=$name->input();
-        $str_action=_('Modification');
-
-       $start_date=new IPeriod('start_date');
-       $start_date->type=ALL;
-       $start_date->cn=$this->cn;
-       $start_date->show_end_date=false;
-       $start_date->show_start_date=true;
-       $start_date->user=$g_user;
-       $start_date->filter_year=false;
-
-       $end_date=new IPeriod('end_date');
-       $end_date->type=ALL;
-       $end_date->cn=$this->cn;
-       $end_date->show_end_date=true;
-       $end_date->show_start_date=false;
-       $end_date->user=$g_user;
-       $end_date->filter_year=false;
-
-       $start_date->value=$a->f_start_date;
-       $end_date->value=$a->f_end_date;
-
-       $str_start_date=$start_date->input();
-       $str_end_date=$end_date->input();
-
-
-        $r=HtmlInput::hidden('f_id',$this->f_id);
-        $array=Forecast_Cat::load_all($this->cn,$this->f_id);
-
-        for ($i=0;$i<MAX_CAT;$i++)
-        {
-            /* category name */
-            
$name_name=(isset($array[$i]['fc_id']))?'fr_cat'.$array[$i]['fc_id']:'fr_cat_new'.$i;
-            $name=new IText($name_name);
-            $name->value=(isset 
($array[$i]['fc_desc']))?$array[$i]['fc_desc']:'';
-            $aCat[$i]['name']=$name->input();
-
-
-            /* category order */
-            
$order_name=(isset($array[$i]['fc_id']))?'fc_order'.$array[$i]['fc_id']:'fc_order_new'.$i;
-            $order=new IText($order_name);
-            
$order->value=(isset($array[$i]['fc_order']))?$array[$i]['fc_order']:$i+1;
-            $aCat[$i]['order']=$order->input();
-        }
-
-        ob_start();
-        require_once NOALYSS_INCLUDE.'/template/forecast_cat.php';
-        $r.=ob_get_contents();
-        ob_end_clean();
-        return $r;
-    }
-    /**
-     address@hidden Display a form for adding an new anticipation
-     address@hidden html string with the form
-     */
-    private function form_cat_new()
-    {
-     global $g_user;
-      $r="";
-        $str_action=_('Nouveau');
-
-        $name=new IText('an_name');
-        $str_name=$name->input();
-
-       $start_date=new IPeriod('start_date');
-       $start_date->type=ALL;
-       $start_date->cn=$this->cn;
-       $start_date->show_end_date=false;
-       $start_date->show_start_date=true;
-       $start_date->user=$g_user;
-       $start_date->filter_year=false;
-
-       $end_date=new IPeriod('end_date');
-       $end_date->type=ALL;
-       $end_date->cn=$this->cn;
-       $end_date->show_end_date=true;
-       $end_date->show_start_date=false;
-       $end_date->user=$g_user;
-       $end_date->filter_year=false;
-
-       $period=$g_user->get_periode();
-       $per=new Periode($this->cn,$period);
-       $year=$per->get_exercice();
-
-       list($per_start,$per_end)=$per->get_limit($year);
-       $start_date->value=$per_start->p_id;
-       $end_date->value=$per_end->p_id;
-
-       $str_start_date=$start_date->input();
-       $str_end_date=$end_date->input();
-
-        $aLabel=array(_('Ventes'),_('Dépense'),_('Banque'));
-        $aCat=array();
-
-        for ($i=0;$i<MAX_CAT;$i++)
-        {
-            /* category name */
-            $name=new IText('fr_cat'.$i);
-            $name->value=(isset($aLabel[$i]))?$aLabel[$i]:'';
-            $aCat[$i]['name']=$name->input();
-
-
-            /* category order */
-            $order=new IText('fr_order'.$i);
-            $order->value=$i+1;
-            $aCat[$i]['order']=$order->input();
-        }
-
-        ob_start();
-        require_once NOALYSS_INCLUDE.'/template/forecast_cat.php';
-        $r.=ob_get_contents();
-        ob_end_clean();
-        return $r;
-
-    }
-    /**
-     * @brief create an empty object anticipation
-     * @return html string with the form
-     */
-    public  function form_cat()
-    {
-        if ($this->f_id != 0)
-            return $this->form_cat_mod();
-        else
-            return $this->form_cat_new();
-    }
-    /**
-     address@hidden display a form for modifying or add a forecast
-     address@hidden HTML code
-     */
-    public function form_item()
-    {
-        $forecast=new Forecast($this->cn,$this->f_id);
-        $forecast->load();
-        $str_name=$forecast->get_parameter('name');
-        $str_start=$forecast->get_parameter('start_date');
-        $str_end=$forecast->get_parameter('end_date');
-
-
-        $r="";
-        $str_action=_("Elements");
-        $cat=new Forecast_Cat($this->cn);
-        $array=$cat->make_array($this->f_id);
-        $periode=new Periode($this->cn);
-        $aPeriode=$this->cn->make_array("select 
p_id,to_char(p_start,'MM.YYYY') as label from parm_periode
-                                  where p_start >= (select p_start from 
parm_periode where p_id=$str_start)
-                                   and p_end <= (select p_end from 
parm_periode where p_id=$str_end)
-                                  order by p_start");
-        $aPeriode[]=array('value'=>0,'label'=>'Mensuel');
-        $value=$this->cn->get_array("select 
fi_id,fi_text,fi_account,fi_card,fc_id,fi_amount,fi_debit,fi_pid ".
-                                    " from forecast_item ".
-                                    "  where fc_id in (select fc_id from 
forecast_cat where f_id = $1)",array($this->f_id));
-        $max=(count($value) < 
MAX_FORECAST_ITEM)?MAX_FORECAST_ITEM:count($value);
-        $r.=HtmlInput::hidden('nbrow',$max);
-
-        for ($i=0;$i<$max;$i++)
-        {
-            if (isset($value[$i]['fi_id']))
-            {
-                $r.=HtmlInput::hidden('fi_id'.$i,$value[$i]['fi_id']);
-            }
-            /* category*/
-            $category=new ISelect();
-            $category->name='an_cat'.$i;
-            $category->value=$array;
-            
$category->selected=(isset($value[$i]["fc_id"]))?$value[$i]["fc_id"]:-1;
-            $aCat[$i]['cat']=$category->input();
-
-            /* amount   */
-            $amount=new INum('an_cat_amount'.$i);
-            
$amount->value=(isset($value[$i]["fi_amount"]))?$value[$i]["fi_amount"]:0;
-            $aCat[$i]['amount']=$amount->input();
-
-            /* Accounting*/
-            $account=new IPoste('an_cat_acc'.$i);
-            $account->set_attribute('ipopup','ipop_account');
-           //            $account->set_attribute('label','an_label'.$i);
-            $account->set_attribute('account','an_cat_acc'.$i);
-           $account->set_attribute('bracket',1);
-           $account->set_attribute('no_overwrite',1);
-           $account->set_attribute('noquery',1);
-           $account->css_size="85%";
-            
$account->value=(isset($value[$i]["fi_account"]))?$value[$i]["fi_account"]:"";
-            $aCat[$i]['account']=$account->input();
-            /*Quick Code */
-            $qc=new ICard('an_qc'.$i);
-            // If double click call the javascript fill_ipopcard
-            $qc->set_dblclick("fill_ipopcard(this);");
-
-            // This attribute is mandatory, it is the name of the IPopup
-            $qc->set_attribute('ipopup','ipopcard');
-
-            // name of the field to update with the name of the card
-            $qc->set_attribute('label','an_label'.$i);
-
-            // Type of card : all
-            $qc->set_attribute('typecard','all');
-            $qc->set_attribute('jrn',0);
-            $qc->extra='all';
-
-            // when value selected in the autcomplete
-            $qc->set_function('fill_data');
-            if (isset($value[$i]["fi_card"]))
-            {
-                $f=new Fiche($this->cn,$value[$i]["fi_card"]);
-                $qc->value=$f->strAttribut(ATTR_DEF_QUICKCODE);
-                ;
-            }
-
-            $aCat[$i]['qc']=$qc->search().$qc->input();
-            /* Label */
-            $label=new IText('an_label'.$i);
-            
$label->value=(isset($value[$i]["fi_text"]))?$value[$i]["fi_text"]:"";
-            $aCat[$i]['name']=$label->input();
-
-            //Deb or Cred
-            $deb=new ISelect('an_deb'.$i);
-            
$deb->selected=(isset($value[$i]["fi_debit"]))?$value[$i]["fi_debit"]:-1;
-            $deb->value=array(array('value'=>'D','label'=>_('Débit')),
-                              array('value'=>'C','label'=>_('Crédit'))
-                             );
-            $aCat[$i]['deb']=$deb->input();
-            //Periode
-            $isPeriode=new ISelect('month'.$i);
-            $isPeriode->value=$aPeriode;
-            
$isPeriode->selected=(isset($value[$i]["fi_pid"]))?$value[$i]["fi_pid"]:0;
-            $aCat[$i]['per']=$isPeriode->input();
-        }
-        $add_row=new IButton('add_row');
-        $add_row->label=_('Ajouter une ligne');
-        $add_row->javascript='for_add_row(\'fortable\')';
-        $f_add_row=$add_row->input();
-        ob_start();
-        require_once NOALYSS_INCLUDE.'/template/forecast-detail.php';
-        $r.=ob_get_contents();
-        ob_end_clean();
-        return $r;
-    }
-    /**
-     * @brief unit test
-     */
-    static function test_me()
-    {
-        $cn=new Database(dossier::id());
-        $test=new Anticipation($cn);
-
-    }
-
-}
-
-?>
diff --git a/include/class_balance_age.php b/include/class_balance_age.php
deleted file mode 100644
index 364448b..0000000
--- a/include/class_balance_age.php
+++ /dev/null
@@ -1,240 +0,0 @@
-<?php
-
-/*
- * Copyright (C) 2015 Dany De Bontridder <address@hidden>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
- */
-require_once NOALYSS_INCLUDE.'/class_lettering.php';
-
-/* * *
- * @file 
- * @brief compute the ageing balance, currently this code is not used
- *
- */
-
-class Balance_Age
-{
-
-    private $cn;
-
-    function __construct($p_cn)
-    {
-        $this->cn=$p_cn;
-        $this->afiche=null;
-    }
-
-    function get_array_card($p_type, $p_extra="")
-    {
-        switch ($p_type)
-        {
-            case 'X':
-                $this->afiche=$this->cn->get_array("
-            with m as (select distinct qp_supplier as f_id from quant_purchase 
union select qs_client from quant_sold)
-            select distinct fiche.f_id as f_id ,f1.ad_value as name, 
f3.ad_value as first_name,f2.ad_value  as quick_code  
-                from fiche 
-                    join m on (fiche.f_id=m.f_id)
-                    join fiche_detail as f1 on (fiche.f_id=f1.f_id and 
f1.ad_id=1) 
-                    join fiche_detail as f2 on (fiche.f_id=f2.f_id and 
f2.ad_id=23) 
-                    left join fiche_detail as f3 on (fiche.f_id=f3.f_id and 
f3.ad_id=32)
-                 where 
-                 fiche.fd_id=$1
-                 order by f1.ad_value
-                 ", array($p_extra));
-                break;
-            case 'U':
-                $fiche=new Fiche($this->cn, $p_extra);
-                $this->afiche[0]['f_id']=$fiche->id;
-                $this->afiche[0]['quick_code']=$fiche->get_quick_code();
-                $this->afiche[0]['name']=$fiche->strAttribut(ATTR_DEF_NAME, 0);
-                
$this->afiche[0]['first_name']=$fiche->strAttribut(ATTR_DEF_FIRST_NAME, 0);
-                break;
-            case 'F':
-                $this->afiche=$this->cn->get_array("
-            select distinct qp_supplier as f_id ,f1.ad_value as name, 
f3.ad_value as first_name,f2.ad_value  as quick_code  
-                from quant_purchase join 
-                    fiche_detail as f1 on (qp_supplier=f1.f_id and f1.ad_id=1) 
-                    join fiche_detail as f2 on (qp_supplier=f2.f_id and 
f2.ad_id=23) 
-                    left join fiche_detail as f3 on (qp_supplier=f3.f_id and 
f3.ad_id=32)
-                 order by f1.ad_value
-                 ");
-                break;
-            case 'C':
-                $this->afiche=$this->cn->get_array("
-             select distinct qs_client as f_id ,f1.ad_value as name, 
f3.ad_value as first_name,f2.ad_value  as quick_code  
-                from quant_sold join 
-                    fiche_detail as f1 on (qs_client=f1.f_id and f1.ad_id=1) 
-                    join fiche_detail as f2 on (qs_client=f2.f_id and 
f2.ad_id=23) 
-                    left join fiche_detail as f3 on (qs_client=f3.f_id and 
f3.ad_id=32)
-                 order by f1.ad_value
-                 ");
-                break;
-            default:
-                throw new Exception('Type invalide');
-        }
-    }
-
-    function display_card($p_date_start, $p_fiche, $p_let)
-    {
-        $this->get_array_card('U', $p_fiche);
-        $a_fiche=$this->afiche;
-        $nb_fiche=count($a_fiche);
-        require 'template/balance_aged_result.php';
-    }
-
-    function display_category($p_date_start, $p_cat, $p_let)
-    {
-        // Get all fiche from Purchase
-
-        $this->get_array_card('X', $p_cat);
-        $a_fiche=$this->afiche;
-        $nb_fiche=count($a_fiche);
-        require 'template/balance_aged_result.php';
-    }
-
-    /**
-     * Display all the operation for the customer
-     * @param type $p_date_start min date  of the operatin
-     * @param type $p_let 'unlet' only unlettered or 'let' for all
-     */
-    function display_purchase($p_date_start, $p_let)
-    {
-        // Get all fiche from Purchase
-        $this->get_array_card('F');
-        $a_fiche=$this->afiche;
-        $nb_fiche=count($a_fiche);
-        require 'template/balance_aged_result.php';
-    }
-
-    /**
-     * Display all the operation for the supplier
-     * @param type $p_date_start min date  of the operatin
-     * @param type $p_let 'unlet' only unlettered or 'let' for all
-     */
-    function display_sale($p_date_start, $p_let)
-    {
-        // Get all fiche from Purchase
-        $this->get_array_card('C');
-        $a_fiche=$this->afiche;
-        $nb_fiche=count($a_fiche);
-        require 'template/balance_aged_result.php';
-    }
-
-    function export_csv($p_date_start, $p_let)
-    {
-        $nb_fiche=count($this->afiche);
-        $title=sprintf('"%s";', _('QuickCode'));
-        $title.=sprintf('"%s";', _('Nom'));
-        $title.=sprintf('"%s";', _('Prénom'));
-        $title.=sprintf('"%s";', _('Date'));
-        $title.=sprintf('"%s";', _('N° pièce'));
-        $title.=sprintf('"%s";', _('Interne'));
-        $title.=sprintf('"%s";', _('Fin'));
-        $title.=sprintf('"%s";', _('<30 jours'));
-        $title.=sprintf('"%s";', _('entre 30 et 60 jours'));
-        $title.=sprintf('"%s";', _('entre 60 et 90 jours'));
-        $title.=sprintf('"%s";', _('> 90 jours'));
-        $title.=sprintf("\n\r");
-        $flag_title=false;
-        for ($i=0; $i<$nb_fiche; $i++)
-        {
-            $card=new Lettering_Card($this->cn, 
$this->afiche[$i]['quick_code']);
-            $card->set_parameter('start', $p_date_start);
-            $card->get_balance_ageing($p_let);
-            if (empty($card->content))
-                continue;
-            if ( ! $flag_title ) { echo $title;$flag_title=true;}
-            $nb_row=count($card->content);
-            $sum_lt_30=0;
-            $sum_gt_30_lt_60=0;
-            $sum_gt_60_lt_90=0;
-            $sum_gt_90=0;
-            $sum_fin=0;
-            for ($j=0; $j<$nb_row; $j++)
-            {
-                $show=true;
-                printf('"%s";', str_replace('"', '', 
$this->afiche[$i]['quick_code']));
-                printf('"%s";', str_replace('"', '', 
$this->afiche[$i]['name']));
-                printf('"%s";', str_replace('"', '', 
$this->afiche[$i]['first_name']));
-                printf('"%s";', $card->content[$j]['j_date_fmt']);
-                printf('"%s";', $card->content[$j]['jr_pj_number']);
-                printf('"%s";', $card->content[$j]['jr_internal']);
-                if 
($card->content[$j]['jrn_def_type']=='FIN'||$card->content[$j]['jrn_def_type']=='ODS')
-                {
-                    printf("%s;", nb($card->content[$j]['j_montant']));
-                    $sum_fin=bcadd($sum_fin, $card->content[$j]['j_montant']);
-                    $show=false;
-                }
-                else
-                {
-                    printf('0;');
-                }
-                if ($show&&$card->content[$j]['day_paid']<=30)
-                {
-                    printf("%s;", nb($card->content[$j]['j_montant']));
-                    $sum_lt_30=bcadd($sum_lt_30, 
$card->content[$j]['j_montant']);
-                    $show=false;
-                }
-                else
-                {
-                    printf('0;');
-                }
-
-                if 
($show&&$card->content[$j]['day_paid']>30&&$card->content[$j]['day_paid']<=60)
-                {
-                    printf("%s;", nb($card->content[$j]['j_montant']));
-                    $sum_gt_30_lt_60=bcadd($sum_gt_30_lt_60, 
$card->content[$j]['j_montant']);
-                }
-                else
-                {
-                    printf('0;');
-                }
-
-                if 
($show&&$card->content[$j]['day_paid']>60&&$card->content[$j]['day_paid']<=90)
-                {
-                    printf("%s;", nb($card->content[$j]['j_montant']));
-                    $sum_gt_60_lt_90=bcadd($sum_gt_60_lt_90, 
$card->content[$j]['j_montant']);
-                }
-                else
-                {
-                    printf('0;');
-                }
-                if ($show&&$card->content[$j]['day_paid']>90)
-                {
-                    printf("%s", nb($card->content[$j]['j_montant']));
-                    $sum_gt_90=bcadd($sum_gt_90, 
$card->content[$j]['j_montant']);
-                }
-                else
-                {
-                    printf('0;');
-                }
-                printf("\n\r");
-            }
-            printf('"%s";', _('Totaux'));
-            printf('"";');
-            printf('"";');
-            printf('"";');
-            printf('"";');
-            printf('"";');
-            printf('%s;', nb($sum_fin));
-            printf('%s;', nb($sum_lt_30));
-            printf('%s;', nb($sum_gt_30_lt_60));
-            printf('%s;', nb($sum_gt_60_lt_90));
-            printf('%s', nb($sum_gt_90));
-            printf("\n\r");
-        }
-    }
-
-}
diff --git a/include/class_bank.php b/include/class_bank.php
deleted file mode 100644
index 886c209..0000000
--- a/include/class_bank.php
+++ /dev/null
@@ -1,58 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-// Copyright Author Dany De Bontridder address@hidden
-require_once NOALYSS_INCLUDE.'/constant.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_acc_parm_code.php';
-
-require_once NOALYSS_INCLUDE.'/class_fiche.php';
-require_once NOALYSS_INCLUDE.'/class_acc_account_ledger.php';
-require_once NOALYSS_INCLUDE.'/user_common.php';
-/*! \file
- * \brief Derived from class fiche Administration are a specific kind of card
- *        concerned only by official (or not) administration
- */
-/*!
- * \brief  class  admin are a specific kind of card
- */
-
-// Use the view vw_supplier
-//
-class Bank extends Fiche
-{
-
-    var $name;        /*!< $name name of the company */
-    var $street;      /*!< $street Street */
-    var $country;     /*!< $country Country */
-    var $cp;          /*!< $cp Zip code */
-    var $vat_number;  /*!< $vat_number vat number */
-
-    /*! \brief Constructor
-    /* only a db connection is needed */
-    function __construct($p_cn,$p_id=0)
-    {
-        $this->fiche_def_ref=FICHE_TYPE_FIN;
-        parent::__construct($p_cn,$p_id) ;
-    }
-
-
-
-}
-
-?>
diff --git a/include/class_contact.php b/include/class_contact.php
deleted file mode 100644
index 31bde74..0000000
--- a/include/class_contact.php
+++ /dev/null
@@ -1,143 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-// Copyright Author Dany De Bontridder address@hidden
-//!\brief class for the contact, contact are derived from fiche
-require_once NOALYSS_INCLUDE.'/class_fiche.php';
-require_once NOALYSS_INCLUDE.'/constant.php';
-require_once NOALYSS_INCLUDE.'/user_common.php';
-/*! \file
- * \brief Contact are a card which are own by a another card (customer, 
supplier...)
- */
-/*!
- * \brief Class contact (customer, supplier...)
- */
-
-class contact extends Fiche
-{
-    var $company; /*!< $company company of the contact 
(ad_id=ATTR_DEF_COMPANY)*/
-    /*!\brief constructor */
-    function contact($p_cn,$p_id=0)
-    {
-        $this->fiche_def_ref=FICHE_TYPE_CONTACT;
-        parent::__construct($p_cn,$p_id) ;
-        $this->company="";
-    }
-    /*!   Summary
-     **************************************************
-     * \brief  show the default screen
-     *
-     * \param  p_search (filter)
-     *
-     * \return string to display
-     */
-    function Summary($p_search="",$p_action="",$p_sql="",$p_nothing=false)
-    {
-        $p_search=sql_string($p_search);
-        $extra_sql="";
-        if ( $this->company != "")
-        {
-            $extra_sql="and f_id in (select f_id from fiche_detail
-                       where ad_value=upper('".$this->company."') and 
ad_id=".ATTR_DEF_COMPANY.") ";
-        }
-        $url=urlencode($_SERVER['REQUEST_URI']);
-        $script=$_SERVER['PHP_SELF'];
-        // Creation of the nav bar
-        // Get the max numberRow
-        
$all_contact=$this->count_by_modele($this->fiche_def_ref,$p_search,$extra_sql);
-        // Get offset and page variable
-        $offset=( isset ($_REQUEST['offset'] )) ?$_REQUEST['offset']:0;
-        $page=(isset($_REQUEST['page']))?$_REQUEST['page']:1;
-        
$bar=navigation_bar($offset,$all_contact,$_SESSION['g_pagesize'],$page);
-        // set a filter ?
-        $search="";
-        if ( trim($p_search) != "" )
-        {
-            $search=" and f_id in
-                    (select f_id from fiche_Detail
-                    where
-                    ad_id=1 and ad_value ~* '$p_search') ";
-        }
-        // Get The result Array
-        
$step_contact=$this->get_by_category($offset,$search.$extra_sql.$p_sql);
-
-               if ( $all_contact == 0 ) return "";
-        $r=$bar;
-        $r.='<table id="contact_tb" class="sortable">
-            <TR>
-            <th>Quick Code</th>
-            <th>Nom</th>
-            <th>Prénom</th>
-                       <th>Société</th>
-            <th>Téléphone</th>
-            <th>email</th>
-            <th>Fax</th>
-            </TR>';
-        $base=$_SERVER['PHP_SELF'];
-        // Compute the url
-        $url="";
-        $and="?";
-        $get=$_GET;
-        if ( isset ($get) )
-        {
-            foreach ($get as $name=>$value )
-            {
-                // we clean the parameter offset, step, page and size
-                if (  ! in_array($name,array('f_id','detail')))
-                {
-                    $url.=$and.$name."=".$value;
-                    $and="&";
-                }// if
-            }//foreach
-        }// if
-        $back_url=urlencode($_SERVER['REQUEST_URI']);
-        if ( sizeof ($step_contact ) == 0 )
-            return $r;
-        $idx=0;
-        foreach ($step_contact as $contact )
-        {
-            $l_company=new Fiche($this->cn);
-            
$l_company->get_by_qcode($contact->strAttribut(ATTR_DEF_COMPANY),false);
-            $l_company_name=$l_company->strAttribut(ATTR_DEF_NAME);
-            if ( $l_company_name == NOTFOUND ) $l_company_name="";
-            // add popup for detail
-            if ( $l_company_name !="")
-            {
-                               
$l_company_name=HtmlInput::card_detail($contact->strAttribut(ATTR_DEF_COMPANY),$l_company_name,'style="text-decoration:underline;"');
-            }
-            $tr=($idx%2==0)?' <tr class="odd">':'<tr class="even">';
-            $idx++;
-            $r.=$tr;
-            $qcode=$contact->strAttribut(ATTR_DEF_QUICKCODE);
-            $r.='<TD>'.HtmlInput::card_detail($qcode)."</TD>";
-            $r.="<TD>".$contact->strAttribut(ATTR_DEF_NAME)."</TD>";
-            $r.="<TD>".$contact->strAttribut(ATTR_DEF_FIRST_NAME)."</TD>";
-            $r.="<TD>".$l_company_name."</TD>";
-            $r.="<TD>".$contact->strAttribut(ATTR_DEF_TEL)."</TD>";
-            $r.="<TD>".$contact->strAttribut(ATTR_DEF_EMAIL)."</TD>".
-                "<TD> ".$contact->strAttribut(ATTR_DEF_FAX)."</TD>";
-
-            $r.="</TR>";
-
-        }
-        $r.="</TABLE>";
-        $r.=$bar;
-        return $r;
-    }
-
-}
diff --git a/include/class_customer.php b/include/class_customer.php
deleted file mode 100644
index 7545574..0000000
--- a/include/class_customer.php
+++ /dev/null
@@ -1,187 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-// Copyright Author Dany De Bontridder address@hidden
-require_once NOALYSS_INCLUDE.'/constant.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_acc_parm_code.php';
-require_once NOALYSS_INCLUDE.'/class_periode.php';
-require_once NOALYSS_INCLUDE.'/class_fiche.php';
-require_once NOALYSS_INCLUDE.'/class_acc_account_ledger.php';
-require_once NOALYSS_INCLUDE.'/user_common.php';
-/*! \file
- * \brief Derived from class fiche Customer are a specific kind of card
- */
-/*!
- * \brief  class  Customer are a specific kind of card
- */
-
-// Use the view vw_customer
-//
-class Customer extends Fiche
-{
-
-    var $poste;      /*!<  $poste poste comptable */
-    var $name;        /*!<  $name name of the company */
-    var $street;      /*!<  $street Street */
-    var $country;     /*!<  $country Country */
-    var $cp;          /*!<  $cp Zip code */
-    var $vat_number;  /*!<  $vat_number vat number */
-
-    /*! \brief Constructor
-    /* only a db connection is needed */
-    function __construct($p_cn,$p_id=0)
-    {
-        $this->fiche_def_ref=FICHE_TYPE_CLIENT;
-        parent::__construct($p_cn,$p_id) ;
-
-    }
-    /*! \brief  Get all info contains in the view
-     *  thanks to the poste elt (account)
-    */
-    function get_by_account($p_poste=0)
-    {
-        $this->poste=($p_poste==0)?$this->poste:$p_poste;
-        $sql="select * from vw_client where poste_comptable=$1";
-        $Res=$this->cn->exec_sql($sql,array($this->poste));
-        if ( Database::num_row($Res) == 0) return null;
-        if ( Database::num_row($Res) > 1 ) throw new Exception ('Plusieurs 
fiches avec le même poste',1);
-        // There is only _one_ row by customer
-        $row=Database::fetch_array($Res,0);
-        $this->name=$row['name'];
-        $this->id=$row['f_id'];
-        $this->street=$row['rue'];
-        $this->cp=$row['code_postal'];
-        $this->country=$row['pays'];
-        $this->vat_number=$row['tva_num'];
-
-    }
-    /*!
-     * \brief  Get all the info for making a vat listing
-     *           for the vat administration
-     *
-     * \param   $p_year
-     * 
-     * \return  double array structure is 
-     *            ( j_poste,name,vat_number,amount,tva,customer(object)
-     *
-     */
-    function VatListing($p_year)
-    {
-        $cond_sql=" and   A.j_date = B.j_date and extract(year from A.j_date) 
='$p_year'";
-        /* List of customer  */
-        $aCustomer=$this->cn->get_array('select 
f_id,name,quick_code,tva_num,poste_comptable from vw_client '.
-                                        " where tva_num !='' ");
-
-        /* Use the code */
-
-        // BASE ACCOUNT
-        // for belgium
-        $s=new Acc_Parm_Code($this->cn,'VENTE');
-        $s->load();
-        $SOLD=$s->p_value;
-
-        $c=new Acc_Parm_Code($this->cn,'CUSTOMER');
-        $c->load();
-        $CUSTOMER=$c->p_value;
-
-        $t=new Acc_Parm_Code($this->cn,'COMPTE_TVA');
-        $t->load();
-        $TVA=$t->p_value;
-
-        $a_Res=array();
-        /* for each customer compute VAT, Amount...*/
-        foreach ($aCustomer as $l )
-        {
-            // Seek the customer
-            //---
-            $customer=$l['quick_code'];
-            $a_Res[$customer]['name']=$l['name'];
-            $a_Res[$customer]['vat_number']=$l['tva_num'];
-            $a_Res[$customer]['amount']=0;
-            $a_Res[$customer]['tva']=0;
-            $a_Res[$customer]['poste_comptable']=$l['poste_comptable'];
-            /* retrieve only operation of sold and vat */
-            // Get all the sell operation
-            //----
-            $sql="select distinct j_grpt
-                 from
-                 jrnx as A
-                 join jrnx as B using (j_grpt)
-                 where
-                 A.j_qcode = '".$l['quick_code']."' and
-                 B.j_poste::text like '".$SOLD."%'
-                 $cond_sql
-                 ";
-
-            $Res=$this->cn->exec_sql($sql);
-            // Foreach operation
-            // where 7% or tva account are involved
-            // and store the result in an array (a_Res)
-            //---
-
-            for ($i=0; $i < Database::num_row($Res);$i++)
-            {
-                // Get each row
-                //---
-                $row1=Database::fetch_array($Res,$i);
-
-
-                // select the operation
-                //----
-                $Res2=$this->cn->exec_sql("select j_poste,j_montant,j_debit 
from jrnx where j_grpt=".$row1['j_grpt']);
-                $a_row=Database::fetch_all($Res2);
-
-                // Store the amount in the array
-                //---
-                foreach ($a_row as $e)
-                {
-                    $amount=0;
-                    $tva=0;
-                    if ( substr($e['j_poste'],0, strlen($SOLD))===$SOLD)
-                    {
-                        
$amount=($e['j_debit']=='f')?$e['j_montant']:$e['j_montant']*-1;
-                    }
-                    if ( substr($e['j_poste'],0, strlen($TVA))===$TVA)
-                    {
-                        
$tva=($e['j_debit']=='f')?$e['j_montant']:$e['j_montant']*-1;
-                    }
-                    // store sold
-                    //---
-                    
$a_Res[$customer]['amount']=(isset($a_Res[$customer]['amount']))?$a_Res[$customer]['amount']:0;
-                    $a_Res[$customer]['amount']+=$amount;
-
-                    // store vat
-                    //---
-                    
$a_Res[$customer]['tva']=(isset($a_Res[$customer]['tva']))?$a_Res[$customer]['tva']:0;
-                    $a_Res[$customer]['tva']+=$tva;
-
-                    // store customef info
-                    //---
-                    $a_Res[$customer]['customer']=$customer;
-                }
-            }// foreach $a
-        } // foreach ( customer)
-
-        return $a_Res;
-    }
-
-
-}
-
-?>
diff --git a/include/class_database.php b/include/class_database.php
deleted file mode 100644
index 9b87e70..0000000
--- a/include/class_database.php
+++ /dev/null
@@ -1,1051 +0,0 @@
-<?php
-
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/**\file
- * \brief contains the class for connecting to a postgresql database
- */
-require_once NOALYSS_INCLUDE.'/constant.php';
-require_once NOALYSS_INCLUDE.'/ac_common.php';
-
-/**\brief
- * This class allow you to connect to the postgresql database, execute sql, 
retrieve data
- *
- */
-
-class Database
-{
-
-    private $db;    /**< database connection */
-    private $ret;   /**< return value  */
-    private $is_open;                   /*!< true is connected */
-    /**\brief constructor
-     * \param $p_database_id is the id of the dossier, or the modele following 
the
-     * p_type if = 0 then connect to the repository
-     * \param $p_type is 'DOS' (defaut) for dossier or 'MOD'
-     */
-
-    function __construct($p_database_id=0, $p_type='dos')
-    {
-        if (IsNumber($p_database_id)==false||strlen($p_database_id)>5)
-            die("-->Dossier invalide [$p_database_id]");
-        $noalyss_user=(defined("noalyss_user"))?noalyss_user:phpcompta_user;
-        
$password=(defined("noalyss_password"))?noalyss_password:phpcompta_password;
-        
$port=(defined("noalyss_psql_port"))?noalyss_psql_port:phpcompta_psql_port;
-        $host=(!defined("noalyss_psql_host") )?'127.0.0.1':noalyss_psql_host;
-        if (defined("MULTI")&&MULTI=="0")
-        {
-            $l_dossier=dbname;
-        }
-        else
-        {
-
-            if ($p_database_id==0)
-            { /* connect to the repository */
-                $l_dossier=sprintf("%saccount_repository", 
strtolower(domaine));
-            }
-            else if ($p_type=='dos')
-            { /* connect to a folder (dossier) */
-                $l_dossier=sprintf("%sdossier%d", strtolower(domaine), 
$p_database_id);
-            }
-            else if ($p_type=='mod')
-            { /* connect to a template (modele) */
-                $l_dossier=sprintf("%smod%d", strtolower(domaine), 
$p_database_id);
-            }
-            else if ($p_type=='template')
-            {
-                $l_dossier='template1';
-            }
-            else
-            {
-                throw new Exception('Connection invalide');
-            }
-        }
-
-        ob_start();
-        $a=pg_connect("dbname=$l_dossier host='$host' user='$noalyss_user'
-                      password='$password' port=$port");
-
-        if ($a==false)
-        {
-            if (DEBUG)
-            {
-                ob_end_clean();
-                echo '<h2 class="error">Impossible de se connecter &agrave; 
postgreSql !</h2>';
-                echo '<p>';
-                echo "Vos param&egrave;tres sont incorrectes : <br>";
-                echo "<br>";
-                echo "base de donn&eacute;e : $l_dossier<br>";
-                echo "Domaine : ".domaine."<br>";
-                echo "Port $port <br>";
-                echo "Utilisateur : $noalyss_user <br>";
-                echo '</p>';
-
-                die("Connection impossible : v&eacute;rifiez vos 
param&egrave;tres de base
-                  de donn&eacute;es");
-            }
-            else
-            {
-                echo '<h2 class="error">Erreur de connexion !</h2>';
-            }
-        }
-        $this->db=$a;
-        $this->is_open=TRUE;
-        if ($this->exist_schema('comptaproc'))
-        pg_exec($this->db, 'set search_path to public,comptaproc;');
-        pg_exec($this->db, 'set DateStyle to ISO, MDY;');
-        ob_end_clean();
-    }
-
-    public function verify()
-    {
-        // Verify that the elt we want to add is correct
-    }
-
-    function set_encoding($p_charset)
-    {
-        pg_set_client_encoding($this->db, $p_charset);
-    }
-
-    /**
-     * \brief send a sql string to the database
-     * \param $p_string     sql string
-     * \param $p_array array for the SQL string (see pg_query_params)
-     * \return the result of the query, a resource or false if an
-     * error occured
-     */
-
-    function exec_sql($p_string, $p_array=null)
-    {
-        try
-        {
-            if ( ! $this->is_open ) throw new Exception(' Database is closed');
-            $this->sql=$p_string;
-            $this->array=$p_array;
-
-            if ($p_array==null)
-            {
-                if (!DEBUG)
-                    $this->ret=pg_query($this->db, $p_string);
-                else
-                    $this->address@hidden($this->db, $p_string);
-            }
-            else
-            {
-                $a=is_array($p_array);
-                if (!is_array($p_array))
-                {
-                    throw new Exception("Erreur : exec_sql attend un array");
-                }
-                if (!DEBUG) 
-                    $this->ret=pg_query_params($this->db, $p_string, $p_array);
-                else
-                    $this->address@hidden($this->db, $p_string, $p_array);
-            }
-            if (!$this->ret)
-            {
-                
$str_error=pg_last_error($this->db).pg_result_error($this->ret);
-                throw new Exception("  SQL ERROR $p_string ".$str_error, 1);
-            }
-        }
-        catch (Exception $a)
-        {
-            if (DEBUG)
-            {
-                print_r($p_string);
-                print_r($p_array);
-                echo $a->getMessage();
-                echo $a->getTrace();
-                echo $a->getTraceAsString();
-                echo pg_last_error($this->db);
-            }
-            $this->rollback();
-            
-            throw ($a);
-        }
-
-        return $this->ret;
-    }
-
-    /** \brief Count the number of row returned by a sql statement
-     *
-     * \param $p_sql sql string
-     * \param $p_array if not null we use the safer pg_query_params
-     */
-
-    function count_sql($p_sql, $p_array=null)
-    {
-        $r_sql=$this->exec_sql($p_sql, $p_array);
-        return pg_NumRows($r_sql);
-    }
-
-    /**\brief get the current sequence value
-     */
-
-    function get_current_seq($p_seq)
-    {
-        $Res=$this->get_value("select currval('$p_seq') as seq");
-        return $Res;
-    }
-
-    /**\brief  get the next sequence value
-     */
-
-    function get_next_seq($p_seq)
-    {
-        $Res=$this->exec_sql("select nextval('$p_seq') as seq");
-        $seq=pg_fetch_array($Res, 0);
-        return $seq['seq'];
-    }
-
-    /**
-     * @ brief : start a transaction
-     *
-     */
-    function start()
-    {
-        $Res=$this->exec_sql("start transaction");
-    }
-
-    /**
-     * Commit the transaction
-     *
-     */
-    function commit()
-    {
-        if ( ! $this->is_open) return;
-        $Res=$this->exec_sql("commit");
-    }
-
-    /**
-     * rollback the current transaction
-     */
-    function rollback()
-    {
-        if ( ! $this->is_open) return;
-        $Res=$this->exec_sql("rollback");
-    }
-
-    /**
-     * @brief alter the sequence value
-     * @param $p_name name of the sequence
-     * @param $min the start value of the sequence
-     */
-    function alter_seq($p_name, $min)
-    {
-        if ($min<1)
-            $min=1;
-        $Res=$this->exec_sql("alter sequence $p_name restart $min");
-    }
-
-    /**
-     * \brief Execute a sql script
-     * \param $script script name
-     */
-
-    function execute_script($script)
-    {
-
-        if (!DEBUG)
-            ob_start();
-        $hf=fopen($script, 'r');
-        if ($hf==false)
-        {
-            throw new Exception ( 'Ne peut ouvrir '.$script);
-        }
-        $sql="";
-        $flag_function=false;
-        while (!feof($hf))
-        {
-            $buffer=fgets($hf);
-            $buffer=str_replace("$", "\$", $buffer);
-            print $buffer."<br>";
-            // comment are not execute
-            if (substr($buffer, 0, 2)=="--")
-            {
-                //echo "comment $buffer";
-                continue;
-            }
-            // Blank Lines Are Skipped
-            If (Strlen($buffer)==0)
-            {
-                //echo "Blank $buffer";
-                Continue;
-            }
-            if (strpos(strtolower($buffer), "create function")===0)
-            {
-                echo "found a function";
-                $flag_function=true;
-                $sql=$buffer;
-                continue;
-            }
-            if (strpos(strtolower($buffer), "create or replace function")===0)
-            {
-                echo "found a function";
-                $flag_function=true;
-                $sql=$buffer;
-                continue;
-            }
-            // No semi colon -> multiline command
-            if ($flag_function==false&&strpos($buffer, ';')==false)
-            {
-                $sql.=$buffer;
-                continue;
-            }
-            if ($flag_function)
-            {
-                if (strpos(strtolower($buffer), "language plpgsql")===false&&
-                        strpos(strtolower($buffer), "language 
'plpgsql'")===false)
-                {
-                    $sql.=$buffer;
-                    continue;
-                }
-            }
-            else
-            {
-                // cut the semi colon
-                $buffer=str_replace(';', '', $buffer);
-            }
-            $sql.=$buffer;
-            if ($this->exec_sql($sql)==false)
-            {
-                $this->rollback();
-                if (!DEBUG)
-                    ob_end_clean();
-                print "ERROR : $sql";
-                throw new Exception("ERROR : $sql");
-            }
-            $sql="";
-            $flag_function=false;
-            print "<hr>";
-        } // while (feof)
-        fclose($hf);
-        if (!DEBUG)
-            ob_end_clean();
-    }
-
-    /**
-     * \brief Get version of a database, the content of the
-     *        table version
-     *
-     * \return version number
-     *
-     */
-
-    function get_version()
-    {
-        $Res=$this->get_value("select val from version");
-        return $Res;
-    }
-
-    /**
-     * @brief fetch the $p_indice array from the last query
-     * @param $p_indice index
-     *
-     */
-    function fetch($p_indice)
-    {
-        if ($this->ret==false)
-            throw new Exception('this->ret is empty');
-        return pg_fetch_array($this->ret, $p_indice);
-    }
-
-    /**
-     * 
-     * @brief return the number of rows found by the last query, or the number
-     * of rows from $p_ret
-     * @param $p_ret is the result of a query, the default value is null, in 
that case
-     * it is related to the last query
-     * @note synomym for count()
-     */
-
-    function size($p_ret=null)
-    {
-        if ($p_ret==null)
-            return pg_NumRows($this->ret);
-        else
-            return pg_NumRows($p_ret);
-    }
-
-    /**
-     * @brief       synomym for size() 
-     */
-
-    function count($p_ret=null)
-    {
-        return $this->size($p_ret);
-    }
-
-    /**
-     * \brief loop to apply all the path to a folder or
-     *         a template
-     * \param $p_name database name
-     * \param $from_setup == 1 if called from setup.php
-     *
-     */
-
-    function apply_patch($p_name, $from_setup=1)
-    {
-        if ( ! $this->exist_table('version')) {
-            echo _('Base de donnée vide');
-            return;
-        }
-        $MaxVersion=DBVERSION-1;
-        $succeed="<span style=\"font-size:18px;color:green\">&#x2713;</span>";
-        echo '<ul style="list-type-style:square">';
-        $add=($from_setup==0)?'admin/':'';
-        for ($i=4; $i<=$MaxVersion; $i++)
-        {
-            $to=$i+1;
-
-            if ($this->get_version()<=$i)
-            {
-                if ($this->get_version()==97)
-                {
-                    if ($this->exist_schema("amortissement"))
-                    {
-                        $this->exec_sql('ALTER TABLE 
amortissement.amortissement_histo
-                                                       ADD CONSTRAINT 
internal_fk FOREIGN KEY (jr_internal) REFERENCES jrn (jr_internal)
-                                                       ON UPDATE CASCADE ON 
DELETE SET NULL');
-                    }
-                }
-                echo "<li>Patching ".$p_name.
-                " from the version ".$this->get_version()." to $to ";
-
-                $this->execute_script($add.'sql/patch/upgrade'.$i.'.sql');
-                echo $succeed;
-
-                if (!DEBUG)
-                    ob_start();
-                // specific for version 4
-                if ($i==4)
-                {
-                    $sql="select jrn_def_id from jrn_def ";
-                    $Res=$this->exec_sql($sql);
-                    $Max=$this->size();
-                    for ($seq=0; $seq<$Max; $seq++)
-                    {
-                        $row=pg_fetch_array($Res, $seq);
-                        $sql=sprintf("create sequence s_jrn_%d", 
$row['jrn_def_id']);
-                        $this->exec_sql($sql);
-                    }
-                }
-                // specific to version 7
-                if ($i==7)
-                {
-                    // now we use sequence instead of computing a max
-                    //
-                    $Res2=$this->exec_sql('select coalesce(max(jr_grpt_id),1) 
as l from jrn');
-                    $Max2=pg_NumRows($Res2);
-                    if ($Max2==1)
-                    {
-                        $Row=pg_fetch_array($Res2, 0);
-                        var_dump($Row);
-                        $M=$Row['l'];
-                        $this->exec_sql("select setval('s_grpt',$M,true)");
-                    }
-                }
-                // specific to version 17
-                if ($i==17)
-                {
-                    $this->execute_script($add.'sql/patch/upgrade17.sql');
-                    $max=$this->get_value('select last_value from 
s_jnt_fic_att_value');
-                    $this->alter_seq($p_cn, 's_jnt_fic_att_value', $max+1);
-                } // version
-                // reset sequence in the modele
-                //--
-                if ($i==30&&$p_name=="mod")
-                {
-                    $a_seq=array('s_jrn', 's_jrn_op', 's_centralized',
-                        's_stock_goods', 'c_order', 's_central');
-                    foreach ($a_seq as $seq)
-                    {
-                        $sql=sprintf("select setval('%s',1,false)", $seq);
-                        $Res=$this->exec_sql($sql);
-                    }
-                    $sql="select jrn_def_id from jrn_def ";
-                    $Res=$this->exec_sql($sql);
-                    $Max=pg_NumRows($Res);
-                    for ($seq=0; $seq<$Max; $seq++)
-                    {
-                        $row=pg_fetch_array($Res, $seq);
-                        $sql=sprintf("select setval('s_jrn_%d',1,false)", 
$row['jrn_def_id']);
-                        $this->exec_sql($sql);
-                    }
-                }
-                if ($i==36)
-                {
-                    /* check the country and apply the path */
-                    $res=$this->exec_sql("select pr_value from parameter where 
pr_id='MY_COUNTRY'");
-                    $country=pg_fetch_result($res, 0, 0);
-                    
$this->execute_script($add."sql/patch/upgrade36.".$country.".sql");
-                    $this->exec_sql('update tmp_pcmn set 
pcm_type=find_pcm_type(pcm_val)');
-                }
-                if ($i==59)
-                {
-                    $res=$this->exec_sql("select pr_value from parameter where 
pr_id='MY_COUNTRY'");
-                    $country=pg_fetch_result($res, 0, 0);
-                    if ($country=='BE')
-                        $this->exec_sql("insert into parm_code values 
('SUPPLIER',440,'Poste par défaut pour les fournisseurs')");
-                    if ($country=='FR')
-                        $this->exec_sql("insert into parm_code values 
('SUPPLIER',400,'Poste par défaut pour les fournisseurs')");
-                }
-                if ($i==61)
-                {
-                    $country=$this->get_value("select pr_value from parameter 
where pr_id='MY_COUNTRY'");
-                    
$this->execute_script($add."sql/patch/upgrade61.".$country.".sql");
-                }
-
-                if (!DEBUG)
-                    ob_end_clean();
-            }
-        }
-        echo '</ul>';
-    }
-
-    /**
-     * 
-     * \brief return the value of the sql, the sql will return only one value
-     *        with the value
-     * \param $p_sql the sql stmt example :select s_value from
-      document_state where s_id=2
-     * \param $p_array if array is not null we use the ExecSqlParm (safer)
-     * \see exec_sql
-     * \note print a warning if several value are found, if only the first 
value is needed
-     * consider using a LIMIT clause
-     * \return only the first value or an empty string if nothing is found
-     */
-
-    function get_value($p_sql, $p_array=null)
-    {
-        $this->ret=$this->exec_sql($p_sql, $p_array);
-        $r=pg_NumRows($this->ret);
-        if ($r==0)
-            return "";
-        if ($r>1)
-        {
-            $array=pg_fetch_all($this->ret);
-            throw new Exception("Attention $p_sql retourne 
".pg_NumRows($this->ret)."  valeurs ".
-            var_export($p_array, true)." values=".var_export($array, true));
-        }
-        $r=pg_fetch_row($this->ret, 0);
-        return $r[0];
-    }
-    /**
-     * @brief return the number of rows affected by the previous query
-     */
-    function get_affected()
-    {
-        return Database::num_row($this->ret);
-    }
-
-    /**
-     * \brief  purpose return the result of a sql statment
-     * in a array
-     * \param $p_sql sql query
-     * \param $p_array if not null we use ExecSqlParam
-     * \return an empty array if nothing is found
-     */
-
-    function get_array($p_sql, $p_array=null)
-    {
-        $r=$this->exec_sql($p_sql, $p_array);
-
-        if (($Max=pg_NumRows($r))==0)
-            return array();
-        $array=pg_fetch_all($r);
-        return $array;
-    }
-
-    function create_sequence($p_name, $min=1)
-    {
-        if ($min<1)
-            $min=1;
-        $sql="create sequence ".$p_name." minvalue $min";
-        $this->exec_sql($sql);
-    }
-
-    /**
-     * \brief test if a sequence exist */
-    /* \return true if the seq. exist otherwise false
-     */
-
-    function exist_sequence($p_name)
-    {
-        $r=$this->count_sql("select relname from pg_class where 
relname=lower($1)", array($p_name));
-        if ($r==0)
-            return false;
-        return true;
-    }
-
-    /**\brief test if a table exist
-     * \param $p_name table name
-     * \param  $schema name of the schema default public
-     * \return true if a table exist otherwise false
-     */
-
-    function exist_table($p_name, $p_schema='public')
-    {
-        $r=$this->count_sql("select table_name from information_schema.tables 
where table_schema=$1 and table_name=lower($2)", array($p_schema, $p_name));
-        if ($r==0)
-            return false;
-        return true;
-    }
-
-    /**
-     * Check if a column exists in a table
-     * @param $col : column name
-     * @param $table :table name
-     * @param $schema :schema name, default public
-     * @return true or false
-     */
-    function exist_column($col, $table, $schema)
-    {
-        $r=$this->get_value('select count(*) from information_schema.columns 
where table_name=lower($1) and column_name=lower($2) and 
table_schema=lower($3)', array($col, $table, $schema));
-        if ($r>0)
-            return true;
-        return false;
-    }
-
-    /**
-     * return the name of the database with the domain name
-     * @param $p_id of the folder WITHOUT the domain name
-     * @param $p_type dos for folder mod for template
-     * @return formatted name
-     */
-    function format_name($p_id, $p_type)
-    {
-        switch ($p_type)
-        {
-            case 'dos':
-                $sys_name=sprintf("%sdossier%d", strtolower(domaine), $p_id);
-                break;
-            case 'mod':
-                $sys_name=sprintf("%smod%d", strtolower(domaine), $p_id);
-                break;
-            default:
-                echo_error(__FILE__." format_name invalid type ".$p_type, 
__LINE__);
-                throw new Exception(__FILE__." format_name invalid type 
".$p_type. __LINE__);
-        }
-        return $sys_name;
-    }
-
-    /**
-     * Count the database name in a system view
-     * @param $p_name string database name
-     * @return number of database found (normally 0 or 1)
-     */
-    function exist_database($p_name)
-    {
-        $database_exist=$this->get_value('select count(*)
-                from pg_catalog.pg_database where datname = lower($1)', 
array($p_name));
-        return $database_exist;
-    }
-
-    /**
-     * @brief check if the large object exists
-     * @param $p_oid of the large object
-     * @return return true if the large obj exist or false if not
-     */
-    function exist_blob($p_oid)
-    {
-        $r=$this->get_value('select count(loid) from pg_largeobject where 
loid=$1'
-                , array($p_oid));
-        if ($r>0)
-            return true;
-        else
-            return false;
-    }
-
-    /*
-     * !\brief test if a view exist
-     * \return true if the view. exist otherwise false
-     */
-
-    function exist_view($p_name)
-    {
-        $r=$this->count_sql("select viewname from pg_views where 
viewname=lower($1)", array($p_name));
-        if ($r==0)
-            return false;
-        return true;
-    }
-
-    /*
-     * !\brief test if a schema exists
-     * \return true if the schemas exists otherwise false
-     */
-
-    function exist_schema($p_name)
-    {
-        $r=$this->count_sql("select nspname from pg_namespace where 
nspname=lower($1)", array($p_name));
-        if ($r==0)
-            return false;
-        return true;
-    }
-
-    /**
-     * \brief create a string containing the value separated by comma
-     * for use in a SQL in statement
-     * \return the string or empty if nothing is found
-     * \see fid_card.php
-     */
-
-    function make_list($sql, $p_array=null)
-    {
-        if ($p_array==null)
-        {
-            $aArray=$this->get_array($sql);
-        }
-        else
-        {
-            $aArray=$this->get_array($sql, $p_array);
-        }
-        if (empty($aArray))
-            return "";
-        $aIdx=array_keys($aArray[0]);
-        $idx=$aIdx[0];
-        $ret="";
-        $f="";
-        for ($i=0; $i<count($aArray); $i++)
-        {
-            $row=$aArray[$i];
-            $ret.=$f.$aArray[$i][$idx];
-            $f=',';
-        }
-        $ret=trim($ret, ',');
-        return $ret;
-    }
-
-    /**
-     * \brief make a array with the sql.
-     *
-     * \param $p_sql  sql statement, only the first two column will be 
returned in
-     *  an array. The first col. is the label and the second the value
-     *  \param $p_null if the array start with a null value
-     *  \param $p_array is the array with the bind value
-     * \note this function is used with ISelect when it is needed to have a 
list of
-     * options.
-     * \return: a double array like
-      \verbatim
-      Array
-      (
-        [0] => Array
-                (
-                [value] => 1
-                [label] => Marchandise A
-               )
-
-      [1] => Array
-            (
-            [value] => 2
-            [label] => Marchandise B
-            )
-
-      [2] => Array
-            (
-            [value] => 3
-            [label] => Marchandise C
-            )
-      )
-      \endverbatim
-     * \see ISelect
-     */
-
-    function make_array($p_sql, $p_null=0,$p_array=null)
-    {
-        $a=$this->exec_sql($p_sql,$p_array);
-        $max=pg_NumRows($a);
-        if ($max==0&&$p_null==0)
-            return null;
-        for ($i=0; $i<$max; $i++)
-        {
-            $row=pg_fetch_row($a);
-            $r[$i]['value']=$row[0];
-            $r[$i]['label']=h($row[1]);
-        }
-        // add a blank item ?
-        if ($p_null==1)
-        {
-            for ($i=$max; $i!=0; $i--)
-            {
-                $r[$i]['value']=$r[$i-1]['value'];
-                $r[$i]['label']=h($r[$i-1]['label']);
-            }
-            $r[0]['value']=-1;
-            $r[0]['label']=" ";
-        } //   if ( $p_null == 1 )
-
-        return $r;
-    }
-
-    /**
-     * \brief Save a "piece justificative"
-     *
-     * \param $seq jr_grpt_id
-     * \return $oid of the lob file if success
-     *         null if a error occurs
-     *
-     */
-
-    function save_upload_document($seq)
-    {
-        /* there is
-          no file to
-          upload */
-        if ($_FILES["pj"]["error"]==UPLOAD_ERR_NO_FILE)
-        {
-            return;
-        }
-
-        $new_name=tempnam($_ENV['TMP'], 'pj');
-        if ($_FILES["pj"]["error"]>0)
-        {
-            print_r($_FILES);
-            echo_error(__FILE__.":".__LINE__."Error: ".$_FILES["pj"]["error"]);
-        }
-        if (strlen($_FILES['pj']['tmp_name'])!=0)
-        {
-            if (move_uploaded_file($_FILES['pj']['tmp_name'], $new_name))
-            {
-                // echo "Image saved";
-                $oid=pg_lo_import($this->db, $new_name);
-                if ($oid==false)
-                {
-                    echo_error('postgres.php', __LINE__, "cannot upload 
document");
-                    $this->rollback();
-                    return;
-                }
-                // Remove old document
-                $ret=$this->exec_sql("select jr_pj from jrn where 
jr_grpt_id=$seq");
-                if (pg_num_rows($ret)!=0)
-                {
-                    $r=pg_fetch_array($ret, 0);
-                    $old_oid=$r['jr_pj'];
-                    if (strlen($old_oid)!=0)
-                        pg_lo_unlink($cn, $old_oid);
-                }
-                // Load new document
-               $this->exec_sql("update jrn set jr_pj=$1 , jr_pj_name=$2,
-                                        jr_pj_type=$3  where jr_grpt_id=$4",
-                                        array($oid,$_FILES['pj']['name'] 
,$_FILES['pj']['type'],$seq));
-                return $oid;
-            }
-            else
-            {
-                echo "<H1>Error</H1>";
-                $this->rollback();
-            }
-        }
-        return 0;
-    }
-
-    /**\brief wrapper for the function pg_NumRows
-     * \param $ret is the result of a exec_sql
-     * \return number of line affected
-     */
-
-    static function num_row($ret)
-    {
-        return pg_NumRows($ret);
-    }
-
-    /**\brief wrapper for the function pg_fetch_array
-     * \param $ret is the result of a pg_exec
-     * \param $p_indice is the index
-     * \return $array of column
-     */
-
-    static function fetch_array($ret, $p_indice=0)
-    {
-        return pg_fetch_array($ret, $p_indice);
-    }
-
-    /**\brief wrapper for the function pg_fetch_all
-     * \param $ret is the result of pg_exec (exec_sql)
-     * \return double array (row x col )
-     */
-
-    static function fetch_all($ret)
-    {
-        return pg_fetch_all($ret);
-    }
-
-    /**\brief wrapper for the function pg_fetch_all
-     * \param $ret is the result of pg_exec (exec_sql)
-     * \param $p_row is the indice of the row
-     * \param $p_col is the indice of the col
-     * \return a string or an integer
-     */
-
-    static function fetch_result($ret, $p_row=0, $p_col=0)
-    {
-        return pg_fetch_result($ret, $p_row, $p_col);
-    }
-
-    /**\brief wrapper for the function pg_fetch_row
-     * \param $ret is the result of pg_exec (exec_sql)
-     * \param $p_row is the indice of the row
-     * \return an array indexed from 0
-     */
-
-    static function fetch_row($ret, $p_row)
-    {
-        return pg_fetch_row($ret, $p_row);
-    }
-
-    /**\brief wrapper for the function pg_lo_unlink
-     * \param $p_oid is the of oid
-     * \return return the result of the operation
-     */
-
-    function lo_unlink($p_oid)
-    {
-        return pg_lo_unlink($this->db, $p_oid);
-    }
-
-    /**\brief wrapper for the function pg_prepare
-     * \param $p_string string name for pg_prepare function
-     * \param $p_sql  is the sql to prepare
-     * \return return the result of the operation
-     */
-
-    function prepare($p_string, $p_sql)
-    {
-        return pg_prepare($this->db, $p_string, $p_sql);
-    }
-
-    /**\brief wrapper for the function pg_execute
-     * \param $p_string string name of the stmt given in pg_prepare function
-     * \param $p_array contains the variables
-     * \note set this->ret to the return of pg_execute
-     * \return return the result of the operation,
-     */
-
-    function execute($p_string, $p_array)
-    {
-        $this->ret=pg_execute($this->db, $p_string, $p_array);
-        return $this->ret;
-    }
-
-    /**\brief wrapper for the function pg_lo_export
-     * \param $p_oid is the oid of the log
-     * \param $tmp  is the file
-     * \return result of the operation
-     */
-
-    function lo_export($p_oid, $tmp)
-    {
-        return pg_lo_export($this->db, $p_oid, $tmp);
-    }
-
-    /**\brief wrapper for the function pg_lo_export
-     * \param $p_oid is the oid of the log
-     * \param $tmp  is the file
-     * \return result of the operation
-     */
-
-    function lo_import($p_oid)
-    {
-        return pg_lo_import($this->db, $p_oid);
-    }
-
-    /**\brief wrapper for the function pg_escape_string
-     * \param $p_string is the string to escape
-     * \return escaped string
-     */
-
-    static function escape_string($p_string)
-    {
-        return pg_escape_string($p_string);
-    }
-
-    /**\brief wrapper for the function pg_close
-     */
-
-    function close()
-    {
-        if ( $this->is_open ) pg_close($this->db);
-        $this->is_open=FALSE;
-    }
-
-    /**\brief
-     * \param
-     * \return
-     * \note
-     * \see
-     */
-
-    function __toString()
-    {
-        return "database ";
-    }
-
-    static function test_me()
-    {
-        
-    }
-
-    function status()
-    {
-        return pg_transaction_status($this->db);
-    }
-
-    /**
-     * with the handle of a successull query, echo each row into CSV and
-     * send it directly
-     * @param type $ret handle to a query
-     * @param type $aheader  double array, each item of the array contains
-     * a key type (num) and a key title
-     */
-    function query_to_csv($ret, $aheader)
-    {
-        $seq="";
-        for ($i=0; $i<count($aheader); $i++)
-        {
-            echo $seq.'"'.$aheader[$i]['title'].'"';
-            $seq=";";
-        }
-        printf("\n\r");
-        // fetch all the rows
-        for ($i=0; $i<Database::num_row($ret); $i++)
-        {
-            $row=Database::fetch_array($ret, $i);
-            $sep2="";
-            // for each rows, for each value
-            for ($e=0; $e<count($row)/2; $e++)
-            {
-                switch ($aheader[$e]['type'])
-                {
-                    case 'num':
-                        echo $sep2.nb($row[$e]);
-                        break;
-                    default:
-                        echo $sep2.'"'.$row[$e].'"';
-                }
-                $sep2=";";
-            }
-            printf("\n\r");
-        }
-    }
-
-}
-
-/* test::test_me(); */
diff --git a/include/class_default_menu.php b/include/class_default_menu.php
deleted file mode 100644
index 4c6d32f..0000000
--- a/include/class_default_menu.php
+++ /dev/null
@@ -1,153 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-// Copyright Author Dany De Bontridder address@hidden
-
-/**
- * Description of class_default_menu
- *
- * @author dany
- */
-require_once NOALYSS_INCLUDE.'/class_default_menu_sql.php';
-require_once NOALYSS_INCLUDE.'/class_itext.php';
-
-class Default_Menu
-{
-
-    /**
-     * $a_menu_def is an array of Default_Menu_SQL
-     */
-    private $a_menu_def;
-
-    /**
-     * Possible value
-     */
-    private $code; // array with the valid code
-
-    function __construct()
-    {
-        global $cn;
-        $menu = new Default_Menu_SQL($cn);
-        $ret = $menu->seek();
-        for ($i = 0; $i < Database::num_row($ret); $i++)
-        {
-            $tmenu = $menu->next($ret, $i);
-            $idx = $tmenu->getp('md_code');
-            $this->a_menu_def[$idx] = $tmenu->getp('me_code');
-        }
-        $this->code = explode(',', 'code_follow,code_invoice');
-    }
-
-    function input_value()
-    {
-        $code_invoice = new IText('code_invoice', 
$this->a_menu_def['code_invoice']);
-        $code_follow = new IText('code_follow', 
$this->a_menu_def['code_follow']);
-        echo '<p>' . _('Code pour création facture depuis gestion') . 
$code_invoice->input() . '</p>';
-        echo '<p>' . _('Code pour appel gestion') . $code_follow->input() . 
'</p>';
-    }
-
-    private function check_code($p_string)
-    {
-        global $cn;
-        $count = $cn->get_value('select count(*) from 
v_menu_description_favori where '
-                . 'code = $1', array($p_string));
-        if ($count == 0)
-        {
-            throw new Exception('code_inexistant');
-        }
-    }
-
-    function verify()
-    {
-        foreach ($this->code as $code)
-        {
-            $this->check_code($this->a_menu_def[$code]);
-        }
-    }
-
-    function set($p_string, $p_value)
-    {
-        if (in_array($p_string, $this->code) == false)
-        {
-            throw new Exception("code_invalid");
-        }
-        $this->a_menu_def[$p_string] = $p_value;
-    }
-    function get ($p_string)
-    {
-        return $this->a_menu_def[$p_string];
-    }
-
-    function save()
-    {
-        global $cn;
-        try
-        {
-            $this->verify();
-            foreach ($this->code as $key => $value)
-            {
-                $cn->exec_sql('update menu_default set me_code=$1 where
-                        md_code =$2', array($value,$this->a_menu_def[$value]));
-            }
-        } catch (Exception $e)
-        {
-            $e->getTraceAsString();
-            throw $e;
-        }
-    }
-
-    static function test_me()
-    {
-        global $cn, $g_user, $g_succeed, $g_failed;
-
-        echo h2('Constructor', '');
-        $a = new Default_Menu();
-        echo $g_succeed . 'constructor';
-        if (count($a->a_menu_def) != 2)
-            echo $g_failed;
-        else
-            echo $g_succeed;
-        echo h2("input_value", "");
-        $a->input_value();
-        echo h2('verify');
-        $a->verify();
-        try {
-            echo h2('Verify must failed');
-            $a->set('code_follow', 'MEMNU/MEMEM/');
-            $a->verify();   
-        } catch (Exception $e) {
-            echo $g_succeed. " OK ";
-        }
-        echo h2('Verify must succeed');
-        try {
-            $a->set('code_follow', 'GESTION/FOLLOW');
-            $a->verify();
-            echo $g_succeed. " OK ";
-        } catch (Exception $e)
-        {
-            echo $g_failed."NOK";
-        }
-        echo h2('Save');
-        $a->save();
-        echo h2('GET');
-        echo ( assert($a->get('code_follow')=='GESTION/FOLLOW') 
)?$g_succeed.$a->get('code_follow'):$g_failed.$a->get('code_follow');
-        echo ( assert($a->get('code_invoice')=='COMPTA/VENMENU/VEN') 
)?$g_succeed.$a->get('code_invoice'):$g_failed.$a->get('code_invoice');
-        echo $a->get('code_invoice');
-    }
-
-}
diff --git a/include/class_default_menu_sql.php 
b/include/class_default_menu_sql.php
deleted file mode 100644
index 38292e1..0000000
--- a/include/class_default_menu_sql.php
+++ /dev/null
@@ -1,57 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-// Copyright Author Dany De Bontridder address@hidden
-
-/**
- * Description of class_default_menu_sql
- *
- * @author dany
- */
-require_once NOALYSS_INCLUDE.'/class_noalyss_sql.php';
-
-class Default_Menu_SQL extends Noalyss_SQL
-{
-    var $md_id;
-    var $md_code;
-    var $me_code;
-
-    function __construct(&$p_cn, $p_id = -1)
-    {
-        $this->table = "public.menu_default";
-        $this->primary_key = "md_id";
-
-        $this->name = array(
-            "md_id"=>"md_id",
-            "md_code" => "md_code",
-            "me_code" => "me_code"
-        );
-        $this->type = array(
-            "md_id"=>"md_id"
-            ,"md_code" => "text"
-            , "me_code" => "text"
-        );
-        $this->default = array(
-            "md_id"
-        );
-        global $cn;
-
-        parent::__construct($cn, $p_id);
-    }
-
-}
diff --git a/include/class_document.php b/include/class_document.php
deleted file mode 100644
index 7acaf91..0000000
--- a/include/class_document.php
+++ /dev/null
@@ -1,1285 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-// Copyright Author Dany De Bontridder address@hidden
-require_once NOALYSS_INCLUDE.'/class_own.php';
-require_once NOALYSS_INCLUDE.'/class_acc_account_ledger.php';
-require_once NOALYSS_INCLUDE.'/class_follow_up.php';
-require_once NOALYSS_INCLUDE.'/class_acc_tva.php';
-require_once NOALYSS_INCLUDE.'/class_user.php';
-require_once NOALYSS_INCLUDE.'/class_zip_extended.php';
-
-/*! \file
- * \brief Class Document corresponds to the table document
- */
-/*! \brief Class Document corresponds to the table document
- */
-class Document
-{
-    var $db;          /*!< $db Database connexion*/
-    var $d_id;        /*!< $d_id Document id */
-    var $ag_id;       /*!< $ag_id action_gestion.ag_id (pk) */
-    var $d_mimetype;  /*!< $d_mimetype  */
-    var $d_filename;  /*!< $d_filename */
-    var $d_lob;       /*!< $d_lob the oid of the lob */
-    var $d_description;       /*!< Description of the file*/
-    var $d_number;    /*!< $d_number number of the document */
-    var $md_id;       /*!< $md_id document's template */
-    /* Constructor
-     * \param $p_cn Database connection
-     */
-    function Document($p_cn,$p_d_id=0)
-    {
-        $this->db=$p_cn;
-        $this->d_id=$p_d_id;
-        $this->counter=0;
-    }
-    /*!\brief insert a minimal document and set the d_id
-     */
-    function blank()
-    {
-        $this->d_id=$this->db->get_next_seq("document_d_id_seq");
-        // affect a number
-        
$this->d_number=$this->db->get_next_seq("seq_doc_type_".$this->md_type);
-        $sql=sprintf('insert into document(d_id,ag_id,d_number) 
values(%d,%d,%d)',
-                     $this->d_id,
-                     $this->ag_id,
-                     $this->d_number);
-        $this->db->exec_sql($sql);
-
-    }
-       function compute_filename($pj,$filename)
-       {
-               foreach (array('/','*','<','>',';',',','\\','.',':') as $i) {
-                       $pj= str_replace($i, "-",$pj);
-               }
-               // save the suffix
-               $pos_prefix=strrpos($filename,".");
-               if ($pos_prefix == 0) $pos_prefix=strlen($filename);
-               $filename_no=substr($filename,0,$pos_prefix);
-               $filename_suff=substr($filename,$pos_prefix,strlen($filename));
-               $new_filename=  strtolower($filename_no."-".$pj.$filename_suff);
-               return $new_filename;
-       }
-    /*!
-     * \brief Generate the document, Call $this-\>Replace to replace
-     *        tag by value
-     address@hidden p_array contains the data normally it is the $_POST
-     address@hidden contains the new filename
-     * \return an array : the url where the generated doc can be found, the 
name
-     * of the file and his mimetype
-     */
-    function Generate($p_array,$p_filename="")
-    {
-        // create a temp directory in /tmp to unpack file and to parse it
-        $dirname=tempnam($_ENV['TMP'],'doc_');
-
-
-        unlink($dirname);
-        mkdir ($dirname);
-        // Retrieve the lob and save it into $dirname
-        $this->db->start();
-        $dm_info="select md_name,md_type,md_lob,md_filename,md_mimetype
-                 from document_modele where md_id=".$this->md_id;
-        $Res=$this->db->exec_sql($dm_info);
-
-        $row=Database::fetch_array($Res,0);
-        $this->d_lob=$row['md_lob'];
-        $this->d_filename=$row['md_filename'];
-        $this->d_mimetype=$row['md_mimetype'];
-        $this->d_name=$row['md_name'];
-
-
-        chdir($dirname);
-        $filename=$row['md_filename'];
-        
$exp=$this->db->lo_export($row['md_lob'],$dirname.DIRECTORY_SEPARATOR.$filename);
-        if ( $exp === false ) echo_warning( __FILE__.":".__LINE__."Export NOK 
$filename");
-
-        $type="n";
-        // if the doc is a OOo, we need to unzip it first
-        // and the name of the file to change is always content.xml
-        if ( strpos($row['md_mimetype'],'vnd.oasis') != 0 )
-        {
-            ob_start();
-           $zip = new Zip_Extended;
-           if ($zip->open($filename) === TRUE) {
-             $zip->extractTo($dirname.DIRECTORY_SEPARATOR);
-             $zip->close();
-           } else {
-             echo __FILE__.":".__LINE__."cannot unzip model ".$filename;
-           }
-
-            // Remove the file we do  not need anymore
-            unlink($filename);
-            ob_end_clean();
-            $file_to_parse="content.xml";
-            $type="OOo";
-        }
-        else
-            $file_to_parse=$filename;
-        // affect a number
-        
$this->d_number=$this->db->get_next_seq("seq_doc_type_".$row['md_type']);
-
-        // parse the document - return the doc number ?
-        $this->ParseDocument($dirname,$file_to_parse,$type,$p_array);
-
-        $this->db->commit();
-        // if the doc is a OOo, we need to re-zip it
-        if ( strpos($row['md_mimetype'],'vnd.oasis') != 0 )
-        {
-            ob_start();
-           $zip = new Zip_Extended;
-            $res = $zip->open($filename, ZipArchive::CREATE);
-            if($res !== TRUE)
-             {
-               throw new Exception ( __FILE__.":".__LINE__."cannot recreate 
zip");
-             }
-           $zip->add_recurse_folder($dirname.DIRECTORY_SEPARATOR);
-           $zip->close();
-
-            ob_end_clean();
-
-            $file_to_parse=$filename;
-        }
-               if ( $p_filename !="") {
-
-                       $this->d_filename=$this->compute_filename($p_filename, 
$this->d_filename);
-               }
-        $this->SaveGenerated($dirname.DIRECTORY_SEPARATOR.$file_to_parse);
-        // Invoice
-        $ret='<A class="mtitle" 
HREF="show_document.php?d_id='.$this->d_id.'&'.dossier::get().'">Document 
g&eacute;n&eacute;r&eacute;</A>';
-        @rmdir($dirname);
-        return $ret;
-    }
-
-    /*! ParseDocument
-     * \brief This function parse a document and replace all
-     *        the predefined tags by a value. This functions
-     *        generate diffent documents (invoice, order, letter)
-     *        with the info from the database
-     *
-     * \param $p_dir directory name
-     * \param $p_file filename
-     * \param $p_type For the OOo document the tag are &lt and &gt instead of 
< and >
-     * \param $p_array variable from $_POST
-     */
-    function ParseDocument($p_dir,$p_file,$p_type,$p_array)
-    {
-
-        /*!\note Replace in the doc the tags by their values.
-         *  - MY_*   table parameter
-         *  - ART_VEN* table quant_sold for invoice
-         *  - CUST_* table quant_sold and fiche for invoice
-         *  - e_* for the invoice in the $_POST
-         */
-        // open the document
-        $infile_name=$p_dir.DIRECTORY_SEPARATOR.$p_file;
-        $h=fopen($infile_name,"r");
-
-        // check if tmpdir exist otherwise create it
-        $temp_dir=$_SERVER["DOCUMENT_ROOT"].DIRECTORY_SEPARATOR.'tmp';
-        if ( is_dir($temp_dir) == false )
-        {
-            if ( mkdir($temp_dir) == false )
-            {
-                $msg=_("Ne peut pas créer le répertoire ".$temp_dir); 
-                throw new Exception($msg);
-            }
-        }
-        // Compute output_name
-        $output_name=tempnam($temp_dir,"gen_doc_");
-        $output_file=fopen($output_name,"w+");
-        // check if the opening is sucessfull
-        if (  $h === false )
-        {
-            echo __FILE__.":".__LINE__."cannot open $p_dir $p_file ";
-            $msg=_("Ne peut pas ouvrir $p_dir $p_file"); 
-            throw new Exception($msg);
-        }
-        if ( $output_file == false)
-        {
-            $msg=_("Ne peut pas ouvrir $p_dir $p_file"); 
-            echo $msg;
-            throw new Exception($msg);
-        }
-        // compute the regex
-        if ( $p_type=='OOo')
-        {
-            
$regex="/=*&lt;&lt;[A-Z]+_*[A-Z]*_*[A-Z]*_*[A-Z]*_*[0-9]*&gt;&gt;/i";
-            $lt="&lt;";
-            $gt="&gt;";
-        }
-        else
-        {
-            $regex="/=*<<[A-Z]+_*[A-Z]*_*[A-Z]*_*[A-Z]*_*[0-9]*>>/i";
-            $lt="<";
-            $gt=">";
-        }
-
-        //read the file
-        while(! feof($h))
-         {
-            // replace the tag
-            $buffer=fgets($h);
-            // search in the buffer the magic << and >>
-            // while preg_match_all finds something to replace
-            while ( preg_match_all ($regex,$buffer,$f) >0  )
-             {
-
-
-                foreach ( $f as $apattern )
-                 {
-
-
-                   foreach($apattern as $pattern)
-                     {
-
-
-                       $to_remove=$pattern;
-                       // we remove the < and > from the pattern
-                       $tag=str_replace($lt,'',$pattern);
-                       $tag=str_replace($gt,'',$tag);
-
-
-                       // if the pattern if found we replace it
-                       $value=$this->Replace($tag,$p_array);
-                       if ( strpos($value,'ERROR') != false )            
$value="";
-                        /*
-                         * Change type of cell to numeric
-                         *  allow numeric cel in ODT for the formatting and 
formula
-                         */
-                       if ( is_numeric($value) && $p_type=='OOo')
-                         {
-                           
$searched='/office:value-type="string"><text:p>'.$pattern.'/';
-                           $replaced='office:value-type="float" 
office:value="'.$value.'"><text:p>'.$pattern;
-                           $buffer=preg_replace($searched, $replaced, 
$buffer,1);
-                         }
-                       // replace into the $buffer
-                       // take the position in the buffer
-                       $pos=strpos($buffer,$to_remove);
-                       // get the length of the string to remove
-                       $len=strlen($to_remove);
-                       if ( $p_type=='OOo' )
-                         {
-                           $value=str_replace('&','&amp;',$value);
-                           $value=str_replace('<','&lt;',$value);
-                           $value=str_replace('>','&gt;',$value);
-                           $value=str_replace('"','&quot;',$value);
-                           $value=str_replace("'",'&apos;',$value);
-                         }
-                       $buffer=substr_replace($buffer,$value,$pos,$len);
-
-                       // if the pattern if found we replace it
-                     }
-                 }
-             }
-            // write into the output_file
-            fwrite($output_file,$buffer);
-
-         }
-        fclose($h);
-        fclose($output_file);
-        if ( ($ret=copy ($output_name,$infile_name)) == FALSE )
-        {
-            echo _('Ne peut pas sauver '.$output_name.' vers '.$infile_name.' 
code d\'erreur ='.$ret);
-        }
-
-
-    }
-    /*! SaveGenerated
-     * \brief Save the generated Document
-     * \param $p_file is the generated file
-     *
-     *
-     * \return 0 if no error otherwise 1
-     */
-    function SaveGenerated($p_file)
-    {
-        // We save the generated file
-        $doc=new Document($this->db);
-        $this->db->start();
-        $this->d_lob=$this->db->lo_import($p_file);
-        if ( $this->d_lob == false )
-        {
-            echo "ne peut pas importer [$p_file]";
-            return 1;
-        }
-
-        $sql="insert into document(ag_id,d_lob,d_number,d_filename,d_mimetype)
-             values ($1,$2,$3,$4,$5)";
-
-        $this->db->exec_sql($sql,      array($this->ag_id,
-                                             $this->d_lob,
-                                             $this->d_number,
-                                             $this->d_filename,
-                                             $this->d_mimetype));
-        $this->d_id=$this->db->get_current_seq("document_d_id_seq");
-        // Clean the file
-        unlink ($p_file);
-        $this->db->commit();
-        return 0;
-    }
-    /*! Upload
-     * \brief Upload a file into document
-     *  all the needed data are in $_FILES we don't increment the seq
-     * \param $p_file : array containing by default $_FILES
-     *
-     * \return
-     */
-    function Upload($p_ag_id)
-    {
-        // nothing to save
-        if ( sizeof($_FILES) == 0 ) return;
-
-        /* for several files  */
-        /* $_FILES is now an array */
-        // Start Transaction
-        $this->db->start();
-        $name=$_FILES['file_upload']['name'];
-        for ($i = 0; $i < sizeof($name);$i++)
-        {
-            $new_name=tempnam($_ENV['TMP'],'doc_');
-            // check if a file is submitted
-            if ( strlen($_FILES['file_upload']['tmp_name'][$i]) != 0 )
-            {
-                // upload the file and move it to temp directory
-                if ( 
move_uploaded_file($_FILES['file_upload']['tmp_name'][$i],$new_name))
-                {
-                    $oid=$this->db->lo_import($new_name);
-                    // check if the lob is in the database
-                    if ( $oid == false )
-                    {
-                        $this->db->rollback();
-                        return 1;
-                    }
-                }
-                // the upload in the database is successfull
-                $this->d_lob=$oid;
-                $this->d_filename=$_FILES['file_upload']['name'][$i];
-                $this->d_mimetype=$_FILES['file_upload']['type'][$i];
-                $this->d_description=  strip_tags($_POST['input_desc'][$i]);
-                // insert into  the table
-                $sql="insert into document (ag_id, 
d_lob,d_filename,d_mimetype,d_number,d_description) values ($1,$2,$3,$4,$5,$6)";
-                
$this->db->exec_sql($sql,array($p_ag_id,$this->d_lob,$this->d_filename,$this->d_mimetype,1,$this->d_description));
-            }
-        } /* end for */
-        $this->db->commit();
-
-    }
-    /**
-     * Copy a existing OID (LOB) into the table document
-     * @note  use of global variable $cn which is the db connx to the current 
folder
-     * @param type $p_ag_id Follow_Up::ag_id
-     * @param type $p_lob oid of existing document
-     * @param type $p_filename filename of existing document
-     * @param type $p_mimetype mimetype of existing document
-     * @param type $p_description Description of existing document (default 
empty)
-     */
-    static function insert_existing_document($p_ag_id, $p_lob, $p_filename, 
$p_mimetype, $p_description = "")
-    {
-        global $cn;
-        // insert into  the table
-        $sql = "insert into document (ag_id, 
d_lob,d_filename,d_mimetype,d_number,d_description) values ($1,$2,$3,$4,$5,$6)";
-        $cn->exec_sql($sql, array($p_ag_id, $p_lob, $p_filename, $p_mimetype, 
1, $p_description));
-    }
-
-    /*! a_ref
-     * \brief create and compute a string for reference the doc <A ...>
-     *
-     * \return a string
-     */
-    function anchor()
-    {
-        if ( $this->d_id == 0 )
-            return '';
-        $image='<IMG SRC="image/insert_table.gif" 
title="'.$this->d_filename.'" border="0">';
-        $r="";
-        $r='<A class="mtitle" 
HREF="show_document.php?d_id='.$this->d_id.'&'.dossier::get().'">'.$image.'</A>';
-        return $r;
-    }
-    /** Get
-     * \brief Send the document
-     */
-    function Send()
-    {
-        // retrieve the template and generate document
-        $this->db->start();
-        $ret=$this->db->exec_sql(
-                 "select d_id,d_lob,d_filename,d_mimetype from document where 
d_id=".$this->d_id );
-        if ( Database::num_row ($ret) == 0 )
-            return;
-        $row=Database::fetch_array($ret,0);
-        //the document  is saved into file $tmp
-        $tmp=tempnam($_ENV['TMP'],'document_');
-        $this->db->lo_export($row['d_lob'],$tmp);
-        $this->d_mimetype=$row['d_mimetype'];
-        $this->d_filename=$row['d_filename'];
-
-        // send it to stdout
-        ini_set('zlib.output_compression','Off');
-        header("Pragma: public");
-        header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
-        header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
-        header("Cache-Control: must-revalidate");
-        header('Content-type: '.$this->d_mimetype);
-        header('Content-Disposition: 
attachment;filename="'.$this->d_filename.'"',FALSE);
-        header("Accept-Ranges: bytes");
-        $file=fopen($tmp,'r');
-        while ( !feof ($file) )
-        {
-            echo fread($file,8192);
-        }
-        fclose($file);
-
-        unlink ($tmp);
-
-        $this->db->commit();
-
-    }
-    /*!\brief get all the document of a given action
-     *\param $ag_id the ag_id from action::ag_id (primary key)
-     *\return an array of objects document or an empty array if nothing found
-     */
-    function get_all($ag_id)
-    {
-        $res=$this->db->get_array('select d_id, ag_id, d_lob, d_number, 
d_filename,'.
-                                  ' d_mimetype,d_description from document 
where ag_id=$1',array($ag_id));
-        $a=array();
-        for ($i=0;$i<sizeof($res); $i++ )
-        {
-            $doc=new Document($this->db);
-            $doc->d_id=$res[$i]['d_id'];
-            $doc->ag_id=$res[$i]['ag_id'];
-            $doc->d_lob=$res[$i]['d_lob'];
-            $doc->d_number=$res[$i]['d_number'];
-            $doc->d_filename=$res[$i]['d_filename'];
-            $doc->d_mimetype=$res[$i]['d_mimetype'];
-            $doc->d_description=$row['d_description'];
-            $a[$i]=clone $doc;
-        }
-        return $a;
-    }
-
-    /*!\brief Get  complete all the data member thx info from the database
-     */
-    function get()
-    {
-        $sql="select * from document where d_id=".$this->d_id;
-        $ret=$this->db->exec_sql($sql);
-        if ( Database::num_row($ret) == 0 )
-            return;
-        $row=Database::fetch_array($ret,0);
-        $this->ag_id=$row['ag_id'];
-        $this->d_mimetype=$row['d_mimetype'];
-        $this->d_filename=$row['d_filename'];
-        $this->d_lob=$row['d_lob'];
-        $this->d_number=$row['d_number'];
-        $this->d_description=$row['d_description'];
-
-    }
-    /*!
-     * \brief replace the TAG by the real value, this value can be into
-     * the database or in $_POST
-     * The possible tags are
-     *  - [CUST_NAME] customer's name
-     *  - [CUST_ADDR_1] customer's address line 1
-     *  - [CUST_CP] customer's ZIP code
-     *  - [CUST_CO] customer's country
-     *  - [CUST_CITY] customer's city
-     *  - [CUST_VAT] customer's VAT
-     *  - [MARCH_NEXT]   end this item and increment the counter $i
-     *  - [DATE_LIMIT]
-     *  - [VEN_ART_NAME]
-     *  - [VEN_ART_PRICE]
-     *  - [VEN_ART_QUANT]
-     *  - [VEN_ART_TVA_CODE]
-     *  - [VEN_ART_STOCK_CODE]
-     *  - [VEN_HTVA]
-     *  - [VEN_TVAC]
-     *  - [VEN_TVA]
-     *  - [TOTAL_VEN_HTVA]
-     *  - [DATE_CALC]
-     *  - [DATE]
-     *  - [DATE_LIMIT]
-     *  - [DATE_LIMIT_CALC]
-     *  - [NUMBER]
-     *  - [MY_NAME]
-     *  - [MY_CP]
-     *  - [MY_COMMUNE]
-     *  - [MY_TVA]
-     *  - [MY_STREET]
-     *  - [MY_NUMBER]
-     *  - [TVA_CODE]
-     *  - [TVA_RATE]
-     *  - [BON_COMMANDE]
-     *  - [OTHER_INFO]
-     *  - [CUST_NUM]
-     *  - [CUST_BANQUE_NAME]
-     *  - [CUST_BANQUE_NO]
-     *  - [USER]
-     *  - [REFERENCE]
-     *  - [BENEF_NAME]
-     *  - [BENEF_BANQUE_NAME]
-     *  - [BENEF_BANQUE_NO]
-     *  - [BENEF_ADDR_1]
-     *  - [BENEF_CP]
-     *  - [BENEF_CO]
-     *  - [BENEF_CITY]
-     *  - [BENEF_VAT]
-     *  - [ACOMPTE]
-     *  - [TITLE]
-     *  - [DESCRIPTION]
-     *
-     * \param $p_tag TAG
-     * \param $p_array data from $_POST
-     * \return String which must replace the tag
-     */
-    function Replace($p_tag,$p_array)
-    {
-               global $g_parameter;
-        $p_tag=strtoupper($p_tag);
-        $p_tag=str_replace('=','',$p_tag);
-        $r="Tag inconnu";
-
-        switch ($p_tag)
-        {
-               case 'DATE':
-                       $r=(isset 
($p_array['ag_timestamp']))?$p_array['ag_timestamp']:$p_array['e_date'];
-                       break;
-        case 'DATE_CALC':
-                $r=' Date inconnue ';
-            // Date are in $p_array['ag_date']
-            // or $p_array['e_date']
-            if ( isset ($p_array['ag_timestamp'])) {
-                
$date=format_date($p_array['ag_timestamp'],'DD.MM.YYYY','YYYY-MM-DD');
-                $r=$date;
-            }
-            if ( isset ($p_array['e_date'])) {
-                
$date=format_date($p_array['e_date'],'DD.MM.YYYY','YYYY-MM-DD');
-                $r=$date;
-            }
-            break;
-            //
-            //  the company priv
-
-        case 'MY_NAME':
-            $r=$g_parameter->MY_NAME;
-            break;
-        case 'MY_CP':
-            $r=$g_parameter->MY_CP;
-            break;
-        case 'MY_COMMUNE':
-            $r=$g_parameter->MY_COMMUNE;
-            break;
-        case 'MY_TVA':
-            $r=$g_parameter->MY_TVA;
-            break;
-        case 'MY_STREET':
-            $r=$g_parameter->MY_STREET;
-            break;
-        case 'MY_NUMBER':
-            $r=$g_parameter->MY_NUMBER;
-            break;
-        case 'MY_TEL':
-            $r=$g_parameter->MY_TEL;
-            break;
-        case 'MY_FAX':
-            $r=$g_parameter->MY_FAX;
-            break;
-        case 'MY_PAYS':
-            $r=$g_parameter->MY_PAYS;
-            break;
-
-            // customer
-            /*\note The CUST_* are retrieved thx the $p_array['tiers']
-             * which contains the quick_code
-             */
-        case 'SOLDE':
-            $tiers=new Fiche($this->db);
-            
$qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
-            $tiers->get_by_qcode($qcode,false);
-            $p=$tiers->strAttribut(ATTR_DEF_ACCOUNT);
-            $poste=new Acc_Account_Ledger($this->db,$p);
-            $r=$poste->get_solde(' true' );
-            break;
-        case 'CUST_NAME':
-            $tiers=new Fiche($this->db);
-            
$qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
-            $tiers->get_by_qcode($qcode,false);
-            $r=$tiers->strAttribut(ATTR_DEF_NAME);
-            break;
-        case 'CUST_ADDR_1':
-            $tiers=new Fiche($this->db);
-            
$qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
-            $tiers->get_by_qcode($qcode,false);
-            $r=$tiers->strAttribut(ATTR_DEF_ADRESS);
-
-            break ;
-        case 'CUST_CP':
-            $tiers=new Fiche($this->db);
-
-            
$qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
-            $tiers->get_by_qcode($qcode,false);
-            $r=$tiers->strAttribut(ATTR_DEF_CP);
-
-            break;
-        case 'CUST_CITY':
-            $tiers=new Fiche($this->db);
-
-            
$qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
-            $tiers->get_by_qcode($qcode,false);
-            $r=$tiers->strAttribut(ATTR_DEF_CITY);
-
-            break;
-
-        case 'CUST_CO':
-            $tiers=new Fiche($this->db);
-
-            
$qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
-            $tiers->get_by_qcode($qcode,false);
-            $r=$tiers->strAttribut(ATTR_DEF_PAYS);
-
-            break;
-            // Marchandise in $p_array['e_march*']
-            // \see user_form_achat.php or user_form_ven.php
-        case 'CUST_VAT':
-            $tiers=new Fiche($this->db);
-
-            
$qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
-            $tiers->get_by_qcode($qcode,false);
-            $r=$tiers->strAttribut(ATTR_DEF_NUMTVA);
-            break;
-        case 'CUST_NUM':
-            $tiers=new Fiche($this->db);
-            
$qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
-            $tiers->get_by_qcode($qcode,false);
-            $r=$tiers->strAttribut(ATTR_DEF_NUMBER_CUSTOMER);
-            break;
-        case 'CUST_BANQUE_NO':
-            $tiers=new Fiche($this->db);
-            
$qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
-            $tiers->get_by_qcode($qcode,false);
-            $r=$tiers->strAttribut(ATTR_DEF_BQ_NO);
-            break;
-        case 'CUST_BANQUE_NAME':
-            $tiers=new Fiche($this->db);
-            
$qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
-            $tiers->get_by_qcode($qcode,false);
-            $r=$tiers->strAttribut(ATTR_DEF_BQ_NAME);
-            break;
-            /* 
--------------------------------------------------------------------------------
 */
-            /* BENEFIT (fee notes */
-        case 'BENEF_NAME':
-            $tiers=new Fiche($this->db);
-            $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
-            if ( $qcode=='')
-            {
-                $r='';
-                break;
-            }
-            $tiers->get_by_qcode($qcode,false);
-            $r=$tiers->strAttribut(ATTR_DEF_NAME);
-            break;
-        case 'BENEF_ADDR_1':
-            $tiers=new Fiche($this->db);
-            $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
-            if ( $qcode=='')
-            {
-                $r='';
-                break;
-            }
-            $tiers->get_by_qcode($qcode,false);
-            $r=$tiers->strAttribut(ATTR_DEF_ADRESS);
-
-            break ;
-        case 'BENEF_CP':
-            $tiers=new Fiche($this->db);
-
-            $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
-            if ( $qcode=='')
-            {
-                $r='';
-                break;
-            }
-            $tiers->get_by_qcode($qcode,false);
-            $r=$tiers->strAttribut(ATTR_DEF_CP);
-
-            break;
-        case 'BENEF_CITY':
-            $tiers=new Fiche($this->db);
-
-            $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
-            if ( $qcode=='')
-            {
-                $r='';
-                break;
-            }
-            $tiers->get_by_qcode($qcode,false);
-            $r=$tiers->strAttribut(ATTR_DEF_CITY);
-
-            break;
-
-        case 'BENEF_CO':
-            $tiers=new Fiche($this->db);
-
-            $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
-            if ( $qcode=='')
-            {
-                $r='';
-                break;
-            }
-            $tiers->get_by_qcode($qcode,false);
-            $r=$tiers->strAttribut(ATTR_DEF_PAYS);
-
-            break;
-            // Marchandise in $p_array['e_march*']
-            // \see user_form_achat.php or user_form_ven.php
-        case 'BENEF_VAT':
-            $tiers=new Fiche($this->db);
-
-            $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
-            if ( $qcode=='')
-            {
-                $r='';
-                break;
-            }
-            $tiers->get_by_qcode($qcode,false);
-            $r=$tiers->strAttribut(ATTR_DEF_NUMTVA);
-            break;
-        case 'BENEF_NUM':
-            $tiers=new Fiche($this->db);
-            $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
-            if ( $qcode=='')
-            {
-                $r='';
-                break;
-            }
-            $tiers->get_by_qcode($qcode,false);
-            $r=$tiers->strAttribut(ATTR_DEF_NUMBER_CUSTOMER);
-            break;
-        case 'BENEF_BANQUE_NO':
-            $tiers=new Fiche($this->db);
-            $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
-            if ( $qcode=='')
-            {
-                $r='';
-                break;
-            }
-            $tiers->get_by_qcode($qcode,false);
-            $r=$tiers->strAttribut(ATTR_DEF_BQ_NO);
-            break;
-        case 'BENEF_BANQUE_NAME':
-            $tiers=new Fiche($this->db);
-            $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
-            if ( $qcode=='')
-            {
-                $r='';
-                break;
-            }
-            $tiers->get_by_qcode($qcode,false);
-            $r=$tiers->strAttribut(ATTR_DEF_BQ_NAME);
-            break;
-
-            // Marchandise in $p_array['e_march*']
-            // \see user_form_achat.php or user_form_ven.php
-        case 'NUMBER':
-            $r=$this->d_number;
-            break;
-
-        case 'USER' :
-            return $_SESSION['use_name'].', '.$_SESSION['use_first_name'];
-
-            break;
-        case 'REFERENCE':
-            $act=new Follow_Up($this->db);
-            $act->ag_id=$this->ag_id;
-            $act->get();
-            $r=$act->ag_ref;
-            break;
-
-            /*
-             *  - [VEN_ART_NAME]
-             *  - [VEN_ART_PRICE]
-             *  - [VEN_ART_QUANT]
-             *  - [VEN_ART_TVA_CODE]
-             *  - [VEN_ART_STOCK_CODE]
-             *  - [VEN_HTVA]
-             *  - [VEN_TVAC]
-             *  - [VEN_TVA]
-             *  - [TOTAL_VEN_HTVA]
-             *  - [DATE_LIMIT]
-             */
-        case 'DATE_LIMIT_CALC':
-            extract ($p_array);
-            $id='e_ech' ;
-            if ( !isset (${$id}) ) return "";
-            $r=format_date(${$id},'DD.MM.YYYY','YYYY-MM-DD');
-            break;
-      case 'DATE_LIMIT':
-            extract ($p_array);
-            $id='e_ech' ;
-            if ( !isset (${$id}) ) return "";
-            $r=${$id};
-            break;
-        case 'MARCH_NEXT':
-            $this->counter++;
-            $r='';
-            break;
-
-        case 'VEN_ART_NAME':
-            extract ($p_array);
-            $id='e_march'.$this->counter;
-            // check if the march exists
-            if ( ! isset (${$id})) return "";
-            // check that something is sold
-            if ( ${'e_march'.$this->counter.'_price'} != 0 && 
${'e_quant'.$this->counter} != 0 )
-            {
-                $f=new Fiche($this->db);
-                $f->get_by_qcode(${$id},false);
-                $r=$f->strAttribut(ATTR_DEF_NAME);
-            }
-            else $r = "";
-            break;
-       case 'VEN_ART_LABEL':
-            extract ($p_array);
-            $id='e_march'.$this->counter."_label";
-            // check if the march exists
-
-            if (! isset (${$id}) || (isset (${$id}) && strlen(trim(${$id})) == 
0))
-                {
-                    $id = 'e_march' . $this->counter;
-                    // check if the march exists
-                    if (!isset(${$id}))
-                        $r= "";
-                    else 
-                    {
-                    // check that something is sold
-                        if (${'e_march' . $this->counter . '_price'} != 0 && 
${'e_quant' . $this->counter} != 0)
-                        {
-                            $f = new Fiche($this->db);
-                            $f->get_by_qcode(${$id}, false);
-                            $r = $f->strAttribut(ATTR_DEF_NAME);
-                        } else
-                            $r = "";
-                    }
-                }
-                else
-                    $r=${'e_march'.$this->counter.'_label'};
-            break;
-        case 'VEN_ART_STOCK_CODE':
-            extract ($p_array);
-                    $id = 'e_march' . $this->counter;
-                    // check if the march exists
-                    if (!isset(${$id}))
-                        $r= "";
-                    else 
-                    {
-                    // check that something is sold
-                        if (${'e_march' . $this->counter . '_price'} != 0 && 
${'e_quant' . $this->counter} != 0)
-                        {
-                            $f = new Fiche($this->db);
-                            $f->get_by_qcode(${$id}, false);
-                            $r = $f->strAttribut(ATTR_DEF_STOCK);
-                            $r=($r == NOTFOUND)?'':$r;
-                        } 
-                    }
-            break;
-        case 'VEN_ART_PRICE':
-            extract ($p_array);
-            $id='e_march'.$this->counter.'_price' ;
-            if ( !isset (${$id}) ) return "";
-                       if (${$id} == 0 ) return "";
-            $r=${$id};
-            break;
-
-        case 'TVA_RATE':
-        case 'VEN_ART_TVA_RATE':
-            extract ($p_array);
-            $id='e_march'.$this->counter.'_tva_id';
-            if ( !isset (${$id}) ) return "";
-            if ( ${$id} == -1 || ${$id}=='' ) return "";
-            $march_id='e_march'.$this->counter.'_price' ;
-            if ( ! isset (${$march_id})) return '';
-            $tva=new Acc_Tva($this->db);
-            $tva->set_parameter("id",${$id});
-            if ( $tva->load() == -1) return '';
-            return $tva->get_parameter("rate");
-            break;
-
-        case 'TVA_CODE':
-        case 'VEN_ART_TVA_CODE':
-            extract ($p_array);
-            $id='e_march'.$this->counter.'_tva_id';
-            if ( !isset (${$id}) ) return "";
-            if ( ${$id} == -1 ) return "";
-            $qt='e_quant'.$this->counter;
-            $price='e_march'.$this->counter.'_price' ;
-            if ( ${$price} == 0 || ${$qt} == 0
-                    || strlen(trim( $price )) ==0
-                    || strlen(trim($qt)) ==0)
-                return "";
-
-            $r=${$id};
-            break;
-
-        case 'TVA_LABEL':
-            extract ($p_array);
-            $id='e_march'.$this->counter.'_tva_id';
-            if ( !isset (${$id}) ) return "";
-            $march_id='e_march'.$this->counter.'_price' ;
-            if ( ! isset (${$march_id})) return '';
-            if ( ${$march_id} == 0) return '';
-            $tva=new Acc_Tva($this->db,${$id});
-            if ($tva->load() == -1 ) return "";
-            $r=$tva->get_parameter('label');
-
-            break;
-
-            /* total VAT for one sold */
-        case 'TVA_AMOUNT':
-        case 'VEN_TVA':
-            extract ($p_array);
-            $qt='e_quant'.$this->counter;
-            $price='e_march'.$this->counter.'_price' ;
-            $tva='e_march'.$this->counter.'_tva_id';
-            /* if we do not use vat this var. is not set */
-            if ( !isset(${$tva}) ) return '';
-            if ( !isset (${'e_march'.$this->counter}) ) return "";
-            // check that something is sold
-            if ( ${$price} == 0 || ${$qt} == 0
-                    || strlen(trim( $price )) ==0
-                    || strlen(trim($qt)) ==0)
-                return "";
-            $r=${'e_march'.$this->counter.'_tva_amount'};
-            break;
-            /* TVA automatically computed */
-        case 'VEN_ART_TVA':
-        
-            extract ($p_array);
-            $qt='e_quant'.$this->counter;
-            $price='e_march'.$this->counter.'_price' ;
-            $tva='e_march'.$this->counter.'_tva_id';
-            if ( !isset (${'e_march'.$this->counter}) ) return "";
-            // check that something is sold
-            if ( ${$price} == 0 || ${$qt} == 0
-                    || strlen(trim( $price )) ==0
-                    || strlen(trim($qt)) ==0)
-                return "";
-            $oTva=new Acc_Tva($this->db,${$tva});
-            if ($oTva->load() == -1 ) return "";
-            $r=round(${$price},2)*$oTva->get_parameter('rate');
-            $r=round($r,2);
-            break;
-
-        case 'VEN_ART_TVAC':
-            extract ($p_array);
-            $qt='e_quant'.$this->counter;
-            $price='e_march'.$this->counter.'_price' ;
-            $tva='e_march'.$this->counter.'_tva_id';
-            if ( !isset (${'e_march'.$this->counter}) ) return "";
-            // check that something is sold
-            if ( ${$price} == 0 || ${$qt} == 0
-                    || strlen(trim( $price )) ==0
-                    || strlen(trim($qt)) ==0)
-                return "";
-            if ( ! isset (${$tva}) ) return '';
-            $tva=new Acc_Tva($this->db,${$tva});
-            if ($tva->load() == -1 )
-            {
-                $r=round(${$price},2);
-            }
-            else
-            {
-                $r=round(${$price}*$tva->get_parameter('rate')+${$price},2);
-            }
-
-            break;
-
-        case 'VEN_ART_QUANT':
-            extract ($p_array);
-            $id='e_quant'.$this->counter;
-            if ( !isset (${$id}) ) return "";
-            // check that something is sold
-            if ( ${'e_march'.$this->counter.'_price'} == 0
-                    || ${'e_quant'.$this->counter} == 0
-                    || strlen(trim( ${'e_march'.$this->counter.'_price'} )) ==0
-                    || strlen(trim(${'e_quant'.$this->counter})) ==0 )
-                return "";
-            $r=${$id};
-            break;
-
-        case 'VEN_HTVA':
-            extract ($p_array);
-            $id='e_march'.$this->counter.'_price' ;
-            $quant='e_quant'.$this->counter;
-            if ( !isset (${$id}) ) return "";
-
-            // check that something is sold
-            if ( ${'e_march'.$this->counter.'_price'} == 0 || 
${'e_quant'.$this->counter} == 0
-                    || strlen(trim( ${'e_march'.$this->counter.'_price'} )) ==0
-                    || strlen(trim(${'e_quant'.$this->counter})) ==0)
-                return "";
-                       bcscale(4);
-            $r=bcmul(${$id},${$quant});
-                       $r=round($r,2);
-            break;
-
-        case 'VEN_TVAC':
-            extract ($p_array);
-            $id='e_march'.$this->counter.'_tva_amount' ;
-            $price='e_march'.$this->counter.'_price' ;
-            $quant='e_quant'.$this->counter;
-            if ( ! isset(${'e_march'.$this->counter.'_price'})|| 
!isset(${'e_quant'.$this->counter}))     return "";
-            // check that something is sold
-            if ( ${'e_march'.$this->counter.'_price'} == 0 || 
${'e_quant'.$this->counter} == 0 ) return "";
-                       bcscale(4);
-            // if TVA not exist
-            if ( ! isset(${$id}))
-                $r=  bcmul(${$price},${$quant});
-            else{
-                $r=  bcmul(${$price},${$quant});
-                $r=bcadd($r,${$id});
-                       }
-                       $r=round($r,2);
-                       return $r;
-            break;
-
-        case 'TOTAL_VEN_HTVA':
-            extract($p_array);
-                       bcscale(4);
-            $sum=0.0;
-            for ($i=0;$i<$nb_item;$i++)
-            {
-                $sell='e_march'.$i.'_price';
-                $qt='e_quant'.$i;
-
-                if ( ! isset (${$sell}) ) break;
-
-                if ( strlen(trim(${$sell})) == 0 ||
-                        strlen(trim(${$qt})) == 0 ||
-                        ${$qt}==0 || ${$sell}==0)
-                    continue;
-                $tmp1=bcmul(${$sell},${$qt});
-                $sum=bcadd($sum,$tmp1);
-
-
-            }
-            $r=round($sum,2);
-            break;
-        case 'TOTAL_VEN_TVAC':
-            extract($p_array);
-            $sum=0.0;
-                       bcscale(4);
-            for ($i=0;$i<$nb_item;$i++)
-            {
-                $tva='e_march'.$i.'_tva_amount';
-                $tva_amount=0;
-                /* if we do not use vat this var. is not set */
-                if ( isset(${$tva}) )
-                {
-                    $tva_amount=${$tva};
-                }
-                $sell=${'e_march'.$i.'_price'};
-                $qt=${'e_quant'.$i};
-                               $tot=bcmul($sell,$qt);
-                               $tot=bcadd($tot,$tva_amount);
-                               $sum=bcadd($sum,$tot);
-            }
-            $r=round($sum,2);
-
-            break;
-        case 'TOTAL_TVA':
-            extract($p_array);
-            $sum=0.0;
-            for ($i=0;$i<$nb_item;$i++)
-            {
-                $tva='e_march'.$i.'_tva_amount';
-                if (! isset(${$tva})) $tva_amount=0.0;
-                else $tva_amount=$
-                                     {
-                                         $tva
-                                     };
-                $sum+=$tva_amount;
-                $sum=round($sum,2);
-            }
-            $r=$sum;
-
-            break;
-        case 'BON_COMMANDE':
-            if ( isset($p_array['bon_comm']))
-                return $p_array['bon_comm'];
-            else
-                return "";
-            break;
-        case 'PJ':
-            if ( isset($p_array['e_pj']))
-                return $p_array['e_pj'];
-            else
-                return "";
-
-        case 'OTHER_INFO':
-            if ( isset($p_array['other_info']))
-                return $p_array['other_info'];
-            else
-                return "";
-            break;
-        case 'COMMENT':
-            if ( isset($p_array['e_comm']))
-                return $p_array['e_comm'];
-            break;
-        case 'ACOMPTE':
-            if ( isset($p_array['acompte']))
-                return $p_array['acompte'];
-                       return "0";
-            break;
-        case 'STOCK_NAME':
-                if ( ! isset ($p_array['repo'])) return "";
-                $ret=$this->db->get_value('select r_name from 
public.stock_repository where r_id=$1',array($p_array['repo']));
-                return $ret;
-        case 'STOCK_ADRESS':
-                if ( ! isset ($p_array['repo'])) return "";
-                $ret=$this->db->get_value('select r_adress from 
public.stock_repository where r_id=$1',array($p_array['repo']));
-                return $ret;
-        case 'STOCK_COUNTRY':
-                if ( ! isset ($p_array['repo'])) return "";
-                $ret=$this->db->get_value('select r_country from 
public.stock_repository where r_id=$1',array($p_array['repo']));
-                return $ret;
-        case 'STOCK_CITY':
-                if ( ! isset ($p_array['repo'])) return "";
-                $ret=$this->db->get_value('select r_city from 
public.stock_repository where r_id=$1',array($p_array['repo']));
-                return $ret;
-        case 'STOCK_PHONE':
-                if ( ! isset ($p_array['repo'])) return "";
-                $ret=$this->db->get_value('select r_phone from 
public.stock_repository where r_id=$1',array($p_array['repo']));
-                return $ret;
-        case 'TITLE':
-            $title=HtmlInput::default_value_request("ag_title", "");
-            return $title;
-
-               }
-        /*
-         * retrieve the value of ATTR for e_march
-         */
-        if (preg_match('/^ATTR/', $p_tag) == 1)
-        {
-            // Retrieve f_id
-            if ( isset ($p_array['e_march'.$this->counter]))
-            {
-                $id = $p_array['e_march' . $this->counter];
-                $r=$this->replace_special_tag($id,$p_tag);
-            }
-        }
-        /*
-         * retrieve the value of ATTR for e_march
-         */
-        if (preg_match('/^BENEFATTR/', $p_tag) == 1)
-        {
-            $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
-            // Retrieve f_id
-             $r=$this->replace_special_tag($qcode,$p_tag);
-        }
-        if (preg_match('/^CUSTATTR/', $p_tag) == 1)
-        {
-            if ( isset($p_array['qcode_dest']) || isset($p_array['e_client']) )
-            {
-                
$qcode=(isset($p_array['qcode_dest']))?$p_array['qcode_dest']:$p_array['e_client'];
-                $r=$this->replace_special_tag($qcode,$p_tag);
-            }
-        }
-        return $r;
-    }
-    /*!\brief remove a row from the table document, the lob object is not 
deleted
-     *        because can be linked elsewhere
-     */
-    function remove()
-    {
-      $d_lob=$this->db->get_value('select d_lob from document where d_id=$1',
-                                 array($this->d_id));
-        $sql='delete from document where d_id='.$this->d_id;
-        $this->db->exec_sql($sql);
-        if ( $d_lob != 0 )
-            $this->db->lo_unlink($d_lob);
-    }
-    /*!\brief Move a document from the table document into the concerned row
-     *        the document is not copied : it is only a link
-     *
-     * \param $p_internal internal code
-     *
-     */
-    function MoveDocumentPj($p_internal)
-    {
-        $sql="update jrn set jr_pj=$1,jr_pj_name=$2,jr_pj_type=$3 where 
jr_internal=$4";
-
-        
$this->db->exec_sql($sql,array($this->d_lob,$this->d_filename,$this->d_mimetype,$p_internal));
-        // clean the table document
-        $sql='delete from document where d_id='.$this->d_id;
-        $this->db->exec_sql($sql);
-
-
-    }
-    /**
-     *Replace a special tag *TAGxxxx with the value from fiche_detail, the xxxx
-     * is the ad_value
-     * @param $p_qcode qcode of the card
-     * @param $p_tag tag to parse
-     * @return  the ad_value contained in fiche_detail or for the type 
"select" the
-     *          label
-     */
-    function replace_special_tag($p_qcode, $p_tag)
-    {
-        // check if the march exists
-        if ($p_qcode == "")
-            return "";
-
-        $f = new Fiche($this->db);
-        $found = $f->get_by_qcode($p_qcode, false);
-        // if not found exit
-        if ($found == 1)
-            return "";
-
-        // get the ad_id
-        $attr=preg_replace("/^.*ATTR/","",$p_tag);
-
-        if (isNumber($attr) == 0) return "";
-        $ad_type=$this->db->get_value("select ad_type from attr_def where 
ad_id=$1",array($attr));
-
-        // get ad_value
-        $ad_value=$this->db->get_value("select ad_value from fiche_detail 
where f_id=$1 and ad_id=$2",array($f->id,$attr));
-
-        // if ad_id is type select execute select and get value
-        if ( $ad_type=="select")
-        {
-            $sql=$this->db->get_value("select ad_extra from attr_def where 
ad_id=$1",array($attr));
-            $array= $this->db->make_array($sql);
-            for ($a=0;$a<count ($array);$a++)
-            {
-                if ($array[$a]['value']==$ad_value)
-                    return $array[$a]['label'];
-            }
-            
-        }
-        // if ad_id is not type select get value
-        return $ad_value;
-    }
-    function update_description ($p_desc)
-    {
-        $this->db->exec_sql('update document set d_description = $1 where 
d_id=$2',
-                array($p_desc,$this->d_id));
-    }
-
-}
diff --git a/include/class_document_modele.php 
b/include/class_document_modele.php
deleted file mode 100644
index e993af3..0000000
--- a/include/class_document_modele.php
+++ /dev/null
@@ -1,364 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-// Copyright Author Dany De Bontridder address@hidden
-/*! \file
- * \brief Class for the document template
- */
-/*!
- * \brief Class for the document template
- */
-require_once NOALYSS_INCLUDE.'/class_icheckbox.php';
-require_once NOALYSS_INCLUDE.'/class_ihidden.php';
-require_once NOALYSS_INCLUDE.'/class_ifile.php';
-class Document_modele
-{
-    var $cn;           /*!< $cn  database connection */
-    var $md_id;                /*!< $md_id pk */
-    var $md_name;         /*!< $md_name template's name */
-    var $md_type;         /*!< $md_type template's type (letter, invoice, 
order...) */
-    var $md_lob;          /*!< $md_lob Document file */
-    var $md_sequence;     /*!<  $md_sequence sequence name (autogenerate) */
-    var $sequence;        /*!< $sequence sequence number used by the create 
sequence start with */
-    var $md_affect;    /*!< $md_affect if you can use it in VEN for sale, ACH 
for purchase or GES for follow-up */
-    //Constructor parameter = database connexion
-    function Document_modele($p_cn,$p_id=-1)
-    {
-        $this->cn=$p_cn;
-        $this->md_id=$p_id;
-    }
-
-    /*!
-     **************************************************
-     * \brief : show all the stored document_modele.
-     *        return a string containing all the data
-     *        separate by TD & TR tag
-     * \return table in HTML Code
-     */
-    function myList()
-    {
-        $s=dossier::get();
-        $sql="select md_id,md_name,md_affect,dt_value from document_modele 
join document_type on(dt_id=md_type) order by md_name";
-        $Res=$this->cn->exec_sql($sql);
-        $all=Database::fetch_all($Res);
-       $r='';
-        if ( Database::num_row($Res) != 0 ) {
-
-         $r.='<p><form method="post">';
-         $r.=dossier::hidden();
-         $r.="<table>";
-         $r.="<tr> ";
-         $r.=th(_('Nom'));
-         $r.=th(_('Catégorie'));
-         $r.=th(_('Affect.'));
-         $r.=th(_('Fichier'));
-         $r.=th(_('Effacer'));
-         $r.="</tr>";
-         foreach ( $all as $row)
-           {
-             $r.="<tr>";
-             $r.="<td>";
-             $r.=h($row['md_name']);
-             $r.="</td>";
-             $r.="<td>";
-             $r.=$row['dt_value'];
-             $r.="</td>";
-             $r.=td(h($row['md_affect']));
-             $r.="<td>";
-             $r.='<A 
HREF="show_document_modele.php?md_id='.$row['md_id'].'&'.$s.'">Document</a>';
-             $r.="</td>";
-             $r.="<TD>";
-             $c=new ICheckBox();
-             $c->name="dm_remove_".$row['md_id'];
-             $r.=$c->input();
-             $r.="</td>";
-             
$r.=td(HtmlInput::detail_modele_document($row['md_id'],'Modifier'));
-
-             $r.="</tr>";
-           }
-         $r.="</table>";
-
-         // need hidden parameter for subaction
-         $a=new IHidden();
-         $a->name="sa";
-         $a->value="rm_template";
-         $r.=$a->input();
-         $r.=HtmlInput::submit("rm_template","Effacer la sélection");
-       }
-       $b=new IButton('show');
-       $b->label="Ajout d'un document";
-       $b->javascript="$('add_modele').style.display='block';new 
Draggable('add_modele',{starteffect:function(){
-                      new 
Effect.Highlight(obj.id,{scroll:window,queue:'end'});}});";
-               $r.=$b->input();
-        $r.="</form></p>";
-        return $r;
-    }
-    /*!
-     * \brief :  Save a document_modele in the database,
-     *       if the document_modele doesn't exist yet it will be
-     *       first created (-> insert into document_modele)
-     *       in that case the name and the type must be set
-     *       set before calling Save, the name will be modified
-     *       with sql_string
-     *
-     */
-    function Save()
-    {
-        // if name is empty return immediately
-        if ( trim(strlen($this->md_name))==0)
-            return;
-        try
-        {
-            // Start transaction
-            $this->cn->start();
-            // Save data into the table document_modele
-            // if $this->md_id == -1 it means it is a new document model
-            // so first we have to insert it
-            // the name and the type must be set before calling save
-            if ( $this->md_id == -1)
-            {
-
-                // insert into the table document_modele
-                
$this->md_id=$this->cn->get_next_seq('document_modele_md_id_seq');
-                $sql="insert into 
document_modele(md_id,md_name,md_type,md_affect)
-                     values ($1,$2,$3,$4)";
-
-                
$Ret=$this->cn->exec_sql($sql,array($this->md_id,$this->md_name,$this->md_type,$this->md_affect));
-                // create the sequence for this modele of document
-                
$this->md_sequence="document_".$this->cn->get_next_seq("document_seq");
-                // if start is not equal to 0 and he's a number than the user
-                // request a number change
-
-                if ( $this->start != 0 && isNumber($this->start) == 1 )
-                {
-                    $sql="alter sequence seq_doc_type_".$this->md_type." 
restart ".$this->start;
-                    $this->cn->exec_sql($sql);
-                }
-
-            }
-            // Save the file
-            $new_name=tempnam($_ENV['TMP'],'document_');
-            if ( strlen ($_FILES['doc']['tmp_name']) != 0 )
-            {
-                if (move_uploaded_file($_FILES['doc']['tmp_name'],
-                                       $new_name))
-                {
-                    // echo "Image saved";
-                    $oid= $this->cn->lo_import($new_name);
-                    if ( $oid == false )
-                    {
-                        
echo_error('class_document_modele.php',__LINE__,"cannot upload document");
-                        $this->cn->rollback();
-                        return;
-                    }
-                    // Remove old document
-                    $ret=$this->cn->exec_sql("select md_lob from 
document_modele where md_id=".$this->md_id);
-                    if (Database::num_row($ret) != 0)
-                    {
-                        $r=Database::fetch_array($ret,0);
-                        $old_oid=$r['md_lob'];
-                        if (strlen($old_oid) != 0)
-                            $this->cn->lo_unlink($old_oid);
-                    }
-                    // Load new document
-                    $this->cn->exec_sql("update document_modele set 
md_lob=".$oid.", md_mimetype='".$_FILES['doc']['type']."' 
,md_filename='".$_FILES['doc']['name']."' where md_id=".$this->md_id);
-                    $this->cn->commit();
-                }
-                else
-                {
-                    echo "<H1>Error</H1>";
-                    $this->cn->rollback();
-                   throw new Exception("Erreur".__FILE__.__LINE__);
-                }
-            }
-        }
-        catch (Exception $e)
-        {
-            rollback($this->cn);
-            return ;
-        }
-    }
-    /*!
-     * \brief Remove a template
-     * \return nothing
-     */
-    function Delete()
-    {
-        $this->cn->start();
-        // first we unlink the document
-        $sql="select md_lob from document_modele where md_id=".$this->md_id;
-        $res=$this->cn->exec_sql($sql);
-        $r=Database::fetch_array($res,0);
-        // if a lob is found
-        if ( strlen ($r['md_lob']) &&
-                $this->cn->exist_blob($r['md_lob']) )
-        {
-            // we remove it first
-            $this->cn->lo_unlink($r['md_lob']);
-        }
-        // now we can delete the row
-        $sql="delete from document_modele where md_id =".$this->md_id;
-        $sql=$this->cn->exec_sql($sql);
-        $this->cn->commit();
-    }
-
-    /**
-     * @brief show the form for loading a template
-     * @param p_action for the field action = destination url
-     *
-     *
-     * @return string containing the forms
-     */
-    function form()
-    {
-        $r='<p class="notice">';
-        $r.='Veuillez introduire les mod&egrave;les servant à 
g&eacute;n&eacute;rer vos documents';
-        $r.='</p>';
-        $r.='<form enctype="multipart/form-data"  method="post">';
-        $r.=dossier::hidden();
-        // we need to add the sub action as hidden
-        $h=new IHidden();
-        $h->name="sa";
-        $h->value="add_document";
-
-        $r.=$h->input();
-
-        $r.='<table>';
-        $t=new IText();
-        $t->name="md_name";
-        $r.="<tr><td> Nom </td><td>".$t->input()."</td>";
-
-        $r.="</tr>";
-        $r.="<tr><td>Catégorie de document </td>";
-        $w=new ISelect();
-        $w->name="md_type";
-
-        $w->value=$this->cn->make_array('select dt_id,dt_value from 
document_type order by dt_value');
-        $r.="<td>".$w->input()."</td></tr>";
-
-        $r.='<tr>';
-        $r.=td(_('Affectation'));
-        $waffect=new ISelect();
-        $waffect->name='md_affect';
-        $waffect->value=array(
-                            array('value'=>'ACH','label'=>_('Uniquement 
journaux achat')),
-                            array('value'=>'VEN','label'=>_('Uniquement 
journaux vente')),
-                            array('value'=>'GES','label'=>_('Partie gestion'))
-                        );
-
-        $r.=td($waffect->input());
-        $r.='</tr>';
-
-        $f=new IFile();
-        $f->name="doc";
-        $r.="<tr><td>fichier</td><td> ".$f->input()."</td></tr>";
-
-        $start=new IText();
-        $start->name="start_seq";
-        $start->size=9;
-        $start->value="0";
-
-        $r.="<tr><td> Numerotation commence a</td><td> 
".$start->input()."</td>";
-        $r.='<td class="notice">Si vous laissez &agrave; 0, la 
num&eacute;rotation ne changera pas, la prochaine facture sera n+1, n étant le 
n° que vous avez donn&eacute;</td>';
-        $r.="</tr>";
-        $r.='</table>';
-        $r.=HtmlInput::submit('add_document','Ajout');
-        $r.="</form></p>";
-        return $r;
-    }
-    /*!\brief load the value of a document_modele,the ag_id variable must be 
set
-     */
-    function load()
-    {
-        $array=$this->cn->get_array("SELECT md_id, md_name, md_lob, md_type, 
md_filename, md_mimetype,md_affect".
-                                    " FROM document_modele where 
md_id=$1",array($this->md_id));
-        if ( count($array) == 0 ) return null;
-        foreach ( array('md_name', 'md_lob','md_type', 'md_filename', 
'md_mimetype','md_affect') as $idx)
-        {
-            $this->$idx=$array[0][$idx];
-        }
-    }
-    /*!
-     * \brief :  update a document_modele in the database,
-     */
-    function update($p_array)
-    {
-      $this->load();
-        // if name is empty return immediately
-        if ( trim(strlen($p_array['md_name']))==0)
-            return;
-        try
-        {
-            // Start transaction
-            $this->cn->start();
-           $sql="update document_modele set md_name=$1,md_type=$2,md_affect=$3 
where md_id=$4";
-           $this->cn->exec_sql($sql,array(
-                                          $p_array['md_name'],
-                                          $p_array['md_type'],
-                                          $p_array['md_affect'],
-                                          $this->md_id
-                                          ));
-           if ( $p_array['seq'] != 0 )
-             
$this->cn->alter_seq('seq_doc_type_'.$p_array['md_type'],$p_array['seq']);
-
-            // Save the file
-            $new_name=tempnam($_ENV['TMP'],'document_');
-            if ( strlen ($_FILES['doc']['tmp_name']) != 0 )
-            {
-                if (move_uploaded_file($_FILES['doc']['tmp_name'],
-                                       $new_name))
-                {
-                    // echo "Image saved";
-                    $oid= $this->cn->lo_import($new_name);
-                    if ( $oid == false )
-                    {
-                        
echo_error('class_document_modele.php',__LINE__,"cannot upload document");
-                        $this->cn->rollback();
-                        return;
-                    }
-                    // Remove old document
-                    $ret=$this->cn->exec_sql("select md_lob from 
document_modele where md_id=".$this->md_id);
-                    if (Database::num_row($ret) != 0)
-                    {
-                        $r=Database::fetch_array($ret,0);
-                        $old_oid=$r['md_lob'];
-                        if (strlen($old_oid) != 0)
-                            $this->cn->lo_unlink($old_oid);
-                    }
-                    // Load new document
-                    $this->cn->exec_sql("update document_modele set 
md_lob=".$oid.", md_mimetype='".$_FILES['doc']['type']."' 
,md_filename='".$_FILES['doc']['name']."' where md_id=".$this->md_id);
-                    $this->cn->commit();
-                }
-                else
-                {
-                    echo "<H1>Error</H1>";
-                    $this->cn->rollback();
-                    throw new Exception("Erreur".__FILE__.__LINE__);
-                }
-            }
-        }
-        catch (Exception $e)
-        {
-            rollback($this->cn);
-            return ;
-        }
-       $this->cn->commit();
-    }
-
-}
-?>
diff --git a/include/class_dossier.php b/include/class_dossier.php
deleted file mode 100644
index 2925587..0000000
--- a/include/class_dossier.php
+++ /dev/null
@@ -1,314 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief the class for the dossier, everywhere we need to know to
- * which folder we are connected, because we can't use $_SESSION, we
- * need to pass the dossier_id via a _GET or a POST variable
- */
-
-/*! \brief manage the current dossier, everywhere we need to know to
- * which folder we are connected, because we can't use $_SESSION, we
- * need to pass the dossier_id via a _GET or a POST variable
- *  private static $variable=array("id"=>"dos_id",
-                                "name"=>"dos_name",
-                                "desc"=>"dos_description");
- *
- */
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/ac_common.php';
-
-class Dossier
-{
-    private static $variable=array("id"=>"dos_id",
-                                   "name"=>"dos_name",
-                                   "desc"=>"dos_description");
-    function __construct($p_id)
-    {
-        $this->cn=new Database();      // Connect to the repository
-        $this->dos_id=$p_id;
-    }
-    /*!\brief return the $_REQUEST['gDossier'] after a check */
-    static function id()
-    {
-        self::check();
-        return $_REQUEST['gDossier'];
-    }
-
-    /**
-     * @brief Show the folder where user have access. 
-     * @param  p_type string   
-       - A for all dossiers 
-       - R for accessible folders
-       - X forbidden folders
-     * @param p_login is the user name
-     * @param p_text is a part of the name where are looking for
-     * @return     nothing
-     *
-     */
-    static function show_dossier($p_type,$p_login="",$p_text="",$limit=0)
-    {
-        $cn=new Database();
-        $str_limit=($limit==0)?'':' limit '.$limit;
-        if ( $p_type == "A")
-        {
-            $l_sql="select *, 'W' as priv_priv from ac_dossier where dos_name 
~* $2 or dos_description ~* $2 ORDER BY dos_name $str_limit  ";
-            $a_row=$cn->get_array($l_sql,$p_text);
-            return $a_row;
-        }
-        else if ($p_type == "R")
-        {
-            $l_sql="select * from jnt_use_dos
-                   natural join ac_dossier
-                   natural join ac_users
-                   where
-                   use_login=$1
-                   and ( dos_name ~* $2 or dos_description ~* $2)
-                   
-                   order by dos_name 
-                   $str_limit
-                   ";
-            
-            $a_row=$cn->get_array($l_sql,array($p_login,$p_text));
-            return $a_row;
-
-        } 
-        else  if ($p_type == 'X')
-        {
-            $l_sql=' select * from ac_dossier where dos_id not in 
-                  (select dos_id from jnt_use_dos where use_id=$1)
-                  and ( dos_name ~* $2 or dos_description ~* $2)
-                  order by dos_name '.$str_limit;
-            $a_row=$cn->get_array($l_sql,array($p_login,$p_text));
-            return $a_row;
-
-        }
-        else
-        {
-            throw new Exception (_("Erreur paramètre"));
-        } 
-        
-       
-    }
-    /**
-     * Count the number of folder in the repository
-     * @return integer
-     */
-    function count() 
-    {
-        $nb_folder=$this->cn->get_value('select count(*) from ac_dossier');
-        return $nb_folder;
-    }
-    /*!
-     * \brief Return all the users
-     * as an array
-     */
-    function get_user_folder($sql="")
-    {
-
-        $sql="
-            select
-                use_id,
-                use_first_name,
-                use_name,
-                use_login,
-                use_active,
-                use_admin,
-                ag_dossier
-            from
-            ac_users  as ac
-            left join    (select array_to_string(array_agg(dos_name),',') as 
ag_dossier,jt.use_id as jt_use_id
-                        from ac_dossier as ds
-                        join  jnt_use_dos as jt on (jt.dos_id=ds.dos_id)
-                        group by jt.use_id) as dossier_name on 
(jt_use_id=ac.use_id)
-            where
-            use_login!='phpcompta'
-            $sql
-            ";
-
-        $res=$this->cn->get_array($sql);
-        return $res;
-        }
-
-    /*!\brief check if gDossier is set */
-    static function check()
-    {
-        if ( ! isset ($_REQUEST['gDossier']) )
-        {
-            echo_error ('Dossier inconnu ');
-            exit('Dossier invalide ');
-        }
-        $id=$_REQUEST['gDossier'];
-        if ( is_numeric ($id) == 0 ||
-                strlen($id)> 6 ||
-                $id > 999999)
-            exit('gDossier Invalide : '.$id);
-
-    }
-    /*!\brief return a string to put to gDossier into a GET */
-    static function get()
-    {
-        self::check();
-        return "gDossier=".$_REQUEST['gDossier'];
-
-    }
-
-    /*!\brief return a string to set gDossier into a FORM */
-    static function hidden()
-    {
-        self::check();
-        return '<input type="hidden" id="gDossier" name="gDossier" 
value="'.$_REQUEST['gDossier'].'">';
-    }
-    /*!\brief retrieve the name of the current dossier */
-    static function name($id=0)
-    {
-        self::check();
-
-        $cn=new Database();
-        $id=($id==0)?$_REQUEST['gDossier']:$id;
-        $name=$cn->get_value("select dos_name from ac_dossier where 
dos_id=$1",array($_REQUEST['gDossier']));
-        return $name;
-    }
-
-    public function get_parameter($p_string)
-    {
-        if ( array_key_exists($p_string,self::$variable) )
-        {
-            $idx=self::$variable[$p_string];
-            return $this->$idx;
-        }
-        else
-            throw new Exception("Attribut inexistant $p_string");
-    }
-    public function set_parameter($p_string,$p_value)
-    {
-        if ( array_key_exists($p_string,self::$variable) )
-        {
-            $idx=self::$variable[$p_string];
-            $this->$idx=$p_value;
-        }
-        else
-           throw new Exception("Attribut inexistant $p_string");
-
-
-    }
-    public function get_info()
-    {
-        return var_export(self::$variable,true);
-    }
-
-    public function save()
-    {
-        $this->update();
-    }
-
-    public function update()
-    {
-        if ( strlen(trim($this->dos_name))== 0 ) return;
-
-        if ( $this->cn->get_value("select count(*) from ac_dossier where 
dos_name=$1 and dos_id<>$2",
-                                  array($this->dos_name,$this->dos_id)) !=0 )
-            return ;
-
-        $sql="update ac_dossier set dos_name=$1,dos_description=$2 ".
-             " where dos_id = $3";
-        $res=$this->cn->exec_sql(
-                 $sql,
-                 array(trim($this->dos_name),
-                       trim($this->dos_description),
-                       $this->dos_id)
-             );
-    }
-
-    public function load()
-    {
-
-        $sql="select dos_name,dos_description from ac_dossier where dos_id=$1";
-
-        $res=$this->cn->exec_sql(
-                 $sql,
-                 array($this->dos_id)
-             );
-
-        if ( Database::num_row($res) == 0 ) return;
-        $row=Database::fetch_array($res,0);
-        foreach ($row as $idx=>$value)
-        {
-            $this->$idx=$value;
-        }
-
-    }
-
-    static function get_version($p_cn)
-       {
-               return $p_cn->get_value('select val from version');
-       }
-
-       static function connect()
-       {
-               $id = Dossier::id();
-               $cn = new Database($id);
-               return $cn;
-       }
-       /**
-        *connect to folder and give to admin. the profile Admin(builtin)
-        * @param int $p_id dossier::id()
-        */
-       static function synchro_admin($p_id)
-       {
-               // connect to target
-               $cn=new Database($p_id);
-
-               if (! $cn->exist_table("profile_menu"))
-               {
-                       echo_warning("Dossier invalide");
-                       return;
-               }
-               // connect to repo
-               $repo=new Database();
-
-               $a_admin=$repo->get_array("select use_login from ac_users where
-                       use_admin=1 and use_active=1");
-               try
-               {
-                       /**
-                        * synchro global
-                        */
-                       $cn->start();
-                       for ($i=0;$i<count($a_admin);$i++)
-                       {
-                               $exist=$cn->get_value("select p_id from 
profile_user
-                                       where 
user_name=$1",array($a_admin[$i]['use_login']));
-                               if ( $exist == "")
-                               {
-                                       $cn->exec_sql("insert into 
profile_user(user_name,p_id) values($1,1)",
-                                                       
array($a_admin[$i]['use_login']));
-                               }
-
-                       }
-                       $cn->commit();
-               } catch(Exception $e)
-               {
-                       echo_warning($e->getMessage());
-                       $cn->rollback();
-               }
-       }
-}
diff --git a/include/class_exercice.php b/include/class_exercice.php
deleted file mode 100644
index 490157b..0000000
--- a/include/class_exercice.php
+++ /dev/null
@@ -1,77 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief about the accountant exercice
- */
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_iselect.php';
-class Exercice
-{
-  function __construct(&$cn)
-  {
-    $this->cn=$cn;
-  }
-  /**
-   *return the number of different exercices into a folder
-   address@hidden $cn is the database connexion object database
-   address@hidden the count of exercice
-   */
-   function count()
-  {
-    $count=$this->cn->get_value('select count(distinct p_exercice) from 
parm_periode');
-    return $count;
-  }
-   /**
-    *Show a ISelect with the different exercices
-    address@hidden $name of the iselect
-    address@hidden $selected the selected year  (default = '')
-    address@hidden $js javascript (default = '')
-    address@hidden ISelect object
-    */
-   function select($name,$selected='',$js='')
-   {
-     $iselect=new ISelect($name);
-     $iselect->value=$this->cn->make_array('select distinct 
p_exercice,p_exercice from parm_periode order by 1');
-     $iselect->selected=$selected;
-     $iselect->javascript=$js;
-     return $iselect;
-   }
-   /**
-    *Show a ISelect with the different exercices, display start and end date
-    address@hidden $name of the iselect
-    address@hidden $selected the selected year  (default = '')
-    address@hidden $js javascript (default = '')
-    address@hidden ISelect object
-    */
-   function select_date($name,$selected='',$js='')
-   {
-     $iselect=new ISelect($name);
-     $iselect->value=$this->cn->make_array("select distinct p_exercice,to_char 
(min(p_start),'DD.MM.YY')
-                                                                               
                                                         ||' - '
-                                                                               
                                                         ||to_char 
(max(p_end),'DD.MM.YY')
-                                                                               
        from parm_periode
-                                                                               
        group by p_exercice order by 1");
-     $iselect->selected=$selected;
-     $iselect->javascript=$js;
-     return $iselect;
-   }
-}
diff --git a/include/class_extension.php b/include/class_extension.php
deleted file mode 100644
index 7ca07c3..0000000
--- a/include/class_extension.php
+++ /dev/null
@@ -1,309 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief the extension class manages the plugins for the security, the access
- * the inclusion...
- */
-/*!\brief manage the extension, it involves the table extension
- *
- * Data member
- * - $cn database connection
- * - $variable :
- *    -  id (extension.ex_id)
- *    -  name (extension.ex_name)
- *    - plugin_code (extension.ex_code)
- *    - desc (extension.ex_desc)
- *    - enable (extension.ex_enable)
- *    - filepath (extension.ex_file)
- */
-require_once NOALYSS_INCLUDE.'/class_menu_ref_sql.php';
-require_once NOALYSS_INCLUDE.'/class_profile_sql.php';
-require_once NOALYSS_INCLUDE.'/class_menu_ref.php';
-require_once NOALYSS_INCLUDE.'/class_profile_menu.php';
-
-class Extension extends Menu_Ref_sql
-{
-    public function verify()
-    {
-        // Verify that the elt we want to add is correct
-        if (trim($this->me_code)=="") throw new Exception('Le code ne peut pas 
être vide');
-        if (trim($this->me_menu)=="") throw new Exception('Le nom ne peut pas 
être vide');
-        if (trim($this->me_file)=="") throw new Exception('Chemin incorrect');
-        if 
(file_exists('..'.DIRECTORY_SEPARATOR.'include'.DIRECTORY_SEPARATOR.'ext'.DIRECTORY_SEPARATOR.$this->me_file)
 == false)
-            throw new Exception ('Extension non trouvée, le chemin est-il 
correct?');
-    }
-    /address@hidden search a extension, the what is the column (extends_code */
-    function search($p_what)
-    {
-               $this->me_code=strtoupper($p_what);
-               if ( $this->load() == -1) return null;
-               return 1;
-    }
-    /*!\brief return 1 if the user given in parameter can access this extension
-     * otherwise returns 0
-     *\param $p_login the user login
-     *\return 1 has access, 0 has no access
-     */
-    function can_request($p_login)
-    {
-               $cnt=$this->cn->get_value("select count(*) from menu_ref
-                                                                               
join profile_menu using (me_code)
-                                                                               
join profile_user using (p_id)
-                                                                               
where
-                                                                               
me_code=$1
-                                                                               
and user_name=$2",
-                                                               
array($this->me_code,$p_login));
-               if ( $cnt > 0)        return 1;
-               return 0;
-    }
-    /address@hidden make an array of the available plugin for the current user
-     * @return  an array
-     address@hidden ISelect
-     */
-    static function make_array($cn)
-    {
-        $sql="select DISTINCT me_code as value, me_menu as label from ".
-             " menu_ref join profile_menu using (me_code)
-                                join profile_user using (p_id) where ".
-             " user_name=$1 and me_type='PL' ORDER BY ME_MENU";
-        $a=$cn->get_array($sql,array($_SESSION['g_user']));
-        return $a;
-    }
-    static function check_version($i)
-    {
-        global $version_noalyss;
-        if ( ! isset ($version_noalyss) || $version_noalyss < $i )
-        {
-            alert('Cette extension ne fonctionne pas sur cette version de 
NOALYSS'.
-                  ' Veuillez mettre votre programme a jour. Version minimum 
'.$i);
-            return;
-        }
-        Extension::check_plugin_version();
-    }
-    /**
-     * insert into the table profile_menu for the given profile id and 
depending
-     * of the module $p_module
-     * @global type $cn
-     * @param type $p_id profile.p_id
-     * @param type $p_module menu_ref.me_code
-     * @throws Exception 10 : profile absent , 20 module absent , 30 No parent 
menu
-     */
-    function insert_profile_menu($p_id=1,$p_module='EXT')
-    {
-        global $cn;
-        //profile exists ?
-        $profile=new Profile_sql($cn,$p_id);
-        if ( $profile->p_id != $p_id) {
-                throw new Exception(_('Profil inexistant'),10);
-        }
-        // Menu exists
-        $module=new Menu_Ref($cn,$p_module);
-        if ($module->me_code==null) {
-                throw new Exception(_('Module inexistant'),20);
-        }
-        // Dependency
-        $dep_id=$cn->get_value('select pm_id from profile_menu 
-                where
-                p_id=$1
-                and me_code = $2 ',array($p_id,$p_module));
-        // throw an exception if there is no dependency
-        if ($dep_id=="") {
-                throw new Exception(_('Pas de menu ').$p_module,30);
-        }
-        
-        $profil_menu=new Profile_Menu($cn);
-        $profil_menu->me_code=$this->me_code;
-        $profil_menu->me_code_dep=$p_module;
-        $profil_menu->p_type_display='S';
-        $profil_menu->p_id=$p_id;
-        $profil_menu->pm_id_dep=$dep_id;
-        
-        $cnt=$profil_menu->count(' where p_id=$1 and me_code = 
$2',array($p_id,$this->me_code));
-        if ( $cnt==0) {
-            $profil_menu->insert();
-        }
-
-        
-    }
-    function remove_from_profile_menu($p_id)
-    {
-        global $cn;
-       
-         $cn->exec_sql('delete from profile_menu  where (me_code = $1 or 
me_code in (select me_code from menu_ref where me_file=$2)) and 
p_id=$3',array($this->me_code,$this->me_file,$p_id));
-        
-    }
-    /**
-     * Insert a plugin into the given profile, by default always insert into 
EXT
-     * 
-     * @param type $p_id profile.p_id
-     * @throws Exception if duplicate or error db
-     */
-       function insert_plugin()
-       {
-               try
-               {
-                       $this->cn->start();
-                       $this->verify();
-                       // check if duplicate
-                       $this->me_code = strtoupper($this->me_code);
-                       $count = $this->cn->get_value("select count(*) from 
menu_ref where me_code=$1", array($this->me_code));
-                       if ($count != 0)
-                               throw new Exception("Doublon");
-                       $this->me_type = 'PL';
-                       $this->insert();
-                       $this->cn->commit();
-               }
-               catch (Exception $exc)
-               {
-                       echo alert($exc->getMessage());
-               }
-       }
-       function update_plugin()
-       {
-               try
-               {
-                       $this->cn->start();
-                       $this->verify();
-                       $this->me_type = 'PL';
-                       $this->update();
-                       $this->cn->commit();
-               }
-               catch (Exception $exc)
-               {
-                       echo alert($exc->getMessage());
-               }
-       }
-       function remove_plugin()
-       {
-               try
-               {
-                       $this->cn->start();
-                       $this->delete();
-                       $this->cn->commit();
-               }
-               catch (Exception $exc)
-               {
-                       echo alert($exc->getMessage());
-               }
-       }
-       /**
-        *remove all the schema from the plugins
-        * @param Database $p_cn
-        */
-       static function clean(Database $p_cn)
-       {
-               
$a_ext=array("tva_belge","amortissement","impdol","coprop","importbank");
-               for($i=0;$i<count($a_ext);$i++){
-                       if ($p_cn->exist_schema($a_ext[$i])) {
-                               $p_cn->exec_sql("drop schema ".$a_ext[$i]." 
cascade");
-                       }
-               }
-       }
-        static function check_plugin_version()
-        {
-            global $g_user,$version_plugin;
-            if ($g_user->Admin() == 1)
-            {
-                if (SITE_UPDATE_PLUGIN != "")
-                {
-                    $update = @file_get_contents(SITE_UPDATE_PLUGIN);
-                    if ($update > $version_plugin)
-                    {
-                        echo '<div id="version_plugin_div_id" 
class="inner_box" 
style="position:absolute;zindex:2;top:5px;left:37.5%;width:25%">';
-                        echo '<p class="notice">';
-                        echo "Mise à jour disponible des plugins pour NOALYSS, 
version actuelle : $update votre version $version_plugin";
-                        echo '</p>';
-                         echo '<p style="text-align:center">'.
-                               '<a id="version_plugin_button" class="button" 
onclick="$(\'version_plugin_div_id\').remove()">'.
-                         _('Fermer').
-                         "</a></p>";
-                        echo '</div>';
-                    }
-                }
-            }
-        }
-        /**
-         * Check that the xml contains all the needed information to change 
them into
-         * a extension, the exception code is 0 if the element is optional
-         * @brief Check XML.
-         * @param SimpleXMLElement $xml
-         * @throws Exception
-         */
-        function check_xml(SimpleXMLElement $xml)
-        {
-            try {
-                if ( !isset ($xml->plugin)) throw new Exception(_('Manque 
plugin'),1);
-                $nb_plugin=count($xml->plugin);
-            
-                for ($i=0;$i<$nb_plugin;$i++)
-                {
-                    if ( !isset ($xml->plugin[$i]->name)) throw new 
Exception(_('Manque nom'),1);
-                    if ( !isset ($xml->plugin[$i]->description)) throw new 
Exception(_('Manque description'),0);
-                    if ( !isset ($xml->plugin[$i]->code)) throw new 
Exception(_('Manque code'),1);
-                    if ( !isset ($xml->plugin[$i]->author)) throw new 
Exception(_('Manque auteur'),0);
-                    if ( !isset ($xml->plugin[$i]->root)) throw new 
Exception(_('Manque répertoire racine'),1);
-                    if ( !isset ($xml->plugin[$i]->file)) throw new 
Exception(_('Manque fichier à inclure'),1);
-                }
-            } catch (Exception $ex) {
-                throw $ex;
-            }
-        }
-         /**
-         * Parse a XML file to complete an array of extension objects
-         * @brief Create extension from XML.
-         * @param type $p_file filename
-         * @return array of Extension
-         */
-        static function read_definition($p_file)
-        {
-            global $cn;
-            $dom=new DomDocument('1.0');
-            $dom->load($p_file);
-            $xml=simplexml_import_dom($dom);
-            $nb_plugin=count($xml->plugin);
-            $a_extension=array();
-            for ($i=0;$i<$nb_plugin;$i++)
-            {
-                
-                $extension=new Extension($cn);
-                try {
-                        $extension->check_xml($xml);
-                } catch (Exception $ex) {
-                    echo_warning($e->getMessage());
-                    if ( $ex->getCode()==1) {
-                        continue;
-                    }
-                    
-                }
-                
$extension->me_file=trim($xml->plugin[$i]->root).'/'.trim($xml->plugin[$i]->file);
-                $extension->me_code=trim($xml->plugin[$i]->code);
-                $extension->me_description=(isset 
($xml->plugin[$i]->description))?trim($xml->plugin[$i]->description):"";
-                
$extension->me_description_etendue=(trim($xml->plugin[$i]->author))?trim($xml->plugin[$i]->author):"";
-                $extension->me_type='PL';
-                $extension->me_menu=trim($xml->plugin[$i]->name);
-                
$extension->me_parameter='plugin_code='.trim($xml->plugin[$i]->code);
-                $a_extension[]=clone $extension;
-            }
-            return $a_extension;
-        }
-}
-
diff --git a/include/class_fiche.php b/include/class_fiche.php
deleted file mode 100644
index 065c24a..0000000
--- a/include/class_fiche.php
+++ /dev/null
@@ -1,1992 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-
-
-// Copyright Author Dany De Bontridder address@hidden
-include_once("class_fiche_attr.php");
-require_once NOALYSS_INCLUDE.'/class_ispan.php';
-require_once NOALYSS_INCLUDE.'/class_itva_popup.php';
-require_once NOALYSS_INCLUDE.'/class_itext.php';
-require_once NOALYSS_INCLUDE.'/class_ihidden.php';
-require_once NOALYSS_INCLUDE.'/class_fiche_def.php';
-require_once NOALYSS_INCLUDE.'/class_iposte.php';
-
-/*! \file
- * \brief define Class fiche, this class are using
- *        class attribut
- */
-/*!
- * \brief define Class fiche and fiche def, those class are using
- *        class attribut. When adding or modifing new card in a IPOPUP
- *        the ipopup for the accounting item is ipop_account
- */
-
-//-----------------------------------------------------
-// class fiche
-//-----------------------------------------------------
-class Fiche
-{
-    var $cn;           /*! < $cn database connection */
-    var $id;           /*! < $id fiche.f_id */
-    var $fiche_def;    /*! < $fiche_def fd_id */
-    var $attribut;     /*! < $attribut array of attribut object */
-    var $fiche_def_ref; /*!< $fiche_def_ref Type */
-    var $row;           /*! < All the row from the ledgers */
-    var $quick_code;           /*!< quick_code of the card */
-    function __construct($p_cn,$p_id=0)
-    {
-        $this->cn=$p_cn;
-        $this->id=$p_id;
-        $this->quick_code='';
-    }
-    /**
-     address@hidden used with a usort function, to sort an array of Fiche on 
the name
-     */
-    static function cmp_name(Fiche $o1,Fiche $o2)
-    {
-        return 
strcmp($o1->strAttribut(ATTR_DEF_NAME),$o2->strAttribut(ATTR_DEF_NAME));
-    }
-
-  /**
-   address@hidden get the available bank_account filtered by the security
-   address@hidden array of card
-   */
-    function get_bk_account()
-    {
-        global $g_user;
-      $sql_ledger=$g_user->get_ledger_sql('FIN',3);
-      $avail=$this->cn->get_array("select jrn_def_id,jrn_def_name,"
-              . "jrn_def_bank,jrn_def_description from jrn_def where 
jrn_def_type='FIN' and $sql_ledger
-                            order by jrn_def_name");
-
-      if ( count($avail) == 0 )
-            return null;
-
-      for ($i=0;$i<count($avail);$i++)
-        {
-            $t=new Fiche($this->cn,$avail[$i]['jrn_def_bank']);
-            $t->ledger_name=$avail[$i]['jrn_def_name'];
-            $t->ledger_description=$avail[$i]['jrn_def_description'];
-            $t->getAttribut();
-            $all[$i]=$t;
-
-        }
-        return $all;
-    }
-
-
-    /*!   get_by_qcode($p_qcode)
-     * \brief Retrieve a card thx his quick_code
-     *        complete the object,, set the id member of the object or set it
-     *        to 0 if no card is found
-     * \param $p_qcode quick_code (ad_id=23)
-     * \param $p_all retrieve all the attribut of the card, possible value
-     * are true or false. false retrieves only the f_id. By default true
-     * \return 0 success 1 error not found
-     */
-    function get_by_qcode($p_qcode=null,$p_all=true)
-    {
-        if ( $p_qcode == null )
-            $p_qcode=$this->quick_code;
-        $p_qcode=trim($p_qcode);
-        $sql="select f_id from fiche_detail
-             where ad_id=23 and ad_value=upper($1)";
-        $this->id=$this->cn->get_value($sql,array($p_qcode));
-        if ( $this->cn->count()==0)
-        {
-            $this->id=0;
-            return 1;
-        }
-
-
-        if ( $p_all )
-            $this->getAttribut();
-        return 0;
-    }
-    /**
-     address@hidden set an attribute by a value, if the attribut array is empty
-     * a call to getAttribut is performed
-     address@hidden the AD_ID
-     address@hidden the value
-     address@hidden constant.php table: attr_def
-     */
-    function setAttribut($p_ad_id,$p_value)
-    {
-        if ( sizeof($this->attribut)==0 ) $this->getAttribut();
-        for ($e=0;$e <sizeof($this->attribut);$e++)
-        {
-            if ( $this->attribut[$e]->ad_id == $p_ad_id )
-            {
-                $this->attribut[$e]->av_text=$p_value;
-                break;
-            }
-        }
-    }
-    /**
-     *\brief  get all the attribute of a card, add missing ones
-     *         and sort the array ($this-\>attribut) by ad_id
-     */
-    function getAttribut()
-    {
-        if ( $this->id == 0)
-        {
-            return;
-        }
-        $sql="select *
-             from
-                   fiche
-             natural join fiche_detail
-            join jnt_fic_attr on (jnt_fic_attr.fd_id=fiche.fd_id and 
fiche_detail.ad_id=jnt_fic_attr.ad_id)
-             join attr_def on (attr_def.ad_id=fiche_detail.ad_id) where 
f_id=".$this->id.
-             " order by jnt_order";
-
-        $Ret=$this->cn->exec_sql($sql);
-        if ( ($Max=Database::num_row($Ret)) == 0 )
-            return ;
-        for ($i=0;$i<$Max;$i++)
-        {
-            $row=Database::fetch_array($Ret,$i);
-            $this->fiche_def=$row['fd_id'];
-            $t=new Fiche_Attr ($this->cn);
-            $t->ad_id=$row['ad_id'];
-            $t->ad_text=$row['ad_text'];
-            $t->av_text=$row['ad_value'];
-            $t->ad_type=$row['ad_type'];
-            $t->ad_size=$row['ad_size'];
-            $t->ad_extra=$row['ad_extra'];
-            $t->jnt_order=$row['jnt_order'];
-            $this->attribut[$i]=$t;
-        }
-        $e=new Fiche_Def($this->cn,$this->fiche_def);
-        $e->GetAttribut();
-
-        if ( sizeof($this->attribut) != sizeof($e->attribut ) )
-        {
-
-            /*
-                        * !! Missing attribute
-                        */
-            foreach ($e->attribut as $f )
-            {
-                $flag=0;
-                foreach ($this->attribut as $g )
-                {
-                    if ( $g->ad_id == $f->ad_id )
-                        $flag=1;
-                }
-                if ( $flag == 0 )
-                {
-                    // there's a missing one, we insert it
-                    $t=new Fiche_Attr ($f->ad_id);
-                    $t->av_text="";
-                    $t->ad_text=$f->ad_text;
-                    $t->jnt_order=$f->jnt_order;
-                    $t->ad_type=$f->ad_type;
-                    $t->ad_size=$f->ad_size;
-                    $t->ad_id=$f->ad_id;
-                    $t->ad_extra=$f->ad_extra;
-                    $this->attribut[$Max]=$t;
-                    $Max++;
-                } // if flag == 0
-
-            }// foreach
-
-
-        }//missing attribut
-    }
-    /**
-     * @brief find the card with the p_attribut equal to p_value, it is not 
case sensitive
-     * @param $p_attribut attribute to find see table attr_def
-     * @param $p_value value in attr_value.av_text
-     * @return return ARRAY OF jft_id,f_id,fd_id,ad_id,av_text
-     */
-    function seek($p_attribut,$p_value)
-    {
-        $sql="select jft_id,f_id,fd_id,ad_id,ad_value from fiche join 
fiche_detail using (f_id)
-             where ad_id=$1 and upper(ad_value)=upper($2)";
-        $res=$this->cn->get_array($sql,array($p_attribut,$p_value));
-        return $res;
-    }
-
-    /*!
-     * \brief give the size of a card object
-     *
-     * \return size
-     */
-    function size()
-    {
-        if ( isset ($this->ad_id))
-            return sizeof($this->ad_id);
-        else
-            return 0;
-    }
-
-
-    /*!
-     **************************************************
-     * \brief  Return array of card from the frd family
-     *
-     * \param $p_frd_id the fiche_def_ref.frd_id
-     * \param $p_search p_search is a filter on the name
-     * \param $p_sql extra sql condition
-     *
-     * \return array of fiche object
-     */
-    function count_by_modele($p_frd_id,$p_search="",$p_sql="")
-    {
-        $sql="select *
-             from
-             fiche join fiche_Def using (fd_id)
-             where frd_id=".$p_frd_id;
-        if ( $p_search != "" )
-        {
-            $a=sql_string($p_search);
-            $sql="select * from vw_fiche_attr where frd_id=".$p_frd_id.
-                 " and vw_name ~* '$p_search'";
-        }
-
-        $Ret=$this->cn->exec_sql($sql.$p_sql);
-
-        return Database::num_row($Ret) ;
-    }
-    /*!
-     **************************************************
-     * \brief  Return array of card from the frd family
-     *
-     *
-     * \param  $p_frd_id the fiche_def_ref.frd_id
-     * \param  $p_offset
-     * \param  $p_search is an optional filter
-     *\param $p_order : possible values are name, f_id
-     * \return array of fiche object
-     */
-    function GetByDef($p_frd_id,$p_offset=-1,$p_search="",$p_order='')
-    {
-        switch($p_order)
-        {
-        case 'name' :
-                $order=' order by name';
-            break;
-        case 'f_id':
-            $order='order by f_id';
-            break;
-        default:
-            $order='';
-        }
-        if ( $p_offset == -1 )
-        {
-            $sql="select *
-                 from
-                 fiche join fiche_Def using (fd_id) join vw_fiche_name 
using(f_id)
-                 where frd_id=".$p_frd_id." $p_search ".$order;
-        }
-        else
-        {
-            $limit=($_SESSION['g_pagesize']!=-1)?"limit 
".$_SESSION['g_pagesize']:"";
-            $sql="select *
-                 from
-                 fiche join fiche_Def using (fd_id) join vw_fiche_name 
using(f_id)
-                 where frd_id=".$p_frd_id." $p_search $order  "
-                 .$limit." offset ".$p_offset;
-
-        }
-
-        $Ret=$this->cn->exec_sql($sql);
-        if ( ($Max=Database::num_row($Ret)) == 0 )
-            return ;
-        $all[0]=new Fiche($this->cn);
-
-        for ($i=0;$i<$Max;$i++)
-        {
-            $row=Database::fetch_array($Ret,$i);
-            $t=new Fiche($this->cn,$row['f_id']);
-            $t->getAttribut();
-            $all[$i]=clone $t;
-
-        }
-        return $all;
-    }
-    function ShowTable()
-    {
-        echo "<TR><TD> ".
-        $this->id."</TD>".
-        "<TR> <TD>".
-        $this->attribut_value."</TD>".
-        "<TR> <TD>".
-        $this->attribut_def."</TD></TR>";
-    }
-    /***
-     * @brief  return the string of the given attribute
-     *        (attr_def.ad_id)
-     * @param $p_ad_id the AD_ID from attr_def.ad_id
-     * @param $p_return 1 return NOTFOUND otherwise an empty string
-     * @see constant.php
-     * @return string
-     */
-    function strAttribut($p_ad_id,$p_return=1)
-    {
-               $return=($p_return==1)?NOTFOUND:"";
-        if ( sizeof ($this->attribut) == 0 )
-        {
-
-            if ($this->id==0) {
-                                       return $return;
-                       }
-            // object is not in memory we need to look into the database
-            $sql="select ad_value from fiche_detail
-                 where f_id= $1  and ad_id= $2 ";
-            $Res=$this->cn->exec_sql($sql,array($this->id,$p_ad_id));
-            $row=Database::fetch_all($Res);
-            // if not found return error
-            if ( $row == false )
-                return $return;
-
-            return $row[0]['ad_value'];
-        }
-
-        foreach ($this->attribut as $e)
-        {
-            if ( $e->ad_id == $p_ad_id )
-                return $e->av_text;
-        }
-        return $return;
-    }
-    /**
-     * @brief make an array of attributes of the category of card 
(FICHE_DEF.FD_ID)
-     *The array can be used with the function insert, it will return a struct 
like this :
-     * in the first key (av_textX),  X is the ATTR_DEF::AD_ID
-    \verbatim
-    Example
-    Array
-    (
-      [av_text1] => Nom
-      [av_text12] => Personne de contact
-      [av_text5] => Poste Comptable
-      [av_text13] => numéro de tva
-      [av_text14] => Adresse
-      [av_text15] => code postal
-      [av_text24] => Ville
-      [av_text16] => pays
-      [av_text17] => téléphone
-      [av_text18] => email
-      [av_text23] => Quick Code
-    )
-
-    \endverbatim
-     *\param $pfd_id FICHE_DEF::FD_ID
-     *\return an array of attribute
-     *\exception Exception if the cat of card doesn't exist, 
Exception.getCode()=1
-     *\see fiche::insert()
-     */
-    function to_array($pfd_id)
-    {
-        $sql="select 'av_text'||to_char(ad_id,'9999') as key,".
-             " ad_text ".
-             " from fiche_def join jnt_fic_attr using (fd_id)".
-             " join attr_def using (ad_id) ".
-             " where fd_id=$1 order by jnt_order";
-        $ret=$this->cn->get_array($sql,array($pfd_id));
-        if ( empty($ret)) throw new Exception(_('Cette categorie de card 
n\'existe pas').' '.$pfd_id,1);
-        $array=array();
-        foreach($ret as $idx=>$val)
-        {
-            $a=str_replace(' ','',$val['key']);
-            $array[$a]=$val['ad_text'];
-        }
-        return $array;
-
-    }
-    /*!
-     * \brief  insert a new record
-     *         show a blank card to be filled
-     *
-     * \param  $p_fiche_def is the fiche_def.fd_id
-     *
-     * \return HTML Code
-     */
-    function blank($p_fiche_def)
-    {
-        // array = array of attribute object sorted on ad_id
-        $f=new Fiche_Def($this->cn,$p_fiche_def);
-        $f->get();
-        $array=$f->getAttribut();
-        $r=h2(_('Catégorie').' '.$f->label,"");
-        $r.='<table style="width:98%;margin:1%">';
-        foreach ($array as $attr)
-        {
-            $table=0;
-            $msg="";$bulle='';
-            if ( $attr->ad_id == ATTR_DEF_ACCOUNT)
-            {
-                $w=new IPoste("av_text".$attr->ad_id);
-                $w->set_attribute('ipopup','ipop_account');
-                $w->set_attribute('account',"av_text".$attr->ad_id);
-                               $w->dbl_click_history();
-                //  account created automatically
-                $sql="select account_auto($p_fiche_def)";
-                $ret_sql=$this->cn->exec_sql($sql);
-                $a=Database::fetch_array($ret_sql,0);
-                $label=new ISpan();
-                $label->name="av_text".$attr->ad_id."_label";
-
-                if ( $a['account_auto'] == 't' )
-                    $msg.=$label->input()." <span style=\"color:red\">".
-                                               _("Rappel: Poste créé 
automatiquement à partir de ")
-                                               .$f->class_base." </span> ";
-                else
-                {
-                    // if there is a class base in fiche_def_ref, this account 
will be the
-                    // the default one
-                    if ( strlen(trim($f->class_base)) != 0 )
-                    {
-                        $msg.="<TD>".$label->input()." <span 
style=\"color:red\">"._("Rappel: Poste par défaut sera ").
-                              $f->class_base.
-                              " !</span> ";
-                        $w->value=$f->class_base;
-                    }
-
-                }
-                $r.="<TR>".td(_("Poste Comptable"),' class="input_text" ' 
).td($w->input().$msg)."</TR>";
-                continue;
-            }
-            elseif ( $attr->ad_id == ATTR_DEF_TVA)
-            {
-                $w=new ITva_Popup('popup_tva');
-                $w->table=1;
-            }
-
-            else
-            {
-             switch ($attr->ad_type)
-                {
-                    case 'text':
-                            $w = new IText();
-                            $w->css_size = "100%";
-                            break;
-                    case 'numeric':
-                            $w = new INum();
-                            $w->prec=($attr->ad_extra=="")?2:$attr->ad_extra;
-                            $w->size = $attr->ad_size;
-                            break;
-                    case 'date':
-                            $w = new IDate();
-                            break;
-                    case 'zone':
-                            $w = new ITextArea();
-                            $w->style=' class="itextarea" 
style="margin:0px;width:100%"';
-                            break;
-                    case 'poste':
-                            $w = new IPoste("av_text" . $attr->ad_id);
-                            $w->set_attribute('ipopup', 'ipop_account');
-                            $w->set_attribute('account', "av_text" . 
$attr->ad_id);
-                            $w->table = 1;
-                            $bulle = HtmlInput::infobulle(14);
-                            break;
-                    case 'select':
-                            $w = new ISelect("av_text" . $attr->ad_id);
-                            $w->value = $this->cn->make_array($attr->ad_extra);
-                            $w->style= 'style="width:100%"';
-                            break;
-                    case 'card':
-                            $w = new ICard("av_text" . $attr->ad_id);
-                            // filter on frd_id
-                            $w->extra = $attr->ad_extra;
-                            $w->extra2 = 0;
-                            $label = new ISpan();
-                            $label->name = "av_text" . $attr->ad_id . "_label";
-                            $w->set_attribute('ipopup', 'ipopcard');
-                            $w->set_attribute('typecard', $attr->ad_extra);
-                            $w->set_attribute('inp', "av_text" . $attr->ad_id);
-                            $w->set_attribute('label', "av_text" . 
$attr->ad_id . "_label");
-                            $msg = $w->search();
-                            $msg.=$label->input();
-                            break;
-                }
-                $w->table = 0;
-            }
-            $w->table = $table;
-            $w->label = $attr->ad_text;
-            $w->name = "av_text" . $attr->ad_id;
-            if ($attr->ad_id == 21 || 
$attr->ad_id==22||$attr->ad_id==20||$attr->ad_id==31)
-            {
-                    $bulle=HtmlInput::infobulle(21);
-            }
-            $r.="<TR>" . td(_($w->label)." $bulle", ' class="input_text" ') . 
td($w->input()." $msg")." </TR>";
-        }
-        $r.= '</table>';
-        return $r;
-    }
-
-
-    /*!
-     * \brief  Display object instance, getAttribute
-     *        sort the attribute and add missing ones
-     * \param $p_readonly true= if can not modify, otherwise false
-     *
-     *
-     * \return string to display or FNT string for fiche non trouvé
-     */
-    function Display($p_readonly)
-    {
-        $this->GetAttribut();
-        $attr=$this->attribut;
-        /* show card type here */
-        $type_card=$this->cn->get_value('select fd_label '
-                . ' from fiche_def join fiche using (fd_id) where f_id=$1',
-                array($this->id));
-        $ret="";
-        $ret.=h2(_("Catégorie")." ".$type_card, 'style="display:inline"');
-        $ret.='<span style="font-weight:bolder;margin-right:5px;float:right">'.
-                _('id fiche').':'.$this->id."</span>";
-        $ret.="<table style=\"width:98%;margin:1%\">";
-        if (empty($attr))
-        {
-            return 'FNT';
-        }
-
-        /* for each attribute */
-        foreach ($attr as $r)
-        {
-            $msg="";
-            $bulle="";
-            if ($p_readonly)
-            {
-                $w=new IText();
-                $w->table=1;
-                $w->readOnly=true;
-                $w->css_size="100%";
-            }
-            if ($p_readonly==false)
-            {
-
-                if ($r->ad_id==ATTR_DEF_ACCOUNT)
-                {
-                    $w=new IPoste("av_text".$r->ad_id);
-                    $w->set_attribute('ipopup', 'ipop_account');
-                    $w->set_attribute('account', "av_text".$r->ad_id);
-                    $w->dbl_click_history();
-                    //  account created automatically
-                    $w->table=0;
-                    $w->value=$r->av_text;
-                    //  account created automatically
-                    $sql="select account_auto($this->fiche_def)";
-                    $ret_sql=$this->cn->exec_sql($sql);
-                    $a=Database::fetch_array($ret_sql, 0);
-                    $bulle=HtmlInput::infobulle(10);
-
-                    if ($a['account_auto']=='t')
-                        $bulle.=HtmlInput::warnbulle(11);
-                }
-                elseif ($r->ad_id==ATTR_DEF_TVA)
-                {
-                    $w=new ITva_Popup('popup_tva');
-                    $w->table=1;
-                    $w->value=$r->av_text;
-                }
-                else
-                {
-                    switch ($r->ad_type)
-                    {
-                        case 'text':
-                            $w=new IText('av_text'.$r->ad_id);
-                            $w->css_size="100%";
-                            $w->value=$r->av_text;
-                            break;
-                        case 'numeric':
-                            $w=new INum('av_text'.$r->ad_id);
-                            $w->size=$r->ad_size;
-                            $w->prec=($r->ad_extra=="")?2:$r->ad_extra;
-                            $w->value=$r->av_text;
-                            break;
-                        case 'date':
-                            $w=new IDate('av_text'.$r->ad_id);
-                            $w->value=$r->av_text;
-                            break;
-                        case 'zone':
-                            $w=new ITextArea('av_text'.$r->ad_id);
-                            $w->style=' class="itextarea" 
style="margin:0px;width:100%"';
-                            $w->value=$r->av_text;
-                            break;
-                        case 'poste':
-                            $w=new IPoste("av_text".$r->ad_id);
-                            $w->set_attribute('ipopup', 'ipop_account');
-                            $w->set_attribute('account', "av_text".$r->ad_id);
-                            $w->dbl_click_history();
-                            $w->width=$r->ad_size;
-                            $w->table=0;
-                            $bulle=HtmlInput::infobulle(14);
-                            $w->value=$r->av_text;
-                            break;
-                        case 'card':
-                            $uniq=rand(0, 1000);
-                            $w=new ICard("av_text".$r->ad_id);
-                            $w->id="card_".$this->id.$uniq;
-                            // filter on ad_extra
-
-                            $filter=$r->ad_extra;
-                            $w->width=$r->ad_size;
-                            $w->extra=$filter;
-                            $w->extra2=0;
-                            $label=new ISpan();
-                            $label->name="av_text".$uniq.$r->ad_id."_label";
-                            $fiche=new Fiche($this->cn);
-                            $fiche->get_by_qcode($r->av_text);
-                            if ($fiche->id==0)
-                            {
-                                $label->value=(trim($r->av_text)=='')?"":" 
"._("Fiche non trouvée")." ";
-                                $r->av_text="";
-                            }
-                            else
-                            {
-                                
$label->value=$fiche->strAttribut(ATTR_DEF_NAME).
-                                        " ".
-                                        
$fiche->strAttribut(ATTR_DEF_FIRST_NAME,0);
-                            }
-                            $w->set_attribute('ipopup', 'ipopcard');
-                            $w->set_attribute('typecard', $filter);
-                            $w->set_attribute('inp', "av_text".$r->ad_id);
-                            $w->set_attribute('label', $label->name);
-                            $w->autocomplete=0;
-                            $w->dblclick="fill_ipopcard(this);";
-                            $msg=$w->search();
-                            $msg.=$label->input();
-                            $w->value=$r->av_text;
-                            break;
-                        case 'select':
-                            $w=new ISelect();
-                            $w->value=$this->cn->make_array($r->ad_extra);
-                            $w->selected=$r->av_text;
-                            $w->style=' style="width:100%" ';
-                            break;
-                        default:
-                            var_dump($r);
-                            throw new Exception("Type invalide");
-                    }
-                    $w->table=0;
-                }
-            }
-            else
-            {
-                switch ($r->ad_type)
-                {
-                    case 'select':
-                        $x=new ISelect();
-                        $x->value=$this->cn->make_array($r->ad_extra);
-                        $x->selected=$r->av_text;
-                        $value=$x->display();
-                        $w->value=$value;
-                        break;
-                    default:
-                        $w->value=$r->av_text;
-                }
-            }
-
-            $w->name="av_text".$r->ad_id;
-            $w->readOnly=$p_readonly;
-
-            if ($r->ad_id==21||$r->ad_id==22||$r->ad_id==20||$r->ad_id==31)
-            {
-                $bulle=HtmlInput::infobulle(21);
-            }
-            $ret.="<TR>".td(_($r->ad_text).$bulle).td($w->input()." ".$msg)." 
</TR>";
-        }
-
-        $ret.="</table>";
-
-        return $ret;
-    }
-
-    /*!
-     * \brief  Save a card, call insert or update
-     *
-     * \param p_fiche_def (default 0)
-     */
-    function Save($p_fiche_def=0)
-    {
-        // new card or only a update ?
-        if ( $this->id == 0 )
-            $this->insert($p_fiche_def);
-        else
-            $this->update();
-    }
-    /*!
-     * \brief  insert a new record
-     *
-     * \param $p_fiche_def fiche_def.fd_id
-     * \param $p_array is the array containing the data
-     *\param $transation if we want to manage the transaction in this function
-     * true for small insert and false for a larger loading, the BEGIN / 
COMMIT sql
-     * must be done into the caller
-     av_textX where X is the ad_id
-     *\verb
-    example
-    av_text1=>'name'
-    \endverb
-     */
-    function insert($p_fiche_def,$p_array=null,$transaction=true)
-    {
-        if ($p_array==null)
-            $p_array=$_POST;
-
-        $fiche_id=$this->cn->get_next_seq('s_fiche');
-        $this->id=$fiche_id;
-        // first we create the card
-        if ($transaction)
-            $this->cn->start();
-        /*
-         * Sort the array for having the name AFTER the quickcode and the 
-         * Accounting
-         */
-        ksort($p_array);
-
-        try
-        {
-            $sql=sprintf("insert into fiche(f_id,fd_id)".
-                    " values (%d,%d)", $fiche_id, $p_fiche_def);
-            $Ret=$this->cn->exec_sql($sql);
-            // parse the $p_array array
-            foreach ($p_array as $name=> $value)
-            {
-                /* avoid the button for searching an accounting item */
-                if (preg_match('/^av_text[0-9]+$/', $name)==0)
-                    continue;
-
-                list ($id)=sscanf($name, "av_text%d");
-                if ($id==null)
-                    continue;
-
-                // Special traitement
-                // quickcode
-                if ($id==ATTR_DEF_QUICKCODE)
-                {
-                    $sql=sprintf("select insert_quick_code(%d,'%s')", 
$fiche_id,
-                            sql_string($value));
-                    $this->cn->exec_sql($sql);
-                    continue;
-                }
-                // name
-                if ($id==ATTR_DEF_NAME)
-                {
-                    if (strlen(trim($value))==0)
-                        $value="pas de nom";
-                }
-                // account
-                if ($id==ATTR_DEF_ACCOUNT)
-                {
-                    $v=mb_substr(sql_string($value), 0, 40);
-                    try
-                    {
-
-                        if (strlen(trim($v))!=0)
-                        {
-                            if (strpos($value, ',')==0)
-                            {
-                                $v=$this->cn->get_value("select 
format_account($1)",
-                                        array($value));
-                            }
-                            else
-                            {
-                                $ac_array=explode(",", $value);
-                                if (count($ac_array)<>2)
-                                    throw new Exception('Désolé, il y a trop 
de virgule dans le poste comptable '.h($value));
-                                $part1=$ac_array[0];
-                                $part2=$ac_array[1];
-                                $part1=$this->cn->get_value('select 
format_account($1)',
-                                        array($part1));
-                                $part2=$this->cn->get_value('select 
format_account($1)',
-                                        array($part2));
-                                $v=$part1.','.$part2;
-                            }
-                            $parameter=array($this->id, $v);
-                        }
-                        else
-                        {
-                            $parameter=array($this->id, null);
-                        }
-                        $v=$this->cn->get_value("select account_insert($1,$2)",
-                                $parameter);
-                    }
-                    catch (Exception $e)
-                    {
-                        throw new Exception("Erreur : ce compte [$v] n'a pas 
de compte parent.".
-                        "L'opération est annulée", 1);
-                    }
-                    continue;
-                }
-                // TVA
-                if ($id==ATTR_DEF_TVA)
-                {
-                    // Verify if the rate exists, if not then do not update
-                    if (strlen(trim($value))!=0)
-                    {
-                        if (isNumber($value)==0)
-                            continue;
-                        if ($this->cn->count_sql("select * from tva_rate where 
tva_id=".$value)==0)
-                        {
-                            continue;
-                        }
-                    }
-                }
-                // Normal traitement
-                $value2=sql_string($value);
-
-                $sql=sprintf("select attribut_insert(%d,%d,'%s')", $fiche_id,
-                        $id, strip_tags(trim($value2)));
-                $this->cn->exec_sql($sql);
-            }
-        }
-        catch (Exception $e)
-        {
-            $this->cn->rollback();
-            throw ($e);
-            return;
-        }
-        if ($transaction)
-            $this->cn->commit();
-        return;
-    }
-
-    /*!\brief update a card
-     */
-    function update($p_array=null)
-    {
-        global $g_user;
-        if ($p_array==null)
-            $p_array=$_POST;
-
-        try
-        {
-            $this->cn->start();
-            // parse the $p_array array
-            foreach ($p_array as $name=> $value)
-            {
-                if (preg_match('/^av_text[0-9]+$/', $name)==0)
-                    continue;
-
-                list ($id)=sscanf($name, "av_text%d");
-
-                if ($id==null)
-                    continue;
-
-                // retrieve jft_id to update table attr_value
-                $sql=" select jft_id from fiche_detail where ad_id=$id and 
f_id=$this->id";
-                $Ret=$this->cn->exec_sql($sql);
-                if (Database::num_row($Ret)==0)
-                {
-                    // we need to insert this new attribut
-                    $jft_id=$this->cn->get_next_seq('s_jnt_fic_att_value');
-
-                    $sql2="insert into 
fiche_detail(jft_id,ad_id,f_id,ad_value) values ($1,$2,$3,NULL)";
-
-                    $ret2=$this->cn->exec_sql($sql2,
-                            array($jft_id, $id, $this->id));
-                }
-                else
-                {
-                    $tmp=Database::fetch_array($Ret, 0);
-                    $jft_id=$tmp['jft_id'];
-                }
-                // Special traitement
-                // quickcode
-                if ($id==ATTR_DEF_QUICKCODE)
-                {
-                    $sql=sprintf("select update_quick_code(%d,'%s')", $jft_id,
-                            sql_string($value));
-                    $this->cn->exec_sql($sql);
-                    continue;
-                }
-                // name
-                if ($id==ATTR_DEF_NAME)
-                {
-                    if (strlen(trim($value))==0)
-                        continue;
-                }
-                // account
-                if ($id==ATTR_DEF_ACCOUNT)
-                {
-                    $v=sql_string($value);
-                    if (trim($v)!='')
-                    {
-                        if (strpos($v, ',')!=0)
-                        {
-                            $ac_array=explode(",", $v);
-                            if (count($ac_array)<>2)
-                                throw new Exception('Désolé, il y a trop de 
virgule dans le poste comptable '.h($v));
-                            $part1=$ac_array[0];
-                            $part2=$ac_array[1];
-                            $part1=$this->cn->get_value('select 
format_account($1)',
-                                    array($part1));
-                            $part2=$this->cn->get_value('select 
format_account($1)',
-                                    array($part2));
-                            $v=$part1.','.$part2;
-                        }
-                        else
-                        {
-                            $v=$this->cn->get_value('select 
format_account($1)',
-                                    array($value));
-                        }
-                        $sql=sprintf("select account_update(%d,'%s')",
-                                $this->id, $v);
-                        try
-                        {
-                            $this->cn->exec_sql($sql);
-                        }
-                        catch (Exception $e)
-                        {
-                            throw new Exception(__LINE__."Erreur : ce compte 
[$v] n'a pas de compte parent.".
-                            "L'op&eacute;ration est annul&eacute;e");
-                        }
-                        continue;
-                    }
-                    if (strlen(trim($v))==0)
-                    {
-
-                        $sql=sprintf("select account_update(%d,null)", 
$this->id);
-                        try
-                        {
-                            $Ret=$this->cn->exec_sql($sql);
-                        }
-                        catch (Exception $e)
-                        {
-                            throw new Exception(__LINE__."Erreur : ce compte 
[$v] n'a pas de compte parent.".
-                            "L'opération est annulée");
-                        }
-
-                        continue;
-                    }
-                }
-                // TVA
-                if ($id==ATTR_DEF_TVA)
-                {
-                    // Verify if the rate exists, if not then do not update
-                    if (strlen(trim($value))!=0)
-                    {
-                        if ($this->cn->count_sql("select * from tva_rate where 
tva_id=".$value)==0)
-                        {
-                            continue;
-                        }
-                    }
-                }
-                // Normal traitement
-                $sql="update fiche_detail set ad_value=$1 where jft_id=$2";
-                $this->cn->exec_sql($sql, array(strip_tags($value), $jft_id));
-            }
-        }
-        catch (Exception $e)
-        {
-            echo '<span class="error">'.
-            $e->getMessage().
-            '</span>';
-            $this->cn->rollback();
-            return;
-        }
-        $this->cn->commit();
-        return;
-    }
-
-    /*!\brief  remove a card
-    */
-    function remove($silent=false)
-    {
-        if ( $this->id==0 ) return;
-        // verify if that card has not been used is a ledger
-        // if the card has its own account in PCMN
-        // Get the fiche_def.fd_id from fiche.f_id
-        $this->Get();
-        $fiche_def=new Fiche_Def($this->cn,$this->fiche_def);
-        $fiche_def->get();
-
-        // if the card is used do not removed it
-        $qcode=$this->strAttribut(ATTR_DEF_QUICKCODE);
-
-        if ( $this->cn->count_sql("select * from jrnx where 
j_qcode='".Database::escape_string($qcode)."'") != 0)
-        {
-            if ( ! $silent ) {
-               alert(_('Impossible cette fiche est utilisée dans un journal'));
-            }
-            return 1;
-        }
-
-        $this->delete();
-               return 0;
-    }
-
-
-    /*!\brief return the name of a card
-     *
-     */
-    function getName()
-    {
-        $sql="select ad_value from fiche_detail
-             where ad_id=1 and f_id=$1";
-        $Res=$this->cn->exec_sql($sql,array($this->id));
-        $r=Database::fetch_all($Res);
-        if ( sizeof($r) == 0 )
-            return 1;
-        return $r[0]['ad_value'];
-    }
-
-    /*!\brief return the quick_code of a card
-     * \return null if not quick_code is found
-     */
-    function get_quick_code()
-    {
-        $sql="select ad_value from fiche_detail where ad_id=23 and f_id=$1";
-        $Res=$this->cn->exec_sql($sql,array($this->id));
-        $r=Database::fetch_all($Res);
-        if ( sizeof($r) == 0 )
-            return null;
-        return $r[0]['ad_value'];
-    }
-
-    /*!\brief Synonum of fiche::getAttribut
-     */
-    function Get()
-    {
-        $this->getAttribut();
-    }
-    /*!\brief Synonum of fiche::getAttribut
-     */
-    function load() 
-    {
-        $this->getAttribut();
-    }
-    /*!\brief get all the card thanks the fiche_def_ref
-     * \param $p_offset (default =-1)
-     * \param $p_search sql condition
-     * \return array of fiche object
-     */
-    function get_by_category($p_offset=-1,$p_search="",$p_order='')
-    {
-        return 
fiche::GetByDef($this->fiche_def_ref,$p_offset,$p_search,$p_order);
-    }
-    /*!\brief retrieve the frd_id of the fiche it is the type of the
-     *        card (bank, purchase...)
-     *        (fiche_def_ref primary key)
-     */
-    function get_fiche_def_ref_id()
-    {
-        $result=$this->cn->get_array("select frd_id from fiche join fiche_Def 
using (fd_id) where f_id=".$this->id);
-        if ( $result == null )
-            return null;
-
-        return $result[0]['frd_id'];
-    }
-    /**
-     address@hidden fetch and return and array
-     address@hidden get_row get_row_date
-     */
-    private function get_row_result($res)
-    {
-        $array=array();
-        $tot_cred=0.0;
-        $tot_deb=0.0;
-        $Max=Database::num_row($res);
-        if ( $Max == 0 ) return null;
-        for ($i=0;$i<$Max;$i++)
-        {
-            $array[]=Database::fetch_array($res,$i);
-            if ($array[$i]['j_debit']=='t')
-            {
-                $tot_deb+=$array[$i]['deb_montant'] ;
-            }
-            else
-            {
-                $tot_cred+=$array[$i]['cred_montant'] ;
-            }
-        }
-        $this->row=$array;
-        return array($array,$tot_deb,$tot_cred);
-    }
-    /*!
-     * \brief  Get data for poste
-     *
-     * \param  $p_from periode from
-     * \param  $p_to   end periode
-     *\param $op_let 0 all operation, 1 only lettered one, 2 only unlettered 
one
-     * \return double array 
(j_date,deb_montant,cred_montant,description,jrn_name,j_debit,jr_internal)
-     *         (tot_deb,tot_credit
-     *
-     */
-    function get_row_date($p_from,$p_to,$op_let=0)
-    {
-        global $g_user;
-        if ( $this->id == 0 )
-        {
-            echo_error("class_fiche",__LINE__,"id is 0");
-            return;
-        }
-        $filter_sql=$g_user->get_ledger_sql('ALL',3);
-        $sql_let='';
-        switch ($op_let)
-        {
-        case 0:
-            break;
-        case 1:
-            $sql_let=' and j_id in (select j_id from letter_cred union select 
j_id from letter_deb)';
-            break;
-        case '2':
-            $sql_let=' and j_id not in (select j_id from letter_cred union 
select j_id from letter_deb) ';
-            break;
-        }
-
-        $qcode=$this->strAttribut(ATTR_DEF_QUICKCODE);
-        $Res=$this->cn->exec_sql("select distinct 
substring(jr_pj_number,'[0-9]+$'),j_id,j_date,to_char(j_date,'DD.MM.YYYY') as 
j_date_fmt,j_qcode,".
-                                 "case when j_debit='t' then j_montant else 0 
end as deb_montant,".
-                                 "case when j_debit='f' then j_montant else 0 
end as cred_montant,".
-                                 " jr_comment as description,jrn_def_name as 
jrn_name,".
-                                " jr_pj_number,".
-                                 "j_debit, 
jr_internal,jr_id,coalesce(comptaproc.get_letter_jnt(j_id),-1) as letter, ".
-                                " jr_tech_per,p_exercice,jrn_def_name,
-                                                                 jrn_def_code".
-                                 " from jrnx left join jrn_def on 
jrn_def_id=j_jrn_def ".
-                                 " left join jrn on jr_grpt_id=j_grpt".
-                                " left join parm_periode on (p_id=jr_tech_per) 
".
-                                 " where j_qcode=$1 and ".
-                                 " ( to_date($2,'DD.MM.YYYY') <= j_date and ".
-                                 "   to_date($3,'DD.MM.YYYY') >= j_date )".
-                                 " and $filter_sql $sql_let ".
-                                 " order by 
j_date,substring(jr_pj_number,'[0-9]+$')",array($qcode,$p_from,$p_to));
-
-        return $this->get_row_result($Res);
-    }
-
-    /*!
-     * \brief  Get data for poste
-     *
-     * \param  $p_from periode from
-     * \param  $p_to   end periode
-     * \return double array 
(j_date,deb_montant,cred_montant,description,jrn_name,j_debit,jr_internal)
-     *         (tot_deb,tot_credit
-     *
-     */
-    function get_row($p_from,$p_to)
-    {
-        if ( $this->id == 0 )
-        {
-            echo_error("class_fiche",__LINE__,"id is 0");
-            return;
-        }
-        $qcode=$this->strAttribut(ATTR_DEF_QUICKCODE);
-        $periode=sql_filter_per($this->cn,$p_from,$p_to,'p_id','jr_tech_per');
-
-        $Res=$this->cn->exec_sql("select j_date,to_char(j_date,'DD.MM.YYYY') 
as j_date_fmt,j_qcode,".
-                                 "case when j_debit='t' then j_montant else 0 
end as deb_montant,".
-                                 "case when j_debit='f' then j_montant else 0 
end as cred_montant,".
-                                 " jr_comment as description,jrn_def_name as 
jrn_name,".
-                                 "j_debit, jr_internal,jr_id ".
-                                 " from jrnx left join jrn_def on 
jrn_def_id=j_jrn_def ".
-                                 " left join jrn on jr_grpt_id=j_grpt".
-                                 " where j_qcode='".$qcode."' and ".$periode.
-                                 " order by j_date::date");
-        return $this->get_row_result($Res);
-
-    }
-    /*!
-     * \brief HtmlTable, display a HTML of a card for the asked period
-     *\param $op_let 0 all operation, 1 only lettered one, 2 only unlettered 
one
-     * \return none
-     */
-    function HtmlTableDetail($p_array=null,$op_let=0)
-    {
-        if ( $p_array == null)
-            $p_array=$_REQUEST;
-
-        $name=$this->getName();
-
-        list($array,$tot_deb,$tot_cred)=$this->get_row_date( 
$p_array['from_periode'],
-                                        $p_array['to_periode'],
-                                        $op_let
-                                                           );
-
-        if ( count($this->row ) == 0 )
-            return;
-        $qcode=$this->strAttribut(ATTR_DEF_QUICKCODE);
-
-        $rep="";
-        $already_seen=array();
-        echo '<h2 class="info">'.$this->id." ".$name.'</h2>';
-        echo "<TABLE class=\"result\" 
style=\"width:100%;border-collapse:separate;border-spacing:5px\">";
-        echo "<TR>".
-        "<TH>"._("n° de pièce / Code interne")." </TH>".
-        "<TH>"._("Date")."</TH>".
-        "<TH>"._("Description")." </TH>".
-        "<TH>"._('Montant')."  </TH>".
-        "<TH> "._('Débit/Crédit')." </TH>".
-        "</TR>";
-
-        foreach ( $this->row as $op )
-        {
-            if ( in_array($op['jr_internal'],$already_seen) )
-                continue;
-            else
-                $already_seen[]=$op['jr_internal'];
-            echo "<TR  
style=\"text-align:center;background-color:lightgrey\">".
-            "<td>".$op['jr_pj_number']." / ".$op['jr_internal']."</td>".
-            "<td>".$op['j_date']."</td>".
-            "<td>".h($op['description'])."</td>".
-            "<td>"."</td>".
-            "<td>"."</td>".
-            "</TR>";
-            $ac=new Acc_Operation($this->cn);
-            $ac->jr_id=$op['jr_id'];
-            $ac->qcode=$qcode;
-            echo $ac->display_jrnx_detail(1);
-
-        }
-        $solde_type=($tot_deb>$tot_cred)?_("solde débiteur"):_("solde 
créditeur");
-        $diff=round(abs($tot_deb-$tot_cred),2);
-        echo "<TR>".
-        "<TD>$solde_type".
-        "<TD>$diff</TD>".
-        "<TD></TD>".
-        "<TD>$tot_deb</TD>".
-        "<TD>$tot_cred</TD>".
-        "</TR>";
-
-        echo "</table>";
-
-        return;
-    }
-    /*!
-     * \brief HtmlTable, display a HTML of a card for the asked period
-     * \param $p_array default = null keys = from_periode, to_periode
-     *\param $op_let 0 all operation, 1 only lettered one, 2 only unlettered 
one
-     *\return -1 if nothing is found otherwise 0
-     *\see get_row_date
-     */
-    function HtmlTable($p_array=null,$op_let=0,$from_div=1)
-    {
-        if ( $p_array == null)
-            $p_array=$_REQUEST;
-        $progress=0;
-               // if from_periode is greater than to periode then swap the 
values
-               if (cmpDate($p_array['from_periode'],$p_array['to_periode']) > 
0)
-               {
-                       $tmp=$p_array['from_periode'];
-                       $p_array['from_periode']=$p_array['to_periode'];
-                       $p_array['to_periode']=$tmp;
-
-               }
-        list($array, $tot_deb, $tot_cred) = 
$this->get_row_date($p_array['from_periode'], $p_array['to_periode'], $op_let);
-
-        if ( count($this->row ) == 0 )
-            return -1;
-
-        $rep="";
-       if ( $from_div==1)
-         {
-           echo "<TABLE class=\"resultfooter\" 
style=\"margin:1%;width:98%;;border-collapse:separate;border-spacing:0px 
5px\">";
-         }
-       else
-         {
-           echo "<TABLE id=\"tb" . $from_div . "\"class=\"result\" 
style=\"margin:1%;width:98%;border-collapse:separate;border-spacing:0px 2px\">";
-               }
-        echo '<tbody>';
-        echo "<TR>".
-        "<TH style=\"text-align:left\">"._('Date')."</TH>".
-        "<TH style=\"text-align:left\">"._('n° pièce')." </TH>".
-        "<TH style=\"text-align:left\">"._('Code interne')." </TH>".
-        "<TH style=\"text-align:left\">"._('Description')." </TH>".
-        "<TH style=\"text-align:right\">"._('Débit')."  </TH>".
-        "<TH style=\"text-align:right\">"._('Crédit')." </TH>".
-        th('Prog.','style="text-align:right"').
-        th('Let.','style="text-align:right"');
-        "</TR>"
-        ;
-       $old_exercice="";$sum_deb=0;$sum_cred=0;
-       bcscale(2);
-       $idx=0;
-        foreach ( $this->row as $op )
-        {
-            $vw_operation = sprintf('<A class="detail" 
style="text-decoration:underline;color:red" 
HREF="javascript:modifyOperation(\'%s\',\'%s\')" >%s</A>', $op['jr_id'], 
dossier::id(), $op['jr_internal']);
-            $let = '';
-                       $html_let = "";
-                       if ($op['letter'] != -1)
-                       {
-                               $let = strtoupper(base_convert($op['letter'], 
10, 36));
-                               $html_let = 
HtmlInput::show_reconcile($from_div, $let);
-                       }
-                       $tmp_diff=bcsub($op['deb_montant'],$op['cred_montant']);
-
-           /*
-            * reset prog. balance to zero if we change of exercice
-            */
-           if ( $old_exercice != $op['p_exercice'])
-             {
-               if ($old_exercice != '' )
-                 {
-                   $progress=bcsub($sum_deb,$sum_cred);
-                       $side="&nbsp;".$this->get_amount_side($progress);
-                   echo "<TR class=\"highlight\">".
-                      "<TD>$old_exercice</TD>".
-                     td('').
-                     "<TD></TD>".
-                     "<TD>Totaux</TD>".
-                     "<TD style=\"text-align:right\">".nbm($sum_deb)."</TD>".
-                     "<TD style=\"text-align:right\">".nbm($sum_cred)."</TD>".
-                     td(nbm(abs($progress)).$side,'style="text-align:right"').
-                     td('').
-                     "</TR>";
-                   $sum_cred=0;
-                   $sum_deb=0;
-                   $progress=0;
-                 }
-             }
-            $progress=bcadd($progress,$tmp_diff);
-                       $side="&nbsp;".$this->get_amount_side($progress);
-           $sum_cred=bcadd($sum_cred,$op['cred_montant']);
-           $sum_deb=bcadd($sum_deb,$op['deb_montant']);
-               if ($idx%2 == 0) $class='class="odd"'; else $class=' 
class="even"';
-               $idx++;
-
-           echo "<TR $class name=\"tr_" . $let . "_" . $from_div . "\">" .
-                       
"<TD>".smaller_date(format_date($op['j_date_fmt']))."</TD>".
-             td(h($op['jr_pj_number'])).
-            "<TD>".$vw_operation."</TD>".
-            "<TD>".h($op['description'])."</TD>".
-            "<TD style=\"text-align:right\">".nbm($op['deb_montant'])."</TD>".
-             "<TD 
style=\"text-align:right\">".nbm($op['cred_montant'])."</TD>".
-             td(nbm(abs($progress)).$side,'style="text-align:right"').
-            td($html_let, ' style="text-align:right"') .
-                       "</TR>";
-           $old_exercice=$op['p_exercice'];
-
-        }
-        $solde_type=($sum_deb>$sum_cred)?"solde débiteur":"solde créditeur";
-        $diff=abs(bcsub($sum_deb,$sum_cred));
-        echo '<tfoot>';
-       echo "<TR class=\"highlight\">".
-        "<TD>Totaux</TD>".
-        "<TD ></TD>".
-        "<TD ></TD>".
-        "<TD></TD>".
-        "<TD  style=\"text-align:right\">".nbm($sum_deb)."</TD>".
-        "<TD  style=\"text-align:right\">".nbm($sum_cred)."</TD>".
-         "<TD style=\"text-align:right\">".nbm($diff)."</TD>".
-
-        "</TR>";
-        echo "<TR style=\"font-weight:bold\">".
-        "<TD>$solde_type</TD>".
-         "<TD style=\"text-align:right\">".nbm($diff)."</TD>".
-        "<TD></TD>".
-        "</TR>";
-        echo '</tfoot>';
-        echo '</tbody>';
-
-        echo "</table>";
-
-        return 0;
-    }
-    /*!
-     * \brief Display HTML Table Header (button)
-     *
-     * \return none
-     */
-    function HtmlTableHeader($p_array=null)
-    {
-        if ( $p_array == null)
-            $p_array=$_REQUEST;
-
-        $hid=new IHidden();
-        echo '<div class="noprint">';
-        echo "<table >";
-        echo '<TR>';
-
-        echo '<TD><form method="GET" ACTION="">'.
-            HtmlInput::submit('bt_other',"Autre poste").
-            HtmlInput::array_to_hidden(array('gDossier','ac'), $_REQUEST).
-            dossier::hidden().
-            
$hid->input("type","poste").$hid->input('p_action','impress')."</form></TD>";
-        
$str_ople=(isset($_REQUEST['ople']))?HtmlInput::hidden('ople',$_REQUEST['ople']):'';
-
-        echo '<TD><form method="GET" ACTION="export.php">'.
-            HtmlInput::submit('bt_pdf',_("Export PDF")).
-            dossier::hidden().$str_ople.
-              HtmlInput::hidden('act','PDF:fichedetail').
-            $hid->input("type","poste").
-            $hid->input('p_action','impress').
-            $hid->input("f_id",$this->id).
-            dossier::hidden().
-            $hid->input("from_periode",$p_array['from_periode']).
-            $hid->input("to_periode",$p_array['to_periode']);
-        if (isset($p_array['oper_detail']))
-            echo $hid->input('oper_detail','on');
-
-        echo "</form></TD>";
-
-        echo '<TD><form method="GET" ACTION="export.php">'.
-        HtmlInput::submit('bt_csv',_("Export CSV")).
-         HtmlInput::hidden('act','CSV:fichedetail').
-        dossier::hidden().$str_ople.
-        $hid->input("type","poste").
-        $hid->input('p_action','impress').
-        $hid->input("f_id",$this->id).
-        $hid->input("from_periode",$p_array['from_periode']).
-        $hid->input("to_periode",$p_array['to_periode']);
-        if (isset($p_array['oper_detail']))
-            echo $hid->input('oper_detail','on');
-
-        echo "</form></TD>";
-               echo "</form></TD>";
-               echo '<td style="vertical-align:top">';
-               echo HtmlInput::print_window();
-               echo '</td>';
-        echo "</table>";
-        echo '</div>';
-
-    }
-    /*!
-     * \brief   give the balance of an card
-     * \return
-     *      balance of the card
-     *
-     */
-    function get_solde_detail($p_cond="")
-    {
-        if ( $this->id == 0 ) return array('credit'=>0,'debit'=>0,'solde'=>0);
-        $qcode=$this->strAttribut(ATTR_DEF_QUICKCODE);
-
-        if ( $p_cond != "") $p_cond=" and ".$p_cond;
-        $Res=$this->cn->exec_sql("select sum(deb) as sum_deb, sum(cred) as 
sum_cred from
-                                 ( select j_poste,
-                                 case when j_debit='t' then j_montant else 0 
end as deb,
-                                 case when j_debit='f' then j_montant else 0 
end as cred
-                                 from jrnx
-                                 where
-                                 j_qcode = ('$qcode'::text)
-                                 $p_cond
-                                 ) as m  ");
-        $Max=Database::num_row($Res);
-        if ($Max==0) return 0;
-        $r=Database::fetch_array($Res,0);
-
-        return array('debit'=>$r['sum_deb'],
-                     'credit'=>$r['sum_cred'],
-                     'solde'=>abs($r['sum_deb']-$r['sum_cred']));
-    }
-    /**
-     *get the bank balance with receipt or not
-     *
-     */
-    function get_bk_balance($p_cond="")
-    {
-        if ( $this->id == 0 ) throw  new Exception('fiche->id est nul');
-        $qcode=$this->strAttribut(ATTR_DEF_QUICKCODE);
-
-        if ( $p_cond != "") $p_cond=" and ".$p_cond;
-       $sql="select sum(deb) as sum_deb, sum(cred) as sum_cred from
-                                 ( select j_poste,
-                                 case when j_debit='t' then j_montant else 0 
end as deb,
-                                 case when j_debit='f' then j_montant else 0 
end as cred
-                                 from jrnx
-                                 join jrn on (jr_grpt_id=j_grpt)
-                                 where
-                                 j_qcode = ('$qcode'::text)
-                                 $p_cond
-                                 ) as m  ";
-
-        $Res=$this->cn->exec_sql($sql);
-        $Max=Database::num_row($Res);
-        if ($Max==0) return 0;
-        $r=Database::fetch_array($Res,0);
-
-        return array('debit'=>$r['sum_deb'],
-                     'credit'=>$r['sum_cred'],
-                     'solde'=>abs($r['sum_deb']-$r['sum_cred']));
-
-    }
-    /*!\brief check if an attribute is empty
-     *\param $p_attr the id of the attribut to check (ad_id)
-     *\return return true is the attribute is empty or missing
-     */
-    function empty_attribute($p_attr)
-    {
-        $sql="select ad_value
-             from fiche_detail
-             natural join fiche
-             left join attr_def using (ad_id) where f_id=".$this->id.
-             " and ad_id = ".$p_attr.
-             " order by ad_id";
-        $res=$this->cn->exec_sql($sql);
-        if ( Database::num_row($res) == 0 ) return true;
-        $text=Database::fetch_result($res,0,0);
-        return (strlen(trim($text)) > 0)?false:true;
-
-
-    }
-    /*! Summary
-     * \brief  show the default screen
-     *
-     * \param $p_search (filter)
-     * \param $p_action used for specific action bank, red if credit < debit
-     * \param $p_sql SQL to filter the number of card must start with AND
-     * \param $p_amount true : only cards with at least one operation default 
: false
-     * \return: string to display
-     */
-    function Summary($p_search="",$p_action="",$p_sql="",$p_amount=false)
-    {
-        global $g_user;
-        $bank=new Acc_Parm_Code($this->cn,'BANQUE');
-        $cash=new Acc_Parm_Code($this->cn,'CAISSE');
-        $cc=new Acc_Parm_Code($this->cn,'COMPTE_COURANT');
-        
-        bcscale(4);
-        $gDossier=dossier::id();
-        $p_search=sql_string($p_search);
-        $script=$_SERVER['PHP_SELF'];
-        // Creation of the nav bar
-        // Get the max numberRow
-        $filter_amount='';
-        global $g_user;
-
-        $filter_year="  j_tech_per in (select p_id from parm_periode ".
-                     "where p_exercice='".$g_user->get_exercice()."')";
-
-        if ( $p_amount) $filter_amount=' and f_id in (select f_id from jrnx 
where  '.$filter_year.')';
-
-        
$all_tiers=$this->count_by_modele($this->fiche_def_ref,"",$p_sql.$filter_amount);
-        // Get offset and page variable
-        $offset=( isset ($_REQUEST['offset'] )) ?$_REQUEST['offset']:0;
-        $page=(isset($_REQUEST['page']))?$_REQUEST['page']:1;
-        $bar=navigation_bar($offset,$all_tiers,$_SESSION['g_pagesize'],$page);
-
-        // set a filter ?
-        $search=$p_sql;
-
-        $exercice=$g_user->get_exercice();
-        $tPeriode=new Periode($this->cn);
-        list($max,$min)=$tPeriode->get_limit($exercice);
-
-
-        if ( trim($p_search) != "" )
-        {
-            $search.=" and f_id in
-                     (select distinct f_id from fiche_detail
-                     where
-                     ad_id in (1,32,30,23,18,13) and ad_value ~* '$p_search')";
-        }
-        // Get The result Array
-        
$step_tiers=$this->get_by_category($offset,$search.$filter_amount,'name');
-
-        if ( $all_tiers == 0 || count($step_tiers)==0 ) return "";
-        $r="";
-        $r.=_("Filtre rapide ").HtmlInput::filter_table("tiers_tb", '0,1,2', 
1);
-        $r.=$bar;
-        
-        $r.='<table  id="tiers_tb" class="sortable"  
style="width:90%;margin-left:5%">
-            <TR >
-            <TH>'._('Quick Code').HtmlInput::infobulle(17).'</TH>'.
-            '<th>'._('Poste comptable').'</th>'.
-            '<th  class="sorttable_sorted_reverse">'._('Nom').'<span 
id="sorttable_sortrevind">&nbsp;&blacktriangle;</span>'.'</th>
-            <th>'._('Adresse').'</th>
-            <th style="text-align:right">'._('Total débit').'</th>
-            <th style="text-align:right">'._('Total crédit').'</th>
-            <th style="text-align:right">'._('Solde').'</th>';
-        $r.='</TR>';
-        if ( sizeof ($step_tiers ) == 0 )
-            return $r;
-
-        $i=0;
-               $deb=0;$cred=0;
-        foreach ($step_tiers as $tiers )
-        {
-            $i++;
-            
-             /* Filter on the default year */
-             $amount=$tiers->get_solde_detail($filter_year);
-
-            /* skip the tiers without operation */
-            if ( $p_amount && $amount['debit']==0 && $amount['credit'] == 0 && 
$amount['solde'] == 0 ) continue;
-
-            $odd="";
-             $odd  = ($i % 2 == 0 ) ? ' odd ': ' even ';
-             $accounting=$tiers->strAttribut(ATTR_DEF_ACCOUNT);
-             if ( $p_action == 'bank' && $amount['debit'] <  $amount['credit'] 
 ){
-                 if ( strpos($accounting,$bank->p_value)===0 || 
strpos($accounting,$cash->p_value)===0 || strpos($accounting,$cc->p_value)===0){
-                 //put in red if c>d
-                 $odd.=" notice ";
-                 }
-             }
-        
-             $odd=' class="'.$odd.'"';
-             
-            $r.="<TR $odd>";
-            
$url_detail=$script.'?'.http_build_query(array('sb'=>'detail','sc'=>'sv','ac'=>$_REQUEST['ac'],'f_id'=>$tiers->id,'gDossier'=>$gDossier));
-            $e=sprintf('<A HREF="%s" title="Détail" class="line"> ',
-                       $url_detail);
-
-            $r.="<TD> $e".$tiers->strAttribut(ATTR_DEF_QUICKCODE)."</A></TD>";
-            $r.="<TD> $e".$accounting."</TD>";
-            $r.="<TD>".h($tiers->strAttribut(ATTR_DEF_NAME))."</TD>";
-            $r.="<TD>".h($tiers->strAttribut(ATTR_DEF_ADRESS).
-                         " ".$tiers->strAttribut(ATTR_DEF_CP).
-                         " ".$tiers->strAttribut(ATTR_DEF_PAYS)).
-                "</TD>";
-            $str_deb=(($amount['debit']==0)?0:nbm($amount['debit']));
-            $str_cred=(($amount['credit']==0)?0:nbm($amount['credit']));
-            $str_solde=nbm($amount['solde']);
-            $r.='<TD sorttable_customkey="'.$amount['debit'].'" align="right"> 
'.$str_deb.'</TD>';
-            $r.='<TD sorttable_customkey="'.$amount['credit'].'" 
align="right"> '.$str_cred.'</TD>';
-            $side=($amount['debit'] >  $amount['credit'])?'D':'C';
-            $side=($amount['debit'] ==  $amount['credit'])?'=':$side;
-            $red="";
-            if ( $p_action == 'customer' && $amount['debit'] <  
$amount['credit']  ){
-                 //put in red if d>c
-                 $red=" notice ";
-             }
-             if ( $p_action == 'supplier' && $amount['debit'] >  
$amount['credit']  ){
-                 //put in red if c>d
-                 $red=" notice ";
-             }
-            $r.='<TD class="'.$red.'" 
sorttable_customkey="'.$amount['solde'].'" align="right"> '.$str_solde."$side 
</TD>";
-            $deb=bcadd($deb,$amount['debit']);
-            $cred=bcadd($cred,$amount['credit']);
-
-            $r.="</TR>";
-
-        }
-               $r.="<tfoot >";
-               $solde=abs(bcsub($deb,$cred));
-                $side=($deb > $cred)?'Débit':'Crédit';
-                $r.='<tr class="highlight">';
-               
$r.=td("").td("").td("").td("Totaux").td(nbm($deb),'class="num"').td(nbm($cred),'class="num"').td("
 $side ".nbm($solde),'class="num"');
-                $r.='</tr>';
-               $r.="</tfoot>";
-        $r.="</TABLE>";
-        $r.=$bar;
-        return $r;
-    }
-    /*!
-     * \brief get the fd_id of the card : fd_id, it set the attribute fd_id
-     */
-    function get_categorie()
-    {
-        if ( $this->id == 0 ) throw  new Exception('class_fiche : f_id = 0 ');
-        $sql='select fd_id from fiche where f_id='.$this->id;
-        $R=$this->cn->get_value($sql);
-        if ( $R == "" )
-            $this->fd_id=0;
-        else
-            $this->fd_id=$R;
-    }
-    /*!
-     ***************************************************
-     * \brief   Check if a fiche is used by a jrn
-     *  return 1 if the  fiche is in the range otherwise 0, the quick_code
-     *  or the id  must be set
-     *
-     *
-     * \param   $p_jrn journal_id
-     * \param   $p_type : deb or cred default empty
-     *
-     * \return 1 if the fiche is in the range otherwise < 1
-     *        -1 the card doesn't exist
-     *        -2 the ledger has no card to check
-     *
-     */
-    function belong_ledger($p_jrn,$p_type="")
-    {
-        // check if we have a quick_code or a f_id
-        if (($this->quick_code==null || $this->quick_code == "" )
-                && $this->id == 0 )
-        {
-            throw  new Exception( 'erreur ni quick_code ni f_id ne sont 
donnes');
-        }
-
-        //retrieve the quick_code
-        if ( $this->quick_code=="")
-            $this->quick_code=$this->get_quick_code();
-
-
-        if ( $this->quick_code==null)
-            return -1;
-
-        if ( $this->id == 0 )
-            if ( $this->get_by_qcode(null,false) == 1)
-                return -1;
-
-        $get="";
-        if ( $p_type == 'deb' )
-        {
-            $get='jrn_def_fiche_deb';
-        }
-        if ( $p_type == 'cred' )
-        {
-            $get='jrn_def_fiche_cred';
-        }
-        if ( $get != "" )
-        {
-            $Res=$this->cn->exec_sql("select $get as fiche from jrn_def where 
jrn_def_id=$p_jrn");
-        }
-        else
-        {
-            // Get all the fiche type (deb and cred)
-            $Res=$this->cn->exec_sql(" select jrn_def_fiche_cred as fiche
-                                     from jrn_def where jrn_def_id=$p_jrn
-                                     union
-                                     select jrn_def_fiche_deb
-                                     from jrn_def where jrn_def_id=$p_jrn"
-                                    );
-        }
-        $Max=Database::num_row($Res);
-        if ( $Max==0)
-        {
-            return -2;
-        }
-        /* convert the array to a string */
-        $list=Database::fetch_all($Res);
-        $str_list="";
-        $comma='';
-        foreach ($list as $row)
-        {
-            if ( $row['fiche'] != '' )
-            {
-                $str_list.=$comma.$row['fiche'];
-                $comma=',';
-            }
-        }
-        // Normally Max must be == 1
-
-        if ( $str_list=="")
-        {
-            return -3;
-        }
-
-        $sql="select *
-             from fiche
-             where
-             fd_id in (".$str_list.") and f_id= ".$this->id;
-
-        $Res=$this->cn->exec_sql($sql);
-        $Max=Database::num_row($Res);
-        if ($Max==0 )
-            return 0;
-        else
-            return 1;
-    }
-    /*!\brief  get all the card from a categorie
-     *\param $p_cn database connx
-     *\param $pFd_id is the category id
-     *\param $p_order for the sort, possible values is name_asc,name_desc or 
nothing
-     *\return an array of card, but only the fiche->id is set
-     */
-    static function get_fiche_def($p_cn,$pFd_id,$p_order='')
-    {
-        switch ($p_order)
-        {
-        case 'name_asc':
-            $sql='select f_id,ad_value from fiche join fiche_detail using 
(f_id) where ad_id=1 and fd_id=$1 order by 2 asc';
-            break;
-        case 'name_desc':
-            $sql='select f_id,ad_value from fiche join fiche_detail using 
(f_id) where ad_id=1 and fd_id=$1 order by 2 desc';
-            break;
-        default:
-            $sql='select f_id from fiche  where fd_id=$1 ';
-        }
-        $array=$p_cn->get_array($sql,array($pFd_id));
-
-       return $array;
-    }
-    /*!\brief check if a card is used
-     *\return return true is a card is used otherwise false
-     */
-    function is_used()
-    {
-        /* retrieve first the quickcode */
-        $qcode=$this->strAttribut(ATTR_DEF_QUICKCODE);
-        $sql='select count(*) as c from jrnx where j_qcode=$1';
-        $count=$this->cn->get_value($sql,array($qcode));
-        if ( $count == 0 ) return false;
-        return true;
-    }
-    /*\brief remove a card without verification */
-    function delete()
-    {
-        // Remove from attr_value
-        $Res=$this->cn->exec_sql("delete from fiche_detail
-                                 where
-                                   f_id=".$this->id);
-
-        // Remove from fiche
-        $Res=$this->cn->exec_sql("delete from fiche where f_id=".$this->id);
-
-    }
-    /*!\brief create the sql statement for retrieving all
-     * the card
-     *\return string with sql statement
-     *\param $array contains the condition
-    \verbatim
-       [jrn] => 2
-       [typecard] => cred / deb / filter or list
-       [query] => string
-    \endverbatim
-     *\note the typecard cred, deb or filter must be used with jrn, the value 
of list means a list of fd_id
-     *\see ajax_card.php cards.js
-     */
-    function build_sql($array)
-    {
-        if (!empty($array))
-            extract($array);
-        $and='';
-        $filter_fd_id='true';
-        $filter_query='';
-        if (isset($typecard))
-        {
-            if (strpos($typecard, "sql")==false)
-            {
-                switch ($typecard)
-                {
-                    case 'cred':
-                        if (!isset($jrn))
-                            throw ('Erreur pas de valeur pour jrn');
-                        $filter_jrn=$this->cn->make_list("select 
jrn_def_fiche_cred from jrn_Def where jrn_def_id=$1",
-                                array($jrn));
-                        $filter_fd_id=" fd_id in (".$filter_jrn.")";
-                        $and=" and ";
-                        break;
-                    case 'deb':
-                        if (!isset($jrn))
-                            throw ('Erreur pas de valeur pour jrn');
-                        $filter_jrn=$this->cn->make_list("select 
jrn_def_fiche_deb from jrn_Def where jrn_def_id=$1",
-                                array($jrn));
-                        $filter_fd_id=" fd_id in (".$filter_jrn.")";
-                        $and=" and ";
-                        break;
-                    case 'filter':
-                        if (!isset($jrn))
-                            throw ('Erreur pas de valeur pour jrn');
-                        $filter_jrn=$this->cn->make_list("select 
jrn_def_fiche_deb from jrn_Def where jrn_def_id=$1",
-                                array($jrn));
-
-                        if (trim($filter_jrn)!='')
-                            $fp1=" fd_id in (".$filter_jrn.")";
-                        else
-                            $fp1="fd_id < 0";
-
-                        $filter_jrn=$this->cn->make_list("select 
jrn_def_fiche_cred from jrn_Def where jrn_def_id=$1",
-                                array($jrn));
-
-                        if (trim($filter_jrn)!='')
-                            $fp2=" fd_id in (".$filter_jrn.")";
-                        else
-                            $fp2="fd_id < 0";
-
-                        $filter_fd_id='('.$fp1.' or '.$fp2.')';
-
-                        $and=" and ";
-                        break;
-                    case 'all':
-                        $filter_fd_id=' true';
-                        break;
-                    default:
-                        if (trim($typecard)!='')
-                            $filter_fd_id=' fd_id in ('.$typecard.')';
-                        else
-                            $filter_fd_id=' fd_id < 0';
-                }
-            }
-            else
-            {
-                $filter_fd_id=str_replace('[sql]', '', $typecard);
-            }
-        }
-
-        $and=" and ";
-        if (isset($query))
-        {
-            $query=sql_string($query);
-
-            if (strlen(trim($query))>1)
-            {
-                $filter_query=$and."(vw_name ilike '%$query%' or quick_code 
ilike ('%$query%') "
-                        ." or vw_description ilike '%$query%' or tva_num ilike 
'%$query%' or accounting like upper('$query%'))";
-            }
-            else
-            {
-                $filter_query='';
-            }
-        }
-        $sql="select * from vw_fiche_attr where ".$filter_fd_id.$filter_query;
-        return $sql;
-    }
-
-    /**
-     address@hidden move a card to another cat. The properties will changed
-     * and be removed
-     address@hidden $p_fdid the fd_id of destination
-     */
-    function move_to($p_fdid)
-    {
-        $this->cn->start();
-        $this->cn->exec_sql('update fiche set fd_id=$1 where 
f_id=$2',array($p_fdid,$this->id));
-        // add missing
-        $this->cn->exec_sql('select 
fiche_attribut_synchro($1)',array($p_fdid));
-        // add to the destination missing fields
-        $this->cn->exec_sql("insert into jnt_fic_attr (fd_id,ad_id,jnt_order) 
select $1,ad_id,100 from fiche_detail where f_id=$2 and ad_id not in (select 
ad_id from jnt_fic_attr where fd_id=$3)",array($p_fdid,$this->id,$p_fdid));
-        $this->cn->commit();
-    }
-    /**
-     * return the letter C if amount is > 0, D if < 0 or =
-     * @param type $p_amount
-     * @return string
-     */
-    function get_amount_side($p_amount)
-    {
-            if ($p_amount == 0)
-                    return "=";
-            if ($p_amount < 0)
-                    return "C";
-            if ($p_amount > 0)
-                    return "D";
-    }
-    static function test_me()
-    {
-        $cn=new Database(dossier::id());
-        $a=new Fiche($cn);
-        $select_cat=new ISelect('fd_id');
-        $select_cat->value=$cn->make_array('select fd_id,fd_label from 
fiche_def where frd_id='.
-                                           FICHE_TYPE_CLIENT);
-        echo '<FORM METHOD="GET"> ';
-        echo dossier::hidden();
-        echo HtmlInput::hidden('test_select',$_GET['test_select']);
-        echo 'Choix de la catégorie';
-        echo $select_cat->input();
-        echo HtmlInput::submit('go_card','Afficher');
-        echo '</form>';
-        if ( isset ($_GET['go_card']))
-        {
-            $empty=$a->to_array($_GET['fd_id']);
-            print_r($empty);
-        }
-    }
-
-       function get_gestion_title()
-       {
-               $r = "<h2>" . h($this->getName()) . " " . 
h($this->getAttribut(ATTR_DEF_FIRST_NAME)) . '[' . $this->get_quick_code() . 
']</h2>';
-               return $r;
-       }
-       function get_all_account()
-       {
-
-       }
-}
-
-?>
diff --git a/include/class_fiche_attr.php b/include/class_fiche_attr.php
deleted file mode 100644
index ff7a4fb..0000000
--- a/include/class_fiche_attr.php
+++ /dev/null
@@ -1,284 +0,0 @@
-<?php
-//This file is part of NOALYSS and is under GPL 
-//see licence.txt
-/**
- address@hidden Manage the table attr_def
- *
- *
- */
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/ac_common.php';
-
-class Fiche_Attr
-{
-    /* example private 
$variable=array("easy_name"=>column_name,"email"=>"column_name_email","val3"=>0);
 */
-
-    protected 
$variable=array("id"=>"ad_id","desc"=>"ad_text","type"=>"ad_type","size"=>"ad_size","extra"=>"ad_extra");
-    function __construct ($p_cn,$p_id=0)
-    {
-        $this->cn=$p_cn;
-        if ( $p_id == 0 )
-        {
-            /* Initialize an empty object */
-            foreach ($this->variable as $key=>$value) $this->$value='';
-        }
-        else
-        {
-            /* load it */
-            $this->ad_id=$p_id;
-            $this->load();
-        }
-    }
-    public function get_parameter($p_string)
-    {
-        if ( array_key_exists($p_string,$this->variable) )
-        {
-            $idx=$this->variable[$p_string];
-            return $this->$idx;
-        }
-        else
-            throw new Exception (__FILE__.":".__LINE__.$p_string.'Erreur 
attribut inexistant');
-    }
-    public function set_parameter($p_string,$p_value)
-    {
-        if ( array_key_exists($p_string,$this->variable) )
-        {
-            $idx=$this->variable[$p_string];
-            $this->$idx=$p_value;
-        }
-        else
-            throw new Exception (__FILE__.":".__LINE__.$p_string.'Erreur 
attribut inexistant');
-    }
-    public function get_info()
-    {
-        return var_export($this,true);
-    }
-    public function verify()
-    {
-        // Verify that the elt we want to add is correct
-        /* verify only the datatype */
-        if ( strlen(trim($this->ad_text))==0)
-            throw new Exception('La description ne peut pas être vide',1);
-        if ( strlen(trim($this->ad_type))==0)
-            throw new Exception('Le type ne peut pas être vide',1);
-        $this->ad_type=strtolower($this->ad_type);
-        if ( 
in_array($this->ad_type,array('date','text','numeric','zone','poste','card','select'))==false)
-            throw new Exception('Le type doit être text, numeric,poste, card, 
select ou date',1);
-        if ( trim($this->ad_size)=='' || 
isNumber($this->ad_size)==0||$this->ad_size>22)
-        {
-            switch ($this->ad_type)
-            {
-            case 'text':
-                    $this->ad_size=22;
-                break;
-            case 'numeric':
-                $this->ad_size=9;
-                break;
-            case 'date':
-                $this->ad_size=8;
-                break;
-            case 'zone':
-                $this->ad_size=22;
-                break;
-
-            default:
-                $this->ad_size=22;
-            }
-        }
-               if ( $this->ad_type == 'numeric' ) {
-                       
$this->ad_extra=(trim($this->ad_extra)=='')?'2':$this->ad_extra;
-                       if (isNumber($this->ad_extra) == 0) throw new Exception 
("La précision doit être un chiffre");
-
-               }
-               if ( $this->ad_type == 'select')
-        {
-                if (trim($this->ad_extra)=="") throw new Exception ("La 
requête SQL est vide ");
-               if ( preg_match('/^\h*select/i',$this->ad_extra)  == 0) throw 
new Exception ("La requête SQL doit commencer par SELECT ");
-                try{
-
-                        $this->cn->exec_sql($this->ad_extra);
-                }catch (Exception $e)
-                {
-                    throw new Exception ("La requête SQL 
".h($this->ad_extra)." est invalide ");
-                }
-        }
-    }
-    public function save()
-    {
-
-        /* please adapt */
-        if (  $this->ad_id == 0 )
-            $this->insert();
-        else
-            $this->update();
-    }
-    /**
-     address@hidden retrieve array of object thanks a condition
-     address@hidden $cond condition (where clause)
-     address@hidden $p_array array for the SQL stmt
-     address@hidden Database::get_array
-     address@hidden an empty array if nothing is found
-     */
-    public function seek($cond='',$p_array=null)
-    {
-        if ( $cond != '')
-            $sql="select * from attr_def where $cond order by ad_text";
-        else
-            $sql="select * from attr_def order by ad_text";
-
-        $aobj=array();
-        $array= $this->cn->get_array($sql,$p_array);
-        // map each row in a object
-        $size=$this->cn->count();
-        if ( $size == 0 ) return $aobj;
-        for ($i=0;$i<$size;$i++)
-        {
-            $oobj=new Fiche_Attr ($this->cn);
-            foreach ($array[$i] as $idx=>$value)
-            {
-                $oobj->$idx=$value;
-            }
-            $aobj[]=clone $oobj;
-        }
-        return $aobj;
-    }
-    public function insert()
-    {
-        try{
-        $this->verify();
-        /*  please adapt */
-        $sql="insert into attr_def(ad_text
-             ,ad_type,ad_size,ad_extra
-             ) values ($1
-             ,$2,$3,$4
-             ) returning ad_id";
-
-        $this->ad_id=$this->cn->get_value(
-                         $sql,
-                         array( 
$this->ad_text,$this->ad_type,$this->ad_size,$this->ad_extra
-                              )
-                     );
-        } catch (Exception $e)
-        {
-            throw $e;
-        }
-
-    }
-
-    public function update()
-    {
-        try
-        {
-         $this->verify();
-        if ( $this->ad_id < 9000) return;
-        /*   please adapt */
-        $sql=" update attr_def set ad_text = $1
-             ,ad_type = $2,ad_size=$4,ad_extra=$5
-             where ad_id= $3";
-        $res=$this->cn->exec_sql(
-                 $sql,
-                 array($this->ad_text
-                       ,$this->ad_type
-                       ,$this->ad_id,$this->ad_size,$this->ad_extra)
-             );
-        }catch (Exception $e)
-        {
-            throw $e;
-        }
-
-
-    }
-    /**
-     address@hidden load a object
-     address@hidden 0 on success -1 the object is not found
-     */
-    public function load()
-    {
-
-        $sql="select ad_text
-             ,ad_type,ad_size,ad_extra
-             from attr_def where ad_id=$1";
-        /* please adapt */
-        $res=$this->cn->get_array(
-                 $sql,
-                 array($this->ad_id)
-             );
-
-        if ( count($res) == 0 )
-        {
-            /* Initialize an empty object */
-            foreach ($this->variable as $key=>$value) $this->$key='';
-
-            return -1;
-        }
-        foreach ($res[0] as $idx=>$value)
-        {
-            $this->$idx=$value;
-        }
-        return 0;
-    }
-
-    public function delete()
-    {
-        if ($this->ad_id < 9000)  return;
-        $sql=$this->cn->exec_sql("delete from fiche_detail  where ad_id=$1 ",
-                                 array($this->ad_id));
-
-       $sql="delete from jnt_fic_attr where ad_id=$1";
-        $res=$this->cn->exec_sql($sql,array($this->ad_id));
-
-        $sql="delete from attr_def where ad_id=$1";
-        $res=$this->cn->exec_sql($sql,array($this->ad_id));
-
-    }
-    /**
-     * Unit test for the class
-     */
-    static function test_me()
-    {
-        $cn=new Database(25);
-        $cn->start();
-        echo h2info('Test object vide');
-        $obj=new Fiche_Attr($cn);
-        var_dump($obj);
-
-        echo h2info('Test object NON vide');
-        $obj->set_parameter('j_id',3);
-        $obj->load();
-        var_dump($obj);
-
-        echo h2info('Update');
-        $obj->set_parameter('j_qcode','NOUVEAU CODE');
-        $obj->save();
-        $obj->load();
-        var_dump($obj);
-
-        echo h2info('Insert');
-        $obj->set_parameter('j_id',0);
-        $obj->save();
-        $obj->load();
-        var_dump($obj);
-
-        echo h2info('Delete');
-        $obj->delete();
-        echo (($obj->load()==0)?'Trouve':'non trouve');
-        var_dump($obj);
-        $cn->rollback();
-
-    }
-    /*!
-     address@hidden used with a usort function, to sort an array of Attribut 
on the attribut_id (ad_id)
-     */
-    static function sort_by_id($o1,$o2)
-    {
-        if ( $o1->ad_id > $o2->ad_id ) return 1;
-        if ( $o1->ad_id == $o2->ad_id ) return 0;
-        return -1;
-    }
-
-
-}
-//Fiche_Attr::test_me();
-
-
-
diff --git a/include/class_fiche_def.php b/include/class_fiche_def.php
deleted file mode 100644
index 9962fb7..0000000
--- a/include/class_fiche_def.php
+++ /dev/null
@@ -1,816 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-// Copyright Author Dany De Bontridder address@hidden
-require_once NOALYSS_INCLUDE.'/class_fiche_attr.php';
-require_once NOALYSS_INCLUDE.'/class_itext.php';
-require_once NOALYSS_INCLUDE.'/class_fiche_def_ref.php';
-require_once NOALYSS_INCLUDE.'/class_fiche.php';
-require_once NOALYSS_INCLUDE.'/user_common.php';
-require_once NOALYSS_INCLUDE.'/class_iradio.php';
-
-/*! \file
- * \brief define Class fiche and fiche def, those class are using
- *        class attribut
- */
-/*!
- * \brief define Class fiche and fiche def, those class are using
- *        class attribut
- */
-class Fiche_Def
-{
-    var $cn;           // database connection
-    var $id;                   // id (fiche_def.fd_id
-    var $label;                        // fiche_def.fd_label
-    var $class_base;           // fiche_def.fd_class_base
-    var $fiche_def;            // fiche_def.frd_id = fiche_def_ref.frd_id
-    var $create_account;               // fd_create_account: flag
-    var $all;
-    var $attribut;             // get from attr_xxx tables
-    function __construct($p_cn,$p_id = 0)
-    {
-        $this->cn=$p_cn;
-        $this->id=$p_id;
-    }
-    /*!\brief show the content of the form to create  a new Fiche_Def_Ref
-    */
-    function input ()
-    {
-        $ref=$this->cn->get_array("select * from fiche_def_ref order by 
frd_text");
-        $iradio=new IRadio();
-        /* the accounting item */
-        $class_base=new IPoste('class_base');
-        $class_base->set_attribute('ipopup','ipop_account');
-        $class_base->set_attribute('account','class_base');
-        $class_base->set_attribute('label','acc_label');
-        $f_class_base=$class_base->input();
-               $fd_description=new ITextarea('fd_description');
-               $fd_description->width=80;
-               $fd_description->heigh=4;
-               $fd_description->style='class="itextarea" 
style="margin-left:0px;vertical-align:text-top"';
-        require_once  NOALYSS_INCLUDE.'/template/fiche_def_input.php';
-        return;
-    }
-
-    /*!
-     *  \brief  Get attribut of a fiche_def
-     *
-     * \return string value of the attribute
-     */
-    function getAttribut()
-    {
-        $sql="select * from jnt_fic_attr ".
-             " natural join attr_def where fd_id=".$this->id.
-             " order by jnt_order";
-
-        $Ret=$this->cn->exec_sql($sql);
-
-        if ( ($Max=Database::num_row($Ret)) == 0 )
-            return ;
-        for ($i=0;$i < $Max;$i++)
-        {
-            $row=Database::fetch_array($Ret,$i);
-            $t = new Fiche_Attr($this->cn);
-            $t->ad_id=$row['ad_id'];
-            $t->ad_text=$row['ad_text'];
-            $t->jnt_order=$row['jnt_order'];
-            $t->ad_size=$row['ad_size'];
-            $t->ad_type=$row['ad_type'];
-            $t->ad_extra=$row['ad_extra'];
-            $this->attribut[$i]=clone $t;
-        }
-        return $this->attribut;
-    }
-
-    /*!
-    * \brief  Get attribut of the fiche_def
-    *
-    */
-    function get()
-    {
-        if ( $this->id == 0 )
-            return 0;
-        /*    $this->cn->exec_sql('select fiche_attribut_synchro($1)',
-        array($this->id));
-        */
-        $sql="select * from fiche_def ".
-             " where fd_id=".$this->id;
-        $Ret=$this->cn->exec_sql($sql);
-        if ( ($Max=Database::num_row($Ret)) == 0 )
-            return ;
-        $row=Database::fetch_array($Ret,0);
-        $this->label=$row['fd_label'];
-        $this->class_base=$row['fd_class_base'];
-        $this->fiche_def=$row['frd_id'];
-        $this->create_account=$row['fd_create_account'];
-        $this->fd_description=$row['fd_description'];
-    }
-    /*!
-     **************************************************
-     * \brief  Get all the fiche_def
-     *
-     * \return an array of fiche_def object
-     */
-    function get_all()
-    {
-        $sql="select * from fiche_def ";
-
-        $Ret=$this->cn->exec_sql($sql);
-        if ( ($Max=Database::num_row($Ret)) == 0 )
-            return ;
-
-        for ( $i = 0; $i < $Max;$i++)
-        {
-            $row=Database::fetch_array($Ret,$i);
-            $this->all[$i]=new Fiche_Def($this->cn,$row['fd_id']);
-            $this->all[$i]->label=$row['fd_label'];
-            $this->all[$i]->class_base=$row['fd_class_base'];
-            $this->all[$i]->fiche_def=$row['frd_id'];
-            $this->all[$i]->create_account=$row['fd_create_account'];
-        }
-    }
-    /*!
-     **************************************************
-     * \brief  Check in vw_fiche_def if a fiche has
-     *           a attribut X
-     *
-     *
-     * \param  $p_attr attribut to check
-     * \return  true or false
-     */
-    function HasAttribute($p_attr)
-    {
-        return ($this->cn->count_sql("select * from vw_fiche_def where 
ad_id=$p_attr and fd_id=".$this->id)>0)?true:false;
-
-    }
-    /*!
-     **************************************************
-     * \brief  Display category into a table
-     *
-     * \return HTML row
-     */
-    function Display()
-    {
-               $tab = new Sort_Table();
-
-               $url = HtmlInput::get_to_string(array('ac', 'gDossier'));
-               $tab->add(_("Nom de fiche"), $url, "order by fd_label asc", 
"order by fd_label desc", "na", "nd");
-               $tab->add(_("Basé sur le poste comptable"), $url, "order by 
fd_class_base asc", "order by fd_class_base desc", "pa", "pd");
-               $tab->add(_("Calcul automatique du poste comptable"), $url, 
"order by fd_create_account asc", "order by fd_create_account desc", "ca", 
"cd");
-               $tab->add(_("Basé sur le modèle"), $url, "order by frd_text 
asc", "order by frd_text  desc", "ma", "md");
-
-               $order = (isset($_GET['ord'])) ? 
$tab->get_sql_order($_GET["ord"]) : $tab->get_sql_order("na");
-
-
-               $res = $this->cn->exec_sql("SELECT fd_id, fd_class_base, 
fd_label, fd_create_account, fiche_def_ref.frd_id,
-frd_text , fd_description FROM fiche_def join fiche_def_ref on 
(fiche_def.frd_id=fiche_def_ref.frd_id)
-$order
-");
-
-               require_once NOALYSS_INCLUDE.'/template/fiche_def_list.php';
-       }
-    /*!\brief Add a fiche category thanks the element from the array
-     * you cannot add twice the same cat. name
-     * table : insert into fiche_def
-     *         insert into attr_def
-     *
-     * \param $array array
-     *        index FICHE_REF
-     *              nom_mod
-     *              class_base
-     *              fd_description
-     */
-    function Add($array)
-    {
-        /** 
-         * Check needed info
-         */
-        $p_nom_mod = HtmlInput::default_value('nom_mod', "", $array);
-        $p_fd_description = HtmlInput::default_value('fd_description', "", 
$array);
-        $p_class_base= HtmlInput::default_value('class_base', "", $array);
-        $p_fiche_def= HtmlInput::default_value('FICHE_REF', "", $array);
-        $p_create= HtmlInput::default_value('create', "off", $array);
-        
-        // If there is no description then add a empty one
-        if ( ! isset ($p_fd_description)) {
-            $p_fd_description="";
-        }
-        // Format correctly the name of the cat. of card
-        $p_nom_mod=sql_string($p_nom_mod);
-
-
-        // Name can't be empty
-        if ( strlen(trim($p_nom_mod)) == 0 )
-       {
-            alert (_('Le nom de la catégorie ne peut pas être vide'));
-            return 1;
-       }
-        // $p_fiche_def can't be empty
-        if ( strlen(trim($p_fiche_def)) == 0 )
-       {
-            alert (_('Un modéle de catégorie est obligatoire'));
-            return 1;
-       }
-        
-        /* check if the cat. name already exists */
-        $sql="select count(*) from fiche_Def where upper(fd_label)=upper($1)";
-        $count=$this->cn->get_value($sql,array(trim($p_nom_mod)));
-
-        if ($count != 0 ) {
-                        echo alert (_('Catégorie existante'));
-                       return 1;
-               }
-        // Set the value of fiche_def.fd_create_account
-        // automatic creation for 'poste comptable'
-        if ( $p_create == "on" && strlen(trim($p_class_base)) != 0)
-            $p_create='true';
-        else
-            $p_create='false';
-
-        // Class is valid ?
-        if ( sql_string($p_class_base) != null || ( $p_class_base !='' && 
strpos(',',$p_class_base) != 0 ))
-        {
-            // p_class is a valid number
-            $sql="insert into 
fiche_def(fd_label,fd_class_base,frd_id,fd_create_account,fd_description)
-                 values ($1,$2,$3,$4,$5) returning fd_id";
-
-            
$fd_id=$this->cn->get_value($sql,array($p_nom_mod,$p_class_base,$p_fiche_def,$p_create,$p_fd_description));
-
-            // p_class must be added to tmp_pcmn if it is a single accounting
-            if ( strpos(',',$p_class_base) ==0)
-            {
-                $sql="select account_add($1,$2)";
-                $Res=$this->cn->exec_sql($sql,array($p_class_base,$p_nom_mod));
-            }
-                       // Get the fd_id
-                       $fd_id=$this->cn->get_current_seq('s_fdef');
-
-                       // update jnt_fic_attr
-                       $sql=sprintf("insert into 
jnt_fic_attr(fd_id,ad_id,jnt_order)
-                                        values 
(%d,%d,10)",$fd_id,ATTR_DEF_ACCOUNT);
-                       $Res=$this->cn->exec_sql($sql);
-        }
-        else
-        {
-            //There is no class base not even as default
-            $sql="insert into 
fiche_def(fd_label,frd_id,fd_create_account,fd_description) values 
($1,$2,$3,$4) returning fd_id";
-
-
-            
$this->id=$this->cn->get_value($sql,array($p_nom_mod,$p_fiche_def,$p_create,$p_fd_description));
-
-            // Get the fd_id
-            $fd_id=$this->cn->get_current_seq('s_fdef');
-
-        }
-
-        // Get the default attr_def from attr_min
-        $def_attr=$this->get_attr_min($p_fiche_def);
-
-        //if defaut attr not null
-        // build the sql insert for the table attr_def
-        if (sizeof($def_attr) != 0 )
-        {
-            // insert all the mandatory fields into jnt_fiche_attr
-            $jnt_order=10;
-            foreach ( $def_attr as $i=>$v)
-            {
-                               $order=$jnt_order;
-                if ( $v['ad_id'] == ATTR_DEF_NAME )
-                    $order=0;
-                               $count=$this->cn->get_value("select count(*) 
from jnt_fic_attr where fd_id=$1 and ad_id=$2",array($fd_id,$v['ad_id']));
-                               if ($count == 0)
-                               {
-                                       $sql=sprintf("insert into 
jnt_fic_Attr(fd_id,ad_id,jnt_order)
-                             values (%d,%s,%d)",
-                             $fd_id,$v['ad_id'],$order);
-                                       $this->cn->exec_sql($sql);
-                                       $jnt_order+=10;
-                               }
-            }
-        }
-        $this->id=$fd_id;
-        return 0;
-
-    }//--------------end function Add ----------------------------
-    /*!
-     * \brief Get all the card where the fiche_def.fd_id is given in parameter
-     * \param $step = 0 we don't use the offset, page_size,...
-     *        $step = 1 we use the jnr_bar_nav
-     *
-     * \return array ('f_id'=>..,'ad_value'=>..)
-     *\see fiche
-     */
-    function get_by_type($step=0)
-    {
-        $sql="select f_id,ad_value
-             from
-             fiche join fiche_detail using(f_id)
-             where ad_id=1 and fd_id=$1 order by 2";
-
-        // we use navigation_bar
-        if ($step == 1  && $_SESSION['g_pagesize'] != -1   )
-        {
-            $offset=(isset($_GET['offset']))?$_GET['offset']:0;
-            $step=$_SESSION['g_pagesize'];
-            $sql.=" offset $offset limit $step";
-        }
-
-        $Ret=$this->cn->get_array($sql,array($this->id));
-
-        return $Ret;
-    }
-    /*!
-     * \brief Get all the card where the fiche_def.frd_id is given in parameter
-     * \return array of fiche or null is nothing is found
-     */
-    function get_by_category($p_cat)
-    {
-        $sql="select f_id,ad_value
-             from
-             fiche join fiche_def  using(fd_id)
-            join fiche_detail using(f_id)
-             where ad_id=1 and frd_id=$1 order by 2 ";
-
-        $Ret=$this->cn->exec_sql($sql,array($p_cat));
-        if ( ($Max=Database::num_row($Ret)) == 0 )
-            return null;
-        $all[0]=new Fiche($this->cn);
-
-        for ($i=0;$i<$Max;$i++)
-        {
-            $row=Database::fetch_array($Ret,$i);
-            $t=new Fiche($this->cn,$row['f_id']);
-            $t->getAttribut();
-            $all[$i]=$t;
-
-        }
-        return $all;
-    }
-
-    /*!\brief list the card of a fd_id
-     */
-    function myList()
-    {
-        $this->get();
-        echo '<H2 class="info">'.$this->id." ".$this->label.'</H2>';
-
-        $step=$_SESSION['g_pagesize'];
-        $sql_limit="";
-        $sql_offset="";
-        $bar="";
-        if ( $step != -1 )
-        {
-
-            $page=(isset($_GET['page']))?$_GET['page']:1;
-            $offset=(isset($_GET['offset']))?$_GET['offset']:0;
-            $max_line=$this->cn->count_sql("select f_id,ad_value  from
-                                           fiche join fiche_detail using (f_id)
-                                           where fd_id='".$this->id."' and 
ad_id=".ATTR_DEF_NAME." order by f_id");
-            $sql_limit=" limit ".$step;
-            $sql_offset=" offset ".$offset;
-            $bar=navigation_bar($offset,$max_line,$step,$page);
-        }
-
-        // Get all name the cards of the select category
-        // 1 for attr_def.ad_id is always the name
-        $Res=$this->cn->exec_sql("select f_id,vw_name,quick_code  from ".
-                                 " vw_fiche_attr ".
-                                 " where fd_id='".$this->id.
-                                 "' order by f_id $sql_offset $sql_limit ");
-        $Max=Database::num_row($Res);
-        echo $bar;
-        $str="";
-        // save the url
-        // with offet &offset=15&step=15&page=2&size=15
-        if ( $_SESSION['g_pagesize'] != -1)
-        {
-            $str=sprintf("&offset=%s&step=%s&page=%s&size=%s",
-                         $offset,
-                         $step,
-                         $page,
-                         $max_line);
-        }
-
-
-        echo '<FORM METHOD="POST" 
action="?p_action=fiche&action=vue'.$str.'">';
-       echo HtmlInput::hidden('ac',$_REQUEST['ac']);
-        echo dossier::hidden();
-        echo HtmlInput::hidden("fiche",$this->id);
-        echo HtmlInput::submit('add','Ajout fiche');
-        echo '</FORM>';
-        $str_dossier=dossier::get();
-        echo '<table>';
-        for ( $i = 0; $i < $Max; $i++)
-        {
-            $l_line=Database::fetch_array($Res,$i);
-            if ( $i%2 == 0)
-                echo '<TR class="odd">';
-            else
-                echo '<TR class="even">';
-
-            $span_mod='<TD><A href="?p_action=fiche&'.$str_dossier.
-                   '&action=detail&fiche_id='.$l_line['f_id'].$str.'&fiche='.
-                   
$_REQUEST['fiche'].'&ac='.$_REQUEST['ac'].'">'.$l_line['quick_code']
-                   .'</A></TD>';
-
-            echo $span_mod.'<TD>'.h($l_line['vw_name'])."</TD>";
-            echo '</tr>';
-        }
-        echo '</table>';
-        echo '<FORM METHOD="POST" 
action="?p_action=fiche&action=vue'.$str.'">';
-       echo HtmlInput::hidden('ac',$_REQUEST['ac']);
-        echo dossier::hidden();
-        echo HtmlInput::hidden("fiche",$this->id);
-        echo HtmlInput::submit('add','Ajout fiche');
-        echo '</FORM>';
-        echo $bar;
-
-    }
-    /*!\brief show input for the basic attribute : label, class_base, 
create_account
-     * use only when we want to update
-     *
-     *\return HTML string with the form
-     */
-    function input_base()
-    {
-        $r="";
-        $r.=_('Label');
-        $label=new IText('label',$this->label);
-        $r.=$label->input();
-        $r.='<br>';
-        /* the accounting item */
-        $class_base=new IPoste('class_base',$this->class_base);
-        $class_base->set_attribute('ipopup','ipop_account');
-        $class_base->set_attribute('account','class_base');
-        $class_base->set_attribute('label','acc_label');
-        $fd_description=new ITextarea('fd_description',$this->fd_description);
-        $fd_description->width=80;
-        $fd_description->heigh=4;
-        $fd_description->style='class="itextarea" 
style="margin-left:0px;vertical-align:text-top"';
-
-        $r.=_('Poste Comptable de base').' : ';
-        $r.=$class_base->input();
-        $r.='<span id="acc_label"></span><br>';
-               $r.='<br/>';
-               $r.=" Description ".$fd_description->input();
-        /* auto Create */
-               $r.='<br/>';
-        $ck=new ICheckBox('create');
-        $ck->selected=($this->create_account=='f')?false:true;
-        $r.=_('Chaque fiche aura automatiquement son propre poste comptable : 
');
-        $r.=$ck->input();
-        return $r;
-    }
-    /*!\brief Display all the attribut of the fiche_def
-     *\param $str give the action possible values are remove, empty
-     */
-    function DisplayAttribut($str="")
-    {
-        if ( $this->id == 0 )
-            return ;
-           $this->cn->exec_sql('select 
fiche_attribut_synchro($1)',array($this->id));
-
-                  $MaxLine=sizeof($this->attribut);
-        $r="<TABLE>";
-       $r.="<tr>".th('Nom 
attribut').th('').th('Ordre','style="text-align:right"').'</tr>';
-        // Display each attribute
-        $add_action="";
-        for ($i=0;$i<$MaxLine;$i++)
-        {
-            $class="even";
-            if ( $i % 2 == 0 )
-                $class="odd";
-
-            $r.='<TR class="'.$class.'"><td>';
-            // Can change the name
-            if ( $this->attribut[$i]->ad_id == ATTR_DEF_NAME )
-            {
-                continue;
-            }
-            else
-            {
-                if ( $str == "remove" )
-                {
-                    //Only for the not mandatory attribute (not defined in 
attr_min)
-                    if ( $this->cn->count_sql("select * from attr_min where 
frd_id=".
-                                              $this->fiche_def." and ad_id = 
".$this->attribut[$i]->ad_id) == 0
-                            && $this->attribut[$i]->ad_id != ATTR_DEF_QUICKCODE
-                            && $this->attribut[$i]->ad_id != ATTR_DEF_ACCOUNT
-                       )
-                    {
-                        $add_action=sprintf( '</TD><TD> Supprimer <input 
type="checkbox" name="chk_remove[]" value="%d">',
-                                             $this->attribut[$i]->ad_id);
-                    }
-                    else
-                        $add_action="</td><td>";
-                }
-                // The attribut.
-                $a=sprintf('%s ',  $this->attribut[$i]->ad_text);
-                $r.=$a.$add_action;
-                /*----------------------------------------  */
-                /*  ORDER OF THE CARD */
-                /*----------------------------------------  */
-                $order=new IText();
-                $order->name='jnt_order'.$this->attribut[$i]->ad_id;
-                $order->size=3;
-                $order->value=$this->attribut[$i]->jnt_order;
-                $r.='</td><td> '.$order->input();
-            }
-            $r.= '</td></tr>';
-        }
-
-        // Show the possible attribute which are not already attribute of the 
model
-        // of card
-        $Res=$this->cn->exec_sql("select ad_id,ad_text from attr_def
-                                 where
-                                 ad_id not in (select ad_id from fiche_def 
natural join jnt_fic_attr
-                                 where fd_id=$1) order by 
ad_text",array($this->id) );
-        $M=Database::num_row($Res);
-
-        // Show the unused attribute
-        $r.='<TR> <TD>';
-        $r.= '<SELECT NAME="ad_id">';
-        for ($i=0;$i<$M;$i++)
-        {
-            $l=Database::fetch_array($Res,$i);
-            $a=sprintf('<OPTION VALUE="%s"> %s',
-                       $l['ad_id'],$l['ad_text']);
-            $r.=$a;
-        }
-        $r.='</SELECT>';
-
-        $r.="</TABLE>";
-        return $r;
-    }
-    /*!\brief Save the label of the fiche_def
-     * \param $p_label label
-     */
-    function SaveLabel($p_label)
-    {
-        if ( $this->id == 0 ) return;
-        $p_label=sql_string($p_label);
-        if (strlen(trim ($p_label)) == 0 )
-        {
-            return;
-        }
-        $sql=sprintf("update   fiche_def set fd_label='%s' ".
-                     "where                    fd_id=%d",
-                     $p_label,$this->id);
-        $Res=$this->cn->exec_sql($sql);
-
-    }
-    /*!\brief set the auto create accounting item for each card and
-     * save it into the database
-     * \param $p_label true or false
-     */
-    function set_autocreate($p_label)
-    {
-        if ( $this->id == 0 ) return;
-        if ($p_label==true)
-            $t='t';
-        if ($p_label==false)
-            $t='f';
-
-        $sql="update   fiche_def set fd_create_account=$1 ".
-             "where                    fd_id=$2";
-
-        $Res=$this->cn->exec_sql($sql,array($t,$this->id));
-
-    }
-    /*!\brief Save the class base
-     * \param $p_label label
-     */
-    function save_class_base($p_label)
-    {
-        if ( $this->id == 0 ) return;
-        $p_label=sql_string($p_label);
-
-        $sql="update   fiche_def set fd_class_base=$1 ".
-             "where                    fd_id=$2";
-
-        $Res=$this->cn->exec_sql($sql,array($p_label,$this->id));
-    }
-       function save_description($p_description)
-       {
-               if ( $this->id == 0)                    return;
-               $this->cn->exec_sql("update fiche_def set fd_description=$1 
where fd_id=$2",array($p_description,$this->id));
-       }
-
-
-    /*!\brief insert a new attribut for this fiche_def
-     * \param $p_ad_id id of the attribut
-     */
-    function InsertAttribut($p_ad_id)
-    {
-        if ( $this->id == 0 ) return;
-        /* ORDER */
-        $this->GetAttribut();
-        $max=sizeof($this->attribut)*15;
-        // Insert a new attribute for the model
-        // it means insert a row in jnt_fic_attr
-        $sql=sprintf("insert into jnt_fic_attr (fd_id,ad_id,jnt_order) values 
(%d,%d,%d)",
-                     $this->id,$p_ad_id,$max);
-        $Res=$this->cn->exec_sql($sql);
-    }
-    /*!\brief remove an attribut for this fiche_def
-     * \param array of ad_id to remove
-     * \remark you can't remove the attribut defined in attr_min
-     */
-    function RemoveAttribut($array)
-    {
-        foreach ($array as $ch)
-        {
-            $this->cn->start();
-            $sql="delete from jnt_fic_attr where fd_id=$1 ".
-                 "   and ad_id=$2";
-            $this->cn->exec_sql($sql,array($this->id,$ch));
-
-            $sql="delete from fiche_detail  where jft_id in ( select ".
-                 " jft_id from fiche_Detail ".
-                 " join fiche using(f_id) ".
-                 " where ".
-                 "fd_id = $1 and ".
-                 "ad_id=$2)";
-            $this->cn->exec_sql($sql,array($this->id,$ch));
-
-            $this->cn->commit();
-        }
-    }
-
-    /*!\brief save the order of a card, update the column 
jnt_fic_attr.jnt_order
-     *\param $p_array containing the order
-     */
-    function save_order($p_array)
-    {
-        extract($p_array);
-        $this->GetAttribut();
-        foreach ($this->attribut as $row)
-        {
-            if ( $row->ad_id == 1 ) continue;
-            if ( ${'jnt_order'.$row->ad_id} <= 0 ) continue;
-            $sql='update jnt_fic_attr set jnt_order=$1 where fd_id=$2 and 
ad_id=$3';
-            $this->cn->exec_sql($sql,array(${'jnt_order'.$row->ad_id},
-                                           $this->id,
-                                           $row->ad_id));
-
-        }
-        /* correct the order */
-        $this->cn->exec_sql('select attribute_correct_order()');
-    }
-
-
-    /*!\brief remove all the card from a categorie after having verify
-     *that the card is not used and then remove also the category
-     *\return the remains items, not equal to 0 if a card remains and
-     *then the category is not removed
-     */
-    function remove()
-    {
-        if ( $this->id >= 500000 ) {
-            throw new Exception(_('Catégorie verrouillée '));
-        }
-        $remain=0;
-        /* get all the card */
-        $aFiche=fiche::get_fiche_def($this->cn,$this->id);
-        if ( $aFiche != null )
-        {
-            /* check if the card is used */
-            foreach ($aFiche as $dfiche)
-            {
-             $fiche=new Fiche($this->cn,$dfiche['f_id']);
-
-                /* if the card is not used then remove it otherwise increment 
remains */
-                if ( $fiche->is_used() == false )
-                {
-                    $fiche->delete();
-                }
-                else
-                    $remain++;
-            }
-        }
-        /* if remains == 0 then remove cat */
-        if ( $remain == 0 )
-        {
-            $sql='delete from jnt_fic_attr where fd_id=$1';
-            $this->cn->exec_sql($sql,array($this->id));
-            $sql='delete from fiche_def where fd_id=$1';
-            $this->cn->exec_sql($sql,array($this->id));
-        }
-
-        return $remain;
-
-    }
-    /*!
-     * \brief  retrieve the mandatory field of the card model
-     *
-     * \param $p_fiche_def_ref
-     * \return array of ad_id  (attr_min.ad_id) and  labels (attr_def.ad_text)
-     */
-    function get_attr_min($p_fiche_def_ref)
-    {
-
-        // find the min attr for the fiche_def_ref
-        $Sql="select ad_id,ad_text from attr_min natural join attr_def
-             natural join fiche_def_ref
-             where
-             frd_id= $1";
-        $Res=$this->cn->exec_sql($Sql,array($p_fiche_def_ref));
-        $Num=Database::num_row($Res);
-
-        // test the number of returned rows
-        if ($Num == 0 ) return null;
-
-        // Get Results & Store them in a array
-        for ($i=0;$i<$Num;$i++)
-        {
-            $f=Database::fetch_array($Res,$i);
-            $array[$i]['ad_id']=$f['ad_id'];
-            $array[$i]['ad_text']=$f['ad_text'];
-        }
-        return $array;
-    }
-    /*!\brief count the number of fiche_def (category) which has the frd_id 
(type of category)
-     *\param $p_frd_id is the frd_id in constant.php the FICHE_TYPE_
-     *\return the number of cat. of card of the given type
-     *\see constant.php
-     */
-    function count_category($p_frd_id)
-    {
-        $ret=$this->cn->count_sql("select fd_id from fiche_def where 
frd_id=$1",array($p_frd_id));
-        return $ret;
-    }
-       function input_detail()
-       {
-               $r = "";
-               // Save the label
-
-               $this->get();
-               $this->GetAttribut();
-               $r.= '<H2 class="info">' . $this->id . " " . h($this->label) . 
'</H2>';
-               $r.='<fieldset><legend>'._('Données générales').'</legend>';
-
-               /* show the values label class_base and create account */
-               $r.='<form method="post">';
-               $r.=dossier::hidden();
-               $r.=HtmlInput::hidden("fd_id", $this->id);
-               $r.=HtmlInput::hidden("p_action", "fiche");
-               $r.= $this->input_base();
-               $r.='<hr>';
-               $r.=HtmlInput::submit('change_name', _('Sauver'));
-               $r.='</form>';
-               $r.='</fieldset>';
-               /* attributes */
-               $r.='<fieldset><legend>'._('Détails').'</legend>';
-
-               $r.= '<FORM  id="input_detail_frm" method="POST">';
-               $r.=dossier::hidden();
-               $r.=HtmlInput::hidden("fd_id", $this->id);
-               $r.=HtmlInput::hidden("action", "");
-               $r.= $this->DisplayAttribut("remove");
-               $r.= HtmlInput::submit('add_line_bt', _('Ajoutez cet élément'),
-                        'onclick="$(\'action\').value=\'add_line\'"');
-               $r.= HtmlInput::submit("save_line_bt", _("Sauvez"),
-                        'onclick="$(\'action\').value=\'save_line\'"');
-                        
-               $r.=HtmlInput::submit('remove_cat_bt', _('Effacer cette 
catégorie'), 'onclick="$(\'action\').value=\'remove_cat\';return 
confirm_box(\'input_detail_frm\',\'' . _('Vous confirmez ?') . '\')"');
-               // if there is nothing to remove then hide the button
-               if (strpos($r, "chk_remove") != 0)
-               {
-                    $r.=HtmlInput::submit('remove_line_bt', _("Enleve les 
éléments cochés"), 
-                            
'onclick="$(\'action\').value=\'remove_line\';return 
confirm_box(\'input_detail_frm\',\'' . _('Vous confirmez ?') . '\')"');
-               }
-               $r.= "</form>";
-               $r.=" <p class=\"notice\"> " . _("Attention : il n'y aura pas 
de demande de confirmation pour enlever les
-                                   attributs sélectionnés. Il ne sera pas 
possible de revenir en arrière") . "</p>";
-               $r.='</fieldset>';
-               return $r;
-       }
-       function input_new()
-       {
-               $single=new Tool_Uos("dup");
-               echo '<form method="post" style="display:inline">';
-               echo $single->hidden();
-               echo HtmlInput::hidden("p_action","fiche");
-               echo dossier::hidden();
-               echo $this->input(); //    CreateCategory($cn,$search);
-               echo HtmlInput::submit("add_modele" ,_("Sauve"));
-               echo '</FORM>';
-       }
-
-}
-?>
diff --git a/include/class_follow_up.php b/include/class_follow_up.php
deleted file mode 100644
index ed5c662..0000000
--- a/include/class_follow_up.php
+++ /dev/null
@@ -1,1840 +0,0 @@
-<?php
-
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-// Copyright Author Dany De Bontridder address@hidden
-require_once NOALYSS_INCLUDE.'/class_itextarea.php';
-require_once NOALYSS_INCLUDE.'/class_idate.php';
-require_once NOALYSS_INCLUDE.'/class_iselect.php';
-require_once NOALYSS_INCLUDE.'/class_ihidden.php';
-require_once NOALYSS_INCLUDE.'/class_itext.php';
-require_once NOALYSS_INCLUDE.'/class_ispan.php';
-require_once NOALYSS_INCLUDE.'/class_icard.php';
-require_once NOALYSS_INCLUDE.'/class_icheckbox.php';
-require_once NOALYSS_INCLUDE.'/class_ifile.php';
-require_once NOALYSS_INCLUDE.'/class_fiche.php';
-require_once NOALYSS_INCLUDE.'/class_document.php';
-require_once NOALYSS_INCLUDE.'/class_document_type.php';
-require_once NOALYSS_INCLUDE.'/class_document_modele.php';
-require_once NOALYSS_INCLUDE.'/user_common.php';
-require_once NOALYSS_INCLUDE.'/class_follow_up_detail.php';
-require_once NOALYSS_INCLUDE.'/class_inum.php';
-require_once NOALYSS_INCLUDE.'/class_sort_table.php';
-require_once NOALYSS_INCLUDE.'/class_irelated_action.php';
-require_once NOALYSS_INCLUDE.'/class_tag.php';
-require_once NOALYSS_INCLUDE.'/class_default_menu.php';
-/**
- * \file
- * \brief class_action for manipulating actions
- * action can be :
- * <ul>
- * <li>an invoice
- * <li>a meeting
- * <li>an order
- * <li>a letter
- * </ul>
- * The table document_type are the possible actions
- */
-
-/**
- * \brief class_action for manipulating actions
- * action can be :
- * <ul>
- * <li> a meeting
- * <li>an order
- * <li>a letter
- * </ul>
- * The table document_type are the possible actions
- */
-class Follow_Up
-{
-
-    var $db; /* !<  $db  database connexion    */
-    var $ag_timestamp;  /* !<   $ag_timestamp document date 
(ag_gestion.ag_timestamp) */
-    var $dt_id;   /* !<   $dt_id type of the document (document_type.dt_id) */
-    var $ag_state; /* !<   $ag_state stage of the document (printed, send to 
client...) */
-    var $d_number;   /* !<   $d_number number of the document */
-    var $d_filename; /* !<   $d_filename filename's document      */
-    var $d_mimetype; /* !<   $d_mimetype document's filename      */
-    var $ag_title;   /* !<   $ag_title title document        */
-    var $f_id; /* !<   $f_id_dest fiche id (From field )  */
-    var $ag_ref;  /* !< $ag_ref is the ref  */
-    var $ag_hour;  /* !< $ag_hour is the hour of the meeting, action */
-    var $ag_priority; /* !< $ag_priority is the priority 1 High, 2 medium, 3 
low */
-    var $ag_dest;  /* !< $ag_dest person who is in charged */
-    var $ag_contact;  /* !< $ag_contact contact */
-    var $ag_remind_date;  /* !< $ag_contact contact */
-
-    /**
-     * @brief $operation string related operation
-     */
-    var $operation;
-
-    /**
-     * @brief $action string related action
-     */
-    var $action;
-
-    /**
-     * @brief constructor
-     * \brief constructor
-     * \param p_cn database connection
-     */
-    function __construct($p_cn, $p_id=0)
-    {
-        $this->db=$p_cn;
-        $this->ag_id=$p_id;
-        $this->f_id=0;
-        $this->aAction_detail=array();
-        $this->operation="";
-        $this->action="";
-    }
-    /**
-     * Create a filter based on the current user, 
-     * @global type $g_user Connected user
-     * @param type $cn Database connection
-     * @param type $p_mode Mode is R (for Read) or W (for write)
-     * @return string SQL where clause to include in the SQL 
-     * example: (ag_dest in (select p_granted from user_sec_action_profile 
where p_id=x)
-     */
-    static function sql_security_filter($cn, $p_mode)
-    {
-        global $g_user;
-        $profile=$cn->get_value("select p_id from profile_user where 
user_name=$1", array($g_user->login));
-        if ($profile=='')
-            die("Security");
-        if ($p_mode=='R')
-        {
-            $sql=" (ag_dest in (select p_granted from user_sec_action_profile 
where p_id=$profile ) ) ";
-        } else if ($p_mode=='W')
-        {
-            $sql=" ( ag_dest in (select p_granted from user_sec_action_profile 
where p_id=$profile and ua_right='W' ) )";
-        } else  {
-            error_log(_('Securité'));
-            throw new Exception(_('Securité'));
-        }
-        return $sql;
-    }
-
-    //----------------------------------------------------------------------
-    /**
-     * \brief Display the object, the tags for the FORM
-     *        are in the caller. It will be used for adding and updating
-     *        action
-     * \note  If  ag_id is not equal to zero then it is an update otherwise
-     *        it is a new document
-     *
-     * \param $p_view form will be in readonly mode (value: READ, UPD or NEW  )
-     * \param $p_gen true we show the tag for generating a doc (value : true 
or false) and adding files
-     * \param $p_base is the ac parameter
-     * \param $retour is the html code for the return button
-     * \note  update the reference number or the document type is not allowed
-     *
-     *
-     * \return string containing the html code
-     */
-    function Display($p_view, $p_gen, $p_base, $retour="")
-    {
-        global $g_user;
-        if ($p_view=='UPD')
-        {
-            $upd=true;
-            $readonly=false;
-        }
-        elseif ($p_view=="NEW")
-        {
-            $upd=false;
-            $readonly=false;
-            $this->ag_ref=_("Nouveau");
-        }
-        elseif ($p_view=='READ')
-        {
-            $upd=true;
-            $readonly=true;
-        }
-        else
-        {
-            throw new Exception('class_action'.__LINE__.'Follow_Up::Display 
error unknown parameter'.$p_view);
-        }
-        // Compute the widget
-        // Date
-        $date=new IDate();
-        $date->readOnly=$readonly;
-        $date->name="ag_timestamp";
-        $date->id="ag_timestamp";
-        $date->value=$this->ag_timestamp;
-
-        $remind_date=new IDate();
-        $remind_date->readOnly=$readonly;
-        $remind_date->name="ag_remind_date";
-        $remind_date->id="ag_remind_date";
-        $remind_date->value=$this->ag_remind_date;
-
-
-        // Doc Type
-        $doc_type=new ISelect();
-        $doc_type->name="dt_id";
-        $doc_type->value=$this->db->make_array("select dt_id,dt_value from 
document_type order by dt_value", 1);
-        $doc_type->selected=$this->dt_id;
-        $doc_type->readOnly=$readonly;
-        $str_doc_type=$doc_type->input();
-
-        // Description
-        $desc=new ITextArea();
-        $desc->style=' class="itextarea" style="width:80%;margin-left:0px"';
-        $desc->name="ag_comment";
-        $desc->readOnly=$readonly;
-        $acomment=$this->db->get_array("SELECT agc_id, ag_id, 
to_char(agc_date,'DD.MM.YYYY HH24:MI') as str_agc_date, agc_comment, tech_user
-                                FROM action_gestion_comment where ag_id=$1 
order by agc_id;", array($this->ag_id)
-        );
-
-        // List opération liées
-        $operation=$this->db->get_array("select 
ago_id,j.jr_id,j.jr_internal,j.jr_comment,to_char(j.jr_date,'DD.MM.YY') as 
str_date
-                       from jrn as j join action_gestion_operation as ago on 
(j.jr_id=ago.jr_id)
-                       where ag_id=$1 order by jr_date", array($this->ag_id));
-        $iconcerned=new IConcerned('operation');
-
-        // List related action
-        $action=$this->db->get_array("
-                       select ag_id,ag_ref,substr(ag_title,1,40) as 
sub_title,to_char(ag_timestamp,'DD.MM.YY') as str_date ,
-                               ag_timestamp,dt_value
-                                       from action_gestion
-                                        join document_type on (ag_type=dt_id)
-                               where
-                               ag_id in (select aga_greatest from 
action_gestion_related where aga_least =$1)
-                               or
-                               ag_id in (select aga_least from 
action_gestion_related where aga_greatest =$1)
-                               order by ag_timestamp", array($this->ag_id));
-        $iaction=new IRelated_Action('action');
-        $iaction->value=(isset($this->action))?$this->action:"";
-
-        // state
-        // Retrieve the value
-        $a=$this->db->make_array("select s_id,s_value from document_state ");
-        $state=new ISelect();
-        $state->readOnly=$readonly;
-        $state->name="ag_state";
-        $state->value=$a;
-        $state->selected=$this->ag_state;
-        $str_state=$state->input();
-
-        // Retrieve the value if there is an attached doc
-        $doc_ref="";
-        // Document id
-
-        $h2=new IHidden();
-        $h2->name="d_id";
-        $h2->value=$this->d_id;
-
-        if ($this->d_id!=0&&$this->d_id!="")
-        {
-            $h2->readonly=($p_view=='NEW')?false:true;
-            $doc=new Document($this->db, $this->d_id);
-            $doc->get();
-            if (strlen(trim($doc->d_lob))!=0)
-            {
-                $d_id=new IHidden();
-                $doc_ref="<p> Document ".$doc->anchor().'</p>';
-                $doc_ref.=$h2->input().$d_id->input('d_id', $this->d_id);
-            }
-        }
-
-
-        // title
-        $title=new IText();
-        $title->readOnly=$readonly;
-        $title->name="ag_title";
-        $title->value=$this->ag_title;
-        $title->size=60;
-
-
-        // Priority of the ag_priority
-        $ag_priority=new ISelect();
-        $ag_priority->readOnly=$readonly;
-        $ag_priority->name="ag_priority";
-        $ag_priority->selected=$this->ag_priority;
-        $ag_priority->value=array(array('value'=>1, 'label'=>'Haute'),
-            array('value'=>2, 'label'=>'Moyenne'),
-            array('value'=>3, 'label'=>'Basse')
-        );
-        $str_ag_priority=$ag_priority->input();
-
-        // hour of the action (meeting) ag_hour
-        $ag_hour=new IText();
-        $ag_hour->readOnly=$readonly;
-        $ag_hour->name="ag_hour";
-        $ag_hour->value=$this->ag_hour;
-        $ag_hour->size=6;
-        $ag_hour->javascript=" onblur=check_hour('ag_hour');";
-        $str_ag_hour=$ag_hour->input();
-
-        // Profile in charged of the action
-        $ag_dest=new ISelect();
-        $ag_dest->readOnly=$readonly;
-        $ag_dest->name="ag_dest";
-        // select profile
-        $aAg_dest=$this->db->make_array("select  p_id as value, ".
-                "p_name as label ".
-                " from profile  where p_id in (select p_granted from 
user_sec_action_profile where ua_right='W' and p_id=".$g_user->get_profile().") 
order by 2");
-
-        $ag_dest->value=$aAg_dest;
-        $ag_dest->selected=$this->ag_dest;
-        $str_ag_dest=$ag_dest->input();
-
-        // ag_ref
-        // Always false for update
-
-        $client_label=new ISpan();
-
-        /* Add button */
-        $f_add_button=new IButton('add_card');
-        $f_add_button->label=_('Créer une nouvelle fiche');
-        $f_add_button->set_attribute('ipopup', 'ipop_newcard');
-        $filter=$this->db->make_list('select fd_id from fiche_def ');
-        $f_add_button->set_attribute('filter', $filter);
-
-        $f_add_button->javascript=" select_card_type(this);";
-        $str_add_button=$f_add_button->input();
-
-        // f_id_dest sender
-        if ($this->qcode_dest!=NOTFOUND&&strlen(trim($this->qcode_dest))!=0)
-        {
-            $tiers=new Fiche($this->db);
-            $tiers->get_by_qcode($this->qcode_dest);
-            $qcode_dest_label=$tiers->strAttribut(1);
-            $this->f_id_dest=$tiers->id;
-        }
-        else
-        {
-            
$qcode_dest_label=($this->f_id_dest==0||trim($this->qcode_dest)=="")?'Interne 
':'Error';
-        }
-
-        $h_ag_id=new IHidden();
-        // if concerns another action : show the link otherwise nothing
-        //
-               // sender
-        $w=new ICard();
-        $w->readOnly=$readonly;
-        $w->jrn=0;
-        $w->name='qcode_dest';
-        $w->value=($this->f_id_dest!=0)?$this->qcode_dest:"";
-        $w->label="";
-        $list_recipient=$this->db->make_list('select fd_id from fiche_def 
where frd_id in (14,25,8,9,16)');
-        $w->extra=$list_recipient;
-        $w->set_attribute('typecard', $list_recipient);
-        $w->set_dblclick("fill_ipopcard(this);");
-        $w->set_attribute('ipopup', 'ipopcard');
-
-        // name of the field to update with the name of the card
-        $w->set_attribute('label', 'qcode_dest_label');
-        // name of the field to update with the name of the card
-        $w->set_attribute('typecard', $w->extra);
-        $w->set_function('fill_data');
-        $w->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ', 
$w->name);
-
-        $sp=new ISpan();
-        $sp->name='qcode_dest_label';
-        $sp->value=$qcode_dest_label;
-
-        // autre - a refaire pour avoir plusieurs fiches
-        // Sur le modèle des tags
-        $ag_contact=new ICard();
-        $ag_contact->readOnly=$readonly;
-        $ag_contact->jrn=0;
-        $ag_contact->name='ag_contact';
-        $ag_contact->value='';
-        $ag_contact->set_attribute('ipopup', 'ipopcard');
-
-        if ($this->ag_contact!=0)
-        {
-            $contact=new Fiche($this->db, $this->ag_contact);
-            $ag_contact->value=$contact->get_quick_code();
-        }
-
-        $ag_contact->label="";
-
-        $list_contact=$this->db->make_list('select fd_id from fiche_def where 
frd_id=16');
-        $ag_contact->extra=$list_contact;
-
-        $ag_contact->set_dblclick("fill_ipopcard(this);");
-        // name of the field to update with the name of the card
-        $ag_contact->set_attribute('label', 'ag_contact_label');
-        // name of the field to update with the name of the card
-        $ag_contact->set_attribute('typecard', $list_contact);
-        $ag_contact->set_function('fill_data');
-        $ag_contact->javascript=sprintf(' 
onchange="fill_data_onchange(\'%s\');" ', $ag_contact->name);
-
-        $spcontact=new ISpan();
-        $spcontact->name='ag_contact_label';
-        $spcontact->value='';
-        $fiche_contact=new Fiche($this->db);
-        $fiche_contact->get_by_qcode($this->ag_contact);
-        if ($fiche_contact->id!=0)
-        {
-            $spcontact->value=$fiche_contact->strAttribut(ATTR_DEF_NAME);
-        }
-
-
-        $h_agrefid=new IHidden();
-        $iag_ref=new IText("ag_ref");
-        $iag_ref->value=$this->ag_ref;
-        $iag_ref->readOnly=($p_view=="NEW"||$p_view=='READ')?true:false;
-        $str_ag_ref=$iag_ref->input();
-        // Preparing the return string
-        $r="";
-
-        /* for new files */
-        $upload=new IFile();
-        $upload->name="file_upload[]";
-        $upload->readOnly=$readonly;
-        $upload->value="";
-        $aAttachedFile=$this->db->get_array('select 
d_id,d_filename,d_description,d_mimetype,'.
-                '\'show_document.php?'.
-                Dossier::get().'&d_id=\'||d_id as link'.
-                ' from document where ag_id=$1', array($this->ag_id));
-        /* create the select for document */
-        $aDocMod=new ISelect();
-        $aDocMod->name='doc_mod';
-        $aDocMod->value=$this->db->make_array('select md_id,dt_value||\' : 
\'||md_name as md_name'.
-                ' from document_modele join document_type on (md_type=dt_id)'.
-                ' order by md_name');
-        $str_select_doc=$aDocMod->input();
-        /* if no document then do not show the generate button */
-        if (empty($aDocMod->value))
-            $str_submit_generate="";
-        else
-            $str_submit_generate=HtmlInput::submit("generate", _("Génére le 
document"));
-
-        $ag_id=$this->ag_id;
-
-        /* fid = Icard  */
-        $icard=new ICard();
-        $icard->jrn=0;
-        $icard->table=0;
-        $icard->extra2='QuickCode';
-        $icard->noadd="no";
-        $icard->extra='all';
-
-        /* Text desc  */
-        $text=new IText();
-        $num=new INum();
-
-        /* TVA */
-        $itva=new ITva_Popup($this->db);
-        $itva->in_table=true;
-        $aCard=array();
-        /* create aArticle for the detail section */
-        
$article_count=(count($this->aAction_detail)==0)?MAX_ARTICLE:count($this->aAction_detail);
-        /* Compute total */
-        $tot_item=0;
-        $tot_vat=0;
-        for ($i=0; $i<$article_count; $i++)
-        {
-            /* fid = Icard  */
-            $icard=new ICard();
-            $icard->jrn=0;
-            $icard->table=0;
-            $icard->noadd="no";
-            $icard->extra='all';
-            $icard->name="e_march".$i;
-            
$tmp_ad=(isset($this->aAction_detail[$i]))?$this->aAction_detail[$i]:false;
-            $icard->readOnly=$readonly;
-            $icard->value='';
-            $aCard[$i]=0;
-            if ($tmp_ad)
-            {
-                $march=new Fiche($this->db);
-                $f=$tmp_ad->get_parameter('qcode');
-                if ($f!=0)
-                {
-                    $march->id=$f;
-                    $icard->value=$march->get_quick_code();
-                    $aCard[$i]=$f;
-                }
-            }
-            $icard->set_dblclick("fill_ipopcard(this);");
-            // name of the field to update with the name of the card
-            $icard->set_attribute('label', "e_march".$i."_label");
-            // name of the field to update with the name of the card
-            $icard->set_attribute('typecard', $icard->extra);
-            $icard->set_attribute('ipopup', 'ipopcard');
-            $icard->set_function('fill_data');
-            $icard->javascript=sprintf(' 
onchange="fill_data_onchange(\'%s\');" ', $icard->name);
-
-            $aArticle[$i]['fid']=$icard->search().$icard->input();
-
-            $text->javascript=' 
onchange="clean_tva('.$i.');compute_ledger('.$i.')"';
-            $text->css_size="100%";
-            $text->name="e_march".$i."_label";
-            $text->id="e_march".$i."_label";
-            $text->size=40;
-            $text->value=($tmp_ad)?$tmp_ad->get_parameter('text'):"";
-            $text->readOnly=$readonly;
-            $aArticle[$i]['desc']=$text->input();
-
-            $num->javascript=' 
onchange="format_number(this);clean_tva('.$i.');compute_ledger('.$i.')"';
-            $num->name="e_march".$i."_price";
-            $num->id="e_march".$i."_price";
-            $num->size=8;
-            $num->readOnly=$readonly;
-            $num->value=($tmp_ad)?$tmp_ad->get_parameter('price_unit'):0;
-            $aArticle[$i]['pu']=$num->input();
-
-            $num->name="e_quant".$i;
-            $num->id="e_quant".$i;
-            $num->size=8;
-            $num->value=($tmp_ad)?$tmp_ad->get_parameter('quantity'):0;
-            $aArticle[$i]['quant']=$num->input();
-
-            $itva->name='e_march'.$i.'_tva_id';
-            $itva->id='e_march'.$i.'_tva_id';
-            $itva->value=($tmp_ad)?$tmp_ad->get_parameter('tva_id'):0;
-            $itva->readOnly=$readonly;
-            $itva->js=' 
onchange="format_number(this);clean_tva('.$i.');compute_ledger('.$i.')"';
-            $itva->set_attribute('compute', $i);
-
-            $aArticle[$i]['tvaid']=$itva->input();
-
-            $num->name="e_march".$i."_tva_amount";
-            $num->id="e_march".$i."_tva_amount";
-            $num->value=($tmp_ad)?$tmp_ad->get_parameter('tva_amount'):0;
-            $num->javascript=" onchange=\"compute_ledger('".$i." ')\"";
-            $num->size=8;
-            $aArticle[$i]['tva']=$num->input();
-            $tot_vat=bcadd($tot_vat,$num->value);
-
-            $num->name="tvac_march".$i;
-            $num->id="tvac_march".$i;
-            $num->value=($tmp_ad)?$tmp_ad->get_parameter('total'):0;
-            $num->size=8;
-            $aArticle[$i]['tvac']=$num->input();
-            $tot_item=bcadd($tot_item,$num->value);
-
-            $aArticle[$i]['hidden_htva']=HtmlInput::hidden('htva_march'.$i, 0);
-            $aArticle[$i]['hidden_tva']=HtmlInput::hidden('tva_march'.$i, 0);
-            $aArticle[$i]['ad_id']=($tmp_ad)?HtmlInput::hidden('ad_id'.$i, 
$tmp_ad->get_parameter('id')):HtmlInput::hidden('ad_id'.$i, 0);
-        }
-
-        /* Add the needed hidden values */
-        $r.=dossier::hidden();
-
-        /* add the number of item */
-        $Hid=new IHidden();
-        $r.=$Hid->input("nb_item", $article_count);
-        $r.=HtmlInput::request_to_hidden(array("closed_action", 
"remind_date_end", "remind_date", "sag_ref", "only_internal", "state", "qcode", 
"ag_dest_query", "action_query", "tdoc", "date_start", "date_end", "hsstate", 
"searchtag"));
-        $a_tag=$this->tag_get();
-        $menu=new Default_Menu();
-        /* get template */
-        ob_start();
-        require 'template/detail-action.php';
-        $content=ob_get_contents();
-        ob_end_clean();
-        $r.=$content;
-
-        //hidden
-        $r.="<p>";
-        $r.=$h2->input();
-        $r.=$h_ag_id->input('ag_id', $this->ag_id);
-        $hidden2=new IHidden();
-        $r.=$hidden2->input('f_id_dest', $this->f_id_dest);
-        $r.="</p>";
-
-        return $r;
-    }
-
-    //----------------------------------------------------------------------
-    /*     * \brief This function shows the detail of an action thanks the 
ag_id
-     */
-    function get()
-    {
-        $sql="select ag_id,to_char (ag_timestamp,'DD.MM.YYYY') as 
ag_timestamp,".
-                " f_id_dest,ag_title,ag_ref,d_id,ag_type,ag_state, ag_owner, ".
-                "  ag_dest, ag_hour, ag_priority, ag_contact,to_char 
(ag_remind_date,'DD.MM.YYYY') as ag_remind_date ".
-                " from action_gestion left join document using (ag_id) where 
ag_id=".$this->ag_id;
-        $r=$this->db->exec_sql($sql);
-        $row=Database::fetch_all($r);
-        if ($row==false)
-        {
-            $this->ag_id=0;
-            return;
-        }
-        $this->ag_timestamp=$row[0]['ag_timestamp'];
-        $this->ag_contact=$row[0]['ag_contact'];
-        $this->f_id_dest=$row[0]['f_id_dest'];
-        $this->ag_title=$row[0]['ag_title'];
-        $this->ag_type=$row[0]['ag_type'];
-        $this->ag_ref=$row[0]['ag_ref'];
-        $this->ag_state=$row[0]['ag_state'];
-        $this->d_id=$row[0]['d_id'];
-        $this->ag_dest=$row[0]['ag_dest'];
-        $this->ag_hour=$row[0]['ag_hour'];
-        $this->ag_priority=$row[0]['ag_priority'];
-        $this->ag_remind_date=$row[0]['ag_remind_date'];
-        $this->ag_owner=$row[0]['ag_owner'];
-
-        $action_detail=new Follow_Up_Detail($this->db);
-        $action_detail->set_parameter('ag_id', $this->ag_id);
-        $this->aAction_detail=$action_detail->load_all();
-
-
-        // if there is no document set 0 to d_id
-        if ($this->d_id=="")
-            $this->d_id=0;
-        // if there is a document fill the object
-        if ($this->d_id!=0)
-        {
-            $this->state=$row['0']['ag_state'];
-            $this->ag_state=$row[0]['ag_state'];
-        }
-        $this->dt_id=$this->ag_type;
-        $aexp=new Fiche($this->db, $this->f_id_dest);
-        $this->qcode_dest=$aexp->strAttribut(ATTR_DEF_QUICKCODE);
-    }
-
-    /**
-     * \brief Save the document and propose to save the generated document or
-     *  to upload one, the data are included except the file. Temporary the 
generated
-     * document is save.
-     * The files into $_FILES['file_upload'] will be saved
-     * @note the array $_POST['input_desc'] must be set, contains the 
description
-     * of the uploaded files
-     *
-     * \return
-     */
-    function save()
-    {
-
-        // Get The sequence id,
-        $seq_name="seq_doc_type_".$this->dt_id;
-        $str_file="";
-        $add_file='';
-
-        // f_id exp
-        $exp=new Fiche($this->db);
-        $exp->get_by_qcode($this->qcode_dest);
-        $exp->id=($exp->id==0)?null:$exp->id;
-
-        $contact=new Fiche($this->db);
-        $contact->get_by_qcode($this->ag_contact);
-
-        if (trim($this->ag_title)=="")
-        {
-            $doc_mod=new document_type($this->db);
-            $doc_mod->dt_id=$this->dt_id;
-            $doc_mod->get();
-            $this->ag_title=$doc_mod->dt_value;
-        }
-        $this->ag_id=$this->db->get_next_seq('action_gestion_ag_id_seq');
-
-        // Create the reference
-        $ag_ref=$this->db->get_value('select dt_prefix from document_type 
where dt_id=$1', array($this->dt_id)).'-'.$this->db->get_next_seq($seq_name);
-        $this->ag_ref=$ag_ref;
-
-        // save into the database
-        if ($this->ag_remind_date!=null||$this->ag_remind_date!='')
-        {
-            $sql="insert into action_gestion".
-                    "(ag_id,ag_timestamp,ag_type,ag_title,f_id_dest,ag_ref, 
ag_dest, ".
-                    " ag_hour, 
ag_priority,ag_owner,ag_contact,ag_state,ag_remind_date) ".
-                    " values 
($1,to_date($2,'DD.MM.YYYY'),$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,to_date($13,'DD.MM.YYYY'))";
-        }
-        else
-        {
-            $this->ag_remind_date=null;
-            $sql="insert into action_gestion".
-                    "(ag_id,ag_timestamp,ag_type,ag_title,f_id_dest,ag_ref, 
ag_dest, ".
-                    " ag_hour, 
ag_priority,ag_owner,ag_contact,ag_state,ag_remind_date) ".
-                    " values 
($1,to_date($2,'DD.MM.YYYY'),$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13)";
-        }
-        $this->db->exec_sql($sql, array($this->ag_id, /* 1 */
-            $this->ag_timestamp, /* 2 */
-            $this->dt_id, /* 3 */
-            $this->ag_title, /* 4 */
-            $exp->id, /* 5 */
-            $ag_ref, /* 6 */
-            $this->ag_dest, /* 7 */
-            $this->ag_hour, /* 8 */
-            $this->ag_priority, /* 9 */
-            $_SESSION['g_user'], /* 10 */
-            $contact->id, /* 11 */
-            $this->ag_state, /* 12 */
-            $this->ag_remind_date /* 13 */
-                )
-        );
-
-        /* insert also the details */
-        for ($i=0; $i<$_POST['nb_item']; $i++)
-        {
-            $act=new Follow_Up_Detail($this->db);
-            $act->from_array($_POST, $i);
-            if ($act->f_id==0)
-                continue;
-            $act->ag_id=$this->ag_id;
-            $act->save();
-        }
-
-        /* Upload the documents */
-        $doc=new Document($this->db);
-        $doc->Upload($this->ag_id);
-        if (trim($this->ag_comment)!='')
-        {
-            $this->db->exec_sql("insert into action_gestion_comment 
(ag_id,tech_user,agc_comment) values ($1,$2,$3)"
-                    , array($this->ag_id, $_SESSION['g_user'], 
$this->ag_comment));
-        }
-        $this->insert_operation();
-        $this->insert_action();
-    }
-
-    /**
-     * myList($p_base, $p_filter = "", $p_search = "") 
-     * Show list of action by default if sorted on date
-     * @param $p_base base url with ac...
-     * @param $p_filter filters on the document_type
-     * @param $p_search must a valid sql command ( ex 'and  ag_title like 
upper('%hjkh%'))
-     * @return string containing html code
-     */
-    function myList($p_base, $p_filter="", $p_search="")
-    {
-        // for the sort
-        $url=HtmlInput::get_to_string(array("closed_action", 
"remind_date_end", "remind_date", "sag_ref", "only_internal", "state", "qcode", 
"ag_dest_query", "action_query", "tdoc", "date_start", "date_end", "hsstate", 
"searchtag")).'&'.$p_base;
-
-        $table=new Sort_Table();
-        $table->add('Date Doc.', $url, 'order by ag_timestamp asc', 'order by 
ag_timestamp desc', 'da', 'dd');
-        $table->add('Date Comm.', $url, 'order by last_comment', 'order by 
last_comment desc', 'dca', 'dcd');
-        $table->add('Date Limite', $url, 'order by ag_remind_date asc', 'order 
by ag_remind_date  desc', 'ra', 'rd');
-        $table->add('Tag', $url, 'order by tags asc', 'order by tags desc', 
'taa', 'tad');
-        $table->add('Réf.', $url, 'order by ag_ref asc', 'order by ag_ref 
desc', 'ra', 'rd');
-        $table->add('Groupe', $url, "order by coalesce((select p_name from 
profile where p_id=ag_dest),'Aucun groupe')", "order by coalesce((select p_name 
from profile where p_id=ag_dest),'Aucun groupe') desc", 'dea', 'ded');
-        $table->add('Dest/Exp', $url, 'order by name asc', 'order by name 
desc', 'ea', 'ed');
-        $table->add('Titre', $url, 'order by ag_title asc', 'order by ag_title 
desc', 'ta', 'td');
-
-        $ord=(!isset($_GET['ord']))?"dcd":$_GET['ord'];
-        $sort=$table->get_sql_order($ord);
-
-        if (strlen(trim($p_filter))!=0)
-            $p_filter_doc=" dt_id in ( $p_filter )";
-        else
-            $p_filter_doc=" 1=1 ";
-
-        $sql="
-             select ag_id,to_char(ag_timestamp,'DD.MM.YYYY') as my_date,
-                to_char(ag_remind_date,'DD.MM.YYYY') as my_remind,
-                to_char(coalesce((select max(agc_date) from 
action_gestion_comment as agc where 
agc.ag_id=ag.ag_id),ag_timestamp),'DD.MM.YY') as str_last_comment,
-                coalesce((select max(agc_date) from action_gestion_comment as 
agc where agc.ag_id=ag.ag_id),ag_timestamp) as last_comment,
-                f_id_dest,
-                s_value,
-                ag_title,dt_value,ag_ref, ag_priority,ag_state,
-                coalesce((select p_name from profile where 
p_id=ag_dest),'Aucun groupe') as dest,
-                (select ad_value from fiche_Detail where f_id=ag.f_id_dest and 
ad_id=1) as name,
-                array_to_string((select array_agg(t1.t_tag) from action_tags 
as a1 join tags as t1 on (a1.t_id=t1.t_id) where a1.ag_id=ag.ag_id ),',') as 
tags
-            from action_gestion as ag
-                join document_type on (ag_type=dt_id)
-                join document_state on (ag_state=s_id)
-             where $p_filter_doc $p_search $sort";
-        $max_line=$this->db->count_sql($sql);
-        $step=$_SESSION['g_pagesize'];
-        $page=(isset($_GET['offset']))?$_GET['page']:1;
-        
$offset=(isset($_GET['offset']))?Database::escape_string($_GET['offset']):0;
-        if ($step!=-1)
-            $limit=" LIMIT $step OFFSET $offset ";
-        else
-            $limit='';
-        $bar=navigation_bar($offset, $max_line, $step, $page);
-
-        $Res=$this->db->exec_sql($sql.$limit);
-        $a_row=Database::fetch_all($Res);
-
-        $r="";
-        $r.='<p>'.$bar.'</p>';
-        $r.='<table class="document">';
-        $r.="<tr>";
-        $r.='<th name="ag_id_td" style="display:none" 
>'.ICheckBox::toggle_checkbox('ag', 'list_ag_frm').'</th>';
-        $r.='<th>'.$table->get_header(0).'</th>';
-        $r.='<th>'.$table->get_header(1).'</th>';
-        $r.='<th>'.$table->get_header(2).'</th>';
-        $r.='<th>'.$table->get_header(3).'</th>';
-        $r.='<th>'.$table->get_header(4).'</th>';
-        $r.='<th>'.$table->get_header(5).'</th>';
-        $r.='<th>'.$table->get_header(6).'</th>';
-        $r.='<th>'.$table->get_header(7).'</th>';
-        $r.=th('Priorité');
-        $r.="</tr>";
-
-
-        // if there are no records return a message
-        if (sizeof($a_row)==0 or $a_row==false)
-        {
-            $r='<div style="clear:both">';
-            $r.='<hr>Aucun enregistrement trouvé';
-            $r.="</div>";
-            return $r;
-        }
-        $today=date('d.m.Y');
-        $i=0;
-        $checkbox=new ICheckBox("mag_id[]");
-        //show the sub_action
-        foreach ($a_row as $row)
-        {
-            $href='<A class="document" 
HREF="do.php?'.$p_base.HtmlInput::get_to_string(array("closed_action", 
"remind_date_end", "remind_date", "sag_ref", "only_internal", "state", 
"gDossier", "qcode", "ag_dest_query", "action_query", "tdoc", "date_start", 
"date_end", "hsstate", "searchtag", "ac"), 
"&").'&sa=detail&ag_id='.$row['ag_id'].'">';
-            $i++;
-            $tr=($i%2==0)?'even':'odd';
-            if ($row['ag_priority']<2)
-                $tr='priority1';
-            $st='';
-            if ($row['my_date']==$today)
-                $st=' style="font-weight:bold; border:2px solid orange;"';
-            $date_remind=format_date($row['my_remind'], 'DD.MM.YYYY', 
'YYYYMMDD');
-            $date_today=date('Ymd');
-            if 
($date_remind!=""&&$date_remind==$date_today&&$row['ag_state']!=1&&$row['ag_state']!=3)
-                $st=' style="font-weight:bold;background:orange"';
-            if 
($date_remind!=""&&$date_remind<$date_today&&$row['ag_state']!=1&&$row['ag_state']!=3)
-                $st=' 
style="font-weight:bold;background:#FF0000;color:white;"';
-            $r.="<tr class=\"$tr\" $st>";
-            $checkbox->value=$row['ag_id'];
-            $r.='<td name="ag_id_td" 
style="display:none">'.$checkbox->input().'</td>';
-            $r.="<td>".$href.smaller_date($row['my_date']).'</a>'."</td>";
-            $r.="<td>".$href.$row['str_last_comment'].'</a>'."</td>";
-            $r.="<td>".$href.smaller_date($row['my_remind']).'</a>'."</td>";
-            $r.="<td>".$href.h($row['tags']).'</a>'."</td>";
-            $r.="<td>".$href.$row['ag_ref'].'</a>'."</td>";
-            $r.="<td>".$href.h($row['dest']).'</a>'."</td>";
-
-            // Expediteur
-            $fexp=new Fiche($this->db);
-            $fexp->id=$row['f_id_dest'];
-            $qcode_dest=$fexp->strAttribut(ATTR_DEF_QUICKCODE);
-
-            $qexp=($qcode_dest==NOTFOUND)?"Interne":$qcode_dest;
-            $jsexp=sprintf("javascript:showfiche('%s')", $qexp);
-            if ($qexp!='Interne')
-            {
-                $r.="<td>$href".$qexp." : ".$fexp->getName().'</a></td>';
-            }
-            else
-                $r.="<td>$href Interne </a></td>";
-
-            $ref="";
-
-
-            $r.='<td>'.$href.
-                    h($row['ag_title'])."</A></td>";
-
-            /*
-             * State
-             */
-            switch ($row['ag_priority'])
-            {
-                case 1:
-                    $priority='Haute';
-                    break;
-                case 2:
-                    $priority="Moyenne";
-                    break;
-                case 3:
-                    $priority="Important";
-                    break;
-            }
-            $r.=td($priority);
-
-            $r.="<td>".$ref."</td>";
-            $r.="</tr>";
-        }
-
-        $r.="</table>";
-
-        $r.='<p>'.$bar.'</p>';
-        return $r;
-    }
-
-    //----------------------------------------------------------------------
-    /*     * \brief Update the data into the database
-     *
-     * \return true on success otherwise false
-     */
-    function Update()
-    {
-
-        // if ag_id == 0 nothing to do
-        if ($this->ag_id==0)
-            return;
-        // retrieve customer
-        // f_id
-
-        if (trim($this->qcode_dest)=="")
-        {
-            // internal document
-            $this->f_id_dest=null; // internal document
-        }
-        else
-        {
-            $tiers=new Fiche($this->db);
-            if ($tiers->get_by_qcode($this->qcode_dest)==-1) // Error we 
cannot retrieve this qcode
-                return false;
-            else
-                $this->f_id_dest=$tiers->id;
-        }
-        $contact=new Fiche($this->db);
-        if ($contact->get_by_qcode($this->ag_contact)==-1)
-            $contact->id=0;
-
-        // reload the old one
-        $old=new Follow_Up($this->db);
-        $old->ag_id=$this->ag_id;
-        $old->get();
-
-        // If ag_ref changed then check if unique
-        if ($old->ag_ref!=$this->ag_ref)
-        {
-            $nAg_ref=$this->db->get_value("select count(*) from action_gestion 
where ag_ref=$1", array($this->ag_ref));
-            if ($nAg_ref!=0)
-            {
-                echo h2("Référence en double, référence non sauvée", 
'class="error"');
-                $this->ag_ref=$old->ag_ref;
-            }
-        }
-
-
-        if ($this->ag_remind_date!=null)
-        {
-            $this->db->exec_sql("update action_gestion set ".
-                    " ag_timestamp=to_date($1,'DD.MM.YYYY'),".
-                    " ag_title=$2,".
-                    " ag_type=$3, ".
-                    " f_id_dest=$4, ".
-                    "ag_state=$5,".
-                    " ag_hour = $7 ,".
-                    " ag_priority = $8 ,".
-                    " ag_dest = $9 , ".
-                    " ag_contact = $10, ".
-                    " ag_ref = $11, ".
-                    " ag_remind_date=to_date($12,'DD.MM.YYYY') ".
-                    " where ag_id = $6", array(
-                $this->ag_timestamp, /* 1 */
-                $this->ag_title, /* 2 */
-                $this->dt_id, /* 3 */
-                $this->f_id_dest, /* 4 */
-                $this->ag_state, /* 5 */
-                $this->ag_id, /* 6 */
-                $this->ag_hour, /* 7 */
-                $this->ag_priority, /* 8 */
-                $this->ag_dest, /* 9 */
-                $contact->id, /* 10 */
-                $this->ag_ref, /* 11 */
-                $this->ag_remind_date /* 12 */
-            ));
-        }
-        else
-        {
-            $this->db->exec_sql("update action_gestion set ".
-                    " ag_timestamp=to_date($1,'DD.MM.YYYY'),".
-                    " ag_title=$2,".
-                    " ag_type=$3, ".
-                    " f_id_dest=$4, ".
-                    "ag_state=$5,".
-                    " ag_hour = $7 ,".
-                    " ag_priority = $8 ,".
-                    " ag_dest = $9 , ".
-                    " ag_contact = $10, ".
-                    " ag_ref = $11, ".
-                    " ag_remind_date=null ".
-                    " where ag_id = $6", array(
-                $this->ag_timestamp, /* 1 */
-                $this->ag_title, /* 2 */
-                $this->dt_id, /* 3 */
-                $this->f_id_dest, /* 4 */
-                $this->ag_state, /* 5 */
-                $this->ag_id, /* 6 */
-                $this->ag_hour, /* 7 */
-                $this->ag_priority, /* 8 */
-                $this->ag_dest, /* 9 */
-                $contact->id, /* 10 */
-                $this->ag_ref /* 11 */
-            ));
-        }
-        // Upload  documents
-        $doc=new Document($this->db);
-        $doc->Upload($this->ag_id);
-
-        /* save action details */
-        for ($i=0; $i<$_POST['nb_item']; $i++)
-        {
-            $act=new Follow_Up_Detail($this->db);
-            $act->from_array($_POST, $i);
-            if ($act->f_id==0&&$act->ad_id!=0)
-                $act->delete();
-            if ($act->f_id==0)
-                continue;
-            $act->save();
-        }
-        if (trim($this->ag_comment)!='')
-        {
-            $this->db->exec_sql("insert into action_gestion_comment 
(ag_id,tech_user,agc_comment) values ($1,$2,$3)"
-                    , array($this->ag_id, $_SESSION['g_user'], 
$this->ag_comment));
-        }
-        $this->insert_operation();
-        $this->insert_action();
-        return true;
-    }
-
-    /**
-     * \brief generate the document and add it to the action
-     * \param md_id is the id of the document_modele
-     * \param $p_array contains normally the $_POST
-     */
-    function generate_document($md_id, $p_array)
-    {
-        $doc=new Document($this->db);
-        $mod=new Document_Modele($this->db, $md_id);
-        $mod->load();
-        $doc->f_id=$this->f_id_dest;
-        $doc->md_id=$md_id;
-        $doc->ag_id=$this->ag_id;
-        $doc->Generate($p_array);
-    }
-
-    /**
-     * \brief put an array in the variable member, the indice
-     * is the member name
-     * \param $p_array to parse
-     *      - ag_id id of the Follow_up
-     *      - ag_ref reference of the action
-     *      - qcode_dest quick_code of the card of dest
-     *      - f_id_dest f_id of the card of dest
-     *      - dt_id Document_Modele::dt_id
-     *      - ag_state document_state::s_id (default:2)
-     *      - ag_title title of the action
-     *      - ag_hour
-     *      - ag_dest Profile, profile of the user
-     *      - ag_comment comment
-     *      - ag_remind_date Remind Date
-     *      - operation related operation
-     *      - action related action 
-     *      - op deprecated
-     * \return nothing
-     */
-    function fromArray($p_array)
-    {
-        global $g_user;
-        $this->ag_id=(isset($p_array['ag_id']))?$p_array['ag_id']:0;
-        $this->ag_ref=(isset($p_array['ag_ref']))?$p_array['ag_ref']:"";
-        
$this->qcode_dest=(isset($p_array['qcode_dest']))?$p_array['qcode_dest']:"";
-        
$this->f_id_dest=(isset($p_array['f_id_dest']))?$p_array['f_id_dest']:null;
-        
$this->ag_timestamp=(isset($p_array['ag_timestamp']))?$p_array['ag_timestamp']:date('d.m.Y');
-        
$this->qcode_dest=(isset($p_array['qcode_dest']))?$p_array['qcode_dest']:"";
-        $this->dt_id=(isset($p_array['dt_id']))?$p_array['dt_id']:"";
-        $this->ag_state=(isset($p_array['ag_state']))?$p_array['ag_state']:2;
-        $this->ag_ref=(isset($p_array['ag_ref']))?$p_array['ag_ref']:"";
-        $this->ag_title=(isset($p_array['ag_title']))?$p_array['ag_title']:"";
-        $this->ag_hour=(isset($p_array['ag_hour']))?$p_array['ag_hour']:"";
-        
$this->ag_dest=(isset($p_array['ag_dest']))?$p_array['ag_dest']:$g_user->get_profile();
-        
$this->ag_priority=(isset($p_array['ag_priority']))?$p_array['ag_priority']:2;
-        
$this->ag_contact=(isset($p_array['ag_contact']))?$p_array['ag_contact']:"";
-        
$this->ag_comment=(isset($p_array['ag_comment']))?$p_array['ag_comment']:"";
-        
$this->ag_remind_date=(isset($p_array['ag_remind_date']))?$p_array['ag_remind_date']:null;
-        
$this->operation=(isset($p_array['operation']))?$p_array['operation']:null;
-        /**
-         * @todo
-         * deprecated : to remove
-          $this->op = (isset($p_array['op'])) ? $p_array['op'] : null;
-         */
-        $this->action=(isset($p_array['action']))?$p_array['action']:null;
-    }
-
-    /**
-     * \brief remove the action
-     *
-     */
-    function remove()
-    {
-        $this->get();
-        // remove the key
-        $sql="delete from action_gestion where ag_id=$1";
-        $this->db->exec_sql($sql, array($this->ag_id));
-
-        /*  check the number of attached document */
-        $doc=new Document($this->db);
-        $aDoc=$doc->get_all($this->ag_id);
-        if (!empty($aDoc))
-        {
-            // if there are documents
-            for ($i=0; $i<sizeof($aDoc); $i++)
-            {
-                $aDoc[$i]->remove();
-            }
-        }
-    }
-
-    /**
-     * \brief return the last p_limit operation into an array, there is a 
security
-     * on user
-     * \param $p_limit is the max of operation to return
-     * \return $p_array of Follow_Up object
-     */
-    function get_last($p_limit)
-    {
-        
-        $sql="select coalesce(vw_name,'Interne') as 
vw_name,quick_code,ag_id,ag_title,ag_ref, 
dt_value,to_char(ag_timestamp,'DD.MM.YYYY') as ag_timestamp_fmt,ag_timestamp ".
-                " from action_gestion join document_type ".
-                " on (ag_type=dt_id) "
-                . "left join vw_fiche_attr on (f_id=f_id_dest) "
-                . "where ag_state in (2,3) "
-                . "and ".self::sql_security_filter($this->db,'R').
-                        "order by ag_timestamp desc limit $p_limit";
-        $array=$this->db->get_array($sql);
-        return $array;
-    }
-
-    /**
-     * get the action where the remind day is today
-     * @return array
-     */
-    function get_today()
-    {
-        $sql="select ag_ref,coalesce(vw_name,'Interne') as 
vw_name,ag_id,ag_title,ag_ref, dt_value,to_char(ag_remind_date,'DD.MM.YYYY') as 
ag_timestamp_fmt,ag_timestamp ".
-                " from action_gestion join document_type ".
-                " on (ag_type=dt_id) 
-                  left join vw_fiche_attr on (f_id=f_id_dest) 
-                  where 
-                  ag_state not in (1,4)
-                  and 
to_char(ag_remind_date,'DDMMYYYY')=to_char(now(),'DDMMYYYY')
-                  and ". self::sql_security_filter($this->db,'R');
-        $array=$this->db->get_array($sql);
-        return $array;
-    }
-
-    /**
-     * get the action where the remind day is today
-     * @return array
-     */
-    function get_late()
-    {
-        $sql="select ag_ref,coalesce(vw_name,'Interne') as 
vw_name,ag_id,ag_title,ag_ref, dt_value,to_char(ag_remind_date,'DD.MM.YYYY') as 
ag_timestamp_fmt,ag_timestamp ".
-                " from action_gestion join document_type ".
-                " on (ag_type=dt_id) left join vw_fiche_attr on 
(f_id=f_id_dest) where ag_state not in  (1,4)
-                               and ag_remind_date < now()  and 
".self::sql_security_filter($this->db,'R');
-        $array=$this->db->get_array($sql);
-        return $array;
-    }
-
-    /**
-     * insert a related operation
-     */
-    function insert_operation()
-    {
-        if (trim($this->operation)=='')
-            return;
-        $array=explode(",", $this->operation);
-        for ($i=0; $i<count($array); $i++)
-        {
-            if ($this->db->get_value("select count(*) from 
action_gestion_operation
-                               where ag_id=$1 and jr_id=$2", 
array($this->ag_id, $array[$i]))==0)
-            {
-                $this->db->exec_sql("insert into action_gestion_operation 
(ag_id,jr_id) values ($1,$2)", array($this->ag_id, $array[$i]));
-            }
-        }
-    }
-
-    /**
-     * remove a related operation
-     * @deprecated not used : dead_code
-     * @todo to remove
-     */
-    function remove_operation_deprecated()
-    {
-        if ($this->op==null)
-            return;
-        $op=$this->op;
-        for ($i=0; $i<count($op); $i++)
-        {
-            $this->db->exec_sql("delete from action_gestion_operation where 
ago_id=$1", array($op[$i]));
-        }
-    }
-
-    /**
-     * Display only a search box for searching an action
-     * @param $cn database connx
-     */
-    static function display_search($cn, $inner=false)
-    {
-        $a=(isset($_GET['action_query']))?$_GET['action_query']:"";
-        $qcode=(isset($_GET['qcode']))?$_GET['qcode']:"";
-
-        $supl_hidden='';
-        if (isset($_REQUEST['sc']))
-            $supl_hidden.=HtmlInput::hidden('sc', $_REQUEST['sc']);
-        if (isset($_REQUEST['f_id']))
-        {
-            $supl_hidden.=HtmlInput::hidden('f_id', $_REQUEST['f_id']);
-            $f=new Fiche($cn, $_REQUEST['f_id']);
-            $supl_hidden.=HtmlInput::hidden('qcode_dest', 
$f->get_quick_code());
-        }
-        if (isset($_REQUEST['sb']))
-            $supl_hidden.=HtmlInput::hidden('sb', $_REQUEST['sb']);
-        $supl_hidden.=HtmlInput::hidden('ac', $_REQUEST['ac']);
-
-        /**
-         * Show the default button (add action, show search...)
-         */
-        if (!$inner)
-            require_once NOALYSS_INCLUDE.'/template/action_button.php';
-
-        $w=new ICard();
-        $w->name='qcode';
-        $w->id=$w->generate_id($w->name);
-        $w->value=$qcode;
-        $w->extra="all";
-        $w->typecard='all';
-        $w->jrn=0;
-        $w->table=0;
-        $list=$cn->make_list("select fd_id from fiche_def where frd_id in 
(4,8,9,14,15,16,25)");
-        $w->extra=$list;
-
-
-        /* type of documents */
-        $type_doc=new ISelect('tdoc');
-        $aTDoc=$cn->make_array('select dt_id,dt_value from document_type order 
by dt_value');
-        $aTDoc[]=array('value'=>'-1', 'label'=>_('Tous les types'));
-        $type_doc->value=$aTDoc;
-        $type_doc->selected=(isset($_GET['tdoc']))?$_GET['tdoc']:-1;
-
-        /* State of documents */
-        $type_state=new ISelect('state');
-        $aState=$cn->make_array('select s_id,s_value from document_state order 
by s_value');
-        $aState[]=array('value'=>'-1', 'label'=>_('Tous les Etats'));
-        $type_state->value=$aState;
-        $type_state->selected=(isset($_GET['state']))?$_GET['state']:-1;
-
-
-
-        /* Except State of documents */
-        $hsExcptype_state=new ISelect('hsstate');
-        $aExcpState=$cn->make_array('select s_id,s_value from document_state 
order by s_value');
-        $aExcpState[]=array('value'=>'-1', 'label'=>_('Aucun'));
-        $hsExcptype_state->value=$aExcpState;
-        
$hsExcptype_state->selected=(isset($_GET['hsstate']))?$_GET['hsstate']:-1;
-
-
-        // date
-        $start=new IDate('date_start');
-        $start->value=(isset($_GET['date_start']))?$_GET['date_start']:"";
-        $end=new IDate('date_end');
-        $end->value=(isset($_GET['date_end']))?$_GET['date_end']:"";
-
-        // Closed action
-        $closed_action=new ICheckBox('closed_action');
-        $closed_action->selected=(isset($_GET['closed_action']))?true:false;
-
-        // Internal
-        $only_internal=new ICheckBox('only_internal');
-        $only_internal->selected=(isset($_GET['only_internal']))?true:false;
-        // select profile
-        $aAg_dest=$cn->make_array("select  p_id as value, ".
-                "p_name as label ".
-                " from profile order by 2");
-        $aAg_dest[]=array('value'=>'-2', 'label'=>_('Tous les profiles'));
-        $ag_dest=new ISelect();
-        $ag_dest->name="ag_dest_query";
-        $ag_dest->value=$aAg_dest;
-        
$ag_dest->selected=(isset($_GET["ag_dest_query"]))?$_GET["ag_dest_query"]:-2;
-        $str_ag_dest=$ag_dest->input();
-        $osag_ref=new IText("sag_ref");
-        $osag_ref->value=(isset($_GET['sag_ref']))?$_GET['sag_ref']:"";
-        $remind_date=new IDate('remind_date');
-        
$remind_date->value=(isset($_GET['remind_date']))?$_GET['remind_date']:"";
-        $remind_date_end=new IDate('remind_date_end');
-        
$remind_date_end->value=(isset($_GET['remind_date_end']))?$_GET['remind_date_end']:"";
-        $otag=new Tag($cn);
-
-        // show the  action in
-        require_once NOALYSS_INCLUDE.'/template/action_search.php';
-    }
-
-    /**
-     * @brief show a list of documents
-     * @param $cn database connextion
-     * @param $p_base base URL
-     */
-    static function show_action_list($cn, $p_base)
-    {
-
-        Follow_Up::display_search($cn);
-
-        $act=new Follow_Up($cn);
-        /** \brief
-         *  \note The field 'recherche' is   about a part of the title or a 
ref. number
-         */
-        $query=Follow_Up::create_query($cn);
-
-        echo '<form method="POST" id="list_ag_frm" style="display:inline">';
-        echo HtmlInput::request_to_hidden(array("gDossier", "ac", "sb", "sc", 
"f_id"));
-        require_once NOALYSS_INCLUDE.'/template/action_other_action.php';
-        echo $act->myList($p_base, "", $query);
-        echo '</form>';
-    }
-
-    /**
-     * Create a subquery to filter thanks the selected tag
-     * @param  $cn db connx
-     * @param $p_array
-     * @return SQL 
-     */
-    static function filter_by_tag($cn, $p_array=null)
-    {
-        if ($p_array==null)
-            $p_array=$_GET;
-
-        extract($p_array);
-        $query="";
-        if (count($searchtag)==0)
-            return "";
-        for ($i=0; $i<count($searchtag); $i++)
-        {
-            if (isNumber($searchtag[$i])==1)
-                $query .= ' and ag_id in (select ag_id from action_tags where 
t_id= '.sql_string($searchtag[$i]).')';
-        }
-        return $query;
-    }
-
-    /**
-     * Get date from $_GET and create the sql stmt for the query
-     * @note the query is taken in $_REQUEST
-     * @see Follow_Up::ShowActionList
-     * @return string SQL condition
-     */
-    static function create_query($cn, $p_array=null)
-    {
-        if ($p_array==null)
-            $p_array=$_GET;
-
-        extract($p_array);
-        $action_query="";
-
-
-        if (isset($_REQUEST['action_query']))
-        {
-            // if a query is request build the sql stmt
-            $action_query="and (ag_title ~* 
'".sql_string($_REQUEST['action_query'])."' ".
-                    "or ag_ref ='".trim(sql_string($_REQUEST['action_query'])).
-                    "' or ag_id in (select ag_id from action_gestion_comment 
where agc_comment ~* '".trim(sql_string($_REQUEST['action_query']))."')".
-                    ")";
-        }
-
-        $str="";
-        if (isset($qcode))
-        {
-            // verify that qcode is not empty
-            if (strlen(trim($qcode))!=0)
-            {
-
-                $fiche=new Fiche($cn);
-                $fiche->get_by_qcode($_REQUEST['qcode']);
-                // if quick code not found then nothing
-                if ($fiche->id==0)
-                    $str=' and false ';
-                else
-                    $str=" and (f_id_dest= ".$fiche->id." or ag_id in (select 
ag_id from action_person as ap where ap.f_id=".$fiche->id.")  )";
-            }
-        }
-        if (isset($tdoc)&&$tdoc!=-1)
-        {
-            $action_query .= ' and dt_id = '.sql_string($tdoc);
-        }
-        if (isset($state)&&$state!=-1)
-        {
-            $action_query .= ' and ag_state= '.sql_string($state);
-        }
-        if (isset($hsstate)&&$hsstate!=-1)
-        {
-            $action_query .= ' and ag_state <> '.sql_string($hsstate);
-        }
-        if (isset($sag_ref)&&trim($sag_ref)!="")
-        {
-            $query .= ' and ag_ref= \''.sql_string($sag_ref)."'";
-        }
-
-        if (isset($_GET['only_internal']))
-            $action_query .= ' and f_id_dest=0 ';
-
-        if (isset($date_start)&&isDate($date_start)!=null)
-        {
-            $action_query.=" and ag_timestamp >= 
to_date('$date_start','DD.MM.YYYY')";
-        }
-        if (isset($date_end)&&isDate($date_end)!=null)
-        {
-            $action_query.=" and ag_timestamp <= 
to_date('$date_end','DD.MM.YYYY')";
-        }
-        if (isset($ag_dest_query)&&$ag_dest_query!=-2)
-        {
-            $action_query.= " and ((ag_dest = ".sql_string($ag_dest_query)." 
and ".self::sql_security_filter($cn, "R").") or ".
-                    "(ag_dest = ".sql_string($ag_dest_query)." and 
".self::sql_security_filter($cn, "R")." and ".
-                    " ag_owner='".$_SESSION['g_user']."'))";
-        }
-        else
-        {
-            $action_query .=" and (ag_owner='".$_SESSION['g_user']."' or 
".self::sql_security_filter($cn, "R")." or ag_dest=-1 )";
-        }
-
-
-        if (isNumber($ag_id)==1&&$ag_id!=0)
-        {
-            $action_query=" and ag_id= ".sql_string($ag_id);
-        }
-        if 
(isset($remind_date)&&$remind_date!=""&&isDate($remind_date)==$remind_date)
-        {
-            $action_query .= " and 
to_date('".sql_string($remind_date)."','DD.MM.YYYY')<= ag_remind_date";
-        }
-        if 
(isset($remind_date_end)&&$remind_date_end!=""&&isDate($remind_date_end)==$remind_date_end)
-        {
-            $action_query .= " and 
to_date('".sql_string($remind_date_end)."','DD.MM.YYYY')>= ag_remind_date";
-        }
-        if (!isset($closed_action))
-        {
-            $action_query.=" and s_status is null ";
-        }
-        if (isset($searchtag))
-        {
-            $action_query .= Follow_Up::filter_by_tag($cn, $p_array);
-        }
-        return $action_query.$str;
-    }
-
-    /**
-     * Show the result of a search in an inner windows, the result is limited 
to 25
-     * @param type $cn database connx
-     * @param type $p_sql the query
-     */
-    static function short_list($cn, $p_sql)
-    {
-        $sql="
-             select ag_id,to_char(ag_timestamp,'DD.MM.YY') as my_date,
-                        f_id_dest,
-             substr(ag_title,1,40) as sub_ag_title,dt_value,ag_ref, 
ag_priority,ag_state,
-                       coalesce((select p_name from profile where 
p_id=ag_dest),'Aucun groupe') as dest,
-                               (select ad_value from fiche_Detail where 
f_id=action_gestion.f_id_dest and ad_id=1) as name
-             from action_gestion
-             join document_type on (ag_type=dt_id)
-                        join document_state on (s_id=ag_state)
-             where $p_sql";
-        $max_line=$cn->count_sql($sql);
-
-        $limit=($max_line>25)?25:$max_line;
-        $Res=$cn->exec_sql($sql."limit ".$limit);
-        $a_row=Database::fetch_all($Res);
-        require_once NOALYSS_INCLUDE.'/template/action_search_result.php';
-    }
-
-    /**
-     * Insert a related action into the table action_gestion_related
-     */
-    function insert_action()
-    {
-        if (trim($this->action)=='')
-            return;
-        $array=explode(",", $this->action);
-        for ($i=0; $i<count($array); $i++)
-        {
-            if ($this->db->get_value("select count(*) from 
action_gestion_related
-                               where (aga_least=$1 and aga_greatest=$2) or 
(aga_greatest=$1 and aga_least=$2)", array($array[$i], 
$this->ag_id))==0&&$this->ag_id!=$array[$i])
-            {
-                $this->db->exec_sql("insert into 
action_gestion_related(aga_least,aga_greatest) values ($1,$2)", 
array($this->ag_id, $array[$i]));
-            }
-        }
-    }
-
-    /**
-     * export to CSV the query the p_array has
-     * @param array $p_array
-     */
-    function export_csv($p_array)
-    {
-        extract($p_array);
-
-
-        $p_search=self::create_query($this->db, $p_array);
-        $sql="
-             select ag_id,
-                       to_char(ag_timestamp,'DD.MM.YYYY') as my_date,
-                        to_char(ag_remind_date,'DD.MM.YYYY') as my_remind,
-                         to_char(coalesce((select max(agc_date) from 
action_gestion_comment as agc where agc.ag_id=ag_id),ag_timestamp),'DD.MM.YY') 
as last_comment,
-                        array_to_string((select array_agg(t1.t_tag) from 
action_tags as a1 join tags as t1 on (a1.t_id=t1.t_id) where a1.ag_id=ag.ag_id 
),',') as tags,
-                               (select ad_value from fiche_Detail where 
f_id=ag.f_id_dest and ad_id=1) as name,
-             ag_title,
-                       dt_value,
-                       ag_ref,
-                       ag_priority,
-                       ag_state,
-                         
-                       coalesce((select p_name from profile where 
p_id=ag_dest),'Aucun groupe') as dest
-             from action_gestion as ag
-             join document_type on (ag.ag_type=dt_id)
-                        join document_state on(ag.ag_state=s_id)
-             where  true  $p_search order by ag.ag_timestamp,ag.ag_id";
-        $ret=$this->db->exec_sql($sql);
-
-        if (Database::num_row($ret)==0)
-            return;
-        $this->db->query_to_csv($ret, array(
-            array("title"=>"doc id", "type"=>"string"),
-            array("title"=>"date", "type"=>"date"),
-            array("title"=>"rappel", "type"=>"date"),
-            array("title"=>"date dernier commentaire", "type"=>"date"),
-            array("title"=>"tags", "type"=>"string"),
-            array("title"=>"nom", "type"=>"string"),
-            array("title"=>"titre", "type"=>"string"),
-            array("title"=>"type document", "type"=>"string"),
-            array("title"=>"ref", "type"=>"string"),
-            array("title"=>"priorite", "type"=>"string"),
-            array("title"=>"etat", "type"=>"string"),
-            array("title"=>"profil", "type"=>"string")
-                )
-        );
-    }
-
-    static function get_all_operation($p_jr_id)
-    {
-        global $cn;
-        $array=$cn->get_array("
-                       select ag_id,ag_ref,ago_id,
-                               ag_title
-                               from action_gestion
-                               join action_gestion_operation using(ag_id)
-                               where
-                               jr_id=$1", array($p_jr_id));
-        return $array;
-    }
-
-    /**
-     * @brief get the tags of the current objet
-     * @return an array idx [ag_id,t_id,at_id,t_tag]
-     */
-    function tag_get()
-    {
-        if ($this->ag_id==0)
-            return;
-        $sql='select b.ag_id,b.t_id,b.at_id,a.t_tag'
-                .' from '
-                .' tags as a join action_tags as b on (a.t_id=b.t_id)'
-                .' where ag_id=$1 '
-                .' order by a.t_tag';
-        $array=$this->db->get_array($sql, array($this->ag_id));
-        return $array;
-    }
-
-    /**
-     * @brief show the tags of the current objet
-     * normally used by ajax. The same tag cannot be added twice
-     * 
-     */
-    function tag_add($p_t_id)
-    {
-        if ($this->ag_id==0)
-            return;
-        $count=$this->db->get_value('select count(*) from action_tags'.
-                ' where ag_id=$1 and t_id=$2', array($this->ag_id, $p_t_id));
-        if ($count>0)
-            return;
-        $sql=' insert into action_tags (ag_id,t_id) values ($1,$2)';
-        $this->db->exec_sql($sql, array($this->ag_id, $p_t_id));
-    }
-
-    /**
-     * @brief remove the tags of the current objet
-     * normally used by ajax
-     */
-    function tag_remove($p_t_id)
-    {
-        if ($this->ag_id==0)
-            return;
-        $sql=' delete from action_tags where ag_id=$1 and t_id=$2';
-        $this->db->exec_sql($sql, array($this->ag_id, $p_t_id));
-    }
-
-    /**
-     * @brief show the cell content in Display for the tags
-     * called also by ajax
-     */
-    function tag_cell()
-    {
-        global $g_user;
-        $a_tag=$this->tag_get();
-        $c=count($a_tag);
-        for ($e=0; $e<$c; $e++)
-        {
-            echo '<span style="border:1px solid black;margin-right:5px;">';
-            echo $a_tag[$e]['t_tag'];
-            if ($g_user->can_write_action($this->ag_id)==true)
-            {
-                
$js_remove=sprintf("onclick=\"action_tag_remove('%s','%s','%s')\"", 
dossier::id(), $this->ag_id, $a_tag[$e]['t_id']);
-                echo HtmlInput::anchor(SMALLX, "javascript:void(0)", 
$js_remove, ' class="smallbutton" style="padding:0px;display:inline" ');
-            }
-            echo '</span>';
-            echo '&nbsp;';
-            echo '&nbsp;';
-        }
-        $js=sprintf("onclick=\"action_tag_select('%s','%s')\"", dossier::id(), 
$this->ag_id);
-        if ($g_user->can_write_action($this->ag_id)==true)
-        {
-            echo HtmlInput::button('tag_bt', 'Ajout tag', $js, 'smallbutton');
-        }
-    }
-
-    static function action_tag_remove($cn, $p_array)
-    {
-        global $g_user;
-        $mag_id=$p_array['mag_id'];
-        $remtag=$p_array['remtag'];
-        for ($i=0; $i<count($mag_id); $i++)
-        {
-            if ($g_user->can_write_action($mag_id[$i])==false)
-                continue;
-            for ($e=0; $e<count($remtag); $e++)
-            {
-                $a=new Follow_Up($cn, $mag_id[$i]);
-                $a->tag_remove($remtag[$e]);
-            }
-        }
-    }
-
-    static function action_tag_add($cn, $p_array)
-    {
-        global $g_user;
-        $mag_id=$p_array['mag_id'];
-        $addtag=$p_array['addtag'];
-        for ($i=0; $i<count($mag_id); $i++)
-        {
-            if ($g_user->can_write_action($mag_id[$i])==false)
-                continue;
-            for ($e=0; $e<count($addtag); $e++)
-            {
-                $a=new Follow_Up($cn, $mag_id[$i]);
-                $a->tag_add($addtag[$e]);
-            }
-        }
-    }
-
-    static function action_tag_clear($cn, $p_array)
-    {
-        global $g_user;
-        $mag_id=$p_array['mag_id'];
-        for ($i=0; $i<count($mag_id); $i++)
-        {
-            if ($g_user->can_write_action($mag_id[$i])==false)
-                continue;
-            $a=new Follow_Up($cn, $mag_id[$i]);
-            $a->tag_clear();
-        }
-    }
-
-    static function action_print($cn, $p_array)
-    {
-        global $g_user;
-        $mag_id=$p_array['mag_id'];
-        for ($i=0; $i<count($mag_id); $i++)
-        {
-            if ($g_user->can_read_action($mag_id[$i])==false)
-                continue;
-            $a=new Follow_Up($cn, $mag_id[$i]);
-            $a->get();
-            echo '<div class="content">';
-            echo $a->Display("READ", false, "");
-            echo '</div>';
-            echo '<P id="breakhere"> - - </p>';
-        }
-    }
-
-    function tag_clear()
-    {
-        $this->db->exec_sql('delete from action_tags where ag_id=$1', 
array($this->ag_id));
-    }
-
-    static function action_set_state($cn, $p_array)
-    {
-
-        global $g_user;
-        $mag_id=$p_array['mag_id'];
-        $state=$p_array['ag_state'];
-        for ($i=0; $i<count($mag_id); $i++)
-        {
-            if ($g_user->can_write_action($mag_id[$i])==false)
-                continue;
-            $cn->exec_sql('update action_gestion set ag_state=$1 where 
ag_id=$2', array($state, $mag_id[$i]));
-        }
-    }
-
-    static function action_remove($cn, $p_array)
-    {
-        global $g_user;
-
-        $mag_id=$p_array['mag_id'];
-        for ($i=0; $i<count($mag_id); $i++)
-        {
-            if ($g_user->can_write_action($mag_id[$i])==false)
-                continue;
-            $cn->exec_sql('delete from action_gestion where ag_id=$1', 
array($mag_id[$i]));
-        }
-    }
-
-    /**
-     * Verify that data are correct
-     * @throws Exception
-     */
-    function verify()
-    {
-        if ($this->dt_id==-1)
-        {
-            throw new Exception(_('Type action invalide'), 10);
-        }
-        if (isDate($this->ag_timestamp)!=$this->ag_timestamp)
-            throw new Exception(_('Date invalide'), 20);
-        if (isDate($this->ag_remind_date)!=$this->ag_remind_date)
-            throw new Exception(_('Date invalide'), 30);
-        if ($this->f_id_dest==0)
-            $this->f_id_dest=null;
-    }
-
-    /**
-     *  Add another concerned (tiers, supplier...)
-     * @global type $g_user
-     * @param type $p_fiche_id
-     */
-    function insert_linked_card($p_fiche_id)
-    {
-        global $g_user;
-        if ($g_user->can_write_action($this->ag_id))
-        {
-            /**
-             * insert into action_person
-             */
-            $count=$this->db->get_value('select count(*) from action_person 
where f_id=$1 and ag_id=$2', array($p_fiche_id, $this->ag_id));
-            if ($count==0)
-            {
-                $this->db->exec_sql('insert into action_person (ag_id,f_id) 
values ($1,$2)', array($this->ag_id, $p_fiche_id));
-            }
-        }
-    }
-
-    /**
-     * Remove  another concerned (tiers, supplier...)
-     * @global type $g_user
-     * @param type $p_fiche_id
-     */
-    function remove_linked_card($p_fiche_id)
-    {
-        global $g_user;
-        if ($g_user->can_write_action($this->ag_id))
-        {
-            $this->db->exec_sql('delete from action_person where ag_id = $1 
and f_id = $2', array($this->ag_id, $p_fiche_id));
-        }
-    }
-
-    /**
-     * Display the other concerned (tiers, supplier...)
-     * @return string
-     */
-    function display_linked()
-    {
-        $a_linked=$this->db->get_array('select ap_id,f_id from action_person 
where ag_id=$1', array($this->ag_id));
-        if (count($a_linked)==0)
-            return "";
-        for ($i=0; $i<count($a_linked); $i++)
-        {
-            $fiche=new Fiche($this->db, $a_linked[$i]['f_id']);
-            $qc=$fiche->get_quick_code();
-            
$js_remove=sprintf("onclick=\"action_remove_concerned('%s','%s','%s')\"", 
dossier::id(), $a_linked[$i]['f_id'], $this->ag_id);
-            echo '<span style="border:1px solid black;margin-right:5px;">';
-            echo $qc;
-            echo HtmlInput::anchor(SMALLX, "javascript:void(0)", $js_remove, ' 
class="smallbutton" style="padding:0px;display:inline" ');
-            echo '</span>';
-            echo '&nbsp;';
-            echo '&nbsp;';
-        }
-    }
-    /**
-     * @brief display a small form to enter a new event
-     * 
-     */
-    function display_short()
-    {
-        $cn=$this->db;
-        include 'template/action_display_short.php'; 
-    }
-    /**
-     * Add an event , with the minimum of informations, 
-     * used in Dashboard and Scheduler
-     */
-    function save_short()
-    {
-        global $g_user;
-        // check if we can add
-        if ($g_user->can_add_action($this->ag_dest) == FALSE ) 
-        {
-                throw new Exception(_('SECURITE : Ajout impossible'));
-        }
-        
-            
-        
-        // Get The sequence id,
-        $seq_name="seq_doc_type_".$this->dt_id;
-        $str_file="";
-        $add_file='';
-
-        
-        $this->ag_id=$this->db->get_next_seq('action_gestion_ag_id_seq');
-
-        // Create the reference
-        $ag_ref=$this->db->get_value('select dt_prefix from document_type '
-                . 'where dt_id=$1', array($this->dt_id))
-                .'-'.$this->db->get_next_seq($seq_name);
-        
-        $this->ag_ref=$ag_ref;
-        /**
-         * If ag_ref already exist then compute a new one
-         */
-        
-        // save into the database
-        $sql="insert into action_gestion".
-                    "(ag_id,ag_timestamp,ag_type,ag_title,f_id_dest,ag_ref, "
-                . "ag_dest, ".
-                    "  ag_priority,ag_owner,ag_state,ag_remind_date) ".
-                    " values "
-                . "($1,to_date($2,'DD.MM.YYYY'),$3,$4,$5,$6,"
-                . "$7,"
-                . "$8,$9,$10,to_date($11,'DD.MM.YYYY'))";
-        
-        $this->db->exec_sql($sql, array(
-            $this->ag_id, /* 1 */
-            $this->ag_timestamp, /* 2 */
-            $this->dt_id, /* 3 */
-            $this->ag_title, /* 4 */
-            $this->f_id_dest, /* 5 */
-            $ag_ref, /* 6 */
-            $this->ag_dest, /* 7 */
-            $this->ag_priority, /* 8 */
-            $_SESSION['g_user'], /* 9 */
-            $this->ag_state, /* 10 */
-            $this->ag_remind_date /* 11 */
-           )
-        );
-
-        if (trim($this->ag_comment)!='')
-        {
-            $this->db->exec_sql("insert into action_gestion_comment 
(ag_id,tech_user,agc_comment) values ($1,$2,$3)"
-                    , array($this->ag_id, $_SESSION['g_user'], 
$this->ag_comment));
-        }
-    }
-}
diff --git a/include/class_follow_up_detail.php 
b/include/class_follow_up_detail.php
deleted file mode 100644
index 35365b9..0000000
--- a/include/class_follow_up_detail.php
+++ /dev/null
@@ -1,248 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-require_once  NOALYSS_INCLUDE.'/class_fiche.php';
-require_once  NOALYSS_INCLUDE.'/class_database.php';
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief Follow_Up details are the details for a actions
- */
-
-/*!\brief Follow_Up Details are the details for an actions, it means
- * the details of an order, delivery order, submit a quote...
- * this class is linked to the table action_detail
- * - "id"=>"ad_id", primary key
- * - "qcode"=>"f_id", quick_code
- * - "text"=>"ad_text", description lines
- * - "price_unit"=>"ad_pu", price by unit
- * - "quantity"=>"ad_quant", quantity
- * - "tva_id"=>"ad_tva_id", tva_od
- * - "tva_amount"=>"ad_tva_amount", vat amount
- * - "total"=>"ad_total_amount", total amount including vat
- * - "ag_id"=>"ag_id" => foreign key to action_gestion
- * -  db is the database connection
- */
-class Follow_Up_Detail
-{
-    private static $variable=array(
-                                 "id"=>"ad_id",
-                                 "qcode"=>"f_id",
-                                 "text"=>"ad_text",
-                                 "price_unit"=>"ad_pu",
-                                 "quantity"=>"ad_quant",
-                                 "tva_id"=>"ad_tva_id",
-                                 "tva_amount"=>"ad_tva_amount",
-                                 "total"=>"ad_total_amount",
-                                 "ag_id"=>"ag_id"
-                             );
-    function __construct ($p_cn,$p_id=0)
-    {
-        $this->db=$p_cn;
-        $this->ad_id=$p_id;
-    }
-    public function get_parameter($p_string)
-    {
-        if ( array_key_exists($p_string,self::$variable) )
-        {
-            $idx=self::$variable[$p_string];
-            return $this->$idx;
-        }
-        else
-           throw new Exception("Attribut inexistant $p_string");
-    }
-    public function set_parameter($p_string,$p_value)
-    {
-        if ( array_key_exists($p_string,self::$variable) )
-        {
-            $idx=self::$variable[$p_string];
-            $this->$idx=$p_value;
-        }
-        else
-            throw new Exception("Attribut inexistant $p_string");
-
-
-    }
-    public function get_info()
-    {
-        return var_export(self::$variable,true);
-    }
-    public function verify()
-    {
-        // Verify that the elt we want to add is correct
-        return 0;
-    }
-    public function save()
-    {
-        if (  $this->ad_id == 0 )
-            $this->insert();
-        else
-            $this->update();
-    }
-
-    public function insert()
-    {
-        if ( $this->verify() != 0 ) return;
-        $sql='INSERT INTO action_detail('.
-             ' f_id, ad_text, ad_pu, ad_quant, ad_tva_id, ad_tva_amount,'.
-             '   ad_total_amount, ag_id)'.
-             ' VALUES ($1, $2, $3, $4,$5,$6,$7,$8) returning ad_id';
-        $this->ad_id=$this->db->get_value($sql,array(
-                                              $this->f_id,
-                                              $this->ad_text,
-                                              $this->ad_pu,
-                                              $this->ad_quant,
-                                              $this->ad_tva_id,
-                                              $this->ad_tva_amount,
-                                              $this->ad_total_amount,
-                                              $this->ag_id
-                                          )
-                                         );
-
-    }
-
-    public function update()
-    {
-        if ( $this->verify() != 0 ) return;
-
-        $sql='UPDATE action_detail '.
-             ' SET f_id=$1, ad_text=$2, ad_pu=$3, ad_quant=$4, ad_tva_id=$5,'.
-             '     ad_tva_amount=$6, ad_total_amount=$7, ag_id=$8'.
-             ' WHERE ad_id=$9';
-        $this->id=$this->db->exec_sql($sql,array(
-                                          $this->f_id,
-                                          $this->ad_text,
-                                          $this->ad_pu,
-                                          $this->ad_quant,
-                                          $this->ad_tva_id,
-                                          $this->ad_tva_amount,
-                                          $this->ad_total_amount,
-                                          $this->ag_id,
-                                          $this->ad_id
-                                      )
-                                     );
-
-
-    }
-    /*!\brief retrieve all the details of an Follow_Up
-     *\return array of Action_Detail
-     *\see Follow_Up::get
-     */
-    public function load_all()
-    {
-        $sql="SELECT ad_id, f_id, ad_text, ad_pu, ad_quant, ad_tva_id, 
ad_tva_amount,
-             ad_total_amount, ag_id   FROM action_detail ".
-             " where ag_id=$1 order by ad_id";
-        $res=$this->db->get_array(
-                 $sql,
-                 array($this->ag_id)
-             );
-        if ( $this->db->count() == 0 ) return;
-        $aRet=array();
-        for($i=0;$i<count($res);$i++)
-        {
-            $a=new Follow_Up_Detail($this->db);
-            $row=$res[$i];
-            foreach ($row as $idx=>$value)
-            {
-                $a->$idx=$value;
-            }
-            $aRet[$i]=clone $a;
-        }
-        return $aRet;
-    }
-
-    public function load()
-    {
-        $sql="SELECT ad_id, f_id, ad_text, ad_pu, ad_quant, ad_tva_id, 
ad_tva_amount,
-             ad_total_amount, ag_id   FROM action_detail".
-             " where ad_id=$1";
-
-        $res=$this->db->get_array($this->db,
-                                  $sql,
-                                  array($this->ad_id)
-                                 );
-        if ( $this->db->count() == 0 ) return;
-        $row=$res[0];
-        foreach ($row as $idx=>$value)
-        {
-            $this->$idx=$value;
-        }
-
-    }
-    public function delete()
-    {
-               $sql="delete from action_detail where ad_id=$1";
-               $this->db->exec_sql($sql,array($this->ad_id));
-       }
-    /*!\brief Fill an Action_Detail Object with the data contained in an array
-    *\param $array
-     - [ad_id7] => ad_id
-     - [e_march7] =>  f_id
-     - [e_march7_label] => ad_text
-     - [e_march7_price] => ad_pu
-     - [e_quant7] => ad_quant
-     - [e_march7_tva_id] => ad_tva_id
-     - [e_march7_tva_amount] => ad_tva_amount
-     - [tvac_march7] => ad_total_amount
-     - [ag_id] => ag_id
-     *\param $idx is the idx (example 7)
-     *\note    */
-    public function from_array($array,$idx)
-    {
-        $row=$array;
-        $this->ad_id=(isset($row['ad_id'.$idx]))?$row['ad_id'.$idx]:0;
-
-        $qcode=(isset($row['e_march'.$idx]))?$row['e_march'.$idx]:"";
-        if (trim($qcode)=='')
-        {
-            $this->f_id=0;
-        }
-        else
-        {
-            $tmp=new Fiche($this->db);
-            $tmp->get_by_qcode($qcode,false);
-            $this->f_id=$tmp->id;
-        }
-        
$this->ad_text=(isset($row['e_march'.$idx.'_label']))?$row['e_march'.$idx.'_label']:"";
-        
$this->ad_pu=(isset($row['e_march'.$idx.'_price']))?$row['e_march'.$idx.'_price']:0;
-        $this->ad_quant=(isset($row['e_quant'.$idx]))?$row['e_quant'.$idx]:0;
-        
$this->ad_tva_id=(isset($row['e_march'.$idx.'_tva_id']))?$row['e_march'.$idx.'_tva_id']:0;
-        
$this->ad_tva_amount=(isset($row['e_march'.$idx.'_tva_amount']))?$row['e_march'.$idx.'_tva_amount']:0;
-        
$this->ad_total_amount=(isset($row['tvac_march'.$idx]))?$row['tvac_march'.$idx]:0;
-        $this->ag_id=(isset($array['ag_id']))?$array['ag_id']:0;
-        /* protect numeric */
-        if (trim($this->ad_pu)=="" || isNumber($this->ad_pu)==0) 
$this->ad_pu=0;
-        if (trim($this->ad_quant)=="" || isNumber($this->ad_quant)==0) 
$this->ad_quant=0;
-        if (trim($this->ad_tva_amount)==""||isNumber($this->ad_tva_amount)==0) 
$this->ad_tva_amount=0;
-        if 
(trim($this->ad_total_amount)==""||isNumber($this->ad_total_amount)==0) 
$this->ad_total_amount=0;
-        if (trim($this->ad_tva_id)=="" || isNumber($this->ad_tva_id)==0) 
$this->ad_tva_id=0;
-    }
-    /*!\brief
-     *\param
-     *\return
-     *\note
-     *\see
-     */
-    static function test_me()
-{}
-
-}
-
-/* test::test_me(); */
-
diff --git a/include/class_gestion_purchase.php 
b/include/class_gestion_purchase.php
deleted file mode 100644
index 8a1d592..0000000
--- a/include/class_gestion_purchase.php
+++ /dev/null
@@ -1,128 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
-* \brief Definition of the class gestion_purchase
- */
-
-/*! \brief this object handles the table quant_purchase
- *
- */
-require_once  NOALYSS_INCLUDE.'/class_gestion_table.php';
-
-
-class gestion_purchase extends gestion_table
-{
-    var $qp_id;                                        /*!< id */
-    var $qp_internal;                          /*!< internal code */
-    var $qp_fiche;                                     /*!< card id 
(fiche.f_id) */
-    var $qp_quantite;                          /*!< quantity */
-    var $qp_price;                                     /*!< quantity */
-    var $qp_vat;                                       /*!< vat amount */
-    var $qp_vat_code;                          /*!< vat_code */
-    var $qp_nd_amount;                         /*!< no deductible */
-    var $qp_nd_tva;                            /*!< tva not deductible */
-    var $qp_nd_tva_recup;                      /*!< tva ded via taxe */
-    var $qp_supplier;                          /*!< supplier code (f_id) */
-    var $qp_valid;
-    var $j_id;                                         /*!< jrnx.j_id
-                                                                 */
-    var $qp_dep_priv;          /*!< private purchase */
-    var $qp_vat_sided;      /* autoliquidation */
-    /*!\brief return an array of gestion_table, the object are
-     * retrieved thanks the qs_internal
-     */
-    function get_list()
-    {
-        if ($this->qp_internal=="")
-            throw  new Exception(__FILE__.__LINE__." qs_internal est vide");
-        $sql="select  qp_id,
-             qp_internal,
-             qp_fiche,
-             qp_quantite,
-             qp_price,
-             qp_vat,
-             qp_vat_code,
-             tva_rate,
-             tva_label,
-             qp_nd_amount,
-             qp_nd_tva,
-             qp_nd_tva_recup,
-             qp_supplier,
-             j_id,
-             qp_dep_priv,
-             qp_vat_sided
-             from quant_purchase left join tva_rate on (qp_vat_code=tva_id)
-             where qp_internal='".$this->qp_internal."'";
-        $ret=$this->db->exec_sql($sql);
-        // $res contains all the line
-        $res=Database::fetch_all($ret);
-
-        if ( sizeof($res)==0) return null;
-        $count=0;
-        foreach ($res as $row)
-        {
-            $t_gestion_purchase=new gestion_purchase($this->db);
-            foreach ($row as $idx=>$value)
-            $t_gestion_purchase->$idx=$value;
-            $array[$count]=clone $t_gestion_purchase;
-            $count++;
-        }
-        return $array;
-    }
-    function search_by_jid($p_jid)
-    {
-        $res=$this->db->exec_sql("select qp_id from quant_purchase where 
j_id=".$p_jid);
-
-        if ( Database::num_row($res) == 1)
-            $this->qp_id=Database::fetch_result($res,0,0);
-        else
-            $this->qp_id=0;
-    }
-    function load()
-    {
-        $sql="select  qp_id,
-             qp_internal,
-             qp_fiche,
-             qp_quantite,
-             qp_price,
-             qp_vat,
-             qp_vat_code,
-             qp_nd_amount,
-             qp_nd_tva,
-             qp_nd_tva_recup,
-             qp_supplier,
-             j_id,
-             qp_dep_priv,
-             qp_vat_sided
-             from quant_purchase
-             where qp_id=".$this->qp_id;
-        $ret=$this->db->exec_sql($sql);
-        // $res contains all the line
-        $res=Database::fetch_all($ret);
-
-        if ( empty($res) ) return null;
-        foreach ($res[0] as $idx=>$value)
-        $this->$idx=$value;
-
-    }
-
-}
diff --git a/include/class_gestion_sold.php b/include/class_gestion_sold.php
deleted file mode 100644
index 1b0036f..0000000
--- a/include/class_gestion_sold.php
+++ /dev/null
@@ -1,115 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief definition of the class gestion_sold
- */
-
-/*! \brief this object handles the table quant_sold
- *
- */
-
-require_once  NOALYSS_INCLUDE.'/class_gestion_table.php';
-
-
-class gestion_sold extends gestion_table
-{
-    var $qs_id;                                        /*!< $qs_id primary key 
*/
-    var $qs_internal;                          /*!< qs_internal */
-    var $qs_fiche;                             /*!< f_id code  */
-    var $qs_quantite;                          /*!< quantity of the card */
-    var $qs_price;                             /*!< price */
-    var $qs_vat;                                       /*!< vat_amount */
-    var $qs_vat_code;                          /*!< vat_code */
-    var $qs_client;                            /*!< f_id of the customer */
-    var $qs_valid;                             /*!< will not be used */
-    var $j_id;                                 /*!< jrnx.j_id */
-    var $qs_vat_sided;
-    /*!\brief return an array of gestion_table, the object are
-     * retrieved thanks the qs_internal
-     */
-    function get_list()
-    {
-        if ($this->qs_internal=="")
-            throw  new Exception(__FILE__.__LINE__." qs_internal est vide");
-        $sql="select  qs_id,
-             qs_internal,
-             qs_fiche,
-             qs_quantite,
-             qs_price,
-             qs_vat,
-             tva_label,
-             tva_rate,
-             qs_vat_code,
-             qs_client,
-             j_id,
-             qs_vat_sided
-             from quant_sold left join tva_rate on (qs_vat_code=tva_id)
-             where qs_internal='".$this->qs_internal."'";
-        $ret=$this->db->exec_sql($sql);
-        // $res contains all the line
-        $res=Database::fetch_all($ret);
-
-        if ( sizeof($res)==0) return null;
-        $count=0;
-
-        foreach ($res as $row)
-        {
-            $t_gestion_sold=new gestion_sold($this->db);
-            foreach ($row as $idx=>$value)
-            $t_gestion_sold->$idx=$value;
-            $array[$count]=clone $t_gestion_sold;
-            $count++;
-        }
-        return $array;
-    }
-     function search_by_jid($p_jid)
-    {
-        $res=$this->db->exec_sql("select qs_id from quant_sold where 
j_id=".$p_jid);
-
-        if ( Database::num_row($res) == 1)
-            $this->qs_id=Database::fetch_result($res,0,0);
-        else
-            $this->qs_id=0;
-    }
-    function load()
-    {
-       $sql=" select  qs_id,
-             qs_internal,
-             qs_fiche,
-             qs_quantite,
-             qs_price,
-             qs_vat,
-             qs_vat_code,
-             qs_client,
-             j_id,
-             qs_vat_sided
-             from quant_sold 
-             where qs_id=$1";
-       $ret=$this->db->exec_sql($sql,array($this->qs_id));
-        // $res contains all the line
-        $res=Database::fetch_all($ret);
-
-        if ( empty($res) ) return null;
-        foreach ($res[0] as $idx=>$value)
-        $this->$idx=$value;
-    }
-}
diff --git a/include/class_html_input.php b/include/class_html_input.php
deleted file mode 100755
index 98ded82..0000000
--- a/include/class_html_input.php
+++ /dev/null
@@ -1,929 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*! \file
- * \brief This class is used to create all the HTML INPUT TYPE
- */
-
-/*!
- * \brief class widget This class is used to create all the HTML INPUT TYPE
- *        and some specials which works with javascript like
- *        js_search.
- *
- * special value
- *    js_search and js_search_only :you need to add a span widget the name
- *    of the js_* widget + '_label' , the member extra contains cred,deb to
- *    filter the search of cred of deb of a jrn or contains a string with
- *    a list of frd_id.
- *    Possible type
- *    $type
- *      - TEXT
- *      - HIDDEN
- *      - BUTTON in this->js you have the javascript code
- *      - SELECT the options are passed via this->value, this array is
- *        build thanks the make_array function, each array (of the
- *        array) aka row must contains a field value and a field label
- *      - PASSWORD
- *      - CHECKBOX
- *      - RADIO
- *      - TEXTAREA
- *      - RICHTEXT
- *      - FILE
- *      - SPAN
- */
-class HtmlInput
-{
-
-    var $type;                      /*!<  $type type of the widget */
-    var $name;                      /*!<  $name field NAME of the INPUT */
-    var $value;                     /*!<  $value what the INPUT contains */
-    var $readOnly;                  /*!<  $readonly true : we cannot change 
value */
-    var $size;                      /*!<  $size size of the input */
-    var $selected;                  /*!<  $selected for SELECT RADIO and 
CHECKBOX the selected value */
-    var $table;                     /*!<  $table =1 add the table tag */
-    var $label;                     /*!<  $label the question before the input 
*/
-    var $disabled;                  /*!<  $disabled poss. value == true or 
nothing, to disable INPUT*/
-    var $extra;                     /*!<  $extra different usage, it depends 
of the $type */
-    var $extra2;                    /*!<  $extra2 different usage,
-                                                                               
it depends of the $type */
-    var $javascript;                              /*!< $javascript  is the 
javascript to add to the widget */
-    var $ctrl;                                         /*!<$ctrl is the 
control to update (see js_search_card_control) */
-
-    var $tabindex;
-    function __construct($p_name="",$p_value="",$p_id="")
-    {
-        $this->name=$p_name;
-        $this->readOnly=false;
-        $this->size=20;
-        $this->width=50;
-        $this->heigh=20;
-        $this->value=$p_value;
-        $this->selected="";
-        $this->table=0;
-        $this->disabled=false;
-        $this->javascript="";
-        $this->extra2="all";
-        $this->attribute=array();
-        $this->id=$p_id;
-
-    }
-    function setReadOnly($p_read)
-    {
-        $this->readOnly=$p_read;
-    }
-    /*!\brief set the extra javascript property for the INPUT field
-     *\param $p_name name of the parameter
-     *\param $p_value default value of this parameter
-     */
-    public function set_attribute($p_name,$p_value)
-    {
-        $this->attribute[]=array($p_name,$p_value);
-        $this->$p_name=$p_value;
-    }
-    /**
-     address@hidden you can add attribute to this in javascript
-     * this function is a wrapper and create a script (in js) to modify
-     * "this" (in javascript) with the value of obj->attribute from PHP
-     address@hidden return string with the javascript code
-     */
-    public function get_js_attr()
-    {
-        require_once NOALYSS_INCLUDE.'/function_javascript.php';
-        $attr="";
-        if ( count($this->attribute) == 0) return "";
-
-        /* Add properties at the widget */
-        for ($i=0;$i< count($this->attribute);$i++)
-        {
-            list($name,$value)=$this->attribute[$i];
-            $tmp1=sprintf("$('%s').%s='%s';",
-                          $this->name,
-                          $name,
-                          $value);
-            $attr.=$tmp1;
-        }
-        $attr=create_script($attr);
-        return $attr;
-    }
-    /**
-     * Make a JSON object, this method create a javascript object
-     * with the attribute set, it returns a javascript string with the object
-     * @param $p_name : name of the object, can be null. If the name is not 
null, return
-     * $p_name={} otherwise only the object {}
-     * @return javascript string with the object
-     * @note: there is not check on the key->value, so you could need to escape
-     * special char as quote, single-quote...
-     * @code
-    $a=new IButton()
-    $a->set_attribute('prop','1');
-    $a->set_attribute('prop','2');
-    $a->set_attribute('prop','3');
-    $string = $a->make_object('property');
-    echo $string => property={'prop':'1','prop2':'2','prop3':'3'};
-    $string = $a->make_object(null);
-    echo $string => {'prop':'1','prop2':'2','prop3':'3'};
-    @endcode
-    */
-    public function make_object($p_name=null)
-    {
-        $name=($p_name != null)?$p_name.'=':'';
-        if ( count($this->attribute) == 0) return $name."{}";
-        $ret=$name."{";
-        $and='';
-
-        for ($i=0;$i< count($this->attribute);$i++)
-        {
-            list($name,$value)=$this->attribute[$i];
-            $tmp1=sprintf($and."'%s':'%s'",
-                          $name,
-                          $value);
-            $ret.=$tmp1;
-            $and=',';
-        }
-
-        $ret.='}';
-        return $ret;
-    }
-    //#####################################################################
-    /* Debug
-     */
-    function debug()
-    {
-        echo "Type ".$this->type."<br>";
-        echo "name ".$this->name."<br>";
-        echo "value". $this->value."<br>";
-        $readonly=($this->readonly==false)?"false":"true";
-        echo "read only".$readonly."<br>";
-    }
-    static   function submit 
($p_name,$p_value,$p_javascript="",$p_class="smallbutton")
-    {
-
-        return '<INPUT TYPE="SUBMIT" class="'.$p_class.'" NAME="'.$p_name.'" 
ID="'.$p_name.'_submit_id"  VALUE="'.$p_value.'" '.$p_javascript.'>';
-    }
-    static   function button 
($p_name,$p_value,$p_javascript="",$p_class="smallbutton")
-    {
-
-        return '<INPUT TYPE="button" class="'.$p_class.'" NAME="'.$p_name.'" 
ID="'.$p_name.'" VALUE="'.$p_value.'" '.$p_javascript.'>';
-    }
-
-    static function reset ($p_value)
-    {
-        return '<INPUT TYPE="RESET" class="smallbutton" VALUE="'.$p_value.'">';
-    }
-    static function hidden($p_name,$p_value,$p_id="")
-    {
-               if ($p_id=="") $p_id=$p_name;
-        return '<INPUT TYPE="hidden" id="'.$p_id.'" NAME="'.$p_name.'" 
VALUE="'.$p_value.'">';
-    }
-
-    static function extension()
-    {
-        return self::hidden('plugin_code',$_REQUEST['plugin_code']);
-    }
-
-    /*!\brief create a button with a ref
-     *\param $p_label the text
-     *\param $p_value the location of the window,
-     *\param $p_name the id of the span
-     *\param $p_javascript javascript for this button
-     *\return string with htmlcode
-     */
-    static function 
button_anchor($p_label,$p_value,$p_name="",$p_javascript="",$p_class="button")
-    {
-        $r=sprintf('<span id="%s" > <A class="'.$p_class.'" 
style="display:inline;"  href="%s" %s >%s</A></span>',
-                   $p_name,
-                   $p_value,
-                   $p_javascript,
-                   $p_label);
-        return $r;
-    }
-    static function infobulle($p_comment)
-    {
-        $r='<A HREF="#" tabindex="-1" 
style="display:inline;color:black;background-color:yellow;padding-left:4px;width:2em;padding-right:4px;text-decoration:none;"
 onmouseover="showBulle(\''.$p_comment.'\')"  
onclick="showBulle(\''.$p_comment.'\')" onmouseout="hideBulle(0)">?</A>';
-        return $r;
-    }
-    static function warnbulle($p_comment)
-    {
-        $r='<A HREF="#" tabindex="-1" 
style="display:inline;color:red;background-color:white;padding-left:4px;padding-right:4px;text-decoration:none;"
 onmouseover="showBulle(\''.$p_comment.'\')"  
onclick="showBulle(\''.$p_comment.'\')" onmouseout="hideBulle(0)">&Delta;</A>';
-        return $r;
-    }
-    /**
-     * return a string containing the html code for calling the modifyOperation
-     */
-    static function detail_op($p_jr_id,$p_mesg)
-    {
-        return sprintf('<A class="detail" 
style="text-decoration:underline;display:inline" 
HREF="javascript:modifyOperation(%d,%d)">%s</A>',
-                       $p_jr_id,dossier::id(),$p_mesg);
-    }
-       /**
-        * @brief return an anchor to view the detail of an action
-        * @param $ag_id
-        * @param $p_mesg
-        * @param $p_modify let you modify an operation
-        *
-        */
-    static function detail_action($ag_id,$p_mesg,$p_modify=1)
-    {
-        return sprintf('<A class="detail" 
style="text-decoration:underline;display:inline" 
HREF="javascript:view_action(%d,%d,%d)">%s</A>',
-                       $ag_id,dossier::id(),$p_modify,$p_mesg);
-    }
-    /**
-     * return a string containing the html code for calling the 
modifyModeleDocument
-     */
-    static function detail_modele_document($p_id,$p_mesg)
-    {
-        return sprintf('<A class="detail" style="text-decoration:underline" 
HREF="javascript:modifyModeleDocument(%d,%d)">%s</A>',
-                       $p_id,dossier::id(),$p_mesg);
-    }
-
-    /**
-     * return a string containing the html code for calling the removeStock
-     */
-    static function remove_stock($p_id,$p_mesg)
-    {
-        return sprintf('<A class="detail" style="text-decoration:underline" 
HREF="javascript:removeStock(%d,%d)">%s</A>',
-                       $p_id,dossier::id(),$p_mesg);
-    }
-
-    /**
-     * display a div with the history of the card
-     */
-    static function history_card($f_id,$p_mesg,$p_style="")
-    {
-        $view_history= sprintf('<A class="detail"  
style="text-decoration:underline;%s" 
HREF="javascript:view_history_card(\'%s\',\'%s\')" >%s</A>',
-                               $p_style,$f_id, dossier::id(), $p_mesg);
-        return $view_history;
-    }
-    /**
-     * display a div with the history of the card
-     */
-    static function history_card_button($f_id,$p_mesg)
-    {
-      static $e=0;
-      $e++;
-      $js= sprintf('onclick="view_history_card(\'%s\',\'%s\')"',
-                               $f_id, dossier::id());
-      $view_history=HtmlInput::button("hcb"+$e,$p_mesg,$js);
-      return $view_history;
-    }
-
-    /**
-     * display a div with the history of the account
-     */
-    static function history_account($p_account,$p_mesg,$p_style="")
-    {
-        $view_history= sprintf('<A class="detail" 
style="text-decoration:underline;%s" 
HREF="javascript:view_history_account(\'%s\',\'%s\')" >%s</A>',
-                               $p_style,$p_account, dossier::id(), $p_mesg);
-        return $view_history;
-    }
-
-    /**
-     * return the html code to create an hidden div and a button
-     * to show this DIV. This contains all the available ledgers
-     * for the user in READ or RW
-     address@hidden $selected is an array of checkbox
-     address@hidden $div div suffix
-     address@hidden the choosen ledger are stored in the array r_jrn (_GET)
-     */
-    static function select_ledger($p_type,$p_selected,$div='')
-    {
-        global $g_user;
-       $r = '';
-       /* security : filter ledger on user */
-       $p_array = $g_user->get_ledger($p_type, 3);
-        
-        ob_start();
-        
-
-        /* create a hidden div for the ledger */
-        echo '<div id="div_jrn'.$div.'" >';
-        echo HtmlInput::title_box(_("Journaux"), $div."jrn_search");
-        echo '<div style="padding:5px">';
-        echo '<form method="GET" id="'.$div.'search_frm" onsubmit="return 
hide_ledger_choice(\''.$div.'search_frm\')">';
-        echo HtmlInput::hidden('nb_jrn', count($p_array));
-        echo _('Filtre ').HtmlInput::filter_table($div.'tb_jrn', '0,1,2', 2);
-        echo '<table class="result" id="'.$div.'tb_jrn">';
-        echo '<tr>';
-        echo th(_('Nom'));
-        echo th(_('Description'));
-        echo th(_('Type'));
-        echo '</tr>';
-        echo '<tr>';
-        echo '<td>';
-        echo HtmlInput::button('sel_'.$div,_('Inverser la sélection'),' 
onclick = "toggle_checkbox(\''."{$div}search_frm".'\')"');
-        echo '</td>';
-        echo '</tr>';
-        for ($e=0;$e<count($p_array);$e++)
-        {
-            $row=$p_array[$e];
-            $r=new ICheckBox($div.'r_jrn'.$e,$row['jrn_def_id']);
-            $idx=$row['jrn_def_id'];
-            if ( $p_selected != null &&  
in_array($row['jrn_def_id'],$p_selected))
-            {
-                $r->selected=true;
-            }
-            $class=($e%2==0)?' class="even" ':' class="odd" ';
-            echo '<tr '.$class.'>';
-            echo '<td style="white-space: 
nowrap">'.$r->input().$row['jrn_def_name'].'</td>';
-            echo '<td >'.$row['jrn_def_description'].'</td>';
-            echo '<td >'.$row['jrn_def_type'].'</td>';
-            echo '</tr>';
-
-        }
-        echo '</table>';
-        echo HtmlInput::hidden('div',$div);
-        echo HtmlInput::submit('save',_('Valider'));
-        echo HtmlInput::button_close($div."jrn_search");
-        echo '</form>';
-        echo '</div>';
-        echo '</div>';
-  
-        $ret=ob_get_contents();
-        ob_end_clean();
-        return $ret;
-    }
-    /**
-     *create a hidden plus button to select the cat of ledger
-     address@hidden the selected value is stored in the array p_cat
-     */
-    static function select_cat($array_cat)
-    {
-        ob_start();
-        $ledger=new ISmallButton('l');
-        $ledger->label=_("Catégorie");
-        $ledger->javascript=" show_cat_choice()";
-        echo $ledger->input();
-
-        /* create a hidden div for the ledger */
-        echo '<div id="div_cat">';
-        echo '<h2 class="info">'._('Choix des categories').'</h2>';
-        $selected=(isset($_GET['r_cat']))?$_GET['r_cat']:null;
-
-        echo '<ul>';
-        for ($e=0;$e<count($array_cat);$e++)
-        {
-            $row=$array_cat[$e];
-            $re=new ICheckBox('r_cat['.$e.']',$row['cat']);
-
-            if ( $selected != null && isset($selected[$e]))
-            {
-                $re->selected=true;
-            }
-            echo '<li style="list-style-type: 
none;">'.$re->input().$row['name'].'('.$row['cat'].')</li>';
-
-        }
-        echo '</ul>';
-        $hide=new IButton('l2');
-        $hide->label=_("Valider");
-        $hide->javascript=" hide_cat_choice() ";
-        echo $hide->input();
-
-        echo '</div>';
-        $r=ob_get_contents();
-        ob_end_clean();
-        return $r;
-    }
-    static function display_periode($p_id)
-    {
-      $r=sprintf('<a href="javascript:void(0)" 
onclick="display_periode(%d,%d)">Modifier</a>',
-                dossier::id(),
-                $p_id);
-      return $r;
-    }
-    /**
-     *close button for the HTML popup
-     address@hidden add_div modify_operation
-     address@hidden $div_name is the name of the div to remove
-     */
-    static function button_close($div_name)
-    {
-      $a=new IButton('Fermer');
-      $a->label=_("Fermer");
-      $a->javascript="removeDiv('".$div_name."')";
-      $html=$a->input();
-
-      return $html;
-
-    }
-    /**
-     * Return a html string with an anchor which close the inside popup. 
(top-right corner)
-     address@hidden name of the DIV to close
-     */
-    static function anchor_close($div,$p_js="")
-    {
-       $r='';
-       $r.='<div style="position:absolute;right:2px;margin:2px;padding:0px;">';
-       $r.= '<A id="close_div" class="input_text" 
onclick="removeDiv(\''.$div.'\');'.$p_js.'">&#10761;</A>';
-       $r.='</div>';
-       return $r;
-    }
-    /**
-     * button Html
-     address@hidden $action action action to perform (message) without onclick
-     address@hidden $javascript javascript to execute
-     */
-    static function 
button_action($action,$javascript,$id="xx",$p_class="button")
-    {
-        if ($id=="xx"){
-            $id=HtmlInput::generate_id("xx");
-        }
-               $r="";
-               $r.='<input type="button" id="'.$id.'" class="'.$p_class.'" 
onclick="'.$javascript.'" value="'.h($action).'">';
-               return $r;
-
-    }
-    /**
-     * button Html image
-     address@hidden $javascript javascript to execute
-     * @param $id id of the button
-     * @param  $class class of the button
-     * @param $p_image image
-     */
-    static function 
button_image($javascript,$id="xx",$p_class='class="button"',$p_image="")
-    {
-        if ($id=="xx"){
-            $id=HtmlInput::generate_id("xx");
-        }
-        $r="";
-        $r.='<image id="'.$id.'" '.$p_class.' onclick="'.$javascript.'"  
src="'.$p_image.'" />';
-        return $r;
-
-    }
-    /**
-     * Return a html string with an anchor to hide a div, put it in the right 
corner
-     address@hidden $action action action to perform (message)
-     address@hidden $javascript javascript
-     address@hidden not protected against html
-     address@hidden Acc_Ledger::display_search_form
-     */
-    static function anchor_hide($action,$javascript)
-    {
-       $r='';
-       $r.='<div style="position:absolute;margin:2px;right:2px">';
-       $r.= '<span id="close_div" class="input_text"  
onclick="'.$javascript.'">'.$action.'</span>';
-       $r.='</div>';
-       return $r;
-    }
-
-    /**
-     * Javascript to print the current window
-     */
-    static function print_window()
-    {
-       $r='';
-       $r.=HtmlInput::button('print','Imprimer','onclick="window.print();"');
-       return $r;
-    }
-    /**
-     *show the detail of a card
-     */
-    static function 
card_detail($p_qcode,$pname='',$p_style="",$p_nohistory=false)
-    {
-      //if ($pname=='')$pname=$p_qcode;
-      $r="";
-      $histo=($p_nohistory==true)?' ,nohistory:1':"";
-      $r.=sprintf('<a href="javascript:void(0)" %s 
onclick="fill_ipopcard({qcode:\'%s\' %s})">%s [%s]</a>',
-                 $p_style,$p_qcode,$histo,$pname,$p_qcode);
-      return $r;
-    }
-    /**
-     *transform request data  to hidden
-     address@hidden $array is an of indices
-     address@hidden $request name of the superglobal $_POST $_GET 
$_REQUEST(default)
-     address@hidden html string with the hidden data
-     */
-    static function array_to_hidden($array,$global_array )
-    {
-
-      $r="";
-
-      if ( count($global_array )==0) return '';
-      foreach ($array  as $a)
-       {
-         if (isset($global_array [$a])) 
-          if (is_array($global_array[$a]) == false ) {
-                $r.=HtmlInput::hidden($a,$global_array [$a]);
-              } else {
-                  if (count($global_array[$a]) > 0)
-                  {
-                      foreach ($global_array[$a] as $value)
-                      {
-                          $r.=HtmlInput::hidden($a."[]",$value);
-                    }
-                  }
-              }
-       }
-
-      return $r;
-    }
-    /**
-     *transform $_GET   data  to hidden
-     address@hidden $array is an of indices
-     address@hidden HtmlInput::request_to_hidden
-     address@hidden html string with the hidden data
-     */
-    static function get_to_hidden($array)
-    {
-      $r=self::array_to_hidden($array,$_GET );
-      return $r;
-    }
-
-    /**
-     *transform $_POST  data  to hidden
-     address@hidden $array is an of indices
-     address@hidden HtmlInput::request_to_hidden
-     address@hidden html string with the hidden data
-     */
-    static function post_to_hidden($array)
-    {
-      $r=self::array_to_hidden($array,$_POST );
-      return $r;
-    }
-
-    /**
-     *transform $_REQUEST   data  to hidden
-     address@hidden $array is an of indices
-     address@hidden HtmlInput::request_to_hidden
-     address@hidden html string with the hidden data
-     */
-    static function request_to_hidden($array)
-    {
-      $r=self::array_to_hidden($array,$_REQUEST  );
-      return $r;
-    }
-
-    /**
-     *transform request data  to string
-     address@hidden $array is an of indices
-     address@hidden $request name of the superglobal $_POST $_GET 
$_REQUEST(default)
-     address@hidden html string with the string data
-     */
-    static function array_to_string($array,$global_array,$start="?" )
-    {
-
-      $r=$start;
-
-      if ( count($global_array )==0) return '';
-      $and="";
-      foreach ($array  as $a)
-       {
-         if (isset($global_array [$a]))
-          {
-              if (is_array($global_array[$a]) == false ) {
-                $r.=$and."$a=".$global_array [$a];
-              } else {
-                  for ($i=0;$i<count($global_array[$a]);$i++) {
-                      $r.=$and."$a"."[]=".$global_array[$a][$i];
-                      $and="&amp;";
-                  }
-              }
-          }
-         $and="&amp;";
-       }
-
-      return $r;
-    }
-    /**
-     *transform $_GET   data  to string
-     address@hidden $array is an of indices
-     address@hidden HtmlInput::request_to_string
-     address@hidden html string with the string data
-     */
-    static function get_to_string($array,$start="?")
-    {
-      $r=self::array_to_string($array,$_GET ,$start);
-      return $r;
-    }
-
-    /**
-     *transform $_POST  data  to string
-     address@hidden $array is an of indices
-     address@hidden HtmlInput::request_to_string
-     address@hidden html string with the string data
-     */
-    static function post_to_string($array)
-    {
-      $r=self::array_to_string($array,$_POST );
-      return $r;
-    }
-
-    /**
-     *transform $_REQUEST   data  to string
-     address@hidden $array is an of indices
-     address@hidden HtmlInput::request_to_string
-     address@hidden html string with the string data
-     */
-    static function request_to_string($array,$start="?")
-    {
-      $r=self::array_to_string($array,$_REQUEST,$start  );
-      return $r;
-    }
-
-    /**
-     * generate an unique id for a widget,
-     address@hidden $p_prefix prefix
-     address@hidden HtmlInput::IDate
-     address@hidden string with a unique id
-     */
-    static function generate_id($p_prefix)
-    {
-      $r=sprintf('%s_%d',$p_prefix,mt_rand(0,999999));
-      return $r;
-    }
-    /**
-     * return default if the value if the value doesn't exist in the array
-     address@hidden $ind the index to check
-     address@hidden $default the value to return
-     address@hidden $array the array
-     */
-    static function default_value($ind,$default,$array)
-    {
-      if ( ! isset($array[$ind]))
-       {
-         return $default;
-       }
-      return $array[$ind];
-    }
-       /**
-        *  return default if the value if the value doesn't exist in $_GET
-        * @param  $ind name of the variable
-        * @param type $default
-        * @return type
-        */
-       static function default_value_get($ind, $default)
-       {
-               if (!isset($_GET[$ind]))
-               {
-                       return $default;
-               }
-               return $_GET[$ind];
-       }
-       /**
-        *  return default if the value if the value doesn't exist in $_POST
-        * @param  $ind name of the variable
-        * @param type $default
-        * @return type
-        */
-       static function default_value_post($ind, $default)
-       {
-               if (!isset($_POST[$ind]))
-               {
-                       return $default;
-               }
-               return $_POST[$ind];
-       }
-       /**
-        *  return default if the value if the value doesn't exist in $_REQUEST
-        * @param  $ind name of the variable
-        * @param type $default
-        * @return type
-        */
-       static function default_value_request($ind, $default)
-       {
-               if (!isset($_REQUEST[$ind]))
-               {
-                       return $default;
-               }
-               return $_REQUEST[$ind];
-       }
-        /**
-         * Title for boxes, you can customize the symbol thanks symbol with
-         * the mode "custom"
-         * @param type $name Title
-         * @param type $div element id, except for mode none or custom
-         * @param type $mod hide , close , zoom , custom or none, with
-         * custom , the $name contains all the code
-         * @param type $p_js contains the javascript with "custom" contains 
button + code 
-         * @return type
-         */
-       static function title_box($name,$div,$mod="close",$p_js="")
-       {
-               if ($mod=='close')      
{$r=HtmlInput::anchor_close($div,$p_js); }else
-               if ($mod=='hide')       
{$r=HtmlInput::anchor_hide("&#10761;","$('$div').hide();$p_js");} else
-               if ($mod=='zoom')       {$r='<span  id="span_'.$div.'" 
style="float:right;margin-right:5px">'.HtmlInput::anchor("&#11036;","",$p_js,' 
name="small'.$div.'" id="close_div" class="input_text"  ').'</span>'; } else
-                if ( $mod == 'custom')  {$r='<span  id="span_'.$div.'" 
style="float:right;margin-right:5px">'.$p_js."</span>";} else
-                if ( $mod == 'none')    {$r="" ; }
-                    else 
-                            die (__FILE__.":".__LINE__._('Paramètre invaide'));
-               $r.=h2($name,' class="title" ');
-               return $r;
-       }
-        /**
-         * @brief let you create only a link and set an id on it.
-         * After create a javascript for getting the event 
-         * onclick = function() {...}
-         * @param type $p_text Text to display
-         * @param type $p_id id of the link
-         * @param type $type title of the link
-         * @code
-         * echo HtmlInput::anchor_empty('go','go_id');
-         * <script>$("go_id").onclick=function (e) { ...}</script>
-         * @endcode
-         */
-        static  function anchor_empty($p_text,$p_id,$p_title="")
-        {
-            $p_url="javascript:void(0)";
-            $str=sprintf('<a id="%s" href="javascript:void(0)" class="line" 
title="%s">%s</a>',
-            $p_id,$p_title,$p_text);
-            return $str;
-        }
-        /**
-         *Return a simple anchor with a url or a javascript
-         * if $p_js is not null then p_url will be javascript:void(0)
-         * we don't add the event onclick. You must give p_url OR p_js
-         * default CSS class=line
-         * @param string $p_text text of the anchor
-         * @param string $p_url  url
-         * @param string $p_js javascript
-         * @param string $p_style is the visuable effect (class, style...)
-         */
-      static function anchor($p_text,$p_url="",$p_js="",$p_style=' 
class="line" ')
-      {
-          if ($p_js != "")
-          {
-              $p_url="javascript:void(0)";
-          }
-
-
-          $str=sprintf('<a %s href="%s" %s>%s</a>',
-                  $p_style,$p_url,$p_js,$p_text);
-          return $str;
-      }
-      /**
-       *Create an ISelect object containing the available repository for 
reading
-       * or writing
-       * @global $g_user
-       * @param $p_cn db object
-       * @param $p_name name of the select
-       * @param $p_mode is 'R' for reading, 'W' for writinh
-       * @return ISelect
-       * @throws Exception if p_mode is wrong
-       */
-      static function select_stock( $p_cn, $p_name,$p_mode)
-      {
-          global $g_user;
-          if ( ! in_array($p_mode,array('R','W') ) )
-          {
-              throw  new Exception  (__FILE__.":".__LINE__." $p_mode 
invalide");
-          }
-          $profile=$g_user->get_profile();
-          $sel=new ISelect($p_name);
-
-                 if ($p_mode == 'W')
-                       {
-                         $sel->value=$p_cn->make_array("
-                select r_id,r_name
-                                 from stock_repository join 
profile_sec_repository using (r_id)
-                where
-                 ur_right='W' and  p_id=".sql_string($profile).
-                " order by 2" );
-                     return $sel;
-                       }
-                         if ($p_mode == 'R')
-                       {
-                         $sel->value=$p_cn->make_array("
-                select r_id,r_name
-                                 from stock_repository join 
profile_sec_repository using (r_id)
-                where
-                  p_id=".sql_string($profile).
-                " order by 2" );
-                     return $sel;
-                       }
-       }
-       static function filter_table($p_table_id,$p_col,$start_row)
-       {
-               $r= "
-                       <span>
-                       <input id=\"lk_".$p_table_id."\" autocomplete=\"off\" 
class=\"input_text\" name=\"filter\" onkeyup=\"filter_table(this, 
'$p_table_id','$p_col',$start_row )\" type=\"text\">
-                       <input type=\"button\" class=\"smallbutton\" 
onclick=\"$('lk_".$p_table_id."').value='';filter_table($('lk_".$p_table_id."'),
 '$p_table_id','$p_col',$start_row );\" value=\"X\">
-                       </span>
-                       ";
-                $r.=' <span class="notice" id="info_'.$p_table_id.'"></span>';
-               return $r;
-       }
-
-       static function show_reconcile($p_div, $let,$span="")
-       {
-               $r = '<A  style="color:red;text-decoration:underline" 
href="javascript:void(0)" onclick="show_reconcile(\'' . $p_div . '\',\'' . $let 
. '\')">' . $let.$span . '</A>';
-               return $r;
-       }
-        /**
-         * Zoom the calendar
-         * @param type $obj objet json for the javascript
-         * @see calendar_zoom in scripts.js 
-         */
-        static function calendar_zoom($obj)
-        {
-            $button=new ISmallButton("calendar", _("Calendrier"));
-            $button->javascript="calendar_zoom($obj)";
-            return $button->input();
-        }
-        /**
-         * 
-         * @param type $p_array indice
-         *   - div div name
-         *   - type ALL, VEN, ACH or ODS
-         *   - all_type 1 yes 0 no
-         * 
-         */
-        static function button_choice_ledger($p_array)
-        {
-            extract ($p_array);
-            $bledger_param = json_encode(array(
-                'dossier' => $_REQUEST['gDossier'],
-                'type' => $type,
-                'all_type' => $all_type,
-                'div' => $div,
-                'class'=>'inner_box'
-            ));
-
-            $bledger_param = str_replace('"', "'", $bledger_param);
-            $bledger = new ISmallButton('l');
-            $bledger->label = _("choix des journaux");
-            $bledger->javascript = " show_ledger_choice($bledger_param)";
-            $f_ledger = $bledger->input();
-            $hid_jrn = "";
-            if (isset($_REQUEST[$div . 'nb_jrn']))
-            {
-                for ($i = 0; $i < $_REQUEST[$div . 'nb_jrn']; $i++)
-                {
-                    if (isset($_REQUEST[$div . "r_jrn"][$i]))
-                        $hid_jrn.=HtmlInput::hidden($div . 'r_jrn[' . $i . 
']', $_REQUEST[$div . "r_jrn"][$i]);
-                }
-                $hid_jrn.=HtmlInput::hidden($div . 'nb_jrn', $_REQUEST[$div . 
'nb_jrn']);
-            } else
-            {
-                $hid_jrn = HtmlInput::hidden($div . 'nb_jrn', 0);
-            }
-            echo $f_ledger;
-            echo '<span id="ledger_id' . $div . '">';
-            echo $hid_jrn;
-            echo '</span>';
-        }
-        /**
-         * Returns HTML code for displaying a icon with a link to a receipt 
document from
-         * the ledger 
-         * @global $cn database connx
-         * @param $p_jr_id jrn.jr_id
-         * @return nothing or HTML Code for a link to the document
-         */
-        static function show_receipt_document($p_jr_id)
-        {
-            global $cn;
-            
-            $array=$cn->get_array('select jr_def_id,jr_pj_name,jr_grpt_id from 
jrn where jr_id=$1',array($p_jr_id));
-            if (count($array)==0) return "";
-            if ($array[0]['jr_pj_name'] == "") return "";
-            $str_dossier=Dossier::get();
-            $image='<IMG style="width:24px;height:24px;border:0px" 
SRC="image/documents.png" title="' . $array[0]['jr_pj_name'] . '" >';
-            $r=sprintf('<A class="detail" 
HREF="show_pj.php?jrn=%s&jr_grpt_id=%s&%s">%s</A>', $array[0]['jr_def_id'], 
$array[0]['jr_grpt_id'], $str_dossier, $image);
-            return $r;
-            
-        }
-        /**
-         * 
-         * @param type $p_operation_jr_id action_gestion_operation.ago_id
-         */
-        static function  button_action_remove_operation($p_operation) 
-        {
-            
$rmOperation=sprintf("javascript:confirm_box(null,'"._('Voulez-vous effacer 
cette relation ')."',function ()  {remove_operation('%s','%s');});",
-                                                       dossier::id(),
-                                                       $p_operation);
-            $js= '<a class="tinybutton" id="acop'.$p_operation.'" 
href="javascript:void(0)" onclick="'.$rmOperation.'">'.SMALLX.'</a>';
-            return $js;
-        }
-        static function button_action_add_concerned_card($p_agid)
-        {
-            $dossier=Dossier::id();
-            $javascript= <<<EOF
-                    
obj={dossier:$dossier,ag_id:$p_agid};action_add_concerned_card(obj);
-EOF;
-            $js=HtmlInput::button_action(_('Ajout autres'), 
$javascript,'xx','smallbutton');
-            return $js;
-        }
-        static function button_action_add()
-        {
-            $dossier=Dossier::id();
-            $js=HtmlInput::button_action(_('Nouvel 
événement'),'action_add('.$dossier.')','xx','smallbutton');
-            return $js;
-        }
-}
diff --git a/include/class_iaction.php b/include/class_iaction.php
deleted file mode 100644
index 86ed399..0000000
--- a/include/class_iaction.php
+++ /dev/null
@@ -1,61 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief Html Input show just a ref to an action
- * create a button with a link, if you want to use a javascript
- * value must be empty
- */
-require_once NOALYSS_INCLUDE.'/class_html_input.php';
-class IAction_deprecated extends HtmlInput
-{
-    /*!\brief show the html  input of the widget*/
-    public function input($p_name="",$p_value="")
-    {
-        $this->name=($p_name=="")?$this->name:$p_name;
-        $this->value=($p_value=="")?$this->value:$p_value;
-        $this->id=($this->id=="")?$this->name:$this->id;
-        if ( $this->readOnly==true) return $this->display();
-        $this->javascript= (!isset ($this->javascript))?"":$this->javascript;
-        if ( $this->value !="")
-            $r=sprintf('<span id="%s" class="action"> <A class="action" 
HREF="%s" %s>%s</A></span>',
-                       $this->id,
-                       $this->value,
-                       $this->javascript,
-                       $this->label);
-        else
-            $r=sprintf('<span id="%s" class="action"> <A class="action" 
href="javascript: %s">%s</A></span>',
-                       $this->id,
-                       $this->javascript,
-                       $this->label);
-
-        return $r;
-
-    }
-    /*!\brief print in html the readonly value of the widget*/
-    public function display()
-    {
-        return;
-    }
-    static public function test_me()
-    {
-    }
-}
diff --git a/include/class_ianccard.php b/include/class_ianccard.php
deleted file mode 100644
index 10ae7c2..0000000
--- a/include/class_ianccard.php
+++ /dev/null
@@ -1,200 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief Input HTML for the card show buttons
- *
- */
-
-/*!
- * \brief
-*/
-require_once NOALYSS_INCLUDE.'/class_html_input.php';
-require_once NOALYSS_INCLUDE.'/function_javascript.php';
-
-class IAncCard extends HtmlInput
-{
-    function __construct($name="",$value="",$p_id="")
-    {
-        parent::__construct($name,$value,$p_id);
-        $this->fct='update_value';
-        $this->dblclick='';
-        $this->callback='null';
-        $this->javascript='';
-        // the pa_id to filter
-        $this->plan=0;
-        // or the container of the Plan Analytic which contains the pa_id
-        $this->plan_ctl="";
-    }
-    /*!\brief set the javascript callback function
-     * by default it is update_value called BEFORE the querystring is send
-     * If you use the plan ctl must be set to filter_anc
-     *\param $p_name callback function name
-     */
-    function set_callback($p_name)
-    {
-        $this->callback=$p_name;
-    }
-
-    /*!\brief set the javascript callback function
-     * by default it is update_value called AFTER an item has been selected
-     *\param $p_name callback function name
-     */
-    function set_function($p_name)
-    {
-        $this->fct=$p_name;
-    }
-
-    /*!\brief set the extra javascript property for a double click on
-     *  INPUT field
-     *\param $p_action action when a double click happens
-     *\note the $p_action cannot contain a double quote
-     */
-    function set_dblclick($p_action)
-    {
-        $this->dblclick=$p_action;
-    }
-    /*!\brief show the html  input of the widget*/
-    public function input($p_name=null,$p_value=null)
-    {
-        if ( $p_name == null && $this->name == "")
-            throw (new Exception('Le nom d une icard doit être donne'));
-
-        $this->value=($p_value==null)?$this->value:$p_value;
-        if ( $this->readOnly==true) return $this->display();
-
-        $this->id=($this->id=="")?$this->name:$this->id;
-
-
-
-        $label='';
-        if ( $this->dblclick != '')
-        {
-            $e=sprintf(' ondblclick="%s" ',
-                       $this->dblclick);
-            $this->dblclick=$e;
-        }
-        $input=sprintf('<INPUT TYPE="Text"  class="input_text"  '.
-                       ' NAME="%s" ID="%s" VALUE="%s" SIZE="%d" %s %s>',
-                       $this->name,
-                       $this->name,
-                       $this->value,
-                       $this->size,
-                       $this->dblclick,
-                       $this->javascript
-                      );
-
-
-        $div=sprintf('<div id="%s_choices"  class="autocomplete"></div>',
-                     $this->name);
-        $query="op=autoanc&".dossier::get();
-
-        // add parameter to search into a plan (pa_id) or get the value from
-        // a HtmlObject
-        if ($this->plan <> 0)
-        {
-            $query.="&pa_id=".$this->plan;
-        } elseif ( $this->plan_ctl <> '')
-        {
-               $this->set_attribute("plan_ctl", $this->plan_ctl);
-        }
-        $attr=$this->get_js_attr();
-        $javascript=sprintf('try { new 
Ajax.Autocompleter("%s","%s_choices","ajax_misc.php?%s",'.
-                            '{paramName:"anccard",minChars:1,indicator:null, '.
-                            'callback:%s, '.
-                            ' afterUpdateElement:%s});} catch 
(e){alert(e.message);};',
-                            $this->name,
-                            $this->name,
-                            $query,
-                            $this->callback,
-                            $this->fct);
-
-        $javascript=create_script($javascript.$this->dblclick);
-
-        $r=$label.$input.$attr.$div.$javascript;
-        if ( $this->table == 1 )
-            $r=td($r);
-        return $r;
-
-    }
-    /*!\brief print in html the readonly value of the widget*/
-    public function display()
-    {
-        $r=sprintf('
-                    <INPUT TYPE="hidden" NAME="%s" VALUE="%s" SIZE="8">',
-                   $this->name,
-                   $this->value
-                  );
-        $r.='<span>'.$this->value.'</span>';
-        return $r;
-
-    }
-    /**
-     address@hidden return a string containing the button for displaying
-     * a search form. When clicking on the result, update the input text file
-     * the common used attribute as
-     *   - jrn   the ledger
-     *   - label the field to update
-     *   - name name of the input text
-     *   - price amount
-     *   - tvaid
-     *   - typecard (deb, cred, filter or list of value)
-     * will be set
-     * if ICard is in readOnly, the button disappears, so the return string is 
empty
-    \code
-      // search ipopup
-    $search_card=new IPopup('ipop_card');
-    $search_card->title=_('Recherche de fiche');
-    $search_card->value='';
-    echo $search_card->input();
-
-    $a=new ICard('test');
-    $a->search();
-
-    \endcode
-     *\see ajax_card.php
-     *\note the ipopup id is hard coded : ipop_card
-     address@hidden HTML string with the button
-     */
-    function search()
-    {
-        if ( $this->readOnly==true) return '';
-
-        $button=new IButton($this->name.'_bt');
-        $a="";
-        foreach (array('typecard','jrn','label','price','tvaid') as $att)
-        {
-            if (isset($this->$att) )
-                $a.="this.".$att."='".$this->$att."';";
-        }
-        if (isset($this->name))
-            $a.="this.inp='".$this->name."';";
-        $a.="this.popup='ipop_card';";
-
-        $button->javascript=$a.' search_card(this)';
-        return $button->input();
-    }
-
-    static public function test_me()
-    {
-
-    }
-}
diff --git a/include/class_ibutton.php b/include/class_ibutton.php
deleted file mode 100644
index d348a0c..0000000
--- a/include/class_ibutton.php
+++ /dev/null
@@ -1,118 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief Html Input
- */
-require_once NOALYSS_INCLUDE.'/class_html_input.php';
-class IButton extends HtmlInput
-{
-    var $label;
-    var $class;
-    /*!\brief show the html  input of the widget*/
-    public function input($p_name=null,$p_value=null,$p_class="")
-    {
-        $this->name=($p_name==null)?$this->name:$p_name;
-        $this->value=($p_value==null)?$this->value:$p_value;
-       $this->label=(trim($this->label) != '')?$this->label:$this->value;
-        $this->class=($p_class != "")?$p_class:$this->class;
-        $this->class=($this->class=="")?"smallbutton ":$this->class;
-        if ( $this->readOnly==true) return $this->display();
-        $extra= ( isset($this->extra))?$this->extra:"";
-        $this->id=($this->id=="")?$this->name:$this->id;
-               $tab=(isset($this->tabindex))?' 
tabindex="'.$this->tabindex.'"':"";
-        $r='<input type="BUTTON" name="'.$this->name.'"'.
-           ' class="'.$this->class.'" '.
-                $this->extra.
-                               $tab.
-           ' id="'.$this->id.'"'.
-           ' value="'.$this->label.'"'.
-           ' onClick="'.$this->javascript.'"'.$extra.'>';
-        $attr=$this->get_js_attr();
-        $r.=$attr;
-        return $r;
-
-    }
-
-    /*!\brief print in html the readonly value of the widget*/
-    public function display()
-    {
-        return "";
-    }
-    static function tooggle_checkbox($p_form)
-    {
-        $select_all=new IButton('select_all');
-        $select_all->label=_('Inverser la sélection');
-        $select_all->javascript="toggle_checkbox('$p_form')";
-        return $select_all->input();
-    }
-    static function select_checkbox($p_form)
-    {
-        $select_all=new IButton('select_all');
-        $select_all->label=_('Cocher tous');
-        $select_all->javascript="select_checkbox('$p_form')";
-        return $select_all->input();
-    }
-    static function unselect_checkbox($p_form)
-    {
-        $select_all=new IButton('select_all');
-        $select_all->label=_('Décocher tous');
-        $select_all->javascript="unselect_checkbox('$p_form')";
-        return $select_all->input();
-    }
-    static function show_calc()
-    {
-        $calc=new IButton('shcalc');
-        $calc->label=_('Calculatrice');
-        $calc->javascript="show_calc()";
-        return $calc->input();
-
-    }
-    static public function test_me()
-    {
-    }
-}
-class ISmallButton extends IButton
-{
-    var $label;
-    /*!\brief show the html  input of the widget*/
-    public function input($p_name=null,$p_value=null,$p_style=null)
-    {
-        $this->name=($p_name==null)?$this->name:$p_name;
-        $this->value=($p_value==null)?$this->value:$p_value;
-               $this->label=(trim($this->label) != 
'')?$this->label:$this->value;
-        if ( $this->readOnly==true) return $this->display();
-        $extra= ( isset($this->extra))?$this->extra:"";
-        $this->id=($this->id=="")?$this->name:$this->id;
-               $tab=(isset($this->tabindex))?' 
tabindex="'.$this->tabindex.'"':"";
-        $r='<input type="BUTTON" name="'.$this->name.'"'.
-           ' class="smallbutton" '.
-                $this->extra.
-                               $tab.
-           ' id="'.$this->id.'"'.
-           ' value="'.$this->label.'"'.
-           ' onClick="'.$this->javascript.'"'.$extra.'>';
-        $attr=$this->get_js_attr();
-        $r.=$attr;
-        return $r;
-
-    }
-}
\ No newline at end of file
diff --git a/include/class_icard.php b/include/class_icard.php
deleted file mode 100644
index 0865cc9..0000000
--- a/include/class_icard.php
+++ /dev/null
@@ -1,394 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief Input HTML for the card show buttons
- *
- */
-
-/*!
- * \brief Input HTML for the card show buttons, in the file, you have to add 
card.js
- * How to use :
- * - label is the label in the button
- * - extra contents the type (all, deb or cred, a list of FD_ID between 
parent.  or a SQL clause
- * - attribute are the attribute to set (via ajax). The ledger is either a 
attribute (jrn) or a
- *  hidden field in the document, if none are set, there is no filter on the 
ledger
- *\note you must in a hidden field gDossier (dossier::hidden)
- *\see ajaxFid
- *\see card.js
- *\see fid.php
- *\see fid_card.php
- *\see ajax_card.php
- *
- * Set the hidden field or input field to be set by javascript with the 
function set_attribute
- * call the input method. After selecting a value the update_value function is 
called. If you need
- * to modify the queryString before the request is sent, you'll use the 
set_callback; the first
- * parameter is the INPUT field and the second the queryString, the function 
must returns a
- * queryString
- *\code
-// insert all the javascript files
-  echo js_include('prototype.js');
-  echo js_include('scriptaculous.js');
-  echo js_include('effects.js');
-  echo js_include('controls.js');
-
-//
-  $W1=new ICard();
-  $W1->label="Client ".HtmlInput::infobulle(0) ;
-  $W1->name="e_client";
-  $W1->tabindex=3;
-  $W1->value=$e_client;
-  $W1->table=0;
-// If double click call the javascript fill_ipopcard
-  $W1->set_dblclick("fill_ipopcard(this);");
-
-  // Type of card : deb, cred or all
-  $W1->set_attribute('typecard','deb');
-
-  $W1->extra='deb';
-
-// Add the callback function to filter the card on the jrn
-  $W1->set_callback('filter_card');
-
-// when value selected in the autcomplete
-  $W1->set_function('fill_data');
-
-// when the data change
-  $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
-           $W1->name);
-
- // name of the field to update with the name of the card
-  $W1->set_attribute('label','e_client_label');
-  $client_label=new ISpan();
-  $client_label->table=0;
-  $f_client=$client_label->input("e_client_label",$e_client_label);
-
-  $f_client_qcode=$W1->input();
-
-// Search button for card
-  $f_client_bt=$W1->search();
-* \endcode
-For searching a card, you need a popup, the script card.js and set
-the values for card, popup filter_card callback
address@hidden
-$card=new ICard('acc');
-$card->name="acc";
-$card->extra="all";
-$card->set_attribute('typecard','all');
-$card->set_callback('filter_card');
-
-echo $card->input();
-echo $card->search();
-// example 2
-$w=new ICard("av_text".$attr->ad_id);
-// filter on frd_id
-$sql=' select fd_id from fiche_def where frd_id in 
('.FICHE_TYPE_CLIENT.','.FICHE_TYPE_FOURNISSEUR.','.FICHE_TYPE_ADM_TAX.')';
-$filter=$this->cn->make_list($sql);
-$w->set_attribute('ipopup','ipopcard');
-$w->set_attribute('typecard',$filter);
-$w->set_attribute('inp',"av_text".$attr->ad_id);
-$w->set_attribute('label',"av_text".$attr->ad_id."_label");
-
-$w->extra=$filter;
-$w->extra2=0;
-$label=new ISpan();
-$label->name="av_text".$attr->ad_id."_label";
-$msg.=td($w->search().$label->input());
address@hidden
-*/
-require_once NOALYSS_INCLUDE.'/class_html_input.php';
-require_once NOALYSS_INCLUDE.'/function_javascript.php';
-
-class ICard extends HtmlInput
-{
-    function __construct($name="",$value="",$p_id="")
-    {
-        parent::__construct($name,$value);
-        $this->fct='update_value';
-        $this->dblclick='';
-        $this->callback='null';
-        $this->javascript='';
-       $this->id=($p_id != "")?$p_id:$name;
-        $this->choice=null;
-        $this->indicator=null;
-        $this->choice_create=1;
-       $this->autocomplete=1;
-        $this->style=' style="vertical-align:50%"';
-    }
-    /*!\brief set the javascript callback function
-     * by default it is update_value called BEFORE the querystring is send
-     *
-     *\param $p_name callback function name
-     */
-    function set_callback($p_name)
-    {
-        $this->callback=$p_name;
-    }
-
-    /*!\brief set the javascript callback function
-     * by default it is update_value called AFTER an item has been selected
-     *\param $p_name callback function name
-     */
-    function set_function($p_name)
-    {
-        $this->fct=$p_name;
-    }
-    /*!\brief return the html string for creating the ipopup, this ipopup
-     * can be used for adding, modifying or display a card
-     address@hidden ipopup is obsolete, the popin is created by javascript
-     *\param $p_name name of the ipopup, must be set after with set_attribute
-    \code
-      $f_add_button=new IButton('add_card');
-      $f_add_button->label='Créer une nouvelle fiche';
-      $f_add_button->set_attribute('ipopup','ipop_newcard');
-      $f_add_button->set_attribute('filter',$this->get_all_fiche_def ());
-      $f_add_button->javascript=" select_card_type(this);";
-      $str_add_button=$f_add_button->input();
-
-    \endcode
-     *\return html string
-     *\note must be one of first instruction on a new page, to avoid problem
-     * of position with IE
-     */
-    static function ipopup($p_name)
-    {
-        $ip_card=new IPopup ($p_name);
-        $ip_card->drag=true;
-               $ip_card->set_width('45%');
-        $ip_card->title='Fiche ';
-        $ip_card->value='';
-        
-        return $ip_card->input();
-    }
-    /*!\brief set the extra javascript property for a double click on
-     *  INPUT field
-     *\param $p_action action when a double click happens
-     *\note the $p_action cannot contain a double quote
-     */
-    function set_dblclick($p_action)
-    {
-        $this->dblclick=$p_action;
-    }
-    /*!\brief show the html  input of the widget*/
-    public function input($p_name=null,$p_value=null)
-    {
-        if ( $p_name == null && $this->name == "")
-            throw (new Exception('Le nom d une icard doit être donne'));
-
-        $this->value=($p_value==null)?$this->value:$p_value;
-        if ( $this->readOnly==true) return $this->display();
-
-                $this->id=($this->id=="")?$this->name:$this->id;
-        
$this->choice=($this->choice==null)?sprintf("%s_choices",$this->id):$this->choice;
-        
$this->indicator=($this->indicator==null)?sprintf("%s_ind",$this->id):$this->indicator;
-        $attr=$this->get_js_attr();
-
-        $label='';
-        if ( $this->dblclick != '')
-        {
-            $e=sprintf(' ondblclick="%s" ',
-                       $this->dblclick);
-            $this->dblclick=$e;
-        }
-        $input=sprintf('<INPUT TYPE="Text"  class="input_text"  '.
-                       ' NAME="%s" ID="%s" VALUE="%s" SIZE="%d" %s %s  %s>',
-                       $this->name,
-                       $this->id,
-                       $this->value,
-                       $this->size,
-                       $this->dblclick,
-                       $this->javascript,
-                       $this->style
-                      );
-               if ( $this->autocomplete == 1)
-               {
-                    $this->indicator="ind_".$this->id;
-                       $ind=sprintf('<span id="%s" class="autocomplete" 
style="position:absolute;display:none">Un instant... <img 
src="image/loading.gif" alt="Chargement..."/>'.
-                                               '</span>',
-                                               $this->indicator);
-                        $this->indicator="null";
-                       $div=($this->choice_create == 1) ? sprintf('<div 
id="%s"  class="autocomplete"></div>',$this->choice):"";
-
-                       $query=dossier::get().'&e='.urlencode($this->typecard);
-
-                       $javascript=sprintf('try { new 
Ajax.Autocompleter("%s","%s","fid_card.php?%s",'.
-                                                               
'{paramName:"FID",minChars:1,indicator:%s, '.
-                                                               'callback:%s, '.
-                                                               ' 
afterUpdateElement:%s});} catch (e){alert(e.message);};',
-                                                               $this->id,
-                                                                $this->choice,
-                                                                $query,
-                                                               
$this->indicator,
-                                                               $this->callback,
-                                                               $this->fct);
-
-                       $javascript=create_script($javascript.$this->dblclick);
-
-                       $r=$label.$input.$attr.$ind.$div.$javascript;
-               }
-               else
-               {
-                       $r=$label.$input;
-               }
-        if ( $this->table == 1 )
-            $r=td($r);
-        return $r;
-
-    }
-    /*!\brief print in html the readonly value of the widget*/
-    public function display()
-    {
-        $r=sprintf('         <INPUT TYPE="hidden" NAME="%s" id="%s" VALUE="%s" 
SIZE="8">',
-                   $this->name,
-                   $this->name,
-                   $this->value
-                  );
-        $r.='<span>'.$this->value.'</span>';
-        return $r;
-
-    }
-    /**
-     address@hidden return a string containing the button for displaying
-     * a search form. When clicking on the result, update the input text file
-     * the common used attribute as
-     *   - jrn   the ledger
-     *   - label the field to update
-     *   - name name of the input text
-     *   - price amount
-     *   - tvaid
-     *   - typecard (deb, cred, filter or list of value)
-     * will be set
-     * if ICard is in readOnly, the button disappears, so the return string is 
empty
-    \code
-      // search ipopup
-    $search_card=new IPopup('ipop_card');
-    $search_card->title=_('Recherche de fiche');
-    $search_card->value='';
-    echo $search_card->input();
-
-    $a=new ICard('test');
-    $a->search();
-
-    \endcode
-     *\see ajax_card.php
-     *\note the ipopup id is hard coded : ipop_card
-     address@hidden HTML string with the button
-     */
-    function search()
-    {
-        if ( $this->readOnly==true) return '';
-               if ( ! isset($this->id )) $this->id=$this->name;
-        $a="";
-        foreach (array('typecard','jrn','label','price','tvaid') as $att)
-        {
-            if (isset($this->$att) )
-                $a.="this.".$att."='".$this->$att."';";
-        }
-        if (isset($this->id) && $this->id != "")
-            $a.="this.inp='".$this->id."';";
-               else
-            $a.="this.inp='".$this->name."';";
-        $a.="this.popup='ipop_card';";
-        $javascript=$a.' search_card(this);return false;';
-        
-        $button=HtmlInput::button_image($javascript,$this->name."_bt", 
'alt="'._('Recherche').'" class="image_search"',"image/magnifier13.png");
-        return $button;
-    }
-
-    static public function test_me()
-    {
-        require_once NOALYSS_INCLUDE.'/class_itext.php';
-        $_SESSION['isValid']=1;
-        $a=new ICard('testme');
-        $a->extra="all";
-        $a->set_attribute('label','ctl_label');
-        $a->set_attribute('tvaid','ctl_tvaid');
-        $a->set_attribute('price','ctl_price');
-        $a->set_attribute('purchase','ctl_purchase');
-        $a->set_attribute('type','all');
-        echo <<<EOF
-         <div id="debug" style="border:solid 1px black;overflow:auto"></div>
-         <script type="text/javascript" language="javascript"  
src="js/prototype.js">
-         </script>
-         <script type="text/javascript" language="javascript"  
src="js/scriptaculous.js">
-         </script>
-         <script type="text/javascript" language="javascript"  
src="js/effects.js">
-         </script>
-         <script type="text/javascript" language="javascript"  
src="js/controls.js">
-         </script>
-         <script type="text/javascript" language="javascript"  
src="js/ajax_fid.js">
-         </script>
-         <script type="text/javascript" language="javascript"  >
-         function test_value(text,li)
-         {
-           alert("premier"+li.id);
-
-           str="";
-           str=text.id+'<hr>';
-           if ( text.js_attr1)
-             {
-               str+=text.js_attr1;
-               str+='<hr>';
-             }
-           if ( text.js_attr2)
-             {
-               str+=text.js_attr2;
-               str+='<hr>';
-             }
-           if ( text.js_attr3)
-             {
-               str+=text.js_attr3;
-               str+='<hr>';
-             }
-           for (var i in text)
-             {
-               str+=i+'<br>';
-             }
-
-           // $('debug').innerHTML=str;
-           ajaxFid(text);
-         }
-       </script>
-
-EOF;
-        echo "<form>";
-        $l=new IText('ctl_label');
-        $t=new IText('ctl_tvaid');
-        $p=new IText('ctl_price');
-        $b=new IText('ctl_purchase');
-
-        echo "Label ".$l->input().'<br>';
-        echo "Tva id  ".$t->input().'<br>';
-        echo "Price ".$p->input().'<br>';
-        echo "Purchase ".$b->input().'<br>';
-
-        if ( isset($_REQUEST['test_select']) )
-            echo HtmlInput::hidden('test_select',$_REQUEST['test_select']);
-        $a->set_function('test_value');
-        $a->javascript=' onchange="alert(\'onchange\');" 
onblur="alert(\'onblur\');" ';
-        echo $a->input();
-        echo dossier::hidden();
-        echo HtmlInput::submit('Entree','entree');
-        echo '</form>';
-        echo <<<EOF
-EOF;
-    }
-}
diff --git a/include/class_icheckbox.php b/include/class_icheckbox.php
deleted file mode 100644
index 67ad397..0000000
--- a/include/class_icheckbox.php
+++ /dev/null
@@ -1,74 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief Html Input
- */
-require_once NOALYSS_INCLUDE.'/class_html_input.php';
-class ICheckBox extends HtmlInput
-{
-    /*!\brief show the html  input of the widget*/
-    public function input($p_name=null,$p_value=null)
-    {
-        $this->name=($p_name==null)?$this->name:$p_name;
-        $this->value=($p_value==null)?$this->value:$p_value;
-        if ( $this->readOnly==true) return $this->display();
-                $this->id=($this->id=="")?$this->name:$this->id;
-
-        $check=( $this->selected==true )?"checked":"unchecked";
-        $r='<input type="CHECKBOX" id="'.$this->id.'" 
name="'.$this->name.'"'.' value="'.$this->value.'"';
-        $r.="  $check";
-        $r.=' '.$this->disabled."  ".$this->javascript.'>';
-
-        $r=$r." $this->label";
-
-        return $r;
-
-
-    }
-    /*!\brief print in html the readonly value of the widget*/
-    public function display()
-    {
-        $check=( $this->selected==true )?"checked":"unchecked";
-        $r='<input type="CHECKBOX" id="'.$this->name.'" 
name="'.$this->name.'"';
-        $r.="  $check";
-        $r.=' disabled>';
-
-        return $r;
-
-    }
-    /**
-     *set selected to true (checked) if the value equal the parameter
-     * @param $p_value value to compare
-     */
-    public function set_check($p_value)
-        {
-        if ($this->value==$p_value)$this->selected=true;
-        }
-    static function toggle_checkbox($p_name,$p_form) {
-            $a=new ICheckBox($p_name);
-            $a->javascript='onclick="toggle_checkbox(\''.$p_form.'\')"';
-            return $a->input();
-        }
-    static public function test_me()
-    {
-    }
-}
diff --git a/include/class_iconcerned.php b/include/class_iconcerned.php
deleted file mode 100644
index 283189e..0000000
--- a/include/class_iconcerned.php
+++ /dev/null
@@ -1,80 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief Html Input
- *  - name is the name and id of the input
- *  - extra amount of the operation to reconcile
- *  - extra2 ledger paid
- */
-require_once NOALYSS_INCLUDE.'/class_html_input.php';
-class IConcerned extends HtmlInput
-{
-
-       public function __construct($p_name='',$p_value='',$p_id="")
-       {
-               $this->name=$p_name;
-               $this->value=$p_value;
-               $this->amount_id=null;
-               $this->paid='';
-               $this->id=$p_id;
-                $this->tiers=""; // id of the field for the tiers to be updated
-       }
-    /*!\brief show the html  input of the widget*/
-    public function input($p_name=null,$p_value=null)
-    {
-        $this->name=($p_name==null)?$this->name:$p_name;
-        $this->value=($p_value==null)?$this->value:$p_value;
-        if ( $this->readOnly==true) return $this->display();
-
-           $this->id=($this->id=="")?$this->name:$this->id;
-
-
-        $r=sprintf("
-                    <image 
onclick=\"search_reconcile(".dossier::id().",'%s','%s','%s','%s')\" 
class=\"image_search\" src=\"image/magnifier13.png\" />
-                   
-                   <INPUT TYPE=\"text\"  
style=\"color:black;background:lightyellow;border:solid 1px grey;\"  
NAME=\"%s\" ID=\"%s\" VALUE=\"%s\" SIZE=\"8\" readonly>
-                                  <INPUT class=\"smallbutton\"  
TYPE=\"button\" onClick=\"$('%s').value=''\" value=\"X\">
-
-                   ",
-                   $this->name,
-                   $this->amount_id,
-                   $this->paid,
-                   $this->tiers,
-                   $this->name,
-                   $this->id,
-                   $this->value,
-                   $this->id
-                  );
-        return $r;
-    }
-    /*!\brief print in html the readonly value of the widget*/
-    public function display()
-    {
-        $r=sprintf("<span><b>%s</b></span>",$this->value);
-        $r.=sprintf('<input type="hidden" name="%s" value="%s">', 
$this->name,$this->value);
-        return $r;
-
-    }
-    static public function test_me()
-    {
-    }
-}
diff --git a/include/class_idate.php b/include/class_idate.php
deleted file mode 100644
index cea64c8..0000000
--- a/include/class_idate.php
+++ /dev/null
@@ -1,71 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief Html Input
- */
-require_once NOALYSS_INCLUDE.'/class_html_input.php';
-class IDate extends HtmlInput
-{
-    /*!\brief show the html  input of the widget*/
-    public function input($p_name=null,$p_value=null)
-    {
-        $this->name=($p_name==null)?$this->name:$p_name;
-        $this->value=($p_value==null)?$this->value:$p_value;
-        if ( $this->readOnly==true) return $this->display();
-       if( $this->id=="")
-         $this->id=self::generate_id($this->name);
-        $r='<input type="text" name="'.$this->name.'" id="'.$this->id.'" '.
-           ' class="input_text" '.
-           'size="10" style="width:6em" '.
-           ' value ="'.$this->value.'" '.
-           '/>'.
-           '<img src="image/x-office-calendar.png" id="'.$this->id.'_trigger"'.
-           ' style="cursor: pointer" '.
-           'onmouseover="this.style.background=\'red\';" 
onmouseout="this.style.background=\'\'" />';
-        $r.='<script type="text/javascript">'.
-            'Calendar.setup({'.
-            // 'date : "'.$this->value.'",
-            'inputField     :    "'.$this->id.'",     // id of the input field
-            ifFormat       :    "%d.%m.%Y",      // format of the input field
-            button         :    "'.$this->id.'_trigger",  // trigger for the 
calendar (button ID)
-            align          :    "Bl",           // alignment (defaults to "Bl")
-            singleClick    :    true
-        });
-            </script>
-            ';
-        return $r;
-
-    }
-    /*!\brief print in html the readonly value of the widget*/
-    public function display()
-    {
-        $r="<span>  : ".$this->value;
-        $r.='<input type="hidden" name="'.$this->name.'"'.
-            'id="'.$this->name.'"'.
-            ' value = "'.$this->value.'"></span>';
-        return $r;
-
-    }
-    static public function test_me()
-    {
-    }
-}
diff --git a/include/class_ifile.php b/include/class_ifile.php
deleted file mode 100644
index 66475f3..0000000
--- a/include/class_ifile.php
+++ /dev/null
@@ -1,46 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief Html Input 
- */
-require_once NOALYSS_INCLUDE.'/class_html_input.php';
-class IFile extends HtmlInput
-{
-    /*!\brief show the html  input of the widget*/
-    public function input($p_name=null,$p_value=null)
-    {
-        $this->name=($p_name==null)?$this->name:$p_name;
-        $this->value=($p_value==null)?$this->value:$p_value;
-        if ( $this->readOnly==true) return $this->display();
-        $r='<INPUT class="inp" TYPE="file" name="'.$this->name.'" 
VALUE="'.$this->value.'">';
-        return $r;
-
-    }
-    /*!\brief print in html the readonly value of the widget*/
-    public function display()
-    {
-
-    }
-    static public function test_me()
-    {
-    }
-}
diff --git a/include/class_ihidden.php b/include/class_ihidden.php
deleted file mode 100644
index 08d00a5..0000000
--- a/include/class_ihidden.php
+++ /dev/null
@@ -1,42 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief Html Input
- */
-require_once NOALYSS_INCLUDE.'/class_html_input.php';
-class IHidden extends HtmlInput
-{
-    /*!\brief show the html  input of the widget*/
-    public function input($p_name=null,$p_value=null)
-    {
-        $this->name=($p_name==null)?$this->name:$p_name;
-        $this->value=($p_value==null)?$this->value:$p_value;
-               $this->id=($this->id=="")?$this->name:$this->id;
-
-        $r='<INPUT TYPE="HIDDEN" id="'.$this->id.'" name="'.$this->name.'" 
value="'.$this->value.'">';
-        return $r;
-
-    }
-    static public function test_me()
-    {
-    }
-}
diff --git a/include/class_impress.php b/include/class_impress.php
deleted file mode 100644
index 2bdbafd..0000000
--- a/include/class_impress.php
+++ /dev/null
@@ -1,293 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-/*!\file
- * \brief contains function for the printing
-*/
-require_once NOALYSS_INCLUDE.'/class_periode.php';
-
-
-class Impress
-{
-    /*! \brief   Purpose Parse a formula
-     *
-     * \param $p_cn connexion
-     * \param $p_label
-     * \param $p_formula
-     * \param $p_eval  true if we eval here otherwise the function returns
-     *                 a string which must be evaluated
-     * \param $p_type_date : type of the date 0 for accountant period or 1
-     * for calendar
-     * \return array
-     *
-     *
-     */
-    static function 
parse_formula($p_cn,$p_label,$p_formula,$p_start,$p_end,$p_eval=true,$p_type_date=0,$p_sql="")
-    {
-        global $g_user;
-        if ( Impress::check_formula($p_formula) == false)
-        {
-            if ( $p_eval == true)
-                return array('desc'=>$p_label.'  Erreur Formule!',
-                             'montant'=>0);
-            else
-                return $p_formula;
-
-        }
-        if ( $p_type_date == 0 )
-            $cond=sql_filter_per($p_cn,$p_start,$p_end,'p_id','j_tech_per');
-        else
-            $cond="( j_date >= to_date('$p_start','DD.MM.YYYY') and j_date <= 
to_date('$p_end','DD.MM.YYYY'))";
-
-        include_once("class_acc_account_ledger.php");
-
-        while (preg_match_all("(\[[0-9]*[A-Z]*%*c*d*s*\])",$p_formula,$e) == 
true)
-          {
-
-            // remove the [ ]
-            $x=$e[0];
-            foreach ($x as $line)
-              {
-                $compute='all';
-                if ( strpos($line,'d') != 0 )
-                  $compute='deb';
-                if ( strpos($line,'c') != 0 )
-                  $compute='cred';
-                if ( strpos($line,'s') != 0 )
-                  $compute='signed';
-                $line=str_replace ("[","",$line);
-                $line=str_replace ("]","",$line);
-                $line=str_replace ("d","",$line);
-                $line=str_replace ("c","",$line);
-                $line=str_replace ("s","",$line);
-                // If there is a FROM clause we must recompute
-                // the time cond
-
-                if ($p_type_date == 0 && preg_match ("/FROM=[0-9]+\.[0-9]+/", 
$p_formula,$afrom) == 1 )
-                  {
-                    // There is a FROM clause
-                    // then we must modify the cond for the periode
-                    $from=str_replace("FROM=","",$afrom[0]);
-
-                    // Get the periode
-                    /*! \note special value for the clause FROM=00.0000
-                     */
-                    if ( $from == '00.0000' )
-                      {
-
-                        // retrieve the first month of this periode
-                        $user_periode=$g_user->get_periode();
-                        $oPeriode=new Periode($p_cn);
-                        $periode=$oPeriode->get_exercice($user_periode);
-                        list($first,$last)=$oPeriode->get_limit($periode);
-                        $ret=$first->get_date_limit();
-                        $end_date=$oPeriode->get_date_limit($p_end);
-                        if ($ret == null ) throw new Exception ('Pas de limite 
à cette période',1);
-                        
$cond=sql_filter_per($p_cn,$ret['p_start'],$end_date['p_end'],'date','j_tech_per');
-
-
-                      }
-                    else
-                      {
-                        $oPeriode=new Periode($p_cn);
-                        try
-                          {
-                            $pfrom=$oPeriode->find_periode('01.'.$from);
-                            $cond=  sql_filter_per($p_cn, $pfrom, 
$p_end,'p_id','j_tech_per');
-                          }
-                        catch (Exception $exp)
-                          {
-                            /* if none periode is found
-                               then we take the first periode of the year
-                            */
-                            $user_periode=$g_user->get_periode();
-
-                            $year=$oPeriode->get_exercice($user_periode);
-                            list($first,$last)=$oPeriode->get_limit($year);
-                            $ret=$first->get_date_limit();
-                            $end_date=$oPeriode->get_date_limit($p_end);
-                            if ($ret == null ) throw new Exception ('Pas de 
limite à cette période',1);
-                            
$cond=sql_filter_per($p_cn,$ret['p_start'],$end_date['p_end'],'date','j_tech_per');
-                          }
-                      }
-                  }
-
-                if ( strpos($p_formula,"FROM") != 0)
-                  {
-                    // We remove FROM out of the p_formula
-                    
$p_formula=substr_replace($p_formula,"",strpos($p_formula,"FROM"));
-                  }
-
-                // Get sum of account
-                $P=new Acc_Account_Ledger($p_cn,$line);
-                $detail=$P->get_solde_detail($cond.$p_sql);
-
-
-                if ( $compute=='all')
-                  $i=$detail['solde'];
-                if ( $compute=='deb')
-                  $i=$detail['debit'];
-                if ( $compute=='cred')
-                  $i=$detail['credit'];
-                if ( $compute=='signed')
-                  $i=$detail['debit']-$detail['credit'];
-                $p_formula=str_replace($x[0],$i,$p_formula);
-              }
-          }
-
-        // $p_eval is true then we eval and returns result
-        if ( $p_eval == true)
-        {
-            $p_formula="\$result=".$p_formula.";";
-            eval("$p_formula");
-
-            while (preg_match("/\[([0-9]+)([Tt]*)\]/",trim($p_label),$e) == 1)
-            {
-                $nom = "!!".$e[1]."!!";
-                if (Impress::check_formula($e[0]))
-                {
-                    $nom = $p_cn->get_value ( "SELECT pcm_lib AS acct_name 
FROM tmp_pcmn WHERE pcm_val::text LIKE $1||'%' ORDER BY pcm_val ASC LIMIT 
1",array($e[1]));
-                    if($nom)
-                    {
-                        if($e[2] == 'T') $nom = strtoupper($nom);
-                        if($e[2] == 't') $nom = strtolower($nom);
-                    }
-                }
-                $p_label = str_replace($e[0], $nom, $p_label);
-            }
-
-            $aret=array('desc'=>$p_label,
-                        'montant'=>$result);
-            return $aret;
-        }
-        else
-        {
-            // $p_eval is false we returns only the string
-            return $p_formula;
-        }
-    }
-    /*!
-     * \brief  Check if formula doesn't contain
-     *           php injection
-     * \param string
-     *
-     * \return true if the formula is good otherwise false
-     */
-    static function check_formula($p_string)
-    {
-        // the preg_match gets too complex if we want to add a test
-        // for parenthesis, math function...
-        // So I prefer remove them before testing
-        $p_string=str_replace("round","",$p_string);
-        $p_string=str_replace("abs","",$p_string);
-        $p_string=str_replace("(","",$p_string);
-        $p_string=str_replace(")","",$p_string);
-        // for  the inline test like $a=(cond)?value:other;
-        $p_string=str_replace("?","+",$p_string);
-        $p_string=str_replace(":","+",$p_string);
-        $p_string=str_replace(">=","+",$p_string);
-        $p_string=str_replace("<=","+",$p_string);
-        $p_string=str_replace(">","+",$p_string);
-        $p_string=str_replace("<","+",$p_string);
-        // eat Space + comma
-        $p_string=str_replace(" ","",$p_string);
-        $p_string=str_replace(",","",$p_string);
-        // Remove D/C/S
-        $p_string=str_replace("c","",$p_string);
-        $p_string=str_replace("d","",$p_string);
-        $p_string=str_replace("s","",$p_string);
-        // Remove T,t
-        $p_string=str_replace("t","",$p_string);
-
-               // remove date
-               $p_string=  preg_replace("/FROM*=*[0-9]+/", "", $p_string);
-               // remove comment
-               $p_string=  preg_replace("/#.*/", "", $p_string);
-               // remove $C=
-               $p_string=  preg_replace('/\$[a-z]*[A-Z]*[0-9]*[A-Z]*[a-z]*/', 
"", $p_string);
-               $p_string=  preg_replace('/=/', "", $p_string);
-
-               // remove account
-               $p_string=  preg_replace("/\[[0-9]*[A-Z]*%*\]/", "", $p_string);
-
-               $p_string=  preg_replace("/\+|-|\/|\*/", "", $p_string);
-               $p_string=  preg_replace("/[0-9]*\.*[0-9]/", "", $p_string);
-
-               
//********************************************************************************************************************
-               // If the string is empty then formula should be good
-               //
-               
//********************************************************************************************************************
-               if ($p_string == '')
-        {
-            return true;
-        }
-        else
-        {
-            return false;
-        }
-    }
-     /**
-     * with the handle of a successull query, echo each row into CSV and
-     * send it directly
-     * @param type $array of data
-     * @param type $aheader  double array, each item of the array contains
-     * a key type (num) and a key title
-     */
-    static function array_to_csv($array,$aheader)
-    {
-        $seq="";
-        for ($i=0;$i<count($aheader);$i++)
-        {
-            echo $seq.'"'.$aheader[$i]['title'].'"';
-            $seq=";";
-        }
-        printf("\r");
-
-        $seq="";
-        // fetch all the rows
-        for ($i=0;$i<count($array);$i++)
-        {
-            $row=$array[$i];
-            $sep2="";
-                       $e=0;
-            // for each rows, for each value
-            foreach ($array[$i] as $key=>$value)
-            {
-                               if ($e > count($aheader)) $e=0;
-
-                               if ( isset ($aheader[$e]['type']))
-                               {
-                                       switch ($aheader[$e]['type'])
-                                       {
-                                               case 'num':
-                                                       echo $sep2.nb($value);
-                                                       break;
-                                               default:
-                                                       echo 
$sep2.'"'.$value.'"';
-                                       }
-                               } else {
-                                       echo '"'.$value.'"'.$sep2;
-                               }
-                $sep2=";";$e++;
-            }
-            printf("\r");
-        }
-    }
-}
\ No newline at end of file
diff --git a/include/class_inum.php b/include/class_inum.php
deleted file mode 100644
index 3cba46c..0000000
--- a/include/class_inum.php
+++ /dev/null
@@ -1,111 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief for the numeric input text field
- */
-require_once NOALYSS_INCLUDE.'/class_itext.php';
-/*!\brief
- * This class handles only the numeric input, the input will
- * call a javascript
- * to change comma to period  and will round it (2 decimal), the precision is 
given by
- * the attribute prec
- * attribute
- *  extra = extra code (free)
- *  size = size of the field
- *  prec = precision default = 2
- *  name = name of the html object
- *  javascript = javascript to execute (default = 
onchange="format_number(this,2);)
- *  value = value of the widget
- *
- */
-class INum extends IText
-{
-    function __construct($name='',$value='')
-    {
-        parent::__construct($name,$value);
-
-        $this->size=9;
-        $this->style='class="inum"';
-       $this->javascript= 'onchange="format_number(this,2);"';
-    }
-    /*!\brief print in html the readonly value of the widget*/
-    public function display()
-    {
-
-        $readonly=" readonly ";
-               $this->id=($this->id=="")?$this->name:$this->id;
-
-        //$style='style="border:solid 1px 
blue;color:black;background:#EDEDED;text-align:right"';
-        $style=' class="inum input_text_ro"';
-        $this->value=str_replace('"','',$this->value);
-        $r='<INPUT '.$style.' TYPE="TEXT" id="'.
-           $this->id.'"'.
-           'NAME="'.$this->name.'" VALUE="'.$this->value.'"  '.
-           'SIZE="'.$this->size.'" '.$this->javascript." $readonly 
$this->extra >";
-
-        /* add tag for column if inside a table */
-        if ( $this->table == 1 )                 $r='<td>'.$r.'</td>';
-
-        return $r;
-
-    }
-        /*!\brief show the html  input of the widget*/
-    public function input($p_name=null,$p_value=null)
-    {
-               if ( isset ($this->prec)) {
-                       $this->javascript= 
'onchange="format_number(this,'.$this->prec.');"';
-               }
-        $this->name=($p_name==null)?$this->name:$p_name;
-        $this->value=($p_value==null)?$this->value:$p_value;
-               $this->id=($this->id=="")?$this->name:$this->id;
-
-        if ( $this->readOnly==true) return $this->display();
-
-        $t= ((isset($this->title)))?'title="'.$this->title.'"   ':' ';
-
-        $extra=(isset($this->extra))?$this->extra:"";
-
-        $this->value=str_replace('"','',$this->value);
-        if ( ! isset ($this->css_size))
-        {
-        $r='<INPUT '.$this->style.' TYPE="TEXT" id="'.
-           $this->id.'"'.$t.
-           'NAME="'.$this->name.'" VALUE="'.$this->value.'"  '.
-           'SIZE="'.$this->size.'" '.$this->javascript."  $this->extra >";
-        /* add tag for column if inside a table */
-        } else {
-           $r='<INPUT '.$this->style.' TYPE="TEXT" id="'.
-           $this->id.'"'.$t.
-           'NAME="'.$this->name.'" VALUE="'.$this->value.'"  '.
-           ' style="width:'.$this->css_size.';" '.$this->javascript."  
$this->extra >";
-
-        }
-
-        if ( $this->table == 1 )                 $r='<td>'.$r.'</td>';
-
-        return $r;
-
-    }
-
-}
-
-
diff --git a/include/class_iperiod.php b/include/class_iperiod.php
deleted file mode 100644
index a22c26e..0000000
--- a/include/class_iperiod.php
+++ /dev/null
@@ -1,171 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief Html Input
- */
-/*! \brief          Generate the form for the periode
-* Data Members
- *   - $cn connexion to the current folder
- *   - $type the type of the periode OPEN CLOSE NOTCENTRALIZED or ALL, IT MUST 
BE SET
- *   - $filter_year make a filter on the default exercice by default true
- *   - $user if a filter_year is required then we need who is the user (object 
User)
- *   - $show_end_date; $show_end_date is not set or false, do not show the end 
date  default = true
- *   - $show_start_date; $show_start_date is not set or false, do not show the 
start date  default=true
-*/
-require_once NOALYSS_INCLUDE.'/class_html_input.php';
-class IPeriod extends HtmlInput
-{
-    var $type; /*!< $type the type of the periode OPEN CLOSE NOTCENTRALIZED or 
ALL */
-    var $cn;  /*!< $cn is the database connection */
-    var $show_end_date; /*!< $show_end_date is not set or false, do not show 
the end date */
-    var $show_start_date; /*!< $show_start_date is not set or false, do not 
show the start date */
-    var $filter_year; /*!< $filter_year make a filter on the default exercice 
by default yes */
-    var $user;  /*! $user if a filter is required then we need who is the user 
(object User)*/
-    function __construct($p_name="",$p_value="",$p_exercice='')
-    {
-        $this->name=$p_name;
-        $this->readOnly=false;
-        $this->size=20;
-        $this->width=50;
-        $this->heigh=20;
-        $this->value=$p_value;
-        $this->selected="";
-        $this->table=0;
-        $this->disabled=false;
-        $this->javascript="";
-        $this->extra2="all";
-        $this->show_start_date=true;
-        $this->show_end_date=true;
-               $this->exercice=$p_exercice;
-    }
-    /*!
-     * \brief show the input html for a periode
-     *\param $p_name is the name of the widget
-     *\param $p_value is the default value
-     *\param $p_exercice is the exercice, if not set then the user preference 
is used
-     * \return string containing html code for the HTML
-     *
-     *
-     */
-    public function input($p_name=null,$p_value=null)
-    {
-        foreach (array('type','cn') as $a)
-        {
-            if ( ! isset ($this->$a) ) throw new Exception('Variable non 
définie [ '.$a.']');
-        }
-        $this->name=($p_name==null)?$this->name:$p_name;
-        $this->value=($p_value==null)?$this->value:$p_value;
-        if ( $this->readOnly==true) return $this->display();
-
-        switch ($this->type)
-        {
-        case CLOSED:
-            $sql_closed="where p_closed=true and p_central = false ";
-            break;
-        case OPEN:
-            $sql_closed="where p_closed=false";
-            break;
-        case NOTCENTRALIZED:
-            $sql_closed="where p_closed=true and p_central = false ";
-            break;
-        case ALL:
-            $sql_closed="";
-            break;
-        default:
-            throw new Exception("invalide p_type in ".__FILE__.':'.__LINE__);
-        }
-        $sql="select p_id,to_char(p_start,'DD.MM.YYYY') as p_start_string,
-             to_char(p_end,'DD.MM.YYYY') as p_end_string
-             from parm_periode
-             $sql_closed ";
-
-       $cond="";
-
-
-        /* Create a filter on the current exercice */
-        if ( ! isset($this->filter_year) || (isset($this->filter_year) && 
$this->filter_year==true))
-        {
-         if ( $this->exercice=='')
-           {
-             if (! isset($this->user) ) throw new Exception 
(__FILE__.':'.__LINE__.' user is not set');
-             $this->exercice=$this->user->get_exercice();
-           }
-
-            $cond='';
-           if ( $sql_closed=="") $and=" where " ; else $and=" and ";
-            if ($this->type == 'all' ) $cond=$and.'   true ';
-            $cond.=" $and p_exercice='".sql_string($this->exercice)."'";
-        }
-
-        $sql.=$cond."  order by p_start,p_end";
-
-        $Res=$this->cn->exec_sql($sql);
-        $Max=$this->cn->size($Res);
-        if ( $Max == 0 )  throw new Exception(_('Aucune periode trouvée'),1);
-        $ret='<SELECT NAME="'.$this->name.'" '.$this->javascript.'>';
-        for ( $i = 0; $i < $Max;$i++)
-        {
-            $l_line=$this->cn->fetch($i);
-            if ( $this->value==$l_line['p_id'] )
-                $sel="SELECTED";
-            else
-                $sel="";
-
-            if ( $this->show_start_date == true && $this->show_end_date==true )
-            {
-                $ret.=sprintf('<OPTION VALUE="%s" %s>%s - %s',$l_line['p_id']
-                              ,$sel
-                              ,$l_line['p_start_string']
-                              ,$l_line['p_end_string']);
-            }
-            else if ($this->show_start_date == true )
-            {
-                $ret.=sprintf('<OPTION VALUE="%s" %s>%s ',$l_line['p_id']
-                              ,$sel
-                              ,$l_line['p_start_string']
-                             );
-            }
-            else if ( $this->show_end_date == true )
-            {
-                $ret.=sprintf('<OPTION VALUE="%s" %s>%s ',$l_line['p_id']
-                              ,$sel
-                              ,$l_line['p_end_string']
-                             );
-            }
-
-        }
-        $ret.="</SELECT>";
-        return $ret;
-
-
-    }
-    /*!\brief print in html the readonly value of the widget*/
-    public function display()
-    {
-        $r="not implemented ".__FILE__.":".__LINE__;
-        return $r;
-
-    }
-    static public function test_me()
-    {
-    }
-}
diff --git a/include/class_ipopup.php b/include/class_ipopup.php
deleted file mode 100644
index 62620ae..0000000
--- a/include/class_ipopup.php
+++ /dev/null
@@ -1,191 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief create a popup in html above the current layer
- * the html inside the popup cannot contain any floating elt as div..
- *
- */
-require_once NOALYSS_INCLUDE.'/function_javascript.php';
-require_once NOALYSS_INCLUDE.'/class_html_input.php';
-
-class IPopup extends HtmlInput
-{
-    var $name;                 /*!< name name and id of the div */
-    function __construct($p_name)
-    {
-        $this->name=$p_name;
-        $this->parameter='';
-        $this->attribute=array();
-        $this->drag=false;
-        $this->blocking=true;
-    }
-    function set_width($p_val)
-    {
-        $js=sprintf('$("%s'.'_border").style.width="%s";',
-                    $this->name,$p_val);
-        $this->parameter.=$js;
-
-    }
-    function set_height($p_val)
-    {
-        $js=sprintf('$("%s'.'_border").style.height="%s";',
-                    $this->name,$p_val);
-        $this->parameter.=$js;
-
-    }
-    /**
-     address@hidden set or not a blocking fond
-     address@hidden $p_block if true if you want to avoid access to background,
-     *accept true or false
-     */
-    function set_block($p_block)
-    {
-        $this->blocking=$p_block;
-    }
-
-    function set_zindex($p_val)
-    {
-        $js=sprintf('$("%s'.'_border").style.zIndex=%d;',
-                    $this->name,$p_val);
-        $js=sprintf('$("%s'.'_content").style.zIndex=%d;',
-                    $this->name,$p_val);
-        $this->parameter.=$js;
-    }
-    function set_dragguable($p_value)
-    {
-        $this->drag=$p_value;
-    }
-    /*!\brief set the attribute thanks javascript as the width, the position 
...
-     *\param $p_name attribute name
-     *\param $p_val val of the attribute
-     *\note add to  the this->attribut, it will be used in input()
-     */
-    function set_attribute($p_name,$p_val)
-    {
-        $this->attribute[]=array($p_name,$p_val);
-    }
-    /*!\brief set the title of a ipopup thanks javascript and php mode
-     *\param title of the IPopup
-     *\return html string with js script
-     */
-    function set_title($p_title)
-    {
-        $this->title=$p_title;
-        $s=sprintf('$("%s_"+"title")="%s"',
-                   $this->name,$this->title);
-        return create_script($s);
-    }
-    function input()
-    {
-        $r="";
-        if ($this->blocking)
-        {
-            $r.=sprintf('<div id="%s_fond" class="popup_back">',$this->name);
-            $r.="</div>";
-        }
-        $javascript=sprintf("javascript:hideIPopup('%s')",
-                            $this->name);
-
-
-        if ( isset($this->title) && trim($this->title) != "" )
-        {
-            $r.=sprintf('<div id="%s_border" id="%s_border" 
class="popup_border_title">',
-                        $this->name,
-                        $this->name);
-            $r.=sprintf('<span id="%s_">%s</span>',$this->name,$this->title);
-        }
-        else
-        {
-            $r.=sprintf('<div id ="%s_border" id="%s_border" 
class="popup_border_notitle">',
-                        $this->name,
-                        $this->name);
-        }
-        $r.='<div 
style="position:absolute;top:0px;right:10px;font-weight:normal;font-size:9px;color:black;text-align:right">';
-        $r.=sprintf('<a 
style="background-color:blue;color:white;text-decoration:none" 
href="%s">&#10761;</a></div>',
-                    $javascript);
-
-        $r.=sprintf('<div id ="%s_content" id="%s_content" class="inner_box"> 
%s </div></div>',
-                    $this->name,
-                    $this->name,
-                    $this->value);
-
-
-        /* Add properties at the widget */
-        $attr=$this->parameter;
-        for ($i=0;$i< count($this->attribute);$i++)
-        {
-            list($name,$value)=$this->attribute[$i];
-            $tmp1=sprintf("$('%s').%s='%s';",
-                          $this->name,
-                          $name,
-                          $value);
-            $attr.=$tmp1;
-        }
-        $draggable='';
-        if ($this->drag==true)
-        {
-            /* add draggable possibility */
-            $draggable=sprintf("  new 
Draggable('%s_border',{starteffect:function(){
-                               new 
Effect.Highlight('%s_border',{scroll:window,queue:'end'});  } });"
-                               ,$this->name
-                               ,$this->name);
-
-        }
-        $attr=create_script($attr.$draggable);
-        $r.=$attr;
-        return $r;
-    }
-
-    static function test_me()
-    {
-        require_once NOALYSS_INCLUDE.'/class_iselect.php';
-        $select=new ISelect('a');
-        $select->value=array(array ('value'=>0,'label'=>'Première valeur'),
-                             array ('value'=>0,'label'=>'Première valeur'),
-                             array ('value'=>0,'label'=>'Première valeur'));
-        for ($e=0;$e<5;$e++)
-        {
-            echo $select->input();
-            if ($e%10 == 0 ) echo '<hr>';
-        }
-        $a=new IPopup('pop1');
-        $a->value="";
-        for ($e=0;$e<500;$e++)
-        {
-            $a->value.="<p>Il etait une fois dans  un pays vraiment lointain 
où même plus loin que ça</p>";
-        }
-        echo $a->input();
-        echo '
-        <input type="button" onclick="hide(\'pop1\');hide(\'pop1_border\')" 
value="cacher">
-                                     <input type="button" 
onclick="showIPopup(\'pop1\')" value="montrer">
-              ';
-        $a=new IPopup('pop2');
-        $a->value='';
-        $a->title="Retrouvez une saucisse";
-        echo $a->input();
-        echo '
-        <input type="button" onclick="hide(\'pop2\');hide(\'pop2_border\')" 
value="cacher">
-                        <input type="button" onclick="showIPopup(\'pop2\')" 
value="montrer">
-              ';
-
-    }
-}
diff --git a/include/class_iposte.php b/include/class_iposte.php
deleted file mode 100644
index 9da05fe..0000000
--- a/include/class_iposte.php
+++ /dev/null
@@ -1,203 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief Html Input
- *
- */
-require_once NOALYSS_INCLUDE.'/class_html_input.php';
-require_once NOALYSS_INCLUDE.'/class_itext.php';
-require_once NOALYSS_INCLUDE.'/class_ibutton.php';
-require_once NOALYSS_INCLUDE.'/class_ipopup.php';
-require_once NOALYSS_INCLUDE.'/function_javascript.php';
-/**
- address@hidden show a button, for selecting a account and a input text for 
manually inserting an account
- * the different value of table are
- * - 0 no table, it means no TD tags
- * - 1 the button and the text are separated by TD tags
- * - 2 the button and the text are in the same column (TD)
- * - 3 the button and the text are in the table (TD)
- *\note we use the set_attribute for giving parameter to search_account
- * attribute are
- *  - gDossier
- *  - jrn  if set there is a filter on a ledger, in  that case, contains the 
jrn_id (0 for no filter)
- *  - account field to update with the account_number,
- *  - label  field to update  control with account_label,
- *  - bracket if true return the account_number between bracket
- *  - noquery don't start a search with the content
- *  - no_overwrite do not overwrite the existant content
- *  - query value to seek
- address@hidden needed javascript are
- - echo js_include('prototype.js');
- - echo js_include('scriptaculous.js');
- - echo js_include('effects.js');
- - echo js_include('controls.js');
- - echo js_include('dragdrop.js');
- - echo js_include('accounting_item.js');
- *\see ajax_poste.php
- *\code
-// must be done BEFORE any FORM
- echo js_include('prototype.js');
- echo js_include('scriptaculous.js');
- echo js_include('effects.js');
- echo js_include('controls.js');
- echo js_include('dragdrop.js');
- echo js_include('accounting_item.js');
-
-
-require_once NOALYSS_INCLUDE.'/class_iposte.php';
-
-// In the FORM
-$text=new IPoste();
-$text->name('field');
-$text->value=$p_res[$i]['pvalue'];
-$text->set_attribute('gDossier',Dossier::id());
-$text->set_attribute('jrn',0);
-$text->set_attribute('account','field');
-
-
-\endcode
- */
-class IPoste extends HtmlInput
-{
-
-    function __construct($p_name="",$p_value="",$p_id="")
-    {
-        $this->name=$p_name;
-        $this->readOnly=false;
-        $this->size=10;
-        $this->value=$p_value;
-        $this->selected="";
-        $this->table=0;
-        $this->disabled=false;
-        $this->javascript="";
-        $this->extra2="all";
-        $this->attribute=array();
-       $this->id=$p_id;
-       
-
-    }
-
-    static function ipopup($p_name)
-    {
-        $ip=new IPopup($p_name);
-        $ip->title='Plan comptable';
-        $ip->value='';
-        $ip->set_height('80%');
-        $ip->set_zindex(20);
-        return $ip->input();
-    }
-    /*!\brief create the javascript for adding the javascript properties
-     * onto the *button*
-     *\return a javascript surrounded by the tag <SCRIPT>
-     */
-    public function get_js_attr()
-    {
-        $attr="";
-        /* Add properties at the widget */
-        for ($i=0;$i< count($this->attribute);$i++)
-        {
-            list($name,$value)=$this->attribute[$i];
-            $tmp1=sprintf("$('%s_bt').%s='%s';",
-                          $this->id,
-                          $name,
-                          $value);
-            $attr.=$tmp1;
-        }
-        $attr=create_script($attr);
-        return $attr;
-    }
-
-    public function dsp_button()
-    {
-               $this->id=($this->id=="")?$this->name:$this->id;
-        $javascript='search_poste(this)';
-        $button=HtmlInput::button_image($javascript,$this->id."_bt", 
'alt="'._('Recherche').'" class="image_search"',"image/magnifier13.png");
-        /*  add the property */
-        $sc=$this->get_js_attr();
-        return $button.$sc;
-    }
-    /*!\brief show the html  input of the widget*/
-    public function input($p_name=null,$p_value=null)
-    {
-        $this->name=($p_name==null)?$this->name:$p_name;
-        $this->value=($p_value==null)?$this->value:$p_value;
-        if ( $this->readOnly==true) return $this->display();
-        //--
-        if ( ! isset($this->ctrl) ) $this->ctrl='none';
-
-        if ( ! isset($this->javascript)) $this->javascript="";
-               $this->id=($this->id=="")?$this->name:$this->id;
-
-        /* create the text  */
-        $itext=new IText($this->name,$this->value,$this->id);
-
-       if ( isset ($this->css_size))
-            $itext->css_size=$this->css_size;
-       else
-            $itext->size=$this->size;
-
-                $itext->javascript=$this->javascript;
-        /* create the button */
-        $ibutton=$this->dsp_button();
-        if ( $this->table==3)
-        {
-            $r='<table>'.tr(td($itext->input()).td($ibutton));
-            $r.='</table>';
-            return $r;
-        }
-        $r=$itext->input().$ibutton;
-        if ( $this->table==1) $r=td($r);
-
-        return $r;
-
-
-        //--
-
-    }
-    /*!\brief print in html the readonly value of the widget*/
-    public function display()
-    {
-        $r=sprintf('<TD><input type="hidden" name="%s" value="%s">
-                   %s
-
-                   </TD>',
-                   $this->name,
-                   $this->value ,
-                   $this->value
-                  );
-
-        return $r;
-
-    }
-       /**
-        *add a double click to poste to see his history
-        address@hidden change $this->javascript
-        */
-       public function dbl_click_history()
-       {
-               $r=' 
ondblclick="get_history_account(\''.$this->name.'\',\''.dossier::id().'\')"';
-               $this->javascript=$r;
-       }
-    static public function test_me()
-    {
-    }
-}
diff --git a/include/class_iradio.php b/include/class_iradio.php
deleted file mode 100644
index 69c7891..0000000
--- a/include/class_iradio.php
+++ /dev/null
@@ -1,73 +0,0 @@
-<?php
-
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/**\file
- * \brief Html Input 
- */
-require_once NOALYSS_INCLUDE.'/class_html_input.php';
-
-class IRadio extends HtmlInput
-    {
-    /**\brief show the html  input of the widget */
-
-    public function input($p_name=null, $p_value=null)
-        {
-        $this->name = ($p_name == null) ? $this->name : $p_name;
-        $this->value = ($p_value == null) ? $this->value : $p_value;
-        if ($this->readOnly == true)
-            return $this->display();
-
-        $check = ( $this->selected == true || $this->selected == 't' ) ? 
"checked" : "unchecked";
-        $r = '<input type="RADIO" name="' . $this->name . '"';
-        $r.=" VALUE=\"$this->value\"";
-        $r.=' class="css-checkbox" ';
-        $r.=($this->javascript != '') ? 'onclick="' . $this->javascript . '"' 
: '';
-        $r.="  $check > ";
-        return $r;
-        }
-
-    /**\brief print in html the readonly value of the widget */
-
-    public function display()
-        {
-
-        $check = ( $this->selected == true || $this->selected == 't' ) ? "Yes" 
: "no";
-        $r = $check;
-        return $r;
-        }
-
-    /**
-     * set selected to true (checked) if the value equal the parameter
-     * @param $p_value value to compare
-     */
-    public function set_check($p_value)
-        {
-        if ($this->value == $p_value)
-            $this->selected = true;
-        }
-
-    static public function test_me()
-        {
-        
-        }
-       
-    }
diff --git a/include/class_irelated_action.php 
b/include/class_irelated_action.php
deleted file mode 100644
index ac04742..0000000
--- a/include/class_irelated_action.php
+++ /dev/null
@@ -1,73 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief Html Input
- *  - name is the name and id of the input
- */
-require_once NOALYSS_INCLUDE.'/class_html_input.php';
-class IRelated_Action extends HtmlInput
-{
-
-       public function __construct($p_name='',$p_value='')
-       {
-               $this->name=$p_name;
-               $this->value=$p_value;
-               $this->amount_id=null;
-               $this->paid='';
-               $this->id=$p_name;
-       }
-    /*!\brief show the html  input of the widget*/
-    public function input($p_name=null,$p_value=null)
-    {
-        $this->name=($p_name==null)?$this->name:$p_name;
-        $this->value=($p_value==null)?$this->value:$p_value;
-        if ( $this->readOnly==true) return $this->display();
-
-               $this->id=($this->id=="")?$this->name:$this->id;
-
-
-        $r=sprintf("
-                   <INPUT class=\"smallbutton\" TYPE=\"button\" 
onClick=\"search_action(".dossier::id().",'%s')\" value=\"?\">
-                   <INPUT TYPE=\"text\"  
style=\"color:black;background:lightyellow;border:solid 1px grey;\"  
NAME=\"%s\" ID=\"%s\" VALUE=\"%s\" SIZE=\"8\" readonly>
-                                  <INPUT class=\"smallbutton\"  
TYPE=\"button\" onClick=\"$('%s').value=''\" value=\"X\">
-
-                   ",
-                   $this->id,
-                   $this->name,
-                   $this->id,
-                   $this->value,
-                   $this->id
-                  );
-        return $r;
-    }
-    /*!\brief print in html the readonly value of the widget*/
-    public function display()
-    {
-        $r=sprintf("<span><b>%s</b></span>",$this->value);
-        $r.=sprintf('<input type="hidden" name="%s" value="%s">', 
$this->name,$this->value);
-        return $r;
-
-    }
-    static public function test_me()
-    {
-    }
-}
diff --git a/include/class_iselect.php b/include/class_iselect.php
deleted file mode 100644
index 2ae8b3d..0000000
--- a/include/class_iselect.php
+++ /dev/null
@@ -1,76 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief Html Input
- * @see Database::make_array
- */
-require_once NOALYSS_INCLUDE.'/class_html_input.php';
-class ISelect extends HtmlInput
-{
-    /*!\brief show the html  input of the widget*/
-    public function input($p_name=null,$p_value=null)
-    {
-        $this->name=($p_name==null)?$this->name:$p_name;
-        $this->value=($p_value==null)?$this->value:$p_value;
-        if ( $this->readOnly==true) return $this->display();
-        $style=(isset($this->style))?$this->style:"";
-               $this->id=($this->id=="")?$this->name:$this->id;
-
-        $disabled=($this->disabled==true)?"disabled":"";
-        $rowsize = (isset ($this->rowsize)) ? ' size = 
"'.$this->rowsize.'"':"";
-        $r="";
-
-        $a="<SELECT  id=\"$this->id\" NAME=\"$this->name\" $style 
$this->javascript $disabled $rowsize>";
-
-        if (empty($this->value)) return '';
-        for ( $i=0;$i<sizeof($this->value);$i++)
-        {
-            
$checked=($this->selected==$this->value[$i]['value'])?"SELECTED":"";
-            $a.='<OPTION VALUE="'.$this->value[$i]['value'].'" '.$checked.'>';
-            $a.=$this->value[$i]['label'];
-        }
-        $a.="</SELECT>";
-        if ( $this->table == 1 )                 $a='<td>'.$a.'</td>';
-
-        return $r.$a;
-    }
-    /*!\brief print in html the readonly value of the widget*/
-    public function display()
-    {
-        $r="";
-        for ( $i=0;$i<sizeof($this->value);$i++)
-        {
-            if ($this->selected==$this->value[$i]['value'] )
-            {
-                $r=h($this->value[$i]['label']);
-
-            }
-        }
-               if ( $this->table == 1 )                  $a='<td>'.$r.'</td>';
-        return $r;
-    }
-
-
-    static public function test_me()
-    {
-    }
-}
diff --git a/include/class_ispan.php b/include/class_ispan.php
deleted file mode 100644
index 2d54990..0000000
--- a/include/class_ispan.php
+++ /dev/null
@@ -1,53 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief Html Input
- */
-require_once NOALYSS_INCLUDE.'/class_html_input.php';
-class ISpan extends HtmlInput
-{
-    public function __construct($p_name="",$p_value="")
-    {
-        parent::__construct($p_name,$p_value);
-        $this->style="display:inline";
-
-    }
-    /*!\brief show the html  input of the widget, the span is always readonly 
*/
-    public function input($p_name=null,$p_value=null)
-    {
-        $this->name=($p_name==null)?$this->name:$p_name;
-        $this->value=($p_value==null)?$this->value:$p_value;
-
-
-        $r=sprintf('<span style="%s" id="%s">%s </span>',
-                   $this->style,
-                   $this->name,
-                   $this->value
-                  );
-
-        return $r;
-    }
-
-    static public function test_me()
-    {
-    }
-}
diff --git a/include/class_itext.php b/include/class_itext.php
deleted file mode 100644
index 62fc6c1..0000000
--- a/include/class_itext.php
+++ /dev/null
@@ -1,98 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief Html Input
- */
-require_once NOALYSS_INCLUDE.'/class_html_input.php';
-class IText extends HtmlInput
-{
-    function __construct($name='',$value='',$p_id="")
-    {
-        parent::__construct($name,$value,$p_id);
-        $this->style=' class="input_text" ';
-    }
-    /*!\brief show the html  input of the widget*/
-    public function input($p_name=null,$p_value=null)
-    {
-        $this->name=($p_name==null)?$this->name:$p_name;
-        $this->value=($p_value==null)?$this->value:$p_value;
-        if ( $this->readOnly==true) return $this->display();
-               $this->id=($this->id=="")?$this->name:$this->id;
-
-        $t= ((isset($this->title)))?'title="'.$this->title.'"   ':' ';
-
-        $extra=(isset($this->extra))?$this->extra:"";
-
-        $this->value=str_replace('"','',$this->value);
-        if ( ! isset ($this->css_size))
-        {
-        $r='<INPUT '.$this->style.' TYPE="TEXT" id="'.
-           $this->id.'"'.$t.
-           'NAME="'.$this->name.'" VALUE="'.$this->value.'"  '.
-           'SIZE="'.$this->size.'" '.$this->javascript."  $this->extra >";
-        /* add tag for column if inside a table */
-        } else {
-           $r='<INPUT '.$this->style.' TYPE="TEXT" id="'.
-           $this->id.'"'.$t.
-           'NAME="'.$this->name.'" VALUE="'.$this->value.'"  '.
-           ' style="width:'.$this->css_size.';" '.$this->javascript."  
$this->extra >";
-
-        }
-
-        if ( $this->table == 1 )                 $r='<td>'.$r.'</td>';
-
-        return $r;
-
-    }
-    /*!\brief print in html the readonly value of the widget*/
-    public function display()
-    {
-        $t= ((isset($this->title)))?'title="'.$this->title.'"   ':' ';
-
-        $extra=(isset($this->extra))?$this->extra:"";
-
-        $readonly=" readonly ";
-        $this->value=str_replace('"','',$this->value);
-                $this->style=' class="input_text_ro" ';
-         if ( ! isset ($this->css_size))
-        {
-        $r='<INPUT '.$this->style.' TYPE="TEXT" id="'.
-           $this->id.'"'.$t.
-           'NAME="'.$this->name.'" VALUE="'.$this->value.'"  '.
-           'SIZE="'.$this->size.'" '.$this->javascript." $readonly 
$this->extra >";
-        } else {
-               $r='<INPUT '.$this->style.' TYPE="TEXT" id="'.
-           $this->id.'"'.$t.
-           'NAME="'.$this->name.'" VALUE="'.$this->value.'"  '.
-           ' style="width:'.$this->css_size.'" '.$this->javascript." $readonly 
 $this->extra >";
-        }
-
-        /* add tag for column if inside a table */
-        if ( $this->table == 1 )                 $r='<td>'.$r.'</td>';
-
-        return $r;
-
-    }
-    static public function test_me()
-    {
-    }
-}
diff --git a/include/class_itextarea.php b/include/class_itextarea.php
deleted file mode 100644
index 562adc2..0000000
--- a/include/class_itextarea.php
+++ /dev/null
@@ -1,61 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief Html Input
- */
-require_once NOALYSS_INCLUDE.'/class_html_input.php';
-class ITextarea extends HtmlInput
-{
-    /*!\brief show the html  input of the widget*/
-    public function input($p_name=null,$p_value=null)
-    {
-        $this->name=($p_name==null)?$this->name:$p_name;
-        $this->value=($p_value==null)?$this->value:$p_value;
-       if ( !isset ($this->style )) $this->style=' class="itextarea" ';
-       $this->id=($this->id=="")?$this->name:$this->id;
-
-        if ( $this->readOnly==true) return $this->display();
-
-        $r="";
-        $r.='<TEXTAREA '.$this->style.'  name="'.$this->name.'" 
id="'.$this->id.'"';
-        $r.='>';
-        $r.=$this->value;
-
-        $r.="</TEXTAREA>";
-        return $r;
-    }
-
-
-    /*!\brief print in html the readonly value of the widget*/
-    public function display()
-    {
-        $r='<p>';
-        $r.=h($this->value);
-        $r.=sprintf('<input type="hidden" name="%s" value="%s">',
-                    $this->name,h($this->value));
-        $r.='</p>';
-
-    }
-    static public function test_me()
-    {
-    }
-}
diff --git a/include/class_itva_popup.php b/include/class_itva_popup.php
deleted file mode 100644
index 36bf1ba..0000000
--- a/include/class_itva_popup.php
+++ /dev/null
@@ -1,177 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief Html Input
- */
-require_once  NOALYSS_INCLUDE.'/class_ipopup.php';
-require_once NOALYSS_INCLUDE.'/class_ibutton.php';
-require_once NOALYSS_INCLUDE.'/class_ispan.php';
-/**
- address@hidden let you choose a TVA in a popup
- address@hidden
-    $a=new IPopup('popup_tva');
-    $a->set_title('Choix de la tva');
-    echo $a->input();
-    $tva=new ITva_Popup("tva1");
-    $tva->with_button(true);
-    // You must add the attributes gDossier, popup
-    $tva->set_attribute('popup','popup_tva');
-    $tva->set_attribute('gDossier',dossier::id());
-
-    // We can add a label for the code
-    $tva->add_label('code');
-    $tva->js='onchange="set_tva_label(this);"';
-    echo $tva->input();
address@hidden
-*/
-class ITva_Popup extends HtmlInput
-{
-    /**
-     address@hidden by default, the p_name is the name/id of the input type
-     * the this->button is false (control if a button is visible) and
-     * this->in_table=false (return the widget inside a table)
-     * this->code is a span widget to display the code (in this case, you will
-     * to set this->cn as database connexion)
-     * to have its own javascript for the button you can use 
this->but_javascript)
-     * by default it is 'popup_select_tva(this)';
-     */
-    public function __construct($p_name=null,$p_value="",$p_id="")
-    {
-        $this->name=$p_name;
-        $this->button=true;
-        $this->in_table=false;
-               $this->value=$p_value;
-               $this->id=$p_id;
-    }
-    function with_button($p)
-    {
-        if ($p == true )
-            $this->button=true;
-        else
-            $this->button=false;
-    }
-    /*!\brief show the html  input of the widget*/
-    public function input($p_name=null,$p_value=null)
-    {
-        $this->name=($p_name==null)?$this->name:$p_name;
-        $this->value=($p_value==null)?$this->value:$p_value;
-        
$this->js=(isset($this->js))?$this->js:'onchange="format_number(this);"';
-               $this->id=($this->id=="")?$this->name:$this->id;
-
-        if ( $this->readOnly==true) return $this->display();
-
-        $str='<input type="TEXT"  class="input_text" name="%s" value="%s" 
id="%s" size="3" %s>';
-        $r=sprintf($str,$this->name,$this->value,$this->id,$this->js);
-
-        if ($this->in_table)
-            $table='<table>'.'<tr>'.td($r);
-
-        if ( $this->button==true && ! $this->in_table)
-            $r.=$this->dbutton();
-
-        if ( $this->button==true &&  $this->in_table)
-            $r=$table.td($this->dbutton()).'</tr></table>';
-
-        if ( isset($this->code))
-        {
-            if ( $this->cn != NULL)
-            {
-                /* check if tva_id == integer */
-                if (trim($this->value)!='' &&  isNumber($this->value)==1 && 
strpos($this->value,',') === false)
-                    $this->code->value=$this->cn->get_value('select tva_label 
from tva_rate where tva_id=$1',
-                                                            
array($this->value));
-                ;
-            }
-            $r.=$this->code->input();
-            if ($this->table==1) $r=td($r);
-            $this->set_attribute('jcode',$this->code->name);
-            $this->set_attribute('gDossier',dossier::id());
-            $this->set_attribute('ctl',$this->name);
-            $r.=$this->get_js_attr();
-
-        }
-
-        return $r;
-
-    }
-    /**
-     address@hidden show a button, if it is pushed show a popup to select the 
need vat
-     address@hidden
-     * - a ipopup must be created before with the name popup_tva
-     * - the javascript scripts.js must be loaded
-     address@hidden string with html code
-     */
-    function dbutton()
-    {
-        if( trim($this->name)=='') throw new Exception (_('Le nom ne peut être 
vide'));
-               $this->id=($this->id=="")?$this->name:$this->id;
-
-        // button
-        $bt=new ISmallButton('bt_'.$this->id);
-               $bt->tabindex="-1";
-        $bt->label=_(' TVA ');
-        $bt->set_attribute('gDossier',dossier::id());
-        $bt->set_attribute('ctl',$this->id);
-        $bt->set_attribute('popup','popup_tva');
-        if ( isset($this->code))
-            $bt->set_attribute('jcode',$this->code->name);
-        if ( isset($this->compute))
-            $bt->set_attribute('compute',$this->compute);
-        
$bt->javascript=(isset($this->but_javascript))?$this->but_javascript:'popup_select_tva(this)';
-        $r=$bt->input();
-        return $r;
-    }
-
-    /*!\brief print in html the readonly value of the widget*/
-    public function display()
-    {
-        $cn=  new Database(Dossier::id());
-        $tva=new Acc_Tva($cn, $this->value);
-        
-        $comment=($tva->load()  != "-1")? $tva->tva_label:"";
-       $res=sprintf('<input type="text" name="%s" size="6" 
class="input_text_ro" value="%s" id="%s" 
readonly="">%s',$this->name,$this->value,$this->name,$comment);
-        return $res;
-    }
-    /**
-     address@hidden add a field to show the selected tva's label
-     address@hidden $p_code is the name of the label where you can see the 
label of VAT
-     address@hidden $p_cn is a database connection if NULL it doesn't seek in 
the database
-     */
-    public function add_label($p_code,$p_cn=null)
-    {
-        $this->cn=$p_cn;
-        $this->code=new ISpan($p_code);
-    }
-    static public function test_me()
-    {
-        $a=new IPopup('popup_tva');
-        $a->set_title('Choix de la tva');
-        echo $a->input();
-        $tva=new ITva_Popup("tva1");
-        $tva->with_button(true);
-        // We can add a label for the code
-        $tva->add_label('code');
-        $tva->js='onchange="set_tva_label(this);"';
-        echo $tva->input();
-        echo $tva->dbutton();
-    }
-}
diff --git a/include/class_jrn_def_sql.php b/include/class_jrn_def_sql.php
deleted file mode 100644
index 3008f3c..0000000
--- a/include/class_jrn_def_sql.php
+++ /dev/null
@@ -1,408 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-// Copyright Author Dany De Bontridder address@hidden
-
-/**
- * @file
- * @brief Manage the table public.jrn_def
- *
- *
-  Example
-  @code
-
-  @endcode
- */
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/ac_common.php';
-
-/**
- * @brief Manage the table public.jrn_def
- */
-class Jrn_Def_sql
-{
-       /* example private 
$variable=array("easy_name"=>column_name,"email"=>"column_name_email","val3"=>0);
 */
-
-       protected $variable = array(
-               "jrn_def_id" => "jrn_def_id",
-               "jrn_def_name" => "jrn_def_name"
-               , "jrn_def_class_deb" => "jrn_def_class_deb"
-               , "jrn_def_class_cred" => "jrn_def_class_cred"
-               , "jrn_def_fiche_deb" => "jrn_def_fiche_deb"
-               , "jrn_def_fiche_cred" => "jrn_def_fiche_cred"
-               , "jrn_deb_max_line" => "jrn_deb_max_line"
-               , "jrn_cred_max_line" => "jrn_cred_max_line"
-               , "jrn_def_ech" => "jrn_def_ech"
-               , "jrn_def_ech_lib" => "jrn_def_ech_lib"
-               , "jrn_def_type" => "jrn_def_type"
-               , "jrn_def_code" => "jrn_def_code"
-               , "jrn_def_pj_pref" => "jrn_def_pj_pref"
-               , "jrn_def_bank" => "jrn_def_bank"
-               , "jrn_def_num_op" => "jrn_def_num_op"
-               , "jrn_def_description" => "jrn_def_description"
-       );
-
-       function __construct(& $p_cn, $p_id=-1)
-       {
-               $this->db = $p_cn;
-               $this->jrn_def_id = $p_id;
-
-               if ($p_id == -1)
-               {
-                       /* Initialize an empty object */
-                       foreach ($this->variable as $key => $value)
-                               $this->$value = null;
-                       $this->jrn_def_id = $p_id;
-               }
-               else
-               {
-                       /* load it */
-
-                       $this->load();
-               }
-       }
-
-       public function get_parameter($p_string)
-       {
-               if (array_key_exists($p_string, $this->variable))
-               {
-                       $idx = $this->variable[$p_string];
-                       return $this->$idx;
-               }
-               else
-                       throw new Exception(__FILE__ . ":" . __LINE__ . 
$p_string . 'Erreur attribut inexistant');
-       }
-
-       public function set_parameter($p_string, $p_value)
-       {
-               if (array_key_exists($p_string, $this->variable))
-               {
-                       $idx = $this->variable[$p_string];
-                       $this->$idx = $p_value;
-               }
-               else
-                       throw new Exception(__FILE__ . ":" . __LINE__ . 
$p_string . 'Erreur attribut inexistant');
-       }
-
-       public function get_info()
-       {
-               return var_export($this, true);
-       }
-
-       public function verify_sql()
-       {
-               // Verify that the elt we want to add is correct
-               /* verify only the datatype */
-               if (trim($this->jrn_def_name) == '')
-                       $this->jrn_def_name = null;
-               if (trim($this->jrn_def_class_deb) == '')
-                       $this->jrn_def_class_deb = null;
-               if (trim($this->jrn_def_class_cred) == '')
-                       $this->jrn_def_class_cred = null;
-               if (trim($this->jrn_def_fiche_deb) == '')
-                       $this->jrn_def_fiche_deb = null;
-               if (trim($this->jrn_def_fiche_cred) == '')
-                       $this->jrn_def_fiche_cred = null;
-               if (trim($this->jrn_deb_max_line) == '')
-                       $this->jrn_deb_max_line = null;
-               if ($this->jrn_deb_max_line !== null && 
settype($this->jrn_deb_max_line, 'float') == false)
-                       throw new Exception('DATATYPE jrn_deb_max_line 
$this->jrn_deb_max_line non numerique');
-               if (trim($this->jrn_cred_max_line) == '')
-                       $this->jrn_cred_max_line = null;
-               if ($this->jrn_cred_max_line !== null && 
settype($this->jrn_cred_max_line, 'float') == false)
-                       throw new Exception('DATATYPE jrn_cred_max_line 
$this->jrn_cred_max_line non numerique');
-               if (trim($this->jrn_def_ech) == '')
-                       $this->jrn_def_ech = null;
-               if (trim($this->jrn_def_ech_lib) == '')
-                       $this->jrn_def_ech_lib = null;
-               if (trim($this->jrn_def_type) == '')
-                       $this->jrn_def_type = null;
-               if (trim($this->jrn_def_code) == '')
-                       $this->jrn_def_code = null;
-               if (trim($this->jrn_def_pj_pref) == '')
-                       $this->jrn_def_pj_pref = null;
-               if (trim($this->jrn_def_bank) == '')
-                       $this->jrn_def_bank = null;
-               if ($this->jrn_def_bank !== null && 
settype($this->jrn_def_bank, 'float') == false)
-                       throw new Exception('DATATYPE jrn_def_bank 
$this->jrn_def_bank non numerique');
-               if (trim($this->jrn_def_num_op) == '')
-                       $this->jrn_def_num_op = null;
-               if ($this->jrn_def_num_op !== null && 
settype($this->jrn_def_num_op, 'float') == false)
-                       throw new Exception('DATATYPE jrn_def_num_op 
$this->jrn_def_num_op non numerique');
-       }
-
-       public function save($p_string='')
-       {
-               /* please adapt */
-               if ($this->jrn_def_id == -1)
-                       $this->insert();
-               else
-                       $this->update();
-       }
-
-       /**
-        * @brief retrieve array of object thanks a condition
-        * @param $cond condition (where clause) (optional by default all the 
rows are fetched)
-        * you can use this parameter for the order or subselect
-        * @param $p_array array for the SQL stmt
-        * @see Database::exec_sql get_object  Database::num_row
-        * @return the return value of exec_sql
-        */
-       public function seek($cond='', $p_array=null)
-       {
-               $sql = "select * from public.jrn_def  $cond";
-               $aobj = array();
-               $ret = $this->db->exec_sql($sql, $p_array);
-               return $ret;
-       }
-
-       /**
-        * get_seek return the next object, the return of the query must have 
all the column
-        * of the object
-        * @param $p_ret is the return value of an exec_sql
-        * @param $idx is the index
-        * @see seek
-        * @return object
-        */
-       public function get_object($p_ret, $idx)
-       {
-               // map each row in a object
-               $oobj = new Jrn_Def_sql($this->db);
-               $array = Database::fetch_array($p_ret, $idx);
-               foreach ($array as $idx => $value)
-               {
-                       $oobj->$idx = $value;
-               }
-               return $oobj;
-       }
-
-       public function insert($p_array=null)
-       {
-               if ($this->verify_sql() != 0)
-                       return;
-               if ($this->jrn_def_id == -1)
-               {
-                       /*  please adapt */
-                       $sql = "insert into public.jrn_def(jrn_def_name
-,jrn_def_class_deb
-,jrn_def_class_cred
-,jrn_def_fiche_deb
-,jrn_def_fiche_cred
-,jrn_deb_max_line
-,jrn_cred_max_line
-,jrn_def_ech
-,jrn_def_ech_lib
-,jrn_def_type
-,jrn_def_code
-,jrn_def_pj_pref
-,jrn_def_bank
-,jrn_def_num_op
-,jrn_def_description
-) values ($1
-,$2
-,$3
-,$4
-,$5
-,$6
-,$7
-,$8
-,$9
-,$10
-,$11
-,$12
-,$13
-,$14
-,$15
-) returning jrn_def_id";
-
-                       $this->jrn_def_id = $this->db->get_value(
-                                       $sql, array($this->jrn_def_name
-                               , $this->jrn_def_class_deb
-                               , $this->jrn_def_class_cred
-                               , $this->jrn_def_fiche_deb
-                               , $this->jrn_def_fiche_cred
-                               , $this->jrn_deb_max_line
-                               , $this->jrn_cred_max_line
-                               , $this->jrn_def_ech
-                               , $this->jrn_def_ech_lib
-                               , $this->jrn_def_type
-                               , $this->jrn_def_code
-                               , $this->jrn_def_pj_pref
-                               , $this->jrn_def_bank
-                               , $this->jrn_def_num_op
-                               , strip_tags($this->jrn_def_description)
-                                       )
-                       );
-               }
-               else
-               {
-                       $sql = "insert into public.jrn_def(jrn_def_name
-,jrn_def_class_deb
-,jrn_def_class_cred
-,jrn_def_fiche_deb
-,jrn_def_fiche_cred
-,jrn_deb_max_line
-,jrn_cred_max_line
-,jrn_def_ech
-,jrn_def_ech_lib
-,jrn_def_type
-,jrn_def_code
-,jrn_def_pj_pref
-,jrn_def_bank
-,jrn_def_num_op
-,jrn_def_id
-,jrn_def_description) values ($1
-,$2
-,$3
-,$4
-,$5
-,$6
-,$7
-,$8
-,$9
-,$10
-,$11
-,$12
-,$13
-,$14
-,$15
-,$16
-) returning jrn_def_id";
-
-                       $this->jrn_def_id = $this->db->get_value(
-                                       $sql, array($this->jrn_def_name
-                               , $this->jrn_def_class_deb
-                               , $this->jrn_def_class_cred
-                               , $this->jrn_def_fiche_deb
-                               , $this->jrn_def_fiche_cred
-                               , $this->jrn_deb_max_line
-                               , $this->jrn_cred_max_line
-                               , $this->jrn_def_ech
-                               , $this->jrn_def_ech_lib
-                               , $this->jrn_def_type
-                               , $this->jrn_def_code
-                               , $this->jrn_def_pj_pref
-                               , $this->jrn_def_bank
-                               , $this->jrn_def_num_op
-                               , $this->jrn_def_id
-                                , strip_tags($this->jrn_def_description))
-                       );
-               }
-       }
-
-       public function update($p_string='')
-       {
-               if ($this->verify_sql() != 0)
-                       return;
-               /*   please adapt */
-               $sql = " update public.jrn_def set jrn_def_name = $1
-,jrn_def_class_deb = $2
-,jrn_def_class_cred = $3
-,jrn_def_fiche_deb = $4
-,jrn_def_fiche_cred = $5
-,jrn_deb_max_line = $6
-,jrn_cred_max_line = $7
-,jrn_def_ech = $8
-,jrn_def_ech_lib = $9
-,jrn_def_type = $10
-,jrn_def_code = $11
-,jrn_def_pj_pref = $12
-,jrn_def_bank = $13
-,jrn_def_num_op = $14
-,jrn_def_description = $15
- where jrn_def_id= $16";
-               $res = $this->db->exec_sql(
-                               $sql, array($this->jrn_def_name
-                       , $this->jrn_def_class_deb
-                       , $this->jrn_def_class_cred
-                       , $this->jrn_def_fiche_deb
-                       , $this->jrn_def_fiche_cred
-                       , $this->jrn_deb_max_line
-                       , $this->jrn_cred_max_line
-                       , $this->jrn_def_ech
-                       , $this->jrn_def_ech_lib
-                       , $this->jrn_def_type
-                       , $this->jrn_def_code
-                       , $this->jrn_def_pj_pref
-                       , $this->jrn_def_bank
-                       , $this->jrn_def_num_op
-                       , strip_tags($this->jrn_def_description)
-                       , $this->jrn_def_id)
-               );
-       }
-
-       /**
-        * @brief load a object
-        * @return 0 on success -1 the object is not found
-        */
-       public function load()
-       {
-
-               $sql = "select jrn_def_name
-,jrn_def_class_deb
-,jrn_def_class_cred
-,jrn_def_fiche_deb
-,jrn_def_fiche_cred
-,jrn_deb_max_line
-,jrn_cred_max_line
-,jrn_def_ech
-,jrn_def_ech_lib
-,jrn_def_type
-,jrn_def_code
-,jrn_def_pj_pref
-,jrn_def_bank
-,jrn_def_num_op
-,jrn_def_description
- from public.jrn_def where jrn_def_id=$1";
-               /* please adapt */
-               $res = $this->db->get_array(
-                               $sql, array($this->jrn_def_id)
-               );
-
-               if (count($res) == 0)
-               {
-                       /* Initialize an empty object */
-                       foreach ($this->variable as $key => $value)
-                               $this->$key = '';
-
-                       return -1;
-               }
-               foreach ($res[0] as $idx => $value)
-               {
-                       $this->$idx = $value;
-               }
-               return 0;
-       }
-
-       public function delete()
-       {
-               $sql = "delete from public.jrn_def where jrn_def_id=$1";
-               $res = $this->db->exec_sql($sql, array($this->jrn_def_id));
-       }
-
-       /**
-        * Unit test for the class
-        */
-       static function test_me()
-       {
-       }
-
-}
-
-// Jrn_Def_sql::test_me();
-?>
diff --git a/include/class_lettering.php b/include/class_lettering.php
deleted file mode 100644
index 9b5d769..0000000
--- a/include/class_lettering.php
+++ /dev/null
@@ -1,760 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief letter the accounting entry (row level)
- */
-require_once  NOALYSS_INCLUDE.'/class_user.php';
-
-/**
- address@hidden mother class for the lettering by account and by card
- * use the tables jnt_letter, letter_deb and letter_cred
- * - "account"=>"account",       => the accounting of the j_id (use by 
Lettering_Account)
- * - "quick_code"=>"quick_code", => the quick_code of the j_id (used by 
Lettering_Card)
- * - "start"=>"start",    => date of the first day
- * - "end"=>"end",                => date of the last day
- * - "sql_ledger"=>"sql_ledger"  => the sql clause to filter on the available 
ledgers
-*/
-class Lettering
-{
-
-    protected $variable=array("account"=>"account", /* the accounting of the 
j_id (use by Lettering_Account) */
-                              "quick_code"=>"quick_code", /* the quick_code of 
the j_id (used by Lettering_Card) */
-                              "start"=>"start",                /* date of the 
first day */
-                              "end"=>"end",            /* date of the last day 
*/
-                              "sql_ledger"=>"sql_ledger"       /*   the sql 
clause to filter on the available ledgers */
-                             )
-                        ;
-    /**
-     * constructor
-     address@hidden $p_init resource to database
-     address@hidden by default start and end are the 1.1.exercice to 
31.12.exercice
-     */
-    function __construct ($p_init)
-    {
-        $this->db=$p_init;
-        $a=new User($p_init);
-        $exercice=$a->get_exercice();
-        $this->start='01.01.'.$exercice;
-        $this->end='31.12.'.$exercice;
-        // available ledgers
-        
$this->sql_ledger=str_replace('jrn_def_id','jr_def_id',$a->get_ledger_sql('ALL',3));
-
-    }
-    public function get_parameter($p_string)
-    {
-        if ( array_key_exists($p_string,$this->variable) )
-        {
-            $idx=$this->variable[$p_string];
-            return $this->$idx;
-        }
-        else
-            throw new Exception (__FILE__.":".__LINE__.$p_string.'Erreur 
attribut inexistant');
-    }
-    public function set_parameter($p_string,$p_value)
-    {
-        if ( array_key_exists($p_string,$this->variable) )
-        {
-            $idx=$this->variable[$p_string];
-            $this->$idx=$p_value;
-        }
-        else
-            throw new Exception (__FILE__.":".__LINE__.$p_string.'Erreur 
attribut inexistant');
-    }
-    /**
-     *Use to just insert a couple of lettered operation
-     */
-    function insert_couple($j_id1,$j_id2)
-    {
-
-        /*  take needed data */
-        $first=$this->db->get_value('select j_debit from jrnx where 
j_id=$1',array($j_id1));
-        if ( $this->db->count() == 0 ) throw new Exception ('Opération non 
existante');
-
-        $second=$this->db->get_value('select j_debit from jrnx where 
j_id=$1',array($j_id2));
-        if ( $this->db->count() == 0 ) throw new Exception ('Opération non 
existante');
-               $sql_already="select distinct(jl_id)
-                       from jnt_letter
-                       left outer join letter_deb using (jl_id)
-                       left outer join letter_cred using (jl_id)
-                       where
-                       letter_deb.j_id = $1 or letter_cred.j_id=$1";
-               $let1=0;$let2=0;
-               $already=$this->db->get_array($sql_already,array($j_id1));
-               if ( count ($already ) > 0) {
-                       if ( count($already)==1) {
-                               // retrieve the letter
-                               $let1=$this->db->get_value("select 
distinct(jl_id)
-                                                                               
from jnt_letter
-                                                                               
left outer join letter_deb using (jl_id)
-                                                                               
left outer join letter_cred using (jl_id)
-                                                                               
where
-                                                                               
letter_deb.j_id = $1 or letter_cred.j_id=$1",array($j_id1));
-                       }else
-                       {
-                               return;
-                       }
-               }
-
-               $already=$this->db->get_array($sql_already,array($j_id2));
-               if ( count ($already ) > 0) {
-                       if ( count($already)==1) {
-                               // retrieve the letter
-                               $let2=$this->db->get_value("select 
distinct(jl_id)
-                                                                               
from jnt_letter
-                                                                               
left outer join letter_deb using (jl_id)
-                                                                               
left outer join letter_cred using (jl_id)
-                                                                               
where
-                                                                               
letter_deb.j_id = $1 or letter_cred.j_id=$1",array($j_id2));
-                       }else  {
-                               return;
-                       }
-               }
-               $jl_id=0;
-               // already linked together
-               if ( $let1 != 0 && $let1 == $let2 )return;
-
-               // already linked
-               if ( $let1 != 0 && $let2!=0 && $let1 != $let2 )return;
-
-               // none is linked
-               if ( $let1 == 0 && $let2==0)
-               {
-                       $jl_id=$this->db->get_next_seq("jnt_letter_jl_id_seq");
-                       $this->db->exec_sql('insert into jnt_letter(jl_id) 
values($1)',
-                                                               array($jl_id));
-               }
-               // one is linked but not the other
-               if ( $let1 == 0 && $let2 != 0 ) $jl_id=$let2;
-               if ( $let1 != 0 && $let2 == 0 ) $jl_id=$let1;
-
-               /* insert */
-        if ( $first == 't')
-        {
-            // save into letter_deb
-            if ($let1 == 0) $ld_id=$this->db->get_value('insert into 
letter_deb(j_id,jl_id) values($1,$2) returning ld_id',array($j_id1,$jl_id));
-        }
-        else
-        {
-            if ($let1 == 0)$lc_id=$this->db->get_value('insert into 
letter_cred(j_id,jl_id)  values($1,$2) returning lc_id',array($j_id1,$jl_id));
-        }
-        if ( $second == 't')
-        {
-            // save into letter_deb
-            if ($let2 == 0)$ld_id=$this->db->get_value('insert into 
letter_deb(j_id,jl_id) values($1,$2) returning ld_id',array($j_id2,$jl_id));
-        }
-        else
-        {
-            if ($let2 == 0)$lc_id=$this->db->get_value('insert into 
letter_cred(j_id,jl_id)  values($1,$2) returning lc_id',array($j_id2,$jl_id));
-        }
-
-    }
-    public function get_info()
-    {
-        return var_export(self::$variable,true);
-    }
-    public function verify()
-    {
-        // Verify that the elt we want to add is correct
-    }
-    /**
-     address@hidden save from array
-     address@hidden $p_array
-    @code
-    'gDossier' => string '13' (length=2)
-    'letter_j_id' =>
-       ck => array
-    @endcode
-    */
-    public function save($p_array)
-    {
-        if ( ! isset ($p_array['letter_j_id'])) return;
-        $this->db->exec_sql('delete from jnt_letter where 
jl_id=$1',array($p_array['jnt_id']));
-
-        $this->db->start();
-        $jl_id=$this->db->get_next_seq("jnt_letter_jl_id_seq");
-        $this->db->exec_sql('insert into jnt_letter(jl_id) values($1)',
-                            array($jl_id));
-
-        // save the source
-        $deb=$this->db->get_value('select j_debit,j_montant from jrnx where 
j_id=$1',array($p_array['j_id']));
-        if ( $deb == 't')
-        {
-            // save into letter_deb
-            $ld_id=$this->db->get_value('insert into letter_deb(j_id,jl_id) 
values($1,$2) returning ld_id',array($p_array['j_id'],$jl_id));
-        }
-        else
-        {
-            $lc_id=$this->db->get_value('insert into letter_cred(j_id,jl_id)  
values($1,$2) returning lc_id',array($p_array['j_id'],$jl_id));
-        }
-        $count=0;
-        // save dest
-        for($i=0;$i<count($p_array['letter_j_id']);$i++)
-        {
-            if (isset ($p_array['ck'][$i]) && $p_array['ck'][$i] !="-2")
-            { //if 1
-                // save the dest
-                $deb=$this->db->get_value('select j_debit,j_montant from jrnx 
where j_id=$1',array($p_array['ck'][$i]));
-                if ( $deb == 't')
-                {
-                    $count++;
-                    // save into letter_deb
-                    $ld_id=$this->db->get_value('insert into 
letter_deb(j_id,jl_id) values($1,$2) returning 
ld_id',array($p_array['ck'][$i],$jl_id));
-                }
-                else
-                {
-                    $count++;
-                    $lc_id=$this->db->get_value('insert into 
letter_cred(j_id,jl_id)  values($1,$2) returning 
lc_id',array($p_array['ck'][$i],$jl_id));
-                }
-            } //end if 1
-        } //end for
-        // save into jnt_letter
-        /* if only one row we delete the joint */
-        if ( $count==0)
-        {
-            $this->db->rollback();
-        }
-        $this->db->commit();
-    }
-    /**
-     address@hidden retrieve * row thanks a condition
-     */
-    public function seek($cond,$p_array=null)
-    {
-        /*
-          $sql="select * from * where $cond";
-          return $this->cn->get_array($cond,$p_array)
-        */
-    }
-    public function insert()
-    {
-        if ( $this->verify() != 0 ) return;
-
-    }
-    /**
-     *show all the record from jrnx and their status (linked or not)
-     *it fills the array $this->content
-     */
-    protected function show_all()
-    {
-        $this->get_all();
-        $r="";
-        ob_start();
-        include('template/letter_all.php');
-        $r=ob_get_contents();
-        ob_end_clean();
-        return $r;
-    }
-       function get_linked($p_jlid)
-       {
-               $sql="select j_id,j_date,to_char(j_date,'DD.MM.YYYY') as 
j_date_fmt,
-             j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
-             coalesce(comptaproc.get_letter_jnt(j_id),-1) as letter
-             from jrnx join jrn on (j_grpt = jr_grpt_id)
-                        where
-                        j_id in (select j_id from letter_cred where jl_id=$1
-                                       union all
-                                       select j_id from letter_deb where 
jl_id=$1)
-                                       order by j_date";
-
-               $this->linked=$this->db->get_array($sql,array($p_jlid));
-       }
-    /**
-     *show only the lettered records from jrnx
-     *it fills the array $this->content
-     */
-    protected function show_lettered()
-    {
-        $this->get_letter();
-        $r="";
-        ob_start();
-        include('template/letter_all.php');
-        $r=ob_get_contents();
-        ob_end_clean();
-        return $r;
-    }
-       /**
-     *show only the lettered records from jrnx
-     *it fills the array $this->content
-     */
-    protected function show_lettered_diff()
-    {
-        $this->get_letter_diff();
-        $r="";
-        ob_start();
-        include('template/letter_all.php');
-        $r=ob_get_contents();
-        ob_end_clean();
-        return $r;
-    }
-
-    /**
-     *show only the not lettered records from jrnx
-     *it fills the array $this->content
-     */
-
-    protected function show_not_lettered()
-    {
-        $this->get_unletter();
-        $r="";
-        ob_start();
-        include('template/letter_all.php');
-        $r=ob_get_contents();
-        ob_end_clean();
-        return $r;
-    }
-    /**
-     *wrapper : it call show_all, show_lettered or show_not_lettered depending
-     * of the parameter
-     address@hidden $p_type poss. values are all, unletter, letter
-     */
-    public function show_list($p_type)
-    {
-        switch($p_type)
-        {
-        case 'all':
-                return $this->show_all();
-            break;
-        case 'unletter':
-            return $this->show_not_lettered();
-            break;
-        case 'letter':
-            return $this->show_lettered();
-            break;
-               case 'letter_diff':
-                       return $this->show_lettered_diff();
-                       break;
-        }
-        throw new Exception ("[$p_type] is no unknown");
-    }
-
-    public function show_letter($p_jid)
-    {
-        $j_debit=$this->db->get_value('select j_Debit from jrnx where 
j_id=$1',array($p_jid));
-        $amount_init=$this->db->get_value('select j_montant from jrnx where 
j_id=$1',array($p_jid));
-
-        $this->get_filter($p_jid);
-        // retrieve jnt_letter.id
-        $sql="select distinct(jl_id) from jnt_letter  left outer join 
letter_deb using (jl_id) left outer join letter_cred using (jl_id)
-             where letter_deb.j_id = $1 or letter_cred.j_id=$2";
-        $a_jnt_id=$this->db->get_array($sql,array($p_jid,$p_jid));
-
-        if (count($a_jnt_id)==0 )
-               {
-                       $jnt_id=-2;
-               } else
-               {
-                       $jnt_id=$a_jnt_id[0]['jl_id'];
-               }
-               $this->get_linked($jnt_id);
-        ob_start();
-        require_once NOALYSS_INCLUDE.'/template/letter_prop.php';
-        $r=ob_get_contents();
-        ob_end_clean();
-        $r.=HtmlInput::hidden('j_id',$p_jid);
-        $r.=HtmlInput::hidden('jnt_id',$jnt_id);
-
-        return $r;
-    }
-
-    public function update()
-    {
-        if ( $this->verify() != 0 ) return;
-    }
-
-    public function load()
-{}
-
-    public function delete()
-    {
-        throw new Exception ('delete not implemented');
-    }
-    /**
-     * Unit test for the class
-     */
-    static function test_me()
-    {}
-
-}
-/**
- * only for operation retrieved thanks a account (jrnx.j_poste)
- * manage the accounting entries for a given account
- */
-
-class Lettering_Account extends Lettering
-{
-    function __construct($p_init,$p_account=null)
-    {
-        parent::__construct($p_init);
-        $this->account=$p_account;
-        $this->object_type='account';
-    }
-
-    /**
-     * fills the this->content, datas are filtered thanks
-     * - fil_deb poss values t (debit), f(credit), ' ' (everything)
-     * - fil_amount_max max amount
-     * - fil_amount_min min amount
-     * - $this->start min date
-     * - $this->end max date
-     * - this->account: accounting
-     */
-    public function get_filter($p_jid=0)
-    {
-        $filter_deb='';
-        if (isset($this->fil_deb))
-        {
-            switch ($this->fil_deb)
-            {
-            case 0:
-                $filter_deb=" and j_debit='t' ";
-                break;
-            case 1:
-                $filter_deb=" and j_debit='f' ";
-                break;
-            case 2:
-                $filter_deb=" ";
-                break;
-            }
-
-        }
-        $filter_amount="";
-        if ( isset ($this->fil_amount_max ) &&
-                isset ($this->fil_amount_min ) &&
-                isNumber($this->fil_amount_max)==1 &&
-                isNumber($this->fil_amount_min)==1 &&
-                ($this->fil_amount_max != 0 || $this->fil_amount_min != 0) )
-            $filter_amount=" and (j_montant >= $this->fil_amount_min and 
j_montant<=$this->fil_amount_max  or 
(coalesce(comptaproc.get_letter_jnt($p_jid),-1)= 
coalesce(comptaproc.get_letter_jnt(j_id),-1) and 
coalesce(comptaproc.get_letter_jnt($p_jid),-1) <> -1 )) ";
-        $sql="
-             select j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,
-             j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
-             coalesce(comptaproc.get_letter_jnt(j_id),-1) as letter
-             from jrnx join jrn on (j_grpt = jr_grpt_id)
-             where j_poste = $1 and j_date >= to_date($2,'DD.MM.YYYY') and 
j_date <= to_date ($3,'DD.MM.YYYY')
-             and $this->sql_ledger
-             $filter_deb
-             $filter_amount
-             order by j_date,j_id";
-
-        
$this->content=$this->db->get_array($sql,array($this->account,$this->start,$this->end));
-    }
-
-    /**
-     * fills this->content with all the operation for the 
this->account(jrnx.j_poste)
-     */
-    public function get_all()
-    {
-        $sql=" with let_diff as (select jl_id,deb_amount-cred_amount as 
diff_letter1
-                       from
-                       ( select jl_id,coalesce(sum(j_montant),0) as 
cred_amount from letter_cred join jrnx using (j_id) group by jl_id) as CRED
-                       left join (select jl_id,coalesce(sum(j_montant),0) as 
deb_amount from letter_deb join jrnx using (j_id) group by jl_id) as DEB using 
(jl_id)) ,
-                       letter_jl as (select jl_id,j_id from letter_cred union 
all select jl_id,j_id from letter_deb)
-                       select j_id,j_date,to_char(j_date,'DD.MM.YYYY') as 
j_date_fmt,jr_pj_number,
-                                               
j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
-                                                       
coalesce(let_diff.jl_id,-1) as letter,
-                                       diff_letter1 as letter_diff
-                                               from jrnx join jrn on (j_grpt = 
jr_grpt_id)
-                                               left join letter_jl using (j_id)
-                                               left join let_diff using (jl_id)
-             where j_poste = $1 and j_date >= to_date($2,'DD.MM.YYYY') and 
j_date <= to_date ($3,'DD.MM.YYYY')
-             and $this->sql_ledger
-
-             order by j_date,j_id";
-        
$this->content=$this->db->get_array($sql,array($this->account,$this->start,$this->end));
-    }
-    /**
-     * same as get_all but only for lettered operation
-     */
-    public function get_letter()
-    {
-        $sql="
-                       with let_diff as (select jl_id,deb_amount-cred_amount 
as diff_letter1
-                       from
-                       ( select jl_id,coalesce(sum(j_montant),0) as 
cred_amount from letter_cred join jrnx using (j_id) group by jl_id) as CRED
-                       left join (select jl_id,coalesce(sum(j_montant),0) as 
deb_amount from letter_deb join jrnx using (j_id) group by jl_id) as DEB using 
(jl_id)) ,
-                       letter_jl as (select jl_id,j_id from letter_cred union 
all select jl_id,j_id from letter_deb)
-                       select j_id,j_date,to_char(j_date,'DD.MM.YYYY') as 
j_date_fmt,jr_pj_number,
-                                               
j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
-                                               let_diff.jl_id as letter,
-                                       diff_letter1 as letter_diff
-                                               from jrnx join jrn on (j_grpt = 
jr_grpt_id)
-                                                join letter_jl using (j_id)
-                                               left join let_diff using (jl_id)
-                                       where j_poste = $1 and j_date >= 
to_date($2,'DD.MM.YYYY') and j_date <= to_date ($3,'DD.MM.YYYY')
-             and $this->sql_ledger
-             order by j_date,j_id";
-        
$this->content=$this->db->get_array($sql,array($this->account,$this->start,$this->end));
-    }
-        /**
-     * same as get_all but only for lettered operation
-     */
-    public function get_letter_diff()
-    {
-        $sql="
-            with let_diff as (select jl_id,deb_amount-cred_amount as 
diff_letter1
-                       from
-                       ( select jl_id,coalesce(sum(j_montant),0) as 
cred_amount from letter_cred join jrnx using (j_id) group by jl_id) as CRED
-                       left join (select jl_id,coalesce(sum(j_montant),0) as 
deb_amount from letter_deb join jrnx using (j_id) group by jl_id) as DEB using 
(jl_id)) ,
-                       letter_jl as (select jl_id,j_id from letter_cred union 
all select jl_id,j_id from letter_deb)
-                       select  distinct 
j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,jr_pj_number,
-                                               
j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
-                                               let_diff.jl_id as letter,
-                                       diff_letter1 as letter_diff
-                                               from
-                                               jrnx join jrn on (j_grpt = 
jr_grpt_id)
-                                                join letter_jl using (j_id)
-                                               join let_diff using (jl_id)
-             where j_poste = $1 and j_date >= to_date($2,'DD.MM.YYYY') and 
j_date <= to_date ($3,'DD.MM.YYYY')
-             and $this->sql_ledger
-                        and diff_letter1 <> 0
-             order by j_date,j_id";
-        
$this->content=$this->db->get_array($sql,array($this->account,$this->start,$this->end));
-    }
-    /**
-     * same as get_all but only for unlettered operation
-     */
-
-    public function get_unletter()
-    {
-        $sql="
-                       with letter_jl as (select jl_id,j_id from letter_cred 
union all select jl_id,j_id from letter_deb)
-                       select j_id,j_date,to_char(j_date,'DD.MM.YYYY') as 
j_date_fmt,jr_pj_number,
-                                               
j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
-                                               -1 as letter,
-                                       0 as letter_diff
-                                               from jrnx join jrn on (j_grpt = 
jr_grpt_id)
-             where j_poste = $1 and j_date >= to_date($2,'DD.MM.YYYY') and 
j_date <= to_date ($3,'DD.MM.YYYY')
-             and $this->sql_ledger
-             and j_id not in (select j_id from letter_jl)
-             order by j_date,j_id";
-        
$this->content=$this->db->get_array($sql,array($this->account,$this->start,$this->end));
-    }
-
-}
-/**
- * only for operation retrieved thanks a quick_code
- * manage the accounting entries for a given card
- */
-class Lettering_Card extends Lettering
-{
-    /**
-     *constructor
-     address@hidden $p_init db resource
-     address@hidden $p_qcode quick_code of the jrnx.j_id
-     */
-    function __construct($p_init,$p_qcode=null)
-    {
-        parent::__construct($p_init);
-        $this->quick_code=$p_qcode;
-        $this->object_type='card';
-    }
-    /**
-     * fills the this->content, datas are filtered thanks
-     * - fil_deb poss values t (debit), f(credit), ' ' (everything)
-     * - fil_amount_max max amount
-     * - fil_amount_min min amount
-     * - $this->start min date
-     * - $this->end max date
-     * - this->quick_code: quick_code
-     */
-    public function get_filter($p_jid=0)
-    {
-        $filter_deb='';
-        if (isset($this->fil_deb))
-        {
-            switch ($this->fil_deb)
-            {
-            case 0:
-                $filter_deb=" and j_debit='t' ";
-                break;
-            case 1:
-                $filter_deb=" and j_debit='f' ";
-                break;
-            case 2:
-                $filter_deb=" ";
-                break;
-            }
-
-        }
-        $filter_amount="";
-        if ( isset ($this->fil_amount_max ) &&
-                isset ($this->fil_amount_min ) &&
-                isNumber($this->fil_amount_max)==1 &&
-                isNumber($this->fil_amount_min)==1 &&
-                ($this->fil_amount_max != 0 || $this->fil_amount_min != 0) )
-         $filter_amount=" and (j_montant between $this->fil_amount_min and 
$this->fil_amount_max or (coalesce(comptaproc.get_letter_jnt($p_jid),-1)= 
coalesce(comptaproc.get_letter_jnt(j_id),-1) and 
coalesce(comptaproc.get_letter_jnt($p_jid),-1) <> -1 )) ";
-        $sql="
-            with let_diff as (select jl_id,deb_amount-cred_amount as 
diff_letter1
-                       from
-                       ( select jl_id,coalesce(sum(j_montant),0) as 
cred_amount from letter_cred join jrnx using (j_id) group by jl_id) as CRED
-                       left join (select jl_id,coalesce(sum(j_montant),0) as 
deb_amount from letter_deb join jrnx using (j_id) group by jl_id) as DEB using 
(jl_id)) ,
-                       letter_jl as (select jl_id,j_id from letter_cred union 
all select jl_id,j_id from letter_deb)
-                       select distinct 
j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,jr_pj_number,
-                                               
j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
-                                               coalesce(let_diff.jl_id,-1) as 
letter,
-                                       diff_letter1 as letter_diff
-                                               from jrnx join jrn on (j_grpt = 
jr_grpt_id)
-                                               left join letter_jl using (j_id)
-                                               left join let_diff using (jl_id)
-             where j_qcode = upper($1) and j_date >= to_date($2,'DD.MM.YYYY') 
and j_date <= to_date ($3,'DD.MM.YYYY')
-             and $this->sql_ledger
-             $filter_deb
-             $filter_amount
-             order by j_date,j_id";
-
-        
$this->content=$this->db->get_array($sql,array($this->quick_code,$this->start,$this->end));
-    }
-    /**
-     * fills this->content with all the operation for the 
this->quick_code(j_qcode)
-     */
-    public function get_all()
-    {
-        $sql="
-       with let_diff as (select jl_id,deb_amount-cred_amount as diff_letter1
-                       from
-                       ( select jl_id,coalesce(sum(j_montant),0) as 
cred_amount from letter_cred join jrnx using (j_id) group by jl_id) as CRED
-                       left join (select jl_id,coalesce(sum(j_montant),0) as 
deb_amount from letter_deb join jrnx using (j_id) group by jl_id) as DEB using 
(jl_id)) ,
-                       letter_jl as (select jl_id,j_id from letter_cred union 
all select jl_id,j_id from letter_deb)
-                       select DISTINCT 
j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,jr_pj_number,
-                                               
j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
-                                               coalesce(let_diff.jl_id,-1) as 
letter,
-                                       diff_letter1 as letter_diff
-                                               from jrnx join jrn on (j_grpt = 
jr_grpt_id)
-                                               left join letter_jl using (j_id)
-                                               left join let_diff using (jl_id)
-             where j_qcode = upper($1) and j_date >= to_date($2,'DD.MM.YYYY') 
and j_date <= to_date ($3,'DD.MM.YYYY')
-             and $this->sql_ledger
-
-             order by j_date,j_id";
-        
$this->content=$this->db->get_array($sql,array($this->quick_code,$this->start,$this->end));
-    }
-    /**
-     * same as get_all but only for lettered operation
-     */
-
-    public function get_letter()
-    {
-        $sql="
-    with let_diff as (select jl_id,deb_amount-cred_amount as diff_letter1
-                       from
-                       ( select jl_id,coalesce(sum(j_montant),0) as 
cred_amount from letter_cred join jrnx using (j_id) group by jl_id) as CRED
-                       left join (select jl_id,coalesce(sum(j_montant),0) as 
deb_amount from letter_deb join jrnx using (j_id) group by jl_id) as DEB using 
(jl_id)) ,
-                       letter_jl as (select jl_id,j_id from letter_cred union 
all select jl_id,j_id from letter_deb)
-                       select j_id,j_date,to_char(j_date,'DD.MM.YYYY') as 
j_date_fmt,jr_pj_number,
-                                               
j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
-                                               let_diff.jl_id as letter,
-                                       diff_letter1 as letter_diff
-                                               from jrnx join jrn on (j_grpt = 
jr_grpt_id)
-                                               join letter_jl using (j_id)
-                                               left join let_diff using (jl_id)
-             where j_qcode = upper($1) and j_date >= to_date($2,'DD.MM.YYYY') 
and j_date <= to_date ($3,'DD.MM.YYYY')
-             and $this->sql_ledger
-             order by j_date,j_id";
-        
$this->content=$this->db->get_array($sql,array($this->quick_code,$this->start,$this->end));
-    }
-           public function get_letter_diff()
-    {
-        $sql="
-   with let_diff as (select jl_id,deb_amount-cred_amount as diff_letter1
-                       from
-                       ( select jl_id,coalesce(sum(j_montant),0) as 
cred_amount from letter_cred join jrnx using (j_id) group by jl_id) as CRED
-                       left join (select jl_id,coalesce(sum(j_montant),0) as 
deb_amount from letter_deb join jrnx using (j_id) group by jl_id) as DEB using 
(jl_id)) ,
-                       letter_jl as (select jl_id,j_id from letter_cred union 
all select jl_id,j_id from letter_deb)
-                       select distinct 
j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,jr_pj_number,
-                                               
j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
-                                               let_diff.jl_id as letter,
-                                       diff_letter1 as letter_diff
-                                               from jrnx join jrn on (j_grpt = 
jr_grpt_id)
-                                               left join letter_jl using (j_id)
-                                               left join let_diff using (jl_id)
-             where j_qcode = upper($1) and j_date >= to_date($2,'DD.MM.YYYY') 
and j_date <= to_date ($3,'DD.MM.YYYY')
-             and $this->sql_ledger
-                        and diff_letter1 <>0
-             order by j_date,j_id";
-        
$this->content=$this->db->get_array($sql,array($this->quick_code,$this->start,$this->end));
-    }
-    /**
-     * same as get_all but only for unlettered operation
-     */
-    public function get_unletter()
-    {
-        $sql="
-             select j_id,j_date,to_char(j_date,'DD.MM.YYYY') as 
j_date_fmt,jr_pj_number,
-             j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
-             -1 as letter,
-                        0 as letter_diff
-             from jrnx join jrn on (j_grpt = jr_grpt_id)
-             where j_qcode = upper($1) and j_date >= to_date($2,'DD.MM.YYYY') 
and j_date <= to_date ($3,'DD.MM.YYYY')
-             and $this->sql_ledger
-             and j_id not in (select j_id from letter_deb join jnt_letter 
using (jl_id) union select j_id from letter_cred join jnt_letter using (jl_id) )
-             order by j_date,j_id";
-        
$this->content=$this->db->get_array($sql,array($this->quick_code,$this->start,$this->end));
-    }
-    /**
-     * fill $this->content with the rows from this query
-     * Columns are 
-     *  - j_id, id of jrnx
-     *  - j_date, date opeation (yyyy.mm.dd)
-     *  - to_char(j_date,'DD.MM.YYYY') as j_date_fmt,
-     *  - jr_pj_number, receipt number
-     *  - j_montant, amount of the rows
-     *  - j_debit,  Debit or credit
-     *  - jr_comment, label of the operation
-     *  - jr_internal, internal number
-     *  - jr_id, id of jrn
-     *  - jr_def_id, id of the ledger (jrn_def.jrn_def_id)
-     *  - coalesce(let_diff.jl_id,-1) as letter, id of the lettering , -1 
means unlettered
-     *  - diff_letter1 as letter_diff, delta between lettered operation
-     *  - extract ('days' from 
coalesce(jr_date_paid,now())-coalesce(jr_ech,jr_date)) as day_paid, days 
between operation and payment
-     *  - jd1.jrn_def_type type of the ledger (FIN, ODS,VEN or ACH)
-     * 
-     * 
-     * @param type $p_type  value is unlet for unlettered operation or let for 
everything
-     */
-    public function get_balance_ageing($p_type)
-    {
-        $sql_let = ($p_type =='unlet')?'  let_diff.jl_id is null and':'';
-        $sql = 
-               "  with let_diff as (select jl_id,deb_amount-cred_amount as 
diff_letter1
-                        from
-                        ( select jl_id,coalesce(sum(j_montant),0) as 
cred_amount from letter_cred join jrnx using (j_id) group by jl_id) as CRED
-                        left join (select jl_id,coalesce(sum(j_montant),0) as 
deb_amount from letter_deb join jrnx using (j_id) group by jl_id) as DEB using 
(jl_id)) ,
-                        letter_jl as (select jl_id,j_id from letter_cred union 
all select jl_id,j_id from letter_deb)
-                select DISTINCT j_id,j_date,to_char(j_date,'DD.MM.YYYY') as 
j_date_fmt,jr_pj_number,
-                                                                
j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
-                                                                
coalesce(let_diff.jl_id,-1) as letter,
-                                                                diff_letter1 
as letter_diff,
-                                                                extract 
('days' from coalesce(jr_date_paid,now())-coalesce(jr_ech,jr_date)) as day_paid,
-                                                                
jd1.jrn_def_type
-                                                                from jrnx join 
jrn on (j_grpt = jr_grpt_id)
-                                                                join jrn_def 
as jd1 on (jrn.jr_def_id=jd1.jrn_def_id)
-                                                                left join 
letter_jl using (j_id)
-                                                                left join 
let_diff using (jl_id)
-                where 
-                 {$sql_let}
-                  j_qcode = upper($1) 
-                and j_date >= to_date($2,'DD.MM.YYYY')
-                and {$this->sql_ledger}
-                 order by j_date,j_id";
-        
$this->content=$this->db->get_array($sql,array($this->quick_code,$this->start));
-
-     }
-}
diff --git a/include/class_manager.php b/include/class_manager.php
deleted file mode 100644
index 55b323f..0000000
--- a/include/class_manager.php
+++ /dev/null
@@ -1,62 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-require_once NOALYSS_INCLUDE.'/constant.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_acc_parm_code.php';
-require_once NOALYSS_INCLUDE.'/class_periode.php';
-require_once NOALYSS_INCLUDE.'/class_fiche.php';
-require_once NOALYSS_INCLUDE.'/class_acc_account_ledger.php';
-require_once NOALYSS_INCLUDE.'/user_common.php';
-/*! \file
- * \brief Derived from class fiche Supplier are a specific kind of card
- */
-/*!
- * \brief  class  Supplier are a specific kind of card
- */
-
-// Use the view vw_supplier
-//
-class Manager extends Fiche
-{
-
-    var $poste;      /*!< $poste poste comptable */
-    var $name;        /*!< $name name of the company */
-    var $first_name;
-    var $street;      /*!< $street Street */
-    var $country;     /*!< $country Country */
-    var $cp;          /*!< $cp Zip code */
-    var $vat_number;  /*!< $vat_number vat number */
-
-    /*! \brief Constructor
-    /* only a db connection is needed */
-    function __construct($p_cn,$p_id=0)
-    {
-        $this->fiche_def_ref=FICHE_TYPE_EMPL;
-        parent::__construct($p_cn,$p_id) ;
-
-    }
-    
-
-
-
-}
-
-?>
diff --git a/include/class_menu_ref.php b/include/class_menu_ref.php
deleted file mode 100644
index 2646959..0000000
--- a/include/class_menu_ref.php
+++ /dev/null
@@ -1,59 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-// Copyright Author Dany De Bontridder address@hidden
-/**
- address@hidden
- address@hidden Menu_Ref let you manage the available menu
- */
-require_once NOALYSS_INCLUDE.'/class_menu_ref_sql.php';
-class Menu_Ref extends Menu_Ref_sql
-{
-    function format_code()
-    {
-        $this->me_code=strtoupper($this->me_code);
-        $this->me_code=trim($this->me_code);
-        $this->me_code=str_replace('<','',$this->me_code);
-        $this->me_code=str_replace('>','',$this->me_code);
-    }
-    function verify()
-    {
-               try
-               {
-        parent::verify();
-        if ( $this->me_code == -1)
-        {
-            $this->format_code();
-            if ( $this->cn->get_value("select count(*) from menu_ref where 
me_code=$1",array($this->me_code)) > 0)
-                    throw new Exception ('Doublon');
-            if (trim($this->me_code)=='')
-                    throw new Exception ('Ce menu existe déjà');
-        }
-        if ( ! file_exists('../include/'.$this->me_file)) throw new Exception 
('Ce menu fichier '.$this->me_file." n'existe pas");
-
-        return 0;
-               } catch (Exception $e)
-               {
-                       alert($e->getMessage());
-                       return -1;
-               }
-    }
-
-}
-
-?>
diff --git a/include/class_menu_ref_sql.php b/include/class_menu_ref_sql.php
deleted file mode 100644
index 0659e34..0000000
--- a/include/class_menu_ref_sql.php
+++ /dev/null
@@ -1,66 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-// Copyright Author Dany De Bontridder address@hidden
-
-/**
- * @file
- * @brief Manage the table public.menu_ref
- *
- *
- */
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/ac_common.php';
-require_once NOALYSS_INCLUDE.'/class_noalyss_sql.php';
-
-/**
- * @brief Manage the table public.menu_ref
- */
-class Menu_Ref_SQL extends Noalyss_SQL
-{
-    protected  $table="public.menu_ref";
-    protected  $primary_key="me_code";
-    protected $name = array(
-                    "me_code" => "me_code"
-                    , "me_menu" => "me_menu"
-                    , "me_file" => "me_file"
-                    , "me_url" => "me_url"
-                    , "me_description" => "me_description"
-                    , "me_parameter" => "me_parameter"
-                    , "me_javascript" => "me_javascript"
-                    , "me_type" => "me_type"
-                    , 'me_description_etendue'=>'me_description_etendue'
-            );
-    protected $type=array(
-                    "me_code" => "text"
-                    , "me_menu" => "text"
-                    , "me_file" => "text"
-                    , "me_url" => "text"
-                    , "me_description" => "text"
-                    , "me_parameter" => "text"
-                    , "me_javascript" => "text"
-                    , "me_type" => "text"
-                    ,"me_description_etendue"=>"text"
-            );
-    function __construct(Database &$p_cn,$p_id=-1)
-    {
-        parent::__construct($p_cn,$p_id);
-    }
-
-}
-?>
diff --git a/include/class_periode.php b/include/class_periode.php
deleted file mode 100644
index 2f650c3..0000000
--- a/include/class_periode.php
+++ /dev/null
@@ -1,575 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief definition of the class periode
- */
-/*!
- * \brief For the periode tables parm_periode and jrn_periode
- */
-require_once  NOALYSS_INCLUDE.'/ac_common.php';
-require_once  NOALYSS_INCLUDE.'/class_database.php';
-class Periode
-{
-    var $cn;                   /*!< database connection */
-    var $jrn_def_id;           /*!< the jr, 0 means all the ledger*/
-    var $p_id;                 /*!< pk of parm_periode */
-    var $status;                       /*!< status is CL for closed, OP for
-                                           open and CE for centralized */
-    var $p_start;                      /*!< start of the periode */
-    var $p_end;                        /*!< end of the periode */
-    function __construct($p_cn,$p_id=0)
-    {
-        $this->p_id=$p_id;
-        $this->cn=$p_cn;
-    }
-    function set_jrn($p_jrn)
-    {
-        $this->jrn_def_id=$p_jrn;
-    }
-    function set_periode($pp_id)
-    {
-        $this->p_id=$pp_id;
-    }
-    /*!\brief return the p_id of the start and the end of the exercice
-     *into an array
-     *\param $p_exercice
-     *\return array [start]=>,[end]=>
-     */
-    function limit_year($p_exercice)
-    {
-        $sql_start="select p_id from parm_periode where p_exercice=$1 order by 
p_start  ASC limit 1";
-        $start=$this->cn->get_value($sql_start,array($p_exercice));
-        $sql_end="select p_id from parm_periode where p_exercice=$1 order by 
p_end  DESC limit 1";
-        $end=$this->cn->get_value($sql_end,array($p_exercice));
-        return array("start"=>$start,"end"=>$end);
-    }
-    /*!\brief check if a periode is closed. If jrn_def_id is set to a no zero 
value then check only for this ledger
-     *\return 1 is the periode is closed otherwise return 0
-     */
-    function is_closed()
-    {
-        if ( $this->jrn_def_id != 0 )
-            $sql="select status from jrn_periode ".
-                 " where jrn_def_id=".$this->jrn_def_id.
-                 " and p_id =".$this->p_id;
-        else
-            $sql="select p_closed as status from parm_periode ".
-                 " where ".
-                 " p_id =".$this->p_id;
-        $res=$this->cn->exec_sql($sql);
-        $status=Database::fetch_result($res,0,0);
-        if ( $status == 'CL' || $status=='t' ||$status=='CE')
-            return 1;
-        return 0;
-    }
-    function is_open()
-    {
-        /* if jrn_Def_id == 0 then we check the global otherwise we check
-           a ledger */
-        if ( $this->jrn_def_id != 0 )
-            $sql="select status from jrn_periode ".
-                 " where jrn_def_id=".$this->jrn_def_id.
-                 " and p_id =".$this->p_id;
-        else
-            $sql="select p_closed as status from parm_periode ".
-                 " where ".
-                 " p_id =".$this->p_id;
-        $res=$this->cn->exec_sql($sql);
-        $status=Database::fetch_result($res,0,0);
-        if ( $status == 'OP' || $status=='f' )
-            return 1;
-        return 0;
-    }
-    function is_centralized()
-    {
-        if ( $this->jrn_def_id != 0 )
-            $sql="select status from jrn_periode ".
-                 " where jrn_def_id=".$this->jrn_def_id.
-                 " and p_id =".$this->p_id;
-        else
-            $sql="select p_centralized as status from parm_periode ".
-                 " where ".
-                 " p_id =".$this->p_id;
-        $res=$this->cn->exec_sql($sql);
-        $status=Database::fetch_result($res,0,0);
-        if ( $status == 'CE' || $status=='t' )
-            return 1;
-        return 0;
-    }
-    function reopen()
-    {
-        if ( $this->jrn_def_id == 0 )
-        {
-         $this->cn->exec_sql("update parm_periode set 
p_closed='f',p_central='f' where p_id=$1",
-                           array($_GET['p_per']));
-
-         $this->cn->exec_sql("update jrn_periode set status='OP' ".
-                                " where p_id = ".$this->p_id);
-
-         return;
-        }
-        else
-        {
-            $this->cn->exec_sql("update jrn_periode set status='OP' ".
-                                " where jrn_def_id=".$this->jrn_def_id." and ".
-                                " p_id = ".$this->p_id);
-           /* if one ledger is open then the periode is open */
-           $this->cn->exec_sql("update parm_periode set p_closed=false where 
p_id=".$this->p_id);
-            return;
-        }
-
-    }
-
-    function close()
-    {
-        if ( $this->jrn_def_id == 0 )
-        {
-            $this->cn->exec_sql("update parm_periode set p_closed=true where 
p_id=".
-                                $this->p_id);
-            $this->cn->exec_sql("update jrn_periode set status='CL' ".
-                                " where p_id = ".$this->p_id);
-
-            return;
-        }
-        else
-        {
-            $this->cn->exec_sql("update jrn_periode set status='CL' ".
-                                " where jrn_def_id=".$this->jrn_def_id." and ".
-                                " p_id = ".$this->p_id);
-            /* if all ledgers have this periode closed then synchro with
-            the table parm_periode
-            */
-            $nJrn=$this->cn->count_sql( "select * from jrn_periode where ".
-                                        " p_id=".$this->p_id);
-            $nJrnPeriode=$this->cn->count_sql( "select * from jrn_periode 
where ".
-                                               " p_id=".$this->p_id." and 
status='CL'");
-
-            if ( $nJrnPeriode==$nJrn)
-                $this->cn->exec_sql("update parm_periode set p_closed=true 
where p_id=".$this->p_id);
-            return;
-        }
-
-    }
-    function centralized()
-    {
-        if ( $this->jrn_def_id == 0 )
-        {
-            $this->cn->exec_sql("update parm_periode set p_central=true");
-            return;
-        }
-        else
-        {
-            $this->cn->exec_sql("update jrn_periode set status='CE' ".
-                                " where ".
-                                " p_id = ".$this->p_id);
-            return;
-        }
-
-    }
-    /*!
-     * \brief Display all the periode and their status
-     *
-     */
-
-    function display_form_periode()
-    {
-        $str_dossier=dossier::get();
-
-        if ( $this->jrn_def_id==0 )
-        {
-            $Res=$this->cn->exec_sql("select 
p_id,to_char(p_start,'DD.MM.YYYY') as date_start,to_char(p_end,'DD.MM.YYYY') as 
date_end,p_central,p_closed,p_exercice,
-                                     (select count(jr_id) as count_op from jrn 
where jr_tech_per = p_id) as count_op
-                                     from parm_periode
-                                     order by p_start,p_end");
-            $Max=Database::num_row($Res);
-            echo '<form id="periode_frm" method="POST" onsubmit="return 
confirm_box(this,\'Confirmez-vous la fermeture des périodes choisies ?\')" >';
-            echo 
HtmlInput::array_to_hidden(array('ac','gDossier','jrn_def_id','choose'), 
$_REQUEST);
-            echo '<TABLE ALIGN="CENTER">';
-            echo "</TR>";
-            echo '<th>'.ICheckBox::toggle_checkbox("per_toggle", 
"periode_frm")."</th>";
-            echo '<TH> Date d&eacute;but </TH>';
-            echo '<TH> Date fin </TH>';
-            echo '<TH> Exercice </TH>';
-            echo "</TR>";
-
-            for ($i=0;$i<$Max;$i++)
-            {
-                $l_line=Database::fetch_array($Res,$i);
-               $class="even";
-               if ( $i % 2 == 0 )
-                 $class="odd";
-               $style='';
-               if ( $l_line['p_closed'] == 't')
-                 $style="color:red";
-                echo '<TR class="'.$class.'" style="'.$style.'">';
-                echo '<td>';
-                if ( $l_line['p_closed'] == 'f') {
-                              $per_to_close=new ICheckBox('sel_per_close[]');
-                              $per_to_close->value=$l_line['p_id'];
-                             echo $per_to_close->input();
-               }
-               echo '</td>';
-
-                echo '<TD ALIGN="CENTER"> '.$l_line['date_start'].'</TD>';
-                echo '<TD  ALIGN="CENTER"> '.$l_line['date_end'].'</TD>';
-                echo '<TD  ALIGN="CENTER"> '.$l_line['p_exercice'].'</TD>';
-
-                if ( $l_line['p_closed'] == 't' )
-                {
-                    
$closed=($l_line['p_central']=='t')?'<TD>Centralis&eacute;e</TD>':'<TD>Ferm&eacute;e</TD>';
-                    $change='<TD></TD>';
-                   $remove=sprintf(_('Nombre opérations 
%d'),$l_line['count_op']);
-                    $remove=td($remove,' class="mtitle" ');
-                    $change=td ('<A class="mtitle" HREF="javascript:void(0)"'
-                            . ' onclick="return 
confirm_box(null,\''._('Confirmez Réouverture').' ?\',function() 
{window.location=\'do.php?ac='.$_REQUEST['ac'].'&action=reopen&p_per='.$l_line['p_id'].'&'.$str_dossier.'\';}
 )"> Réouverture</A>',' class="mtitle"');
-
-                }
-                else
-                {
-                    if ($l_line['count_op'] == 0 )
-                    {
-                     $change=HtmlInput::display_periode($l_line['p_id']);
-                    }
-                    else
-                    {
-                     $change="Non modifiable";
-                    }
-                   $change=td($change,' class="mtitle" ');
-                   $reopen=td("");
-
-
-                    $remove='<TD class="mtitle">';
-
-
-                    if ($l_line['count_op'] == 0 )
-                    {
-                        
$go='do.php?'.http_build_query(array('ac'=>$_REQUEST['ac'],
-                            'action'=>'delete_per',
-                            'p_per'=>$l_line['p_id'],
-                            'gDossier'=>Dossier::id()));
-                        
-                        $remove.='<A class="mtitle" HREF="javascript:void(0)" '
-                                . 'onclick="return confirm_box 
(null,\''._('Confirmez effacement ?').'\',function() { 
window.location=\''.$go.'\'});" >'
-                                . ' Efface</A>';
-                    }
-                    else
-                    {
-                        $remove.=sprintf(_('Nombre opérations 
%d'),$l_line['count_op']);
-                    }
-                    $remove.='</td>';
-                }
-                echo $change;
-
-                echo $remove;
-
-               echo '</TR>';
-
-            }
-            echo '</table>';
-            echo '<p style="text-align:center">';
-            echo HtmlInput::hidden("close_per", 1);
-            echo HtmlInput::submit('close_per_bt','Fermeture des périodes 
sélectionnées');
-            echo '</p>';
-            echo '</form>';
-            $but=new IButton('show_per_add','Ajout d\'une période');
-            $but->javascript="$('periode_add_div').show();";
-            echo $but->input();
-            echo '<div class="inner_box" style="width:40%;" 
id="periode_add_div">';
-            echo HtmlInput::title_box("Ajout d'une 
période","periode_add_div","hide");
-            echo '<FORM  METHOD="POST">';
-            echo dossier::hidden();
-           $istart=new IDate('p_date_start');
-           $iend=new IDate('p_date_end');
-           $iexercice=new INum('p_exercice');
-           $iexercice->size=5;
-            echo '<table>';
-            echo '<TR> ';
-            echo td('Date de début');
-            echo td($istart->input());
-            echo '</tr><tr>';
-            echo td('Date de fin');
-           echo td($iend->input());
-
-            echo '</tr><tr>';
-            echo td('Exercice');
-           echo td($iexercice->input());
-
-            echo '</TABLE>';
-
-            echo HtmlInput::submit('add_per','Valider');
-            echo '</FORM>';
-            echo '</div>';
-            echo create_script("$('periode_add_div').hide();new 
Draggable('periode_add_div',{starteffect:function()
-                                  {
-                                     new 
Effect.Highlight(obj.id,{scroll:window,queue:'end'});
-                                  }}
-                         );");
-        }
-        else
-        {
-            $Res=$this->cn->exec_sql("select 
p_id,to_char(p_start,'DD.MM.YYYY') as date_start,to_char(p_end,'DD.MM.YYYY') as 
date_end,status,p_exercice
-                                     from parm_periode join jrn_periode using 
(p_id) where jrn_def_id=".$this->jrn_def_id."
-                                     order by p_start,p_end");
-            $Max=Database::num_row($Res);
-            $r=$this->cn->exec_sql('select jrn_Def_name from jrn_Def where 
jrn_Def_id='.
-                                   $this->jrn_def_id);
-            $jrn_name=Database::fetch_result($r,0,0);
-            echo '<h2> Journal '.$jrn_name.'</h2>';
-            echo '<form id="periode_frm" method="POST" onsubmit="return 
confirm_box(this,\'Confirmez-vous la fermeture des périodes choisies ?\')" >';
-            echo 
HtmlInput::array_to_hidden(array('ac','gDossier','jrn_def_id','choose'), 
$_REQUEST);
-
-            echo '<TABLE ALIGN="CENTER">';
-            echo "</TR>";
-            echo '<th>'.ICheckBox::toggle_checkbox("per_toggle", 
"periode_frm")."</th>";
-            echo '<TH> Date d&eacute;but </TH>';
-            echo '<TH> Date fin </TH>';
-            echo '<TH> Exercice </TH>';
-            echo "</TR>";
-
-            for ($i=0;$i<$Max;$i++)
-            {
-                $l_line=Database::fetch_array($Res,$i);
-                if ( $l_line['status'] != 'OP' )
-                 echo '<TR style="COLOR:RED">';
-               else
-                 echo '<TR>';
-                echo '<td>';
-                if ( $l_line['status'] == 'OP') {
-                              $per_to_close=new ICheckBox('sel_per_close[]');
-                              $per_to_close->value=$l_line['p_id'];
-                             echo $per_to_close->input();
-               }
-                echo '</td>';
-                echo '<TD ALIGN="CENTER"> '.$l_line['date_start'].'</TD>';
-                echo '<TD  ALIGN="CENTER"> '.$l_line['date_end'].'</TD>';
-                echo '<TD  ALIGN="CENTER"> '.$l_line['p_exercice'].'</TD>';
-                $closed="";
-                if ( $l_line['status'] != 'OP' )
-                {
-                    $go='do.php?'.http_build_query(array('ac'=>$_REQUEST['ac'],
-                        'action'=>'reopen',
-                        'p_per'=>$l_line['p_id'],
-                        'gDossier'=>Dossier::id(),
-                        'jrn_def_id'=>$this->jrn_def_id));
-                    
-                 $closed=td ('<A class="mtitle" HREF="javascript:void(0)" '
-                          . 'onclick="return confirm_box(null,\''._('Confirmez 
Réouverture').' ?\',function() {window.location=\''.$go.'\';} );"> 
Réouverture</A>',' class="mtitle"');
-                }
-               
-                echo "$closed";
-
-                echo '</TR>';
-
-            }
-            echo '</TABLE>';
-            echo '<p style="text-align:center">';
-            echo HtmlInput::submit('close_per','Fermeture des périodes 
sélectionnées');
-            echo '</p>';
-            echo '</form>';
-
-        }
-    }
-    function insert($p_date_start,$p_date_end,$p_exercice)
-    {
-        try
-        {
-
-        if (isDate($p_date_start) == null ||
-                isDate($p_date_end) == null ||
-                strlen (trim($p_exercice)) == 0 ||
-                (string) $p_exercice != (string)(int) $p_exercice
-         ||$p_exercice < COMPTA_MIN_YEAR || $p_exercice > COMPTA_MAX_YEAR)
-
-        {
-         throw new Exception ("Paramètre invalide");
-        }
-        $p_id=$this->cn->get_next_seq('s_periode');
-        $sql=sprintf(" insert into 
parm_periode(p_id,p_start,p_end,p_closed,p_exercice)".
-                     "values 
(%d,to_date('%s','DD.MM.YYYY'),to_date('%s','DD.MM.YYYY')".
-                     ",'f','%s')",
-                     $p_id,
-                     $p_date_start,
-                     $p_date_end,
-                     $p_exercice);
-            $this->cn->start();
-            $Res=$this->cn->exec_sql($sql);
-            $Res=$this->cn->exec_sql("insert into jrn_periode 
(jrn_def_id,p_id,status) ".
-                                     "select jrn_def_id,$p_id,'OP' from 
jrn_def");
-            $this->cn->commit();
-        }
-        catch (Exception $e)
-        {
-            $this->cn->rollback();
-            return 1;
-        }
-        return 0;
-    }
-    /*!\brief load data from database
-     *\return 0 on success and -1 on error
-     */
-    function load()
-    {
-        if ($this->p_id == '') $this->p_id=-1;
-        $row=$this->cn->get_array("select 
p_start,p_end,p_exercice,p_closed,p_central from parm_periode where p_id=$1",
-                                  array($this->p_id));
-        if ($row == null ) return -1;
-
-        $this->p_start=$row[0]['p_start'];
-        $this->p_end=$row[0]['p_end'];
-        $this->p_exercice=$row[0]['p_exercice'];
-        $this->p_closed=$row[0]['p_closed'];
-        $this->p_central=$row[0]['p_central'];
-        return 0;
-    }
-
-    /*!\brief return the max and the min periode of the exercice given
-     *in parameter
-     *\param $p_exercice is the exercice
-     *\return an array of Periode object
-     */
-    function get_limit($p_exercice)
-    {
-
-        $max=$this->cn->get_value("select p_id from parm_periode where 
p_exercice=$1 order by p_start asc limit 1",array($p_exercice));
-        $min=$this->cn->get_value("select p_id from parm_periode where 
p_exercice=$1 order by p_start desc limit 1",array($p_exercice));
-        $rMax=new Periode($this->cn);
-        $rMax->p_id=$max;
-        if ( $rMax->load() ) throw new Exception('Periode n\'existe pas');
-        $rMin=new Periode($this->cn);
-        $rMin->p_id=$min;
-        if ( $rMin->load() ) throw new Exception('Periode n\'existe pas');
-        return array($rMax,$rMin);
-    }
-    /*!
-     * \brief Give the start & end date of a periode
-     * \param $p_periode is the periode id, if omitted the value is the 
current object
-     * \return array containing the start date & the end date, index are 
p_start and p_end or NULL if
-     * nothing is found
-    \verbatim
-    $ret['p_start']=>'01.01.2009'
-    $ret['p_end']=>'31.01.2009'
-    \endverbatim
-     */
-    public function get_date_limit($p_periode = 0)
-    {
-        if ( $p_periode == 0 ) $p_periode=$this->p_id;
-        $sql="select to_char(p_start,'DD.MM.YYYY') as p_start,
-             to_char(p_end,'DD.MM.YYYY')   as p_end
-             from parm_periode
-             where p_id=$1";
-        $Res=$this->cn->exec_sql($sql,array($p_periode));
-        if ( Database::num_row($Res) == 0) return null;
-        return Database::fetch_array($Res,0);
-
-    }
-    /*!\brief return the first day of periode
-     *the this->p_id must be set
-     *\return a string with the date (DD.MM.YYYY)
-     */
-    public function first_day($p=0)
-    {
-               if ($p==0) $p=$this->p_id;
-        list($p_start,$p_end)=$this->get_date_limit($p);
-        return $p_start;
-    }
-    /*!\brief return the last day of periode
-     *the this->p_id must be set
-     *\return a string with the date (DD.MM.YYYY)
-     */
-    public function last_day($p=0)
-    {
-               if ($p==0) $p=$this->p_id;
-        list($p_start,$p_end)=$this->get_date_limit($p);
-        return $p_end;
-    }
-
-    function get_exercice($p_id=0)
-    {
-        if ( $p_id == 0 )  $p_id=$this->p_id;
-        $sql="select p_exercice from parm_periode where p_id=".$p_id;
-        $Res=$this->cn->exec_sql($sql);
-        if ( Database::num_row($Res) == 0) return null;
-        return Database::fetch_result($Res,0,0);
-
-    }
-    /*!\brief retrieve the periode thanks the date_end
-    *\param $p_date format DD.MM.YYYY
-     * \return the periode id
-     *\exception if not periode is found or if more than one periode is found
-     */
-    function find_periode($p_date)
-    {
-        $sql="select p_id from parm_periode where p_start <= 
to_date($1,'DD.MM.YYYY') and p_end >= to_date($1,'DD.MM.YYYY') ";
-        $ret=$this->cn->exec_sql($sql,array($p_date));
-        $nb_periode=Database::num_row($ret);
-        if (  $nb_periode == 0 )
-            throw  (new Exception('Aucune période trouvée',101));
-        if ( $nb_periode > 1 )
-            throw  (new Exception("Trop de périodes trouvées $nb_periode pour 
$p_date",100));
-        $per=Database::fetch_result($ret,0);
-        $this->p_id=$per;
-        return $per;
-    }
-    /**
-     *add a exerice of 13 periode
-     */
-    function insert_exercice($p_exercice,$nb_periode)
-    {
-      try
-       {
-         if ( $nb_periode != 12 && $nb_periode != 13) throw new Exception 
('Nombre de période incorrectes');
-         $this->cn->start();
-         for ($i=1;$i < 12;$i++)
-           {
-             $date_start=sprintf('01.%02d.%d',$i,$p_exercice);
-             $date_end=$this->cn->get_value("select 
to_char(to_date('$date_start','DD.MM.YYYY')+interval '1 month'-interval '1 
day','DD.MM.YYYY')");
-             if ( $this->insert($date_start,$date_end,$p_exercice) != 0)
-               {
-                 throw new Exception('Erreur insertion période');
-               }
-           }
-         if ( $nb_periode==12 && 
$this->insert('01.12.'.$p_exercice,'31.12.'.$p_exercice,$p_exercice) != 0 )
-           {
-             throw new Exception('Erreur insertion période');
-           }
-         if ( $nb_periode==13)
-           {
-             if 
($this->insert('01.12.'.$p_exercice,'30.12.'.$p_exercice,$p_exercice) != 0 )    
     throw new Exception('Erreur insertion période');
-             if 
($this->insert('31.12.'.$p_exercice,'31.12.'.$p_exercice,$p_exercice) != 0 )    
     throw new Exception('Erreur insertion période');
-           }
-
-
-         $this->cn->commit();
-       }
-      catch (Exception $e)
-       {
-         $this->cn->rollback();
-       }
-    }
-    static function test_me()
-    {
-        $cn=new Database(dossier::id());
-        $obj=new Periode($cn);
-        $obj->set_jrn(1);
-        $obj->display_form_periode();
-    }
-}
diff --git a/include/class_pre_op_ach.php b/include/class_pre_op_ach.php
deleted file mode 100644
index 74d6a88..0000000
--- a/include/class_pre_op_ach.php
+++ /dev/null
@@ -1,394 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief definition of the class pre_op_ach
- */
-require_once  NOALYSS_INCLUDE.'/class_pre_operation.php';
-
-/*---------------------------------------------------------------------- */
-/*!\brief concerns the predefined operation for ACH ledger
- */
-class Pre_op_ach extends Pre_operation_detail
-{
-    var $op;
-    function __construct($cn,$p_id=0)
-    {
-        parent::__construct($cn,$p_id);
-
-        $this->operation->od_direct='f';
-    }
-
-    function get_post()
-    {
-        parent::get_post();
-        $this->operation->od_direct='f';
-        $this->e_client=$_POST['e_client'];
-        for ($i=0;$i<$this->operation->nb_item;$i++)
-        {
-            $march="e_march".$i;
-            $this->$march=$_POST['e_march'.$i];
-            $this->{"e_march".$i."_price"}=(isset 
($_POST['e_march'.$i."_price"]))?$_POST['e_march'.$i."_price"]:0;
-            $this->{"e_march".$i."_tva_id"}=(isset 
($_POST['e_march'.$i."_tva_id"]))?$_POST['e_march'.$i."_tva_id"]:0;
-            
$this->{"e_march".$i."_tva_amount"}=(isset($_POST['e_march'.$i."_tva_amount"]))?$_POST['e_march'.$i."_tva_amount"]:0;
-            $this->{"e_quant".$i}=$_POST['e_quant'.$i];
-
-        }
-    }
-
-    /*!
-     * \brief save the detail and op in the database
-     *
-     */
-    function save()
-    {
-        try
-        {
-            $this->db->start();
-            if ($this->operation->save() == false )
-                return;
-            // save the client
-            $sql=sprintf('insert into op_predef_detail 
(od_id,opd_poste,opd_debit)'.
-                         ' values '.
-                         "(%d,'%s','%s')",
-                         $this->operation->od_id,
-                         $this->e_client,
-                         "f");
-            $this->db->exec_sql($sql);
-            // save the selling
-            for ($i=0;$i<$this->operation->nb_item;$i++)
-            {
-                $sql=sprintf('insert into op_predef_detail 
(opd_poste,opd_amount,opd_tva_id,opd_quantity,'.
-                             'opd_debit,od_id,opd_tva_amount)'.
-                             ' values '.
-                             "('%s',%.2f,%d,%f,'%s',%d,%f)",
-                             $this->{"e_march".$i},
-                             $this->{"e_march".$i."_price"},
-                             $this->{"e_march".$i."_tva_id"},
-                             $this->{"e_quant".$i},
-                             't',
-                             $this->operation->od_id,
-                             $this->{"e_march".$i."_tva_amount"}
-                            );
-                $this->db->exec_sql($sql);
-            }
-        }
-        catch (Exception $e)
-        {
-            echo ($e->getMessage());
-            $this->db->rollback();
-        }
-        $this->db->commit();
-    }
-    /*!\brief compute an array accordingly with the FormVenView function
-        * @return an array for filling the form
-     */
-    function compute_array()
-    {
-        $count=0;
-        $a_op=$this->operation->load();
-        $array=$this->operation->compute_array($a_op);
-        $p_array=$this->load();
-               if ( empty ($p_array)) return array();
-        foreach ($p_array as $row)
-        {
-            if ( $row['opd_debit']=='f')
-            {
-                $array+=array('e_client'=>$row['opd_poste']);
-            }
-            else
-            {
-                $array+=array("e_march".$count=>$row['opd_poste'],
-                              "e_march".$count."_price"=>$row['opd_amount'],
-                              "e_march".$count."_tva_id"=>$row['opd_tva_id'],
-                              
"e_march".$count."_tva_amount"=>$row['opd_tva_amount'],
-                              "e_quant".$count=>$row['opd_quantity']
-                             );
-                $count++;
-            }
-        }
-        return $array;
-    }
-    /**
-     * @brief 
-     * load the data from the database and return an array
-     * \return an array
-     */
-    function load()
-    {
-        $sql="select opd_id,opd_poste,opd_amount,opd_tva_id,opd_debit,".
-             " opd_quantity,opd_tva_amount from op_predef_detail where 
od_id=".$this->operation->od_id.
-             " order by opd_id";
-        $res=$this->db->exec_sql($sql);
-        $array=Database::fetch_all($res);
-        return $array;
-    }
-    function set_od_id($p_id)
-    {
-        $this->operation->od_id=$p_id;
-    }
-   function display($p_array)
-   {
-        require_once NOALYSS_INCLUDE.'/class_acc_ledger_purchase.php';
-       global $g_parameter,$g_user;
-       extract($p_array);
-       $ledger=new Acc_Ledger_Purchase($this->db,$this->jrn_def_id);
-        if ( $p_array != null ) extract($p_array);
-
-        $flag_tva=$g_parameter->MY_TVA_USE;
-        /* Add button */
-        $f_add_button=new IButton('add_card');
-        $f_add_button->label=_('Créer une nouvelle fiche');
-               $f_add_button->tabindex=-1;
-        $f_add_button->set_attribute('ipopup','ipop_newcard');
-        $f_add_button->set_attribute('jrn',$this->jrn_def_id);
-        $f_add_button->javascript=" 
this.jrn=\$('p_jrn').value;select_card_type(this);";
-
-        $f_add_button2=new IButton('add_card2');
-               $f_add_button2->tabindex=-1;
-        $f_add_button2->label=_('Créer une nouvelle fiche');
-        $f_add_button2->set_attribute('ipopup','ipop_newcard');
-        $f_add_button2->set_attribute('filter',$ledger->get_all_fiche_def ());
-        //    $f_add_button2->set_attribute('jrn',$ledger->id);
-        $f_add_button2->javascript="  
this.jrn=\$('p_jrn').value;select_card_type(this);";
-        $str_add_button="";
-        $str_add_button2="";
-        if ($g_user->check_action(FICADD)==1)
-        {
-                $str_add_button=$f_add_button->input();
-                $str_add_button2=$f_add_button2->input();
-        }
-
-        $r="";
-        $r.=dossier::hidden();
-        $f_legend=_("En-tête facture fournisseur");
-        $f_legend_detail=_("Détail articles acheté");
-
-        // Ledger (p_jrn)
-        //--
-        /* if we suggest the next pj, then we need a javascript */
-        $add_js="";
-
-        // Display the customer
-        //--
-        $fiche='cred';
-
-        // Save old value and set a new one
-        //--
-        $e_client=( isset ($e_client) )?$e_client:"";
-        $e_client_label="&nbsp;";//str_pad("",100,".");
-
-
-        // retrieve e_client_label
-        //--
-
-        if ( strlen(trim($e_client)) !=  0)
-        {
-            $fClient=new Fiche($ledger->db);
-            $fClient->get_by_qcode($e_client);
-            $e_client_label=$fClient->strAttribut(ATTR_DEF_NAME).' '.
-                            ' Adresse : 
'.$fClient->strAttribut(ATTR_DEF_ADRESS).' '.
-                            $fClient->strAttribut(ATTR_DEF_CP).' '.
-                            $fClient->strAttribut(ATTR_DEF_CITY).' ';
-
-
-        }
-
-        $W1=new ICard();
-        $W1->label=_("Fournisseur ").HtmlInput::infobulle(0) ;
-        $W1->name="e_client";
-        $W1->tabindex=3;
-        $W1->value=$e_client;
-        $W1->table=0;
-        $W1->set_dblclick("fill_ipopcard(this);");
-        $W1->set_attribute('ipopup','ipopcard');
-
-        // name of the field to update with the name of the card
-        $W1->set_attribute('label','e_client_label');
-        // name of the field to update with the name of the card
-        $W1->set_attribute('typecard','cred');
-
-        // Add the callback function to filter the card on the jrn
-        $W1->set_callback('filter_card');
-        $W1->set_function('fill_data');
-        $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
-                                $W1->name);
-        $f_client_qcode=$W1->input();
-        $client_label=new ISpan();
-        $client_label->table=0;
-        $f_client=$client_label->input("e_client_label",$e_client_label);
-        $f_client_bt=$W1->search();
-
-
-        // Record the current number of article
-               $min=$ledger->get_min_row();
-        $p_article= ( isset ($nb_item))?$nb_item:$min;
-        $max=($p_article < $min)?$min:$p_article;
-
-        $e_comment=(isset($e_comment))?$e_comment:"";
-        $Hid=new IHidden();
-        $r.=$Hid->input("nb_item",$p_article);
-        // For each article
-        //--
-        for ($i=0;$i< $max ;$i++)
-        {
-            // Code id, price & vat code
-            //--
-            $march=(isset(${"e_march$i"}))?${"e_march$i"}:""                   
;
-            
$march_price=(isset(${"e_march".$i."_price"}))?${"e_march".$i."_price"}:""
-                         ;
-            /* use vat */
-            if ( $g_parameter->MY_TVA_USE=='Y')
-            {
-                
$march_tva_id=(isset(${"e_march$i"."_tva_id"}))?${"e_march$i"."_tva_id"}:"";
-                
$march_tva_amount=(isset(${"e_march$i"."_tva_amount"}))?${"e_march$i"."_tva_amount"}:"";
-            }
-
-
-
-            
$march_label=(isset(${"e_march".$i."_label"}))?${"e_march".$i."_label"}:"";
-            // retrieve the tva label and name
-            //--
-            if ( strlen(trim($march))!=0  && strlen(trim($march_label))==0 )
-            {
-                $fMarch=new Fiche($ledger->db);
-                $fMarch->get_by_qcode($march);
-                $march_label=$fMarch->strAttribut(ATTR_DEF_NAME);
-                /* vat use */
-                if ( ! isset($march_tva_id) && $g_parameter->MY_TVA_USE=='Y' )
-                    $march_tva_id=$fMarch->strAttribut(ATTR_DEF_TVA);
-            }
-            // Show input
-            //--
-            $W1=new ICard();
-            $W1->label="";
-            $W1->name="e_march".$i;
-            $W1->value=$march;
-            $W1->table=1;
-            $W1->set_dblclick("fill_ipopcard(this);");
-            $W1->set_attribute('ipopup','ipopcard');
-
-            $W1->set_attribute('typecard','deb');
-
-            // name of the field to update with the name of the card
-            $W1->set_attribute('label','e_march'.$i.'_label');
-            // name of the field with the price
-            $W1->set_attribute('purchase','e_march'.$i.'_price'); /* 
autocomplete */
-            $W1->set_attribute('price','e_march'.$i.'_price');    /* via 
search */
-
-            // name of the field with the TVA_ID
-            $W1->set_attribute('tvaid','e_march'.$i.'_tva_id');
-            // Add the callback function to filter the card on the jrn
-            $W1->set_callback('filter_card');
-            $W1->set_function('fill_data');
-            $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
-                                    $W1->name);
-            $W1->readonly=false;
-            $array[$i]['quick_code']=$W1->input();
-            $array[$i]['bt']=$W1->search();
-
-            $array[$i]['hidden']='';
-            // For computing we need some hidden field for holding the value
-            if ( $g_parameter->MY_TVA_USE=='Y')
-            {
-                $array[$i]['hidden'].=HtmlInput::hidden('tva_march'.$i,0);
-            }
-
-            if ( $g_parameter->MY_TVA_USE=='Y')
-                $tvac=new INum('tvac_march'.$i);
-            else
-                $tvac=new IHidden('tvac_march'.$i);
-
-            $tvac->readOnly=1;
-            $tvac->value=0;
-            $array[$i]['tvac']=$tvac->input();
-
-            $htva=new INum('htva_march'.$i);
-            $htva->readOnly=1;
-
-            $htva->value=0;
-            $array[$i]['htva']=$htva->input();
-
-            if ( $g_parameter->MY_UPDLAB == 'Y')
-            {
-                $Span=new IText("e_march".$i."_label");
-                $Span->css_size="100%";
-            } else
-            {
-                $Span=new ISpan("e_march".$i."_label");
-            }
-            $Span->value=$march_label;
-            $Span->setReadOnly(false);
-            // card's name, price
-            //--
-            
$array[$i]['denom']=$Span->input("e_march".$i."_label",$march_label);
-            // price
-            $Price=new INum();
-            $Price->setReadOnly(false);
-            $Price->size=9;
-            
$Price->javascript="onBlur='format_number(this);clean_tva($i);compute_ledger($i)'";
-            $array[$i]['pu']=$Price->input("e_march".$i."_price",$march_price);
-            if ( $g_parameter->MY_TVA_USE=='Y')
-            {
-
-                // vat label
-                //--
-                $Tva=new ITva_Popup($ledger->db);
-                
$Tva->js="onblur=\"format_number(this);onChange=clean_tva($i);compute_ledger($i)\"";
-                $Tva->in_table=true;
-                $Tva->set_attribute('compute',$i);
-                $Tva->value=$march_tva_id;
-                $array[$i]['tva']=$Tva->input("e_march$i"."_tva_id");
-
-                // Tva_amount
-
-                // price
-                $Tva_amount=new INum();
-                $Tva_amount->setReadOnly(false);
-                $Tva_amount->size=9;
-                
$Tva_amount->javascript="onBlur='format_number(this);compute_ledger($i)'";
-                
$array[$i]['amount_tva']=$Tva_amount->input("e_march".$i."_tva_amount",$march_tva_amount);
-            }
-            // quantity
-            //--
-            $quant=(isset(${"e_quant$i"}))?${"e_quant$i"}:"1"
-                   ;
-            $Quantity=new INum();
-            $Quantity->setReadOnly(false);
-            $Quantity->size=9;
-            
$Quantity->javascript="onChange=format_number(this);clean_tva($i);compute_ledger($i)";
-            $array[$i]['quantity']=$Quantity->input("e_quant".$i,$quant);
-
-        }
-        $f_type=_('Fournisseur');
-
-        ob_start();
-        require_once NOALYSS_INCLUDE.'/template/predf_ledger_detail.php';
-        $r.=ob_get_contents();
-        ob_end_clean();
-
-        // Set correctly the REQUEST param for jrn_type
-        $r.= HtmlInput::hidden('jrn_type','ACH');
-        $r.= HtmlInput::button('add_item',_('Ajout article'),      ' 
onClick="ledger_add_row()"');
-
-        return $r;
-   }
-}
\ No newline at end of file
diff --git a/include/class_pre_op_advanced.php 
b/include/class_pre_op_advanced.php
deleted file mode 100644
index fd9ffbe..0000000
--- a/include/class_pre_op_advanced.php
+++ /dev/null
@@ -1,289 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief definition of the class Pre_Op_Advanced
- */
-require_once  NOALYSS_INCLUDE.'/class_pre_operation.php';
-
-/*---------------------------------------------------------------------- */
-/*!\brief concerns the predefined operation for the operation from 'Ecriture 
direct'
- */
-class Pre_Op_Advanced extends Pre_operation_detail
-{
-    var $op;
-    function Pre_Op_Advanced($cn)
-    {
-        parent::__construct($cn);
-        $this->operation->od_direct='t';
-    }
-    function get_post()
-    {
-        parent::get_post();
-
-        extract($_POST);
-
-        for ($i=0;$i<$this->operation->nb_item;$i++)
-        {
-            $poste=HtmlInput::default_value_post("poste".$i, null);
-            $qcode=HtmlInput::default_value_post("qc_".$i, null);
-            
-            if ( $poste == null && $qcode == null )                continue;
-            
-            if ($poste != null && trim ($poste) != "")
-            {
-                $this->{'poste'.$i}=$poste;
-                 $this->{'isqc'.$i}='f';
-            }
-            
-            if ( $qcode != null && trim ($qcode) != "") {
-                $this->{'isqc'.$i}=(trim($_POST['qc_'.$i]) != "")?'t':'f';
-                $this->{'poste'.$i}=trim ($qcode);
-            }   
-            $this->{"amount".$i}=$_POST['amount'.$i];
-            $this->{"ck".$i}=(isset($_POST['ck'.$i]))?'t':'f';
-
-        }
-    }
-    /*!
-     * \brief save the detail and op in the database
-     *
-     */
-    function save()
-    {
-        try
-        {
-            if ($this->operation->save() == false )
-                return;
-            $this->db->start();
-            // save the selling
-            for ($i=0;$i<$this->operation->nb_item;$i++)
-            {
-                if ( ! isset ($this->{"poste".$i}))
-                    continue;
-
-                $sql=sprintf('insert into op_predef_detail 
(opd_poste,opd_amount,'.
-                             'opd_debit,od_id,opd_qc)'.
-                             ' values '.
-                             "('%s',%.2f,'%s',%d,'%s')",
-                             $this->{"poste".$i},
-                             $this->{"amount".$i},
-                             $this->{"ck".$i},
-                             $this->operation->od_id,
-                             $this->{'isqc'.$i}
-                            );
-
-                $this->db->exec_sql($sql);
-
-            }
-             $this->db->commit();
-            
-        }
-        catch (Exception $e)
-        {
-            echo ($e->getMessage());
-            $this->db->rollback();
-        }
-
-    }
-    /*!\brief compute an array accordingly with the FormVenView function
-     */
-    function compute_array()
-    {
-        $count=0;
-        $a_op=$this->operation->load();
-        $array=$this->operation->compute_array($a_op);
-        $array['desc']=$array['e_comm'];
-        $p_array=$this->load();
-               if (empty($p_array)) return array();
-        foreach ($p_array as $row)
-        {
-            $tmp_array=array("qc_".$count=>'',
-                             "poste".$count=>'',
-                             "amount".$count=>$row['opd_amount'],
-                             'ck'.$count=>$row['opd_debit']
-                            );
-
-            if ( $row['opd_qc'] == 't' )
-                $tmp_array['qc_'.$count]=$row['opd_poste'];
-            else
-                $tmp_array['poste'.$count]=$row['opd_poste'];
-
-
-            if ( $row['opd_debit'] == 'f' )
-                unset ($tmp_array['ck'.$count]);
-
-            $array+=$tmp_array;
-            $count++;
-
-        }
-
-        return $array;
-    }
-    /*!\brief load the data from the database and return an array
-     * \return an array
-     */
-    function load()
-    {
-        $sql="select opd_id,opd_poste,opd_amount,opd_debit,".
-             " opd_qc from op_predef_detail where 
od_id=".$this->operation->od_id.
-             " order by opd_id";
-        $res=$this->db->exec_sql($sql);
-        $array=Database::fetch_all($res);
-        return $array;
-    }
-    function set_od_id($p_id)
-    {
-        $this->operation->od_id=$p_id;
-    }
-       function display($p_array)
-    {
-        global $g_parameter, $g_user;
-        require_once NOALYSS_INCLUDE.'/class_acc_ledger.php';
-        $legder=new Acc_Ledger($this->db,$this->jrn_def_id);
-        $legder->nb=$legder->get_min_row();
-
-        if ($p_array != null)
-                extract($p_array);
-        $add_js = "";
-       
-        $ret = "";
-        if ($g_user->check_action(FICADD) == 1)
-        {
-                /* Add button */
-                $f_add_button = new IButton('add_card');
-                $f_add_button->label = _('Créer une nouvelle fiche');
-                $f_add_button->set_attribute('ipopup', 'ipop_newcard');
-                $f_add_button->set_attribute('jrn', $legder->id);
-                $f_add_button->javascript = " 
this.jrn=\$('p_jrn').value;select_card_type(this);";
-                $f_add_button->input();
-        }
-       
-        $nb_row = (isset($nb_item) ) ? $nb_item : $legder->nb;
-
-        $ret.=HtmlInput::hidden('nb_item', $nb_row);
-        $ret.=HtmlInput::hidden('p_jrn', $this->jrn_def_id);
-        $ret.=dossier::hidden();
-        
-        $ret.=dossier::hidden();
-
-        $ret.=HtmlInput::hidden('jrn_type', $legder->get_type());
-        $info = HtmlInput::infobulle(0);
-        $info_poste = HtmlInput::infobulle(9);
-        if ($g_user->check_action(FICADD) == 1)
-                $ret.=$f_add_button->input();
-        $ret.='<table id="quick_item" style="width:100%">';
-        $ret.='<tr>' .
-                        '<th style="text-align:left">Quickcode' . $info . 
'</th>' .
-                        '<th style="text-align:left">' . _('Poste') . 
$info_poste . '</th>' .
-                        '<th style="text-align:left">' . _('Libellé') . 
'</th>' .
-                        '<th style="text-align:left">' . _('Montant') . 
'</th>' .
-                        '<th style="text-align:left">' . _('Débit') . '</th>' .
-                        '</tr>';
-
-
-        for ($i = 0; $i < $nb_row; $i++)
-        {
-                // Quick Code
-                $quick_code = new ICard('qc_' . $i);
-                $quick_code->set_dblclick("fill_ipopcard(this);");
-                $quick_code->set_attribute('ipopup', 'ipopcard');
-
-                // name of the field to update with the name of the card
-                $quick_code->set_attribute('label', "ld" . $i);
-                $quick_code->set_attribute('jrn', $legder->id);
-
-                // name of the field to update with the name of the card
-                $quick_code->set_attribute('typecard', 'filter');
-
-                // Add the callback function to filter the card on the jrn
-                $quick_code->set_callback('filter_card');
-                $quick_code->set_function('fill_data');
-                $quick_code->javascript = sprintf(' 
onchange="fill_data_onchange(\'%s\');" ', $quick_code->name);
-
-                $quick_code->jrn = $legder->id;
-                $quick_code->value = (isset(${'qc_' . $i})) ? ${'qc_' . $i} : 
"";
-
-                $label = '';
-                if ($quick_code->value != '')
-                {
-                        $Fiche = new Fiche($legder->db);
-                        $Fiche->get_by_qcode($quick_code->value);
-                        $label = $Fiche->strAttribut(ATTR_DEF_NAME);
-                }
-
-
-                // Account
-                $poste = new IPoste();
-                $poste->name = 'poste' . $i;
-                $poste->set_attribute('jrn', $legder->id);
-                $poste->set_attribute('ipopup', 'ipop_account');
-                $poste->set_attribute('label', 'ld' . $i);
-                $poste->set_attribute('account', 'poste' . $i);
-                $poste->set_attribute('dossier', Dossier::id());
-
-                $poste->value = (isset(${'poste' . $i})) ? ${"poste" . $i} : ''
-                ;
-                $poste->dbl_click_history();
-
-
-                if ($poste->value != '')
-                {
-                        $Poste = new Acc_Account($legder->db);
-                        $Poste->set_parameter('value', $poste->value);
-                        $label = $Poste->get_lib();
-                }
-
-                // Description of the line
-                $line_desc = new IText();
-                $line_desc->name = 'ld' . $i;
-                $line_desc->size = 30;
-                $line_desc->value = (isset(${"ld" . $i})) ? ${"ld" . $i} :
-                                $label;
-
-                // Amount
-                $amount = new INum();
-                $amount->size = 10;
-                $amount->name = 'amount' . $i;
-                $amount->value = (isset(${'amount' . $i})) ? ${"amount" . $i} 
: ''
-                ;
-                $amount->javascript = ' 
onChange="format_number(this);checkTotalDirect()"';
-                // D/C
-                $deb = new ICheckBox();
-                $deb->name = 'ck' . $i;
-                $deb->selected = (isset(${'ck' . $i})) ? true : false;
-                $deb->javascript = ' onChange="checkTotalDirect()"';
-
-                $ret.='<tr>';
-                $ret.='<td>' . $quick_code->input() . $quick_code->search() . 
'</td>';
-                $ret.='<td>' . $poste->input() .
-                                '<script> document.getElementById(\'poste' . 
$i . '\').onblur=function(){ if (trim(this.value) !=\'\') 
{document.getElementById(\'qc_' . $i . '\').value="";}}</script>' .
-                                '</td>';
-                $ret.='<td>' . $line_desc->input() . '</td>';
-                $ret.='<td>' . $amount->input() . '</td>';
-                $ret.='<td>' . $deb->input() . '</td>';
-                $ret.='</tr>';
-                // If readonly == 1 then show CA
-        }
-        $ret.='</table>';
-        return $ret;
-    }
-}
diff --git a/include/class_pre_op_fin.php b/include/class_pre_op_fin.php
deleted file mode 100644
index ca28933..0000000
--- a/include/class_pre_op_fin.php
+++ /dev/null
@@ -1,135 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief definition of the class Pre_op_fin
- */
-require_once  NOALYSS_INCLUDE.'/class_pre_operation.php';
-
-/*---------------------------------------------------------------------- */
-/*!\brief concerns the predefined operation for FIN ledger
- */
-class Pre_op_fin extends Pre_operation_detail
-{
-    var $op;
-    function __construct($cn)
-    {
-        parent::__construct($cn);
-        $this->operation->od_direct='f';
-    }
-
-    function get_post()
-    {
-        parent::get_post();
-        $this->operation->od_direct='f';
-        $this->e_bank_account=$_POST['e_bank_account'];
-        for ($i=0;$i<$this->operation->nb_item;$i++)
-        {
-            $this->{"e_other".$i}=$_POST['e_other'.$i];
-            $this->{"e_other".$i."_comment"}=$_POST['e_other'.$i.'_comment'];
-            $this->{"e_other".$i."_amount"}=$_POST['e_other'.$i."_amount"];
-        }
-    }
-    /*!
-     * \brief save the detail and op in the database
-     *
-     */
-    function save()
-    {
-        try
-        {
-            $this->db->start();
-            if ($this->operation->save() == false )
-                return;
-            // save the client
-            $sql=sprintf('insert into op_predef_detail 
(od_id,opd_poste,opd_debit)'.
-                         ' values '.
-                         "(%d,'%s','%s')",
-                         $this->operation->od_id,
-                         $this->e_bank_account,
-                         "t");
-            $this->db->exec_sql($sql);
-            // save the selling
-            for ($i=0;$i<$this->operation->nb_item;$i++)
-            {
-                $sql=sprintf('insert into op_predef_detail (opd_poste,'.
-                             'opd_amount,opd_comment,'.
-                             'opd_debit,od_id)'.
-                             ' values '.
-                             "('%s',%.2f,'%s','%s',%d)",
-                             $this->{"e_other".$i},
-                             $this->{"e_other".$i."_amount"},
-                             $this->{"e_other".$i."_comment"},
-                             'f',
-                             $this->operation->od_id
-                            );
-                $this->db->exec_sql($sql);
-            }
-        }
-        catch (Exception $e)
-        {
-            echo ($e->getMessage());
-            $this->db->rollback();
-        }
-
-    }
-    /*!\brief compute an array accordingly with the FormVenView function
-     */
-    function compute_array()
-    {
-        $count=0;
-        $a_op=$this->operation->load();
-        $array=$this->operation->compute_array($a_op);
-        $p_array=$this->load();
-        foreach ($p_array as $row)
-        {
-            if ( $row['opd_debit']=='t')
-            {
-                $array+=array('e_bank_account'=>$row['opd_poste']);
-            }
-            else
-            {
-                $array+=array("e_other".$count=>$row['opd_poste'],
-                              "e_other".$count."_amount"=>$row['opd_amount'],
-                              "e_other".$count."_comment"=>$row['opd_comment']
-                             );
-                $count++;
-            }
-        }
-        return $array;
-    }
-    /*!\brief load the data from the database and return an array
-     * \return an array 
-     */
-    function load()
-    {
-        $sql="select opd_id,opd_poste,opd_amount,opd_comment,opd_debit".
-             " from op_predef_detail where od_id=".$this->operation->od_id.
-             " order by opd_id";
-        $res=$this->db->exec_sql($sql);
-        $array=Database::fetch_all($res);
-        return $array;
-    }
-    function set_od_id($p_id)
-    {
-        $this->operation->od_id=$p_id;
-    }
-}
diff --git a/include/class_pre_op_ods.php b/include/class_pre_op_ods.php
deleted file mode 100644
index c47b002..0000000
--- a/include/class_pre_op_ods.php
+++ /dev/null
@@ -1,122 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief definition of the class Pre_op_ods
- */
-require_once  NOALYSS_INCLUDE.'/class_pre_operation.php';
-
-/*---------------------------------------------------------------------- */
-/*!\brief concerns the predefined operation for ODS ledger
-*/
-class Pre_op_ods extends Pre_operation_detail
-{
-    var $op;
-    function __construct($cn,$p_id=0)
-    {
-        parent::__construct($cn,$p_id);
-        $this->operation->od_direct='f';
-    }
-
-    function get_post()
-    {
-        parent::get_post();
-        $this->operation->od_direct='f';
-        for ($i=0;$i<$this->operation->nb_item;$i++)
-        {
-
-            $this->{"e_account".$i}=$_POST['e_account'.$i];
-            $this->{"e_account".$i."_amount"}=$_POST['e_account'.$i."_amount"];
-            $this->{"e_account".$i."_type"}=$_POST['e_account'.$i."_type"];
-
-        }
-    }
-    /*!
-     * \brief save the detail and op in the database
-     *
-     */
-    function save()
-    {
-        try
-        {
-            $this->db->start();
-            if ($this->operation->save() == false )
-                return;
-
-            // save the selling
-            for ($i=0;$i<$this->operation->nb_item;$i++)
-            {
-                $sql=sprintf('insert into op_predef_detail 
(opd_poste,opd_amount,'.
-                             'opd_debit,od_id)'.
-                             ' values '.
-                             "('%s',%.2f,'%s',%d)",
-                             $this->{"e_account".$i},
-                             $this->{"e_account".$i."_amount"},
-                             ($this->{"e_account".$i."_type"}=='d')?'t':'f',
-                             $this->operation->od_id
-                            );
-                $this->db->exec_sql($sql);
-            }
-        }
-        catch (Exception $e)
-        {
-            echo ($e->getMessage());
-            $this->db->rollback();
-        }
-
-    }
-    /*!\brief compute an array accordingly with the FormVenView function
-     */
-    function compute_array()
-    {
-        $count=0;
-        $a_op=$this->operation->load();
-        $array=$this->operation->compute_array($a_op);
-        $p_array=$this->load();
-        foreach ($p_array as $row)
-        {
-            $c=($row['opd_debit']=='t')?'d':'c';
-            $array+=array("e_account".$count=>$row['opd_poste'],
-                          "e_account".$count."_amount"=>$row['opd_amount'],
-                          "e_account".$count."_type"=>$c
-                         );
-            $count++;
-
-        }
-        return $array;
-    }
-    /*!\brief load the data from the database and return an array
-     * \return an array 
-     */
-    function load()
-    {
-        $sql="select opd_id,opd_poste,opd_amount,opd_debit".
-             "  from op_predef_detail where od_id=".$this->operation->od_id.
-             " order by opd_debit, opd_id,opd_amount";
-        $res=$this->db->exec_sql($sql);
-        $array=Database::fetch_all($res);
-        return $array;
-    }
-    function set_od_id($p_id)
-    {
-        $this->operation->od_id=$p_id;
-    }
-}
diff --git a/include/class_pre_op_ven.php b/include/class_pre_op_ven.php
deleted file mode 100644
index 9894aec..0000000
--- a/include/class_pre_op_ven.php
+++ /dev/null
@@ -1,387 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief definition of the class Pre_op_ven
- */
-require_once  NOALYSS_INCLUDE.'/class_pre_operation.php';
-
-/*---------------------------------------------------------------------- */
-/*!\brief concerns the predefined operation for VEN ledger
-*/
-class Pre_op_ven extends Pre_operation_detail
-{
-    var $op;
-    function __construct($cn,$p_id=0)
-    {
-        parent::__construct($cn,$p_id);
-        $this->operation->od_direct='f';
-    }
-
-    function get_post()
-    {
-        parent::get_post();
-        $this->operation->od_direct='f';
-        $this->e_client=$_POST['e_client'];
-        for ($i=0;$i<$this->operation->nb_item;$i++)
-        {
-            $march="e_march".$i;
-            $this->$march=$_POST['e_march'.$i];
-            $this->{"e_march".$i."_price"}=$_POST['e_march'.$i."_price"];
-            
$this->{"e_march".$i."_tva_id"}=(isset($_POST['e_march'.$i."_tva_id"]))?$_POST['e_march'.$i."_tva_id"]:0;
-            $this->{"e_quant".$i}=$_POST['e_quant'.$i];
-
-        }
-    }
-    /*!
-     * \brief save the detail and op in the database
-     *
-     */
-    function save()
-    {
-        try
-        {
-            $this->db->start();
-            if ($this->operation->save() == false )
-                return;
-            // save the client
-            $sql=sprintf('insert into op_predef_detail 
(od_id,opd_poste,opd_debit)'.
-                         ' values '.
-                         "(%d,'%s','%s')",
-                         $this->operation->od_id,
-                         $this->e_client,
-                         "t");
-            $this->db->exec_sql($sql);
-            // save the selling
-            for ($i=0;$i<$this->operation->nb_item;$i++)
-            {
-                if ( strlen(trim($this->{"e_march".$i}))==0) continue;
-                $sql=sprintf('insert into op_predef_detail 
(opd_poste,opd_amount,opd_tva_id,opd_quantity,'.
-                             'opd_debit,od_id)'.
-                             ' values '.
-                             "('%s',%.2f,%d,%f,'%s',%d)",
-                             $this->{"e_march".$i},
-                             $this->{"e_march".$i."_price"},
-                             $this->{"e_march".$i."_tva_id"},
-                             $this->{"e_quant".$i},
-                             'f',
-                             $this->operation->od_id
-                            );
-                $this->db->exec_sql($sql);
-            }
-        }
-        catch (Exception $e)
-        {
-            echo ($e->getMessage());
-            $this->db->rollback();
-        }
-        $this->db->commit();
-
-    }
-    /*!\brief compute an array accordingly with the FormVenView function
-     */
-    function compute_array()
-    {
-        $count=0;
-        $a_op=$this->operation->load();
-        $array=$this->operation->compute_array($a_op);
-        $p_array=$this->load();
-               if (empty($p_array)) return array();
-        foreach ($p_array as $row)
-        {
-            if ( $row['opd_debit']=='t')
-            {
-                $array+=array('e_client'=>$row['opd_poste']);
-            }
-            else
-            {
-                $array+=array("e_march".$count=>$row['opd_poste'],
-                              "e_march".$count."_price"=>$row['opd_amount'],
-                              "e_march".$count."_tva_id"=>$row['opd_tva_id'],
-                              "e_quant".$count=>$row['opd_quantity']
-                             );
-                $count++;
-            }
-        }
-        return $array;
-    }
-    /*!\brief load the data from the database and return an array
-     * \return an array
-     */
-    function load()
-    {
-        $sql="select opd_id,opd_poste,opd_amount,opd_tva_id,opd_debit,".
-             " opd_quantity from op_predef_detail where 
od_id=".$this->operation->od_id.
-             " order by opd_id";
-        $res=$this->db->exec_sql($sql);
-        $array=Database::fetch_all($res);
-        return $array;
-    }
-    function set_od_id($p_id)
-    {
-        $this->operation->od_id=$p_id;
-    }
-    function display($p_array)
-    {
-        global $g_parameter,$g_user;
-        if ( $p_array != null ) extract($p_array);
-        require_once NOALYSS_INCLUDE.'/class_acc_ledger_sold.php';
-        $ledger=new Acc_Ledger_Sold($this->db,$this->jrn_def_id);
-
-        $flag_tva=$g_parameter->MY_TVA_USE;
-        /* Add button */
-        $f_add_button=new IButton('add_card');
-               $f_add_button->tabindex=-1;
-        $f_add_button->label=_('Créer une nouvelle fiche');
-        $f_add_button->set_attribute('ipopup','ipop_newcard');
-        $f_add_button->set_attribute('jrn',$ledger->id);
-        $f_add_button->javascript="this.jrn=\$('p_jrn').value; 
select_card_type(this);";
-
-        $f_add_button2=new IButton('add_card2');
-               $f_add_button2->tabindex=-1;
-        $f_add_button2->label=_('Créer une nouvelle fiche');
-        $f_add_button2->set_attribute('ipopup','ipop_newcard');
-        $f_add_button2->set_attribute('filter',$ledger->get_all_fiche_def ());
-        //    $f_add_button2->set_attribute('jrn',$ledger->id);
-        $f_add_button2->javascript=" 
this.jrn=\$('p_jrn').value;select_card_type(this);";
-
-        $str_add_button="";
-        $str_add_button2="";
-        if ($g_user->check_action(FICADD)==1)
-        {
-                $str_add_button=$f_add_button->input();
-                $str_add_button2=$f_add_button2->input();
-        }
-
-        $r='';
-        $r.=dossier::hidden();
-        $f_legend=_('En-tête facture client');
-
-
-        /* if we suggest the next pj, then we need a javascript */
-
-        // Display the customer
-        //--
-        $fiche='deb';
-
-        // Save old value and set a new one
-        //--
-        $e_client=( isset ($e_client) )?$e_client:"";
-        $e_client_label="&nbsp;";//str_pad("",100,".");
-
-
-        // retrieve e_client_label
-        //--
-
-        if ( strlen(trim($e_client)) !=  0)
-        {
-            $fClient=new Fiche($ledger->db);
-            $fClient->get_by_qcode($e_client);
-            $e_client_label=$fClient->strAttribut(ATTR_DEF_NAME).' '.
-                            ' Adresse : 
'.$fClient->strAttribut(ATTR_DEF_ADRESS).' '.
-                            $fClient->strAttribut(ATTR_DEF_CP).' '.
-                            $fClient->strAttribut(ATTR_DEF_CITY).' ';
-
-
-        }
-
-        $W1=new ICard();
-        $W1->label="Client ".HtmlInput::infobulle(0) ;
-        $W1->name="e_client";
-        $W1->tabindex=3;
-        $W1->value=$e_client;
-        $W1->table=0;
-        $W1->set_dblclick("fill_ipopcard(this);");
-        $W1->set_attribute('ipopup','ipopcard');
-
-        // name of the field to update with the name of the card
-        $W1->set_attribute('label','e_client_label');
-        // name of the field to update with the name of the card
-        $W1->set_attribute('typecard','deb');
-
-        // Add the callback function to filter the card on the jrn
-        $W1->set_callback('filter_card');
-        $W1->set_function('fill_data');
-        $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
-                                $W1->name);
-        $f_client_qcode=$W1->input();
-        $client_label=new ISpan();
-        $client_label->table=0;
-        $f_client=$client_label->input("e_client_label",$e_client_label);
-        $f_client_bt=$W1->search();
-
-
-        // Record the current number of article
-               $min=$ledger->get_min_row();
-        $p_article= ( isset ($nb_item))?$nb_item:$min;
-        $max=($p_article < $min)?$min:$p_article;
-
-        $e_comment=(isset($e_comment))?$e_comment:"";
-        $Hid=new IHidden();
-        $r.=$Hid->input("nb_item",$p_article);
-
-        $f_legend_detail=_("Détail articles vendus");
-
-        // For each article
-        //--
-        for ($i=0;$i< $max;$i++)
-        {
-            // Code id, price & vat code
-            //--
-            $march=(isset(${"e_march$i"}))?${"e_march$i"}:""
-                   ;
-            
$march_price=(isset(${"e_march".$i."_price"}))?${"e_march".$i."_price"}:""
-                         ;
-            if ( $flag_tva=='Y')
-            {
-                
$march_tva_id=(isset(${"e_march$i"."_tva_id"}))?${"e_march$i"."_tva_id"}:"";
-                
$march_tva_amount=(isset(${"e_march$i"."_tva_amount"}))?${"e_march$i"."_tva_amount"}:"";
-            }
-            
$march_label=(isset(${"e_march".$i."_label"}))?${"e_march".$i."_label"}:"";
-
-            // retrieve the tva label and name
-            //--
-            if ( strlen(trim($march))!=0 && strlen(trim($march_label))==0)
-            {
-                $fMarch=new Fiche($ledger->db);
-                $fMarch->get_by_qcode($march);
-                $march_label=$fMarch->strAttribut(ATTR_DEF_NAME);
-                if ( $flag_tva=='Y')
-                {
-                    if ( ! (isset(${"e_march$i"."_tva_id"})))
-                        $march_tva_id=$fMarch->strAttribut(ATTR_DEF_TVA);
-                }
-            }
-            // Show input
-            //--
-            $W1=new ICard();
-            $W1->label="";
-            $W1->name="e_march".$i;
-            $W1->value=$march;
-            $W1->table=1;
-            $W1->set_attribute('typecard','cred');
-            $W1->set_dblclick("fill_ipopcard(this);");
-            $W1->set_attribute('ipopup','ipopcard');
-
-            // name of the field to update with the name of the card
-            $W1->set_attribute('label','e_march'.$i.'_label');
-            // name of the field with the price
-            $W1->set_attribute('price','e_march'.$i.'_price');
-            // name of the field with the TVA_ID
-            $W1->set_attribute('tvaid','e_march'.$i.'_tva_id');
-            // Add the callback function to filter the card on the jrn
-            $W1->set_callback('filter_card');
-            $W1->set_function('fill_data');
-            $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
-                                    $W1->name);
-
-            $W1->readonly=false;
-
-            $array[$i]['quick_code']=$W1->input();
-            $array[$i]['bt']=$W1->search();
-            // For computing we need some hidden field for holding the value
-            $array[$i]['hidden']='';
-            if ( $flag_tva=='Y') 
$array[$i]['hidden'].=HtmlInput::hidden('tva_march'.$i,0);
-
-            $htva=new INum('htva_march'.$i);
-            $htva->readOnly=1;
-            $htva->value=0;
-            $array[$i]['htva']=$htva->input();
-
-            if ( $g_parameter->MY_TVA_USE=='Y')
-                $tvac=new INum('tvac_march'.$i);
-            else
-                $tvac=new IHidden('tvac_march'.$i);
-
-            $tvac->readOnly=1;
-            $tvac->value=0;
-            $array[$i]['tvac']=$tvac->input();
-
-            if ( $g_parameter->MY_UPDLAB == 'Y')
-            {
-                $Span=new IText("e_march".$i."_label");
-
-                $Span->css_size="100%";
-            } else
-            {
-                $Span=new ISpan("e_march".$i."_label");
-            }
-            $Span->value=$march_label;
-            $Span->setReadOnly(false);
-            // card's name, price
-            //--
-            
$array[$i]['denom']=$Span->input("e_march".$i."_label",$march_label);
-            // price
-            $Price=new INum();
-            $Price->setReadOnly(false);
-            $Price->size=9;
-            
$Price->javascript="onBlur='format_number(this);clean_tva($i);compute_ledger($i)'";
-            $array[$i]['pu']=$Price->input("e_march".$i."_price",$march_price);
-            $array[$i]['tva']='';
-            $array[$i]['amount_tva']='';
-            // if tva is not needed then no tva field
-            if ( $flag_tva == 'Y' )
-            {
-                // vat label
-                //--
-                $Tva=new ITva_Popup($ledger->db);
-                $Tva->in_table=true;
-                $Tva->set_attribute('compute',$i);
-
-                
$Tva->js='onblur="format_number(this);clean_tva('.$i.');compute_ledger('.$i.')"';
-                $Tva->value=$march_tva_id;
-                $array[$i]['tva']=$Tva->input("e_march$i"."_tva_id");
-                // vat amount
-                //--
-                $wTva_amount=new INum();
-                $wTva_amount->readOnly=false;
-                $wTva_amount->size=6;
-                
$wTva_amount->javascript="onBlur='format_number(this);compute_ledger($i)'";
-                
$array[$i]['amount_tva']=$wTva_amount->input("e_march".$i."_tva_amount",$march_tva_amount);
-            }
-            // quantity
-            //--
-            $quant=(isset(${"e_quant$i"}))?${"e_quant$i"}:"1"
-                   ;
-            $Quantity=new INum();
-            $Quantity->setReadOnly(false);
-            $Quantity->size=8;
-            
$Quantity->javascript="onChange='format_number(this);clean_tva($i);compute_ledger($i)'";
-            $array[$i]['quantity']=$Quantity->input("e_quant".$i,$quant);
-
-        }// foreach article
-        $f_type=_('Client');
-
-
-        ob_start();
-        require_once NOALYSS_INCLUDE.'/template/predf_ledger_detail.php';
-        $r.=ob_get_contents();
-        ob_end_clean();
-
-
-
-        // Set correctly the REQUEST param for jrn_type
-        $r.=HtmlInput::hidden('jrn_type','VEN');
-
-        $r.=HtmlInput::button('add_item',_('Ajout article'),      ' 
onClick="ledger_add_row()"');
-        return $r;
-    }
-}
diff --git a/include/class_pre_operation.php b/include/class_pre_operation.php
deleted file mode 100644
index a0c13b9..0000000
--- a/include/class_pre_operation.php
+++ /dev/null
@@ -1,332 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief definition of Pre_operation
- */
-
-/*! \brief manage the predefined operation, link to the table op_def
- * and op_def_detail
- *
- */
-require_once NOALYSS_INCLUDE.'/class_iselect.php';
-require_once NOALYSS_INCLUDE.'/class_ihidden.php';
-require_once NOALYSS_INCLUDE.'/class_pre_op_ach.php';
-require_once NOALYSS_INCLUDE.'/class_pre_op_ven.php';
-require_once NOALYSS_INCLUDE.'/class_pre_op_advanced.php';
-class Pre_operation
-{
-    var $db;                                           /*!< $db database 
connection */
-    var $nb_item;                                      /*!< $nb_item nb of 
item */
-    var $p_jrn;                                        /*!< $p_jrn jrn_def_id 
*/
-    var $jrn_type;                                     /*!< $jrn_type */
-    var $name;                                         /*!< $name name of the 
predef. operation */
-
-    function Pre_operation($cn,$p_id=0)
-    {
-        $this->db=$cn;
-        $this->od_direct='false';
-        $this->od_id=$p_id;
-    }
-    /**
-     * @brief Propose to save the operation into a predefined operation
-     * @return HTML  string
-     */
-    static function save_propose() {
-        $r="";
-        $r.= '<p class="decale">';
-        $r.= _("Donnez un nom pour sauver cette opération comme modèle")." 
<br>";
-        $opd_name = new IText('opd_name');
-        $r.= "Nom du modèle " . $opd_name->input();
-        $opd_description=new ITextarea('od_description');
-        $opd_description->style=' class="itextarea" 
style="width:30em;height:4em;vertical-align:top"';
-        $r.='</p>';
-        $r.= '<p class="decale">';
-        $r.= _('Description (max 50 car.)');   
-        $r.='<br>';
-        $r.=$opd_description->input();
-        $r.='</p>';
-        return $r;
-    }
-
-    /*!\brief fill the object with the $_POST variable */
-    function get_post()
-    {
-        $this->nb_item=$_POST['nb_item'];
-        $this->p_jrn=$_REQUEST['p_jrn'];
-        $this->jrn_type=$_POST['jrn_type'];
-        
-       $this->name=$_POST['opd_name'];
-
-        $this->name=(trim($this->name)=='')?$_POST['e_comm']:$this->name;
-        $this->description=  $_POST['od_description'];
-        if ( $this->name=="")
-        {
-            $n=$this->db->get_next_seq('op_def_op_seq');
-            $this->name=$this->jrn_type.$n;
-            // common value
-        }
-    }
-    function delete ()
-    {
-        $sql="delete from op_predef where od_id=".$this->od_id;
-        $this->db->exec_sql($sql);
-    }
-    /*!\brief save the predef check first is the name is unique
-     * \return true op.success otherwise false
-     */
-    function save()
-    {
-
-        if (   $this->db->count_sql("select * from op_predef ".
-                                  "where 
upper(od_name)=upper('".Database::escape_string($this->name)."')".
-                                  "and jrn_def_id=".$this->p_jrn)
-                != 0 )
-        {
-            $this->name="copy_".$this->name."_".microtime(true);
-        }
-        if ( $this->count()  > MAX_PREDEFINED_OPERATION )
-        {
-            echo '<span class="notice">'.("Vous avez atteint le max. 
d'op&eacute;ration pr&eacute;d&eacute;finie, d&eacute;sol&eacute;").'</span>';
-            return false;
-        }
-        $sql='insert into op_predef 
(jrn_def_id,od_name,od_item,od_jrn_type,od_direct,od_description)'.
-                     'values'.
-                     "($1,$2,$3,$4,$5  ,$6               )";
-        $this->db->exec_sql($sql,array($this->p_jrn,
-                     $this->name,
-                     $this->nb_item,
-                     $this->jrn_type,
-                     $this->od_direct,
-                     $this->description,
-            ));
-        $this->od_id=$this->db->get_current_seq('op_def_op_seq');
-        return true;
-    }
-    /*!\brief load the data from the database and return an array
-     * \return an array
-     */
-    function load()
-    {
-        $sql="select 
od_id,jrn_def_id,od_name,od_item,od_jrn_type,od_description".
-             " from op_predef where od_id=".$this->od_id.
-             " order by od_name";
-        $res=$this->db->exec_sql($sql);
-        $array=Database::fetch_all($res);
-        foreach 
(array('jrn_def_id','od_name','od_item','od_jrn_type','od_description') as 
$field) {
-            $this->$field=$array[0][$field];
-        }
-        switch ($this->od_jrn_type) {
-            case 'ACH':
-                $this->detail=new Pre_op_ach($this->db);
-                break;
-            case 'VEN':
-                $this->detail=new Pre_Op_ven($this->db);
-                break;
-            case 'ODS':
-                $this->detail=new Pre_op_advanced($this->db);
-                break;
-            default:
-                throw new Exception('Load PreOperatoin 
failed'.$this->od_jrn_type);
-          }
-        $this->detail->set_od_id($this->od_id);
-        $this->detail->jrn_def_id=$this->jrn_def_id;
-        
-        return $array;
-    }
-    function compute_array()
-    {
-        $p_array=$this->load();
-        $array=array(
-                   "e_comm"=>$p_array[0]["od_name"],
-                   
"nb_item"=>(($p_array[0]["od_item"]<10?10:$p_array[0]["od_item"]))   ,
-                   "p_jrn"=>$p_array[0]["jrn_def_id"],
-                   "jrn_type"=>$p_array[0]["od_jrn_type"],
-                   "od_description"=>$p_array['0']['od_description']
-               );
-        return $array;
-
-    }
-
-    /*!\brief show the button for selecting a predefined operation */
-    function show_button()
-    {
-
-        $select=new ISelect();
-        $value=$this->db->make_array("select od_id,od_name from op_predef ".
-                                     " where jrn_def_id=".$this->p_jrn.
-                                     " and od_direct ='".$this->od_direct."'".
-                                     " order by od_name");
-
-        if ( empty($value)==true) return "";
-        $select->value=$value;
-        $r=$select->input("pre_def");
-
-        return $r;
-    }
-    /*!\brief count the number of pred operation for a ledger */
-    function count()
-    {
-        $a=$this->db->count_sql("select od_id,od_name from op_predef ".
-                                " where jrn_def_id=".$this->p_jrn.
-                                " and od_direct ='".$this->od_direct."'".
-                                " order by od_name");
-        return $a;
-    }
-    /*!\brief get the list of the predef. operation of a ledger
-     * \return string
-     */
-    function get_list_ledger()
-    {
-        $sql="select od_id,od_name,od_description from op_predef ".
-             " where jrn_def_id=".$this->p_jrn.
-             " and od_direct ='".$this->od_direct."'".
-             " order by od_name";
-        $res=$this->db->exec_sql($sql);
-        $all=Database::fetch_all($res);
-        return $all;
-    }
-    /*!\brief set the ledger
-     * \param $p_jrn is the ledger (jrn_id)
-     */
-    function set_jrn($p_jrn)
-    {
-        $this->p_jrn=$p_jrn;
-    }
-   
-    /**
-     * 
-     * @brief display the detail of predefined operation, normally everything 
-     * is loaded
-     */
-    function display() 
-    {
-        $array=$this->detail->compute_array();
-        echo $this->detail->display($array);
-    }
-}
-
-/*!\brief mother of the pre_op_XXX, it contains only one data : an
- * object Pre_Operation. The child class contains an array of
- * Pre_Operation object
- */
-class Pre_operation_detail
-{
-    var $operation;
-    function __construct($p_cn,$p_id=0)
-    {
-        $this->db=$p_cn;
-        $this->operation=new Pre_operation($this->db);
-        
$this->valid=array('ledger'=>'jrn_def_id','ledger_type'=>'jrn_type','direct'=>'od_direct');
-               $this->jrn_def_id=-1;
-    }
-
-
-    /*!\brief show a form to use pre_op
-     */
-    function form_get ($p_url)
-    {
-        $r=HtmlInput::button_action(_("Modèle d'opérations"), ' 
$(\'modele_op_div\').style.display=\'block\';$(\'lk_modele_op_tab\').focus();');
-        $r.='<div id="modele_op_div" class="noprint">';
-        $r.=HtmlInput::title_box(_("Modèle d'opérations"), 'modele_op_div', 
'hide');
-        $hid=new IHidden();
-        $r.=$hid->input("action","use_opd");
-        $r.=$hid->input("jrn_type",$this->get("ledger_type"));
-        $r.= $this->show_button($p_url);
-        $r.='</div>';
-        return $r;
-
-    }
-    /*!\brief count the number of pred operation for a ledger */
-    function count()
-    {
-        $a=$this->db->count_sql("select od_id,od_name from op_predef ".
-                                " where jrn_def_id=".$this->jrn_def_id.
-                                " and od_direct ='".$this->od_direct."'".
-                                " order by od_name");
-        return $a;
-    }
-    /*!\brief show the button for selecting a predefined operation */
-    function show_button($p_url)
-    {
-        
-        
-        $value=$this->db->get_array("select od_id,od_name,od_description from 
op_predef ".
-                                     " where jrn_def_id=$1".
-                                     " and od_direct =$2".
-                                     " order by od_name",
-                            array($this->jrn_def_id,$this->od_direct ));
-        
-        if ( $this->jrn_def_id=='') $value=array();
-        
-        $r="";
-        $r.='<h2>'._("Choisissez un modèle").'</h2>';
-        $r.=_('Filtrer').' '.HtmlInput::filter_table('modele_op_tab', '0', 
'0');
-        $r.='<table style="width:100%" id="modele_op_tab">';
-        for ($i=0;$i<count($value);$i++) {
-            $r.='<tr class="'.(($i%2==0)?"even":"odd").'">';
-            $r.='<td 
style="font-weight:bold;vertical-align:top;text-decoration:underline">';
-            $r.=sprintf('<a href="%s&pre_def=%s" 
onclick="waiting_box()">%s</a> ',
-                    $p_url,$value[$i]['od_id'],$value[$i]['od_name']);
-            $r.='</td>';
-            $r.='<td>'.h($value[$i]['od_description']).'</td>';
-            $r.='</tr>';
-        }
-        $r.='</table>';
-        return $r;
-    }
-    public function   get_operation()
-    {
-               if ( $this->jrn_def_id=='') return array();
-        $value=$this->db->make_array("select od_id,od_name from op_predef ".
-                                     " where 
jrn_def_id=".sql_string($this->jrn_def_id).
-                                     " and od_direct 
='".sql_string($this->od_direct)."'".
-                                     " order by od_name",1);
-        return $value;
-    }
-    function set($p_param,$value)
-    {
-        if ( ! isset ($this->valid[$p_param] ) )
-        {
-            $msg=_(" le parametre $p_param n'existe pas 
".__FILE__.':'.__LINE__);
-            throw new Exception($msg);
-        }
-        $attr=$this->valid[$p_param];
-        $this->$attr=$value;
-    }
-    function get($p_param)
-    {
-
-        if ( ! isset ($this->valid[$p_param] ) )
-        {
-            $msg=_(" le parametre $p_param n'existe pas 
".__FILE__.':'.__LINE__);
-            throw new Exception($msg);
-        }
-        $attr=$this->valid[$p_param];
-        return $this->$attr;
-    }
-
-    function get_post()
-    {
-        $this->operation->get_post();
-    }
-
-}
diff --git a/include/class_print_ledger.php b/include/class_print_ledger.php
deleted file mode 100644
index d143503..0000000
--- a/include/class_print_ledger.php
+++ /dev/null
@@ -1,130 +0,0 @@
-<?php
-
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-/**
- *  Parent class for the print_ledger class
- *
- * @author danydb
- */
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_print_ledger_detail.php';
-require_once NOALYSS_INCLUDE.'/class_print_ledger_simple.php';
-require_once NOALYSS_INCLUDE.'/class_print_ledger_simple_without_vat.php';
-require_once NOALYSS_INCLUDE.'/class_print_ledger_fin.php';
-require_once NOALYSS_INCLUDE.'/class_print_ledger_misc.php';
-require_once NOALYSS_INCLUDE.'/class_print_ledger_detail_item.php';
-
-/**
- * @brief Strategie class for the print_ledger class
- * 
- */
-class Print_Ledger {
-
-    /**
-     * Create an object Print_Ledger* depending on $p_type_export ( 0 => 
accounting
-     * 1-> one row per operation 2-> detail of item)
-     * @param type $cn
-     * @param type $p_type_export
-     * @param type $p_format_output CSV or PDF
-     * @param Acc_Ledger $ledger
-     */
-    static function factory(Database $cn, $p_type_export, $p_format_output, 
Acc_Ledger $p_ledger) {
-        /**
-         * For PDF output
-         */
-        if ($p_format_output == 'PDF') {
-            switch ($p_type_export) {
-                case 0:
-                    //---------------------------------------------
-                    // Detailled Printing (accounting )
-                    //---------------------------------------------
-                    return new Print_Ledger_Detail($cn, $p_ledger);
-                    break;
-
-                case 1:
-                    
//----------------------------------------------------------------------
-                    // Simple Printing Purchase Ledger
-                    
//---------------------------------------------------------------------
-                    $own = new Own($cn);
-                    $jrn_type = $p_ledger->get_type();
-
-
-                    if ($jrn_type == 'ACH' || $jrn_type == 'VEN') {
-                        if (
-                                ($jrn_type == 'ACH' && $cn->get_value('select 
count(qp_id) from quant_purchase') == 0) ||
-                                ($jrn_type == 'VEN' && $cn->get_value('select 
count(qs_id) from quant_sold') == 0)
-                        ) {
-                            $pdf = new Print_Ledger_Simple_without_vat($cn, 
$p_ledger);
-                            $pdf->set_error(_('Ce journal ne peut être imprimé 
en mode simple'));
-                            return $pdf;
-                        }
-                        if ($own->MY_TVA_USE == 'Y') {
-                            $pdf = new Print_Ledger_Simple($cn, $p_ledger);
-                            return $pdf;
-                        }
-                        if ($own->MY_TVA_USE == 'N') {
-                            $pdf = new Print_Ledger_Simple_without_vat($cn, 
$p_ledger);
-                            return $pdf;
-                        }
-                    }
-
-                    if ($jrn_type == 'FIN') {
-                        $pdf = new Print_Ledger_Financial($cn, $p_ledger);
-                        return $pdf;
-                    }
-                    if ($jrn_type == 'ODS' || $p_ledger->id == 0) {
-                        $pdf = new Print_Ledger_Misc($cn, $p_ledger);
-                        return $pdf;
-                    }
-                    break;
-                case 2:
-                    /**********************************************************
-                     * Print Detail Operation + Item
-                     
********************************************************** */
-                    $own = new Own($cn);
-                    $jrn_type = $p_ledger->get_type();
-                    if ($jrn_type == 'FIN') {
-                        $pdf = new Print_Ledger_Financial($cn, $p_ledger);
-                        return $pdf;
-                        ;
-                    }
-                    if ($jrn_type == 'ODS' || $p_ledger->id == 0) {
-                        $pdf = new Print_Ledger_Misc($cn, $p_ledger);
-                        return $pdf;
-                    }
-                    if (
-                            ($jrn_type == 'ACH' && $cn->get_value('select 
count(qp_id) from quant_purchase') == 0) ||
-                            ($jrn_type == 'VEN' && $cn->get_value('select 
count(qs_id) from quant_sold') == 0)
-                    ) {
-                        $pdf = new Print_Ledger_Simple_without_vat($cn, 
$p_ledger);
-                        $pdf->set_error('Ce journal ne peut être imprimé en 
mode simple');
-                        return $pdf;
-                    }
-                    $pdf = new Print_Ledger_Detail_Item($cn,$p_ledger);
-                    return $pdf;
-                    
-            } // end switch
-        } // end $p_format == PDF
-    }
-
-// end function
-}
-
-?>
diff --git a/include/class_print_ledger_detail.php 
b/include/class_print_ledger_detail.php
deleted file mode 100644
index 7806143..0000000
--- a/include/class_print_ledger_detail.php
+++ /dev/null
@@ -1,148 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief this class extends PDF and let you export the detailled printing
- *  of any ledgers
- */
-require_once NOALYSS_INCLUDE.'/class_pdf.php';
-
-class Print_Ledger_Detail extends PDF
-{
-    public function __construct ($p_cn = null, Acc_Ledger $ledger)
-    {
-
-        if($p_cn == null) die("No database connection. Abort.");
-        
-        parent::__construct($p_cn,'L', 'mm', 'A4');
-        $this->ledger=$ledger;
-        date_default_timezone_set ('Europe/Paris');
-
-    }
-
-    function setDossierInfo($dossier = "n/a")
-    {
-        $this->dossier = dossier::name()." ".$dossier;
-    }
-
-    function Header()
-    {
-        //Arial bold 12
-        $this->SetFont('DejaVu', 'B', 12);
-        //Title
-        $this->Cell(0,10,$this->dossier, 'B', 0, 'C');
-        //Line break
-        $this->Ln(20);
-    }
-    function Footer()
-    {
-        //Position at 2 cm from bottom
-        $this->SetY(-20);
-        //Arial italic 8
-        $this->SetFont('Arial', 'I', 8);
-        //Page number
-        $this->Cell(0,8,'Date '.$this->date." - Page 
".$this->PageNo().'/{nb}',0,0,'L');
-        // Created by NOALYSS
-        $this->Cell(0,8,'Created by NOALYSS, online on 
http://www.aevalys.eu',0,0,'R',false,'http://www.aevalys.eu');
-
-    }
-    function Cell ($w, $h=0, $txt='', $border=0, $ln=0, $align='', 
$fill=false, $link='')
-    {
-        $txt = str_replace("\\", "", $txt);
-        return parent::Cell($w, $h, $txt, $border, $ln, $align, $fill, $link);
-    }
-
-    function export()
-    {
-        
-        // detailled printing
-        $rap_deb=0;
-        $rap_cred=0;
-        // take all operations from jrn
-        
$array=$this->ledger->get_operation($_GET['from_periode'],$_GET['to_periode']);
-
-        $this->SetFont('DejaVu','BI',7);
-        $this->Cell(215,7,'report Débit',0,0,'R');
-        $this->Cell(30,7,nbm($rap_deb),0,0,'R');
-        $this->Ln(4);
-        $this->Cell(215,7,'report Crédit',0,0,'R');
-        $this->Cell(30,7,nbm($rap_cred),0,0,'R');
-        $this->Ln(4);
-
-        // print all operation
-        for ($i=0;$i< count($array);$i++)
-        {
-            $this->SetFont('DejaVuCond','B',7);
-            $row=$array[$i];
-
-            $this->LongLine(20,7,$row['pj']);
-            $this->Cell(15,7,$row['date_fmt']);
-            $this->Cell(20,7,$row['internal']);
-            $this->LongLine(170,7,$row['comment']);
-            $this->Cell(20,7,nbm($row['montant']),0,0,'R');
-
-            $this->Ln();
-            // get the entries
-            $aEntry=$this->cn->get_array("select 
j_id,j_poste,j_qcode,j_montant,j_debit, j_text,".
-                                                                               
 " case when j_text='' or j_text is null then pcm_lib else j_text end as desc,".
-                                         " pcm_lib ".
-                                         " from jrnx join tmp_pcmn on 
(j_poste=pcm_val) where j_grpt = $1".
-                                         " order by j_debit desc,j_id",
-                                         array($row['jr_grpt_id']));
-            for ($j=0;$j<count($aEntry);$j++)
-            {
-                $this->SetFont('DejaVuCond','',7);
-                $entry=$aEntry[$j];
-                // $this->Cell(15,6,$entry['j_id'],0,0,'R');
-                $this->Cell(32,6,$entry['j_qcode'],0,0,'R');
-                $this->Cell(23,6,$entry['j_poste'],0,0,'R');
-
-                // if j_qcode is not empty retrieve name
-                if ( $entry['j_text'] =='' && $entry['j_qcode'] != '')
-                {
-                    $f_id=$this->cn->get_value('select f_id from 
vw_poste_qcode where j_qcode=$1',array($entry['j_qcode']));
-                    if ($f_id != '')
-                        $name=$this->cn->get_value('select ad_value from 
fiche_detail where f_id=$1 and ad_id=1',
-                                                   array($f_id));
-                    else
-                        $name=$entry['pcm_lib'];
-                }
-                else
-                    $name=$entry['desc'];
-                $this->Cell(150,6,$name,0,0,'L');
-
-                // print amount
-                $str_amount=nbm($entry['j_montant']);
-                if ( $entry['j_debit']=='t')
-                {
-                    $this->Cell(20,6,$str_amount,0,0,'R');
-                    $this->Cell(20,6,'',0,0,'R');
-                }
-                else
-                {
-                    $this->Cell(20,6,'',0,0,'R');
-                    $this->Cell(20,6,$str_amount,0,0,'R');
-                }
-                $this->Ln(4);
-            }
-        }
-    }
-}
diff --git a/include/class_print_ledger_detail_item.php 
b/include/class_print_ledger_detail_item.php
deleted file mode 100644
index 9bdcf83..0000000
--- a/include/class_print_ledger_detail_item.php
+++ /dev/null
@@ -1,174 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-// Copyright Author Dany De Bontridder address@hidden
-/**
- * Print detail of operation PURCHASE or SOLD plus the items
- * There is no report of the different amounts
- *
- * @author danydb
- */
-require_once NOALYSS_INCLUDE.'/class_acc_ledger_sold.php';
-require_once NOALYSS_INCLUDE.'/class_acc_ledger_purchase.php';
-class Print_Ledger_Detail_Item extends PDFLand
-{
-    public function __construct (Database $p_cn,Acc_Ledger $p_jrn)
-    {
-
-        if($p_cn == null) die("No database connection. Abort.");
-
-        parent::__construct($p_cn,'L', 'mm', 'A4');
-        $this->ledger=$p_jrn;
-        $this->show_col=true;
-    }
-
-    function setDossierInfo($dossier = "n/a")
-    {
-        $this->dossier = dossier::name()." ".$dossier;
-    }
-    /**
-     address@hidden write the header of each page
-     */
-    function Header()
-    {
-        //Arial bold 12
-        $this->SetFont('DejaVu', 'B', 12);
-        //Title
-        $this->Cell(0,10,$this->dossier, 'B', 0, 'C');
-        //Line break
-        $this->Ln(20);
-        $high=6;
-        $this->SetFont('DejaVu', '', 6);
-        $this->LongLine(20, $high, _('Date'),0,  'L', false);
-        $this->Cell(20, $high, _('Numéro interne'), 0, 0, 'L', false);
-        $this->LongLine(50, $high, _('Code'),0,'L',false);
-        $this->LongLine(80, $high, _('Libellé'),0,'L',false);
-        $this->Cell(20, $high, _('Tot HTVA'), 0, 0, 'R', false);
-        $this->Cell(20, $high, _('Tot TVA NP'), 0, 0, 'R', false);
-        $this->Cell(20, $high, "", 0, 0, 'R', false);
-        $this->Cell(20, $high, _('Tot TVA'), 0, 0, 'R', false);
-        $this->Cell(20, $high, _('TVAC'), 0, 0, 'R', false);
-        $this->Ln(6);
-        $this->show_col=true;
-        
-    }
-    /**
-     address@hidden write the Footer
-     */
-    function Footer()
-    {
-        $this->Ln(2);
-        $this->SetFont('Arial', 'I', 8);
-        $this->Cell(50,8,' Journal '.$this->ledger->get_name(),0,0,'C');
-        //Arial italic 8
-        //Page number
-        $this->Cell(30,8,'Date '.$this->date." - Page 
".$this->PageNo().'/{nb}',0,0,'L');
-        // Created by NOALYSS
-        $this->Cell(0,8,'Created by NOALYSS, online on 
http://www.aevalys.eu',0,0,'R',false,'http://www.aevalys.eu');
-    }
-
-    function Cell ($w, $h=0, $txt='', $border=0, $ln=0, $align='', 
$fill=false, $link='')
-    {
-        $txt = str_replace("\\", "", $txt);
-        return parent::Cell($w, $h, $txt, $border, $ln, $align, $fill, $link);
-    }
-    /**
-     address@hidden export the ledger in  PDF
-     */
-    function export()
-    {
-      bcscale(2);
-      $jrn_type=$this->ledger->get_type();
-      switch ($jrn_type)
-      {
-          case 'VEN':
-              $ledger=new Acc_Ledger_Sold($this->cn, 
$this->ledger->jrn_def_id);
-              
$ret_detail=$ledger->get_detail_sale($_GET['from_periode'],$_GET['to_periode']);
-              break;
-          case 'ACH':
-                $ledger=new Acc_Ledger_Purchase($this->cn, 
$this->ledger->jrn_def_id);
-                
$ret_detail=$ledger->get_detail_purchase($_GET['from_periode'],$_GET['to_periode']);
-              break;
-          default:
-              die (__FILE__.":".__LINE__.'Journal invalide');
-              break;
-      }
-        if ( $ret_detail == null ) return;
-        $nb=Database::num_row($ret_detail);
-        $this->SetFont('DejaVu', '', 6);
-        $internal="";
-        $this->SetFillColor(220,221,255);
-        $high=4;
-        for ( $i=0;$i< $nb ;$i++)
-        {
-            
-            $row=Database::fetch_array($ret_detail, $i);
-            if ($internal != $row['jr_internal'])
-            {
-                // Print the general info line width=270mm
-                $this->LongLine(20, $high, $row['jr_date'],1,  'L', true);
-                $this->Cell(20, $high, $row['jr_internal'], 1, 0, 'L', true);
-                $this->LongLine(50, $high, $row['quick_code']." 
".$row['tiers_name'],1,'L',true);
-                $this->LongLine(80, $high, $row['jr_comment'],1,'L',true);
-                $this->Cell(20, $high, nbm($row['htva']), 1, 0, 'R', true);
-                $this->Cell(20, $high, nbm($row['tot_tva_np']), 1, 0, 'R', 
true);
-                $this->Cell(20, $high, "", 1, 0, 'R', true);
-                $this->Cell(20, $high, nbm($row['tot_vat']), 1, 0, 'R', true);
-                $sum=bcadd($row['htva'],$row['tot_vat']);
-                $sum=bcsub($sum,$row['tot_tva_np']);
-                $this->Cell(20, $high, nbm($sum), 1, 0, 'R', true);
-                $internal=$row['jr_internal'];
-                $this->Ln(6);
-               // on the first line, the code for each column is displaid
-                if ( $this->show_col == true ) {
-                    //
-                    // Header detail
-                    $this->LongLine(30,$high,'QuickCode');
-                    $this->Cell(30,$high,'Poste');
-                    $this->LongLine(70,$high,'Libellé');
-                    $this->Cell(20,$high,'Prix/Unit',0,0,'R');
-                    $this->Cell(20,$high,'Quant.',0,0,'R');
-                    $this->Cell(20,$high,'HTVA',0,0,'R');
-                    $this->Cell(20,$high,'TVA NP',0,0,'R');
-                    $this->Cell(20,$high,'Code TVA');
-                    $this->Cell(20,$high,'TVA',0,0,'R');
-                    $this->Cell(20,$high,'TVAC',0,0,'R');
-                    $this->Ln(6);
-                    $this->show_col=false;
-                 } 
-            }
-            // Print detail sale / purchase
-            $this->LongLine(30,$high,$row['j_qcode']);
-            $this->Cell(30,$high,$row['j_poste']);
-            $comment=($row['j_text']=="")?$row['item_name']:$row['j_text'];
-            $this->LongLine(70,$high,$comment);
-            $this->Cell(20,$high,nbm($row['price_per_unit']),0,0,'R');
-            $this->Cell(20,$high,nbm($row['quantity']),0,0,'R');
-            $this->Cell(20,$high,nbm($row['price']),0,0,'R');
-            $this->Cell(20,$high,nbm($row['vat_sided']),0,0,'R');
-            $this->Cell(20,$high,$row['vat_code']." ".$row['tva_label']);
-            $this->Cell(20,$high,nbm($row['vat']),0,0,'R');
-            $sum=bcadd($row['price'],$row['vat']);
-            $this->Cell(20,$high,nbm($sum),0,0,'R');
-            $this->Ln(6);
-            
-        }
-    }
-
-}
-?>
diff --git a/include/class_print_ledger_fin.php 
b/include/class_print_ledger_fin.php
deleted file mode 100644
index 99fe336..0000000
--- a/include/class_print_ledger_fin.php
+++ /dev/null
@@ -1,119 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief print a listing of financial
- */
-require_once NOALYSS_INCLUDE.'/class_pdf.php';
-class Print_Ledger_Financial extends PDF
-{
-    private $rap_amount; /* amount from begining exercice */
-    private $tp_amount; /* amount total page */
-    
-    function __construct($p_cn,  Acc_Ledger $p_jrn)
-    {
-        parent::__construct($p_cn,'P','mm','A4');
-        $this->ledger=$p_jrn;
-        $this->jrn_type=$p_jrn->get_type();
-        
-        // report from begin exercice
-        $this->rap_amount=0; 
-        
-        // total page
-        $this->tp_amount=0;
-        
-        $amount=$this->ledger->previous_amount($_GET['from_periode']);
-        $this->rap_amount=$amount['amount'];
-    }
-    function Header()
-    {
-        //Arial bold 12
-        $this->SetFont('DejaVu', 'B', 12);
-        //Title
-        $this->Cell(0,10,$this->dossier, 'B', 0, 'C');
-        //Line break
-        $this->SetFont('DejaVu', 'B', 7);
-        $this->Ln(10);
-        $this->Cell(40,6,_('report'),0,0,'R');
-        $this->Cell(40,6,nbm($this->rap_amount),0,0,'R');
-        $this->Ln(6);
-        $this->SetFont('DejaVu', 'B', 7);
-        $this->Cell(15,6,'Piece');
-        $this->Cell(10,6,'Date');
-        $this->Cell(15,6,'Interne');
-        $this->Cell(40,6,'Dest/Orig');
-        $this->Cell(80,6,'Commentaire');
-        $this->Cell(20,6,'Montant');
-        $this->Ln(6);
-        
-    }
-    function Footer()
-    {
-        $this->SetFont('DejaVu', 'B', 7);
-
-        $this->Cell(40,6,_('Total page'),0,0,'R');
-        $this->Cell(40,6,nbm($this->tp_amount),0,0,'R');
-        bcscale(2);
-        $this->rap_amount=bcadd($this->rap_amount,$this->tp_amount);
-        $this->Cell(40,6,_('Total à reporter'),0,0,'R');
-        $this->Cell(40,6,nbm($this->rap_amount),0,0,'R');
-        $this->tp_amount=0;
-        //Position at 2 cm from bottom
-        $this->SetY(-20);
-        //Arial italic 8
-        $this->SetFont('Arial', 'I', 8);
-        //Page number
-        $this->Cell(0,8,'Date '.$this->date." - Page 
".$this->PageNo().'/{nb}',0,0,'C');
-        $this->Ln(3);
-        // Created by NOALYSS
-        $this->Cell(0,8,'Created by NOALYSS, online on 
http://www.aevalys.eu',0,0,'C',false,'http://www.aevalys.eu');
-
-    }
-    /**
-     address@hidden print the pdf for a financial ledger
-     */
-    function export()
-    {
-        $a_jrn=$this->ledger->get_operation($_GET['from_periode'],
-                                            $_GET['to_periode']);
-        $this->SetFont('DejaVu', '', 6);
-        if ( $a_jrn == null ) return;
-        bcscale(2);
-        for ( $i=0;$i<count($a_jrn);$i++)
-        {
-            $row=$a_jrn[$i];
-            $this->LongLine(15,5,$row['pj']);
-            $this->Cell(10,5,$row['date_fmt']);
-            $this->Cell(15,5,$row['internal']);
-
-            $name=$this->ledger->get_tiers($this->jrn_type,$row['id']);
-            $this->LongLine(40,5,$name,0,'L');
-
-
-            $this->LongLine(80,5,$row['comment'],0,'L');
-            $amount=$this->cn->get_value('select qf_amount from quant_fin 
where jr_id=$1',array( $row['id']));
-            $this->Cell(20,5,sprintf('%s',nbm($amount)),0,0,'R');
-            $this->Ln(5);
-            $this->tp_amount=bcadd($this->tp_amount,$amount);
-
-        }
-    }
-}
diff --git a/include/class_print_ledger_misc.php 
b/include/class_print_ledger_misc.php
deleted file mode 100644
index dcf34db..0000000
--- a/include/class_print_ledger_misc.php
+++ /dev/null
@@ -1,97 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief print a listing of financial
- */
-require_once NOALYSS_INCLUDE.'/class_pdf.php';
-class Print_Ledger_Misc extends PDF
-{
-    function __construct($p_cn,$p_jrn)
-    {
-        parent::__construct($p_cn,'P','mm','A4');
-        $this->ledger=$p_jrn;
-        $this->jrn_type=$p_jrn->get_type();
-    }
-    function Header()
-    {
-        //Arial bold 12
-        $this->SetFont('DejaVu', 'B', 12);
-        //Title
-        $this->Cell(0,10,$this->dossier, 'B', 0, 'C');
-        //Line break
-        $this->Ln(20);
-        $this->SetFont('DejaVu', 'B', 7);
-        $this->Cell(30,6,'Piece');
-        $this->Cell(10,6,'Date');
-        $this->Cell(20,6,'Interne');
-        $this->Cell(25,6,'Tiers');
-        $this->Cell(80,6,'Commentaire');
-        $this->Cell(15,6,'Montant');
-        $this->Ln(6);
-
-    }
-    function Footer()
-    {
-        //Position at 2 cm from bottom
-        $this->SetY(-20);
-        //Arial italic 8
-        $this->SetFont('Arial', 'I', 8);
-        //Page number
-        $this->Cell(0,8,'Date '.$this->date." - Page 
".$this->PageNo().'/{nb}',0,0,'C');
-        $this->Ln(3);
-        // Created by NOALYSS
-        $this->Cell(0,8,'Created by NOALYSS, online on 
http://www.aevalys.eu',0,0,'C',false,'http://www.aevalys.eu');
-    }
-    /**
-     address@hidden print the pdf
-     address@hidden
-     address@hidden
-     address@hidden
-     address@hidden
-     */
-    function export()
-    {
-        $a_jrn=$this->ledger->get_rowSimple($_GET['from_periode'],
-                                            $_GET['to_periode']);
-        $this->SetFont('DejaVu', '', 6);
-        if ( $a_jrn == null ) return;
-        for ( $i=0;$i<count($a_jrn);$i++)
-        {
-            $row=$a_jrn[$i];
-            $this->LongLine(30,5,$row['jr_pj_number']);
-            $this->Cell(10,5,  smaller_date($row['date']));
-            $this->Cell(20,5,$row['jr_internal']);
-           $type=$this->cn->get_value("select jrn_def_type from jrn_def where 
jrn_def_id=$1",array($a_jrn[$i]['jr_def_id']));
-           
$other=mb_substr($this->ledger->get_tiers($type,$a_jrn[$i]['jr_id']),0,25);
-           $this->LongLine(25,5,$other,0,'L');
-            $positive=$row['montant'];
-            $this->LongLine(80,5,$row['comment'],0,'L');
-             if ( $type == 'FIN' ) {
-              $positive = $this->cn->get_value("select qf_amount from 
quant_fin  ".
-                                         " where jr_id=".$row['jr_id']);
-             }
-            $this->Cell(15,5,nbm($positive),0,0,'R');
-            $this->Ln(5);
-
-        }
-    }
-}
diff --git a/include/class_print_ledger_simple.php 
b/include/class_print_ledger_simple.php
deleted file mode 100644
index 21a3ae3..0000000
--- a/include/class_print_ledger_simple.php
+++ /dev/null
@@ -1,277 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief this class extends PDF and let you export the detailled printing
- *  of any ledgers
- */
-require_once NOALYSS_INCLUDE.'/class_pdf.php';
-
-class Print_Ledger_Simple extends PDF
-{
-    public function __construct ($p_cn,  Acc_Ledger $p_jrn)
-    {
-
-        if($p_cn == null) die("No database connection. Abort.");
-
-        parent::__construct($p_cn,'L', 'mm', 'A4');
-        $this->ledger=$p_jrn;
-        $this->a_Tva=$this->ledger->existing_vat();
-        foreach($this->a_Tva as $line_tva)
-        {
-            //initialize Amount TVA
-            $tmp1=$line_tva['tva_id'];
-            $this->rap_tva[$tmp1]=0;
-        }
-        $this->jrn_type=$p_jrn->get_type();
-        
//----------------------------------------------------------------------
-        /* report
-         *
-         * get rappel to initialize amount rap_xx
-         *the easiest way is to compute sum from quant_
-         */
-        $this->previous=$this->ledger->previous_amount($_GET['from_periode']);
-
-        /* initialize the amount to report */
-        foreach($this->previous['tva'] as $line_tva)
-        {
-            //initialize Amount TVA
-            $tmp1=$line_tva['tva_id'];
-            $this->rap_tva[$tmp1]=$line_tva['sum_vat'];
-        }
-
-        $this->rap_htva=$this->previous['price'];
-        $this->rap_tvac=$this->previous['price']+$this->previous['vat'];
-        $this->rap_priv=$this->previous['priv'];
-        $this->rap_nd=$this->previous['tva_nd'];
-        $this->rap_tva_np=$this->previous['tva_np'];
-    }
-
-    function setDossierInfo($dossier = "n/a")
-    {
-        $this->dossier = dossier::name()." ".$dossier;
-    }
-    /**
-     address@hidden write the header of each page
-     */
-    function Header()
-    {
-        //Arial bold 12
-        $this->SetFont('DejaVu', 'B', 12);
-        //Title
-        $this->Cell(0,10,$this->dossier, 'B', 0, 'C');
-        //Line break
-        $this->Ln(20);
-        $this->SetFont('DejaVu', 'B', 8);
-        /* column header */
-        
//----------------------------------------------------------------------
-        // Show column header, if $flag_tva is false then display vat as column
-        foreach($this->a_Tva as $line_tva)
-        {
-            //initialize Amount TVA
-            $tmp1=$line_tva['tva_id'];
-            
$this->rap_tva[$tmp1]=(isset($this->rap_tva[$tmp1]))?$this->rap_tva[$tmp1]:0;
-        }
-        $this->Cell(15,6,'Pièce');
-        $this->Cell(10,6,'Date');
-        $this->Cell(13,6,'ref');
-        if ( $this->jrn_type=='ACH')
-            $this->Cell(40,6,'Client');
-        else
-            $this->Cell(40,6,'Fournisseur');
-
-        $flag_tva=(count($this->a_Tva) > 4)?true:false;
-        if ( !$flag_tva )      $this->Cell(65,6,'Description');
-
-        $this->Cell(15,6,'HTVA',0,0,'R');
-        if ( $this->jrn_type=='ACH')
-        {
-            $this->Cell(15,6,'Priv/DNA',0,0,'R');
-            $this->Cell(15,6,'TVA ND',0,0,'R');
-        }
-        $this->Cell(15,6,'TVA NP',0,0,'R'); // Unpaid TVA --> autoliquidation, 
NPR
-        foreach($this->a_Tva as $line_tva)
-        {
-            $this->Cell(15,6,$line_tva['tva_label'],0,0,'R');
-        }
-        $this->Cell(15,6,'TVAC',0,0,'R');
-        $this->Ln(5);
-
-        $this->SetFont('DejaVu','',6);
-        // page Header
-        $this->Cell(143,6,'report',0,0,'R');
-        $this->Cell(15,6,nbm($this->rap_htva),0,0,'R'); /* HTVA */
-        if ( $this->jrn_type != 'VEN')
-        {
-            $this->Cell(15,6,nbm($this->rap_priv),0,0,'R');  /* prive */
-            $this->Cell(15,6,nbm($this->rap_nd),0,0,'R');  /* Tva ND */
-        }
-        $this->Cell(15,6,nbm($this->rap_tva_np),0,0,'R');  /* Tva ND */
-        foreach($this->rap_tva as $line_tva)
-        $this->Cell(15,6,nbm($line_tva),0,0,'R');
-        $this->Cell(15,6,nbm($this->rap_tvac),0,0,'R'); /* Tvac */
-
-        $this->Ln(6);
-        //total page
-        $this->tp_htva=0.0;
-        $this->tp_tvac=0.0;
-        $this->tp_priv=0;
-        $this->tp_nd=0;
-        $this->tp_tva_np=0;
-        foreach($this->a_Tva as $line_tva)
-        {
-            //initialize Amount TVA
-            $tmp1=$line_tva['tva_id'];
-            $this->tp_tva[$tmp1]=0.0;
-        }
-    }
-    /**
-     address@hidden write the Footer
-     */
-    function Footer()
-    {
-        //Position at 3 cm from bottom
-        $this->SetY(-20);
-        /* write reporting  */
-        $this->Cell(143,6,'Total page ','T',0,'R'); /* HTVA */
-        $this->Cell(15,6,nbm($this->tp_htva),'T',0,'R'); /* HTVA */
-        if ( $this->jrn_type !='VEN')
-        {
-            $this->Cell(15,6,nbm($this->tp_priv),'T',0,'R');  /* prive */
-            $this->Cell(15,6,nbm($this->tp_nd),'T',0,'R');  /* Tva ND */
-        }
-        $this->Cell(15,6,nbm($this->tp_tva_np),'T',0,'R');  /* Tva Unpaid */
-        foreach($this->a_Tva as $line_tva)
-        {
-            $l=$line_tva['tva_id'];
-            $this->Cell(15,6,nbm($this->tp_tva[$l]),'T',0,'R');
-        }
-        
-        $this->Cell(15,6,nbm($this->tp_tvac),'T',0,'R'); /* Tvac */
-        $this->Ln(2);
-
-        $this->Cell(143,6,'report',0,0,'R'); /* HTVA */
-        $this->Cell(15,6,nbm($this->rap_htva),0,0,'R'); /* HTVA */
-        if ( $this->jrn_type !='VEN')
-        {
-            $this->Cell(15,6,nbm($this->rap_priv),0,0,'R');  /* prive */
-            $this->Cell(15,6,nbm($this->rap_nd),0,0,'R');  /* Tva ND */
-        }
-        $this->Cell(15,6,nbm($this->rap_tva_np),0,0,'R');  /* Tva ND */
-        
-        foreach($this->a_Tva as $line_tva)
-        {
-            $l=$line_tva['tva_id'];
-            $this->Cell(15,6,nbm($this->rap_tva[$l]),0,0,'R');
-        }
-        $this->Cell(15,6,nbm($this->rap_tvac),0,0,'R'); /* Tvac */
-        $this->Ln(2);
-
-        //Arial italic 8
-        $this->SetFont('Arial', 'I', 8);
-        //Page number
-        $this->Cell(0,8,'Date '.$this->date." - Page 
".$this->PageNo().'/{nb}',0,0,'L');
-        // Created by NOALYSS
-        $this->Cell(0,8,'Created by NOALYSS, online on 
http://www.aevalys.eu',0,0,'R',false,'http://www.aevalys.eu');
-    }
-
-    function Cell ($w, $h=0, $txt='', $border=0, $ln=0, $align='', 
$fill=false, $link='')
-    {
-        $txt = str_replace("\\", "", $txt);
-        return parent::Cell($w, $h, $txt, $border, $ln, $align, $fill, $link);
-    }
-    /**
-     address@hidden export the ledger in  PDF
-     */
-    function export()
-    {
-      bcscale(2);
-        $a_jrn=$this->ledger->get_operation($_GET['from_periode'],
-                                            $_GET['to_periode']);
-
-        if ( $a_jrn == null ) return;
-        for ( $i=0;$i<count($a_jrn);$i++)
-        {
-            /* initialize tva */
-            for ($f=0;$f<count($this->a_Tva);$f++)
-            {
-                $l=$this->a_Tva[$f]['tva_id'];
-                $atva_amount[$l]=0;
-            }
-
-            // retrieve info from ledger
-            $aAmountVat=$this->ledger->vat_operation($a_jrn[$i]['jr_grpt_id']);
-
-            // put vat into array
-            for ($f=0;$f<count($aAmountVat);$f++)
-            {
-                $l=$aAmountVat[$f]['tva_id'];
-                
$atva_amount[$l]=bcadd($atva_amount[$l],$aAmountVat[$f]['sum_vat']);
-                
$this->tp_tva[$l]=bcadd($this->tp_tva[$l],$aAmountVat[$f]['sum_vat']);
-                
$this->rap_tva[$l]=bcadd($this->rap_tva[$l],$aAmountVat[$f]['sum_vat']);
-                
-            }
-
-            $row=$a_jrn[$i];
-            $this->LongLine(15,5,($row['pj']),0);
-            $this->Cell(10,5,$row['date_fmt'],0,0);
-            $this->Cell(13,5,$row['internal'],0,0);
-            list($qc,$name)=$this->get_tiers($row['id'],$this->jrn_type);
-            $this->LongLine(40,5,"[".$qc."]".$name,0,'L');
-
-            $this->LongLine(65,5,mb_substr($row['comment'],0,150),0,'L');
-
-            /* get other amount (without vat, total vat included, private, ND 
*/
-            $other=$this->ledger->get_other_amount($a_jrn[$i]['jr_grpt_id']);
-            $this->tp_htva=bcadd($this->tp_htva,$other['price']);
-            $this->tp_tvac=bcadd($this->tp_tvac,$other['price']+$other['vat']);
-            $this->tp_tva_np=bcadd($this->tp_tva_np,$other['tva_np']);
-            $this->tp_priv=bcadd($this->tp_priv,$other['priv']);
-            $this->tp_nd=bcadd($this->tp_nd,$other['tva_nd']);
-            $this->rap_htva=bcadd($this->rap_htva,$other['price']);
-            $this->rap_tvac=bcadd($this->rap_tvac,bcadd($other['price'], 
bcsub($other['vat'],$other['tva_np'])));
-            $this->rap_priv=bcadd($this->rap_priv,$other['priv']);
-            $this->rap_nd=bcadd($this->rap_nd,$other['tva_nd']);
-            $this->rap_tva_np=bcadd($this->rap_tva_np,$other['tva_np']);
-
-
-            $this->Cell(15,5,nbm($other['price']),0,0,'R');
-            if ( $this->jrn_type !='VEN')
-            {
-             $this->Cell(15,5,nbm($other['priv']),0,0,'R');
-             $this->Cell(15,5,nbm($other['tva_nd']),0,0,'R');
-            }
-            
-           $this->Cell(15,5,nbm($other['tva_np']),0,0,'R');
-            
-            foreach ($atva_amount as $row_atva_amount)
-            {
-                    $this->Cell(15, 5, nbm($row_atva_amount), 0, 0, 'R');
-            }
-
-           $l_tvac=bcadd($other['price'], 
bcsub($other['vat'],$other['tva_np']));
-           $l_tvac=bcadd($l_tvac,$other['tva_nd']);
-            $this->Cell(15,5,nbm($l_tvac),0,0,'R');
-            $this->Ln(5);
-        }
-    }
-
-}
diff --git a/include/class_print_ledger_simple_without_vat.php 
b/include/class_print_ledger_simple_without_vat.php
deleted file mode 100644
index c56c0fd..0000000
--- a/include/class_print_ledger_simple_without_vat.php
+++ /dev/null
@@ -1,185 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief this class extends PDF and let you export the detailled printing
- *  of any ledgers
- */
-require_once NOALYSS_INCLUDE.'/class_pdf.php';
-
-class Print_Ledger_Simple_Without_Vat extends PDF
-{
-    public function __construct ($p_cn,$p_jrn)
-    {
-
-        if($p_cn == null) die("No database connection. Abort.");
-
-        parent::__construct($p_cn,'L', 'mm', 'A4');
-        $this->ledger=$p_jrn;
-        $this->jrn_type=$p_jrn->get_type();
-        
//----------------------------------------------------------------------
-        /* report
-         *
-         * get rappel to initialize amount rap_xx
-         *the easiest way is to compute sum from quant_
-         */
-        $this->previous=$this->ledger->previous_amount($_GET['from_periode']);
-
-
-        $this->rap_htva=$this->previous['price'];
-        $this->rap_tvac=$this->previous['price'];
-        $this->rap_priv=$this->previous['priv'];
-
-
-    }
-
-    function setDossierInfo($dossier = "n/a")
-    {
-        $this->dossier = dossier::name()." ".$dossier;
-    }
-    /**
-     address@hidden write the header of each page
-     */
-    function Header()
-    {
-        //Arial bold 12
-        $this->SetFont('DejaVu', 'B', 12);
-        //Title
-        $this->Cell(0,10,$this->dossier, 'B', 0, 'C');
-        //Line break
-        $this->Ln(20);
-        $this->SetFont('DejaVu', 'B', 8);
-        /* column header */
-        $this->Cell(15,6,'Pièce');
-        $this->Cell(15,6,'Date');
-        $this->Cell(20,6,'ref');
-        if ( $this->jrn_type=='ACH')
-            $this->Cell(60,6,'Client');
-        else
-            $this->Cell(60,6,'Fournisseur');
-        $this->Cell(105,6,'Commentaire');
-        if ( $this->jrn_type=='ACH')
-        {
-            $this->Cell(15,6,'Privé',0,0,'R');
-        }
-        $this->Cell(15,6,'Prix',0,0,'R');
-
-        $this->Ln(5);
-
-        $this->SetFont('DejaVu','',6);
-        // page Header
-        $this->Cell(215,6,'report',0,0,'R'); /* HTVA */
-        if ( $this->jrn_type != 'VEN')
-        {
-            $this->Cell(15,6,sprintf('%.2f',$this->rap_priv),0,0,'R');  /* 
prive */
-        }
-        $this->Cell(15,6,sprintf('%.2f',$this->rap_htva),0,0,'R'); /* HTVA */
-
-
-
-
-        $this->Ln(6);
-        //total page
-        $this->tp_htva=0.0;
-        $this->tp_tvac=0.0;
-        $this->tp_priv=0;
-        $this->tp_nd=0;
-    }
-    /**
-     address@hidden write the Footer
-     */
-    function Footer()
-    {
-        //Position at 3 cm from bottom
-        $this->SetY(-20);
-        /* write reporting  */
-        $this->Cell(215,6,'Total page ','T',0,'R'); /* HTVA */
-        if ( $this->jrn_type !='VEN')
-        {
-            $this->Cell(15,6,sprintf('%.2f',$this->tp_priv),'T',0,'R');  /* 
prive */
-        }
-        $this->Cell(15,6,sprintf('%.2f',$this->tp_htva),'T',0,'R'); /* HTVA */
-        $this->Cell(0,6,'','T',0,'R'); /* line */
-        $this->Ln(2);
-
-        $this->Cell(215,6,'report',0,0,'R'); /* HTVA */
-        if ( $this->jrn_type !='VEN')
-        {
-            $this->Cell(15,6,sprintf('%.2f',$this->rap_priv),0,0,'R');  /* 
prive */
-        }
-        $this->Cell(15,6,sprintf('%.2f',$this->rap_htva),0,0,'R'); /* HTVA */
-        $this->Ln(2);
-
-        //Arial italic 8
-        $this->SetFont('Arial', 'I', 8);
-        //Page number
-        $this->Cell(0,8,'Date '.$this->date." - Page 
".$this->PageNo().'/{nb}',0,0,'L');
-        // Created by NOALYSS
-        $this->Cell(0,8,'Created by NOALYSS, online on 
http://www.aevalys.eu',0,0,'R',false,'http://www.aevalys.eu');
-    }
-
-    function Cell ($w, $h=0, $txt='', $border=0, $ln=0, $align='', 
$fill=false, $link='')
-    {
-        $txt = str_replace("\\", "", $txt);
-        return parent::Cell($w, $h, $txt, $border, $ln, $align, $fill, $link);
-    }
-    /**
-     address@hidden export the ledger in  PDF
-     */
-    function export()
-    {
-
-        $a_jrn=$this->ledger->get_operation($_GET['from_periode'],
-                                            $_GET['to_periode']);
-
-        if ( $a_jrn == null ) return;
-        for ( $i=0;$i<count($a_jrn);$i++)
-        {
-
-            $row=$a_jrn[$i];
-            $this->LongLine(15,5,($row['pj']),0);
-            $this->Cell(15,5,$row['date_fmt'],0,0);
-            $this->Cell(20,5,$row['internal'],0,0);
-            list($qc,$name)=$this->get_tiers($row['id'],$this->jrn_type);
-            $this->Cell(20,5,$qc,0,0);
-            $this->LongLine(40,5,$name,0,'L');
-
-            $this->LongLine(105,5,$row['comment'],0,'L');
-
-            /* get other amount (without vat, total vat included, private, ND 
*/
-            $other=$this->ledger->get_other_amount($a_jrn[$i]['jr_grpt_id']);
-            $this->tp_htva+=$other['price'];
-            $this->tp_priv+=$other['priv'];
-            $this->rap_htva+=$other['price'];
-            $this->rap_priv+=$other['priv'];
-
-
-            if ( $this->jrn_type !='VEN')
-            {
-                $this->Cell(15,6,sprintf("%.2f",$other['priv']),0,0,'R');
-            }
-
-            $this->Cell(15,6,sprintf("%.2f",$other['price']),0,0,'R');
-            $this->Ln(5);
-        }
-    }
-
-}
diff --git a/include/class_profile_menu.php b/include/class_profile_menu.php
deleted file mode 100644
index 58de6dd..0000000
--- a/include/class_profile_menu.php
+++ /dev/null
@@ -1,280 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-// Copyright Author Dany De Bontridder address@hidden
-
-require_once NOALYSS_INCLUDE.'/class_profile_menu_sql.php';
-
-/**
- * Manage the menu of a profile
- *
- * @author dany
- */
-class Profile_Menu extends Profile_Menu_sql
-{
-
-    function __construct($p_cn, $p_id=-1)
-    {
-        $this->cn=$p_cn;
-        parent::__construct($p_cn, $p_id);
-    }
-
-    /**
-     * Display the content of a profile menu for printing
-     * @param type $resource
-     * @param type $p_id
-     */
-    function sub_menu($resource, $p_id)
-    {
-        if (Database::num_row($resource)!=0)
-        {
-            ////
-            // If there are submenus
-            $gDossier=dossier::id();
-            echo '<td>';
-            for ($e=0; $e<Database::num_row($resource); $e++)
-            {
-                $menu=Database::fetch_array($resource, $e);
-                $me_code=$menu['me_code'];
-
-                $me_code_dep=$menu['me_code_dep'];
-
-                $mp_type=$menu['p_type_display'];
-
-                $me_menu=$menu['me_menu'];
-                $me_desc=$menu['me_description'];
-                $me_def=($menu['pm_default']=='1')?'<span class="notice" 
style="display:inline">Défaut</span>':'';
-                ?>
-                <li id="sub<?php echo $menu['pm_id'] ?>">
-
-                    <?php echo $me_menu ?>
-                    <?php echo $me_desc ?>  <?php echo $me_def ?>
-                    <?php $ret2=$this->cn->exec_sql("
-                                    SELECT pm_id,
-                                            pm.me_code,
-                                            me_code_dep,
-                                            p_id,
-                                            p_order,
-                                            p_type_display,
-                                            pm_default,
-                                            pm_desc,
-                                            me_menu,
-                                            me_description
-                                            FROM profile_menu as pm
-                                                    join profile_menu_type on 
(p_type_display=pm_type)
-                                                    join menu_ref as mr on 
(mr.me_code=pm.me_code)
-                                            where
-                                            p_id=$1 and me_code_dep=$2
-                                            order by p_order asc
-                        ", array($p_id, $me_code)); ?>
-                    <span>
-                        <?php
-                        echo HtmlInput::anchor(SMALLX, "",
-                                sprintf(" onclick = 
\"remove_sub_menu(%d,%d)\"",
-                                        Dossier::id(), $menu['pm_id']),
-                                'class="tinybutton"')
-                        ?>
-                    </span>
-                    <?php
-                    echo "</li>";
-                } //end loop e
-                echo '</ul>';
-            } // end if
-        }
-
-        /**
-         * Show a table with all the menu and the type
-         * @param type $p_id profile.p_id
-         */
-        function display_profile_menu_detail()
-        {
-            $a_module=$this->cn->get_array("
-                       SELECT pm_id,
-                                       pm.me_code,
-                                       me_code_dep,
-                                       p_id,
-                                       p_order,
-                                       p_type_display,
-                                       pm_default,
-                                       pm_desc,
-                                       me_menu,
-                                       me_description,
-                                        me_url,
-                                        me_file,
-                                        me_javascript
-                       FROM profile_menu as pm 
-                        join profile_menu_type on (p_type_display=pm_type)
-                       join menu_ref as mr on (mr.me_code=pm.me_code)
-                       where
-                       p_id=$1 and p_type_display='M'
-                       order by p_order asc
-                       ", array($this->p_id));
-            ////////////////////////////////////////////////////////////
-            // With a module
-            ////////////////////////////////////////////////////////////
-            $this->display_module($a_module);
-
-            //*******************************************
-            // show also menu without a module
-            //*******************************************
-            $ret=$this->cn->exec_sql("
-                                        SELECT pm_id,
-                                        pm.me_code,
-                                        me_code_dep,
-                                        p_id,
-                                        p_order,
-                                        p_type_display,
-                                        pm_default,
-                                        pm_desc,
-                                        me_menu,
-                                        me_description
-                                        FROM profile_menu as pm
-                                                join profile_menu_type on 
(p_type_display=pm_type)
-                                                join menu_ref as mr on 
(mr.me_code=pm.me_code)
-                                       where
-                                       p_id=$1 and  p_type_display not in 
('M','P') and me_code_dep is null
-                                       order by p_order asc
-                                                       ", array($this->p_id));
-        }
-
-        /**
-         * @brief Display the module, with a javascript inside to show the 
menu 
-         * contained in the module
-         * Used for setting the configuration
-         * @param $ap_module $array of module received from 
display_profile_menu_detail  
-         * @see Profile_menu::display_profile_menu_detail
-         */
-        function display_module($ap_module)
-        {
-            include 
NOALYSS_INCLUDE.'/template/profile_menu_display_module.php';
-        }
-
-        /**
-         * @brief  Display all menu and submenu of a module.
-         * @see display_profile_module 
-         * 
-         */
-        function display_module_menu($p_module_id, $p_level)
-        {
-            // Get the submenu
-            $a_module=$this->cn->get_array('
-                SELECT pm_id, 
-                    me_code, 
-                    me_code_dep, 
-                    p_id, 
-                    p_order, 
-                    p_type_display, 
-                    pm_default,
-                    me_menu,
-                    me_file,
-                    me_url,
-                    me_javascript,
-                    me_parameter,
-                    me_description
-                FROM profile_menu
-                join menu_ref using (me_code)
-                where
-                p_id = $1 and
-                pm_id_dep = $2 order by p_order',
-                    array($this->p_id, $p_module_id));
-            require 
NOALYSS_INCLUDE.'/template/profile_menu_display_submenu.php';
-        }
-
-        /**
-         * display all the accessible export of a profile $p_id
-         * @param type $p_id profile.p_id
-         */
-        function printing()
-        {
-            $ret=$this->cn->exec_sql("
-                            SELECT pm_id,
-                                pm.me_code,
-                                me_code_dep,
-                                p_id,
-                                p_order,
-                                p_type_display,
-                                pm_default,
-                                pm_desc,
-                                me_menu,
-                                me_description
-                                FROM profile_menu as pm
-                                        join profile_menu_type on 
(p_type_display=pm_type)
-                                        join menu_ref as mr on 
(mr.me_code=pm.me_code)
-                                where
-                                p_id=$1 and me_type='PR'
-                                order by p_order asc
-                                                       ", array($this->p_id));
-            // Menu by module
-            $gDossier=Dossier::id();
-            $this->sub_menu($ret, $this->p_id);
-        }
-
-        /**
-         * Show the available profile for the profile $p_id, it concerns only 
the action of management (action-gestion)
-         * @param $p_id is the profile p_id
-         */
-        function available_profile()
-        {
-            $array=$this->cn->get_array("
-                                       select 
p.p_id,p.p_name,s.p_granted,s.ua_id,s.ua_right
-                                               from profile as p
-                                               join user_sec_action_profile as 
s on (s.p_granted=p.p_id)
-                                               where s.p_id=$1
-                                       union
-                                               select p2.p_id, 
p2.p_name,null,null,'X'
-                                               from profile as p2
-                                               where
-                                               p2.p_id not in (select 
p_granted from user_sec_action_profile where p_id = $1) order by p_name;
-                               ", array($this->p_id));
-            $aright_value=array(
-                array('value'=>'R', 'label'=>_('Lecture')),
-                array('value'=>'W', 'label'=>_('Ecriture')),
-                array('value'=>'X', 'label'=>_('Aucun accès'))
-            );
-            require_once NOALYSS_INCLUDE.'/template/user_sec_profile.php';
-        }
-
-        /**
-         * Show the available repository for the profile $p_id
-         * @param $p_id is the profile p_id
-         */
-        function available_repository()
-        {
-            $array=$this->cn->get_array("
-                                       select 
p.r_id,p.r_name,s.ur_id,s.ur_right
-                                               from stock_repository as p
-                                               join profile_sec_repository as 
s on (s.r_id=p.r_id)
-                                               where s.p_id=$1
-                                       union
-                                               select p2.r_id, 
p2.r_name,null,'X'
-                                               from stock_repository as p2
-                                               where
-                                               p2.r_id not in (select r_id 
from profile_sec_repository where p_id = $1) order by r_name;
-                               ", array($this->p_id));
-            $aright_value=array(
-                array('value'=>'R', 'label'=>_('Lecture')),
-                array('value'=>'W', 'label'=>_('Ecriture')),
-                array('value'=>'X', 'label'=>_('Aucun accès'))
-            );
-            require_once 
NOALYSS_INCLUDE.'/template/profile_sec_repository.php';
-        }
-
-    }
-
-    //end class
-    ?>
\ No newline at end of file
diff --git a/include/class_profile_menu_sql.php 
b/include/class_profile_menu_sql.php
deleted file mode 100644
index 846ff13..0000000
--- a/include/class_profile_menu_sql.php
+++ /dev/null
@@ -1,76 +0,0 @@
-<?php
-
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-// Copyright Author Dany De Bontridder address@hidden
-/**
- * @file
- * @brief Manage the table public.profile_menu
- *
- *
-  Example
-  @code
-
-  @endcode
- */
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/ac_common.php';
-require_once NOALYSS_INCLUDE.'/class_noalyss_sql.php';
-
-/**
- * @brief Manage the table public.profile_menu
- */
-class Profile_Menu_sql extends Noalyss_SQL
-{
-
-    function __construct(&$p_cn,$p_id=-1)
-    {
-        $this->table="public.profile_menu";
-        $this->primary_key="pm_id";
-
-        $this->name=array(
-            "pm_id"=>"pm_id", "me_code"=>"me_code"
-            , "me_code_dep"=>"me_code_dep"
-            , "p_id"=>"p_id"
-            , "p_order"=>"p_order"
-            , "p_type_display"=>"p_type_display"
-            , "pm_default"=>"pm_default"
-            ,"pm_id_dep"=>"pm_id_dep"
-        );
-
-        $this->type=array(
-            "pm_id"=>"number",
-            "me_code"=>"text"
-            , "me_code_dep"=>"text"
-            , "p_id"=>"number"
-            , "p_order"=>"number"
-            , "p_type_display"=>"text"
-            , "pm_default"=>"text"
-            , "pm_id_dep"=>"number"
-        );
-
-        $this->default=array(
-            "pm_id"=>"auto"
-        );
-
-        parent::__construct($p_cn, $p_id);
-    }
-
-}
-
-?>
diff --git a/include/class_profile_sql.php b/include/class_profile_sql.php
deleted file mode 100644
index dba506d..0000000
--- a/include/class_profile_sql.php
+++ /dev/null
@@ -1,72 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-// Copyright Author Dany De Bontridder address@hidden
-
-/**
- * @file
- * @brief Manage the table public.profile
- *
- *
-  Example
-  @code
-
-  @endcode
- */
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/ac_common.php';
-require_once NOALYSS_INCLUDE.'/class_noalyss_sql.php';
-
-/**
- * @brief Manage the table public.profile
- */
-class Profile_sql extends Noalyss_SQL
-{
-       /* example private 
$variable=array("easy_name"=>column_name,"email"=>"column_name_email","val3"=>0);
 */
-
-       function __construct(& $p_cn, $p_id = -1)
-       {
-               $this->table = "public.profile";
-               $this->primary_key = "p_id";
-
-               $this->name = array(
-                       "p_id" => "p_id"
-                       , "p_name" => "p_name"
-                       , "p_desc" => "p_desc"
-                       , "with_calc" => "with_calc"
-                       , "with_direct_form" => "with_direct_form"
-               );
-               $this->type = array(
-                       "p_id" => "numeric"
-                       , "p_name" => "text"
-                       , "p_desc" => "text"
-                       , "with_calc" => "text"
-                       , "with_direct_form" => "text"
-               );
-               $this->default = array(
-                       "p_id" => "auto",
-               );
-
-               parent::__construct($p_cn,$p_id);
-
-       }
-
-}
-
-// Profile_sql::test_me();
-?>
diff --git a/include/class_sendmail.php b/include/class_sendmail.php
deleted file mode 100644
index fae1f19..0000000
--- a/include/class_sendmail.php
+++ /dev/null
@@ -1,160 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-// Copyright Author Dany De Bontridder address@hidden
-
-
-/**
- * Description of class_sendmail
- *
- * @author dany
- */
-require_once NOALYSS_INCLUDE.'/class_filetosend.php';
-
-class Sendmail
-{
-
-    private $mailto;
-    private $afile;
-    private $subject;
-    private $message;
-    private $from;
-    private $content;
-
-    /**
-     * set the from
-     * @parameter $p_from has the form name <address@hidden>
-     */
-    function set_from($p_from)
-    {
-        $this->from = $p_from;
-    }
-
-    /**
-     * 
-     * @param $p_subject set the subject
-     */
-    function set_subject($p_subject)
-    {
-        $this->subject = $p_subject;
-    }
-
-    /**
-     * set the recipient
-     * @param type $p_mailto has the form name <address@hidden>
-     */
-    function mailto($p_mailto)
-    {
-        $this->mailto = $p_mailto;
-    }
-
-    /**
-     * body of the message (utf8)
-     * @param type $p_message
-     */
-    function set_message($p_message)
-    {
-        $this->message = $p_message;
-    }
-
-    /**
-     * Add file to the message
-     * @param FileToSend $file file to add to the message
-     */
-    function add_file(FileToSend $file)
-    {
-        $this->afile[] = $file;
-    }
-
-    /**
-     *  verify that the message is ready to go
-     * @throws Exception
-     */
-    function verify()
-    {
-        $array = explode(",", "from,subject,mailto,message");
-        for ($i = 0; $i < count($array); $i++)
-        {
-            $name = $array[$i];
-            if (trim($this->$name) == "")
-            {
-                throw new Exception($name ._(" est vide"));
-            }
-        }
-    }
-    /**
-    * create the message before sending
-    */
-    function compose()
-    {
-        $this->verify();
-        $uid = md5(uniqid(time()));
-
-        // a random hash will be necessary to send mixed content
-        $separator = md5(time());
-
-        // carriage return type (we use a PHP end of line constant)
-        $eol = PHP_EOL;
-
-        // main header (multipart mandatory)
-        $headers = "From: " . $this->from . $eol;
-        $headers .= "MIME-Version: 1.0" . $eol;
-        $headers .= "Content-Type: multipart/mixed; boundary=\"" . $separator 
. "\"" . $eol . $eol;
-        $headers .= "Content-Transfer-Encoding: 7bit" . $eol;
-        $headers .= "This is a MIME encoded message." . $eol . $eol;
-        $headers .= $eol . $eol;
-
-        // message
-        $headers .= "--" . $separator . $eol;
-        $headers .= "Content-Type: text/plain; charset=\"utf-8\"" . $eol;
-        $headers .= "Content-Transfer-Encoding: 7bit" . $eol . $eol;
-        $headers .= $this->message . $eol . $eol;
-
-        // attachment
-        for ($i = 0; $i < count($this->afile); $i++)
-        {
-            $file = $this->afile[$i];
-            $file_size = filesize($file->full_name);
-            $handle = fopen($file->full_name, "r");
-            $content = fread($handle, $file_size);
-            fclose($handle);
-            $content = chunk_split(base64_encode($content));
-            $headers .= "--" . $separator . $eol;
-            $headers .= "Content-Type: " . $file->type . "; name=\"" . 
$file->filename . "\"" . $eol;
-            $headers .= "Content-Disposition: attachment; filename=\"" . 
$file->filename . "\"" . $eol;
-            $headers .= "Content-Transfer-Encoding: base64" . $eol;
-            $headers.=$eol;
-            $headers .= $content . $eol . $eol;
-        }
-        $headers .= "--" . $separator . "--";
-        $this->content = $headers;
-    }
-    /**
-     * Send the message 
-     * @throws Exception
-     */
-    function send()
-    {
-        //SEND Mail
-        if (!mail($this->mailto, $this->subject, "", $this->content))
-        {
-            throw new Exception('send failed');
-        }
-    }
-
-}
diff --git a/include/class_stock.php b/include/class_stock.php
deleted file mode 100644
index 611e625..0000000
--- a/include/class_stock.php
+++ /dev/null
@@ -1,342 +0,0 @@
-<?php
-
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/**
- * @file
- * @brief
- *
- *
- */
-require_once NOALYSS_INCLUDE.'/class_stock_sql.php';
-
-class Stock extends Stock_Sql
-{
-
-       /**
-        * show history of all the stock movement
-        * @param $p_array usually contains $_GET
-        */
-       function history($p_array)
-       {
-
-               $sql = $this->create_query_histo($p_array);
-               require_once NOALYSS_INCLUDE.'/class_sort_table.php';
-               $p_url = HtmlInput::get_to_string(array("gDossier", "ac", 
"wcard", "wdate_start", "wdate_end", "wrepo",
-                                       "wamount_start", "wamount_end", 
"wcode_stock", "wdirection"));
-
-               $tb = new Sort_Table();
-               $tb->add("Date", $p_url, " order by real_date asc", "order by 
real_date desc", "da", "dd");
-               $tb->add("Code Stock", $p_url, " order by sg_code asc", "order 
by sg_code desc", "sa", "sd");
-               $tb->add("Dépôt", $p_url, " order by r_name asc", "order by 
r_name desc", "ra", "rd");
-               $tb->add("Fiche", $p_url, " order by 2 asc", "order by 2 desc", 
"fa", "fd");
-               $tb->add("Commentaire", $p_url, " order by 
coalesce(sg_comment,jr_comment)  asc", "order by 
coalesce(sg_comment,jr_comment)  desc", "ca", "cd");
-               $tb->add("Montant", $p_url, " order by j_montant asc", "order 
by j_montant desc", "ja", "jd");
-               $tb->add("Quantité", $p_url, " order by sg_quantity asc", 
"order by sg_quantity  desc", "qa", "qd");
-               $tb->add("IN/OUT", $p_url, " order by (case when sg_type='c' 
then 'OUT' when sg_type='c' then 'IN' end ) asc", "order by (case when 
sg_type='c' then 'OUT' when sg_type='c' then 'IN' end ) desc", "ta", "td");
-               $order = (isset($p_array['ord'])) ? $p_array['ord'] : 'da';
-
-               $sql.=$tb->get_sql_order($order);
-               $step = $_SESSION['g_pagesize'];
-               $page = (isset($_GET['offset'])) ? $_GET['page'] : 1;
-               $offset = (isset($_GET['offset'])) ? $_GET['offset'] : 0;
-
-               $res = $this->cn->exec_sql($sql);
-
-               $max_row = Database::num_row($res);
-
-               $nav_bar = navigation_bar($offset, $max_row, 0, $page);
-
-               if ($step != -1)
-                       $res = $this->cn->exec_sql($sql . " , sg_id asc limit " 
. $step . " offset " . $offset);
-               $max_row = Database::num_row($res);
-
-               $this->search_box_button();
-               $this->search_box($p_array);
-               require_once NOALYSS_INCLUDE.'/template/stock_histo.php';
-               $this->export_stock_histo_form();
-               echo HtmlInput::print_window();
-       }
-
-       function export_stock_histo_form()
-       {
-               echo '<form style="display:inline" method="GET" 
action="export.php">';
-                echo HtmlInput::get_to_hidden(array("gDossier", "wcard", 
"wdate_start", "wdate_end", "wrepo",
-                                       "wamount_start", "wamount_end", 
"wcode_stock", "wdirection"));
-                echo HtmlInput::hidden('act','CSV:StockHisto');
-                echo HtmlInput::submit('stockhisto','Export CSV');
-                echo '</form>';
-       }
-       function export_stock_summary_list_form()
-       {
-               echo '<form style="display:inline"  method="GET" 
action="export.php">';
-                echo HtmlInput::get_to_hidden(array("gDossier", 
"state_exercice"));
-                echo HtmlInput::hidden('act','CSV:StockResmList');
-
-                echo HtmlInput::submit('stockresm','Export CSV');
-                echo '</form>';
-       }
-       function search_box_button()
-       {
-               $bt = HtmlInput::button("Recherche", "Recherche", ' 
onclick="$(\'histo_search_d\').show();"');
-               echo $bt;
-       }
-
-       function search_box($p_array)
-       {
-               // Declaration
-               global $g_user;
-               $wrepo = HtmlInput::select_stock($this->cn, "wrepo", 'R');
-               $wrepo->value[] = array('value' => -1, 'label' => 'Tous les 
dépôts');
-
-               $wdate_start = new IDate('wdate_start');
-               $wdate_end = new IDate('wdate_end');
-               $wamount_start = new INum('wamount_start');
-               $wamount_end = new INum('wamount_end');
-               $wcard = new ICard('wcard');
-               $wcode_stock = new ICard('wcode_stock');
-               $wdirection = new ISelect("wdirection");
-
-               // value
-               $wrepo->selected = HtmlInput::default_value("wrepo", -1, 
$p_array);
-
-               // Date start / end
-               $exercice = $g_user->get_exercice();
-               $periode = new Periode($this->cn);
-               list($periode_start, $periode_end) = 
$periode->get_limit($exercice);
-
-               $wdate_start->value = HtmlInput::default_value("wdate_start", 
$periode_start->first_day(), $p_array);
-               $wdate_end->value = HtmlInput::default_value("wdate_end", 
$periode_end->last_day(), $p_array);
-               //amounts
-               $wamount_start->value = 
HtmlInput::default_value("wamount_start", 0, $p_array);
-               $wamount_end->value = HtmlInput::default_value("wamount_end", 
0, $p_array);
-
-               //Card
-               $wcard->extra = "all";
-               $wcard->set_attribute("typecard", "all");
-               $wcard->value = HtmlInput::default_value("wcard", "", $p_array);
-
-               //Card stock
-               $wcode_stock->extra = " [sql] fd_id=500000 ";
-               $wcode_stock->set_attribute("typecard", "[sql] fd_id=500000");
-               $wcode_stock->value = HtmlInput::default_value("wcard", "", 
$p_array);
-
-               // Repository
-               $wcode_stock->value = HtmlInput::default_value("wcode_stock", 
"", $p_array);
-
-               //Direction
-               $wdirection->value = array(
-                       array('value' => "-1", 'label' => "Tout"),
-                       array('value' => "c", 'label' => "OUT"),
-                       array('value' => "d", 'label' => "IN")
-               );
-               $wdirection->selected = HtmlInput::default_value("wdirection", 
"-1", $p_array);
-
-               require_once NOALYSS_INCLUDE.'/template/stock_histo_search.php';
-       }
-
-       function create_query_histo($p_array)
-       {
-               global $cn,$g_user;
-               $profile=$g_user->get_profile();
-               $sql = "
-                       select sg_id,
-                               sg.f_id,
-                               (select ad_value from fiche_Detail as fd1 where 
ad_id=1 and fd1.f_id=jx.f_id) as fname,
-                               (select ad_value from fiche_Detail as fd1 where 
ad_id=23 and fd1.f_id=jx.f_id) as qcode,
-                               sg_code,
-                               coalesce(sg_comment,jr_comment) as ccomment,
-                               sg_exercice,
-                               r_name,
-                               sg.r_id,
-                               j_montant,
-                               jr_date,
-                               sg_quantity,
-                               case when sg_type='c' then 'OUT' when 
sg_type='d' then 'IN' end as direction,
-                               jr_internal,
-                               jr_id,
-                               coalesce(sg_date,jr_date) as real_date,
-                               to_char(coalesce(sg_date,jr_date),'DD.MM.YY') 
as cdate
-                       from stock_goods as sg
-                       join stock_repository as sr on (sg.r_id=sr.r_id)
-                       left join jrnx as jx on (sg.j_id=jx.j_id)
-                       left join jrn as j on (j.jr_grpt_id=jx.j_grpt)
-                       where
-                       sg.r_id in (select r_id from profile_sec_repository 
where p_id = $profile)";
-               $and = " and ";
-               $clause = "";
-               if (isset($p_array['wdate_start']) && $p_array['wdate_start'] 
!= '')
-               {
-                       $clause = $and." to_date('" . 
sql_string($p_array['wdate_start']) . 
"','DD.MM.YYYY')<=coalesce(sg_date,jr_date) ";
-               }
-               if (isset($p_array['wdate_end']) && $p_array['wdate_end'] != '')
-               {
-                       $clause.=$and . " to_date('" . 
sql_string($p_array['wdate_end']) . "','DD.MM.YYYY')>=coalesce(sg_date,jr_date) 
";
-               }
-               if (isset($p_array['wamount_start']) && 
$p_array['wamount_start'] != '' && isNumber($p_array['wamount_start']) == 1
-                                && $p_array['wamount_start'] != 0 )
-               {
-                       $clause.=$and . " j_montant >= " . 
sql_string($p_array['wamount_start']);
-               }
-               if (isset($p_array['wamount_end'])
-                               && $p_array['wamount_end'] != ''
-                               && $p_array['wamount_end'] != 0
-                               && isNumber($p_array['wamount_end']) == 1)
-               {
-                       $clause.=$and . " j_montant <= " . 
sql_string($p_array['wamount_end']);
-               }
-               if (isset($p_array['wcard']) && $p_array['wcard'] != '')
-               {
-                       $f = new Fiche($this->cn);
-                       $f->get_by_qcode($p_array['wcard'], false);
-                       if ($f->id != 0)
-                       {
-                               $clause.=$and . " sg.f_id =  " . 
sql_string($f->id);
-                       }
-               }
-               if (isset($p_array['wcode_stock']) && $p_array['wcode_stock'] 
!= "")
-               {
-                       $clause.=$and . " upper(sg_code) =  upper('" . 
sql_string(trim($p_array['wcode_stock'])) . "')";
-               }
-               if (isset($p_array['wrepo']) && $p_array['wrepo'] != -1)
-               {
-                       $clause.=$and . " sg.r_id = " . 
sql_string($p_array['wrepo']);
-               }
-               if (isset($p_array['wdirection']) && $p_array['wdirection'] != 
-1)
-               {
-                       $clause.=$and . " sg.sg_type = '" . 
sql_string($p_array['wdirection']) . "'";
-               }
-
-               return $sql . $clause;
-       }
-
-       function summary($p_array)
-       {
-               global $cn, $g_user;
-               $tmp_id=$this->build_tmp_table($p_array);
-               // Build condition
-               $a_repository = $g_user->get_available_repository('R');
-               $a_code = $cn->get_array("select distinct sg_code from 
tmp_stockgood_detail where s_id=$1", array($tmp_id));
-               if (isset($p_array['present']))
-               {
-                       $present = $p_array['present'];
-               }
-               else
-               {
-                       $present = 'T';
-               }
-               if ($present == 'T')
-               {
-                       require_once 
NOALYSS_INCLUDE.'/template/stock_summary_table.php';
-               }
-               if ($present == 'L')
-               {
-                       require_once 
NOALYSS_INCLUDE.'/template/stock_summary_list.php';
-                       $this->export_stock_summary_list_form();
-
-               }
-               echo HtmlInput::print_window();
-       }
-       function build_tmp_table($p_array)
-       {
-               global $cn,$g_user;
-                // exercice 
-                if (isset ($p_array['state_exercice']))
-                {
-                    $periode=new Periode($cn);
-                    $date=  format_date($p_array['state_exercice'], 
'YYYY-MM-DD');
-                    $periode->find_periode($date);
-                    
-                } else {
-                    $periode_id=$g_user->get_periode();
-                    $periode=new Periode($cn,$periode_id);
-                }
-                $periode->load();
-               $tmp_id = $cn->get_next_seq("public.tmp_stockgood_s_id_seq");
-               $cn->exec_sql("delete from tmp_stockgood where s_date < now() - 
interval '2 days' ");
-               $cn->exec_sql("insert into tmp_stockgood(s_id) values ($1)", 
array($tmp_id));
-
-               // get all readable repository
-               $a_repository = $g_user->get_available_repository('R');
-
-               // From ACH : IN
-               $sql_repo_detail = "
-                       insert into 
tmp_stockgood_detail(s_id,sg_code,s_qin,r_id,f_id)
-                               select $tmp_id,trim(sg_code), 
coalesce(sum(sg_quantity),0) as qin,r_id,f_id
-                               from stock_goods
-                               where
-                                       sg_type='d'
-                                       and j_id is not null
-                                       and j_id in (select j_id from jrnx 
where  j_tech_per in (select p_id from parm_periode where p_exercice=$2))
-                                       and r_id  in (select r_id from 
profile_sec_repository where p_id=$1)
-                                       group by r_id,trim(sg_code),f_id
-                       ";
-
-               // From VEN : out
-               $cn->exec_sql($sql_repo_detail, array($g_user->get_profile(), 
$periode->p_exercice));
-               $sql_repo_detail = "
-                               insert into 
tmp_stockgood_detail(s_id,sg_code,s_qout,r_id,f_id)
-                               select $tmp_id,trim(sg_code) , 
coalesce(sum(sg_quantity),0) as qout,r_id,f_id
-                               from stock_goods as sg
-                               where
-                                       sg_type='c'
-                                       and sg.j_id is not null
-                                       and sg.j_id in (select j_id from jrnx 
where  j_tech_per in (select p_id from parm_periode where p_exercice=$2))
-                                       and sg.r_id  in (select r_id from 
profile_sec_repository where p_id=$1)
-                                       group by r_id,trim(sg_code),f_id
-                       ";
-               $cn->exec_sql($sql_repo_detail, array($g_user->get_profile(), 
$periode->p_exercice));
-
-               // From INV  IN
-               $sql_repo_detail = "
-                       insert into 
tmp_stockgood_detail(s_id,sg_code,s_qin,r_id,f_id)
-                               select $tmp_id,trim(sg_code) , 
coalesce(sum(sg_quantity),0) as qin,r_id,f_id
-                               from stock_goods as sg
-                               where
-                                       sg_type='d'
-                                       and j_id is null
-                                       and sg_date >= ( select min(p_start) 
from parm_periode where p_exercice=$2)
-                                       and sg_date <= ( select max(p_end) from 
parm_periode where p_exercice=$2)
-                                        and sg.r_id  in (select r_id from 
profile_sec_repository where p_id=$1)
-                                       group by r_id,trim(sg_code),f_id
-                       ";
-               // From INV: OUT
-               $cn->exec_sql($sql_repo_detail, array($g_user->get_profile(), 
$periode->p_exercice));
-               $sql_repo_detail = "
-                               insert into 
tmp_stockgood_detail(s_id,sg_code,s_qout,r_id,f_id)
-                               select $tmp_id,trim(sg_code), 
coalesce(sum(sg_quantity),0) as qout,r_id,f_id
-                               from stock_goods
-                               where
-                                       sg_type='c'
-                                       and j_id is null
-                                        and r_id  in (select r_id from 
profile_sec_repository where p_id=$1)
-                                        and sg_date >= ( select min(p_start) 
from parm_periode where p_exercice=$2)
-                                       and sg_date <= ( select max(p_end) from 
parm_periode where p_exercice=$2)                                       
-                                        group by r_id,trim(sg_code),f_id
-                       ";
-               $cn->exec_sql($sql_repo_detail, array($g_user->get_profile(), 
$periode->p_exercice));
-               return $tmp_id;
-       }
-    
-
-}
-
-?>
diff --git a/include/class_stock_goods.php b/include/class_stock_goods.php
deleted file mode 100644
index e1a0887..0000000
--- a/include/class_stock_goods.php
+++ /dev/null
@@ -1,272 +0,0 @@
-<?php
-
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/**
- * @file
- * @brief Manage the goods
- *
- */
-require_once NOALYSS_INCLUDE.'/class_stock_goods_sql.php';
-
-class Stock_Goods extends Stock_Goods_Sql
-{
-/**
- * if an array if receive the keys are
- *  p_date
- *  p_depot
- *  f_idX f_id
- *  sg_codeX
- *  sg_type0
- *
- * @global $cn database connx
- * @param $p_array
- * if an array if receive the keys are
- *  p_date
- *  p_depot
- *  f_idX f_id
- *  sg_codeX
- *  sg_type0
- * @param $p_readonly true or false
- */
-       function input($p_array = null, $p_readonly = false)
-       {
-               global $cn;
-
-               if ($p_array != null)
-               {
-                       extract($p_array);
-               }
-               else
-               {
-                       $p_date = '';
-                       $p_motif = '';
-                       $p_depot = 0;
-               }
-               $date = new IDate('p_date', $p_date);
-               $date->setReadOnly($p_readonly);
-               $motif = new IText('p_motif', $p_motif);
-               $motif->setReadOnly($p_readonly);
-               $motif->size = 80;
-               $idepo = HtmlInput::select_stock($cn, "p_depot", "W");
-               $idepo->setReadOnly($p_readonly);
-               if (count($idepo->value) == 0)
-               {
-                       NoAccess();
-                       die();
-               }
-               $idepo->selected = $p_depot;
-                if ($p_readonly ) {
-                    $nb=$row;
-                } else {
-                    if (isset ($row ) )
-                    {
-                        $nb=($row > MAX_ARTICLE_STOCK)?$row:MAX_ARTICLE_STOCK;
-                    }else {
-                        $nb=MAX_ARTICLE_STOCK;
-                    }
-                }
-               for ($e = 0; $e < $nb; $e++)
-               {//ATTR_DEF_STOCKfiche_
-                       $sg_code[$e] = new ICard('sg_code' . $e);
-                       $sg_code[$e]->extra = "[sql]  fd_id = 500000";
-                       $sg_code[$e]->set_attribute("typecard", 
$sg_code[$e]->extra);
-                       $sg_code[$e]->set_attribute("label", "label" . $e);
-                       $sg_code[$e]->value = (isset(${'sg_code' . $e})) ? 
${'sg_code' . $e} : '';
-                       $sg_quantity[$e] = new INum('sg_quantity' . $e);
-                       $sg_quantity[$e]->value = (isset(${'sg_quantity' . 
$e})) ? ${'sg_quantity' . $e} : '';
-                       $label[$e] = new ISpan("label$e");
-                       if (trim($sg_code[$e]->value) != '')
-                       {
-                               $label[$e]->value = $cn->get_value("select 
vw_name from vw_fiche_attr where quick_code=$1", array($sg_code[$e]->value));
-                       }
-                       $sg_code[$e]->setReadOnly($p_readonly);
-                       $sg_quantity[$e]->setReadOnly($p_readonly);
-                       if ( isset (${'sg_type'.$e})) {
-                               $sg_type[$e]=(${'sg_type'.$e}=='c')?'OUT':'IN';
-                       }
-                       if ( isset (${'f_id'.$e})) {
-                               $fiche[$e]=new Fiche($this->cn,${'f_id'.$e});
-                       }
-               }
-                $select_exercice=new ISelect('p_exercice');
-                $select_exercice->value=$cn->make_array('select distinct 
p_exercice,p_exercice from parm_periode order by 1 desc');
-                
-                require_once NOALYSS_INCLUDE.'/template/stock_inv.php';
-       }
-
-       function record_save($p_array)
-       {
-               global $cn;
-               try
-               {
-                       if (isDate($p_array['p_date']) == null)
-                               throw new Exception('Date invalide');
-                       $cn->start();
-                       $ch = new Stock_Change_Sql($cn);
-                       $ch->setp("c_comment", $p_array['p_motif']);
-                       $ch->setp("r_id", $p_array['p_depot']);
-                       $ch->setp("c_date", $p_array['p_date']);
-                       $ch->setp('tech_user', $_SESSION['g_user']);
-                       $ch->insert();
-                       $per = new Periode($cn);
-                       $periode = $per->find_periode($p_array['p_date']);
-                       $exercice = $per->get_exercice($periode);
-                        $nb=$p_array['row'];
-                       for ($i = 0; $i < $nb; $i++)
-                       {
-                               $a = new Stock_Goods_Sql($cn);
-                               if ($p_array['sg_quantity' . $i] != 0 &&
-                                               trim($p_array['sg_code' . $i]) 
!= '')
-                               {
-                                        $stock=  
strtoupper(trim($p_array['sg_code' . $i]));
-                                       $fiche=new Fiche($cn);
-                                       $fiche->get_by_qcode($p_array['sg_code' 
. $i]);
-                                       /*
-                                         * check if code stock does exist
-                                         */
-                                        $count=$cn->get_value('select count(*) 
from fiche_detail where ad_id=$1 and ad_value=$2',
-                                                array(ATTR_DEF_STOCK,$stock));
-                                        if ( $count==0) {
-                                            throw new Exception("Code stock 
inexistant");
-                                        }
-                                       $a->f_id=$fiche->id;
-                                       $a->sg_code = $stock;
-                                       $a->sg_quantity = 
abs($p_array['sg_quantity' . $i]);
-                                       $a->sg_type = ($p_array['sg_quantity' . 
$i] > 0) ? 'd' : 'c';
-                                       $a->sg_comment = $p_array['p_motif'];
-                                       $a->tech_user = $_SESSION['g_user'];
-                                       $a->r_id = $p_array['p_depot'];
-                                       $a->sg_exercice = $exercice;
-                                       $a->c_id = $ch->c_id;
-                                       $a->sg_date=$p_array['p_date'];
-                                       $a->insert();
-                               }
-                       }
-                       $cn->commit();
-               }
-               catch (Exception $exc)
-               {
-                       echo $exc->getTraceAsString();
-                       throw $exc;
-               }
-       }
-        /**
-         * Insert into stock_goods from ACH and VEN
-         * @param type $p_array KEY : db => database conx, j_id => 
jrnx.j_id,goods=> f_id of the goods
-         * 'quant' => quantity ,'dir'=> d or c (c for sales OUT and d for 
purchase IN),'repo'=>r_id of the
-         * repository (stock_repository.r_id
-         */
-        static function insert_goods(&$p_cn,$p_array)
-        {
-            global $g_user;
-                       extract ($p_array);
-            if ($g_user->can_write_repo($repo) == false)
-                return false;
-
-            // Retrieve the good account for stock
-            $code = new Fiche($p_cn);
-            $code->get_by_qcode($goods);
-            $code_marchandise = $code->strAttribut(ATTR_DEF_STOCK);
-            if ($code_marchandise == NOTFOUND || $code_marchandise=='')
-                return false;
-
-            $exercice = $g_user->get_exercice();
-
-            if ($exercice == 0)
-                throw new Exception('Annee invalide erreur');
-
-            $Res = $p_cn->exec_sql("insert into stock_goods (
-                            j_id,
-                            f_id,
-                            sg_code,
-                            sg_quantity,
-                            sg_type,sg_exercice,r_id ) values 
($1,$2,$3,$4,$5,$6,$7)", array(
-                $p_array['j_id'],
-                $code->id,
-                $code_marchandise,
-                $p_array['quant'],
-                $p_array['dir'],
-                $exercice,
-                $p_array['repo']
-                    )
-            );
-           return $Res;
-    }
-    /**
-     * Return an array, used by Stock_Goods::input 
-     * @global type $cn
-     * @param type $p_array
-     * @throws Exception
-     */
-    function take_last_inventory($p_array)
-    {
-        global $cn;
-        $year=HtmlInput::default_value("p_exercice", "", $p_array);
-        $depot=HtmlInput::default_value("p_depot", "", $p_array);
-        if ($year=="")
-            throw new Exception(_('Inventaire invalide'), 10);
-        if ($depot=="")
-            throw new Exception(_('Dépôt invalide'), 20);
-
-        // compute state_exercice
-        $periode=new Periode($cn);
-        $periode->p_id=$cn->get_value("select min(p_id) from parm_periode 
where p_exercice=$1", array($year));
-        $first_day=$periode->first_day();
-
-        // compute array for stock
-        $array['state_exercice']=$first_day;
-        
-        $stock=new Stock($cn);
-        $rowid=$stock->build_tmp_table($array);
-
-        // compute first day of the next year
-        $next_year=$year+1;
-        $periode=new Periode($cn);
-        $periode->p_id=$cn->get_value("select min(p_id) from parm_periode 
where p_exercice=$1", array($next_year));
-        
-        if ($periode->p_id=="")
-            $array['p_date']="";
-        else
-            $array['p_date']=$periode->first_day();
-        
-        // Compute an array compatible with Stock_Goods::input
-        $array['p_motif']=_('Inventaire ').$year;
-        $array['p_depot']=$depot;
-        
-        $result=$cn->get_array("
-                select sg_code,sum(coalesce(s_qin,0)-coalesce(s_qout,0)) tot_
-                from tmp_stockgood_detail 
-                where 
-                s_id=$1 and r_id=$2 
-                group by sg_code",
-            array($rowid,$depot));
-        for ($e=0;$e< count($result);$e++) {
-            $array['sg_code'.$e]=$result[$e]['sg_code'];
-            $array['sg_quantity'.$e]=$result[$e]['tot_'];
-        }
-        $array['row']=$e;
-        return $array;
-        
-    }
-}
-
-?>
diff --git a/include/class_stock_goods_sql.php 
b/include/class_stock_goods_sql.php
deleted file mode 100644
index 4ec9424..0000000
--- a/include/class_stock_goods_sql.php
+++ /dev/null
@@ -1,120 +0,0 @@
-<?php
-
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/**
- * @file
- * @brief
- *
- */
-require_once NOALYSS_INCLUDE.'/class_noalyss_sql.php';
-
-class Stock_Goods_Sql extends Noalyss_SQL
-{
-
-       function __construct($cn,$p_id = -1)
-       {
-               $this->table = "public.stock_goods";
-               $this->primary_key = "sg_id";
-               $this->date_format="DD.MM.YYYY";
-
-               $this->name = array(
-                       "sg_id" => "sg_id",
-                       "j_id" => "j_id",
-                       "f_id" => "f_id",
-                       "sg_code" => "sg_code",
-                       "sg_quantity" => "sg_quantity",
-                       "sg_type" => "sg_type",
-                       "sg_date" => "sg_date",
-                       "sg_tech_date" => "sg_tech_date",
-                       "sg_tech_user" => "sg_tech_user",
-                       "sg_comment" => "sg_comment",
-                       "sg_exercice" => "sg_exercice",
-                       "r_id" => "r_id",
-                       "c_id"=>"c_id"
-               );
-
-               $this->type = array(
-                       "sg_id" => "numeric",
-                       "j_id" => "numeric",
-                       "f_id" => "numeric",
-                       "sg_code" => "text",
-                       "sg_quantity" => "text",
-                       "sg_type" => "text",
-                       "sg_date" => "date",
-                       "sg_tech_date" => "date",
-                       "sg_tech_user" => "text",
-                       "sg_comment" => "text",
-                       "sg_exercice" => "sg_exercice",
-                       "r_id" => "numeric",
-                       "c_id" => "numeric"
-
-               );
-
-               $this->default = array(
-                       "sg_id" => "auto",
-                       "sg_tech_date" => "auto",
-                       "sg_user" => "auto"
-               );
-               global $cn;
-
-               parent::__construct($cn, $p_id);
-       }
-
-}
-
-class Stock_Change_Sql extends Noalyss_SQL
-{
-
-       function __construct($cn,$p_id = -1)
-       {
-               $this->date_format="DD.MM.YYYY";
-               $this->table = "public.stock_change";
-               $this->primary_key = "c_id";
-
-               $this->name = array(
-                       "id" => "c_id",
-                       "c_comment" => "c_comment",
-                       "c_date" => "c_date",
-                       "tech_date"=>"tech_date",
-                       "tech_user"=>"tech_user",
-                       "r_id"=>"r_id"
-               );
-
-               $this->type = array(
-                       "c_id" => "numeric",
-                       "c_comment" => "text",
-                       "c_date" => "date",
-                       "tech_date"=>"date",
-                       "tech_user"=>"text",
-                       "r_id"=>"numeric"
-               );
-
-               $this->default = array(
-                       "c_id" => "auto",
-                       "tech_date" => "auto"
-               );
-               global $cn;
-
-               parent::__construct($cn, $p_id);
-       }
-}
-?>
diff --git a/include/class_stock_sql.php b/include/class_stock_sql.php
deleted file mode 100644
index 2d36dbe..0000000
--- a/include/class_stock_sql.php
+++ /dev/null
@@ -1,63 +0,0 @@
-<?php
-
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/**
- * @file
- * @brief
- *
- */
-require_once NOALYSS_INCLUDE.'/class_noalyss_sql.php';
-
-class Stock_Sql extends Noalyss_SQL {
-       function __construct($cn,$p_id=-1)
-       {
-               $this->table = "public.stock_repository";
-               $this->primary_key = "r_id";
-
-               $this->name=array(
-                       "id"=>"r_id",
-                       "name"=>"r_name",
-                       "adress"=>"r_adress",
-                       "city"=>"r_city",
-                       "country"=>"r_country",
-                       "phone"=>"r_phone"
-               );
-
-               $this->type = array(
-                       "r_id"=>"numeric",
-                       "r_name"=>"text",
-                       "r_adress"=>"text",
-                       "r_city"=>"text",
-                       "r_country"=>"text",
-                       "r_phone"=>"text"
-
-                       );
-
-               $this->default = array(
-                       "r_id" => "auto",
-               );
-               global $cn;
-
-               parent::__construct($cn,$p_id);
-       }
-}
-?>
diff --git a/include/class_supplier.php b/include/class_supplier.php
deleted file mode 100644
index 1afca13..0000000
--- a/include/class_supplier.php
+++ /dev/null
@@ -1,78 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-// Copyright Author Dany De Bontridder address@hidden
-require_once NOALYSS_INCLUDE.'/constant.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_acc_parm_code.php';
-require_once NOALYSS_INCLUDE.'/class_periode.php';
-require_once NOALYSS_INCLUDE.'/class_fiche.php';
-require_once NOALYSS_INCLUDE.'/class_acc_account_ledger.php';
-require_once NOALYSS_INCLUDE.'/user_common.php';
-/*! \file
- * \brief Derived from class fiche Supplier are a specific kind of card
- */
-/*!
- * \brief  class  Supplier are a specific kind of card
- */
-
-// Use the view vw_supplier
-//
-class Supplier extends Fiche
-{
-
-    var $poste;      /*!< $poste poste comptable */
-    var $name;        /*!< $name name of the company */
-    var $street;      /*!< $street Street */
-    var $country;     /*!< $country Country */
-    var $cp;          /*!< $cp Zip code */
-    var $vat_number;  /*!< $vat_number vat number */
-
-    /*! \brief Constructor
-    /* only a db connection is needed */
-    function __construct($p_cn,$p_id=0)
-    {
-        $this->fiche_def_ref=FICHE_TYPE_FOURNISSEUR;
-        parent::__construct($p_cn,$p_id) ;
-
-    }
-    /*! \brief  Get all info contains in the view
-     *  thanks to the poste elt (account)
-    */
-    function get_by_account($p_poste=0)
-    {
-        $this->poste=($p_poste==0)?$this->poste:$p_poste;
-        $sql="select * from vw_supplier where poste_comptable=".$this->poste;
-        $Res=$this->cn->exec_sql($sql);
-        if ( Database::num_row($Res) == 0) return null;
-        // There is only _one_ row by supplier
-        $row=Database::fetch_array($Res,0);
-        $this->name=$row['name'];
-        $this->id=$row['f_id'];
-        $this->street=$row['rue'];
-        $this->cp=$row['code_postal'];
-        $this->country=$row['pays'];
-        $this->vat_number=$row['tva_num'];
-
-    }
-
-
-
-}
-
-?>
diff --git a/include/class_tag.php b/include/class_tag.php
deleted file mode 100644
index ee49c6a..0000000
--- a/include/class_tag.php
+++ /dev/null
@@ -1,115 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-// Copyright Author Dany De Bontridder address@hidden
-require_once NOALYSS_INCLUDE.'/class_tag_sql.php';
-
-class Tag
-{
-    function __construct($p_cn,$id=-1)
-    {
-        $this->cn=$p_cn;
-        $this->data=new Tag_SQL($p_cn,$id);
-    }
-    /**
-     * Show the list of available tag
-     * @return HTML
-     */
-    function show_list()
-    {
-        $ret=$this->data->seek(' order by t_tag');
-        if ( $this->cn->count($ret) == 0) return "";
-        require_once NOALYSS_INCLUDE.'/template/tag_list.php';
-    }
-    /**
-     * let select a tag to add
-     */
-    function select()
-    {
-        $ret=$this->data->seek(' order by t_tag');
-        require_once NOALYSS_INCLUDE.'/template/tag_select.php';
-    }
-    /**
-     * Display a inner window with the detail of a tag
-     */
-    function form_add()
-    {
-        $data=$this->data;
-        require_once NOALYSS_INCLUDE.'/template/tag_detail.php';
-    }
-    /**
-     * Show the tag you can add to a document
-     */
-    function show_form_add()
-    {
-        echo '<h2>'.' Ajout d\'un dossier (ou  tag)'.'</h2>';
-       
-        $this->form_add();
-    }
-    function save($p_array)
-    {
-        if ( trim($p_array['t_tag'])=="" ) return ;
-        $this->data->t_id=$p_array['t_id'];
-        $this->data->t_tag=  strip_tags($p_array['t_tag']);
-        $this->data->t_description=strip_tags($p_array['t_description']);
-        $this->data->save();
-    }
-    function remove($p_array)
-    {
-        $this->data->t_id=$p_array['t_id'];
-        $this->data->delete();
-    }
-    /**
-     * Show a button to select tag for Search
-     * @return HTML
-     */
-    static  function button_search($p_prefix)
-    {
-        $r="";
-        $r.=HtmlInput::button("choose_tag", "Etiquette", 
'onclick="search_display_tag('.Dossier::id().',\''.$p_prefix.'\')"', 
"smallbutton");
-        return $r;
-    }
-    /**
-     * let select a tag to add to the search
-     */
-    function select_search($p_prefix)
-    {
-        $ret=$this->data->seek(' order by t_tag');
-        require_once NOALYSS_INCLUDE.'/template/tag_search_select.php';
-    }
-    /**
-     * In the screen search add this data to the cell
-     */
-    function update_search_cell($p_prefix) {
-        echo '<span id="sp_'.$p_prefix.$this->data->t_id.'" style="border:1px 
solid black;margin-right:5px;">';
-        echo h($this->data->t_tag);
-        echo HtmlInput::hidden($p_prefix.'tag[]', $this->data->t_id);
-        $js=sprintf("$('sp_".$p_prefix.$this->data->t_id."').remove();");
-        echo HtmlInput::anchor( SMALLX, "javascript:void(0)", 
"onclick=\"$js\"", ' class="smallbutton " style="padding:0px;display:inline" ');
-        echo '</span>';
-    }
-    /**
-     * clear the search cell
-     */
-    static function add_clear_button($p_prefix) {
-        $clear=HtmlInput::button('clear', 'X', 
'onclick="search_clear_tag('.Dossier::id().',\''.$p_prefix.'\');"', 
'smallbutton');
-        return $clear;
-    }
-}
-
-?>
diff --git a/include/class_tag_sql.php b/include/class_tag_sql.php
deleted file mode 100644
index 149248c..0000000
--- a/include/class_tag_sql.php
+++ /dev/null
@@ -1,54 +0,0 @@
-<?php
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/ac_common.php';
-require_once NOALYSS_INCLUDE.'/class_noalyss_sql.php';
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-// Copyright Author Dany De Bontridder address@hidden
-/**
- * @brief Manage the table public.tag
- */
-class Tag_SQL extends Noalyss_SQL
-{
-       /* example private 
$variable=array("easy_name"=>column_name,"email"=>"column_name_email","val3"=>0);
 */
-
-       function __construct(& $p_cn, $p_id = -1)
-       {
-               $this->table = "public.tags";
-               $this->primary_key = "t_id";
-
-               $this->name = array(
-                       "t_id" => "t_id"
-                       , "t_tag" => "t_tag"
-                       , "t_description" => "t_description"
-                    );
-               $this->type = array(
-                       "t_id" => "numeric"
-                       , "t_tag" => "text"
-                       , "t_description" => "text"
-               );
-               $this->default = array(
-                       "t_id" => "auto",
-               );
-
-               parent::__construct($p_cn,$p_id);
-
-       }
-
-}
-?>
diff --git a/include/class_todo_list.php b/include/class_todo_list.php
deleted file mode 100644
index 24ac216..0000000
--- a/include/class_todo_list.php
+++ /dev/null
@@ -1,415 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief the todo list is managed by this class
- */
-
-require_once NOALYSS_INCLUDE.'/function_javascript.php';
-
-/*!\brief
- * This class manages the table todo_list
- *
- *
- * Data Member :
- * - $cn database connx
- * - $variable
- *    - id (todo_list.tl_id)
- *    - date (todo_list.tl_Date)
- *    - title (todo_list.title)
- *    - desc (todo_list.tl_desc)
- *    - owner (todo_list.use_id)
- *
- */
-class Todo_List
-{
-
-    private static $variable=array(
-                                 "id"=>"tl_id",
-                                 "date"=>"tl_date",
-                                 "title"=>"tl_title",
-                                 "desc"=>"tl_desc",
-                                 "owner"=>"use_login",
-                                 "is_public"=>"is_public");
-    private $cn;
-    private  $tl_id,$tl_date,$tl_title,$use_login,$is_public;
-
-    function __construct ($p_init)
-    {
-        $this->cn=$p_init;
-        $this->tl_id=0;
-        $this->tl_desc="";
-        $this->use_login=$_SESSION['g_user'];
-        $this->is_public="N";
-
-    }
-    public function get_parameter($p_string)
-    {
-        if ( array_key_exists($p_string,self::$variable) )
-        {
-            $idx=self::$variable[$p_string];
-            return $this->$idx;
-        }
-        else
-            throw new Exception("Attribut inexistant $p_string");
-    }
-    public function check($p_idx,&$p_value)
-    {
-        if ( strcmp ($p_idx, 'tl_id') == 0 )
-        {
-            if ( strlen($p_value) > 6 || isNumber ($p_value) == false) return 
false;
-        }
-        if ( strcmp ($p_idx, 'tl_date') == 0 )
-        {
-            if ( strlen(trim($p_value)) ==0 ||strlen($p_value) > 12 || isDate 
($p_value) == false) return false;
-        }
-        if ( strcmp ($p_idx, 'tl_title') == 0 )
-        {
-            $p_value=mb_substr($p_value,0,120) ;
-            return true;
-        }
-        if ( strcmp ($p_idx, 'tl_desc') == 0 )
-        {
-            $p_value=mb_substr($p_value,0,400) ;
-            return true;
-        }
-        return true;
-    }
-    public function set_parameter($p_string,$p_value)
-    {
-        if ( array_key_exists($p_string,self::$variable) )
-        {
-            $idx=self::$variable[$p_string];
-            if ($this->check($idx,$p_value) == true )      
$this->$idx=$p_value;
-        }
-        else
-            throw new Exception("Attribut inexistant $p_string");
-
-
-    }
-    public function get_info()
-    {
-        return var_export(self::$variable,true);
-    }
-    public function verify()
-    {
-        if ( isDate($this->tl_date) == false )
-        {
-                       $this->tl_date=date('d.m.Y');
-        }
-        return 0;
-    }
-    public function save()
-    {
-        if (  $this->get_parameter("id") == 0 )
-            $this->insert();
-        else
-            $this->update();
-    }
-
-    public function insert()
-    {
-        if ( $this->verify() != 0 ) return;
-        if (trim($this->tl_title)=='')
-            $this->tl_title=mb_substr(trim($this->tl_desc),0,30);
-
-        if (trim($this->tl_title)=='')
-        {
-            alert('La note est vide');
-            return;
-        }
-
-        /*  limit the title to 35 char */
-        $this->tl_title=mb_substr(trim($this->tl_title),0,30);
-
-        $sql="insert into todo_list 
(tl_date,tl_title,tl_desc,use_login,is_public) ".
-             " values (to_date($1,'DD.MM.YYYY'),$2,$3,$4,$5)  returning tl_id";
-        $res=$this->cn->exec_sql(
-                 $sql,
-                 array($this->tl_date,
-                       $this->tl_title,
-                       $this->tl_desc,
-                       $this->use_login,
-                     $this->is_public)
-             );
-        $this->tl_id=Database::fetch_result($res,0,0);
-
-    }
-
-    public function update()
-    {
-        if ( $this->verify() != 0 ) return;
-
-        if (trim($this->tl_title)=='')
-            $this->tl_title=mb_substr(trim($this->tl_desc),0,40);
-
-        if (trim($this->tl_title)=='')
-        {
-            
-            return;
-        }
-
-        /*  limit the title to 35 char */
-        $this->tl_title=mb_substr(trim($this->tl_title),0,40);
-
-        $sql="update todo_list set 
tl_title=$1,tl_date=to_date($2,'DD.MM.YYYY'),tl_desc=$3,is_public=$5 ".
-             " where tl_id = $4";
-        $res=$this->cn->exec_sql(
-                 $sql,
-                 array($this->tl_title,
-                       $this->tl_date,
-                       $this->tl_desc,
-                       $this->tl_id,
-                     $this->is_public)
-             );
-
-    }
-    /*!\brief load all the task
-     *\return an array of the existing tasks of the current user
-     */
-    public function load_all()
-    {
-        $sql="select tl_id, 
-                tl_title,
-                tl_desc,
-                to_char( tl_date,'DD.MM.YYYY') as tl_date,
-                is_public,
-                use_login
-             from todo_list 
-             where 
-                use_login=$1
-                or is_public = 'Y'
-                or tl_id in (select todo_list_id from todo_list_shared where 
use_login=$1)
-             order by tl_date::date desc";
-        $res=$this->cn->exec_sql(
-                 $sql,
-                 array($this->use_login));
-        $array=Database::fetch_all($res);
-        
-        return $array;
-    }
-    public function load()
-    {
-
-        $sql="select tl_id,tl_title,tl_desc,to_char( tl_date,'DD.MM.YYYY') as 
tl_date,is_public,use_login
-             from todo_list where tl_id=$1 ";
-
-        $res=$this->cn->exec_sql(
-                 $sql,
-                 array($this->tl_id)
-             );
-
-        if ( Database::num_row($res) == 0 ) return;
-        $row=Database::fetch_array($res,0);
-        foreach ($row as $idx=>$value)
-        {
-            $this->$idx=$value;
-        }
-
-    }
-    public function delete()
-    {
-        global $g_user;
-        if ( $this->use_login != $_SESSION['g_user'] && 
$g_user->check_action(SHARENOTEREMOVE)==0) return;
-        $sql="delete from todo_list where tl_id=$1 ";
-        $res=$this->cn->exec_sql($sql,array($this->tl_id));
-
-    }
-    /**
-     address@hidden transform into xml for ajax answer
-     */
-    public function toXML()
-    {
-        $id='<tl_id>'.$this->tl_id.'</tl_id>';
-        $title='<tl_title>'.escape_xml($this->tl_title).'</tl_title>';
-        $desc='<tl_desc>'.escape_xml($this->tl_desc).'</tl_desc>';
-        $date='<tl_date>'.$this->tl_date.'</tl_date>';
-        $ret='<data>'.$id.$title.$desc.$date.'</data>';
-        return $ret;
-    }
-    /**
-     * @brief set a note public
-     * @param $p_value is Y or N
-     */
-    public function set_is_public($p_value)
-    {
-        global $g_user;
-        if ($g_user->check_action(SHARENOTEPUBLIC) == 1 )
-        {
-            $this->is_public=$p_value;
-        }
-    }
-    /**
-     * @brief Insert a share for current note 
-     * in the table todo_list_shared
-     * @param string (use_login)
-     */
-    public function save_shared_with($p_array)
-    {
-        global $g_user;
-        if ($g_user->check_action(SHARENOTE) == 1 )
-        {
-            $this->cn->exec_sql('insert into todo_list_shared 
(todo_list_id,use_login) values ($1,$2)',
-                    array($this->tl_id,$p_array));
-            
-        }
-    }
-    /**
-     * @brief Insert a share for current note 
-     * in the table todo_list_shared
-     * The public shared note cannot be removed
-     * @param string (use_login)
-     */
-    public function remove_shared_with($p_array)
-    {
-          $this->cn->exec_sql('delete from todo_list_shared where todo_list_id 
= $1 and use_login=$2',
-                    array($this->tl_id,$p_array));
-    }
-
-    /**
-     * Display the note
-     * @return html string
-     */
-    function display()
-    {
-        ob_start();
-        $this->load();
-        include 'template/todo_list_display.php';
-        $ret=ob_get_clean();
-        
-        return $ret;
-    }
-    /**
-     * Highlight today
-     * @return string
-     */
-    function get_class()
-    {
-        $p_odd="";
-        $a=date('d.m.Y');
-        if ($a == $this->tl_date) $p_odd='highlight';
-        return $p_odd;
-    }
-    function display_row($p_odd,$with_tag='Y')
-    {
-        $r="";
-        $highlight=$this->get_class();
-        $p_odd=($highlight == "")?$p_odd:$highlight;
-        if ( $with_tag == 'Y') $r =  '<tr id="tr'.$this->tl_id.'" 
class="'.$p_odd.'">';
-        $r.=
-      '<td 
sorttable_customkey="'.format_date($this->tl_date,'DD.MM.YYYY','YYYYMMDD').'">'.
-                $this->tl_date.
-      '</td>'.
-      '<td>'.
-      '<a class="line" href="javascript:void(0)" 
onclick="todo_list_show(\''.$this->tl_id.'\')">'.
-      htmlspecialchars($this->tl_title).
-      '</a>'.
-       '</td>';
-        if ( $this->is_public == 'Y' && $this->use_login != 
$_SESSION['g_user'] )
-        { // This is a public note, cannot be removed
-            $r.= '<td></td>';
-        }
-        elseif ($this->use_login == $_SESSION['g_user'] )
-        {
-            // This a note the user owns
-            $r.=  '<td>'.
-         
HtmlInput::button('del','X','onClick="todo_list_remove('.$this->tl_id.')"','smallbutton').
-         '</td>';
-        }
-        else
-        { 
-            // this is a note shared by someone else
-            $r.=  '<td>'.
-                
HtmlInput::button('del','X','onClick="todo_list_remove_share('.$this->tl_id.',\''.$this->use_login.'\','.Dossier::id().')"','smallbutton').
-         '</td>';
-        }
-        
-      if ( $with_tag == 'Y')  $r .= '</tr>';
-        return $r;
-    }
-    static  function to_object ($p_cn,$p_array) 
-    {
-        $end=count($p_array);
-        $ret=array();
-        for ($i=0;$i < $end;$i++)
-        {
-            $t=new Todo_List($p_cn);
-            $t->tl_id=$p_array[$i]['tl_id'];
-            $t->tl_date=$p_array[$i]['tl_date'];
-            $t->tl_title=$p_array[$i]['tl_title'];
-            $t->tl_desc=$p_array[$i]['tl_desc'];
-            $t->is_public=$p_array[$i]['is_public'];
-            $t->use_login=$p_array[$i]['use_login'];
-            $ret[$i]=clone $t;
-        }
-        return $ret;
-    }
-    /**
-     * @brief display all the user to select the user with who we want to share
-     * the connected user is not shown
-     * @global type $g_user
-     */
-    function display_user()
-    {
-        global $g_user;
-        // Get array of user
-        $p_array=User::get_list(Dossier::id());
-        $dossier=Dossier::id();
-        include 'template/todo_list_list_user.php';
-        
-    }
-    /**
-     * return the todo_list_shared.id of the note, if nothing is found then
-     * return 0
-     * @param $p_login
-     * @return int
-     */
-    function is_shared_with($p_login)
-    {
-        $ret=$this->cn->get_value("select id from todo_list_shared where 
use_login=$1 and todo_list_id=$2",array($p_login,$this->tl_id));
-        if ($ret == "")return 0;
-        return $ret;
-    }
-    /**
-     * @brief Add a share with someone
-     * @param type $p_login
-     */
-    function add_share($p_login)
-    {
-        $this->cn->exec_sql("insert into 
todo_list_shared(todo_list_id,use_login) values 
($1,$2)",array($this->tl_id,$p_login));
-    }
-    /**
-     * @brief remove the share with someone
-     * @param type $p_login
-     */
-    function remove_share($p_login)
-    {
-        $this->cn->exec_sql("delete from todo_list_shared where todo_list_id = 
$1 and use_login  = $2 ",array($this->tl_id,$p_login));
-    }
-    /*!\brief static testing function
-     */
-    static function test_me()
-    {
-    }
-
-}
-
-
diff --git a/include/class_tool_uos.php b/include/class_tool_uos.php
deleted file mode 100644
index 2046a36..0000000
--- a/include/class_tool_uos.php
+++ /dev/null
@@ -1,107 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-/**
- * @file
- * @brief Objec to check a double insert into the database, this duplicate 
occurs after
- * a refresh of the web page
- */
-// Copyright Author Dany De Bontridder address@hidden
-
-require_once NOALYSS_INCLUDE.'/class_database.php';
-define ('CODE_EXCP_DUPLICATE',901);
-/**
- * @brief Objec to check a double insert into the database, this duplicate 
occurs after
- * a refresh of the web page
- * in
- */
-
-class Tool_Uos
-{
-    /**
-     * Constructor $p_name will be set to $this->name, it is also the name
-     * of the tag hidden in a form
-     * @global $cn Db connxion
-     * @param $p_name
-     */
-    function __construct($p_name)
-    {
-        $this->name=$p_name;
-    }
-    /**
-     * @brief return a string with a tag hidden and a uniq value
-     * @param $hHidden is the name of the tag hidden
-     * @return string : tag hidden
-     */
-    function hidden()
-    {
-               global $cn;
-        $this->id=$cn->get_next_seq('uos_pk_seq');
-        return HtmlInput::hidden($this->name,$this->id);
-    }
-    /**
-     * @brief Try to insert into the table tool_uos
-     * @global $cn Database connx
-     * @throws Exception if the value $p_id is not unique
-     */
-    function save($p_array=null)
-    {
-        global $cn;
-               if ( $p_array == null ) $p_array=$_POST;
-               $this->id=$p_array[$this->name];
-        $sql="insert into tool_uos(uos_value) values ($1)";
-        try {
-            $cn->exec_sql($sql,array($this->id));
-        } catch (Exception $e)
-        {
-            throw new Exception('Duplicate value');
-        }
-    }
-    /**
-     * Count how many time we have this->id into the table tool_uos
-     * @global $cn Database connx
-     * @param $p_array is the array where to find the key name, usually it is
-     * $_POST. The default value is $_POST
-     * @return integer : 0 or 1
-     */
-    function get_count($p_array=null)
-    {
-        global $cn;
-        if ( $p_array == null ) $p_array=$_POST;
-        $this->id=$p_array[$this->name];
-        $count=$cn->get_value('select count(*) from tool_uos where 
uos_value=$1',
-                array($this->id));
-        return $count;
-    }
-    function check ($p_array=null)
-    {
-        global $cn;
-        if ( $p_array == null ) $p_array=$_POST;
-        $this->id=$p_array[$this->name];
-        try
-        {
-            $count=$cn->get_value('select count(*) from tool_uos where 
uos_value=$1',
-                    array($this->id));
-            if ($count != 0 ) throw new Exception 
('DUPLICATE',CODE_EXCP_DUPLICATE);
-        }catch (Exception $e)
-        {
-            throw $e;
-        }
-    }
-}
-?>
diff --git a/include/class_user.php b/include/class_user.php
deleted file mode 100644
index c166303..0000000
--- a/include/class_user.php
+++ /dev/null
@@ -1,1226 +0,0 @@
-<?php
-
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-// Copyright Author Dany De Bontridder address@hidden
-/** 
- * @file
- * @brief Data & function about connected users
- */
-
-/**
- * @brief Data & function about connected users
- *   
- */
-
-require_once NOALYSS_INCLUDE.'/constant.php';
-require_once NOALYSS_INCLUDE.'/user_common.php';
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-require_once NOALYSS_INCLUDE.'/ac_common.php';
-
-class User
-{
-
-       var $id;
-       var $pass;
-       var $db;
-       var $admin;
-       var $valid;
-        var $first_name;
-        var $name;
-        var $active ;
-        var $login ;
-        var $password ;
-        var $email ;
-        
-       function User(&$p_cn, $p_id = -1)
-       {
-               // if p_id is not set then check the connected user
-               if ($p_id == -1)
-               {
-                       if (!isset($_SESSION['g_user']))
-                       {
-                               echo '<h2 class="error">' . _('Session 
expirée<br>Utilisateur déconnecté') . '</h2>';
-                               redirect('index.php', 1);
-                               exit();
-                       }
-
-                       $this->login =strtolower($_SESSION['g_user']);
-                       $this->pass = $_SESSION['g_pass'];
-                       $this->lang = (isset($_SESSION['g_lang'])) ? 
$_SESSION['g_lang'] : 'fr_FR.utf8';
-                       $this->valid = (isset($_SESSION['isValid'])) ? 1 : 0;
-                       $this->db = $p_cn;
-                       $this->id = -1;
-                       if (isset($_SESSION['g_theme']))
-                               $this->theme = $_SESSION['g_theme'];
-
-                       $this->admin = ( isset($_SESSION['use_admin']) ) ? 
$_SESSION['use_admin'] : 0;
-
-                       if (isset($_SESSION['use_name']))
-                               $this->name = $_SESSION['use_name'];
-                       if (isset($_SESSION['use_first_name']))
-                               $this->first_name = $_SESSION['use_first_name'];
-                       $this->load();
-               }
-               else // if p_id is set get data of another user
-               {
-                       $this->id = $p_id;
-                       $this->db = $p_cn;
-                       $this->load();
-               }
-       }
-
-       /**\brief load data from database.
-        * if this->id == -1, it is unknown so we have to retrieve it
-         from the database by the login
-        * return -1 if nothing is found
-        */
-
-       function load()
-       {
-               /* if this->id == -1, it is unknown so we have to retrieve it 
from
-                 the database thanks it login */
-               if ($this->id < 0)
-               {
-                       $sql_cond = "   where lower(use_login)=lower($1)";
-                       $sql_array = array($this->login);
-               }
-               else
-               {
-                       $sql_cond = "   where use_id=$1";
-                       $sql_array = array($this->id);
-               }
-               $sql = "select use_id,
-                            use_first_name,
-                            use_name,
-                            use_login,
-                            use_active,
-                            use_admin,
-                            use_pass,
-                            use_email
-                        from ac_users ";
-               $cn = new Database();
-               $Res = $cn->exec_sql($sql . $sql_cond, $sql_array);
-               if (($Max = Database::num_row($Res)) == 0)
-                       return -1;
-               $row = Database::fetch_array($Res, 0);
-               $this->id = $row['use_id'];
-               $this->first_name = $row['use_first_name'];
-               $this->last_name = $row['use_name'];
-               $this->name = $row['use_name'];
-               $this->active = $row['use_active'];
-               $this->login = $row['use_login'];
-               $this->admin = $row['use_admin'];
-               $this->password = $row['use_pass'];
-                $this->email=$row['use_email'];
-       }
-
-       function save()
-       {
-
-               $Sql = "update ac_users set use_first_name=$1, use_name=$2
-             ,use_active=$3,use_admin=$4,use_pass=$5 ,use_email = $7 where 
use_id=$6";
-               $cn = new Database();
-               $Res = $cn->exec_sql($Sql, array($this->first_name, 
$this->last_name, $this->active, $this->admin, $this->pass, 
$this->id,$this->email));
-       }
-        function insert()
-       {
-
-               $Sql = "INSERT INTO ac_users(
-                        use_first_name, use_name, use_login, use_active,  
-                        use_admin, use_pass, use_email)
-                            VALUES ($1, $2, $3, $4, $5, $6, $7) returning 
use_id";
-
-               $cn = new Database();
-               $this->id= $cn->get_value($Sql, array($this->first_name, 
$this->last_name, $this->login,1,0, $this->pass,$this->email));
-       }
-
-       /**
-        * \brief Check if user is active and exists in therepository
-        * Automatically redirect, it doesn't check if a user can access a 
folder
-        * \param $silent false, echo an error message and exit, true : exit 
without warning
-        * default is false
-        *
-         ++ */
-
-       function Check($silent = false, $from = '')
-       {
-
-               $res = 0;
-               $pass5 = md5($this->pass);
-
-               $cn = new Database();
-               $sql = "select ac_users.use_login,ac_users.use_active, 
ac_users.use_pass,
-             use_admin,use_first_name,use_name
-             from ac_users
-             where ac_users.use_id='$this->id'
-             and ac_users.use_active=1
-             and ac_users.use_pass='$pass5'";
-               $ret = $cn->exec_sql($sql);
-               $res = Database::num_row($ret);
-               if ($res > 0)
-               {
-                       $r = Database::fetch_array($ret, 0);
-                       $_SESSION['use_admin'] = $r['use_admin'];
-                       $_SESSION['use_name'] = $r['use_name'];
-                       $_SESSION['use_first_name'] = $r['use_first_name'];
-                       $_SESSION['isValid'] = 1;
-
-                       $this->admin = $_SESSION['use_admin'];
-                       $this->name = $_SESSION['use_name'];
-                       $this->first_name = $_SESSION['use_first_name'];
-                       $this->load_global_pref();
-               }
-               $sql = "insert into audit_connect 
(ac_user,ac_ip,ac_module,ac_url,ac_state) values ($1,$2,$3,$4,$5)";
-
-               if ($res == 0)
-               {
-                       $cn->exec_sql($sql, array($_SESSION['g_user'], 
$_SERVER["REMOTE_ADDR"], $from, $_SERVER['REQUEST_URI'], 'FAIL'));
-                       if (!$silent)
-                       {
-                               echo '<script> alert(\''._('Utilisateur ou mot 
de passe incorrect').'\')</script>';
-                               redirect('index.html');
-                       }
-                       $this->valid = 0;
-                       session_unset();
-                       exit - 1;
-               }
-               else
-               {
-                       if ($from == 'LOGIN')
-                               $cn->exec_sql($sql, array($_SESSION['g_user'], 
$_SERVER["REMOTE_ADDR"], $from, $_SERVER['REQUEST_URI'], 'SUCCESS'));
-                       $this->valid = 1;
-               }
-
-               return $ret;
-       }
-
-       /**
-         * \brief return  the access to a folder,
-        * \param $p_dossier id if it is == 0 then we take the value from 
$_SESSION
-        * \return the priv_priv
-        *          - X no access
-        *          - R has access (normal user)
-        
-        *
-        */
-
-       function get_folder_access($p_dossier = 0)
-       {
-
-               if ($p_dossier == 0)
-                       $p_dossier = dossier::id();
-               if ($this->admin == 1)          return 'R';
-               $cn = new Database();
-
-               $sql = "select 'R' from jnt_use_dos where use_id=$1 and 
dos_id=$2";
-
-               $res = $cn->get_value($sql, array($this->id, $p_dossier));
-                
-               if ($cn->get_affected()== 0) return 'X';
-               return $res;
-       }
-
-       /**
-         * \brief save the access of a folder
-        * \param $db_id the dossier id
-        * \param $priv boolean, true then it is granted, false it is removed
-        */
-
-       function set_folder_access($db_id, $priv)
-        {
-
-            $cn=new Database();
-            if ($priv)
-            {
-                // the access is granted
-                $jnt=$cn->get_value("select jnt_id from jnt_use_dos where 
dos_id=$1 and use_id=$2", array($db_id, $this->id));
-
-                if ($cn->size()==0)
-                {
-
-                    $Res=$cn->exec_sql("insert into jnt_use_dos(dos_id,use_id) 
values($1,$2)", array($db_id, $this->id));
-                }
-            } 
-            else 
-            {
-                // Access is revoked
-                $cn->exec_sql('delete from jnt_use_dos where use_id  = $1 and 
dos_id = $2 ', array($this->id, $db_id));
-            }
-        }
-
-    /**
-         * \brief check that a user is valid and the access to the folder
-        * \param $p_ledger the ledger to check
-        * \return the priv_priv
-        * - O only predefined operation
-        * - W write
-        * - R read only
-        * - X no access
-        *
-
-        *
-        */
-
-       function get_ledger_access($p_ledger)
-       {
-               if ($this->admin == 1 ||
-                               $this->is_local_admin(dossier::id()) == 1)
-                       return 'W';
-
-               $sql = "select uj_priv from user_sec_jrn where uj_login=$1 and 
uj_jrn_id=$2";
-               $res = $this->db->get_value($sql, array($this->login, 
$p_ledger));
-
-               if ($res == '')
-                       $res = 'X';
-               return $res;
-       }
-
-       /**
-        * \brief get all the available ledgers for the current user
-        * \param $p_type = ALL or the type of the ledger (ACH,VEN,FIN,ODS)
-        * \param $p_access =3 for Read or WRITE, 2  write, 1 for readonly
-        *  \return a double array of available ledgers
-         @verbatim
-         [0] => [jrn_def_id]
-         [jrn_def_type]
-         [jrn_def_name]
-         [jrn_def_class_deb]
-         [jrn_def_class_cred]
-         [jrn_type_id]
-         [jrn_desc]
-         [uj_priv]
-         @endverbatim
-        */
-
-       function get_ledger($p_type = 'ALL', $p_access = 3)
-       {
-               if ($this->admin != 1 && $this->is_local_admin() != 1)
-               {
-                       $sql_type = ($p_type == 'ALL') ? '' : "and 
jrn_def_type=upper('" . sql_string($p_type) . "')";
-                       switch ($p_access)
-                       {
-                               case 3:
-                                       $sql_access = " and uj_priv!= 'X'";
-                                       break;
-                               case 2:
-                                       $sql_access = " and uj_priv = 'W'";
-                                       break;
-
-                               case 1:
-                                       $sql_access = " and ( uj_priv = 'R' or 
uj_priv='W') ";
-                                       break;
-                       }
-
-                       $sql = "select jrn_def_id,jrn_def_type,
-                 
jrn_def_name,jrn_def_class_deb,jrn_def_class_cred,jrn_type_id,jrn_desc,uj_priv,
-                 jrn_deb_max_line,jrn_cred_max_line,jrn_def_description
-                 from jrn_def join jrn_type on jrn_def_type=jrn_type_id
-                 join user_sec_jrn on uj_jrn_id=jrn_def_id
-                 where
-                 uj_login='" . $this->login . "'" .
-                                       $sql_type . $sql_access .
-                                       " order by jrn_Def_id";
-               }
-               else
-               {
-                       $sql_type = ($p_type == 'ALL') ? '' : "where 
jrn_def_type=upper('" . sql_string($p_type) . "')";
-                       $sql = "select 
jrn_def_id,jrn_def_type,jrn_def_name,jrn_def_class_deb,jrn_def_class_cred,jrn_deb_max_line,jrn_cred_max_line,
-                 jrn_type_id,jrn_desc,'W' as uj_priv,jrn_def_description
-                 from jrn_def join jrn_type on jrn_def_type=jrn_type_id
-                 $sql_type
-                 order by jrn_Def_name";
-               }
-               $res = $this->db->exec_sql($sql);
-               if (Database::num_row($res) == 0)
-                       return null;
-               $array = Database::fetch_all($res);
-               return $array;
-       }
-
-       /**
-         * \brief return an sql condition for filtering the permitted ledger
-        * \param $p_type = ALL or the type of the ledger (ACH,VEN,FIN,ODS)
-        * \param $p_access =3 for READ or WRITE, 2 READ and write, 1 for 
readonly
-        *
-        * \return sql condition like = jrn_def_id in (...)
-        */
-
-       function get_ledger_sql($p_type = 'ALL', $p_access = 3)
-       {
-               $aLedger = $this->get_ledger($p_type, $p_access);
-               if (empty($aLedger))
-                       return ' jrn_def_id < 0 ';
-               $sql = " jrn_def_id in (";
-               foreach ($aLedger as $row)
-               {
-                       $sql.=$row['jrn_def_id'] . ',';
-               }
-               $sql.='-1)';
-               return $sql;
-       }
-
-       /**
-        * \brief  Check if an user is an admin
-        *
-        * \return 1 for yes 0 for no
-        */
-
-       function Admin()
-       {
-            $this->admin = 0;
-               if ($this->login != 'phpcompta')
-               {
-                       $pass5 = md5($this->pass);
-                       $sql = "select use_admin from ac_users where 
use_login=$1
-                 and use_active=1  ";
-
-                       $cn = new Database();
-                       $res = $cn->exec_sql($sql, array($this->login));
-                       if (Database::num_row($res) == 0)
-                               throw  new Exception(__FILE__ . " " . __LINE__ 
. " aucun resultat");
-                       $this->admin = Database::fetch_result($res, 0);
-               }
-               else
-                       $this->admin = 1;
-
-               return $this->admin;
-       }
-
-       /**
-        * \brief  Set the selected periode in the user's preferences
-        *
-        * \param $p_periode periode
-        * \param     - $p_user
-        *
-        */
-
-       function set_periode($p_periode)
-       {
-               $sql = "update user_local_pref set parameter_value='$p_periode' 
where user_id='$this->id' and parameter_type='PERIODE'";
-               $Res = $this->db->exec_sql($sql);
-       }
-
-       private function set_default_periode()
-       {
-
-               /* get the first periode */
-               $sql = 'select min(p_id) as pid from parm_periode where 
p_closed = false and p_start = (select min(p_start) from parm_periode)';
-               $Res = $this->db->exec_sql($sql);
-
-               $pid = Database::fetch_result($Res, 0, 0);
-               /* if all the periode are closed, then we use the last closed 
period */
-               if ($pid == null)
-               {
-                       $sql = 'select min(p_id) as pid from parm_periode where 
p_start = (select max(p_start) from parm_periode)';
-                       $Res2 = $this->db->exec_sql($sql);
-                       $pid = Database::fetch_result($Res2, 0, 0);
-                       if ($pid == null)
-                       {
-                               throw  new Exception( _("Aucune période 
trouvéee !!!"));
-                       }
-
-                       $pid = Database::fetch_result($Res2, 0, 0);
-               }
-
-               $sql = sprintf("insert into user_local_pref 
(user_id,parameter_value,parameter_type)
-                     values ('%s','%d','PERIODE')", $this->id, $pid);
-               $Res = $this->db->exec_sql($sql);
-       }
-
-       /**
-        * \brief  Get the default periode from the user's preferences
-        *
-        * \return the default periode
-        *
-        *
-        */
-
-       function get_periode()
-       {
-
-               $array = $this->get_preference();
-               if (!isset($array['PERIODE']))
-               {
-                       $this->set_default_periode();
-                       $array = $this->get_preference();
-               }
-               return $array['PERIODE'];
-       }
-
-       /**
-         * 
-         * \brief return the mini rapport to display on the welcome page
-        * \return 0 if nothing if found or the report to display 
(formdef.fr_id)
-        */
-
-       function get_mini_report()
-       {
-               $array = $this->get_preference();
-               $fr_id = (isset($array['MINIREPORT'])) ? $array['MINIREPORT'] : 
0;
-               return $fr_id;
-       }
-
-       /**\brief set the mini rapport to display on the welcome page
-        */
-
-       function set_mini_report($p_id)
-       {
-               $count = $this->db->get_value("select count(*) from 
user_local_pref where user_id=$1 and parameter_type=$2", array($this->id, 
'MINIREPORT'));
-               if ($count == 1)
-               {
-                       $sql = "update user_local_pref set parameter_value=$1 
where user_id=$2 and parameter_type='MINIREPORT'";
-                       $Res = $this->db->exec_sql($sql, array($p_id, 
$this->id));
-               }
-               else
-               {
-                       $sql = "insert into user_local_pref 
(user_id,parameter_type,parameter_value)" .
-                                       "values($1,'MINIREPORT',$2)";
-                       $Res = $this->db->exec_sql($sql, array($this->id, 
$p_id));
-               }
-       }
-        /**
-         * Save the preference , the scope is global, the settings are saved
-         * into account_repository
-         * @param $key THEME,  LANG , PAGESIZE
-         * @param $value value of the key
-         */
-
-       function save_global_preference($key, $value)
-       {
-               $repo = new Database();
-               $count = $repo->get_value("select count(*)
-           from
-           user_global_pref
-           where
-           parameter_type=$1 and user_id=$2", array($key, $this->login));
-               if ($count == 1)
-               {
-                       $repo->exec_sql("update user_global_pref set 
parameter_value=$1
-               where parameter_type=$2 and user_id=$3", array($value, $key, 
$this->login));
-               }
-               elseif ($count == 0)
-               {
-                       $repo->exec_sql("insert into 
user_global_pref(user_id,parameter_type,parameter_value)
-               values($1,$2,$3)", array($this->login, $key, $value));
-               }
-       }
-
-       /**
-        * \brief  Get the default user's preferences
-        * \return array of (parameter_type => parameter_value)
-        */
-
-       function get_preference()
-       {
-               $sql = "select parameter_type,parameter_value from 
user_local_pref where user_id=$1";
-               $Res = $this->db->exec_sql($sql, array($this->id));
-               $l_array = array();
-               for ($i = 0; $i < Database::num_row($Res); $i++)
-               {
-                       $row = Database::fetch_array($Res, $i);
-                       $type = $row['parameter_type'];
-                       $l_array[$type] = $row['parameter_value'];
-               }
-
-
-               return $l_array;
-       }
-
-       /**
-        * Check if an user can access a module, return 1 if yes, otherwise 0
-        * record in audit log
-         * This function works only if user is connected to a Folder
-        * @param string $p_module menu_ref.me_code
-        */
-       function check_module($p_module)
-       {
-               $acc = $this->db->get_value("select count(*) from v_all_menu 
where p_id = $1
-                and me_code=$2", array($this->get_profile(), $p_module));
-               if ($acc == 0)
-               {
-                       $this->audit("FAIL", $p_module);
-                       return 0;
-               }
-               $this->audit("SUCCESS", $p_module);
-               return 1;
-       }
-
-       /**
-        * \brief  Check if an user is allowed to do an action
-        * \param p_action_id
-        * \return
-        *      - 0 no priv
-        *      - 1 priv granted
-        * @see constant.security.php
-        */
-
-       function check_action($p_action_id)
-       {
-               /*  save it into the log */
-               global $audit;
-               if ($this->Admin() == 1)
-                       return 1;
-               if ($this->is_local_admin(dossier::id()) == 1)
-                       return 1;
-
-               $Res = $this->db->exec_sql(
-                               "select * from user_sec_act where ua_login=$1 
and ua_act_id=$2", array($this->login, $p_action_id));
-               $Count = Database::num_row($Res);
-               if ($Count == 0)
-               {
-                       if (isset($audit) && $audit == true)
-                       {
-                               $cn = new Database();
-                               $sql = "insert into audit_connect 
(ac_user,ac_ip,ac_module,ac_url,ac_state) values ($1,$2,$3,$4,$5)";
-                               $cn->exec_sql($sql, array($_SESSION['g_user'], 
$_SERVER["REMOTE_ADDR"], $p_action_id, $_SERVER['REQUEST_URI'], 'FAIL'));
-                       }
-                       return 0;
-               }
-               if ($Count == 1)
-                       return 1;
-               echo "<H2 class=\"error\"> Action Invalide !!! $Count select * 
from user_sec_act where ua_login='$p_login' and ua_act_id=$p_action_id </H2>";
-               exit();
-       }
-
-       /**
-        * \brief  Get the global preferences from user_global_pref
-        *        in the account_repository db
-        *
-        * \note set $SESSION[g_variable]
-        */
-
-       function load_global_pref()
-       {
-               $cn = new Database();
-               // Load everything in an array
-               $Res = $cn->exec_sql("select parameter_type,parameter_value from
-                            user_global_pref
-                            where user_id='" . $this->login . "'");
-               $Max = Database::num_row($Res);
-               if ($Max == 0)
-               {
-                       $this->insert_default_global_pref();
-                       $this->load_global_pref();
-                       return;
-               }
-               // Load value into array
-               $line = array();
-               for ($i = 0; $i < $Max; $i++)
-               {
-                       $row = Database::fetch_array($Res, $i);
-                       $type = $row['parameter_type'];
-                       $line[$type] = $row['parameter_value'];
-                       ;
-               }
-               // save array into g_ variable
-               $array_pref = array('g_theme' => 'THEME', 'g_pagesize' => 
'PAGESIZE', 'g_topmenu' => 'TOPMENU', 'g_lang' => 'LANG');
-               foreach ($array_pref as $name => $parameter)
-               {
-                       if (!isset($line[$parameter]))
-                       {
-                               $this->insert_default_global_pref($parameter);
-                               $this->load_global_pref();
-                               return;
-                       }
-                       $_SESSION[$name] = $line[$parameter];
-               }
-       }
-
-       /**
-        * \brief  insert default pref
-        *        if no parameter are given insert all the existing
-        *        parameter otherwise only the requested
-        * \param $p_type parameter's type or nothing
-        * \param $p_value parameter value
-        *
-        */
-
-       function insert_default_global_pref($p_type = "", $p_value = "")
-       {
-
-               $default_parameter = array("THEME" => "classic",
-                       "PAGESIZE" => "50",
-                       'TOPMENU' => 'TEXT',
-                       'LANG' => 'fr_FR.utf8');
-               $cn = new Database();
-               $Sql = "insert into 
user_global_pref(user_id,parameter_type,parameter_value)
-             values ('%s','%s','%s')";
-               if ($p_type == "")
-               {
-                       foreach ($default_parameter as $name => $value)
-                       {
-                               $Insert = sprintf($Sql, $this->login, $name, 
$value);
-                               $cn->exec_sql($Insert);
-                       }
-               }
-               else
-               {
-                       $value = ($p_value == "") ? $default_parameter[$p_type] 
: $p_value;
-                       $Insert = sprintf($Sql, $this->login, $p_type, $value);
-                       $cn->exec_sql($Insert);
-               }
-       }
-
-       /**
-        * \brief  update default pref
-        *           if value is not given then use the default value
-        *
-        * \param $p_type parameter's type
-        * \param $p_value parameter's value value of the type
-        */
-
-       function update_global_pref($p_type, $p_value = "")
-       {
-               $default_parameter = array("THEME" => "classic",
-                       "PAGESIZE" => "50",
-                       "LANG" => 'fr_FR.utf8',
-                       'TOPMENU' => 'SELECT');
-               $cn = new Database();
-               $Sql = "update user_global_pref set parameter_value=$1
-             where parameter_type=$2 and
-             user_id=$3";
-               $value = ($p_value == "") ? $default_parameter[$p_type] : 
$p_value;
-               $cn->exec_sql($Sql, array($value, $p_type, $this->login));
-       }
-
-//end function
-       /**\brief Return the year of current Periode
-        *        it is the parm_periode.p_exercice col
-        *        if an error occurs return 0
-        */
-
-       function get_exercice()
-       {
-               $sql = "select p_exercice from parm_periode where p_id=" . 
$this->get_periode();
-               $Ret = $this->db->exec_sql($sql);
-               if (Database::num_row($Ret) == 1)
-               {
-                       $r = Database::fetch_array($Ret, 0);
-                       return $r['p_exercice'];
-               }
-               else
-                       return 0;
-       }
-
-       /**\brief Check if the user can access
-        * otherwise warn and exit
-        * \param $p_action requested action
-        * \param $p_js = 1 javascript, or 0 just a text
-        * \return nothing the program exits automatically
-        */
-
-       function can_request($p_action, $p_js = 0)
-       {
-               if ($this->check_action($p_action) == 0)
-               {
-                       $this->audit('FAIL');
-                       if ($p_js == 1)
-                       {
-                               echo "<script>";
-                               echo "alert ('Cette action ne vous est pas 
autorisée. Contactez votre responsable');";
-                               echo "</script>";
-                       }
-                       else
-                       {
-                               echo '<div class="redcontent">';
-                               echo '<h2 class="error"> Cette action ne vous 
est pas autorisée Contactez votre responsable</h2>';
-                               echo '</div>';
-                       }
-                       exit(-1);
-               }
-       }
-
-       /**
-        address@hidden Check if the user can print (in menu_ref 
p_type_display=p)
-        *      otherwise warn and exit
-        * @param $p_action requested action
-        * @return nothing the program exits automatically
-        */
-       function check_print($p_action)
-       {
-               global $audit, $cn;
-               $this->audit('AUDIT', $p_action);
-               if ($this->Admin() == 1)
-                       return 1;
-               
-               $res = $cn->get_value("select count(*) from profile_menu
-                       join profile_user using (p_id)
-                       where user_name=$1 and me_code=$2 ", 
array($this->login, $p_action));
-               return $res;
-       }
-
-       /**\brief Check if the user can print (in menu_ref p_type_display=p)
-        * otherwise warn and exit
-        * \param $p_action requested action
-        * \return nothing the program exits automatically
-        */
-
-       function can_print($p_action, $p_js = 0)
-       {
-               if ($this->check_print($p_action) == 0)
-               {
-                       $this->audit('FAIL');
-                       if ($p_js == 1)
-                       {
-                               echo "<script>";
-                               echo "alert ('Cette action ne vous est pas 
autorisée. Contactez votre responsable');";
-                               echo "</script>";
-                       }
-                       else
-                       {
-                               echo '<div class="redcontent">';
-                               echo '<h2 class="error"> Cette action ne vous 
est pas autorisée Contactez votre responsable</h2>';
-                               echo '</div>';
-                       }
-                       exit(-1);
-               }
-       }
-
-       /**
-        * \brief  Check if an user is an local administrator
-         * @deprecated since version 6.7
-        *
-        *
-        * \param $p_dossier : dossier_id
-        *
-        * \return
-        *      - 0 if no
-        *      - 1 if yes
-        *
-        */
-
-       function is_local_admin($p_dossier = -1)
-       {
-            if ($p_dossier==-1)
-            {
-                $p_dossier=dossier::id();
-            }
-
-            if ($this->login=='admin')
-            {
-                return 1;
-            }
-            else
-            {
-                return 0;
-            }
-        }
-       /**
-        address@hidden return array of available repository
-        *
-        * @param $p_access  R for read W for write
-        * @return an array
-        */
-       function get_available_repository($p_access='R')
-       {
-                $profile=$this->get_profile();
-                $r=array();
-               if ($p_access=='R')
-               {
-                       $r=$this->db->get_array("select distinct u.r_id,r_name
-                from
-                                       profile_sec_repository as u
-                                       join stock_repository as s 
on(u.r_id=s.r_id)
-                where
-                p_id =$1
-                and ur_right='W'
-                               order by 2
-                               ",array($profile));
-               }
-               if ($p_access == 'W')
-               {
-                        $r=$this->db->get_array("select distinct u.r_id,r_name
-                from
-                                       profile_sec_repository as u
-                                       join stock_repository as s 
on(u.r_id=s.r_id)
-                where
-                p_id =$1 order by 2
-               ",array($profile));
-               }
-               return $r;
-       }
-       /**
-        * \brief return an array with all the active users who can access 
-         *  $p_dossier including the global admin. 
-         *  The user must be activated
-        *
-        * \param $p_dossier dossier
-        * \return an array of user's  object
-        *  array indices
-        *    - use_id (id )
-        *    - use_login (login of the user)
-        *    - use_name
-        *    - use_first_name
-        *
-        * \exception throw an exception if nobody can access
-        */
-
-       static function get_list($p_dossier)
-       {
-               $sql = "select distinct 
use_id,use_login,use_first_name,use_name from ac_users
-             left outer join  jnt_use_dos using (use_id)
-             where
-              (dos_id=$1 and use_active=1) or (use_active=1 and use_admin=1)
-              order by use_login,use_name";
-
-
-               $repo = new Database();
-               $array = $repo->get_array($sql, array($p_dossier));
-               if ($repo->size() == 0)
-                       throw new Exception('Error inaccessible folder');
-               return $array;
-       }
-
-       /**
-        * \brief check the access of an user on a ledger
-        *
-        * \param $p_jrn the ledger id
-        * \return
-        * - O only predefined operation
-        * - W write
-        * - R read only
-        * - X no access
-        *
-        */
-
-       function check_jrn($p_jrn)
-       {
-               return $this->get_ledger_access($p_jrn);
-       }
-
-       /**
-         * \brief check if an user can access a folder, if he cannot display a 
dialog box
-        * and exit
-        * \param the folder if
-        * \param $silent false, echo an error message and exit, true : exit 
without warning
-        * default is false
-        * \return
-        *  - L for administrator (local and global)
-        *  - X no access
-        *  - R regular user
-        */
-
-       function check_dossier($p_dossier_id, $silent = false)
-       {
-               $this->Admin();
-               if ($this->admin == 1 || $this->is_local_admin($p_dossier_id) 
== 1)
-                       return 'L';
-               $cn = new Database();
-
-               $dossier = $cn->get_value("select 'R' from jnt_use_dos where 
dos_id=$1 and use_id=$2", array($p_dossier_id, $this->id));
-               $dossier = ($dossier == '') ? 'X' : $dossier;
-               if ($dossier == 'X')
-               {
-                       $this->audit('FAIL', "Access folder ");
-                       if (!$silent)
-                       {
-                               alert(_('Dossier non accessible'));
-                               exit();
-                       }
-               }
-               return $dossier;
-       }
-
-       /**
-        * @brief return the first date and the last date of the current 
exercice for the current user
-        * @return and array ([0] => start_date,[1] => end_date)
-        */
-       function get_limit_current_exercice()
-       {
-               $current_exercice = $this->get_exercice();
-               $periode = new Periode($this->db);
-               list($per_start, $per_end) = 
$periode->get_limit($current_exercice);
-               $start = $per_start->first_day();
-               $end = $per_end->last_day();
-               return array($start, $end);
-       }
-
-       /**
-        * \brief   Show all the available folder  for the users
-        *          at the login page. For the special case 'E'
-        *          go directly to extension and bypasse the dashboard
-        * \param $p_user user
-        * \param $p_admin 1 if admin
-        *
-        * \return table in HTML
-        *
-        */
-
-       function show_dossier($p_filtre = "")
-       {
-               $p_array = $this->get_available_folder($p_filtre);
-
-               $result = "";
-               
-               $result.="<TABLE id=\"folder\" class=\"result\">";
-                $result.="<tr>";
-                $result.="<th>";
-                $result.=_("Id");
-                $result.="</th>";
-                $result.="<th>";
-                $result.=_("Nom");
-                $result.="</th>";
-                $result.="<th>";
-                $result.=_("Description");
-                $result.="</th>";
-                $result.="</tr>";
-                if ($p_array == 0) {
-                    $result.="<tr>";
-                    $result.='<td style="width:auto" colspan=3>';
-                    $result.=_("Aucun dossier disponible");
-                    $result.='</td>';
-                    $result.="</tr>";
-                    return $result;
-                }
-                
-               for ($i = 0; $i < sizeof($p_array); $i++)
-               {
-
-                       $id = $p_array[$i]['dos_id'];
-                       $name = $p_array[$i]['dos_name'];
-                       $desc = $p_array[$i]['dos_description'];
-                       if ($i % 2 == 0)
-                               $tr = "odd";
-                       else
-                               $tr = "even";
-                       $target = "do.php?gDossier=$id";
-
-                       $result.="<TR class=\"$tr\">";
-
-                       $result.=td($id, ' class="num" ');
-                       $result.="<TD class=\"$tr\">";
-                       $result.="<A class=\"dossier\" HREF=\"$target\">";
-                       $result.= "  <B>" . h($name) . "</B>";
-                       $result.="</A>";
-                       $result.="</TD>";
-                       $desc = ($desc == "") ? "<i>Aucune description</i>" : 
h($desc);
-                       $desc = "<A class=\"dossier\" 
HREF=\"$target\">$desc</A>";
-                       $result.="<TD class=\"$tr\" >" . $desc;
-                       $result.="</TD>";
-                       $result.="</TR>";
-               }
-               $result.="</TABLE>";
-               return $result;
-       }
-
-       /**
-        * \brief   Get all the available folders
-        *          for the users, checked with the security
-        *
-        * \param  $p_user user login
-        * \param  $p_admin 1 if admin
-        * \return array containing
-        *       - ac_dossier.dos_id
-        *       - ac_dossier.dos_name
-        *       - ac_dossier.dos_description
-        *
-        */
-
-       function get_available_folder($p_filter = "")
-       {
-               $cn = new Database();
-               $filter = "";
-               if ($this->admin == 0)
-               {
-                       // show only available folders
-                       // if user is not an admin
-                       $Res = $cn->exec_sql("select distinct 
dos_id,dos_name,dos_description 
-                            from ac_users
-                            natural join jnt_use_dos
-                            natural join  ac_dossier
-                            where
-                            use_login= $1
-                            and use_active = 1
-                            and ( dos_name ~* $2 or dos_description ~* $2 )
-                            order by dos_name", array($this->login, 
$p_filter));
-               }
-               else
-               {
-                       $Res = $cn->exec_sql("select distinct 
dos_id,dos_name,dos_description from ac_dossier
-             where   dos_name ~* $1 or dos_description ~* $1 order by 
dos_name", array($p_filter));
-               }
-               require_once NOALYSS_INCLUDE.'/class_database.php';
-
-               $max = Database::num_row($Res);
-               if ($max == 0)
-                       return 0;
-
-               for ($i = 0; $i < $max; $i++)
-               {
-                       $array[] = Database::fetch_array($Res, $i);
-               }
-               return $array;
-       }
-
-       function audit($action = 'AUDIT', $p_module = "")
-       {
-               global $audit;
-               if ($audit)
-               {
-                       if ($p_module == "" && isset($_REQUEST['ac']))
-                       {
-                               $p_module = $_REQUEST['ac'];
-                       }
-                       $cn = new Database();
-                       if (isset($_REQUEST['gDossier']))
-                               $p_module.= " dossier : " . 
$_REQUEST['gDossier'];
-                       $sql = "insert into audit_connect 
(ac_user,ac_ip,ac_module,ac_url,ac_state) values ($1,$2,$3,$4,$5)";
-
-                       $cn->exec_sql($sql, array(
-                               $_SESSION['g_user'],
-                               $_SERVER["REMOTE_ADDR"],
-                               $p_module,
-                               $_SERVER['REQUEST_URI'],
-                               $action));
-               }
-       }
-
-       function save_profile($p_id)
-       {
-               $count = $this->db->get_value("select count(*) from 
profile_user where user_name=$1", array($this->login));
-               if ($count == 0)
-               {
-                       $this->db->exec_sql("insert into 
profile_user(p_id,user_name)
-                                                               values 
($1,$2)", array($p_id, $this->login));
-               }
-               else
-               {
-                       $this->db->exec_sql("update profile_user set p_id=$1 
where user_name=$2", array($p_id, $this->login));
-               }
-       }
-        /**
-         *return the profile (p_id)
-         * @return profile.p_id
-         */
-       function get_profile()
-       {
-               $profile = $this->db->get_value("select p_id from profile_user 
where
-                               lower(user_name)=lower($1)", 
array($this->login));
-               return $profile;
-       }
-        /**
-         * Check if the current user can add an action in the profile given
-         * in parameter
-         * @param type $p_profile profile.p_id = action_gestion.ag_dest
-         * @return boolean
-         */
-        function can_add_action($p_profile)
-        {
-            $r=$this->db->get_value (' select count(*) 
-                from user_sec_action_profile
-                where p_granted=$1
-                and p_id=$2',
-                    array($this->get_profile(),$p_profile));
-            if ($r == 0 ) 
-            {
-                return false;
-            } 
-            return true;
-        }
-        /**
-         *Check if the profile of the user can write for this profile
-         * @param  $dtoc action_gestion.ag_id
-         * @return true if he can write otherwise false
-         */
-       function can_write_action($dtoc)
-       {
-            if ( $this->Admin() == 1 ) return true;
-               $profile = $this->get_profile();
-                    $r = $this->db->get_value(" select count(*) from 
action_gestion where ag_id=$1 and ag_dest in
-                               (select p_granted from user_sec_action_profile 
where ua_right='W' and p_id=$2) ", array($dtoc, $profile));
-               if ($r == 0)
-                       return false;
-               return true;
-       }
-
-        /**
-         *Check if the profile of the user can write for this profile
-         * @param  $dtoc action_gestion.ag_id
-         * @return true if he can write otherwise false
-         */
-       function can_read_action($dtoc)
-       {
-                if ( $this->Admin() == 1 ) return true;
-               $profile = $this->get_profile();
-               $r = $this->db->get_value(" select count(*) from action_gestion 
where ag_id=$1 and (ag_dest in
-                               (select p_granted from user_sec_action_profile 
where p_id=$2) or ag_owner=$3)", array($dtoc, $profile, $this->login));
-               if ($r == 0)
-                       return false;
-               return true;
-       }
-        /**
-         *Check if the profile of the user can write for this repository
-         * @param  $p_repo stock_repository.r_id
-         * @return true if he can write otherwise false
-         */
-        function can_write_repo($p_repo)
-        {
-            if ( $this->Admin() == 1 ) return true;
-            $profile=$this->get_profile();
-            $r=$this->db->get_value("select count(*)
-                from profile_sec_repository
-                where
-                r_id=$1
-                and p_id =$2
-                and ur_right='W'",array($p_repo,$profile));
-            if ( $r==0)
-                return false;
-            return true;
-        }
-       /**
-         *Check if the profile of the user can read for this repository
-         * @param  $p_repo stock_repository.r_id
-         * @return true if he read write otherwise false
-         */
-        function can_read_repo($p_repo)
-        {
-            if ( $this->Admin() == 1 ) return true;
-            $profile=$this->get_profile();
-            $r=$this->db->get_value("select count(*)
-                from profile_sec_repository
-                where
-                r_id=$1
-                and p_id =$2
-               ",array($p_repo,$profile));
-            if ( $r==0)
-                return false;
-            return true;
-        }
-   function save_password($p_pass1, $p_pass2) {
-        if ($p_pass1 == $p_pass2) {
-            $repo = new Database();
-            $l_pass = md5($_POST['pass_1']);
-            $repo->exec_sql("update ac_users set use_pass=$1 where 
use_login=$2", array($l_pass, $_SESSION['g_user']));
-            $_SESSION['g_pass'] = $_POST['pass_1'];
-        } else {
-            alert(_("Les mots de passe ne correspondent pas. Mot de passe 
inchangé"));
-        }
-    }
-    /**
-     * Save the password from PREFERENCE MODULE
-     * @param type $p_email
-     */
-    function save_email($p_email)
-    {
-        $repo=new Database();
-        $repo->exec_sql("update ac_users set use_email=$1 where use_login=$2", 
array($p_email, $_SESSION['g_user']));
-    }
-}
-
-?>
diff --git a/include/company.inc.php b/include/company.inc.php
index ff1152b..ce82c3b 100644
--- a/include/company.inc.php
+++ b/include/company.inc.php
@@ -21,7 +21,7 @@
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
 global $g_user;
 echo '<div class="content">';
-require_once NOALYSS_INCLUDE.'/class_own.php';
+require_once NOALYSS_INCLUDE.'/class/class_own.php';
 if (isset($_POST['record_company']))
 {
        $m = new Own($cn);
diff --git a/include/compta_ach.inc.php b/include/compta_ach.inc.php
index f4f3104..887c217 100644
--- a/include/compta_ach.inc.php
+++ b/include/compta_ach.inc.php
@@ -25,10 +25,10 @@
  * \brief file included to manage all the sold operation
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_icheckbox.php';
-require_once NOALYSS_INCLUDE.'/class_acc_ledger_purchase.php';
-require_once  NOALYSS_INCLUDE.'/class_pre_op_ach.php';
-require_once NOALYSS_INCLUDE.'/class_ipopup.php';
+require_once NOALYSS_INCLUDE.'/lib/class_icheckbox.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_ledger_purchase.php';
+require_once  NOALYSS_INCLUDE.'/class/class_pre_op_ach.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ipopup.php';
 $gDossier = dossier::id();
 global $g_parameter;
 $cn = new Database(dossier::id());
diff --git a/include/compta_fin.inc.php b/include/compta_fin.inc.php
index f818bf5..282d762 100644
--- a/include/compta_fin.inc.php
+++ b/include/compta_fin.inc.php
@@ -23,8 +23,8 @@
  * \brief this file is to be included to handle the financial ledger
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once  NOALYSS_INCLUDE.'/class_acc_ledger_fin.php';
-require_once NOALYSS_INCLUDE.'/class_ipopup.php';
+require_once  NOALYSS_INCLUDE.'/class/class_acc_ledger_fin.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ipopup.php';
 global $g_user,$g_parameter;
 
 $gDossier=dossier::id();
diff --git a/include/compta_fin_rec.inc.php b/include/compta_fin_rec.inc.php
index 080f6f5..687f722 100644
--- a/include/compta_fin_rec.inc.php
+++ b/include/compta_fin_rec.inc.php
@@ -28,7 +28,7 @@
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
 global $g_failed,$g_succeed;
-require_once NOALYSS_INCLUDE.'/class_acc_ledger_fin.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_ledger_fin.php';
 bcscale(2);
 echo '<div class="content">';
 $Ledger = new Acc_Ledger_Fin($cn, 0);
diff --git a/include/compta_fin_saldo.inc.php b/include/compta_fin_saldo.inc.php
index 48e285e..89a2bc4 100644
--- a/include/compta_fin_saldo.inc.php
+++ b/include/compta_fin_saldo.inc.php
@@ -27,7 +27,7 @@
  *
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once  NOALYSS_INCLUDE.'/class_acc_parm_code.php';
+require_once  NOALYSS_INCLUDE.'/class/class_acc_parm_code.php';
     echo '<div class="content">';
     $fiche=new Fiche($cn);
 
diff --git a/include/compta_ods.inc.php b/include/compta_ods.inc.php
index a760c3f..2e4d18c 100644
--- a/include/compta_ods.inc.php
+++ b/include/compta_ods.inc.php
@@ -27,13 +27,13 @@
  *
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_icheckbox.php';
-require_once  NOALYSS_INCLUDE.'/class_acc_ledger.php';
-require_once  NOALYSS_INCLUDE.'/class_acc_reconciliation.php';
-require_once NOALYSS_INCLUDE.'/ac_common.php';
-require_once NOALYSS_INCLUDE.'/class_periode.php';
-require_once NOALYSS_INCLUDE.'/function_javascript.php';
-require_once NOALYSS_INCLUDE.'/class_ipopup.php';
+require_once NOALYSS_INCLUDE.'/lib/class_icheckbox.php';
+require_once  NOALYSS_INCLUDE.'/class/class_acc_ledger.php';
+require_once  NOALYSS_INCLUDE.'/class/class_acc_reconciliation.php';
+require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
+require_once NOALYSS_INCLUDE.'/class/class_periode.php';
+require_once NOALYSS_INCLUDE.'/lib/function_javascript.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ipopup.php';
 
 global $g_user;
 
diff --git a/include/compta_ven.inc.php b/include/compta_ven.inc.php
index 13029b4..fbecc45 100644
--- a/include/compta_ven.inc.php
+++ b/include/compta_ven.inc.php
@@ -23,12 +23,12 @@
  * \brief file included to manage all the sold operation
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_icheckbox.php';
-require_once NOALYSS_INCLUDE.'/class_acc_ledger_sold.php';
-require_once  NOALYSS_INCLUDE.'/class_pre_op_ven.php';
-require_once  NOALYSS_INCLUDE.'/class_document.php';
-require_once  NOALYSS_INCLUDE.'/class_acc_ledger_info.php';
-require_once NOALYSS_INCLUDE.'/class_ipopup.php';
+require_once NOALYSS_INCLUDE.'/lib/class_icheckbox.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_ledger_sold.php';
+require_once  NOALYSS_INCLUDE.'/class/class_pre_op_ven.php';
+require_once  NOALYSS_INCLUDE.'/class/class_document.php';
+require_once  NOALYSS_INCLUDE.'/class/class_acc_ledger_info.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ipopup.php';
 
 $gDossier=dossier::id();
 $cn=new Database(dossier::id());
diff --git a/include/config_file.php b/include/config_file.php
index 11a82f7..432ff9c 100644
--- a/include/config_file.php
+++ b/include/config_file.php
@@ -23,9 +23,9 @@
  * \brief functions concerning the config file config.inc.php. The domain is 
not set into the form for security issues
  */
 
-require_once NOALYSS_INCLUDE.'/class_itext.php';
-require_once NOALYSS_INCLUDE.'/class_iselect.php';
-require_once NOALYSS_INCLUDE.'/class_icheckbox.php';
+require_once NOALYSS_INCLUDE.'/lib/class_itext.php';
+require_once NOALYSS_INCLUDE.'/lib/class_iselect.php';
+require_once NOALYSS_INCLUDE.'/lib/class_icheckbox.php';
 
 function is_unix()
 {
diff --git a/include/contact.inc.php b/include/contact.inc.php
index 832fe00..ab60a05 100644
--- a/include/contact.inc.php
+++ b/include/contact.inc.php
@@ -21,11 +21,11 @@
  * the contact category
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_iselect.php';
-require_once NOALYSS_INCLUDE.'/class_ihidden.php';
-require_once NOALYSS_INCLUDE.'/class_contact.php';
-require_once NOALYSS_INCLUDE.'/class_ibutton.php';
-require_once NOALYSS_INCLUDE.'/class_fiche_def.php';
+require_once NOALYSS_INCLUDE.'/lib/class_iselect.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ihidden.php';
+require_once NOALYSS_INCLUDE.'/class/class_contact.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ibutton.php';
+require_once NOALYSS_INCLUDE.'/class/class_fiche_def.php';
 
 
 
diff --git a/include/customer.inc.php b/include/customer.inc.php
index 66beaed..f082556 100644
--- a/include/customer.inc.php
+++ b/include/customer.inc.php
@@ -22,11 +22,11 @@
  * the customer category
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_iselect.php';
-require_once NOALYSS_INCLUDE.'/class_ihidden.php';
-require_once NOALYSS_INCLUDE.'/class_customer.php';
-require_once NOALYSS_INCLUDE.'/class_ibutton.php';
-require_once NOALYSS_INCLUDE.'/class_fiche_def.php';
+require_once NOALYSS_INCLUDE.'/lib/class_iselect.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ihidden.php';
+require_once NOALYSS_INCLUDE.'/class/class_customer.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ibutton.php';
+require_once NOALYSS_INCLUDE.'/class/class_fiche_def.php';
 
 
 
diff --git a/include/dashboard.inc.php b/include/dashboard.inc.php
index f9d5f44..bd56d91 100644
--- a/include/dashboard.inc.php
+++ b/include/dashboard.inc.php
@@ -1,19 +1,19 @@
 <?php
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_idate.php';
-require_once NOALYSS_INCLUDE.'/class_itext.php';
+require_once NOALYSS_INCLUDE.'/lib/class_idate.php';
+require_once NOALYSS_INCLUDE.'/lib/class_itext.php';
 require_once  NOALYSS_INCLUDE.'/constant.php';
-require_once  NOALYSS_INCLUDE.'/ac_common.php';
-require_once  NOALYSS_INCLUDE.'/class_user.php';
-require_once NOALYSS_INCLUDE.'/class_acc_report.php';
-require_once NOALYSS_INCLUDE.'/class_periode.php';
+require_once  NOALYSS_INCLUDE.'/lib/ac_common.php';
+require_once  NOALYSS_INCLUDE.'/class/class_user.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_report.php';
+require_once NOALYSS_INCLUDE.'/class/class_periode.php';
 require_once  NOALYSS_INCLUDE.'/user_menu.php';
-require_once  NOALYSS_INCLUDE.'/class_dossier.php';
-require_once NOALYSS_INCLUDE.'/class_todo_list.php';
-require_once NOALYSS_INCLUDE.'/class_itextarea.php';
-require_once NOALYSS_INCLUDE.'/class_calendar.php';
-require_once NOALYSS_INCLUDE.'/class_acc_ledger.php';
-require_once NOALYSS_INCLUDE.'/class_follow_up.php';
+require_once  NOALYSS_INCLUDE.'/class/class_dossier.php';
+require_once NOALYSS_INCLUDE.'/class/class_todo_list.php';
+require_once NOALYSS_INCLUDE.'/lib/class_itextarea.php';
+require_once NOALYSS_INCLUDE.'/class/class_calendar.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_ledger.php';
+require_once NOALYSS_INCLUDE.'/class/class_follow_up.php';
 
 echo '<div class="content">';
 global $g_user;
diff --git a/include/database/class_anc_key_sql.php 
b/include/database/class_anc_key_sql.php
new file mode 100644
index 0000000..121284c
--- /dev/null
+++ b/include/database/class_anc_key_sql.php
@@ -0,0 +1,159 @@
+<?php
+
+/*
+ * Copyright (C) 2014 Dany De Bontridder <address@hidden>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+/**
+ * @file
+ * @brief Class to manage distribution keys for SQL.  
+ *
+ */
+require_once NOALYSS_INCLUDE.'/database/class_noalyss_sql.php';
+
+
+/**
+ * @brief Manage the table key_distribution.
+ */
+class Anc_Key_SQL extends Noalyss_SQL
+{
+
+    function __construct($p_cn, $p_id = -1)
+    {
+        $this->table = "public.key_distribution";
+        $this->primary_key = "kd_id";
+
+        $this->name = array(
+            "id" => "kd_id",
+            "name"=>"kd_name",
+            "description"=>"kd_description"
+        );
+
+        $this->type = array(
+            "kd_id" => "numeric",
+            "kd_name" => "text",
+            "kd_description" => "text"
+        );
+
+        $this->default = array(
+            "kd_id" => "auto"
+        );
+       // PHPUNIT seems to have a problem with this line
+       //global $cn;
+
+        parent::__construct($p_cn, $p_id);
+    }
+
+}
+/**
+ * @brief manage table key_distribution_ledger
+ */
+class Anc_Key_Ledger_SQL extends Noalyss_SQL
+{
+       function __construct(&$p_cn, $p_id = -1)
+    {
+        $this->table = "public.key_distribution_ledger";
+        $this->primary_key = "kl_id";
+
+        $this->name = array(
+            "id" => "kl_id",
+            "key"=>"kd_id",
+            "ledger"=>"jrn_def_id"
+        );
+
+        $this->type = array(
+            "kl_id" => "numeric",
+            "kd_id" => "numeric",
+            "jrn_def_id" => "numeric"
+        );
+
+        $this->default = array(
+            "kl_id" => "auto"
+        );
+        // PHPUNIT seems to have a problem with this line
+       //global $cn;
+
+        parent::__construct($p_cn, $p_id);
+    } 
+}
+/**
+ * @brief manage table key_distribution_detail
+ */
+class Anc_Key_Detail_SQL extends Noalyss_SQL
+{
+       function __construct(&$p_cn, $p_id = -1)
+    {
+          
+        $this->table = "public.key_distribution_detail";
+        $this->primary_key = "ke_id";
+
+        $this->name = array(
+            "id" => "ke_id",
+            "key"=>"kd_id",
+            "row"=>"ke_row",
+            "percent"=>"ke_percent"
+        );
+
+        $this->type = array(
+            "ke_id" => "numeric",
+            "kd_id" => "numeric",
+            "ke_row" => "numeric",
+            "ke_percent" => "numeric"
+        );
+
+        $this->default = array(
+            "ke_id" => "auto"
+        );
+       // PHPUNIT seems to have a problem with this line
+       //global $cn;
+       
+
+        parent::__construct($p_cn, $p_id);
+    } 
+}
+/**
+ * @brief manage table key_distribution_activity
+ */
+class Anc_Key_Activity_SQL extends Noalyss_SQL
+{
+       function __construct($p_cn, $p_id = -1)
+    {
+        $this->table = "public.key_distribution_activity";
+        $this->primary_key = "ka_id";
+
+        $this->name = array(
+            "id" => "ka_id",
+            "detail"=>"ke_id",
+            "activity"=>"po_id",
+            "plan"=>"pa_id"
+        );
+
+        $this->type = array(
+            "ka_id" => "numeric",
+            "ke_id" => "numeric",
+            "po_id" => "numeric",
+            "pa_id" => "numeric"
+           
+        );
+
+        $this->default = array(
+            "ka_id" => "auto"
+        );
+
+        parent::__construct($p_cn, $p_id);
+    } 
+}
\ No newline at end of file
diff --git a/include/database/class_default_menu_sql.php 
b/include/database/class_default_menu_sql.php
new file mode 100644
index 0000000..3e96bac
--- /dev/null
+++ b/include/database/class_default_menu_sql.php
@@ -0,0 +1,57 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+// Copyright Author Dany De Bontridder address@hidden
+
+/**
+ * Description of class_default_menu_sql
+ *
+ * @author dany
+ */
+require_once NOALYSS_INCLUDE.'/database/class_noalyss_sql.php';
+
+class Default_Menu_SQL extends Noalyss_SQL
+{
+    var $md_id;
+    var $md_code;
+    var $me_code;
+
+    function __construct(&$p_cn, $p_id = -1)
+    {
+        $this->table = "public.menu_default";
+        $this->primary_key = "md_id";
+
+        $this->name = array(
+            "md_id"=>"md_id",
+            "md_code" => "md_code",
+            "me_code" => "me_code"
+        );
+        $this->type = array(
+            "md_id"=>"md_id"
+            ,"md_code" => "text"
+            , "me_code" => "text"
+        );
+        $this->default = array(
+            "md_id"
+        );
+        global $cn;
+
+        parent::__construct($cn, $p_id);
+    }
+
+}
diff --git a/include/database/class_jrn_def_sql.php 
b/include/database/class_jrn_def_sql.php
new file mode 100644
index 0000000..2ddb98b
--- /dev/null
+++ b/include/database/class_jrn_def_sql.php
@@ -0,0 +1,408 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+// Copyright Author Dany De Bontridder address@hidden
+
+/**
+ * @file
+ * @brief Manage the table public.jrn_def
+ *
+ *
+  Example
+  @code
+
+  @endcode
+ */
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
+
+/**
+ * @brief Manage the table public.jrn_def
+ */
+class Jrn_Def_sql
+{
+       /* example private 
$variable=array("easy_name"=>column_name,"email"=>"column_name_email","val3"=>0);
 */
+
+       protected $variable = array(
+               "jrn_def_id" => "jrn_def_id",
+               "jrn_def_name" => "jrn_def_name"
+               , "jrn_def_class_deb" => "jrn_def_class_deb"
+               , "jrn_def_class_cred" => "jrn_def_class_cred"
+               , "jrn_def_fiche_deb" => "jrn_def_fiche_deb"
+               , "jrn_def_fiche_cred" => "jrn_def_fiche_cred"
+               , "jrn_deb_max_line" => "jrn_deb_max_line"
+               , "jrn_cred_max_line" => "jrn_cred_max_line"
+               , "jrn_def_ech" => "jrn_def_ech"
+               , "jrn_def_ech_lib" => "jrn_def_ech_lib"
+               , "jrn_def_type" => "jrn_def_type"
+               , "jrn_def_code" => "jrn_def_code"
+               , "jrn_def_pj_pref" => "jrn_def_pj_pref"
+               , "jrn_def_bank" => "jrn_def_bank"
+               , "jrn_def_num_op" => "jrn_def_num_op"
+               , "jrn_def_description" => "jrn_def_description"
+       );
+
+       function __construct(& $p_cn, $p_id=-1)
+       {
+               $this->db = $p_cn;
+               $this->jrn_def_id = $p_id;
+
+               if ($p_id == -1)
+               {
+                       /* Initialize an empty object */
+                       foreach ($this->variable as $key => $value)
+                               $this->$value = null;
+                       $this->jrn_def_id = $p_id;
+               }
+               else
+               {
+                       /* load it */
+
+                       $this->load();
+               }
+       }
+
+       public function get_parameter($p_string)
+       {
+               if (array_key_exists($p_string, $this->variable))
+               {
+                       $idx = $this->variable[$p_string];
+                       return $this->$idx;
+               }
+               else
+                       throw new Exception(__FILE__ . ":" . __LINE__ . 
$p_string . 'Erreur attribut inexistant');
+       }
+
+       public function set_parameter($p_string, $p_value)
+       {
+               if (array_key_exists($p_string, $this->variable))
+               {
+                       $idx = $this->variable[$p_string];
+                       $this->$idx = $p_value;
+               }
+               else
+                       throw new Exception(__FILE__ . ":" . __LINE__ . 
$p_string . 'Erreur attribut inexistant');
+       }
+
+       public function get_info()
+       {
+               return var_export($this, true);
+       }
+
+       public function verify_sql()
+       {
+               // Verify that the elt we want to add is correct
+               /* verify only the datatype */
+               if (trim($this->jrn_def_name) == '')
+                       $this->jrn_def_name = null;
+               if (trim($this->jrn_def_class_deb) == '')
+                       $this->jrn_def_class_deb = null;
+               if (trim($this->jrn_def_class_cred) == '')
+                       $this->jrn_def_class_cred = null;
+               if (trim($this->jrn_def_fiche_deb) == '')
+                       $this->jrn_def_fiche_deb = null;
+               if (trim($this->jrn_def_fiche_cred) == '')
+                       $this->jrn_def_fiche_cred = null;
+               if (trim($this->jrn_deb_max_line) == '')
+                       $this->jrn_deb_max_line = null;
+               if ($this->jrn_deb_max_line !== null && 
settype($this->jrn_deb_max_line, 'float') == false)
+                       throw new Exception('DATATYPE jrn_deb_max_line 
$this->jrn_deb_max_line non numerique');
+               if (trim($this->jrn_cred_max_line) == '')
+                       $this->jrn_cred_max_line = null;
+               if ($this->jrn_cred_max_line !== null && 
settype($this->jrn_cred_max_line, 'float') == false)
+                       throw new Exception('DATATYPE jrn_cred_max_line 
$this->jrn_cred_max_line non numerique');
+               if (trim($this->jrn_def_ech) == '')
+                       $this->jrn_def_ech = null;
+               if (trim($this->jrn_def_ech_lib) == '')
+                       $this->jrn_def_ech_lib = null;
+               if (trim($this->jrn_def_type) == '')
+                       $this->jrn_def_type = null;
+               if (trim($this->jrn_def_code) == '')
+                       $this->jrn_def_code = null;
+               if (trim($this->jrn_def_pj_pref) == '')
+                       $this->jrn_def_pj_pref = null;
+               if (trim($this->jrn_def_bank) == '')
+                       $this->jrn_def_bank = null;
+               if ($this->jrn_def_bank !== null && 
settype($this->jrn_def_bank, 'float') == false)
+                       throw new Exception('DATATYPE jrn_def_bank 
$this->jrn_def_bank non numerique');
+               if (trim($this->jrn_def_num_op) == '')
+                       $this->jrn_def_num_op = null;
+               if ($this->jrn_def_num_op !== null && 
settype($this->jrn_def_num_op, 'float') == false)
+                       throw new Exception('DATATYPE jrn_def_num_op 
$this->jrn_def_num_op non numerique');
+       }
+
+       public function save($p_string='')
+       {
+               /* please adapt */
+               if ($this->jrn_def_id == -1)
+                       $this->insert();
+               else
+                       $this->update();
+       }
+
+       /**
+        * @brief retrieve array of object thanks a condition
+        * @param $cond condition (where clause) (optional by default all the 
rows are fetched)
+        * you can use this parameter for the order or subselect
+        * @param $p_array array for the SQL stmt
+        * @see Database::exec_sql get_object  Database::num_row
+        * @return the return value of exec_sql
+        */
+       public function seek($cond='', $p_array=null)
+       {
+               $sql = "select * from public.jrn_def  $cond";
+               $aobj = array();
+               $ret = $this->db->exec_sql($sql, $p_array);
+               return $ret;
+       }
+
+       /**
+        * get_seek return the next object, the return of the query must have 
all the column
+        * of the object
+        * @param $p_ret is the return value of an exec_sql
+        * @param $idx is the index
+        * @see seek
+        * @return object
+        */
+       public function get_object($p_ret, $idx)
+       {
+               // map each row in a object
+               $oobj = new Jrn_Def_sql($this->db);
+               $array = Database::fetch_array($p_ret, $idx);
+               foreach ($array as $idx => $value)
+               {
+                       $oobj->$idx = $value;
+               }
+               return $oobj;
+       }
+
+       public function insert($p_array=null)
+       {
+               if ($this->verify_sql() != 0)
+                       return;
+               if ($this->jrn_def_id == -1)
+               {
+                       /*  please adapt */
+                       $sql = "insert into public.jrn_def(jrn_def_name
+,jrn_def_class_deb
+,jrn_def_class_cred
+,jrn_def_fiche_deb
+,jrn_def_fiche_cred
+,jrn_deb_max_line
+,jrn_cred_max_line
+,jrn_def_ech
+,jrn_def_ech_lib
+,jrn_def_type
+,jrn_def_code
+,jrn_def_pj_pref
+,jrn_def_bank
+,jrn_def_num_op
+,jrn_def_description
+) values ($1
+,$2
+,$3
+,$4
+,$5
+,$6
+,$7
+,$8
+,$9
+,$10
+,$11
+,$12
+,$13
+,$14
+,$15
+) returning jrn_def_id";
+
+                       $this->jrn_def_id = $this->db->get_value(
+                                       $sql, array($this->jrn_def_name
+                               , $this->jrn_def_class_deb
+                               , $this->jrn_def_class_cred
+                               , $this->jrn_def_fiche_deb
+                               , $this->jrn_def_fiche_cred
+                               , $this->jrn_deb_max_line
+                               , $this->jrn_cred_max_line
+                               , $this->jrn_def_ech
+                               , $this->jrn_def_ech_lib
+                               , $this->jrn_def_type
+                               , $this->jrn_def_code
+                               , $this->jrn_def_pj_pref
+                               , $this->jrn_def_bank
+                               , $this->jrn_def_num_op
+                               , strip_tags($this->jrn_def_description)
+                                       )
+                       );
+               }
+               else
+               {
+                       $sql = "insert into public.jrn_def(jrn_def_name
+,jrn_def_class_deb
+,jrn_def_class_cred
+,jrn_def_fiche_deb
+,jrn_def_fiche_cred
+,jrn_deb_max_line
+,jrn_cred_max_line
+,jrn_def_ech
+,jrn_def_ech_lib
+,jrn_def_type
+,jrn_def_code
+,jrn_def_pj_pref
+,jrn_def_bank
+,jrn_def_num_op
+,jrn_def_id
+,jrn_def_description) values ($1
+,$2
+,$3
+,$4
+,$5
+,$6
+,$7
+,$8
+,$9
+,$10
+,$11
+,$12
+,$13
+,$14
+,$15
+,$16
+) returning jrn_def_id";
+
+                       $this->jrn_def_id = $this->db->get_value(
+                                       $sql, array($this->jrn_def_name
+                               , $this->jrn_def_class_deb
+                               , $this->jrn_def_class_cred
+                               , $this->jrn_def_fiche_deb
+                               , $this->jrn_def_fiche_cred
+                               , $this->jrn_deb_max_line
+                               , $this->jrn_cred_max_line
+                               , $this->jrn_def_ech
+                               , $this->jrn_def_ech_lib
+                               , $this->jrn_def_type
+                               , $this->jrn_def_code
+                               , $this->jrn_def_pj_pref
+                               , $this->jrn_def_bank
+                               , $this->jrn_def_num_op
+                               , $this->jrn_def_id
+                                , strip_tags($this->jrn_def_description))
+                       );
+               }
+       }
+
+       public function update($p_string='')
+       {
+               if ($this->verify_sql() != 0)
+                       return;
+               /*   please adapt */
+               $sql = " update public.jrn_def set jrn_def_name = $1
+,jrn_def_class_deb = $2
+,jrn_def_class_cred = $3
+,jrn_def_fiche_deb = $4
+,jrn_def_fiche_cred = $5
+,jrn_deb_max_line = $6
+,jrn_cred_max_line = $7
+,jrn_def_ech = $8
+,jrn_def_ech_lib = $9
+,jrn_def_type = $10
+,jrn_def_code = $11
+,jrn_def_pj_pref = $12
+,jrn_def_bank = $13
+,jrn_def_num_op = $14
+,jrn_def_description = $15
+ where jrn_def_id= $16";
+               $res = $this->db->exec_sql(
+                               $sql, array($this->jrn_def_name
+                       , $this->jrn_def_class_deb
+                       , $this->jrn_def_class_cred
+                       , $this->jrn_def_fiche_deb
+                       , $this->jrn_def_fiche_cred
+                       , $this->jrn_deb_max_line
+                       , $this->jrn_cred_max_line
+                       , $this->jrn_def_ech
+                       , $this->jrn_def_ech_lib
+                       , $this->jrn_def_type
+                       , $this->jrn_def_code
+                       , $this->jrn_def_pj_pref
+                       , $this->jrn_def_bank
+                       , $this->jrn_def_num_op
+                       , strip_tags($this->jrn_def_description)
+                       , $this->jrn_def_id)
+               );
+       }
+
+       /**
+        * @brief load a object
+        * @return 0 on success -1 the object is not found
+        */
+       public function load()
+       {
+
+               $sql = "select jrn_def_name
+,jrn_def_class_deb
+,jrn_def_class_cred
+,jrn_def_fiche_deb
+,jrn_def_fiche_cred
+,jrn_deb_max_line
+,jrn_cred_max_line
+,jrn_def_ech
+,jrn_def_ech_lib
+,jrn_def_type
+,jrn_def_code
+,jrn_def_pj_pref
+,jrn_def_bank
+,jrn_def_num_op
+,jrn_def_description
+ from public.jrn_def where jrn_def_id=$1";
+               /* please adapt */
+               $res = $this->db->get_array(
+                               $sql, array($this->jrn_def_id)
+               );
+
+               if (count($res) == 0)
+               {
+                       /* Initialize an empty object */
+                       foreach ($this->variable as $key => $value)
+                               $this->$key = '';
+
+                       return -1;
+               }
+               foreach ($res[0] as $idx => $value)
+               {
+                       $this->$idx = $value;
+               }
+               return 0;
+       }
+
+       public function delete()
+       {
+               $sql = "delete from public.jrn_def where jrn_def_id=$1";
+               $res = $this->db->exec_sql($sql, array($this->jrn_def_id));
+       }
+
+       /**
+        * Unit test for the class
+        */
+       static function test_me()
+       {
+       }
+
+}
+
+// Jrn_Def_sql::test_me();
+?>
diff --git a/include/database/class_menu_ref_sql.php 
b/include/database/class_menu_ref_sql.php
new file mode 100644
index 0000000..9bd6b19
--- /dev/null
+++ b/include/database/class_menu_ref_sql.php
@@ -0,0 +1,66 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+// Copyright Author Dany De Bontridder address@hidden
+
+/**
+ * @file
+ * @brief Manage the table public.menu_ref
+ *
+ *
+ */
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
+require_once NOALYSS_INCLUDE.'/database/class_noalyss_sql.php';
+
+/**
+ * @brief Manage the table public.menu_ref
+ */
+class Menu_Ref_SQL extends Noalyss_SQL
+{
+    protected  $table="public.menu_ref";
+    protected  $primary_key="me_code";
+    protected $name = array(
+                    "me_code" => "me_code"
+                    , "me_menu" => "me_menu"
+                    , "me_file" => "me_file"
+                    , "me_url" => "me_url"
+                    , "me_description" => "me_description"
+                    , "me_parameter" => "me_parameter"
+                    , "me_javascript" => "me_javascript"
+                    , "me_type" => "me_type"
+                    , 'me_description_etendue'=>'me_description_etendue'
+            );
+    protected $type=array(
+                    "me_code" => "text"
+                    , "me_menu" => "text"
+                    , "me_file" => "text"
+                    , "me_url" => "text"
+                    , "me_description" => "text"
+                    , "me_parameter" => "text"
+                    , "me_javascript" => "text"
+                    , "me_type" => "text"
+                    ,"me_description_etendue"=>"text"
+            );
+    function __construct(Database &$p_cn,$p_id=-1)
+    {
+        parent::__construct($p_cn,$p_id);
+    }
+
+}
+?>
diff --git a/include/class_noalyss_sql.php 
b/include/database/class_noalyss_sql.php
similarity index 100%
rename from include/class_noalyss_sql.php
rename to include/database/class_noalyss_sql.php
diff --git a/include/database/class_profile_menu_sql.php 
b/include/database/class_profile_menu_sql.php
new file mode 100644
index 0000000..7b8006b
--- /dev/null
+++ b/include/database/class_profile_menu_sql.php
@@ -0,0 +1,76 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+// Copyright Author Dany De Bontridder address@hidden
+/**
+ * @file
+ * @brief Manage the table public.profile_menu
+ *
+ *
+  Example
+  @code
+
+  @endcode
+ */
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
+require_once NOALYSS_INCLUDE.'/database/class_noalyss_sql.php';
+
+/**
+ * @brief Manage the table public.profile_menu
+ */
+class Profile_Menu_sql extends Noalyss_SQL
+{
+
+    function __construct(&$p_cn,$p_id=-1)
+    {
+        $this->table="public.profile_menu";
+        $this->primary_key="pm_id";
+
+        $this->name=array(
+            "pm_id"=>"pm_id", "me_code"=>"me_code"
+            , "me_code_dep"=>"me_code_dep"
+            , "p_id"=>"p_id"
+            , "p_order"=>"p_order"
+            , "p_type_display"=>"p_type_display"
+            , "pm_default"=>"pm_default"
+            ,"pm_id_dep"=>"pm_id_dep"
+        );
+
+        $this->type=array(
+            "pm_id"=>"number",
+            "me_code"=>"text"
+            , "me_code_dep"=>"text"
+            , "p_id"=>"number"
+            , "p_order"=>"number"
+            , "p_type_display"=>"text"
+            , "pm_default"=>"text"
+            , "pm_id_dep"=>"number"
+        );
+
+        $this->default=array(
+            "pm_id"=>"auto"
+        );
+
+        parent::__construct($p_cn, $p_id);
+    }
+
+}
+
+?>
diff --git a/include/database/class_profile_sql.php 
b/include/database/class_profile_sql.php
new file mode 100644
index 0000000..82d14fc
--- /dev/null
+++ b/include/database/class_profile_sql.php
@@ -0,0 +1,72 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+// Copyright Author Dany De Bontridder address@hidden
+
+/**
+ * @file
+ * @brief Manage the table public.profile
+ *
+ *
+  Example
+  @code
+
+  @endcode
+ */
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
+require_once NOALYSS_INCLUDE.'/database/class_noalyss_sql.php';
+
+/**
+ * @brief Manage the table public.profile
+ */
+class Profile_sql extends Noalyss_SQL
+{
+       /* example private 
$variable=array("easy_name"=>column_name,"email"=>"column_name_email","val3"=>0);
 */
+
+       function __construct(& $p_cn, $p_id = -1)
+       {
+               $this->table = "public.profile";
+               $this->primary_key = "p_id";
+
+               $this->name = array(
+                       "p_id" => "p_id"
+                       , "p_name" => "p_name"
+                       , "p_desc" => "p_desc"
+                       , "with_calc" => "with_calc"
+                       , "with_direct_form" => "with_direct_form"
+               );
+               $this->type = array(
+                       "p_id" => "numeric"
+                       , "p_name" => "text"
+                       , "p_desc" => "text"
+                       , "with_calc" => "text"
+                       , "with_direct_form" => "text"
+               );
+               $this->default = array(
+                       "p_id" => "auto",
+               );
+
+               parent::__construct($p_cn,$p_id);
+
+       }
+
+}
+
+// Profile_sql::test_me();
+?>
diff --git a/include/database/class_stock_goods_sql.php 
b/include/database/class_stock_goods_sql.php
new file mode 100644
index 0000000..6c5925b
--- /dev/null
+++ b/include/database/class_stock_goods_sql.php
@@ -0,0 +1,120 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/**
+ * @file
+ * @brief
+ *
+ */
+require_once NOALYSS_INCLUDE.'/database/class_noalyss_sql.php';
+
+class Stock_Goods_Sql extends Noalyss_SQL
+{
+
+       function __construct($cn,$p_id = -1)
+       {
+               $this->table = "public.stock_goods";
+               $this->primary_key = "sg_id";
+               $this->date_format="DD.MM.YYYY";
+
+               $this->name = array(
+                       "sg_id" => "sg_id",
+                       "j_id" => "j_id",
+                       "f_id" => "f_id",
+                       "sg_code" => "sg_code",
+                       "sg_quantity" => "sg_quantity",
+                       "sg_type" => "sg_type",
+                       "sg_date" => "sg_date",
+                       "sg_tech_date" => "sg_tech_date",
+                       "sg_tech_user" => "sg_tech_user",
+                       "sg_comment" => "sg_comment",
+                       "sg_exercice" => "sg_exercice",
+                       "r_id" => "r_id",
+                       "c_id"=>"c_id"
+               );
+
+               $this->type = array(
+                       "sg_id" => "numeric",
+                       "j_id" => "numeric",
+                       "f_id" => "numeric",
+                       "sg_code" => "text",
+                       "sg_quantity" => "text",
+                       "sg_type" => "text",
+                       "sg_date" => "date",
+                       "sg_tech_date" => "date",
+                       "sg_tech_user" => "text",
+                       "sg_comment" => "text",
+                       "sg_exercice" => "sg_exercice",
+                       "r_id" => "numeric",
+                       "c_id" => "numeric"
+
+               );
+
+               $this->default = array(
+                       "sg_id" => "auto",
+                       "sg_tech_date" => "auto",
+                       "sg_user" => "auto"
+               );
+               global $cn;
+
+               parent::__construct($cn, $p_id);
+       }
+
+}
+
+class Stock_Change_Sql extends Noalyss_SQL
+{
+
+       function __construct($cn,$p_id = -1)
+       {
+               $this->date_format="DD.MM.YYYY";
+               $this->table = "public.stock_change";
+               $this->primary_key = "c_id";
+
+               $this->name = array(
+                       "id" => "c_id",
+                       "c_comment" => "c_comment",
+                       "c_date" => "c_date",
+                       "tech_date"=>"tech_date",
+                       "tech_user"=>"tech_user",
+                       "r_id"=>"r_id"
+               );
+
+               $this->type = array(
+                       "c_id" => "numeric",
+                       "c_comment" => "text",
+                       "c_date" => "date",
+                       "tech_date"=>"date",
+                       "tech_user"=>"text",
+                       "r_id"=>"numeric"
+               );
+
+               $this->default = array(
+                       "c_id" => "auto",
+                       "tech_date" => "auto"
+               );
+               global $cn;
+
+               parent::__construct($cn, $p_id);
+       }
+}
+?>
diff --git a/include/database/class_stock_sql.php 
b/include/database/class_stock_sql.php
new file mode 100644
index 0000000..c227b78
--- /dev/null
+++ b/include/database/class_stock_sql.php
@@ -0,0 +1,63 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/**
+ * @file
+ * @brief
+ *
+ */
+require_once NOALYSS_INCLUDE.'/database/class_noalyss_sql.php';
+
+class Stock_Sql extends Noalyss_SQL {
+       function __construct($cn,$p_id=-1)
+       {
+               $this->table = "public.stock_repository";
+               $this->primary_key = "r_id";
+
+               $this->name=array(
+                       "id"=>"r_id",
+                       "name"=>"r_name",
+                       "adress"=>"r_adress",
+                       "city"=>"r_city",
+                       "country"=>"r_country",
+                       "phone"=>"r_phone"
+               );
+
+               $this->type = array(
+                       "r_id"=>"numeric",
+                       "r_name"=>"text",
+                       "r_adress"=>"text",
+                       "r_city"=>"text",
+                       "r_country"=>"text",
+                       "r_phone"=>"text"
+
+                       );
+
+               $this->default = array(
+                       "r_id" => "auto",
+               );
+               global $cn;
+
+               parent::__construct($cn,$p_id);
+       }
+}
+?>
diff --git a/include/database/class_tag_sql.php 
b/include/database/class_tag_sql.php
new file mode 100644
index 0000000..191ead8
--- /dev/null
+++ b/include/database/class_tag_sql.php
@@ -0,0 +1,54 @@
+<?php
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
+require_once NOALYSS_INCLUDE.'/database/class_noalyss_sql.php';
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+// Copyright Author Dany De Bontridder address@hidden
+/**
+ * @brief Manage the table public.tag
+ */
+class Tag_SQL extends Noalyss_SQL
+{
+       /* example private 
$variable=array("easy_name"=>column_name,"email"=>"column_name_email","val3"=>0);
 */
+
+       function __construct(& $p_cn, $p_id = -1)
+       {
+               $this->table = "public.tags";
+               $this->primary_key = "t_id";
+
+               $this->name = array(
+                       "t_id" => "t_id"
+                       , "t_tag" => "t_tag"
+                       , "t_description" => "t_description"
+                    );
+               $this->type = array(
+                       "t_id" => "numeric"
+                       , "t_tag" => "text"
+                       , "t_description" => "text"
+               );
+               $this->default = array(
+                       "t_id" => "auto",
+               );
+
+               parent::__construct($p_cn,$p_id);
+
+       }
+
+}
+?>
diff --git a/include/default_menu.inc.php b/include/default_menu.inc.php
index 0813c92..ff01e1c 100644
--- a/include/default_menu.inc.php
+++ b/include/default_menu.inc.php
@@ -19,7 +19,7 @@
 // Copyright Author Dany De Bontridder address@hidden
 
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_default_menu.php';
+require_once NOALYSS_INCLUDE.'/class/class_default_menu.php';
 
 global $cn,$g_failed,$g_succeed;
 
diff --git a/include/document_modele.inc.php b/include/document_modele.inc.php
index 3859dc3..20f85a4 100644
--- a/include/document_modele.inc.php
+++ b/include/document_modele.inc.php
@@ -22,7 +22,7 @@
  */
 
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_document_modele.php';
+require_once NOALYSS_INCLUDE.'/class/class_document_modele.php';
 $sub_action=(isset ($_REQUEST['sa']))?$_REQUEST['sa']:"";
 echo js_include('modele_document.js');
 echo '<div class="content">';
@@ -35,7 +35,7 @@ $doc=new Document_modele($cn);
 //-----------------------------------------------------
 if ( $sub_action=='add_document')
 {
-    require_once NOALYSS_INCLUDE.'/class_document_modele.php';
+    require_once NOALYSS_INCLUDE.'/class/class_document_modele.php';
     $doc=new Document_modele($cn);
     $doc->md_name=$_POST['md_name'];
     $doc->md_id=-1; // because it is a new model
@@ -49,7 +49,7 @@ if ( $sub_action=='add_document')
 //-----------------------------------------------------
 if ( $sub_action=='rm_template')
 {
-    require_once NOALYSS_INCLUDE.'/class_document_modele.php';
+    require_once NOALYSS_INCLUDE.'/class/class_document_modele.php';
     // Get all the document to remove
 
     foreach ( $_POST as $name=>$value )
@@ -68,7 +68,7 @@ if ( $sub_action=='rm_template')
 //----------------------------------------------------------------------
 if ( $sub_action == 'mod_template')
   {
-    require_once NOALYSS_INCLUDE.'/class_document_modele.php';
+    require_once NOALYSS_INCLUDE.'/class/class_document_modele.php';
     $doc=new Document_modele($cn,$_POST['id']);
     $doc->update($_POST);
   }
diff --git a/include/dossier.inc.php b/include/dossier.inc.php
index f1d9bd7..569bacb 100644
--- a/include/dossier.inc.php
+++ b/include/dossier.inc.php
@@ -23,10 +23,10 @@ if ( !defined ('ALLOWED')) die('Forbidden');
 * \brief Management of the folder
  *
  */
-require_once NOALYSS_INCLUDE.'/class_itext.php';
-require_once NOALYSS_INCLUDE.'/class_icheckbox.php';
-require_once NOALYSS_INCLUDE.'/class_itextarea.php';
-require_once NOALYSS_INCLUDE.'/class_html_input.php';
+require_once NOALYSS_INCLUDE.'/lib/class_itext.php';
+require_once NOALYSS_INCLUDE.'/lib/class_icheckbox.php';
+require_once NOALYSS_INCLUDE.'/lib/class_itextarea.php';
+require_once NOALYSS_INCLUDE.'/lib/class_html_input.php';
 
 $sa=(isset($_REQUEST['sa']))?$_REQUEST['sa']:'list';
 //---------------------------------------------------------------------------
@@ -208,7 +208,7 @@ if ( isset ($_POST["DATABASE"]) )
 // List of folder
 if ( $sa == 'list' )
 {
-       require_once NOALYSS_INCLUDE.'/class_sort_table.php';
+       require_once NOALYSS_INCLUDE.'/lib/class_sort_table.php';
         echo '<p>';
         echo HtmlInput::button(_('Ajouter'),_('Ajouter un dossier')," 
onclick=\$('folder_add_id').show()");
         echo '</p>';
diff --git a/include/export/export_anc_acc_list_csv.php 
b/include/export/export_anc_acc_list_csv.php
new file mode 100644
index 0000000..3269007
--- /dev/null
+++ b/include/export/export_anc_acc_list_csv.php
@@ -0,0 +1,36 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+* \brief  export analytic list in csv
+ *
+ */
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+header('Pragma: public');
+header('Content-type: application/csv');
+header('Content-Disposition: attachment;filename="export-anc-list.csv"',FALSE);
+
+require_once  NOALYSS_INCLUDE.'/class/class_anc_acc_list.php';
+
+
+$bal=new Anc_Acc_List($cn);
+$bal->get_request();
+echo $bal->export_csv();
diff --git a/include/export/export_anc_balance_double_csv.php 
b/include/export/export_anc_balance_double_csv.php
new file mode 100644
index 0000000..4364c45
--- /dev/null
+++ b/include/export/export_anc_balance_double_csv.php
@@ -0,0 +1,40 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief  export the operation in pdf
+ */
+
+/* \brief  export the operation in pdf
+ *
+ */
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+header('Content-type: application/csv');
+header('Pragma: public');
+header('Content-Disposition: attachment;filename="ca_bal_croise.csv"',FALSE);
+
+require_once  NOALYSS_INCLUDE.'/class/class_anc_balance_double.php';
+
+$cn=new Database(dossier::id());
+
+$bal=new Anc_Balance_Double($cn);
+$bal->get_request();
+echo $bal->display_csv();
diff --git a/include/export/export_anc_balance_double_pdf.php 
b/include/export/export_anc_balance_double_pdf.php
new file mode 100644
index 0000000..6c3e166
--- /dev/null
+++ b/include/export/export_anc_balance_double_pdf.php
@@ -0,0 +1,37 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief export the operation in pdf
+ */
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+require_once  NOALYSS_INCLUDE.'/class/class_anc_balance_double.php';
+require_once  NOALYSS_INCLUDE.'/header_print.php';
+
+$cn=new Database(dossier::id());
+
+
+$balance=new Anc_Balance_Double($cn);
+
+$balance->get_request();
+
+$balance->display_pdf();
+
diff --git a/include/export/export_anc_balance_group_csv.php 
b/include/export/export_anc_balance_group_csv.php
new file mode 100644
index 0000000..611df20
--- /dev/null
+++ b/include/export/export_anc_balance_group_csv.php
@@ -0,0 +1,35 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief export balance by group
+ */
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+require_once NOALYSS_INCLUDE.'/class/class_anc_group.php';
+
+header('Pragma: public');
+header('Content-type: application/csv'); 
+header('Content-Disposition: 
attachment;filename="anc-balance-group-export.csv"',FALSE);
+
+$a=new Anc_Group($cn);
+$a->get_request();
+$a->export_csv();
+?>
\ No newline at end of file
diff --git a/include/export/export_anc_balance_simple_csv.php 
b/include/export/export_anc_balance_simple_csv.php
new file mode 100644
index 0000000..6a09602
--- /dev/null
+++ b/include/export/export_anc_balance_simple_csv.php
@@ -0,0 +1,36 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+* \brief  export the operation in pdf
+ */
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+header('Pragma: public');
+header('Content-type: application/csv');
+header('Content-Disposition: attachment;filename="ca_bal_simple.csv"',FALSE);
+
+require_once  NOALYSS_INCLUDE.'/class/class_anc_balance_simple.php';
+
+$cn=new Database(dossier::id());
+
+$bal=new Anc_Balance_Simple($cn);
+$bal->get_request();
+echo $bal->display_csv();
diff --git a/include/export/export_anc_balance_simple_pdf.php 
b/include/export/export_anc_balance_simple_pdf.php
new file mode 100644
index 0000000..66fde7e
--- /dev/null
+++ b/include/export/export_anc_balance_simple_pdf.php
@@ -0,0 +1,35 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief export the operation in pdf
+ *
+ */
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+require_once  NOALYSS_INCLUDE.'/class/class_anc_balance_simple.php';
+
+$cn=new Database(dossier::id());
+
+$balance=new Anc_Balance_Simple($cn);
+
+$balance->get_request();
+$balance->display_pdf();
+?>
diff --git a/include/export/export_anc_grandlivre_csv.php 
b/include/export/export_anc_grandlivre_csv.php
new file mode 100644
index 0000000..c5564b1
--- /dev/null
+++ b/include/export/export_anc_grandlivre_csv.php
@@ -0,0 +1,37 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+// Copyright Author Dany De Bontridder address@hidden
+
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+header('Pragma: public');
+header('Content-type: application/csv');
+header('Content-Disposition: attachment;filename="anc-grand-livre.csv"',FALSE);
+
+require_once NOALYSS_INCLUDE.'/class/class_anc_grandlivre.php';
+
+$cn=Dossier::connect();
+
+$gl=new Anc_GrandLivre($cn);
+$gl->get_request();
+echo $gl->display_csv();
+
+
+
+
+?>
diff --git a/include/export/export_anc_list_csv.php 
b/include/export/export_anc_list_csv.php
new file mode 100644
index 0000000..f88d6c8
--- /dev/null
+++ b/include/export/export_anc_list_csv.php
@@ -0,0 +1,37 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+* \brief  export the operation in pdf
+ *
+ */
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+header('Pragma: public');
+header('Content-type: application/csv');
+header('Content-Disposition: attachment;filename="jrn.csv"',FALSE);
+
+require_once  NOALYSS_INCLUDE.'/class/class_anc_listing.php';
+
+$cn=new Database(dossier::id());
+
+$bal=new Anc_Listing($cn);
+$bal->get_request();
+echo $bal->display_csv();
diff --git a/include/export/export_anc_receipt_pdf.php 
b/include/export/export_anc_receipt_pdf.php
new file mode 100644
index 0000000..88b642f
--- /dev/null
+++ b/include/export/export_anc_receipt_pdf.php
@@ -0,0 +1,40 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+// Copyright Author Dany De Bontridder address@hidden
+// Copyright Author Dany De Bontridder address@hidden
+if (!defined('ALLOWED'))
+    die('Appel direct ne sont pas permis');
+
+
+/**
+ * export all the selected documents for Ana Accountancy in PDF
+ */
+require_once NOALYSS_INCLUDE.'/class/class_document_export.php';
+
+$ck = HtmlInput::default_value_get('ck', 0);
+if ($ck == 0)
+{
+    echo "Aucune sélection";
+    exit();
+}
+$anc=new Document_Export();
+
+$anc->export_all($ck);
diff --git a/include/export/export_anc_table_csv.php 
b/include/export/export_anc_table_csv.php
new file mode 100644
index 0000000..cbf064b
--- /dev/null
+++ b/include/export/export_anc_table_csv.php
@@ -0,0 +1,34 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief export the anc tables in CSV
+ */
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+header('Pragma: public');
+header('Content-type: application/csv'); 
+header('Content-Disposition: 
attachment;filename="anc-table-export.csv"',FALSE);
+
+require_once NOALYSS_INCLUDE.'/class/class_anc_table.php';
+$atable=new Anc_Table($cn);
+$atable->get_request();
+$atable->export_csv();
+?>
\ No newline at end of file
diff --git a/include/export/export_balance_age_csv.php 
b/include/export/export_balance_age_csv.php
new file mode 100644
index 0000000..023dd47
--- /dev/null
+++ b/include/export/export_balance_age_csv.php
@@ -0,0 +1,88 @@
+<?php
+
+/*
+ *   This file is part of PhpCompta.
+ *
+ *   PhpCompta is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   PhpCompta is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with PhpCompta; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+// Copyright (2014) Author Dany De Bontridder <address@hidden>
+
+if (!defined('ALLOWED'))
+    die('Appel direct ne sont pas permis');
+require 'class/class_balance_age.php';
+header('Pragma: public');
+header('Content-type: application/csv');
+header('Content-Disposition: attachment;filename="balance_age.csv"',FALSE);
+/**
+ * @file
+ * @brief Export an ageing balance
+ * @param p_date_start considered writing after this date
+ * @param p_let lettered or not value (all): let or  only unlettered 
value:unlet
+ * @param p_type
+ *  - C customer
+ *  - F supplier
+ *  - U only a card 
+ *  - X a category 
+ * @param cat only if p_type = X it that case contains the category id 
(fiche_def.fd_id)
+ * @param fiche only if p_type = U in that case contains the card id 
(fiche.f_id)
+ * @param all Ony with p_type = X all the customer / supplier cards
+ */
+/*
+ * Retrieve card
+ */
+$bal=new Balance_Age($cn);
+$p_type = HtmlInput::default_value_get('p_type', "-");
+$p_date= HtmlInput::default_value_get('p_date_start', "-");
+$p_let= HtmlInput::default_value_get('p_let', "let");
+$cat= HtmlInput::default_value_get('cat', "");
+$fiche= HtmlInput::default_value_get('fiche', "0");
+$all= HtmlInput::default_value_get('all', "0");
+switch ($p_type)
+{
+    case 'C':
+        $bal->get_array_card('C');
+        $bal->export_csv($p_date, $p_let);
+        break;
+    case 'F':
+        $bal->get_array_card('F');
+        $bal->export_csv($p_date, $p_let);
+        break;
+    case 'U':
+        $bal->get_array_card('U', $fiche);
+        $bal->export_csv($p_date, $p_let);
+        break;
+    case 'X':
+        $all=HtmlInput::default_value_get('all', 0);
+        if ($all==0)
+        {
+            $bal->get_array_card('X', $_GET['cat']);
+            $bal->export_csv($p_date, $p_let);
+        }
+        else
+        {
+            $a_cat=$cn->get_array("select fd_id from vw_fiche_def where 
ad_id=".ATTR_DEF_ACCOUNT." order by fd_label asc");
+            $nb_cat=count($a_cat);
+            for ($i=0; $i<$nb_cat; $i++)
+            {
+                $bal->get_array_card('X', $a_cat[$i]['fd_id']);
+                $bal->export_csv($p_date, $p_let);
+            }
+        }
+        break;
+
+    default:
+        break;
+}
+?>
diff --git a/include/export/export_balance_csv.php 
b/include/export/export_balance_csv.php
new file mode 100644
index 0000000..9ae545e
--- /dev/null
+++ b/include/export/export_balance_csv.php
@@ -0,0 +1,103 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+// Copyright Author Dany De Bontridder address@hidden
+/*! \file
+ * \brief Return the balance in CSV format
+ */
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+header('Pragma: public');
+header('Content-type: application/csv');
+header('Content-Disposition: attachment;filename="balance.csv"',FALSE);
+include_once ("lib/ac_common.php");
+include_once("class/class_acc_balance.php");
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+$gDossier=dossier::id();
+
+require_once NOALYSS_INCLUDE.'/class/class_acc_ledger.php';
+$cn=new Database($gDossier);
+bcscale(2);
+
+require_once  NOALYSS_INCLUDE.'/class/class_user.php';
+
+$bal=new Acc_Balance($cn);
+$bal->jrn=null;
+switch( $_GET['p_filter'])
+{
+case 0:
+        $bal->jrn=null;
+    break;
+case 1:
+    if (  isset($_GET['r_jrn']))
+    {
+        $selected=$_GET['r_jrn'];
+        $array_ledger=$g_user->get_ledger('ALL',3);
+        $array=get_array_column($array_ledger,'jrn_def_id');
+        for ($e=0;$e<count($selected);$e++)
+        {
+            if (isset ($selected[$e]) && in_array ($selected[$e],$array) )
+                $bal->jrn[]=$selected[$e];
+        }
+    }
+    break;
+case 2:
+    if ( isset($_GET['r_cat']))   $bal->filter_cat($_GET['r_cat']);
+    break;
+}
+
+$bal->from_poste=$_GET['from_poste'];
+$bal->to_poste=$_GET['to_poste'];
+if (isset($_GET['unsold'])) $bal->unsold=true;
+$prev = (isset($_GET['previous_exc'])) ? 1: 0;
+
+$row=$bal->get_row($_GET['from_periode'],
+                   $_GET['to_periode'],
+        $prev);
+$prev =  ( isset ($row[0]['sum_cred_previous'])) ?1:0;
+echo 'poste;libelle;';
+if ($prev  == 1 ) echo 'deb n-1;cred n-1;solde n-1;d/c;';
+echo 'deb;cred;solde;d/c';
+printf("\n");
+foreach ($row as $r)
+{
+    echo $r['poste'].';'.
+    $r['label'].';';
+    if ( $prev == 1 )
+    {
+        $delta=bcsub($r['solde_deb_previous'],$r['solde_cred_previous']);
+        $sign=($delta<0)?'C':'D';
+        $sign=($delta == 0)?'=':$sign;
+        echo  nb($r['sum_deb_previous']).';'.
+        nb($r['sum_cred_previous']).';'.
+        nb(abs($delta)).';'.
+        "$sign".';';
+       
+    }
+    $delta=bcsub($r['solde_deb'],$r['solde_cred']);
+    $sign=($delta<0)?'C':'D';
+    $sign=($delta == 0)?'=':$sign;
+    echo nb($r['sum_deb']).';'.
+    nb($r['sum_cred']).';'.
+    nb(abs($delta)).';'.
+    "$sign";
+    printf("\n");
+}
+
+
+?>
diff --git a/include/export/export_balance_pdf.php 
b/include/export/export_balance_pdf.php
new file mode 100644
index 0000000..b1c84c6
--- /dev/null
+++ b/include/export/export_balance_pdf.php
@@ -0,0 +1,284 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/*! \file
+ * \brief Print the balance in pdf format
+ * \param received parameters
+ * \param e_date element 01.01.2003
+ * \param e_client element 3
+ * \param nb_item element 2
+ * \param e_march0 element 11
+ * \param e_quant0 element 1
+ * \param e_march1 element 6
+ * \param e_quant1 element 2
+ * \param e_comment  invoice number
+ */
+// Copyright Author Dany De Bontridder address@hidden
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+include_once("lib/ac_common.php");
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+include_once("class/class_acc_balance.php");
+require_once  NOALYSS_INCLUDE.'/header_print.php';
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+require_once NOALYSS_INCLUDE.'/lib/lib/class_pdf.php';
+$gDossier=dossier::id();
+bcscale(4);
+$cn=new Database($gDossier);
+$rep=new Database();
+require_once  NOALYSS_INCLUDE.'/class/class_user.php';
+$g_user->Check();
+
+$bal=new Acc_Balance($cn);
+
+extract ($_GET);
+$bal->jrn=null;
+switch( $_GET['p_filter'])
+{
+case 0:
+        $bal->jrn=null;
+    break;
+case 1:
+    if (  isset($_GET['r_jrn']))
+    {
+        $selected=$_GET['r_jrn'];
+        $array_ledger=$g_user->get_ledger('ALL',3);
+        $array=get_array_column($array_ledger,'jrn_def_id');
+        for ($e=0;$e<count($selected);$e++)
+        {
+            if (isset ($selected[$e]) && in_array ($selected[$e],$array))
+                $bal->jrn[]=$selected[$e];
+        }
+    }
+    break;
+case 2:
+    if ( isset($_GET['r_cat']))   $bal->filter_cat($_GET['r_cat']);
+    break;
+}
+
+$bal->from_poste=$_GET['from_poste'];
+$bal->to_poste=$_GET['to_poste'];
+if (isset($_GET['unsold'])) $bal->unsold=true;
+$previous=(isset($_GET['previous_exc']))?1:0;
+  
+$array=$bal->get_row($from_periode,$to_periode,$previous);
+
+$previous= (isset ($array[0]['sum_cred_previous']))?1:0;
+
+
+if ( sizeof($array)  == 0 )
+{
+    exit();
+
+}
+
+$pPeriode=new Periode($cn);
+$a=$pPeriode->get_date_limit($from_periode);
+$b=$pPeriode->get_date_limit($to_periode);
+$per_text="  du ".$a['p_start']." au ".$b['p_end'];
+if ($previous == 1 ) {
+    $pdf=new PDFLand($cn);
+} else {
+    $pdf= new PDF($cn);
+}
+$pdf->setDossierInfo(" Balance  ".$per_text);
+$pdf->AliasNbPages();
+$pdf->AddPage();
+$pdf->SetAuthor('NOALYSS');
+$pdf->SetFont('DejaVuCond','',7);
+$pdf->setTitle("Balance comptable",true);
+$pdf->Cell(30,6,'poste');
+$pdf->LongLine(60,6,'Libellé');
+if ($previous == 1 ){ 
+    $pdf->Cell(20,6,'Débit N-1',0,0,'R');
+    $pdf->Cell(20,6,'Crédit N-1',0,0,'R');
+    $pdf->Cell(20,6,'Débiteur N-1',0,0,'R');
+    $pdf->Cell(20,6,'Créditeur N-1',0,0,'R');
+}
+$pdf->Cell(25,6,'Total Débit',0,0,'R');
+$pdf->Cell(25,6,'Total Crédit',0,0,'R');
+$pdf->Cell(25,6,'Solde Débiteur',0,0,'R');
+$pdf->Cell(25,6,'Solde Créditeur',0,0,'R');
+$pdf->Ln();
+
+$pdf->SetFont('DejaVuCond','',8);
+$tp_deb=0;
+$tp_cred=0;
+$tp_sold=0;
+$tp_solc=0;
+$tp_deb_previous=0;
+$tp_cred_previous=0;
+$tp_sold_previous=0;
+$tp_solc_previous=0;
+if ( $previous == 1) {
+    
$a_sum=array('sum_cred','sum_deb','solde_deb','solde_cred','sum_cred_previous','sum_deb_previous','solde_deb_previous','solde_cred_previous');
+}
+else {
+    $a_sum=array('sum_cred','sum_deb','solde_deb','solde_cred') ;
+}
+foreach($a_sum as $a)
+  {
+    $nlvl1[$a]=0;
+    $nlvl2[$a]=0;
+    $nlvl3[$a]=0;
+  }
+$lvl1_old='';
+$lvl2_old='';
+$lvl3_old='';
+
+bcscale(2);
+if (! empty($array))
+  {
+    $i=0;
+    foreach ($array as $key=>$value)
+      {
+       $i++;
+       /*
+        * level x
+        */
+       if ( $value['poste']=='') continue;
+       foreach (array(3,2,1) as $ind)
+         {
+           $r=$value;
+           if ( ! isset($_GET['lvl'.$ind]))continue;
+
+           if (${'lvl'.$ind.'_old'} == '')       
${'lvl'.$ind.'_old'}=substr($r['poste'],0,$ind);
+           if ( ${'lvl'.$ind.'_old'} != substr($r['poste'],0,$ind))
+             {
+               $pdf->SetFont('DejaVu','B',7);
+               $pdf->LongLine(30,6,${'lvl'.$ind.'_old'});
+                
$delta=bcsub(${'nlvl'.$ind}['solde_cred'],${'nlvl'.$ind}['solde_deb']);
+                $side=($delta< 0) ? "D":"C";
+                if ($previous == 1 ) {
+                    
$delta_previous=bcsub(${'nlvl'.$ind}['solde_cred_previous'],${'nlvl'.$ind}['solde_deb_previous']);
+                    $side_previous=($delta_previous < 0) ? "D":"C";
+                    $pdf->Cell(30,6,"n-1 : " .nbm($delta_previous)." 
$side_previous",0,0,'R');
+                     $pdf->Cell(30,6," n : ".nbm($delta)." $side",0,0,'R');
+                    
$pdf->Cell(22,6,nbm(${'nlvl'.$ind}['sum_deb_previous']),0,0,'R');
+                    
$pdf->Cell(22,6,nbm(${'nlvl'.$ind}['sum_cred_previous']),0,0,'R');
+                    
$pdf->Cell(22,6,nbm(${'nlvl'.$ind}['solde_deb_previous']),0,0,'R');
+                    
$pdf->Cell(22,6,nbm(${'nlvl'.$ind}['solde_cred_previous']),0,0,'R');
+                } else {
+                     $pdf->Cell(60,6,nbm($delta)." $side",0,0,'R');
+                }
+               $pdf->Cell(25,6,nbm(${'nlvl'.$ind}['sum_deb']),0,0,'R');
+               $pdf->Cell(25,6,nbm(${'nlvl'.$ind}['sum_cred']),0,0,'R');
+               $pdf->Cell(25,6,nbm(${'nlvl'.$ind}['solde_deb']),0,0,'R');
+               $pdf->Cell(25,6,nbm(${'nlvl'.$ind}['solde_cred']),0,0,'R');
+               $pdf->Ln();
+               $pdf->SetFont('DejaVuCond','',7);
+               ${'lvl'.$ind.'_old'}=substr($r['poste'],0,$ind);
+               foreach($a_sum as $a)
+                 {
+                   ${'nlvl'.$ind}[$a]=0;
+                 }
+             }
+         }
+       foreach($a_sum as $a)
+         {
+           $nlvl1[$a]=bcadd($nlvl1[$a],$r[$a]);
+           $nlvl2[$a]=bcadd($nlvl2[$a],$r[$a]);
+           $nlvl3[$a]=bcadd($nlvl3[$a],$r[$a]);
+         }
+
+       if ( $i % 2 == 0 )
+         {
+           $pdf->SetFillColor(220,221,255);
+           $fill=1;
+         }
+       else
+         {
+           $pdf->SetFillColor(0,0,0);
+           $fill=0;
+         }
+
+       $pdf->LongLine(30,6,$value['poste'],0,'L',$fill);
+       $pdf->LongLine(60,6,$value['label'],0,'L',$fill);
+        if ($previous == 1 ) {
+            $pdf->Cell(22,6,nbm($value['sum_deb_previous']),0,0,'R',$fill);
+            $pdf->Cell(22,6,nbm($value['sum_cred_previous']),0,0,'R',$fill);
+            $pdf->Cell(22,6,nbm($value['solde_deb_previous']),0,0,'R',$fill);
+            $pdf->Cell(22,6,nbm($value['solde_cred_previous']),0,0,'R',$fill);
+            
$tp_deb_previous=bcadd($tp_deb_previous,$value['sum_deb_previous']);
+            
$tp_cred_previous=bcadd($tp_cred_previous,$value['sum_cred_previous']);
+            
$tp_sold_previous=bcadd($tp_sold_previous,$value['solde_deb_previous']);
+            
$tp_solc_previous=bcadd($tp_solc_previous,$value['solde_cred_previous']);
+        }
+       $pdf->Cell(25,6,nbm($value['sum_deb']),0,0,'R',$fill);
+       $pdf->Cell(25,6,nbm($value['sum_cred']),0,0,'R',$fill);
+       $pdf->Cell(25,6,nbm($value['solde_deb']),0,0,'R',$fill);
+       $pdf->Cell(25,6,nbm($value['solde_cred']),0,0,'R',$fill);
+       $pdf->Ln();
+       $tp_deb=bcadd($tp_deb,$value['sum_deb']);
+       $tp_cred=bcadd($tp_cred,$value['sum_cred']);
+       $tp_sold=bcadd($tp_sold,$value['solde_deb']);
+       $tp_solc=bcadd($tp_solc,$value['solde_cred']);
+
+      }
+    foreach (array(3,2,1) as $ind)
+      {
+       $r=$value;
+       if ( ! isset($_GET['lvl'.$ind]))continue;
+
+       if (${'lvl'.$ind.'_old'} == '')   
${'lvl'.$ind.'_old'}=substr($r['poste'],0,$ind);
+       if ( ${'lvl'.$ind.'_old'} != substr($r['poste'],0,$ind))
+         {
+           $pdf->SetFont('DejaVu','B',7);
+           $pdf->Cell(30,6,"Totaux ".$ind);
+           $pdf->Cell(60,6,${'lvl'.$ind.'_old'});
+             if ($previous == 1 ) {
+                
$pdf->Cell(22,6,nbm(${'nlvl'.$ind}['sum_deb_previous']),0,0,'R');
+                
$pdf->Cell(22,6,nbm(${'nlvl'.$ind}['sum_cred_previous']),0,0,'R');
+                
$pdf->Cell(22,6,nbm(${'nlvl'.$ind}['solde_deb_previous']),0,0,'R');
+                
$pdf->Cell(22,6,nbm(${'nlvl'.$ind}['solde_cred_previous']),0,0,'R');
+             }
+           $pdf->Cell(25,6,nbm(${'nlvl'.$ind}['sum_deb']),0,0,'R');
+           $pdf->Cell(25,6,nbm(${'nlvl'.$ind}['sum_cred']),0,0,'R');
+           $pdf->Cell(25,6,nbm(${'nlvl'.$ind}['solde_deb']),0,0,'R');
+           $pdf->Cell(25,6,nbm(${'nlvl'.$ind}['solde_cred']),0,0,'R');
+           $pdf->Ln();
+           $pdf->SetFont('DejaVuCond','',7);
+           ${'lvl'.$ind.'_old'}=substr($r['poste'],0,$ind);
+           foreach($a_sum as $a)
+             {
+               ${'nlvl'.$ind}[$a]=0;
+             }
+         }
+      }
+
+    // Totaux
+    $pdf->SetFont('DejaVuCond','B',8);
+    $pdf->Cell(90,6,'Totaux');
+     if ($previous == 1 ) {
+        $pdf->Cell(22,6,nbm($tp_deb_previous),'T',0,'R',0);
+        $pdf->Cell(22,6,nbm($tp_cred_previous),'T',0,'R',0);
+        $pdf->Cell(22,6,nbm($tp_sold_previous),'T',0,'R',0);
+        $pdf->Cell(22,6,nbm($tp_solc_previous),'T',0,'R',0);
+    }
+    $pdf->Cell(25,6,nbm($tp_deb),'T',0,'R',0);
+    $pdf->Cell(25,6,nbm($tp_cred),'T',0,'R',0);
+    $pdf->Cell(25,6,nbm($tp_sold),'T',0,'R',0);
+    $pdf->Cell(25,6,nbm($tp_solc),'T',0,'R',0);
+    $pdf->Ln();
+  } /** empty */
+
+$fDate=date('dmy-Hi');
+$pdf->Output('balance-'.$fDate.'.pdf','D');
+
+
+
+?>
diff --git a/include/export/export_bilan_oth.php 
b/include/export/export_bilan_oth.php
new file mode 100644
index 0000000..b031bb5
--- /dev/null
+++ b/include/export/export_bilan_oth.php
@@ -0,0 +1,61 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+// Copyright Author Dany De Bontridder address@hidden
+/*! \file
+ * \brief send a Bilan in RTF format
+ */
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+include_once("lib/ac_common.php");
+include_once("lib/class_impress.php");
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once  NOALYSS_INCLUDE.'/header_print.php';
+require_once  NOALYSS_INCLUDE.'/class/class_acc_bilan.php';
+
+require_once   NOALYSS_INCLUDE.'/class/class_user.php';
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+$gDossier=dossier::id();
+
+/* Admin. Dossier */
+$cn=new Database($gDossier);
+
+$bilan=new Acc_Bilan($cn);
+$bilan->get_request_get();
+$bilan->load();
+
+if ( $bilan->b_type=='odt')
+{
+    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
+    header("Cache-Control: must-revalidate");
+    header('Content-type: application/vnd.oasis.opendocument.text');
+    header('Content-Disposition: 
attachment;filename="'.$bilan->b_name.'.odt"',FALSE);
+    header("Accept-Ranges: bytes");
+
+}
+if ( $bilan->b_type=='ods')
+{
+    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
+    header("Cache-Control: must-revalidate");
+    header('Content-type: application/vnd.oasis.opendocument.spreadsheet');
+    header('Content-Disposition: 
attachment;filename="'.$bilan->b_name.'.ods"',FALSE);
+    header("Accept-Ranges: bytes");
+
+}
+
+$bilan->generate();
+?>
diff --git a/include/export/export_fiche_balance_csv.php 
b/include/export/export_fiche_balance_csv.php
new file mode 100644
index 0000000..3b9b47f
--- /dev/null
+++ b/include/export/export_fiche_balance_csv.php
@@ -0,0 +1,200 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief Called by impress->category, export in CVS the history of a category
+ * of card
+ */
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+header('Pragma: public');
+header('Content-type: application/csv');
+header('Content-Disposition: attachment;filename="bal-fiche.csv"',FALSE);
+
+// Security we check if user does exist and his privilege
+require_once NOALYSS_INCLUDE.'/class/class_user.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
+$allcard=(isset($_GET['allcard']))?1:0;
+
+/* balance */
+if ( $_GET['histo'] == 4 || $_GET['histo'] == 5)
+{
+    $fd=new Fiche_Def($cn,$_REQUEST['cat']);
+    if ( $allcard==1 && $fd->hasAttribute(ATTR_DEF_ACCOUNT) == false )
+    {
+      exit;
+    }
+       // all card
+       if ($allcard==1)
+       {
+               $afiche=$cn->get_array("select fd_id from vw_fiche_def where 
ad_id=".ATTR_DEF_ACCOUNT." order by fd_label asc");
+       }
+       else
+       {
+               $afiche[0]=array('fd_id'=>$_REQUEST['cat']);
+       }
+       printf('"Quick code";"Nom";"poste 
comptable";"debit";"credit";"solde";"D/C";');
+               printf("\n");
+       for ($e = 0; $e < count($afiche); $e++)
+       {
+               $aCard = $cn->get_array("select f_id,ad_value from fiche join 
fiche_Detail using (f_id)  where ad_id=1 and fd_id=$1 order by 2 ", 
array($afiche[$e]['fd_id']));
+
+               if (empty($aCard))
+               {
+                       continue;
+               }
+
+               for ($i = 0; $i < count($aCard); $i++)
+               {
+                       if (isDate($_REQUEST['start']) == null || 
isDate($_REQUEST['end']) == null)
+                               exit;
+                       $filter = " (j_date >= to_date('" . $_REQUEST['start'] 
. "','DD.MM.YYYY') " .
+                                       " and  j_date <= to_date('" . 
$_REQUEST['end'] . "','DD.MM.YYYY')) ";
+                       $oCard = new Fiche($cn, $aCard[$i]['f_id']);
+                       $solde = $oCard->get_solde_detail($filter);
+                       if ($solde['debit'] == 0 && $solde['credit'] == 0)
+                               continue;
+                       /* only not purged card */
+                       if ($_GET['histo'] == 5 && $solde['solde'] == 0)
+                               continue;
+                       $side = '';
+                       if (bcsub($solde['credit'], $solde['debit']) < 0)
+                               $side = 'Deb.';
+                       if (bcsub($solde['credit'], $solde['debit']) > 0)
+                               $side = 'Cred.';
+
+                       printf('"%s";"%s";"%s";%s;%s;%s;"%s"', 
$oCard->strAttribut(ATTR_DEF_QUICKCODE), $oCard->strAttribut(ATTR_DEF_NAME),  
$oCard->strAttribut(ATTR_DEF_ACCOUNT),nb($solde['debit']), 
nb($solde['credit']), nb(abs($solde['solde'])), $side);
+                       printf("\n");
+               }
+       }
+}
+else
+{
+       // all card
+       if ($allcard == 1)
+       {
+               $afiche = $cn->get_array("select fd_id from vw_fiche_def where 
ad_id=" . ATTR_DEF_ACCOUNT . " order by fd_label asc");
+       }
+       else
+       {
+               $afiche[0] = array('fd_id' => $_REQUEST['cat']);
+       }
+       $fic=new Fiche($cn);
+       for ($e = 0; $e < count($afiche); $e++)
+       {
+               $array = Fiche::get_fiche_def($cn, $afiche[$e]['fd_id'], 
'name_asc');
+
+               foreach ($array as $card)
+               {
+                       $row = new Fiche($cn, $card['f_id']);
+                       $letter = new Lettering_Card($cn);
+                       $letter->set_parameter('quick_code', 
$row->strAttribut(ATTR_DEF_QUICKCODE));
+                       $letter->set_parameter('start', $_GET['start']);
+                       $letter->set_parameter('end', $_GET['end']);
+                       // all
+                       if ($_GET['histo'] == 0)
+                       {
+                               $letter->get_all();
+                       }
+
+                       // lettered
+                       if ($_GET['histo'] == 1)
+                       {
+                               $letter->get_letter();
+                       }
+                       // unlettered
+                       if ($_GET['histo'] == 2)
+                       {
+                               $letter->get_unletter();
+                       }
+                       if ($_GET['histo'] == 6)
+                       {
+                               $letter->get_letter_diff();
+                       }
+                       /* skip if nothing to display */
+                       if (count($letter->content) == 0)
+                               continue;
+                       
printf('"%s";"%s";"%s"'."\n",$row->strAttribut(ATTR_DEF_QUICKCODE), 
$row->strAttribut(ATTR_DEF_NAME),$row->strAttribut(ATTR_DEF_ACCOUNT));
+
+                       printf('"%s";"%s";"%s";"%s";"%s";"%s";"%s";"%s";"%s"',
+                                       _('Date'),
+                               _('ref'),
+                               _('Interne'),
+                               _('Comm'),
+                               _('Débit'),
+                               _('Crébit'),
+                               _('Prog.'),
+                               _('D/C'),
+                               _('Let.'),
+                                       _("Diff Let."));
+                       printf("\n");
+                       $amount_deb = 0;
+                       $amount_cred = 0;
+                       $prog = 0;
+                       bcscale(2);
+                       for ($i = 0; $i < count($letter->content); $i++)
+                       {
+                               $row = $letter->content[$i];
+                               printf ('"%s";',$row['j_date_fmt']);
+                               printf ('"%s";',$row['jr_pj_number']);
+                               printf ('"%s";',$row['jr_internal']);
+                               printf ('"%s";',$row['jr_comment']);
+                               if ($row['j_debit'] == 't')
+                               {
+                                       printf("%s;",nb($row['j_montant']));
+                                       
$amount_deb=bcadd($amount_deb,$row['j_montant']);
+                                       $prog = bcadd($prog, $row['j_montant']);
+                                       printf (";");
+                               }
+                               else
+                               {
+                                       printf(";");
+                                       printf("%s;",nb($row['j_montant']));
+                                       
$amount_cred=bcadd($amount_cred,$row['j_montant']);
+                                       $prog = bcsub($prog, $row['j_montant']);
+                               }
+                               printf 
("%s;\"%s\";",abs(nb($prog)),$fic->get_amount_side($prog));
+                               if ($row['letter'] != -1)
+                               {
+                                       printf('"%s";',  
strtoupper(base_convert($row['letter'],10,36)));
+                                       printf("%s",nb($row['letter_diff']));
+                               }
+                               else
+                                       printf(";");
+                               printf("\n");
+                       }
+                       if ($prog < 0 )
+                               $msg="Solde Debit";
+                       elseif ($prog>0)
+                               $msg="Solde Credit";
+                       else
+                               $msg="soldé";
+
+                       printf(';;;"%s";%s;%s;%s;"%s"',
+                                       
$msg,nb($amount_deb),nb($amount_cred),nb(abs($prog)),$fic->get_amount_side($prog));
+                       printf("\n");
+               }
+       }
+}
+exit;
+
+
diff --git a/include/export/export_fiche_balance_pdf.php 
b/include/export/export_fiche_balance_pdf.php
new file mode 100644
index 0000000..3e429bf
--- /dev/null
+++ b/include/export/export_fiche_balance_pdf.php
@@ -0,0 +1,317 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief Called by impress->category, export in PDF the history of a category 
or balance
+ * of card
+ */
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+// Security we check if user does exist and his privilege
+require_once NOALYSS_INCLUDE.'/class/class_user.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/lib/lib/class_pdf.php';
+require_once NOALYSS_INCLUDE.'/class/class_lettering.php';
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
+
+/* Security */
+$gDossier=dossier::id();
+$cn=new Database($gDossier);
+$g_user->Check();
+$g_user->check_dossier($gDossier);
+$name=$cn->get_value('select fd_label from fiche_def where 
fd_id=$1',array($_GET['cat']));
+
+$pdf=new PDF($cn);
+$pdf->setDossierInfo("  Periode : ".$_GET['start']." - ".$_GET['end']);
+$pdf->AliasNbPages();
+$pdf->AddPage();
+
+$pdf->SetTitle($name,1);
+$pdf->SetAuthor('NOALYSS');
+/* balance */
+$allcard=(isset($_GET['allcard']))?1:0;
+/*
+ * Balance
+ */
+if ( $_GET['histo'] == 4 || $_GET['histo']==5)
+{
+    $fd=new Fiche_Def($cn,$_REQUEST['cat']);
+    if ($allcard==1 &&  $fd->hasAttribute(ATTR_DEF_ACCOUNT) == false )
+    {
+        $pdf->Cell(0,10, "Cette catégorie n'ayant pas de poste comptable n'a 
pas de balance");
+        //Save PDF to file
+        $fDate=date('dmy-Hi');
+        $pdf->Output("category-$fDate.pdf", 'D');
+        exit;
+    }
+       // all card
+       if ($allcard==1)
+       {
+               $afiche=$cn->get_array("select fd_id from vw_fiche_def where 
ad_id=".ATTR_DEF_ACCOUNT." order by fd_label asc");
+       }
+       else
+       {
+               $afiche[0]=array('fd_id'=>$_REQUEST['cat']);
+       }
+
+       if ( $allcard==0 && empty($afiche))
+    {
+        $pdf->Cell(0,10, "Aucune fiche trouvée");//Save PDF to file
+        $fDate=date('dmy-Hi');
+        $pdf->Output("category-$fDate.pdf", 'D');
+        exit;
+    }
+       for ($e = 0; $e < count($afiche); $e++)
+       {
+    $aCard=$cn->get_array("select f_id,ad_value from fiche join fiche_Detail 
using (f_id)  where ad_id=1 and fd_id=$1 order by 2 
",array($afiche[$e]['fd_id']));
+       $name=$cn->get_value('select fd_label from fiche_def where 
fd_id=$1',array($afiche[$e]['fd_id']));
+       $pdf->SetFont('DejaVu','BI',14);
+       $pdf->Cell(0,8,$name,0,1,'C');
+
+       $pdf->SetFont('DejaVuCond','',7);
+    $pdf->LongLine(30,7,'Quick Code',0,'L',0);
+    $pdf->LongLine(80,7,'Libellé',0,'L',0);
+    $pdf->Cell(20,7,'Débit',0,0,'R',0);
+    $pdf->Cell(20,7,'Crédit',0,0,'R',0);
+    $pdf->Cell(20,7,'Solde',0,0,'R',0);
+    $pdf->Cell(20,7,'D/C',0,0,'C',0);
+    $pdf->Ln();
+
+       if (empty($aCard)) continue;
+
+
+    $idx=0;$sum_deb=0;$sum_cred=0;bcscale(4);
+    for ($i=0;$i < count($aCard);$i++)
+    {
+        if ( isDate($_REQUEST['start']) == null || isDate ($_REQUEST['end']) 
== null )          exit;
+        $filter= " (j_date >= to_date('".$_REQUEST['start']."','DD.MM.YYYY') ".
+                 " and  j_date <= 
to_date('".$_REQUEST['end']."','DD.MM.YYYY')) ";
+        $oCard=new Fiche($cn,$aCard[$i]['f_id']);
+        $solde=$oCard->get_solde_detail($filter);
+        if ( $solde['debit'] == 0 && $solde['credit']==0) continue;
+       /* only not purged card */
+       if ($_GET['histo'] == 5 && $solde['debit'] == $solde['credit']) 
continue;
+
+        if ( $idx % 2 == 0 )
+        {
+            $pdf->SetFillColor(220,221,255);
+            $fill=1;
+        }
+        else
+        {
+            $pdf->SetFillColor(0,0,0);
+            $fill=0;
+        }
+        $idx++;
+       $side='';
+       if(bcsub($solde['credit'],$solde['debit']) < 0) $side='Deb.';
+       if(bcsub($solde['credit'],$solde['debit']) > 0) $side='Cred.';
+
+        $sum_cred=bcadd($sum_cred,$solde['credit']);
+        $sum_deb=bcadd($sum_deb,$solde['debit']);
+        $sum_solde=bcsub($sum_deb,$sum_cred);
+
+        $pdf->Cell(30,7,$oCard->strAttribut(ATTR_DEF_QUICKCODE),0,0,'L',$fill);
+        $pdf->LongLine(80,7,$oCard->strAttribut(ATTR_DEF_NAME)." 
(".$oCard->strAttribut(ATTR_DEF_ACCOUNT).")",0,'L',$fill);
+        $pdf->Cell(20,7,nbm($solde['debit']),0,0,'R',$fill);
+        $pdf->Cell(20,7,nbm($solde['credit']),0,0,'R',$fill);
+        $pdf->Cell(20,7,nbm(abs($solde['solde'])),0,0,'R',$fill);
+        $pdf->Cell(20,7,$side,0,0,'C',$fill);
+        $pdf->Ln();
+        }
+               if ( $idx % 2 == 0 )
+        {
+            $pdf->SetFillColor(220,221,255);
+            $fill=1;
+        }
+        else
+        {
+            $pdf->SetFillColor(0,0,0);
+            $fill=0;
+        }
+               $idx++;
+        // Sum by category
+        $pdf->Cell(30,7,"",0,0,'L',$fill);
+        $pdf->Cell(80,7,_("Totaux"),0,0,'L',$fill);
+        $pdf->Cell(20,7,nbm($sum_deb),0,0,'R',$fill);
+        $pdf->Cell(20,7,nbm($sum_cred),0,0,'R',$fill);
+        $pdf->Cell(20,7,nbm(abs($sum_solde)),0,0,'R',$fill);
+        $side=" = ";
+        if ( $sum_solde > 0 )
+        {
+            $side='Deb.';
+        }
+        else if ( $sum_solde < 0)
+        {
+            $side='Cred.';
+        }
+
+        $pdf->Cell(20,7,$side,0,0,'C',$fill);
+        $pdf->Ln();
+       }
+}
+else
+{
+       // History
+       // all card
+       if ($allcard == 1)
+       {
+               $afiche = $cn->get_array("select fd_id from vw_fiche_def where 
ad_id=" . ATTR_DEF_ACCOUNT . " order by fd_label asc");
+       }
+       else
+       {
+               $afiche[0] = array('fd_id' => $_REQUEST['cat']);
+       }
+       $fic=new Fiche($cn);
+       for ($e = 0; $e < count($afiche); $e++)
+       {
+               $array = Fiche::get_fiche_def($cn,$afiche[$e]['fd_id'] , 
'name_asc');
+               /*
+                * You show now the result
+                */
+               if ($array == null)
+               {
+                       continue;
+               }
+               $tab = array(12, 20, 20,68, 20, 20, 10, 20);
+               $align = array('L', 'C', 'L', 'L', 'R','R', 'R', 'R');
+
+               foreach ($array as $row_fiche)
+               {
+                       $fic = new Fiche($cn, $row_fiche['f_id']);
+                       $letter = new Lettering_Card($cn);
+                       $letter->set_parameter('quick_code', 
$fic->strAttribut(ATTR_DEF_QUICKCODE));
+                       $letter->set_parameter('start', $_GET['start']);
+                       $letter->set_parameter('end', $_GET['end']);
+                       // all
+                       if ($_GET['histo'] == 0)
+                       {
+                               $letter->get_all();
+                       }
+
+                       // lettered
+                       if ($_GET['histo'] == 1)
+                       {
+                               $letter->get_letter();
+                       }
+                       // unlettered
+                       if ($_GET['histo'] == 2)
+                       {
+                               $letter->get_unletter();
+                       }
+                       if ($_GET['histo'] == 6)
+                       {
+                               $letter->get_letter_diff();
+                       }
+                       /* skip if nothing to display */
+                       if (count($letter->content) == 0)
+                               continue;
+                       $pdf->SetFont('DejaVuCond', '', 10);
+                       $fiche = new Fiche($cn, $row_fiche['f_id']);
+                       $pdf->Cell(0, 7, $fiche->strAttribut(ATTR_DEF_NAME)." 
[".$fiche->strAttribut(ATTR_DEF_QUICKCODE).":".$fiche->strAttribut(ATTR_DEF_ACCOUNT)."]",
 1, 'C');
+
+                       $pdf->SetFont('DejaVuCond', '', 7);
+                       $pdf->Ln();
+                       $pdf->Cell($tab[0], 7, 'Date');
+                       $pdf->Cell($tab[1], 7, 'ref');
+                       $pdf->Cell($tab[2], 7, 'Internal');
+                       $pdf->Cell($tab[3], 7, 'Comm');
+                       $pdf->Cell($tab[4], 7, 'Montant', 0, 0, 'C');
+                       $pdf->Cell($tab[5], 7, 'Prog.', 0, 0, 'R');
+                       $pdf->Cell($tab[6], 7, 'Let.', 0, 0, 'R');
+                       $pdf->Cell($tab[7], 7, 'Diff. Let.', 0, 0, 'R');
+                       $pdf->ln();
+
+                       $amount_deb = 0;
+                       $amount_cred = 0;
+                       $prog=0;
+                       for ($i = 0; $i < count($letter->content); $i++)
+                       {
+                               if ($i % 2 == 0)
+                               {
+                                       $pdf->SetFillColor(220, 221, 255);
+                                       $fill = 1;
+                               }
+                               else
+                               {
+                                       $pdf->SetFillColor(0, 0, 0);
+                                       $fill = 0;
+                               }
+                               $pdf->SetFont('DejaVuCond', '', 7);
+                               $row = $letter->content[$i];
+                               $str_date = shrink_date($row['j_date_fmt']);
+
+                               $pdf->LongLine($tab[0], 4, $str_date, 0, 
$align[0], $fill);
+                               $pdf->Cell($tab[1], 4, $row['jr_pj_number'], 0, 
0, $align[1], $fill);
+                               $pdf->LongLine($tab[2], 4, $row['jr_internal'], 
0, $align[1], $fill);
+                               $pdf->LongLine($tab[3], 4, $row['jr_comment'], 
0,  $align[2], $fill);
+                               if ($row['j_debit'] == 't')
+                               {
+                                       $prog=bcadd($prog,$row['j_montant']);
+                                       $pdf->Cell($tab[4], 4, sprintf('%s D', 
nbm($row['j_montant'])), 0, 0, $align[4], $fill);
+                                       $amount_deb+=$row['j_montant'];
+                                       $str_prog=sprintf("%s 
%s",nbm(abs($prog)),$fic->get_amount_side($prog));
+                                       $pdf->Cell($tab[5], 4, $str_prog, 0, 0, 
$align[5], $fill);
+                               }
+                               else
+                               {
+                                       $prog=bcsub($prog,$row['j_montant']);
+                                       $pdf->Cell($tab[4], 4, sprintf('%s C', 
nbm($row['j_montant'])), 0, 0, $align[4], $fill);
+                                       $amount_cred+=$row['j_montant'];
+                                       $str_prog=sprintf("%s 
%s",nbm(abs($prog)),$fic->get_amount_side($prog));
+                                       $pdf->Cell($tab[5], 4, $str_prog, 0, 0, 
$align[5], $fill);
+                               }
+                               if ($row['letter'] != -1)
+                               {
+                                       $pdf->Cell($tab[6], 4, 
strtoupper(base_convert($row['letter'],10,36)), 0, 0, $align[6], $fill);
+                                       // get sum for this lettering
+
+                                       $pdf->Cell($tab[7], 4, sprintf('%s', 
nbm($row['letter_diff'])), '0', '0', $align[7], $fill);
+                               }
+                               else
+                                       $pdf->Cell($tab[6], 4, "", 0, 0, 'R', 
$fill);
+                               $pdf->Ln();
+                       }
+                       $pdf->SetFillColor(0, 0, 0);
+                       $pdf->SetFont('DejaVuCond', 'B', 8);
+                       $debit = sprintf('Debit  : %s', nbm($amount_deb));
+                       $credit = sprintf('Credit : %s', nbm($amount_cred));
+                       if ($amount_deb > $amount_cred)
+                               $s = 'solde débiteur';
+                       else
+                               $s = 'solde crediteur';
+                       $solde = sprintf('%s  : %s', $s, 
nbm(abs(round($amount_cred - $amount_deb, 2))));
+
+                       $pdf->Cell(0, 6, $debit, 0, 0, 'R');
+                       $pdf->ln(4);
+                       $pdf->Cell(0, 6, $credit, 0, 0, 'R');
+                       $pdf->ln(4);
+                       $pdf->Cell(0, 6, $solde, 0, 0, 'R');
+                       $pdf->ln(4);
+
+                       $pdf->Ln();
+               }
+       }
+}
+//Save PDF to file
+$fDate=date('dmy-Hi');
+$pdf->Output("category-$fDate.pdf", 'D');
+exit;
diff --git a/include/export/export_fiche_csv.php 
b/include/export/export_fiche_csv.php
new file mode 100644
index 0000000..4106eb1
--- /dev/null
+++ b/include/export/export_fiche_csv.php
@@ -0,0 +1,89 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+// Copyright Author Dany De Bontridder address@hidden
+/*! \file
+ * \brief Send a CSV file with card
+ */
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+header('Pragma: public');
+header('Content-type: application/csv');
+header('Content-Disposition: attachment;filename="fiche.csv"',FALSE);
+include_once ("lib/ac_common.php");
+include_once('class/class_fiche.php');
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+$gDossier=dossier::id();
+
+$cn=new Database($gDossier);
+
+require_once  NOALYSS_INCLUDE.'/class/class_user.php';
+
+
+
+if  ( isset ($_GET['fd_id']))
+{
+    $fiche_def=new Fiche_Def($cn,$_GET ['fd_id']);
+    $fiche=new Fiche($cn);
+    $e=$fiche_def->get_by_type();
+    $o=0;
+    //  Heading
+    $fiche_def->GetAttribut();
+    foreach ($fiche_def->attribut as $attribut)
+    {
+        if ( $o == 0 )
+        {
+            printf("%s",$attribut->ad_text);
+            $o=1;
+        }
+        else
+        {
+            printf(";%s",$attribut->ad_text);
+        }
+    }
+    printf("\n");
+    $o=0;
+    // Details
+
+    foreach ($e as $fiche)
+      {
+       $detail=new Fiche($cn,$fiche['f_id']);
+
+       $detail->getAttribut();
+
+        foreach ( $detail->attribut as $dattribut )
+        {
+            if ( $o == 0 )
+            {
+                printf("%s",$dattribut->av_text);
+                $o=1;
+            }
+            else
+            {
+                printf (";%s",$dattribut->av_text);
+
+            }
+        }
+        printf("\n");
+        $o=0;
+    }
+
+
+}
+exit;
+?>
diff --git a/include/export/export_fiche_detail_csv.php 
b/include/export/export_fiche_detail_csv.php
new file mode 100644
index 0000000..b12dd49
--- /dev/null
+++ b/include/export/export_fiche_detail_csv.php
@@ -0,0 +1,163 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+// Copyright Author Dany De Bontridder address@hidden
+/*! \file
+ * \brief Send the poste list in csv
+ */
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+include_once("lib/ac_common.php");
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/class/class_fiche.php';
+$f_id=HtmlInput::default_value_request("f_id", "-");
+if ( $f_id == "-") {
+     throw new Exception ('Invalid parameter');
+}
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+$gDossier=dossier::id();
+
+/* Admin. Dossier */
+$cn=new Database($gDossier);
+
+
+$Fiche=new Fiche($cn,$f_id);
+$qcode=$Fiche->get_quick_code();
+
+header('Content-type: application/csv');
+
+header('Pragma: public');
+header('Content-Disposition: 
attachment;filename="fiche-'.$qcode.'.csv"',FALSE);
+$Fiche->getName();
+list($array,$tot_deb,$tot_cred)=$Fiche->get_row_date(
+                                    $_GET['from_periode'],
+                                    $_GET['to_periode'],
+                                    $_GET['ople']
+                                );
+if ( count($Fiche->row ) == 0 )
+{
+    echo "Aucune donnée";
+    return;
+}
+
+
+if ( ! isset ($_REQUEST['oper_detail']))
+{
+    echo '"Qcode";'.
+    "\"Date\";".
+      "\"n° pièce\";".
+    "\"Code interne\";".
+    '"Code journal";'.
+    '"Nom journal";'.
+    "\"Description\";".
+    "\"Débit\";".
+    "\"Crédit\";".
+    "\"Prog.\";".
+    "\"Let.\""     ;
+    printf("\n");
+    $progress=0;
+    $current_exercice="";
+    $tot_deb=0;$tot_cred=0; 
+    bcscale(2);
+    foreach ( $Fiche->row as $op )
+    {
+        /*
+             * separation per exercice
+             */
+            if ( $current_exercice == "") $current_exercice=$op['p_exercice'];
+            
+            if ( $current_exercice != $op['p_exercice']) {
+                $solde_type=($tot_deb>$tot_cred)?"solde débiteur":"solde 
créditeur";
+                $diff=abs($tot_deb-$tot_cred);
+                printf(
+                     ";;;".
+                     '"'._('total').'";'.
+                     '"'.$current_exercice.'";;'.
+                '"'."$solde_type".'"'.";".
+                nb($tot_deb).";".
+                nb($tot_cred).";".
+                nb($diff).";"."\n");
+                /*
+                * reset total and current_exercice
+                */
+                $progress=0;
+                $current_exercice=$op['p_exercice'];
+                $tot_deb=0;$tot_cred=0;    
+            }
+        $diff=bcsub($op['deb_montant'],$op['cred_montant']);
+        $progress=bcadd($progress,$diff);
+        $tot_deb=bcadd($tot_deb,$op['deb_montant']);
+        $tot_cred=bcadd($tot_cred,$op['cred_montant']);
+        echo '"'.$op['j_qcode'].'";'.
+         '"'.$op['j_date_fmt'].'"'.";".
+         '"'.$op['jr_pj_number'].'"'.";".
+         '"'.$op['jr_internal'].'"'.";".
+         '"'.$op['jrn_def_code'].'"'.";".
+         '"'.$op['jrn_def_name'].'"'.";".
+         '"'.$op['description'].'"'.";".
+         nb($op['deb_montant']).";".
+         nb($op['cred_montant']).";".
+         nb(abs($progress)).';'.
+         
'"'.(($op['letter']==-1)?'':strtoupper(base_convert($op['letter'],10,36))).'"';
+        printf("\n");
+
+    }
+}
+else
+{
+    echo '"Poste";"Qcode";"date";"ref";"internal";';
+    echo    "\"Description\";".
+    "\"Montant\";".
+    "\"D/C\"";
+
+    printf("\r\n");
+
+    foreach ( $Fiche->row as $op )
+    {
+        $acc=new Acc_Operation($cn);
+        $acc->jr_id=$op['jr_id'];
+        $result= $acc->get_jrnx_detail();
+
+        foreach ( $result as $r)
+        {
+            printf('"%s";"%s";"%s";"%s";"%s";%s;%s;"%s"',
+                   $r['j_poste'],
+                   $r['j_qcode'],
+                   $r['jr_date'],
+                  $op['jr_pj_number'],
+                   $r['jr_internal'],
+                   $r['description'],
+                   nb($r['j_montant']),
+                   $r['debit']);
+            printf("\r\n");
+
+        }
+
+
+
+    }
+}
+$solde_type=($tot_deb>$tot_cred)?"solde débiteur":"solde créditeur";
+$diff=abs($tot_deb-$tot_cred);
+printf(
+    '"'."$solde_type".'"'.";".
+    nb($diff).";".
+    nb($tot_deb).";".
+    nb($tot_cred)."\n");
+
+exit;
+?>
diff --git a/include/export/export_fiche_detail_pdf.php 
b/include/export/export_fiche_detail_pdf.php
new file mode 100644
index 0000000..846fc64
--- /dev/null
+++ b/include/export/export_fiche_detail_pdf.php
@@ -0,0 +1,231 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+/*! \file
+ * \brief send the account list in PDF
+ */
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+include_once("class/class_acc_account_ledger.php");
+include_once("lib/ac_common.php");
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+include_once("lib/class_impress.php");
+require_once NOALYSS_INCLUDE.'/class/class_fiche.php';
+require_once  NOALYSS_INCLUDE.'/header_print.php';
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+require_once NOALYSS_INCLUDE.'/lib/lib/class_pdf.php';
+$gDossier=dossier::id();
+
+$cn=new Database($gDossier);
+
+extract($_GET);
+
+$ret="";
+$pdf= new PDF($cn);
+$pdf->setDossierInfo("  Periode : ".$_GET['from_periode']." - 
".$_GET['to_periode']);
+$pdf->AliasNbPages();
+$pdf->AddPage();
+$pdf->SetAuthor('NOALYSS');
+$pdf->setTitle("Détail fiche",true);
+
+
+$Fiche=new Fiche($cn,$f_id);
+
+
+list($array,$tot_deb,$tot_cred)=$Fiche->get_row_date($from_periode,$to_periode,$_GET['ople']);
+// don't print empty account
+if ( count($array) == 0 )
+{
+    exit;
+}
+$size=array(13,25,20,60,12,20,20,20);
+$align=array('L','C','C','L','R','R','R','R');
+
+$Libelle=sprintf("(%s) %s [ %s 
]",$Fiche->id,$Fiche->getName(),$Fiche->get_quick_code());
+$pdf->SetFont('DejaVu','',10);
+$pdf->Cell(0,8,$Libelle,1,0,'C');
+$pdf->Ln();
+
+
+$pdf->SetFont('DejaVuCond','',8);
+$l=0;
+$pdf->Cell($size[$l],6,'Date',0,0,'L');
+$l++;
+$pdf->Cell($size[$l],6,'Ref',0,0,'C');
+$l++;
+$pdf->Cell($size[$l],6,'Journal',0,0,'C');
+$l++;
+$pdf->Cell($size[$l],6,'Libellé',0,0,'L');
+$l++;
+$pdf->Cell($size[$l],6,'Let',0,0,'R');
+$l++;
+$pdf->Cell($size[$l],6,'Debit',0,0,'R');
+$l++;
+$pdf->Cell($size[$l],6,'Credit',0,0,'R');
+$l++;
+$pdf->Cell($size[$l],6,'Prog',0,0,'R');
+$l++;
+$pdf->ln();
+$tot_deb=0;
+$tot_cred=0;
+$progress=0;
+$current_exercice="";
+bcscale(2);
+for ($e=0;$e<count($array);$e++)
+{
+    $row=$array[$e];
+    /*
+     * separation per exercice
+     */
+    if ( $current_exercice == "") $current_exercice=$row['p_exercice'];
+
+    if ( $current_exercice != $row['p_exercice']) {
+            $str_debit=sprintf("% 12.2f €",$tot_deb);
+            $str_credit=sprintf("% 12.2f €",$tot_cred);
+            $diff_solde=bcsub($tot_deb,$tot_cred);
+            if ( $diff_solde < 0 )
+            {
+                $solde=" créditeur ";
+                $diff_solde=bcmul($diff_solde,-1);
+            }
+            else
+            {
+                 $solde=" débiteur ";
+            }
+            $str_diff_solde=sprintf("%12.2f €",$diff_solde);
+
+            $pdf->SetFont('DejaVu','B',8);
+            $pdf->LongLine(15,6,_('totaux'),0,'L');
+            $pdf->Cell(15,6,$current_exercice,0,0,'L');
+            $pdf->LongLine(40,6,$solde,0,'L');
+            $pdf->Cell(40,6,$str_debit,0,0,'R');
+            $pdf->Cell(40,6,$str_credit,0,0,'R');
+            $pdf->Cell(40,6,$str_diff_solde,0,0,'R');
+            $pdf->Ln();
+            /*
+            * reset total and current_exercice
+            */
+            $prog=0;
+            $current_exercice=$row['p_exercice'];
+            $tot_deb=0;$tot_cred=0;    
+            $pdf->SetFont('DejaVuCond','',8);
+    }
+    $l=0;
+    $progress=bcsub($row['deb_montant'],$row['cred_montant']);
+
+
+    $date=shrink_date($row['j_date_fmt']);
+    $pdf->LongLine($size[$l],6,$date,0,$align[$l]);
+    $l++;
+    if ( $row['jr_pj_number'] == '')
+      $pdf->Cell($size[$l],6,"",0,0,$align[$l]);
+    else
+      $pdf->Cell($size[$l],6,$row['jr_pj_number'],0,0,$align[$l]);
+
+    $l++;
+    
$pdf->LongLine($size[$l],6,mb_substr($row['jrn_def_code'],0,14),0,$align[$l]);
+    $l++;
+    
$pdf->LongLine($size[$l],6,($row['description'].'('.$row['jr_internal'].")"),0,$align[$l]);
+
+    $l++;
+    
$pdf->LongLine($size[$l],6,(($row['letter']!=-1)?strtoupper(base_convert($row['letter'],10,36)):''),0,$align[$l]);
+    $l++;
+    $pdf->LongLine($size[$l],6,(sprintf('% 
12.2f',$row['deb_montant'])),0,$align[$l]);
+    $l++;
+    $pdf->LongLine($size[$l],6,(sprintf('% 
12.2f',$row['cred_montant'])),0,$align[$l]);
+    $l++;
+    $pdf->LongLine($size[$l],6,(sprintf('% 
12.2f',abs($progress))),0,$align[$l]);
+    $l++;
+    $pdf->ln();
+    $tot_deb=bcadd($tot_deb,$row['deb_montant']);
+    $tot_cred=bcadd($tot_cred,$row['cred_montant']);
+    /* -------------------------------------- */
+    /* if details are asked we show them here */
+    /* -------------------------------------- */
+    if ( isset($_GET['oper_detail']))
+    {
+        $detail=new Acc_Operation($cn);
+        $detail->jr_id=$row['jr_id'];
+        $a_detail=$detail->get_jrnx_detail();
+        for ($f=0;$f<count($a_detail);$f++)
+        {
+            $l=0;
+            $pdf->Cell($size[$l],6,'',0,0,$align[$l]);
+            $l++;
+            $pdf->Cell($size[$l],6,$a_detail[$f]['j_qcode'],0,0,'L');
+            $l++;
+            $pdf->Cell($size[$l],6,$a_detail[$f]['j_poste'],0,0,'R');
+            $l++;
+            if ( $a_detail[$f]['j_qcode']=='')
+                $lib=$a_detail[$f]['pcm_lib'];
+            else
+            {
+                $f_id=$cn->get_value('select f_id from vw_poste_qcode where 
j_qcode=$1',array($a_detail[$f]['j_qcode'])) ;
+                $lib=$cn->get_value('select ad_value from fiche_detail where 
ad_id=$1 and f_id=$2',
+                                    array(ATTR_DEF_NAME,$f_id));
+            }
+            $pdf->Cell($size[$l],6,$lib,0,0,$align[$l]);
+            $l++;
+            
$pdf->Cell($size[$l],6,(($a_detail[$f]['letter']!=-1)?$a_detail[$f]['letter']:''),0,0,$align[$l]);
+            $l++;
+
+            $deb=($a_detail[$f]['debit']=='D')?$a_detail[$f]['j_montant']:'';
+            $cred=($a_detail[$f]['debit']=='C')?$a_detail[$f]['j_montant']:'';
+
+            $pdf->Cell($size[$l],6,(sprintf('% 12.2f',$deb)),0,0,$align[$l]);
+            $l++;
+            $pdf->Cell($size[$l],6,(sprintf('% 12.2f',$cred)),0,0,$align[$l]);
+            $l++;
+            $pdf->ln();
+        }
+    }
+
+}
+$str_debit=sprintf("% 12.2f €",$tot_deb);
+$str_credit=sprintf("% 12.2f €",$tot_cred);
+$diff_solde=$tot_deb-$tot_cred;
+if ( $diff_solde < 0 )
+{
+    $solde=" créditeur ";
+    $diff_solde*=-1;
+}
+else
+{
+    $solde=" débiteur ";
+}
+$str_diff_solde=sprintf("%12.2f €",$diff_solde);
+
+$pdf->SetFont('DejaVu','B',8);
+
+$pdf->Cell(160,5,'Débit',0,0,'R');
+$pdf->Cell(30,5,$str_debit,0,0,'R');
+$pdf->Ln();
+$pdf->Cell(160,5,'Crédit',0,0,'R');
+$pdf->Cell(30,5,$str_credit,0,0,'R');
+$pdf->Ln();
+$pdf->Cell(160,5,'Solde '.$solde,0,0,'R');
+$pdf->Cell(30,5,$str_diff_solde,0,0,'R');
+$pdf->Ln();
+
+$fDate=date('dmy-Hi');
+$pdf->Output('fiche-'.$fDate.'.pdf','D');
+
+
+?>
diff --git a/include/export/export_fiche_pdf.php 
b/include/export/export_fiche_pdf.php
new file mode 100644
index 0000000..2e31622
--- /dev/null
+++ b/include/export/export_fiche_pdf.php
@@ -0,0 +1,232 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief Called by impress->category, export in PDF the history of a category
+ * of card
+ */
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+// Security we check if user does exist and his privilege
+require_once NOALYSS_INCLUDE.'/class/class_user.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/lib/lib/class_pdf.php';
+require_once NOALYSS_INCLUDE.'/class/class_lettering.php';
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
+
+/* Security */
+$gDossier=dossier::id();
+$cn=new Database($gDossier);
+$g_user->Check();
+$g_user->check_dossier($gDossier);
+
+$pdf=new PDF($cn);
+$pdf->setDossierInfo("  Periode : ".$_GET['start']." - ".$_GET['end']);
+$pdf->AliasNbPages();
+$pdf->AddPage();
+$name=$cn->get_value('select fd_label from fiche_def where 
fd_id=$1',array($_GET['cat']));
+$pdf->SetFont('DejaVu','BI',14);
+$pdf->Cell(0,8,$name,0,1,'C');
+$pdf->SetTitle($name,1);
+$pdf->SetAuthor('NOALYSS');
+/* balance */
+if ( $_GET['histo'] == 4 )
+{
+    $fd=new Fiche_Def($cn,$_REQUEST['cat']);
+    if ( $fd->hasAttribute(ATTR_DEF_ACCOUNT) == false )
+    {
+        $pdf->Cell(0,10, "Cette catégorie n'ayant pas de poste comptable n'a 
pas de balance");
+        //Save PDF to file
+        $fDate=date('dmy-Hi');
+        $pdf->Output("category-$fDate.pdf", 'D');
+        exit;
+    }
+    $aCard=$cn->get_array("select f_id,ad_value from fiche join fiche_Detail 
using (f_id)  where ad_id=1 and fd_id=$1 order by 2 ",array($_REQUEST['cat']));
+
+    if ( empty($aCard))
+    {
+        $pdf->Cell(0,10, "Aucune fiche trouvée");//Save PDF to file
+        $fDate=date('dmy-Hi');
+        $pdf->Output("category-$fDate.pdf", 'D');
+        exit;
+    }
+    $pdf->SetFont('DejaVuCond','',7);
+    $pdf->Cell(30,7,'Quick Code',0,0,'L',0);
+    $pdf->Cell(80,7,'Libellé',0,0,'L',0);
+    $pdf->Cell(20,7,'Débit',0,0,'R',0);
+    $pdf->Cell(20,7,'Crédit',0,0,'R',0);
+    $pdf->Cell(20,7,'Solde',0,0,'R',0);
+    $pdf->Cell(20,7,'D/C',0,0,'C',0);
+    $pdf->Ln();
+    $idx=0;
+    for ($i=0;$i < count($aCard);$i++)
+    {
+        if ( isDate($_REQUEST['start']) == null || isDate ($_REQUEST['end']) 
== null )          exit;
+        $filter= " (j_date >= to_date('".$_REQUEST['start']."','DD.MM.YYYY') ".
+                 " and  j_date <= 
to_date('".$_REQUEST['end']."','DD.MM.YYYY')) ";
+        $oCard=new Fiche($cn,$aCard[$i]['f_id']);
+        $solde=$oCard->get_solde_detail($filter);
+        if ( $solde['debit'] == 0 && $solde['credit']==0) continue;
+
+        if ( $idx % 2 == 0 )
+        {
+            $pdf->SetFillColor(220,221,255);
+            $fill=1;
+        }
+        else
+        {
+            $pdf->SetFillColor(0,0,0);
+            $fill=0;
+        }
+        $idx++;
+
+        $pdf->Cell(30,7,$oCard->strAttribut(ATTR_DEF_QUICKCODE),0,0,'L',$fill);
+        $pdf->Cell(80,7,$oCard->strAttribut(ATTR_DEF_NAME),0,0,'L',$fill);
+        $pdf->Cell(20,7,sprintf('%.02f',$solde['debit']),0,0,'R',$fill);
+        $pdf->Cell(20,7,sprintf('%.02f',$solde['credit']),0,0,'R',$fill);
+        $pdf->Cell(20,7,sprintf('%.02f',abs($solde['solde'])),0,0,'R',$fill);
+        $pdf->Cell(20,7,(($solde['solde']<0)?'CRED':'DEB'),0,0,'C',$fill);
+        $pdf->Ln();
+    }
+}
+else
+{
+    $array=Fiche::get_fiche_def($cn,$_GET['cat'],'name_asc');
+    /*
+     * You show now the result
+     */
+    if ($array == null  )
+    {
+        exit();
+    }
+    $tab=array(13,25,55,20,20,12,20);
+    $align=array('L','L','L','R','R','R','R');
+
+    foreach($array as $row_fiche)
+    {
+      $row=new Fiche($cn,$row_fiche['f_id']);
+        $letter=new Lettering_Card($cn);
+        
$letter->set_parameter('quick_code',$row->strAttribut(ATTR_DEF_QUICKCODE));
+        $letter->set_parameter('start',$_GET['start']);
+        $letter->set_parameter('end',$_GET['end']);
+        // all
+        if ( $_GET['histo'] == 0 )
+        {
+            $letter->get_all();
+        }
+
+        // lettered
+        if ( $_GET['histo'] == 1 )
+        {
+            $letter->get_letter();
+        }
+        // unlettered
+        if ( $_GET['histo'] == 2 )
+        {
+            $letter->get_unletter();
+        }
+        /* skip if nothing to display */
+        if (count($letter->content) == 0 ) continue;
+        $pdf->SetFont('DejaVuCond','',10);
+       $fiche=new Fiche($cn,$row_fiche['f_id']);
+        $pdf->Cell(0,7,$fiche->strAttribut(ATTR_DEF_NAME),1,1,'C');
+
+        $pdf->SetFont('DejaVuCond','',7);
+
+        $pdf->Cell($tab[0],7,'Date');
+        $pdf->Cell($tab[1],7,'ref');
+        $pdf->Cell($tab[1],7,'Int.');
+        $pdf->Cell($tab[2],7,'Comm');
+        $pdf->Cell(40,7,'Montant',0,0,'C');
+        $pdf->Cell($tab[5],7,'Let.',0,0,'R');
+        $pdf->Cell($tab[6],7,'Som. Let.',0,0,'R');
+        $pdf->ln();
+
+        $amount_deb=0;
+        $amount_cred=0;
+        for ($i=0;$i<count($letter->content);$i++)
+        {
+            if ( $i % 2 == 0 )
+            {
+                $pdf->SetFillColor(220,221,255);
+                $fill=1;
+            }
+            else
+            {
+                $pdf->SetFillColor(0,0,0);
+                $fill=0;
+            }
+            $pdf->SetFont('DejaVuCond','',7);
+            $row=$letter->content[$i];
+            $str_date=shrink_date($row['j_date_fmt']);
+
+            $pdf->Cell($tab[0],4,$str_date,0,0,$align[0],$fill);
+            $pdf->Cell($tab[1],4,$row['jr_pj_number'],0,0,$align[1],$fill);
+            $pdf->Cell($tab[1],4,$row['jr_internal'],0,0,$align[1],$fill);
+            $pdf->Cell($tab[2],4,$row['jr_comment'],0,0,$align[2],$fill);
+            if ( $row['j_debit'] == 't')
+            {
+                
$pdf->Cell($tab[3],4,sprintf('%10.2f',$row['j_montant']),0,0,$align[4],$fill);
+                $amount_deb+=$row['j_montant'];
+                $pdf->Cell($tab[4],4,"",0,0,'C',$fill);
+            }
+            else
+            {
+                $pdf->Cell($tab[3],4,"",0,0,'C',$fill);
+                
$pdf->Cell($tab[4],4,sprintf('%10.2f',$row['j_montant']),0,0,$align[4],$fill);
+                $amount_cred+=$row['j_montant'];
+            }
+            if ($row['letter'] != -1 )
+            {
+                
$pdf->Cell($tab[5],4,strtoupper(base_convert($row['letter'],10,36)),0,0,$align[5],$fill);
+                // get sum for this lettering
+                $sql="select sum(j_montant) from jrnx where j_debit=$1 and 
j_id in ".
+                     " (select j_id from jnt_letter join letter_deb using 
(jl_id) where jl_id=$2 union ".
+                     "  select j_id from jnt_letter join letter_cred using 
(jl_id) where jl_id=$3)";
+                
$sum=$cn->get_value($sql,array($row['j_debit'],$row['letter'],$row['letter']));
+                $pdf->Cell($tab[6],4,sprintf('%.2f',$sum),'0','0','R',$fill);
+            }
+            else
+                $pdf->Cell($tab[5],4,"",0,0,'R',$fill);
+            $pdf->Ln();
+        }
+        $pdf->SetFillColor(0,0,0);
+        $pdf->SetFont('DejaVuCond','B',8);
+        $debit =sprintf('Debit  : % 12.2f',$amount_deb);
+        $credit=sprintf('Credit : % 12.2f',$amount_cred);
+        if ( $amount_deb>$amount_cred) $s='solde débiteur';
+        else $s='solde crediteur';
+        $solde =sprintf('%s  : % 
12.2f',$s,(abs(round($amount_cred-$amount_deb,2))));
+
+        $pdf->Cell(0,6,$debit,0,0,'R');
+        $pdf->ln(4);
+        $pdf->Cell(0,6,$credit,0,0,'R');
+        $pdf->ln(4);
+        $pdf->Cell(0,6,$solde,0,0,'R');
+        $pdf->ln(4);
+
+        $pdf->Ln();
+    }
+}
+//Save PDF to file
+$fDate=date('dmy-Hi');
+$pdf->Output("category-$fDate.pdf", 'D');
+exit;
diff --git a/include/export/export_follow_up_csv.php 
b/include/export/export_follow_up_csv.php
new file mode 100644
index 0000000..3f40ace
--- /dev/null
+++ b/include/export/export_follow_up_csv.php
@@ -0,0 +1,42 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/**
+ * @file
+ * @brief export Action Gestion to csv, taking in account the search
+ *
+ */
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+require_once NOALYSS_INCLUDE.'/class/class_follow_up.php';
+header('Pragma: public');
+header('Content-type: application/csv');
+header('Content-Disposition: attachment;filename="action-gestion.csv"',FALSE);
+
+$follow=new Follow_Up($cn);
+$array=$_GET;
+if ( isset ($_POST['query']) ) $p_array['query']=$_POST['query'];
+
+echo $follow->export_csv($_GET);
+
+exit();
+
+?>
diff --git a/include/export/export_form_csv.php 
b/include/export/export_form_csv.php
new file mode 100644
index 0000000..64956d2
--- /dev/null
+++ b/include/export/export_form_csv.php
@@ -0,0 +1,105 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+// Copyright Author Dany De Bontridder address@hidden
+/*! \file
+ * \brief Send a report in CSV format
+ */
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+require_once  NOALYSS_INCLUDE.'/lib/ac_common.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once  NOALYSS_INCLUDE.'/class/class_user.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_report.php';
+require_once NOALYSS_INCLUDE.'/lib/class_impress.php';
+header('Pragma: public');
+header('Content-type: application/csv');
+header('Content-Disposition: attachment;filename="rapport.csv"',FALSE);
+
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+$gDossier=dossier::id();
+
+/* Admin. Dossier */
+$cn=new Database($gDossier);
+
+$Form=new Acc_Report($cn,$_GET['form_id']);
+$Form->get_name();
+// Step ?
+//--
+$step=HtmlInput::default_value_get("p_step", 0);
+if (  $step == 0 )
+{
+    if ( $_GET ['type_periode'] == 0 )
+        $array=$Form->get_row( $_GET['from_periode'],$_GET['to_periode'], 
$_GET['type_periode']);
+    else
+        $array=$Form->get_row( $_GET['from_date'],$_GET['to_date'], 
$_GET['type_periode']);
+
+
+    if ( count($Form->row ) == 0 )
+        exit;
+
+    echo       "\"Description\";".
+    "\"Montant\"\n";
+
+
+
+    foreach ( $Form->row as $op )
+    {
+        echo '"'.$op['desc'].'"'.";".
+        nb($op['montant']).
+        "\n";
+
+    }
+}
+elseif ($step == 1)
+{
+    // Gather all the data
+    //---
+    for ($e=$_GET['from_periode'];$e<=$_GET['to_periode'];$e+=$_GET['p_step'])
+    {
+        $periode=getPeriodeName($cn,$e);
+        if ( $periode == null ) continue;
+        $array[]=$Form->get_row($e,$e,$_GET['type_periode']);
+        $periode_name[]=$periode;
+    }
+    // Display column heading
+    //--
+    $x="";
+    printf ("Mois;");
+    foreach ($array[0] as $e)
+    {
+        printf("%s%s",$x,$e['desc']);
+        $x=";";
+
+    }
+    printf("\n");
+    // Display value for each line
+    //--
+    $a=0;
+    foreach ($array as $e )
+    {
+        print $periode_name[$a];
+        $a++;
+        foreach ($e as $elt)
+        {
+            printf(";%s",nb($elt['montant']));
+        }
+        printf("\n");
+    }
+}
+exit;
+?>
diff --git a/include/export/export_form_pdf.php 
b/include/export/export_form_pdf.php
new file mode 100644
index 0000000..7ebbf95
--- /dev/null
+++ b/include/export/export_form_pdf.php
@@ -0,0 +1,130 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+/*! \file
+ * \brief Send a report in PDF
+ */
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+include_once("class/class_acc_report.php");
+include_once("lib/ac_common.php");
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+include_once("lib/class_impress.php");
+require_once NOALYSS_INCLUDE.'/class/class_user.php';
+require_once  NOALYSS_INCLUDE.'/header_print.php';
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_report.php';
+require_once NOALYSS_INCLUDE.'/lib/lib/class_pdf.php';
+
+$gDossier=dossier::id();
+
+$cn=new Database($gDossier);
+
+extract($_GET);
+$ret="";
+$Form=new Acc_Report($cn,$form_id);
+$Libelle=sprintf("%s ",$Form->get_name());
+$pdf= new PDF($cn);
+$pdf->setDossierInfo($Libelle);
+$pdf->AliasNbPages();
+$pdf->AddPage();
+$pdf->SetAuthor('NOALYSS');
+$pdf->setTitle("Rapport ".$Libelle,true);
+
+// Step ??
+//--
+$step=HtmlInput::default_value_get("p_step", 0);
+
+if ( $step == 0 )
+{
+    // No step asked
+    //--
+    if ( $_GET ['type_periode'] == 0 )
+        $array=$Form->get_row( $_GET['from_periode'],$_GET['to_periode'], 
$_GET['type_periode']);
+    else
+        $array=$Form->get_row( $_GET['from_date'],$_GET['to_date'], 
$_GET['type_periode']);
+
+}
+else
+{
+    // yes with step
+    //--
+    for ($e=$_GET['from_periode'];$e<=$_GET['to_periode'];$e+=$_GET['p_step'])
+    {
+        $periode=getPeriodeName($cn,$e);
+        if ( $periode == null ) continue;
+        $array[]=$Form->get_row($e,$e,'periode');
+        $periode_name[]=$periode;
+    }
+
+}
+
+
+$pdf->SetFont('DejaVuCond','',8);
+
+// without step
+if ( $step == 0 )
+{
+    if ( $_GET['type_periode'] == 0 )
+    {
+        $q=getPeriodeName($cn,$from_periode);
+        if ( $from_periode != $to_periode)
+        {
+            $periode=sprintf("Période %s à 
%s",$q,getPeriodeName($cn,$to_periode));
+        }
+        else
+        {
+            $periode=sprintf("Période %s",$q);
+        }
+    }
+    else
+    {
+        $periode=sprintf("Date %s jusque 
%s",$_GET['from_date'],$_GET['to_date']);
+    }
+    $pdf->Cell(0,7,$periode,'B');
+    $pdf->Ln();
+    for ($i=0;$i<count($array);$i++)
+    {
+        $pdf->Cell(160,6,$array[$i]['desc']);
+        $pdf->Cell(30,6,sprintf('% 12.2f',$array[$i]['montant']),0,0,'R');
+        $pdf->Ln();
+    }
+}
+else
+{ // With Step
+    $a=0;
+    foreach ($array as $e)
+    {
+        $pdf->Cell(0,7,$periode_name[$a],'B');
+        $pdf->Ln();
+        $a++;
+        for ($i=0;$i<count($e);$i++)
+        {
+            $pdf->Cell(160,6,$e[$i]['desc']);
+            $pdf->Cell(30,6,sprintf('% 12.2f',$e[$i]['montant']),0,0,'R');
+            $pdf->Ln();
+        }
+    }
+}
+
+$fDate=date('dmy-Hi');
+$pdf->Output('rapport-'.$fDate.'.pdf','D');
+
+?>
diff --git a/include/export/export_gl_csv.php b/include/export/export_gl_csv.php
new file mode 100644
index 0000000..b1e5aa6
--- /dev/null
+++ b/include/export/export_gl_csv.php
@@ -0,0 +1,214 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*! \file
+ * \brief create GL comptes as PDF
+ */
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+include_once('class/class_acc_account_ledger.php');
+include_once('lib/ac_common.php');
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+include_once('lib/class_impress.php');
+require_once NOALYSS_INCLUDE.'/class/class_own.php';
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+require_once NOALYSS_INCLUDE.'/class/class_user.php';
+
+header('Content-type: application/csv');
+header('Content-Disposition: attachment;filename="gl_comptes.csv"',FALSE);
+header('Pragma: public');
+
+
+$gDossier=dossier::id();
+
+/* Security */
+$cn=new Database($gDossier);
+
+
+extract($_GET);
+
+if ( isset($poste_id) && strlen(trim($poste_id)) != 0 && isNumber($poste_id) )
+{
+    if ( isset ($poste_fille) )
+    {
+        $parent=$poste_id;
+        $a_poste=$cn->get_array("select pcm_val from tmp_pcmn where 
pcm_val::text like '$parent%' order by pcm_val::text");
+    }
+    elseif ( $cn->count_sql('select * from tmp_pcmn where 
pcm_val='.sql_string($poste_id)) != 0 )
+    {
+        $a_poste=array('pcm_val' => $poste_id);
+    }
+}
+else
+{
+  $cond_poste='';
+  $sql="select pcm_val from tmp_pcmn ";
+    if ($from_poste != '')
+      {
+       $cond_poste = '  where ';
+       $cond_poste .=" pcm_val >= upper 
('".Database::escape_string($from_poste)."')";
+      }
+
+    if ( $to_poste != '')
+      {
+       if  ( $cond_poste == '')
+         {
+           $cond_poste =  " where pcm_val <= upper 
('".Database::escape_string($to_poste)."')";
+         }
+       else
+         {
+           $cond_poste.=" and pcm_val <= upper 
('".Database::escape_string($to_poste)."')";
+         }
+      }
+
+    $sql=$sql.$cond_poste.'  order by pcm_val::text';
+
+    $a_poste=$cn->get_array($sql);
+
+}
+
+if ( count($a_poste) == 0 )
+{
+    echo 'Rien à rapporter.';
+    printf("\n");
+    exit;
+}
+
+// Header
+$header = array( "Date", "Référence", "Libellé", "Pièce","Lettrage", "Débit", 
"Crédit", "Solde" );
+
+$l=(isset($_GET['letter']))?2:0;
+$s=(isset($_REQUEST['solded']))?1:0;
+
+foreach ($a_poste as $poste)
+{
+
+
+  $Poste=new Acc_Account_Ledger($cn,$poste['pcm_val']);
+
+  $array1=$Poste->get_row_date($from_periode,$to_periode,$l,$s);
+  // don't print empty account
+  if ( count($array1) == 0 )
+    {
+      continue;
+    }
+  $array=$array1[0];
+  $tot_deb=$array1[1];
+  $tot_cred=$array1[2];
+
+    // don't print empty account
+    if ( count($array) == 0 )
+    {
+        continue;
+    }
+
+    echo sprintf("%s - %s ",$Poste->id,$Poste->get_name());
+    printf("\n");
+
+    for($i=0;$i<count($header);$i++)
+        echo $header[$i].";";
+    printf("\n");
+
+    $solde = 0.0;
+    $solde_d = 0.0;
+    $solde_c = 0.0;
+    $current_exercice="";
+    foreach ($Poste->row as $detail)
+    {
+
+        /*
+               [0] => 1 [jr_id] => 1
+               [1] => 01.02.2009 [j_date_fmt] => 01.02.2009
+               [2] => 2009-02-01 [j_date] => 2009-02-01
+               [3] => 0 [deb_montant] => 0
+               [4] => 12211.9100 [cred_montant] => 12211.9100
+               [5] => Ecriture douverture [description] => Ecriture douverture
+               [6] => Opération Diverses [jrn_name] => Opération Diverses
+               [7] => f [j_debit] => f
+               [8] => 17OD-01-1 [jr_internal] => 17OD-01-1
+               [9] => ODS1 [jr_pj_number] => ODS1 ) 1
+         */
+/*
+             * separation per exercice
+             */
+        if ( $current_exercice == "") $current_exercice=$detail['p_exercice'];
+
+        if ( $current_exercice != $detail['p_exercice']) {
+            echo ";";
+            echo '"'.$current_exercice.'";';
+            echo ";";
+            echo ";";
+            echo 'Total du compte '.$Poste->id.";";
+            echo ($solde_d  > 0 ? nb($solde_d)  : '').";";
+            echo ($solde_c  > 0 ? nb( $solde_c)  : '').";";
+            echo nb(abs($solde_c-$solde_d)).";";
+            echo ($solde_c > $solde_d ? 'C' : 'D').";";
+            printf("\n");
+            printf("\n");
+            /*
+            * reset total and current_exercice
+            */
+            $current_exercice=$detail['p_exercice'];
+            $solde = 0.0;
+            $solde_d = 0.0;
+            $solde_c = 0.0;
+
+        }
+        if ($detail['cred_montant'] > 0)
+        {
+            $solde   -= $detail['cred_montant'];
+            $solde_c += $detail['cred_montant'];
+        }
+        if ($detail['deb_montant'] > 0)
+        {
+            $solde   += $detail['deb_montant'];
+            $solde_d += $detail['deb_montant'];
+        }
+
+        echo $detail['j_date_fmt'].";";
+        echo $detail['jr_internal'].";";
+        echo $detail['description'].";";
+        echo $detail['jr_pj_number'].";";
+        if ($detail['letter'] == -1) { echo ';'; } else { echo 
$detail['letter'].";";}
+        echo ($detail['deb_montant']  > 0 ? nb($detail['deb_montant'])  : 
'').";";
+        echo ($detail['cred_montant'] > 0 ? nb($detail['cred_montant']) : 
'').";";
+        echo nb(abs($solde)).";";
+               echo $Poste->get_amount_side($solde);
+        printf("\n");
+
+    }
+
+
+    echo ";";
+    echo '"'.$current_exercice.'";';
+    echo ";";
+    echo ";";
+    echo 'Total du compte '.$Poste->id.";";
+    echo ($solde_d  > 0 ? nb($solde_d)  : '').";";
+    echo ($solde_c  > 0 ? nb( $solde_c)  : '').";";
+    echo nb(abs($solde_c-$solde_d)).";";
+    echo ($solde_c > $solde_d ? 'C' : 'D').";";
+    printf("\n");
+    printf("\n");
+}
+
+exit;
+
+?>
diff --git a/include/export/export_gl_pdf.php b/include/export/export_gl_pdf.php
new file mode 100644
index 0000000..3aafae2
--- /dev/null
+++ b/include/export/export_gl_pdf.php
@@ -0,0 +1,239 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*! \file
+ * \brief create GL comptes as PDF
+ */
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+include_once('class/class_acc_account_ledger.php');
+include_once('lib/ac_common.php');
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+include_once('lib/class_impress.php');
+require_once NOALYSS_INCLUDE.'/class/class_own.php';
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+require_once NOALYSS_INCLUDE.'/class/class_user.php';
+require_once NOALYSS_INCLUDE.'/lib/lib/class_pdf.php';
+bcscale(2);
+
+$gDossier=dossier::id();
+
+/* Security */
+$cn=new Database($gDossier);
+$g_user->Check();
+$g_user->check_dossier($gDossier);
+
+$sql="select pcm_val from tmp_pcmn ";
+
+extract($_GET);
+$cond_poste="";
+if ($from_poste != '')
+  {
+    $cond_poste = '  where ';
+    $cond_poste .=' pcm_val >= upper 
(\''.Database::escape_string($from_poste).'\')';
+  }
+
+if ( $to_poste != '')
+  {
+    if  ( $cond_poste == '')
+      {
+       $cond_poste =  ' where pcm_val <= upper 
(\''.Database::escape_string($to_poste).'\')';
+      }
+    else
+      {
+       $cond_poste.=' and pcm_val <= upper 
(\''.Database::escape_string($to_poste).'\')';
+      }
+  }
+
+$sql=$sql.$cond_poste.'  order by pcm_val::text';
+$a_poste=$cn->get_array($sql);
+
+$pdf = new PDF($cn);
+$pdf->setDossierInfo("  Periode : ".$from_periode." - ".$to_periode);
+$pdf->AliasNbPages();
+$pdf->AddPage();
+$pdf->setTitle("Grand Livre",true);
+$pdf->SetAuthor('NOALYSS');
+
+if ( count($a_poste) == 0 )
+{
+    $pdf->Output();
+    return;
+}
+
+// Header
+$header = array( "Date", "Référence", "Libellé", "Pièce","Let", "Débit", 
"Crédit", "Solde" );
+// Left or Right aligned
+$lor    = array( "L"   , "L"        , "L"      , "L"    , "R",   "R"    , "R"  
   , "R"     );
+// Column widths (in mm)
+$width  = array( 13    , 20         , 60       , 15     ,  12     , 20     , 
20      , 20      );
+$l=(isset($_REQUEST['letter']))?2:0;
+$s=(isset($_REQUEST['solded']))?1:0;
+
+foreach ($a_poste as $poste)
+{
+
+  $Poste=new Acc_Account_Ledger($cn,$poste['pcm_val']);
+
+
+  $array1=$Poste->get_row_date($from_periode,$to_periode,$l,$s);
+  // don't print empty account
+  if ( count($array1) == 0 )
+    {
+        continue;
+    }
+  $array=$array1[0];
+  $tot_deb=$array1[1];
+  $tot_cred=$array1[2];
+
+    $pdf->SetFont('DejaVuCond','',10);
+    $Libelle=sprintf("%s - %s ",$Poste->id,$Poste->get_name());
+    $pdf->Cell(0, 7, $Libelle, 1, 1, 'C');
+
+    $pdf->SetFont('DejaVuCond','',6);
+    for($i=0;$i<count($header);$i++)
+        $pdf->Cell($width[$i], 4, $header[$i], 0, 0, $lor[$i]);
+    $pdf->Ln();
+
+    $pdf->SetFont('DejaVuCond','',7);
+
+
+    $solde = 0.0;
+    $solde_d = 0.0;
+    $solde_c = 0.0;
+    $current_exercice="";
+    foreach ($Poste->row as $detail)
+    {
+
+        /*
+               [0] => 1 [jr_id] => 1
+               [1] => 01.02.2009 [j_date_fmt] => 01.02.2009
+               [2] => 2009-02-01 [j_date] => 2009-02-01
+               [3] => 0 [deb_montant] => 0
+               [4] => 12211.9100 [cred_montant] => 12211.9100
+               [5] => Ecriture douverture [description] => Ecriture douverture
+               [6] => Opération Diverses [jrn_name] => Opération Diverses
+               [7] => f [j_debit] => f
+               [8] => 17OD-01-1 [jr_internal] => 17OD-01-1
+               [9] => ODS1 [jr_pj_number] => ODS1 ) 1
+         */
+         /*
+             * separation per exercice
+             */
+            if ( $current_exercice == "") 
$current_exercice=$detail['p_exercice'];
+            
+            if ( $current_exercice != $detail['p_exercice']) {
+                
+                $pdf->SetFont('DejaVuCond','B',8);
+                $i=0;
+                $pdf->Cell($width[$i], 6, $current_exercice, 0, 0, $lor[$i]);
+                $i++;
+                $pdf->Cell($width[$i], 6, '', 0, 0, $lor[$i]);
+                $i++;
+                $pdf->Cell($width[$i], 6, '', 0, 0, $lor[$i]);
+                $i++;
+                $pdf->Cell($width[$i], 6, '', 0, 0, $lor[$i]);
+                $i++;
+                $pdf->Cell($width[$i], 6, 'Total du compte '.$Poste->id, 0, 0, 
'R');
+                $i++;
+                $pdf->Cell($width[$i], 6, ($solde_d  > 0 ? nbm($solde_d)  : 
''), 0, 0, $lor[$i]);
+                $i++;
+                $pdf->Cell($width[$i], 6, ($solde_c  > 0 ? nbm( $solde_c)  : 
''), 0, 0, $lor[$i]);
+                $i++;
+                $pdf->Cell($width[$i], 6, nbm(abs($solde_c-$solde_d)), 0, 0, 
$lor[$i]);
+                $i++;
+                $pdf->Cell(5, 6, ($solde_c > $solde_d ? 'C' : 'D'), 0, 0, 'L');
+                /*
+                * reset total and current_exercice
+                */
+                $current_exercice=$detail['p_exercice'];
+                $solde = 0.0;
+                $solde_d = 0.0;
+                $solde_c = 0.0;
+                $pdf->Ln();
+                $pdf->SetFont('DejaVuCond','',7);
+
+            }
+
+        if ($detail['cred_montant'] > 0)
+        {
+            $solde   = bcsub ($solde,$detail['cred_montant']);
+            $solde_c = bcadd($solde_c,$detail['cred_montant']);
+        }
+        if ($detail['deb_montant'] > 0)
+        {
+            $solde   = bcadd($solde,$detail['deb_montant']);
+            $solde_d = bcadd($solde_d,$detail['deb_montant']);
+        }
+
+        $i = 0;
+               $side=" ".$Poste->get_amount_side($solde);
+        $pdf->LongLine($width[$i], 6, shrink_date($detail['j_date_fmt']), 0, 
$lor[$i]);
+        $i++;
+        $pdf->LongLine($width[$i], 6, $detail['jr_internal'], 0, $lor[$i] );
+        $i++;
+        /* limit set to 40 for the substring */
+        $triple_point = (mb_strlen($detail['description']) > 40 ) ? '...':'';
+        $pdf->LongLine($width[$i], 6, 
mb_substr($detail['description'],0,40).$triple_point, 0,$lor[$i]);
+        $i++;
+        $pdf->Cell($width[$i], 6, $detail['jr_pj_number'], 0, 0, $lor[$i]);
+        $i++;
+        $pdf->Cell($width[$i], 6, 
($detail['letter']!=-1)?$detail['letter']:'', 0, 0, $lor[$i]);
+        $i++;
+        $pdf->Cell($width[$i], 6, ($detail['deb_montant']  > 0 ? nbm( 
$detail['deb_montant'])  : ''), 0, 0, $lor[$i]);
+        $i++;
+        $pdf->Cell($width[$i], 6, ($detail['cred_montant'] > 0 ? nbm( 
$detail['cred_montant']) : ''), 0, 0, $lor[$i]);
+        $i++;
+        $pdf->Cell($width[$i], 6, nbm(abs( $solde)).$side, 0, 0, $lor[$i]);
+        $i++;
+        $pdf->Ln();
+
+    }
+
+
+    $pdf->SetFont('DejaVuCond','B',8);
+
+    $i = 0;
+    $pdf->Cell($width[$i], 6, $current_exercice, 0, 0, $lor[$i]);
+    $i++;
+    $pdf->Cell($width[$i], 6, '', 0, 0, $lor[$i]);
+    $i++;
+    $pdf->Cell($width[$i], 6, '', 0, 0, $lor[$i]);
+    $i++;
+    $pdf->Cell($width[$i], 6, '', 0, 0, $lor[$i]);
+    $i++;
+    $pdf->Cell($width[$i], 6, 'Total du compte '.$Poste->id, 0, 0, 'R');
+    $i++;
+    $pdf->Cell($width[$i], 6, ($solde_d  > 0 ? nbm($solde_d)  : ''), 0, 0, 
$lor[$i]);
+    $i++;
+    $pdf->Cell($width[$i], 6, ($solde_c  > 0 ? nbm( $solde_c)  : ''), 0, 0, 
$lor[$i]);
+    $i++;
+    $pdf->Cell($width[$i], 6, nbm(abs($solde_c-$solde_d)), 0, 0, $lor[$i]);
+    $i++;
+    $pdf->Cell(5, 6, ($solde_c > $solde_d ? 'C' : 'D'), 0, 0, 'L');
+
+    $pdf->Ln();
+    $pdf->Ln();
+
+}
+//Save PDF to file
+$pdf->Output("gl_comptes.pdf", 'D');
+exit;
+?>
diff --git a/include/export_histo_csv.php b/include/export/export_histo_csv.php
similarity index 100%
rename from include/export_histo_csv.php
rename to include/export/export_histo_csv.php
diff --git a/include/export/export_ledger_csv.php 
b/include/export/export_ledger_csv.php
new file mode 100644
index 0000000..240f9c4
--- /dev/null
+++ b/include/export/export_ledger_csv.php
@@ -0,0 +1,284 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+// Copyright Author Dany De Bontridder address@hidden
+/*! \file
+ * \brief Send a ledger in CSV format
+ */
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+$fDate = date('dmy-Hi');
+header('Pragma: public');
+header('Content-type: application/csv');
+header('Content-Disposition: attachment;filename="jrn-'.$fDate.'.csv"',FALSE);
+include_once ("lib/ac_common.php");
+require_once NOALYSS_INCLUDE.'/class/class_own.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_ledger_sold.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_ledger_purchase.php';
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+$gDossier=dossier::id();
+
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_ledger.php';
+
+/*
+ * Variable from $_GET
+ */
+$get_jrn=HtmlInput::default_value_get('jrn_id', -1);
+$get_option=HtmlInput::default_value_get('p_simple', -1);
+$get_from_periode=  HtmlInput::default_value_get('from_periode', null);
+$get_to_periode=HtmlInput::default_value_get('to_periode', NULL);
+
+//--- Check validity
+if ( $get_jrn ==-1  || $get_option == -1 || $get_from_periode == null || 
$get_to_periode == null)
+{
+    die (_('Options invalides'));
+}
+
+
+require_once  NOALYSS_INCLUDE.'/class/class_user.php';
+$g_user->Check();
+$g_user->check_dossier($gDossier);
+
+//----------------------------------------------------------------------------
+// $get_jrn == 0 when request for all ledger, in that case, we must filter
+// the legder with the security in Acc_Ledger::get_row
+//----------------------------------------------------------------------------
+if ($get_jrn!=0 &&  $g_user->check_jrn($get_jrn) =='X')
+{
+    NoAccess();
+    exit();
+}
+
+$Jrn=new Acc_Ledger($cn,$get_jrn);
+
+$Jrn->get_name();
+$jrn_type=$Jrn->get_type();
+
+//
+// With Detail per item which is possible only for VEN or ACH
+// 
+if ($get_option == 2)
+{
+    if ($jrn_type != 'ACH' && $jrn_type != 'VEN' || $Jrn->id == 0)
+    {
+        $get_option = 0;
+    }
+    else
+    {
+        switch ($jrn_type)
+        {
+            case 'VEN':
+                $ledger = new Acc_Ledger_Sold($cn, $get_jrn);
+                $ret_detail = $ledger->get_detail_sale($get_from_periode, 
$get_to_periode);
+                $a_heading= Acc_Ledger_Sold::heading_detail_sale();
+                
+                break;
+            case 'ACH':
+                $ledger = new Acc_Ledger_Purchase($cn, $get_jrn);
+                $ret_detail = $ledger->get_detail_purchase($get_from_periode, 
$get_to_periode);
+                $a_heading=  Acc_Ledger_Purchase::heading_detail_purchase();
+                break;
+            default:
+                die(__FILE__ . ":" . __LINE__ . 'Journal invalide');
+                break;
+        }
+        if ($ret_detail == null)
+            return;
+        $nb = Database::num_row($ret_detail);
+        $output=fopen("php://output","w");
+        
+        for ($i = 0;$i < $nb ; $i++) {
+            $row=Database::fetch_array($ret_detail, $i);
+            if ( $i == 0 ) {
+              fputcsv($output,$a_heading,';');
+            }
+            $a_row=array();
+            for ($j=0;$j < count($row) / 2;$j++) {
+                $a_row[]=$row[$j];
+            }
+            fputcsv($output,$a_row,';');
+            unset($a_row);
+        }
+    }
+}
+//-----------------------------------------------------------------------------
+// Detailled printing
+// For miscellaneous legder or all ledgers
+//-----------------------------------------------------------------------------
+if  ( $get_option == 0 )
+{
+    $Jrn->get_row( $get_from_periode, $get_to_periode );
+
+    if ( count($Jrn->row) == 0)
+        exit;
+    foreach ( $Jrn->row as $op )
+    {
+        // should clean description : remove <b><i> tag and '; char
+        $desc=$op['description'];
+        $desc=str_replace("<b>","",$desc);
+        $desc=str_replace("</b>","",$desc);
+        $desc=str_replace("<i>","",$desc);
+        $desc=str_replace("</i>","",$desc);
+        $desc=str_replace('"',"'",$desc);
+        $desc=str_replace(";",",",$desc);
+
+        printf("\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";%s;%s\n",
+               $op['j_id'],
+               $op['jr_pj_number'],
+               $op['internal'],
+               $op['j_date'],
+               $op['poste'],
+               $desc,
+               nb($op['deb_montant']),
+               nb($op['cred_montant'])
+              );
+
+    }
+    exit;
+}
+//-----------------------------------------------------------------------------
+// Detail printing for ACH or VEN : 1 row resume the situation with VAT, DNA
+// for Misc the amount 
+// For Financial only the tiers and the sign of the amount
+//-----------------------------------------------------------------------------
+if  ($get_option == 1)
+{
+   
+//-----------------------------------------------------
+     if ( $jrn_type == 'ODS' || $jrn_type == 'FIN' || $jrn_type=='GL')
+       {
+          $Row=$Jrn->get_rowSimple($get_from_periode,
+                             $get_to_periode,
+                             0);
+        printf ('" operation";'.
+                '"Date";'.
+                '"N° Pièce";'.
+                '"Tiers";'.
+                '"commentaire";'.
+                '"internal";'.
+                '"montant";'.
+                "\r\n");
+        foreach ($Row as $line)
+          {
+
+            echo $line['num'].";";
+            echo $line['date'].";";
+            echo $line['jr_pj_number'].";";
+            echo $Jrn->get_tiers($line['jrn_def_type'],$line['jr_id']).";";
+            echo $line['comment'].";";
+            echo $line['jr_internal'].";";
+            //   echo "<TD>".$line['pj'].";";
+            // If the ledger is financial :
+            // the credit must be negative and written in red
+            // Get the jrn type
+            if ( $line['jrn_def_type'] == 'FIN' ) {
+              $positive = $cn->get_value("select qf_amount from quant_fin  ".
+                                         " where jr_id=".$line['jr_id']);
+
+              echo nb($positive);
+              echo ";";
+            }
+            else
+              {
+                echo nb($line['montant']).";";
+              }
+
+            printf("\r\n");
+          }
+       }
+
+//------------------------------------------------------------------------------
+// One line summary with tiers, amount VAT, DNA, tva code ....
+// 
+//------------------------------------------------------------------------------
+    if ( $jrn_type=='ACH' || $jrn_type=='VEN')
+    {
+        $Row=$Jrn->get_rowSimple($get_from_periode,
+                             $get_to_periode,
+                             0);
+        $cn->prepare('reconcile_date',"select to_char(jr_date,'DD.MM.YY') as 
str_date,* "
+                . "from jrn "
+                . "where "
+                . "jr_id in (select jra_concerned from jrn_rapt where jr_id = 
$1 union all select jr_id from jrn_rapt where jra_concerned=$1)");
+
+        $own=new Own($cn);
+        $col_tva="";
+
+        if ( $own->MY_TVA_USE=='Y')
+        {
+            $a_Tva=$cn->get_array("select tva_id,tva_label from tva_rate order 
by tva_rate,tva_label,tva_id");
+            foreach($a_Tva as $line_tva)
+            {
+                $col_tva.='"Tva '.$line_tva['tva_label'].'";';
+            }
+        }
+        echo 
'"Date";"Paiement";"operation";"Pièce";"Client/Fourn.";"Commentaire";"inter.";"HTVA";"privé";"DNA";"tva
 non ded.";"TVA NP";'.$col_tva.'"TVAC";"opérations liées"'."\n\r";
+        foreach ($Row as $line)
+        {
+            printf('"%s";"%s";"%s";"%s";"%s";%s;%s;%s;%s;%s;%s;%s;',
+                   $line['date'],
+                   $line['date_paid'],
+                   $line['num'],
+                   $line['jr_pj_number'],
+                   $Jrn->get_tiers($line['jrn_def_type'],$line['jr_id']),
+                   $line['comment'],
+                   $line['jr_internal'],
+                   nb($line['HTVA']),
+                   nb($line['dep_priv']),
+                   nb($line['dna']),
+                   nb($line['tva_dna']),
+                    nb($line['tva_np'])
+                   );
+            $a_tva_amount=array();
+            //- set all TVA to 0
+            foreach ($a_Tva as $l) {
+                $t_id=$l["tva_id"];
+                $a_tva_amount[$t_id]=0;
+            }
+            foreach ($line['TVA'] as $lineTVA)
+            {
+                $idx_tva=$lineTVA[1][0];
+                $a_tva_amount[$idx_tva]=$lineTVA[1][2];
+             }
+            if ($own->MY_TVA_USE == 'Y' )
+            {
+                foreach ($a_Tva as $line_tva)
+                {
+                    $a=$line_tva['tva_id'];
+                    echo nb($a_tva_amount[$a]).';';
+                }
+            }
+            echo nb ($line['TVAC']);
+            /**
+             * Retrieve payment if any
+             */
+             
$ret_reconcile=$cn->execute('reconcile_date',array($line['jr_id']));
+             $max=Database::num_row($ret_reconcile);
+            if ($max > 0) {
+                $sep=";";
+                for ($e=0;$e<$max;$e++) {
+                    $row=Database::fetch_array($ret_reconcile, $e);
+                    echo $sep.$row['str_date'].'; '. $row['jr_internal'];
+                }
+            }
+           printf("\r\n");
+
+        }
+    }
+}
+?>
diff --git a/include/export/export_ledger_pdf.php 
b/include/export/export_ledger_pdf.php
new file mode 100644
index 0000000..5722d7a
--- /dev/null
+++ b/include/export/export_ledger_pdf.php
@@ -0,0 +1,79 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+
+// Copyright Author Dany De Bontridder address@hidden
+/* ! \file
+ * \brief Send a ledger in a pdf format
+ *
+ */
+if (!defined('ALLOWED'))
+    die('Appel direct ne sont pas permis');
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+$gDossier = dossier::id();
+require_once NOALYSS_INCLUDE.'/lib/lib/class_pdf.php';
+require_once NOALYSS_INCLUDE.'/class/class_user.php';
+require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/lib/class_impress.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_ledger.php';
+require_once NOALYSS_INCLUDE.'/class/class_own.php';
+require_once NOALYSS_INCLUDE.'/class/class_periode.php';
+require_once NOALYSS_INCLUDE.'/class/class_print_ledger.php';
+
+
+$cn = new Database($gDossier);
+$periode = new Periode($cn);
+
+$l_type = "JRN";
+$own = new Own($cn);
+
+$Jrn = new Acc_Ledger($cn, $_GET['jrn_id']);
+
+$Jrn->get_name();
+$g_user->Check();
+$g_user->check_dossier($gDossier);
+
+// Security
+if ($_GET['jrn_id'] != 0 && $g_user->check_jrn($_GET['jrn_id']) == 'X') {
+    /* Cannot Access */
+    NoAccess();
+}
+
+$ret = "";
+
+$jrn_type = $Jrn->get_type();
+
+$pdf = Print_Ledger::factory($cn, $_REQUEST['p_simple'], "PDF", $Jrn);
+
+$pdf->setDossierInfo($Jrn->name);
+$pdf->AliasNbPages();
+$pdf->AddPage();
+$pdf->SetAuthor('NOALYSS');
+$pdf->setTitle(_("Journal"), true);
+
+$pdf->export();
+
+$fDate = date('dmy-Hi');
+$pdf->Output('journal-' . $fDate . '.pdf', 'D');
+exit(0);
+
+
+?>
diff --git a/include/export/export_poste_detail_csv.php 
b/include/export/export_poste_detail_csv.php
new file mode 100644
index 0000000..27277c9
--- /dev/null
+++ b/include/export/export_poste_detail_csv.php
@@ -0,0 +1,194 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+// Copyright Author Dany De Bontridder address@hidden
+/*! \file
+ * \brief Send the poste list in csv
+ */
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_account_ledger.php';
+require_once  NOALYSS_INCLUDE.'/class/class_acc_operation.php';
+$fDate=date('dmy-Hi');
+header('Pragma: public');
+header('Content-type: application/csv');
+header('Content-Disposition: 
attachment;filename="poste-'.$fDate.'-'.$_REQUEST['poste_id'].'.csv"',FALSE);
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+$gDossier=dossier::id();
+
+/* Admin. Dossier */
+$cn=new Database($gDossier);
+
+if ( isset ( $_REQUEST['poste_fille']) )
+{ //choisit de voir tous les postes
+  $a_poste=$cn->get_array("select pcm_val from tmp_pcmn where pcm_val::text 
like $1||'%'",array($_REQUEST["poste_id"]));
+}
+else
+{
+  $a_poste=$cn->get_array("select pcm_val from tmp_pcmn where pcm_val = 
$1",array($_REQUEST['poste_id']));
+}
+bcscale(2);
+if ( ! isset ($_REQUEST['oper_detail']))
+{
+    if ( count($a_poste) == 0 )
+        exit;
+
+    foreach ($a_poste as $pos)
+    {
+        $Poste=new Acc_Account_Ledger($cn,$pos['pcm_val']);
+        $name=$Poste->get_name();
+        list($array,$tot_deb,$tot_cred)=$Poste->get_row_date( 
$_REQUEST['from_periode'],
+                                                             
$_REQUEST['to_periode'],
+                                                             $_GET['ople']
+                                                             );
+        if ( count($Poste->row ) == 0 )
+            continue;
+
+        echo '"Poste";'.
+         '"n° pièce";'.
+         '"Code journal";'.
+         '"Nom journal";'.
+         '"Lib.";'.
+        "\"Code interne\";".
+        "\"Date\";".
+        "\"Description\";".
+        "\"Débit\";".
+        "\"Crédit\";".
+        "\"Prog.\";".
+               "\"Let.\"";
+        printf("\n");
+
+        $prog=0;
+        $current_exercice="";
+        $tot_cred=0;
+        $tot_deb=0;
+        $diff=0;
+        foreach ( $Poste->row as $op )
+        {
+           /*
+             * separation per exercice
+             */
+            if ( $current_exercice == "") $current_exercice=$op['p_exercice'];
+            
+            if ( $current_exercice != $op['p_exercice']) {
+                $solde_type=($tot_deb>$tot_cred)?"solde débiteur":"solde 
créditeur";
+                $diff=abs($tot_deb-$tot_cred);
+                printf(
+                     ";;;".
+                     '"'._('total').'";'.
+                     '"'.$current_exercice.'";'.
+                '"'."$solde_type".'"'.";".
+                nb($tot_deb).";".
+                nb($tot_cred).";".
+                nb($diff).";"."\n");
+                /*
+                * reset total and current_exercice
+                */
+                $prog=0;
+                $current_exercice=$op['p_exercice'];
+                $tot_deb=0;$tot_cred=0;    
+            }
+          $tot_deb=bcadd($tot_deb,$op['deb_montant']);
+          $tot_cred=bcadd($tot_cred,$op['cred_montant']);
+         $diff=bcsub($op['deb_montant'],$op['cred_montant']);
+         $prog=bcadd($prog,$diff);
+         echo '"'.$pos['pcm_val'].'";'.
+           '"'.$op['jr_pj_number'].'"'.";".
+           '"'.$op['jrn_def_code'].'"'.";".
+           '"'.$op['jrn_def_name'].'"'.";".
+            '"'.$name.'";'.
+            '"'.$op['jr_internal'].'"'.";".
+            '"'.$op['j_date_fmt'].'"'.";".
+            '"'.$op['description'].'";'.
+            nb($op['deb_montant']).";".
+            nb($op['cred_montant']).";".
+            nb(abs($prog)).";".
+                       
(($op['letter']!=-1)?strtoupper(base_convert($op['letter'],10,36)):"");
+            printf("\n");
+
+
+        }
+        $solde_type=($tot_deb>$tot_cred)?"solde débiteur":"solde créditeur";
+        $diff=abs($tot_deb-$tot_cred);
+       printf(
+                         ";;;".
+                         '"'._('total').'";'.
+                         '"'.$current_exercice.'";'.
+            '"'."$solde_type".'"'.";".
+            nb($tot_deb).";".
+            nb($tot_cred).";".
+            nb($diff).";"."\n");
+    }
+}
+else
+{
+    /* detail of all operation */
+    if ( count($a_poste) == 0 )
+        exit;
+
+    foreach ($a_poste as $pos)
+    {
+        $Poste=new Acc_Account_Ledger($cn,$pos['pcm_val']);
+        $Poste->get_name();
+        list($array,$tot_deb,$tot_cred)=$Poste->get_row_date( 
$_REQUEST['from_periode'],
+                                        $_REQUEST['to_periode'],
+                                                                             
$_GET['ople']
+                                                            );
+        if ( count($Poste->row ) == 0 )
+            continue;
+
+        echo '"Poste";'.
+        '"Lib.";'.
+        '"QuickCode";'.
+        "\"Code interne\";".
+        "\"Date\";".
+        "\"Description\";".
+        "\"Montant\";".
+        "\"D/C\"";
+        printf("\n");
+
+
+        foreach ( $Poste->row as $a )
+        {
+            $op=new Acc_Operation($cn);
+            $op->jr_id=$a['jr_id'];
+            $result=$op->get_jrnx_detail();
+            foreach ( $result as $r)
+            {
+                printf('"%s";"%s";"%s";"%s";"%s";"%s";"%s";%12.2f;"%s"',
+                       $r['j_poste'],
+                       $r['pcm_lib'],
+                       $r['j_qcode'],
+                       $r['jr_internal'],
+                       $r['jr_date'],
+                       $a['description'],
+                       $a['jr_pj_number'],
+                       nb($r['j_montant']),
+                       $r['debit']);
+                printf("\r\n");
+
+            }
+
+
+
+        }
+    }
+    exit;
+}
+?>
diff --git a/include/export/export_poste_detail_pdf.php 
b/include/export/export_poste_detail_pdf.php
new file mode 100644
index 0000000..c9bebc2
--- /dev/null
+++ b/include/export/export_poste_detail_pdf.php
@@ -0,0 +1,241 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+/*! \file
+ * \brief send the account list in PDF
+ */
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+require_once NOALYSS_INCLUDE.'/class/class_acc_account_ledger.php';
+require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/lib/class_impress.php';
+require_once NOALYSS_INCLUDE.'/header_print.php';
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+require_once NOALYSS_INCLUDE.'/class/class_user.php';
+require_once NOALYSS_INCLUDE.'/lib/lib/class_pdf.php';
+
+$gDossier=dossier::id();
+
+/* Security */
+$cn=new Database($gDossier);
+extract($_GET);
+
+if ( isset ( $poste_fille) )
+{ //choisit de voir tous les postes
+    $a_poste=$cn->get_array("select pcm_val from tmp_pcmn where pcm_val::text 
like '$poste_id%' order by pcm_val");
+}
+else
+    $a_poste=$cn->get_array("select pcm_val from tmp_pcmn where pcm_val::text 
= '$poste_id'");
+
+
+$ret="";
+
+$pdf=new PDF($cn);
+$pdf->setDossierInfo("  Periode : ".$_GET['from_periode']." - 
".$_GET['to_periode']);
+$pdf->AliasNbPages();
+$pdf->AddPage();
+$pdf->SetAuthor('NOALYSS');
+$pdf->setTitle("Détail poste comptable",true);
+
+
+if ( count($a_poste) == 0 )
+{
+    $pdf->Output('poste.pdf','D');
+    exit;
+}
+$size=array(13,25,13,65,12,20,20,20);
+$align=array('L','C','C','L','R','R','R','R');
+
+foreach ($a_poste as $poste)
+{
+    $Poste=new Acc_Account_Ledger($cn,$poste['pcm_val']);
+    
list($array,$tot_deb,$tot_cred)=$Poste->get_row_date($from_periode,$to_periode,$_GET['ople']);
+    // don't print empty account
+    if ( count($array) == 0 )
+    {
+        continue;
+    }
+    $Libelle=sprintf("(%s) %s ",$Poste->id,$Poste->get_name());
+    $pdf->SetFont('DejaVuCond','',10);
+    $pdf->Cell(0,8,$Libelle,1,0,'C');
+    $pdf->Ln();
+
+    $pdf->SetFont('DejaVuCond','',8);
+    $l=0;
+    $pdf->Cell($size[$l],6,'Date',0,0,'L');
+    $l++;
+    $pdf->Cell($size[$l],6,'Ref',0,0,'C');
+    $l++;
+    $pdf->Cell($size[$l],6,'Journal',0,0,'C');
+    $l++;
+    $pdf->LongLine($size[$l],6,'Libellé',0,'L');
+    $l++;
+    $pdf->Cell($size[$l],6,'Let',0,0,'R');
+    $l++;
+    $pdf->Cell($size[$l],6,'Debit',0,0,'R');
+    $l++;
+    $pdf->Cell($size[$l],6,'Credit',0,0,'R');
+    $l++;
+    $pdf->Cell($size[$l],6,'Prog',0,0,'R');
+    $l++;
+    $pdf->ln();
+    $tot_deb=0;
+    $tot_cred=0;
+    $prog=0;
+    $current_exercice="";
+    bcscale(2);
+    for ($e=0;$e<count($array);$e++)
+    {
+        $row=$array[$e];
+         /*
+             * separation per exercice
+             */
+            if ( $current_exercice == "") $current_exercice=$row['p_exercice'];
+            
+            if ( $current_exercice != $row['p_exercice']) {
+                    $str_debit=sprintf("% 12.2f €",$tot_deb);
+                    $str_credit=sprintf("% 12.2f €",$tot_cred);
+                    $diff_solde=bcsub($tot_deb,$tot_cred);
+                    if ( $diff_solde < 0 )
+                    {
+                        $solde=" créditeur ";
+                        $diff_solde=bcmul($diff_solde,-1);
+                    }
+                    else
+                    {
+                         $solde=" débiteur ";
+                    }
+                    $str_diff_solde=sprintf("%12.2f €",$diff_solde);
+
+                    $pdf->SetFont('DejaVu','B',8);
+                    $pdf->Cell(15,6,_('totaux'),0,0,'L');
+                    $pdf->Cell(15,6,$current_exercice,0,0,'L');
+                    $pdf->Cell(40,6,$solde,0,'L');
+                    $pdf->Cell(40,6,$str_debit,0,0,'R');
+                    $pdf->Cell(40,6,$str_credit,0,0,'R');
+                    $pdf->Cell(40,6,$str_diff_solde,0,0,'R');
+                    $pdf->Ln();
+                    /*
+                    * reset total and current_exercice
+                    */
+                    $prog=0;
+                    $current_exercice=$row['p_exercice'];
+                    $tot_deb=0;$tot_cred=0;    
+                    $pdf->SetFont('DejaVuCond','',8);
+            }
+        $l=0;
+        $diff=bcsub($row['deb_montant'],$row['cred_montant']);
+        $prog=bcadd($row['deb_montant'],$row['cred_montant']);
+
+        $date=shrink_date($row['j_date_fmt']);
+        $pdf->Cell($size[$l],6,$date,0,0,$align[$l]);
+        $l++;
+       if ( $row['jr_pj_number'] == '')
+         $pdf->Cell($size[$l],6,$row['jr_internal'],0,0,$align[$l]);
+       else
+         $pdf->Cell($size[$l],6,$row['jr_pj_number'],0,0,$align[$l]);
+        $l++;
+        
$pdf->Cell($size[$l],6,mb_substr($row['jrn_def_code'],0,14),0,0,$align[$l]);
+        $l++;
+        $pdf->LongLine($size[$l],6,  $row['description'],0,$align[$l]);
+        $l++;
+        
$pdf->Cell($size[$l],6,(($row['letter']!=-1)?$row['letter']:''),0,0,$align[$l]);
+        $l++;
+        $pdf->Cell($size[$l],6,(sprintf('% 
12.2f',$row['deb_montant'])),0,0,$align[$l]);
+        $l++;
+        $pdf->Cell($size[$l],6,(sprintf('% 
12.2f',$row['cred_montant'])),0,0,$align[$l]);
+        $l++;
+        $pdf->Cell($size[$l],6,(sprintf('% 12.2f',abs($prog))),0,0,$align[$l]);
+        $l++;
+        $pdf->ln();
+        $tot_deb=bcadd($tot_deb,$row['deb_montant']);
+        $tot_cred=bcadd($tot_deb,$row['cred_montant']);
+        /* -------------------------------------- */
+        /* if details are asked we show them here */
+        /* -------------------------------------- */
+        if ( isset($_GET['oper_detail']))
+        {
+            $detail=new Acc_Operation($cn);
+            $detail->jr_id=$row['jr_id'];
+            $a_detail=$detail->get_jrnx_detail();
+            for ($f=0;$f<count($a_detail);$f++)
+            {
+                $l=0;
+                $pdf->Cell($size[$l],6,'',0,0,$align[$l]);
+                $l++;
+                
$pdf->Cell($size[$l],6,$a_detail[$f]['j_qcode'],0,0,$align[$l]);
+                $l++;
+                
$pdf->Cell($size[$l],6,$a_detail[$f]['j_poste'],0,0,$align[$l]);
+                $l++;
+                if ( $a_detail[$f]['j_qcode']=='')
+                    $lib=$a_detail[$f]['pcm_lib'];
+                else
+                {
+                    $f_id=$cn->get_value('select f_id from vw_poste_qcode 
where j_qcode=$1',array($a_detail[$f]['j_qcode'])) ;
+                    $lib=$cn->get_value('select ad_value from fiche_detail 
where ad_id=$1 and f_id=$2',
+                                        array(ATTR_DEF_NAME,$f_id));
+                }
+                $pdf->Cell($size[$l],6,$lib,0,0,$align[$l]);
+                $l++;
+                
$pdf->Cell($size[$l],6,(($a_detail[$f]['letter']!=-1)?$a_detail[$f]['letter']:''),0,0,$align[$l]);
+                $l++;
+
+                
$deb=($a_detail[$f]['debit']=='D')?$a_detail[$f]['j_montant']:'';
+                
$cred=($a_detail[$f]['debit']=='C')?$a_detail[$f]['j_montant']:'';
+
+                $pdf->Cell($size[$l],6,(sprintf('% 
12.2f',$deb)),0,0,$align[$l]);
+                $l++;
+                $pdf->Cell($size[$l],6,(sprintf('% 
12.2f',$cred)),0,0,$align[$l]);
+                $l++;
+                $pdf->ln();
+            }
+        }
+    }
+    $str_debit=sprintf("% 12.2f €",$tot_deb);
+    $str_credit=sprintf("% 12.2f €",$tot_cred);
+    $diff_solde=$tot_deb-$tot_cred;
+    if ( $diff_solde < 0 )
+    {
+        $solde=" créditeur ";
+        $diff_solde=bcmul($diff_solde,-1);
+    }
+    else
+    {
+        $solde=" débiteur ";
+    }
+    $str_diff_solde=sprintf("%12.2f €",$diff_solde);
+
+    $pdf->SetFont('DejaVu','B',8);
+
+    $pdf->Cell(160,5,'Débit',0,0,'R');
+    $pdf->Cell(30,5,$str_debit,0,0,'R');
+    $pdf->Ln();
+    $pdf->Cell(160,5,'Crédit',0,0,'R');
+    $pdf->Cell(30,5,$str_credit,0,0,'R');
+    $pdf->Ln();
+    $pdf->Cell(160,5,'Solde '.$solde,0,0,'R');
+    $pdf->Cell(30,5,$str_diff_solde,0,0,'R');
+    $pdf->Ln();
+
+}
+$fDate=date('dmy-Hi');
+$pdf->Output('poste-'.$fDate.'-'.$poste_id.'.pdf','D');
+?>
diff --git a/include/export/export_rec_csv.php 
b/include/export/export_rec_csv.php
new file mode 100644
index 0000000..00e3198
--- /dev/null
+++ b/include/export/export_rec_csv.php
@@ -0,0 +1,39 @@
+<?php
+//This file is part of NOALYSS and is under GPL 
+//see licence.txt
+
+/**
+ * Export to CSV the operations asked in impress_rec.inc.php
+ * variable set $g_user,$cn
+ * @see impress_rec.inc.php
+ */
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+$Date=date('Ymd');
+$filename="reconcialed_operation-".$Date;
+
+header('Pragma: public');
+header('Content-type: application/csv');
+header('Content-Disposition: attachment;filename="'.$filename.'.csv"',FALSE);
+
+require_once NOALYSS_INCLUDE.'/class/class_acc_reconciliation.php';
+require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+// --------------------------
+// Check if all mandatory arg are passed
+foreach (array('choice','p_end','p_start') as $arg)
+{
+    if ( ! isset ($_GET[$arg])) {
+        die ("argument [".$arg."] is missing");
+    }
+}
+extract($_GET);
+$r_jrn=(isset($r_jrn))?$r_jrn:'';
+// -------------------------
+// Create object and export
+$acc_reconciliation=new Acc_Reconciliation($cn);
+$acc_reconciliation->a_jrn=$r_jrn;
+$acc_reconciliation->start_day=$p_start;
+$acc_reconciliation->end_day=$p_end;
+
+$array=$acc_reconciliation->export_csv($choice);
\ No newline at end of file
diff --git a/include/export/export_reportinit_csv.php 
b/include/export/export_reportinit_csv.php
new file mode 100644
index 0000000..5b7ef43
--- /dev/null
+++ b/include/export/export_reportinit_csv.php
@@ -0,0 +1,56 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief export definition of a report
+ */
+
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+require_once   NOALYSS_INCLUDE.'/constant.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once  NOALYSS_INCLUDE.'/lib/user_common.php';
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_report.php';
+require_once NOALYSS_INCLUDE.'/class/class_user.php';
+if ( ! isset($_GET['gDossier']) ||
+        ! isset($_GET['f']) )
+{
+    $a='Paramètre manquant';
+    header("Content-type: text/html; charset: utf8",true);
+    print $a;
+    exit();
+}
+
+$gDossier=dossier::id();
+if ( ! is_dir('tmp') )
+{
+    mkdir ('tmp');
+}
+
+$cn=new Database($gDossier);
+$rap=new Acc_Report($cn,$_GET['f']);
+
+$file= fopen('php://output',"a+");
+header('Pragma: public');
+header('Content-type: application/bin');
+header('Content-Disposition: attachment;filename="export.bin"',FALSE);
+$rap->export_csv($file);
+?>
diff --git a/include/export/export_security_pdf.php 
b/include/export/export_security_pdf.php
new file mode 100755
index 0000000..11f0def
--- /dev/null
+++ b/include/export/export_security_pdf.php
@@ -0,0 +1,178 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+// Copyright Stanislas Pinte address@hidden
+
+/*! \file
+ * \brief Print the user security in pdf
+ */
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+$gDossier=dossier::id();
+require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/lib/lib/class_pdf.php';
+$cn=new Database($gDossier);
+//-----------------------------------------------------
+// Security
+
+// Check User
+$rep=new Database();
+require_once  NOALYSS_INCLUDE.'/class/class_user.php';
+$User=new User($rep);
+
+//-----------------------------------------------------
+// Get User's info
+if ( ! isset($_GET['user_id']) )
+    return;
+
+$SecUser=new User($rep,$_GET['user_id']);
+$admin=0;
+$access=$SecUser->get_folder_access($gDossier);
+
+if ( $access == 'L')
+{
+    $str='Local Admin';
+    $admin=1;
+}
+elseif ($access=='R')
+{
+    $str=' Utilisateur normal';
+}
+elseif ($access=='P')
+{
+    $str=' Extension uniquement';
+}
+
+
+if ( $SecUser->admin==1 )
+{
+    $str=' Super Admin';
+    $admin=1;
+}
+
+
+//-----------------------------------------------------
+// Print result
+
+$pdf=new PDF($cn);
+$pdf->setDossierInfo(dossier::name().' Sécurité');
+$pdf->AliasNbPages();
+$pdf->AddPage();
+$pdf->SetAuthor('NOALYSS');
+$pdf->setTitle("Sécurité",true);
+
+$str_user=sprintf("( %d ) %s %s [ %s ] - %s",
+                  $SecUser->id,
+                  $SecUser->first_name,
+                  $SecUser->name,
+                  $SecUser->login,
+                  $str);
+
+$pdf->SetFont('DejaVu','B',9);
+$pdf->Cell(0,7,$str_user,'B',0,'C');
+$pdf->Ln();
+if ( $SecUser->active==0)
+{
+    $pdf->SetTextColor(255,0,34);
+    $pdf->Cell(0,7,'Bloqué',0,0,'R');
+    $pdf->Ln();
+}
+
+if ( $SecUser->admin==1)
+{
+    $pdf->SetTextColor(0,0,0);
+    $pdf->setFillColor(239,251,255);
+    $pdf->Cell(40,7,'Administrateur',1,1,'R');
+    $pdf->Ln();
+}
+$pdf->SetTextColor(0,0,0);
+
+//-----------------------------------------------------
+// Journal
+$pdf->Cell(0,7,'Accès journaux',1,0,'C');
+$pdf->Ln();
+$pdf->SetFont('DejaVu','',6);
+$Res=$cn->exec_sql("select jrn_def_id,jrn_def_name  from jrn_def ");
+$SecUser->db=$cn;
+for ($e=0;$e < Database::num_row($Res);$e++)
+{
+    $row=Database::fetch_array($Res,$e);
+    $pdf->Cell(40,6,$row['jrn_def_name']);
+    $priv=$SecUser->check_jrn($row['jrn_def_id']);
+    switch($priv)
+    {
+    case 'X':
+            $pdf->SetTextColor(255,0,34);
+        $pdf->Cell(30,6,"Pas d'accès");
+        break;
+    case 'R':
+        $pdf->SetTextColor(54,233,0);
+        $pdf->Cell(30,6,"Lecture");
+        break;
+    case 'O':
+        /**
+         *non implemente
+         */
+        $pdf->Cell(30,6,"Opérations prédéfinies uniquement");
+        break;
+    case 'W':
+        $pdf->SetTextColor(54,233,0);
+        $pdf->Cell(30,6,'Ecriture');
+        break;
+    }
+    $pdf->SetTextColor(0);
+    $pdf->Ln();
+}
+
+//-----------------------------------------------------
+// Follow_Up
+$pdf->SetFont('DejaVu','B',9);
+$pdf->Cell(0,7,'Accès action',1,0,'C');
+$pdf->Ln();
+$pdf->SetFont('DejaVu','',6);
+$Res=$cn->exec_sql(
+         "select ac_id, ac_description from action   order by ac_description 
");
+
+$Max=Database::num_row($Res);
+
+for ( $i =0 ; $i < $Max; $i++ )
+{
+    $l_line=Database::fetch_array($Res,$i);
+    $pdf->Cell(90,6,$l_line['ac_description']);
+    $right=$SecUser->check_action($l_line['ac_id']);
+    switch ($right)
+    {
+    case 0:
+        $pdf->SetTextColor(255,0,34);
+
+        $pdf->Cell(30,6,"Pas d'accès");
+        break;
+    case 1:
+    case 2:
+        $pdf->SetTextColor(54,233,0);
+        $pdf->Cell(30,6,"Accès");
+        break;
+    }
+    $pdf->SetTextColor(0);
+
+    $pdf->Ln();
+}
+$fDate=date('dmy-HI');
+$pdf->Output('security-'.$fDate.'pdf','D');
+?>
diff --git a/include/export/export_stock_histo_csv.php 
b/include/export/export_stock_histo_csv.php
new file mode 100644
index 0000000..33a629b
--- /dev/null
+++ b/include/export/export_stock_histo_csv.php
@@ -0,0 +1,63 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/**
+ * @file
+ * @brief export in CSV the export of history
+ *
+ */
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+require_once NOALYSS_INCLUDE.'/class/class_stock.php';
+
+$stock=new Stock($cn);
+$sql = $stock->create_query_histo($_GET);
+$sql .= " order by  real_date asc";
+
+$res=$cn->exec_sql($sql);
+$max_row=Database::num_row($res);
+header('Pragma: public');
+header('Content-type: application/csv');
+header('Content-Disposition: attachment;filename="histo-stock.csv"',FALSE);
+printf('"Date";');
+       printf('"%s";','Code Stock');
+       printf('"%s";','Depot');
+       printf('"%s";','Fiche');
+       printf('"%s";','Commentaire');
+       printf('%s;','Quantité');
+       printf('"%s";','IN/OUT');
+               printf("\n\r");
+for ($i=0;$i<$max_row;$i++)
+{
+       $row=Database::fetch_array($res,$i);
+       printf('"%s";',$row['cdate']);
+       printf('"%s";',$row['sg_code']);
+       printf('"%s";',$row['r_name']);
+       printf('"%s";',$row['qcode']);
+       $row['ccomment']=str_replace('"','',$row['ccomment']);
+       printf('"%s";',$row['ccomment']);
+       printf('%s;',nbm($row['sg_quantity']));
+       printf('"%s";',$row['direction']);
+       printf("\n\r");
+
+}
+
+?>
\ No newline at end of file
diff --git a/include/export/export_stock_resume_list.php 
b/include/export/export_stock_resume_list.php
new file mode 100644
index 0000000..51ca30a
--- /dev/null
+++ b/include/export/export_stock_resume_list.php
@@ -0,0 +1,91 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/**
+ * @file
+ * @brief export in CSV the summary of stock in list
+ *
+ */
+if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
+require_once NOALYSS_INCLUDE.'/class/class_stock.php';
+global $cn;
+// var_dump($_GET);
+$stock=new Stock($cn);
+$tmp_id = $stock->build_tmp_table($_GET);
+
+header('Pragma: public');
+header('Content-type: application/csv');
+header('Content-Disposition: 
attachment;filename="stock-summary-list.csv"',FALSE);
+
+?>
+"Depot";"Adresse";"Ville";"Pays";"Code Stock";"Fiches";"IN";"OUT";"DIFF"
+<?php 
+$a_repo=$cn->get_array("select distinct 
t.r_id,r_name,r_adress,r_city,r_country from stock_repository as s join 
tmp_stockgood_detail as t
+       on (s.r_id=t.r_id)
+       where
+       s_id=$1
+       order by 2
+       ",array($tmp_id));
+ for ($r=0;$r<count($a_repo);$r++):
+
+               $a_stock=$cn->get_array(
+                               "
+                                       select coalesce(sum(s_qin),0) as 
qin,coalesce(sum(s_qout),0) as qout,sg_code
+                                               from tmp_stockgood_detail  
where r_id=$1 and s_id=$2
+                                               group by sg_code
+                                               order by sg_code
+
+                                       ",array($a_repo[$r]['r_id'],$tmp_id));
+               for ($s=0;$s<count($a_stock);$s++):
+
+                       $a_card=$cn->get_array(
+                                       "
+                                               select f_id,vw_name,quick_code
+                                               from vw_fiche_attr
+                                               where
+                                        f_id in (
+                                               select distinct f_id from 
fiche_detail
+                                                       where
+                                                       ad_id=19 and
+                                                       ad_value=$1)
+                                               order by vw_name,quick_code
+                                       ",array($a_stock[$s]['sg_code']));
+
+printf ('"%s";',$a_repo[$r]['r_name']);
+printf ('"%s";',$a_repo[$r]['r_adress']);
+printf ('"%s";',$a_repo[$r]['r_city']);
+printf ('"%s";',$a_repo[$r]['r_country']);
+printf('"%s";',$a_stock[$s]['sg_code']);
+       $sep="";
+                               for ( $c=0;$c<count($a_card);$c++):
+                                       $a=sprintf('[%s] 
%s',$a_card[$c]['quick_code'], $a_card[$c]['vw_name']);
+                                       $sep="  / ";
+                               endfor; // for C
+                               if ( count($a_card)== 0 ) $a= ' Erreur Code non 
utilisé';
+ printf('"%s";',$a);
+ printf('%s;',nbm($a_stock[$s]['qin']));
+ printf('%s;',nbm($a_stock[$s]['qout']));
+ printf ('%s',nbm(bcsub($a_stock[$s]['qin'],$a_stock[$s]['qout'])));
+ printf("\r\n");
+ endfor;
+ endfor;
+
diff --git a/include/export_anc_acc_list_csv.php 
b/include/export_anc_acc_list_csv.php
deleted file mode 100644
index e58d0c2..0000000
--- a/include/export_anc_acc_list_csv.php
+++ /dev/null
@@ -1,36 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
-* \brief  export analytic list in csv
- *
- */
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-header('Pragma: public');
-header('Content-type: application/csv');
-header('Content-Disposition: attachment;filename="export-anc-list.csv"',FALSE);
-
-require_once  NOALYSS_INCLUDE.'/class_anc_acc_list.php';
-
-
-$bal=new Anc_Acc_List($cn);
-$bal->get_request();
-echo $bal->export_csv();
diff --git a/include/export_anc_balance_double_csv.php 
b/include/export_anc_balance_double_csv.php
deleted file mode 100644
index 635a157..0000000
--- a/include/export_anc_balance_double_csv.php
+++ /dev/null
@@ -1,40 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief  export the operation in pdf
- */
-
-/* \brief  export the operation in pdf
- *
- */
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-header('Content-type: application/csv');
-header('Pragma: public');
-header('Content-Disposition: attachment;filename="ca_bal_croise.csv"',FALSE);
-
-require_once  NOALYSS_INCLUDE.'/class_anc_balance_double.php';
-
-$cn=new Database(dossier::id());
-
-$bal=new Anc_Balance_Double($cn);
-$bal->get_request();
-echo $bal->display_csv();
diff --git a/include/export_anc_balance_double_pdf.php 
b/include/export_anc_balance_double_pdf.php
deleted file mode 100644
index 012c68f..0000000
--- a/include/export_anc_balance_double_pdf.php
+++ /dev/null
@@ -1,37 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief export the operation in pdf
- */
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once  NOALYSS_INCLUDE.'/class_anc_balance_double.php';
-require_once  NOALYSS_INCLUDE.'/header_print.php';
-
-$cn=new Database(dossier::id());
-
-
-$balance=new Anc_Balance_Double($cn);
-
-$balance->get_request();
-
-$balance->display_pdf();
-
diff --git a/include/export_anc_balance_group_csv.php 
b/include/export_anc_balance_group_csv.php
deleted file mode 100644
index fed3c00..0000000
--- a/include/export_anc_balance_group_csv.php
+++ /dev/null
@@ -1,35 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief export balance by group
- */
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_anc_group.php';
-
-header('Pragma: public');
-header('Content-type: application/csv'); 
-header('Content-Disposition: 
attachment;filename="anc-balance-group-export.csv"',FALSE);
-
-$a=new Anc_Group($cn);
-$a->get_request();
-$a->export_csv();
-?>
\ No newline at end of file
diff --git a/include/export_anc_balance_simple_csv.php 
b/include/export_anc_balance_simple_csv.php
deleted file mode 100644
index d97c87c..0000000
--- a/include/export_anc_balance_simple_csv.php
+++ /dev/null
@@ -1,36 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
-* \brief  export the operation in pdf
- */
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-header('Pragma: public');
-header('Content-type: application/csv');
-header('Content-Disposition: attachment;filename="ca_bal_simple.csv"',FALSE);
-
-require_once  NOALYSS_INCLUDE.'/class_anc_balance_simple.php';
-
-$cn=new Database(dossier::id());
-
-$bal=new Anc_Balance_Simple($cn);
-$bal->get_request();
-echo $bal->display_csv();
diff --git a/include/export_anc_balance_simple_pdf.php 
b/include/export_anc_balance_simple_pdf.php
deleted file mode 100644
index edaa0c7..0000000
--- a/include/export_anc_balance_simple_pdf.php
+++ /dev/null
@@ -1,35 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief export the operation in pdf
- *
- */
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once  NOALYSS_INCLUDE.'/class_anc_balance_simple.php';
-
-$cn=new Database(dossier::id());
-
-$balance=new Anc_Balance_Simple($cn);
-
-$balance->get_request();
-$balance->display_pdf();
-?>
diff --git a/include/export_anc_grandlivre_csv.php 
b/include/export_anc_grandlivre_csv.php
deleted file mode 100644
index 403f690..0000000
--- a/include/export_anc_grandlivre_csv.php
+++ /dev/null
@@ -1,37 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-// Copyright Author Dany De Bontridder address@hidden
-
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-header('Pragma: public');
-header('Content-type: application/csv');
-header('Content-Disposition: attachment;filename="anc-grand-livre.csv"',FALSE);
-
-require_once NOALYSS_INCLUDE.'/class_anc_grandlivre.php';
-
-$cn=Dossier::connect();
-
-$gl=new Anc_GrandLivre($cn);
-$gl->get_request();
-echo $gl->display_csv();
-
-
-
-
-?>
diff --git a/include/export_anc_list_csv.php b/include/export_anc_list_csv.php
deleted file mode 100644
index 569bb0d..0000000
--- a/include/export_anc_list_csv.php
+++ /dev/null
@@ -1,37 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
-* \brief  export the operation in pdf
- *
- */
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-header('Pragma: public');
-header('Content-type: application/csv');
-header('Content-Disposition: attachment;filename="jrn.csv"',FALSE);
-
-require_once  NOALYSS_INCLUDE.'/class_anc_listing.php';
-
-$cn=new Database(dossier::id());
-
-$bal=new Anc_Listing($cn);
-$bal->get_request();
-echo $bal->display_csv();
diff --git a/include/export_anc_receipt_pdf.php 
b/include/export_anc_receipt_pdf.php
deleted file mode 100644
index 7025f40..0000000
--- a/include/export_anc_receipt_pdf.php
+++ /dev/null
@@ -1,40 +0,0 @@
-<?php
-
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-// Copyright Author Dany De Bontridder address@hidden
-// Copyright Author Dany De Bontridder address@hidden
-if (!defined('ALLOWED'))
-    die('Appel direct ne sont pas permis');
-
-
-/**
- * export all the selected documents for Ana Accountancy in PDF
- */
-require_once NOALYSS_INCLUDE.'/class_document_export.php';
-
-$ck = HtmlInput::default_value_get('ck', 0);
-if ($ck == 0)
-{
-    echo "Aucune sélection";
-    exit();
-}
-$anc=new Document_Export();
-
-$anc->export_all($ck);
diff --git a/include/export_anc_table_csv.php b/include/export_anc_table_csv.php
deleted file mode 100644
index 9a3fd8d..0000000
--- a/include/export_anc_table_csv.php
+++ /dev/null
@@ -1,34 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief export the anc tables in CSV
- */
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-header('Pragma: public');
-header('Content-type: application/csv'); 
-header('Content-Disposition: 
attachment;filename="anc-table-export.csv"',FALSE);
-
-require_once NOALYSS_INCLUDE.'/class_anc_table.php';
-$atable=new Anc_Table($cn);
-$atable->get_request();
-$atable->export_csv();
-?>
\ No newline at end of file
diff --git a/include/export_balance_age_csv.php 
b/include/export_balance_age_csv.php
deleted file mode 100644
index cac21b3..0000000
--- a/include/export_balance_age_csv.php
+++ /dev/null
@@ -1,88 +0,0 @@
-<?php
-
-/*
- *   This file is part of PhpCompta.
- *
- *   PhpCompta is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   PhpCompta is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with PhpCompta; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-// Copyright (2014) Author Dany De Bontridder <address@hidden>
-
-if (!defined('ALLOWED'))
-    die('Appel direct ne sont pas permis');
-require 'class_balance_age.php';
-header('Pragma: public');
-header('Content-type: application/csv');
-header('Content-Disposition: attachment;filename="balance_age.csv"',FALSE);
-/**
- * @file
- * @brief Export an ageing balance
- * @param p_date_start considered writing after this date
- * @param p_let lettered or not value (all): let or  only unlettered 
value:unlet
- * @param p_type
- *  - C customer
- *  - F supplier
- *  - U only a card 
- *  - X a category 
- * @param cat only if p_type = X it that case contains the category id 
(fiche_def.fd_id)
- * @param fiche only if p_type = U in that case contains the card id 
(fiche.f_id)
- * @param all Ony with p_type = X all the customer / supplier cards
- */
-/*
- * Retrieve card
- */
-$bal=new Balance_Age($cn);
-$p_type = HtmlInput::default_value_get('p_type', "-");
-$p_date= HtmlInput::default_value_get('p_date_start', "-");
-$p_let= HtmlInput::default_value_get('p_let', "let");
-$cat= HtmlInput::default_value_get('cat', "");
-$fiche= HtmlInput::default_value_get('fiche', "0");
-$all= HtmlInput::default_value_get('all', "0");
-switch ($p_type)
-{
-    case 'C':
-        $bal->get_array_card('C');
-        $bal->export_csv($p_date, $p_let);
-        break;
-    case 'F':
-        $bal->get_array_card('F');
-        $bal->export_csv($p_date, $p_let);
-        break;
-    case 'U':
-        $bal->get_array_card('U', $fiche);
-        $bal->export_csv($p_date, $p_let);
-        break;
-    case 'X':
-        $all=HtmlInput::default_value_get('all', 0);
-        if ($all==0)
-        {
-            $bal->get_array_card('X', $_GET['cat']);
-            $bal->export_csv($p_date, $p_let);
-        }
-        else
-        {
-            $a_cat=$cn->get_array("select fd_id from vw_fiche_def where 
ad_id=".ATTR_DEF_ACCOUNT." order by fd_label asc");
-            $nb_cat=count($a_cat);
-            for ($i=0; $i<$nb_cat; $i++)
-            {
-                $bal->get_array_card('X', $a_cat[$i]['fd_id']);
-                $bal->export_csv($p_date, $p_let);
-            }
-        }
-        break;
-
-    default:
-        break;
-}
-?>
diff --git a/include/export_balance_csv.php b/include/export_balance_csv.php
deleted file mode 100644
index cb3303d..0000000
--- a/include/export_balance_csv.php
+++ /dev/null
@@ -1,103 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-// Copyright Author Dany De Bontridder address@hidden
-/*! \file
- * \brief Return the balance in CSV format
- */
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-header('Pragma: public');
-header('Content-type: application/csv');
-header('Content-Disposition: attachment;filename="balance.csv"',FALSE);
-include_once ("ac_common.php");
-include_once("class_acc_balance.php");
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-$gDossier=dossier::id();
-
-require_once NOALYSS_INCLUDE.'/class_acc_ledger.php';
-$cn=new Database($gDossier);
-bcscale(2);
-
-require_once  NOALYSS_INCLUDE.'/class_user.php';
-
-$bal=new Acc_Balance($cn);
-$bal->jrn=null;
-switch( $_GET['p_filter'])
-{
-case 0:
-        $bal->jrn=null;
-    break;
-case 1:
-    if (  isset($_GET['r_jrn']))
-    {
-        $selected=$_GET['r_jrn'];
-        $array_ledger=$g_user->get_ledger('ALL',3);
-        $array=get_array_column($array_ledger,'jrn_def_id');
-        for ($e=0;$e<count($selected);$e++)
-        {
-            if (isset ($selected[$e]) && in_array ($selected[$e],$array) )
-                $bal->jrn[]=$selected[$e];
-        }
-    }
-    break;
-case 2:
-    if ( isset($_GET['r_cat']))   $bal->filter_cat($_GET['r_cat']);
-    break;
-}
-
-$bal->from_poste=$_GET['from_poste'];
-$bal->to_poste=$_GET['to_poste'];
-if (isset($_GET['unsold'])) $bal->unsold=true;
-$prev = (isset($_GET['previous_exc'])) ? 1: 0;
-
-$row=$bal->get_row($_GET['from_periode'],
-                   $_GET['to_periode'],
-        $prev);
-$prev =  ( isset ($row[0]['sum_cred_previous'])) ?1:0;
-echo 'poste;libelle;';
-if ($prev  == 1 ) echo 'deb n-1;cred n-1;solde n-1;d/c;';
-echo 'deb;cred;solde;d/c';
-printf("\n");
-foreach ($row as $r)
-{
-    echo $r['poste'].';'.
-    $r['label'].';';
-    if ( $prev == 1 )
-    {
-        $delta=bcsub($r['solde_deb_previous'],$r['solde_cred_previous']);
-        $sign=($delta<0)?'C':'D';
-        $sign=($delta == 0)?'=':$sign;
-        echo  nb($r['sum_deb_previous']).';'.
-        nb($r['sum_cred_previous']).';'.
-        nb(abs($delta)).';'.
-        "$sign".';';
-       
-    }
-    $delta=bcsub($r['solde_deb'],$r['solde_cred']);
-    $sign=($delta<0)?'C':'D';
-    $sign=($delta == 0)?'=':$sign;
-    echo nb($r['sum_deb']).';'.
-    nb($r['sum_cred']).';'.
-    nb(abs($delta)).';'.
-    "$sign";
-    printf("\n");
-}
-
-
-?>
diff --git a/include/export_balance_pdf.php b/include/export_balance_pdf.php
deleted file mode 100644
index 1620aa0..0000000
--- a/include/export_balance_pdf.php
+++ /dev/null
@@ -1,284 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-/*! \file
- * \brief Print the balance in pdf format
- * \param received parameters
- * \param e_date element 01.01.2003
- * \param e_client element 3
- * \param nb_item element 2
- * \param e_march0 element 11
- * \param e_quant0 element 1
- * \param e_march1 element 6
- * \param e_quant1 element 2
- * \param e_comment  invoice number
- */
-// Copyright Author Dany De Bontridder address@hidden
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-include_once("ac_common.php");
-require_once NOALYSS_INCLUDE.'/class_database.php';
-include_once("class_acc_balance.php");
-require_once  NOALYSS_INCLUDE.'/header_print.php';
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-require_once NOALYSS_INCLUDE.'/class_pdf.php';
-$gDossier=dossier::id();
-bcscale(4);
-$cn=new Database($gDossier);
-$rep=new Database();
-require_once  NOALYSS_INCLUDE.'/class_user.php';
-$g_user->Check();
-
-$bal=new Acc_Balance($cn);
-
-extract ($_GET);
-$bal->jrn=null;
-switch( $_GET['p_filter'])
-{
-case 0:
-        $bal->jrn=null;
-    break;
-case 1:
-    if (  isset($_GET['r_jrn']))
-    {
-        $selected=$_GET['r_jrn'];
-        $array_ledger=$g_user->get_ledger('ALL',3);
-        $array=get_array_column($array_ledger,'jrn_def_id');
-        for ($e=0;$e<count($selected);$e++)
-        {
-            if (isset ($selected[$e]) && in_array ($selected[$e],$array))
-                $bal->jrn[]=$selected[$e];
-        }
-    }
-    break;
-case 2:
-    if ( isset($_GET['r_cat']))   $bal->filter_cat($_GET['r_cat']);
-    break;
-}
-
-$bal->from_poste=$_GET['from_poste'];
-$bal->to_poste=$_GET['to_poste'];
-if (isset($_GET['unsold'])) $bal->unsold=true;
-$previous=(isset($_GET['previous_exc']))?1:0;
-  
-$array=$bal->get_row($from_periode,$to_periode,$previous);
-
-$previous= (isset ($array[0]['sum_cred_previous']))?1:0;
-
-
-if ( sizeof($array)  == 0 )
-{
-    exit();
-
-}
-
-$pPeriode=new Periode($cn);
-$a=$pPeriode->get_date_limit($from_periode);
-$b=$pPeriode->get_date_limit($to_periode);
-$per_text="  du ".$a['p_start']." au ".$b['p_end'];
-if ($previous == 1 ) {
-    $pdf=new PDFLand($cn);
-} else {
-    $pdf= new PDF($cn);
-}
-$pdf->setDossierInfo(" Balance  ".$per_text);
-$pdf->AliasNbPages();
-$pdf->AddPage();
-$pdf->SetAuthor('NOALYSS');
-$pdf->SetFont('DejaVuCond','',7);
-$pdf->setTitle("Balance comptable",true);
-$pdf->Cell(30,6,'poste');
-$pdf->LongLine(60,6,'Libellé');
-if ($previous == 1 ){ 
-    $pdf->Cell(20,6,'Débit N-1',0,0,'R');
-    $pdf->Cell(20,6,'Crédit N-1',0,0,'R');
-    $pdf->Cell(20,6,'Débiteur N-1',0,0,'R');
-    $pdf->Cell(20,6,'Créditeur N-1',0,0,'R');
-}
-$pdf->Cell(25,6,'Total Débit',0,0,'R');
-$pdf->Cell(25,6,'Total Crédit',0,0,'R');
-$pdf->Cell(25,6,'Solde Débiteur',0,0,'R');
-$pdf->Cell(25,6,'Solde Créditeur',0,0,'R');
-$pdf->Ln();
-
-$pdf->SetFont('DejaVuCond','',8);
-$tp_deb=0;
-$tp_cred=0;
-$tp_sold=0;
-$tp_solc=0;
-$tp_deb_previous=0;
-$tp_cred_previous=0;
-$tp_sold_previous=0;
-$tp_solc_previous=0;
-if ( $previous == 1) {
-    
$a_sum=array('sum_cred','sum_deb','solde_deb','solde_cred','sum_cred_previous','sum_deb_previous','solde_deb_previous','solde_cred_previous');
-}
-else {
-    $a_sum=array('sum_cred','sum_deb','solde_deb','solde_cred') ;
-}
-foreach($a_sum as $a)
-  {
-    $nlvl1[$a]=0;
-    $nlvl2[$a]=0;
-    $nlvl3[$a]=0;
-  }
-$lvl1_old='';
-$lvl2_old='';
-$lvl3_old='';
-
-bcscale(2);
-if (! empty($array))
-  {
-    $i=0;
-    foreach ($array as $key=>$value)
-      {
-       $i++;
-       /*
-        * level x
-        */
-       if ( $value['poste']=='') continue;
-       foreach (array(3,2,1) as $ind)
-         {
-           $r=$value;
-           if ( ! isset($_GET['lvl'.$ind]))continue;
-
-           if (${'lvl'.$ind.'_old'} == '')       
${'lvl'.$ind.'_old'}=substr($r['poste'],0,$ind);
-           if ( ${'lvl'.$ind.'_old'} != substr($r['poste'],0,$ind))
-             {
-               $pdf->SetFont('DejaVu','B',7);
-               $pdf->LongLine(30,6,${'lvl'.$ind.'_old'});
-                
$delta=bcsub(${'nlvl'.$ind}['solde_cred'],${'nlvl'.$ind}['solde_deb']);
-                $side=($delta< 0) ? "D":"C";
-                if ($previous == 1 ) {
-                    
$delta_previous=bcsub(${'nlvl'.$ind}['solde_cred_previous'],${'nlvl'.$ind}['solde_deb_previous']);
-                    $side_previous=($delta_previous < 0) ? "D":"C";
-                    $pdf->Cell(30,6,"n-1 : " .nbm($delta_previous)." 
$side_previous",0,0,'R');
-                     $pdf->Cell(30,6," n : ".nbm($delta)." $side",0,0,'R');
-                    
$pdf->Cell(22,6,nbm(${'nlvl'.$ind}['sum_deb_previous']),0,0,'R');
-                    
$pdf->Cell(22,6,nbm(${'nlvl'.$ind}['sum_cred_previous']),0,0,'R');
-                    
$pdf->Cell(22,6,nbm(${'nlvl'.$ind}['solde_deb_previous']),0,0,'R');
-                    
$pdf->Cell(22,6,nbm(${'nlvl'.$ind}['solde_cred_previous']),0,0,'R');
-                } else {
-                     $pdf->Cell(60,6,nbm($delta)." $side",0,0,'R');
-                }
-               $pdf->Cell(25,6,nbm(${'nlvl'.$ind}['sum_deb']),0,0,'R');
-               $pdf->Cell(25,6,nbm(${'nlvl'.$ind}['sum_cred']),0,0,'R');
-               $pdf->Cell(25,6,nbm(${'nlvl'.$ind}['solde_deb']),0,0,'R');
-               $pdf->Cell(25,6,nbm(${'nlvl'.$ind}['solde_cred']),0,0,'R');
-               $pdf->Ln();
-               $pdf->SetFont('DejaVuCond','',7);
-               ${'lvl'.$ind.'_old'}=substr($r['poste'],0,$ind);
-               foreach($a_sum as $a)
-                 {
-                   ${'nlvl'.$ind}[$a]=0;
-                 }
-             }
-         }
-       foreach($a_sum as $a)
-         {
-           $nlvl1[$a]=bcadd($nlvl1[$a],$r[$a]);
-           $nlvl2[$a]=bcadd($nlvl2[$a],$r[$a]);
-           $nlvl3[$a]=bcadd($nlvl3[$a],$r[$a]);
-         }
-
-       if ( $i % 2 == 0 )
-         {
-           $pdf->SetFillColor(220,221,255);
-           $fill=1;
-         }
-       else
-         {
-           $pdf->SetFillColor(0,0,0);
-           $fill=0;
-         }
-
-       $pdf->LongLine(30,6,$value['poste'],0,'L',$fill);
-       $pdf->LongLine(60,6,$value['label'],0,'L',$fill);
-        if ($previous == 1 ) {
-            $pdf->Cell(22,6,nbm($value['sum_deb_previous']),0,0,'R',$fill);
-            $pdf->Cell(22,6,nbm($value['sum_cred_previous']),0,0,'R',$fill);
-            $pdf->Cell(22,6,nbm($value['solde_deb_previous']),0,0,'R',$fill);
-            $pdf->Cell(22,6,nbm($value['solde_cred_previous']),0,0,'R',$fill);
-            
$tp_deb_previous=bcadd($tp_deb_previous,$value['sum_deb_previous']);
-            
$tp_cred_previous=bcadd($tp_cred_previous,$value['sum_cred_previous']);
-            
$tp_sold_previous=bcadd($tp_sold_previous,$value['solde_deb_previous']);
-            
$tp_solc_previous=bcadd($tp_solc_previous,$value['solde_cred_previous']);
-        }
-       $pdf->Cell(25,6,nbm($value['sum_deb']),0,0,'R',$fill);
-       $pdf->Cell(25,6,nbm($value['sum_cred']),0,0,'R',$fill);
-       $pdf->Cell(25,6,nbm($value['solde_deb']),0,0,'R',$fill);
-       $pdf->Cell(25,6,nbm($value['solde_cred']),0,0,'R',$fill);
-       $pdf->Ln();
-       $tp_deb=bcadd($tp_deb,$value['sum_deb']);
-       $tp_cred=bcadd($tp_cred,$value['sum_cred']);
-       $tp_sold=bcadd($tp_sold,$value['solde_deb']);
-       $tp_solc=bcadd($tp_solc,$value['solde_cred']);
-
-      }
-    foreach (array(3,2,1) as $ind)
-      {
-       $r=$value;
-       if ( ! isset($_GET['lvl'.$ind]))continue;
-
-       if (${'lvl'.$ind.'_old'} == '')   
${'lvl'.$ind.'_old'}=substr($r['poste'],0,$ind);
-       if ( ${'lvl'.$ind.'_old'} != substr($r['poste'],0,$ind))
-         {
-           $pdf->SetFont('DejaVu','B',7);
-           $pdf->Cell(30,6,"Totaux ".$ind);
-           $pdf->Cell(60,6,${'lvl'.$ind.'_old'});
-             if ($previous == 1 ) {
-                
$pdf->Cell(22,6,nbm(${'nlvl'.$ind}['sum_deb_previous']),0,0,'R');
-                
$pdf->Cell(22,6,nbm(${'nlvl'.$ind}['sum_cred_previous']),0,0,'R');
-                
$pdf->Cell(22,6,nbm(${'nlvl'.$ind}['solde_deb_previous']),0,0,'R');
-                
$pdf->Cell(22,6,nbm(${'nlvl'.$ind}['solde_cred_previous']),0,0,'R');
-             }
-           $pdf->Cell(25,6,nbm(${'nlvl'.$ind}['sum_deb']),0,0,'R');
-           $pdf->Cell(25,6,nbm(${'nlvl'.$ind}['sum_cred']),0,0,'R');
-           $pdf->Cell(25,6,nbm(${'nlvl'.$ind}['solde_deb']),0,0,'R');
-           $pdf->Cell(25,6,nbm(${'nlvl'.$ind}['solde_cred']),0,0,'R');
-           $pdf->Ln();
-           $pdf->SetFont('DejaVuCond','',7);
-           ${'lvl'.$ind.'_old'}=substr($r['poste'],0,$ind);
-           foreach($a_sum as $a)
-             {
-               ${'nlvl'.$ind}[$a]=0;
-             }
-         }
-      }
-
-    // Totaux
-    $pdf->SetFont('DejaVuCond','B',8);
-    $pdf->Cell(90,6,'Totaux');
-     if ($previous == 1 ) {
-        $pdf->Cell(22,6,nbm($tp_deb_previous),'T',0,'R',0);
-        $pdf->Cell(22,6,nbm($tp_cred_previous),'T',0,'R',0);
-        $pdf->Cell(22,6,nbm($tp_sold_previous),'T',0,'R',0);
-        $pdf->Cell(22,6,nbm($tp_solc_previous),'T',0,'R',0);
-    }
-    $pdf->Cell(25,6,nbm($tp_deb),'T',0,'R',0);
-    $pdf->Cell(25,6,nbm($tp_cred),'T',0,'R',0);
-    $pdf->Cell(25,6,nbm($tp_sold),'T',0,'R',0);
-    $pdf->Cell(25,6,nbm($tp_solc),'T',0,'R',0);
-    $pdf->Ln();
-  } /** empty */
-
-$fDate=date('dmy-Hi');
-$pdf->Output('balance-'.$fDate.'.pdf','D');
-
-
-
-?>
diff --git a/include/export_bilan_oth.php b/include/export_bilan_oth.php
deleted file mode 100644
index a4c2ebe..0000000
--- a/include/export_bilan_oth.php
+++ /dev/null
@@ -1,61 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-// Copyright Author Dany De Bontridder address@hidden
-/*! \file
- * \brief send a Bilan in RTF format
- */
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-include_once("ac_common.php");
-include_once("class_impress.php");
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once  NOALYSS_INCLUDE.'/header_print.php';
-require_once  NOALYSS_INCLUDE.'/class_acc_bilan.php';
-
-require_once   NOALYSS_INCLUDE.'/class_user.php';
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-$gDossier=dossier::id();
-
-/* Admin. Dossier */
-$cn=new Database($gDossier);
-
-$bilan=new Acc_Bilan($cn);
-$bilan->get_request_get();
-$bilan->load();
-
-if ( $bilan->b_type=='odt')
-{
-    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
-    header("Cache-Control: must-revalidate");
-    header('Content-type: application/vnd.oasis.opendocument.text');
-    header('Content-Disposition: 
attachment;filename="'.$bilan->b_name.'.odt"',FALSE);
-    header("Accept-Ranges: bytes");
-
-}
-if ( $bilan->b_type=='ods')
-{
-    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
-    header("Cache-Control: must-revalidate");
-    header('Content-type: application/vnd.oasis.opendocument.spreadsheet');
-    header('Content-Disposition: 
attachment;filename="'.$bilan->b_name.'.ods"',FALSE);
-    header("Accept-Ranges: bytes");
-
-}
-
-$bilan->generate();
-?>
diff --git a/include/export_fiche_balance_csv.php 
b/include/export_fiche_balance_csv.php
deleted file mode 100644
index 4588678..0000000
--- a/include/export_fiche_balance_csv.php
+++ /dev/null
@@ -1,200 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief Called by impress->category, export in CVS the history of a category
- * of card
- */
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-header('Pragma: public');
-header('Content-type: application/csv');
-header('Content-Disposition: attachment;filename="bal-fiche.csv"',FALSE);
-
-// Security we check if user does exist and his privilege
-require_once NOALYSS_INCLUDE.'/class_user.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-require_once NOALYSS_INCLUDE.'/ac_common.php';
-$allcard=(isset($_GET['allcard']))?1:0;
-
-/* balance */
-if ( $_GET['histo'] == 4 || $_GET['histo'] == 5)
-{
-    $fd=new Fiche_Def($cn,$_REQUEST['cat']);
-    if ( $allcard==1 && $fd->hasAttribute(ATTR_DEF_ACCOUNT) == false )
-    {
-      exit;
-    }
-       // all card
-       if ($allcard==1)
-       {
-               $afiche=$cn->get_array("select fd_id from vw_fiche_def where 
ad_id=".ATTR_DEF_ACCOUNT." order by fd_label asc");
-       }
-       else
-       {
-               $afiche[0]=array('fd_id'=>$_REQUEST['cat']);
-       }
-       printf('"Quick code";"Nom";"poste 
comptable";"debit";"credit";"solde";"D/C";');
-               printf("\n");
-       for ($e = 0; $e < count($afiche); $e++)
-       {
-               $aCard = $cn->get_array("select f_id,ad_value from fiche join 
fiche_Detail using (f_id)  where ad_id=1 and fd_id=$1 order by 2 ", 
array($afiche[$e]['fd_id']));
-
-               if (empty($aCard))
-               {
-                       continue;
-               }
-
-               for ($i = 0; $i < count($aCard); $i++)
-               {
-                       if (isDate($_REQUEST['start']) == null || 
isDate($_REQUEST['end']) == null)
-                               exit;
-                       $filter = " (j_date >= to_date('" . $_REQUEST['start'] 
. "','DD.MM.YYYY') " .
-                                       " and  j_date <= to_date('" . 
$_REQUEST['end'] . "','DD.MM.YYYY')) ";
-                       $oCard = new Fiche($cn, $aCard[$i]['f_id']);
-                       $solde = $oCard->get_solde_detail($filter);
-                       if ($solde['debit'] == 0 && $solde['credit'] == 0)
-                               continue;
-                       /* only not purged card */
-                       if ($_GET['histo'] == 5 && $solde['solde'] == 0)
-                               continue;
-                       $side = '';
-                       if (bcsub($solde['credit'], $solde['debit']) < 0)
-                               $side = 'Deb.';
-                       if (bcsub($solde['credit'], $solde['debit']) > 0)
-                               $side = 'Cred.';
-
-                       printf('"%s";"%s";"%s";%s;%s;%s;"%s"', 
$oCard->strAttribut(ATTR_DEF_QUICKCODE), $oCard->strAttribut(ATTR_DEF_NAME),  
$oCard->strAttribut(ATTR_DEF_ACCOUNT),nb($solde['debit']), 
nb($solde['credit']), nb(abs($solde['solde'])), $side);
-                       printf("\n");
-               }
-       }
-}
-else
-{
-       // all card
-       if ($allcard == 1)
-       {
-               $afiche = $cn->get_array("select fd_id from vw_fiche_def where 
ad_id=" . ATTR_DEF_ACCOUNT . " order by fd_label asc");
-       }
-       else
-       {
-               $afiche[0] = array('fd_id' => $_REQUEST['cat']);
-       }
-       $fic=new Fiche($cn);
-       for ($e = 0; $e < count($afiche); $e++)
-       {
-               $array = Fiche::get_fiche_def($cn, $afiche[$e]['fd_id'], 
'name_asc');
-
-               foreach ($array as $card)
-               {
-                       $row = new Fiche($cn, $card['f_id']);
-                       $letter = new Lettering_Card($cn);
-                       $letter->set_parameter('quick_code', 
$row->strAttribut(ATTR_DEF_QUICKCODE));
-                       $letter->set_parameter('start', $_GET['start']);
-                       $letter->set_parameter('end', $_GET['end']);
-                       // all
-                       if ($_GET['histo'] == 0)
-                       {
-                               $letter->get_all();
-                       }
-
-                       // lettered
-                       if ($_GET['histo'] == 1)
-                       {
-                               $letter->get_letter();
-                       }
-                       // unlettered
-                       if ($_GET['histo'] == 2)
-                       {
-                               $letter->get_unletter();
-                       }
-                       if ($_GET['histo'] == 6)
-                       {
-                               $letter->get_letter_diff();
-                       }
-                       /* skip if nothing to display */
-                       if (count($letter->content) == 0)
-                               continue;
-                       
printf('"%s";"%s";"%s"'."\n",$row->strAttribut(ATTR_DEF_QUICKCODE), 
$row->strAttribut(ATTR_DEF_NAME),$row->strAttribut(ATTR_DEF_ACCOUNT));
-
-                       printf('"%s";"%s";"%s";"%s";"%s";"%s";"%s";"%s";"%s"',
-                                       _('Date'),
-                               _('ref'),
-                               _('Interne'),
-                               _('Comm'),
-                               _('Débit'),
-                               _('Crébit'),
-                               _('Prog.'),
-                               _('D/C'),
-                               _('Let.'),
-                                       _("Diff Let."));
-                       printf("\n");
-                       $amount_deb = 0;
-                       $amount_cred = 0;
-                       $prog = 0;
-                       bcscale(2);
-                       for ($i = 0; $i < count($letter->content); $i++)
-                       {
-                               $row = $letter->content[$i];
-                               printf ('"%s";',$row['j_date_fmt']);
-                               printf ('"%s";',$row['jr_pj_number']);
-                               printf ('"%s";',$row['jr_internal']);
-                               printf ('"%s";',$row['jr_comment']);
-                               if ($row['j_debit'] == 't')
-                               {
-                                       printf("%s;",nb($row['j_montant']));
-                                       
$amount_deb=bcadd($amount_deb,$row['j_montant']);
-                                       $prog = bcadd($prog, $row['j_montant']);
-                                       printf (";");
-                               }
-                               else
-                               {
-                                       printf(";");
-                                       printf("%s;",nb($row['j_montant']));
-                                       
$amount_cred=bcadd($amount_cred,$row['j_montant']);
-                                       $prog = bcsub($prog, $row['j_montant']);
-                               }
-                               printf 
("%s;\"%s\";",abs(nb($prog)),$fic->get_amount_side($prog));
-                               if ($row['letter'] != -1)
-                               {
-                                       printf('"%s";',  
strtoupper(base_convert($row['letter'],10,36)));
-                                       printf("%s",nb($row['letter_diff']));
-                               }
-                               else
-                                       printf(";");
-                               printf("\n");
-                       }
-                       if ($prog < 0 )
-                               $msg="Solde Debit";
-                       elseif ($prog>0)
-                               $msg="Solde Credit";
-                       else
-                               $msg="soldé";
-
-                       printf(';;;"%s";%s;%s;%s;"%s"',
-                                       
$msg,nb($amount_deb),nb($amount_cred),nb(abs($prog)),$fic->get_amount_side($prog));
-                       printf("\n");
-               }
-       }
-}
-exit;
-
-
diff --git a/include/export_fiche_balance_pdf.php 
b/include/export_fiche_balance_pdf.php
deleted file mode 100644
index c60f58a..0000000
--- a/include/export_fiche_balance_pdf.php
+++ /dev/null
@@ -1,317 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief Called by impress->category, export in PDF the history of a category 
or balance
- * of card
- */
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-// Security we check if user does exist and his privilege
-require_once NOALYSS_INCLUDE.'/class_user.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_pdf.php';
-require_once NOALYSS_INCLUDE.'/class_lettering.php';
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-require_once NOALYSS_INCLUDE.'/ac_common.php';
-
-/* Security */
-$gDossier=dossier::id();
-$cn=new Database($gDossier);
-$g_user->Check();
-$g_user->check_dossier($gDossier);
-$name=$cn->get_value('select fd_label from fiche_def where 
fd_id=$1',array($_GET['cat']));
-
-$pdf=new PDF($cn);
-$pdf->setDossierInfo("  Periode : ".$_GET['start']." - ".$_GET['end']);
-$pdf->AliasNbPages();
-$pdf->AddPage();
-
-$pdf->SetTitle($name,1);
-$pdf->SetAuthor('NOALYSS');
-/* balance */
-$allcard=(isset($_GET['allcard']))?1:0;
-/*
- * Balance
- */
-if ( $_GET['histo'] == 4 || $_GET['histo']==5)
-{
-    $fd=new Fiche_Def($cn,$_REQUEST['cat']);
-    if ($allcard==1 &&  $fd->hasAttribute(ATTR_DEF_ACCOUNT) == false )
-    {
-        $pdf->Cell(0,10, "Cette catégorie n'ayant pas de poste comptable n'a 
pas de balance");
-        //Save PDF to file
-        $fDate=date('dmy-Hi');
-        $pdf->Output("category-$fDate.pdf", 'D');
-        exit;
-    }
-       // all card
-       if ($allcard==1)
-       {
-               $afiche=$cn->get_array("select fd_id from vw_fiche_def where 
ad_id=".ATTR_DEF_ACCOUNT." order by fd_label asc");
-       }
-       else
-       {
-               $afiche[0]=array('fd_id'=>$_REQUEST['cat']);
-       }
-
-       if ( $allcard==0 && empty($afiche))
-    {
-        $pdf->Cell(0,10, "Aucune fiche trouvée");//Save PDF to file
-        $fDate=date('dmy-Hi');
-        $pdf->Output("category-$fDate.pdf", 'D');
-        exit;
-    }
-       for ($e = 0; $e < count($afiche); $e++)
-       {
-    $aCard=$cn->get_array("select f_id,ad_value from fiche join fiche_Detail 
using (f_id)  where ad_id=1 and fd_id=$1 order by 2 
",array($afiche[$e]['fd_id']));
-       $name=$cn->get_value('select fd_label from fiche_def where 
fd_id=$1',array($afiche[$e]['fd_id']));
-       $pdf->SetFont('DejaVu','BI',14);
-       $pdf->Cell(0,8,$name,0,1,'C');
-
-       $pdf->SetFont('DejaVuCond','',7);
-    $pdf->LongLine(30,7,'Quick Code',0,'L',0);
-    $pdf->LongLine(80,7,'Libellé',0,'L',0);
-    $pdf->Cell(20,7,'Débit',0,0,'R',0);
-    $pdf->Cell(20,7,'Crédit',0,0,'R',0);
-    $pdf->Cell(20,7,'Solde',0,0,'R',0);
-    $pdf->Cell(20,7,'D/C',0,0,'C',0);
-    $pdf->Ln();
-
-       if (empty($aCard)) continue;
-
-
-    $idx=0;$sum_deb=0;$sum_cred=0;bcscale(4);
-    for ($i=0;$i < count($aCard);$i++)
-    {
-        if ( isDate($_REQUEST['start']) == null || isDate ($_REQUEST['end']) 
== null )          exit;
-        $filter= " (j_date >= to_date('".$_REQUEST['start']."','DD.MM.YYYY') ".
-                 " and  j_date <= 
to_date('".$_REQUEST['end']."','DD.MM.YYYY')) ";
-        $oCard=new Fiche($cn,$aCard[$i]['f_id']);
-        $solde=$oCard->get_solde_detail($filter);
-        if ( $solde['debit'] == 0 && $solde['credit']==0) continue;
-       /* only not purged card */
-       if ($_GET['histo'] == 5 && $solde['debit'] == $solde['credit']) 
continue;
-
-        if ( $idx % 2 == 0 )
-        {
-            $pdf->SetFillColor(220,221,255);
-            $fill=1;
-        }
-        else
-        {
-            $pdf->SetFillColor(0,0,0);
-            $fill=0;
-        }
-        $idx++;
-       $side='';
-       if(bcsub($solde['credit'],$solde['debit']) < 0) $side='Deb.';
-       if(bcsub($solde['credit'],$solde['debit']) > 0) $side='Cred.';
-
-        $sum_cred=bcadd($sum_cred,$solde['credit']);
-        $sum_deb=bcadd($sum_deb,$solde['debit']);
-        $sum_solde=bcsub($sum_deb,$sum_cred);
-
-        $pdf->Cell(30,7,$oCard->strAttribut(ATTR_DEF_QUICKCODE),0,0,'L',$fill);
-        $pdf->LongLine(80,7,$oCard->strAttribut(ATTR_DEF_NAME)." 
(".$oCard->strAttribut(ATTR_DEF_ACCOUNT).")",0,'L',$fill);
-        $pdf->Cell(20,7,nbm($solde['debit']),0,0,'R',$fill);
-        $pdf->Cell(20,7,nbm($solde['credit']),0,0,'R',$fill);
-        $pdf->Cell(20,7,nbm(abs($solde['solde'])),0,0,'R',$fill);
-        $pdf->Cell(20,7,$side,0,0,'C',$fill);
-        $pdf->Ln();
-        }
-               if ( $idx % 2 == 0 )
-        {
-            $pdf->SetFillColor(220,221,255);
-            $fill=1;
-        }
-        else
-        {
-            $pdf->SetFillColor(0,0,0);
-            $fill=0;
-        }
-               $idx++;
-        // Sum by category
-        $pdf->Cell(30,7,"",0,0,'L',$fill);
-        $pdf->Cell(80,7,_("Totaux"),0,0,'L',$fill);
-        $pdf->Cell(20,7,nbm($sum_deb),0,0,'R',$fill);
-        $pdf->Cell(20,7,nbm($sum_cred),0,0,'R',$fill);
-        $pdf->Cell(20,7,nbm(abs($sum_solde)),0,0,'R',$fill);
-        $side=" = ";
-        if ( $sum_solde > 0 )
-        {
-            $side='Deb.';
-        }
-        else if ( $sum_solde < 0)
-        {
-            $side='Cred.';
-        }
-
-        $pdf->Cell(20,7,$side,0,0,'C',$fill);
-        $pdf->Ln();
-       }
-}
-else
-{
-       // History
-       // all card
-       if ($allcard == 1)
-       {
-               $afiche = $cn->get_array("select fd_id from vw_fiche_def where 
ad_id=" . ATTR_DEF_ACCOUNT . " order by fd_label asc");
-       }
-       else
-       {
-               $afiche[0] = array('fd_id' => $_REQUEST['cat']);
-       }
-       $fic=new Fiche($cn);
-       for ($e = 0; $e < count($afiche); $e++)
-       {
-               $array = Fiche::get_fiche_def($cn,$afiche[$e]['fd_id'] , 
'name_asc');
-               /*
-                * You show now the result
-                */
-               if ($array == null)
-               {
-                       continue;
-               }
-               $tab = array(12, 20, 20,68, 20, 20, 10, 20);
-               $align = array('L', 'C', 'L', 'L', 'R','R', 'R', 'R');
-
-               foreach ($array as $row_fiche)
-               {
-                       $fic = new Fiche($cn, $row_fiche['f_id']);
-                       $letter = new Lettering_Card($cn);
-                       $letter->set_parameter('quick_code', 
$fic->strAttribut(ATTR_DEF_QUICKCODE));
-                       $letter->set_parameter('start', $_GET['start']);
-                       $letter->set_parameter('end', $_GET['end']);
-                       // all
-                       if ($_GET['histo'] == 0)
-                       {
-                               $letter->get_all();
-                       }
-
-                       // lettered
-                       if ($_GET['histo'] == 1)
-                       {
-                               $letter->get_letter();
-                       }
-                       // unlettered
-                       if ($_GET['histo'] == 2)
-                       {
-                               $letter->get_unletter();
-                       }
-                       if ($_GET['histo'] == 6)
-                       {
-                               $letter->get_letter_diff();
-                       }
-                       /* skip if nothing to display */
-                       if (count($letter->content) == 0)
-                               continue;
-                       $pdf->SetFont('DejaVuCond', '', 10);
-                       $fiche = new Fiche($cn, $row_fiche['f_id']);
-                       $pdf->Cell(0, 7, $fiche->strAttribut(ATTR_DEF_NAME)." 
[".$fiche->strAttribut(ATTR_DEF_QUICKCODE).":".$fiche->strAttribut(ATTR_DEF_ACCOUNT)."]",
 1, 'C');
-
-                       $pdf->SetFont('DejaVuCond', '', 7);
-                       $pdf->Ln();
-                       $pdf->Cell($tab[0], 7, 'Date');
-                       $pdf->Cell($tab[1], 7, 'ref');
-                       $pdf->Cell($tab[2], 7, 'Internal');
-                       $pdf->Cell($tab[3], 7, 'Comm');
-                       $pdf->Cell($tab[4], 7, 'Montant', 0, 0, 'C');
-                       $pdf->Cell($tab[5], 7, 'Prog.', 0, 0, 'R');
-                       $pdf->Cell($tab[6], 7, 'Let.', 0, 0, 'R');
-                       $pdf->Cell($tab[7], 7, 'Diff. Let.', 0, 0, 'R');
-                       $pdf->ln();
-
-                       $amount_deb = 0;
-                       $amount_cred = 0;
-                       $prog=0;
-                       for ($i = 0; $i < count($letter->content); $i++)
-                       {
-                               if ($i % 2 == 0)
-                               {
-                                       $pdf->SetFillColor(220, 221, 255);
-                                       $fill = 1;
-                               }
-                               else
-                               {
-                                       $pdf->SetFillColor(0, 0, 0);
-                                       $fill = 0;
-                               }
-                               $pdf->SetFont('DejaVuCond', '', 7);
-                               $row = $letter->content[$i];
-                               $str_date = shrink_date($row['j_date_fmt']);
-
-                               $pdf->LongLine($tab[0], 4, $str_date, 0, 
$align[0], $fill);
-                               $pdf->Cell($tab[1], 4, $row['jr_pj_number'], 0, 
0, $align[1], $fill);
-                               $pdf->LongLine($tab[2], 4, $row['jr_internal'], 
0, $align[1], $fill);
-                               $pdf->LongLine($tab[3], 4, $row['jr_comment'], 
0,  $align[2], $fill);
-                               if ($row['j_debit'] == 't')
-                               {
-                                       $prog=bcadd($prog,$row['j_montant']);
-                                       $pdf->Cell($tab[4], 4, sprintf('%s D', 
nbm($row['j_montant'])), 0, 0, $align[4], $fill);
-                                       $amount_deb+=$row['j_montant'];
-                                       $str_prog=sprintf("%s 
%s",nbm(abs($prog)),$fic->get_amount_side($prog));
-                                       $pdf->Cell($tab[5], 4, $str_prog, 0, 0, 
$align[5], $fill);
-                               }
-                               else
-                               {
-                                       $prog=bcsub($prog,$row['j_montant']);
-                                       $pdf->Cell($tab[4], 4, sprintf('%s C', 
nbm($row['j_montant'])), 0, 0, $align[4], $fill);
-                                       $amount_cred+=$row['j_montant'];
-                                       $str_prog=sprintf("%s 
%s",nbm(abs($prog)),$fic->get_amount_side($prog));
-                                       $pdf->Cell($tab[5], 4, $str_prog, 0, 0, 
$align[5], $fill);
-                               }
-                               if ($row['letter'] != -1)
-                               {
-                                       $pdf->Cell($tab[6], 4, 
strtoupper(base_convert($row['letter'],10,36)), 0, 0, $align[6], $fill);
-                                       // get sum for this lettering
-
-                                       $pdf->Cell($tab[7], 4, sprintf('%s', 
nbm($row['letter_diff'])), '0', '0', $align[7], $fill);
-                               }
-                               else
-                                       $pdf->Cell($tab[6], 4, "", 0, 0, 'R', 
$fill);
-                               $pdf->Ln();
-                       }
-                       $pdf->SetFillColor(0, 0, 0);
-                       $pdf->SetFont('DejaVuCond', 'B', 8);
-                       $debit = sprintf('Debit  : %s', nbm($amount_deb));
-                       $credit = sprintf('Credit : %s', nbm($amount_cred));
-                       if ($amount_deb > $amount_cred)
-                               $s = 'solde débiteur';
-                       else
-                               $s = 'solde crediteur';
-                       $solde = sprintf('%s  : %s', $s, 
nbm(abs(round($amount_cred - $amount_deb, 2))));
-
-                       $pdf->Cell(0, 6, $debit, 0, 0, 'R');
-                       $pdf->ln(4);
-                       $pdf->Cell(0, 6, $credit, 0, 0, 'R');
-                       $pdf->ln(4);
-                       $pdf->Cell(0, 6, $solde, 0, 0, 'R');
-                       $pdf->ln(4);
-
-                       $pdf->Ln();
-               }
-       }
-}
-//Save PDF to file
-$fDate=date('dmy-Hi');
-$pdf->Output("category-$fDate.pdf", 'D');
-exit;
diff --git a/include/export_fiche_csv.php b/include/export_fiche_csv.php
deleted file mode 100644
index aff85a6..0000000
--- a/include/export_fiche_csv.php
+++ /dev/null
@@ -1,89 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-// Copyright Author Dany De Bontridder address@hidden
-/*! \file
- * \brief Send a CSV file with card
- */
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-header('Pragma: public');
-header('Content-type: application/csv');
-header('Content-Disposition: attachment;filename="fiche.csv"',FALSE);
-include_once ("ac_common.php");
-include_once('class_fiche.php');
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-$gDossier=dossier::id();
-
-$cn=new Database($gDossier);
-
-require_once  NOALYSS_INCLUDE.'/class_user.php';
-
-
-
-if  ( isset ($_GET['fd_id']))
-{
-    $fiche_def=new Fiche_Def($cn,$_GET ['fd_id']);
-    $fiche=new Fiche($cn);
-    $e=$fiche_def->get_by_type();
-    $o=0;
-    //  Heading
-    $fiche_def->GetAttribut();
-    foreach ($fiche_def->attribut as $attribut)
-    {
-        if ( $o == 0 )
-        {
-            printf("%s",$attribut->ad_text);
-            $o=1;
-        }
-        else
-        {
-            printf(";%s",$attribut->ad_text);
-        }
-    }
-    printf("\n");
-    $o=0;
-    // Details
-
-    foreach ($e as $fiche)
-      {
-       $detail=new Fiche($cn,$fiche['f_id']);
-
-       $detail->getAttribut();
-
-        foreach ( $detail->attribut as $dattribut )
-        {
-            if ( $o == 0 )
-            {
-                printf("%s",$dattribut->av_text);
-                $o=1;
-            }
-            else
-            {
-                printf (";%s",$dattribut->av_text);
-
-            }
-        }
-        printf("\n");
-        $o=0;
-    }
-
-
-}
-exit;
-?>
diff --git a/include/export_fiche_detail_csv.php 
b/include/export_fiche_detail_csv.php
deleted file mode 100644
index ad6c00e..0000000
--- a/include/export_fiche_detail_csv.php
+++ /dev/null
@@ -1,163 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-// Copyright Author Dany De Bontridder address@hidden
-/*! \file
- * \brief Send the poste list in csv
- */
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-include_once("ac_common.php");
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_fiche.php';
-$f_id=HtmlInput::default_value_request("f_id", "-");
-if ( $f_id == "-") {
-     throw new Exception ('Invalid parameter');
-}
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-$gDossier=dossier::id();
-
-/* Admin. Dossier */
-$cn=new Database($gDossier);
-
-
-$Fiche=new Fiche($cn,$f_id);
-$qcode=$Fiche->get_quick_code();
-
-header('Content-type: application/csv');
-
-header('Pragma: public');
-header('Content-Disposition: 
attachment;filename="fiche-'.$qcode.'.csv"',FALSE);
-$Fiche->getName();
-list($array,$tot_deb,$tot_cred)=$Fiche->get_row_date(
-                                    $_GET['from_periode'],
-                                    $_GET['to_periode'],
-                                    $_GET['ople']
-                                );
-if ( count($Fiche->row ) == 0 )
-{
-    echo "Aucune donnée";
-    return;
-}
-
-
-if ( ! isset ($_REQUEST['oper_detail']))
-{
-    echo '"Qcode";'.
-    "\"Date\";".
-      "\"n° pièce\";".
-    "\"Code interne\";".
-    '"Code journal";'.
-    '"Nom journal";'.
-    "\"Description\";".
-    "\"Débit\";".
-    "\"Crédit\";".
-    "\"Prog.\";".
-    "\"Let.\""     ;
-    printf("\n");
-    $progress=0;
-    $current_exercice="";
-    $tot_deb=0;$tot_cred=0; 
-    bcscale(2);
-    foreach ( $Fiche->row as $op )
-    {
-        /*
-             * separation per exercice
-             */
-            if ( $current_exercice == "") $current_exercice=$op['p_exercice'];
-            
-            if ( $current_exercice != $op['p_exercice']) {
-                $solde_type=($tot_deb>$tot_cred)?"solde débiteur":"solde 
créditeur";
-                $diff=abs($tot_deb-$tot_cred);
-                printf(
-                     ";;;".
-                     '"'._('total').'";'.
-                     '"'.$current_exercice.'";;'.
-                '"'."$solde_type".'"'.";".
-                nb($tot_deb).";".
-                nb($tot_cred).";".
-                nb($diff).";"."\n");
-                /*
-                * reset total and current_exercice
-                */
-                $progress=0;
-                $current_exercice=$op['p_exercice'];
-                $tot_deb=0;$tot_cred=0;    
-            }
-        $diff=bcsub($op['deb_montant'],$op['cred_montant']);
-        $progress=bcadd($progress,$diff);
-        $tot_deb=bcadd($tot_deb,$op['deb_montant']);
-        $tot_cred=bcadd($tot_cred,$op['cred_montant']);
-        echo '"'.$op['j_qcode'].'";'.
-         '"'.$op['j_date_fmt'].'"'.";".
-         '"'.$op['jr_pj_number'].'"'.";".
-         '"'.$op['jr_internal'].'"'.";".
-         '"'.$op['jrn_def_code'].'"'.";".
-         '"'.$op['jrn_def_name'].'"'.";".
-         '"'.$op['description'].'"'.";".
-         nb($op['deb_montant']).";".
-         nb($op['cred_montant']).";".
-         nb(abs($progress)).';'.
-         
'"'.(($op['letter']==-1)?'':strtoupper(base_convert($op['letter'],10,36))).'"';
-        printf("\n");
-
-    }
-}
-else
-{
-    echo '"Poste";"Qcode";"date";"ref";"internal";';
-    echo    "\"Description\";".
-    "\"Montant\";".
-    "\"D/C\"";
-
-    printf("\r\n");
-
-    foreach ( $Fiche->row as $op )
-    {
-        $acc=new Acc_Operation($cn);
-        $acc->jr_id=$op['jr_id'];
-        $result= $acc->get_jrnx_detail();
-
-        foreach ( $result as $r)
-        {
-            printf('"%s";"%s";"%s";"%s";"%s";%s;%s;"%s"',
-                   $r['j_poste'],
-                   $r['j_qcode'],
-                   $r['jr_date'],
-                  $op['jr_pj_number'],
-                   $r['jr_internal'],
-                   $r['description'],
-                   nb($r['j_montant']),
-                   $r['debit']);
-            printf("\r\n");
-
-        }
-
-
-
-    }
-}
-$solde_type=($tot_deb>$tot_cred)?"solde débiteur":"solde créditeur";
-$diff=abs($tot_deb-$tot_cred);
-printf(
-    '"'."$solde_type".'"'.";".
-    nb($diff).";".
-    nb($tot_deb).";".
-    nb($tot_cred)."\n");
-
-exit;
-?>
diff --git a/include/export_fiche_detail_pdf.php 
b/include/export_fiche_detail_pdf.php
deleted file mode 100644
index 73d5d15..0000000
--- a/include/export_fiche_detail_pdf.php
+++ /dev/null
@@ -1,231 +0,0 @@
-<?php
-
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-/*! \file
- * \brief send the account list in PDF
- */
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-include_once("class_acc_account_ledger.php");
-include_once("ac_common.php");
-require_once NOALYSS_INCLUDE.'/class_database.php';
-include_once("class_impress.php");
-require_once NOALYSS_INCLUDE.'/class_fiche.php';
-require_once  NOALYSS_INCLUDE.'/header_print.php';
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-require_once NOALYSS_INCLUDE.'/class_pdf.php';
-$gDossier=dossier::id();
-
-$cn=new Database($gDossier);
-
-extract($_GET);
-
-$ret="";
-$pdf= new PDF($cn);
-$pdf->setDossierInfo("  Periode : ".$_GET['from_periode']." - 
".$_GET['to_periode']);
-$pdf->AliasNbPages();
-$pdf->AddPage();
-$pdf->SetAuthor('NOALYSS');
-$pdf->setTitle("Détail fiche",true);
-
-
-$Fiche=new Fiche($cn,$f_id);
-
-
-list($array,$tot_deb,$tot_cred)=$Fiche->get_row_date($from_periode,$to_periode,$_GET['ople']);
-// don't print empty account
-if ( count($array) == 0 )
-{
-    exit;
-}
-$size=array(13,25,20,60,12,20,20,20);
-$align=array('L','C','C','L','R','R','R','R');
-
-$Libelle=sprintf("(%s) %s [ %s 
]",$Fiche->id,$Fiche->getName(),$Fiche->get_quick_code());
-$pdf->SetFont('DejaVu','',10);
-$pdf->Cell(0,8,$Libelle,1,0,'C');
-$pdf->Ln();
-
-
-$pdf->SetFont('DejaVuCond','',8);
-$l=0;
-$pdf->Cell($size[$l],6,'Date',0,0,'L');
-$l++;
-$pdf->Cell($size[$l],6,'Ref',0,0,'C');
-$l++;
-$pdf->Cell($size[$l],6,'Journal',0,0,'C');
-$l++;
-$pdf->Cell($size[$l],6,'Libellé',0,0,'L');
-$l++;
-$pdf->Cell($size[$l],6,'Let',0,0,'R');
-$l++;
-$pdf->Cell($size[$l],6,'Debit',0,0,'R');
-$l++;
-$pdf->Cell($size[$l],6,'Credit',0,0,'R');
-$l++;
-$pdf->Cell($size[$l],6,'Prog',0,0,'R');
-$l++;
-$pdf->ln();
-$tot_deb=0;
-$tot_cred=0;
-$progress=0;
-$current_exercice="";
-bcscale(2);
-for ($e=0;$e<count($array);$e++)
-{
-    $row=$array[$e];
-    /*
-     * separation per exercice
-     */
-    if ( $current_exercice == "") $current_exercice=$row['p_exercice'];
-
-    if ( $current_exercice != $row['p_exercice']) {
-            $str_debit=sprintf("% 12.2f €",$tot_deb);
-            $str_credit=sprintf("% 12.2f €",$tot_cred);
-            $diff_solde=bcsub($tot_deb,$tot_cred);
-            if ( $diff_solde < 0 )
-            {
-                $solde=" créditeur ";
-                $diff_solde=bcmul($diff_solde,-1);
-            }
-            else
-            {
-                 $solde=" débiteur ";
-            }
-            $str_diff_solde=sprintf("%12.2f €",$diff_solde);
-
-            $pdf->SetFont('DejaVu','B',8);
-            $pdf->LongLine(15,6,_('totaux'),0,'L');
-            $pdf->Cell(15,6,$current_exercice,0,0,'L');
-            $pdf->LongLine(40,6,$solde,0,'L');
-            $pdf->Cell(40,6,$str_debit,0,0,'R');
-            $pdf->Cell(40,6,$str_credit,0,0,'R');
-            $pdf->Cell(40,6,$str_diff_solde,0,0,'R');
-            $pdf->Ln();
-            /*
-            * reset total and current_exercice
-            */
-            $prog=0;
-            $current_exercice=$row['p_exercice'];
-            $tot_deb=0;$tot_cred=0;    
-            $pdf->SetFont('DejaVuCond','',8);
-    }
-    $l=0;
-    $progress=bcsub($row['deb_montant'],$row['cred_montant']);
-
-
-    $date=shrink_date($row['j_date_fmt']);
-    $pdf->LongLine($size[$l],6,$date,0,$align[$l]);
-    $l++;
-    if ( $row['jr_pj_number'] == '')
-      $pdf->Cell($size[$l],6,"",0,0,$align[$l]);
-    else
-      $pdf->Cell($size[$l],6,$row['jr_pj_number'],0,0,$align[$l]);
-
-    $l++;
-    
$pdf->LongLine($size[$l],6,mb_substr($row['jrn_def_code'],0,14),0,$align[$l]);
-    $l++;
-    
$pdf->LongLine($size[$l],6,($row['description'].'('.$row['jr_internal'].")"),0,$align[$l]);
-
-    $l++;
-    
$pdf->LongLine($size[$l],6,(($row['letter']!=-1)?strtoupper(base_convert($row['letter'],10,36)):''),0,$align[$l]);
-    $l++;
-    $pdf->LongLine($size[$l],6,(sprintf('% 
12.2f',$row['deb_montant'])),0,$align[$l]);
-    $l++;
-    $pdf->LongLine($size[$l],6,(sprintf('% 
12.2f',$row['cred_montant'])),0,$align[$l]);
-    $l++;
-    $pdf->LongLine($size[$l],6,(sprintf('% 
12.2f',abs($progress))),0,$align[$l]);
-    $l++;
-    $pdf->ln();
-    $tot_deb=bcadd($tot_deb,$row['deb_montant']);
-    $tot_cred=bcadd($tot_cred,$row['cred_montant']);
-    /* -------------------------------------- */
-    /* if details are asked we show them here */
-    /* -------------------------------------- */
-    if ( isset($_GET['oper_detail']))
-    {
-        $detail=new Acc_Operation($cn);
-        $detail->jr_id=$row['jr_id'];
-        $a_detail=$detail->get_jrnx_detail();
-        for ($f=0;$f<count($a_detail);$f++)
-        {
-            $l=0;
-            $pdf->Cell($size[$l],6,'',0,0,$align[$l]);
-            $l++;
-            $pdf->Cell($size[$l],6,$a_detail[$f]['j_qcode'],0,0,'L');
-            $l++;
-            $pdf->Cell($size[$l],6,$a_detail[$f]['j_poste'],0,0,'R');
-            $l++;
-            if ( $a_detail[$f]['j_qcode']=='')
-                $lib=$a_detail[$f]['pcm_lib'];
-            else
-            {
-                $f_id=$cn->get_value('select f_id from vw_poste_qcode where 
j_qcode=$1',array($a_detail[$f]['j_qcode'])) ;
-                $lib=$cn->get_value('select ad_value from fiche_detail where 
ad_id=$1 and f_id=$2',
-                                    array(ATTR_DEF_NAME,$f_id));
-            }
-            $pdf->Cell($size[$l],6,$lib,0,0,$align[$l]);
-            $l++;
-            
$pdf->Cell($size[$l],6,(($a_detail[$f]['letter']!=-1)?$a_detail[$f]['letter']:''),0,0,$align[$l]);
-            $l++;
-
-            $deb=($a_detail[$f]['debit']=='D')?$a_detail[$f]['j_montant']:'';
-            $cred=($a_detail[$f]['debit']=='C')?$a_detail[$f]['j_montant']:'';
-
-            $pdf->Cell($size[$l],6,(sprintf('% 12.2f',$deb)),0,0,$align[$l]);
-            $l++;
-            $pdf->Cell($size[$l],6,(sprintf('% 12.2f',$cred)),0,0,$align[$l]);
-            $l++;
-            $pdf->ln();
-        }
-    }
-
-}
-$str_debit=sprintf("% 12.2f €",$tot_deb);
-$str_credit=sprintf("% 12.2f €",$tot_cred);
-$diff_solde=$tot_deb-$tot_cred;
-if ( $diff_solde < 0 )
-{
-    $solde=" créditeur ";
-    $diff_solde*=-1;
-}
-else
-{
-    $solde=" débiteur ";
-}
-$str_diff_solde=sprintf("%12.2f €",$diff_solde);
-
-$pdf->SetFont('DejaVu','B',8);
-
-$pdf->Cell(160,5,'Débit',0,0,'R');
-$pdf->Cell(30,5,$str_debit,0,0,'R');
-$pdf->Ln();
-$pdf->Cell(160,5,'Crédit',0,0,'R');
-$pdf->Cell(30,5,$str_credit,0,0,'R');
-$pdf->Ln();
-$pdf->Cell(160,5,'Solde '.$solde,0,0,'R');
-$pdf->Cell(30,5,$str_diff_solde,0,0,'R');
-$pdf->Ln();
-
-$fDate=date('dmy-Hi');
-$pdf->Output('fiche-'.$fDate.'.pdf','D');
-
-
-?>
diff --git a/include/export_fiche_pdf.php b/include/export_fiche_pdf.php
deleted file mode 100644
index 73c4925..0000000
--- a/include/export_fiche_pdf.php
+++ /dev/null
@@ -1,232 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief Called by impress->category, export in PDF the history of a category
- * of card
- */
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-// Security we check if user does exist and his privilege
-require_once NOALYSS_INCLUDE.'/class_user.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_pdf.php';
-require_once NOALYSS_INCLUDE.'/class_lettering.php';
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-require_once NOALYSS_INCLUDE.'/ac_common.php';
-
-/* Security */
-$gDossier=dossier::id();
-$cn=new Database($gDossier);
-$g_user->Check();
-$g_user->check_dossier($gDossier);
-
-$pdf=new PDF($cn);
-$pdf->setDossierInfo("  Periode : ".$_GET['start']." - ".$_GET['end']);
-$pdf->AliasNbPages();
-$pdf->AddPage();
-$name=$cn->get_value('select fd_label from fiche_def where 
fd_id=$1',array($_GET['cat']));
-$pdf->SetFont('DejaVu','BI',14);
-$pdf->Cell(0,8,$name,0,1,'C');
-$pdf->SetTitle($name,1);
-$pdf->SetAuthor('NOALYSS');
-/* balance */
-if ( $_GET['histo'] == 4 )
-{
-    $fd=new Fiche_Def($cn,$_REQUEST['cat']);
-    if ( $fd->hasAttribute(ATTR_DEF_ACCOUNT) == false )
-    {
-        $pdf->Cell(0,10, "Cette catégorie n'ayant pas de poste comptable n'a 
pas de balance");
-        //Save PDF to file
-        $fDate=date('dmy-Hi');
-        $pdf->Output("category-$fDate.pdf", 'D');
-        exit;
-    }
-    $aCard=$cn->get_array("select f_id,ad_value from fiche join fiche_Detail 
using (f_id)  where ad_id=1 and fd_id=$1 order by 2 ",array($_REQUEST['cat']));
-
-    if ( empty($aCard))
-    {
-        $pdf->Cell(0,10, "Aucune fiche trouvée");//Save PDF to file
-        $fDate=date('dmy-Hi');
-        $pdf->Output("category-$fDate.pdf", 'D');
-        exit;
-    }
-    $pdf->SetFont('DejaVuCond','',7);
-    $pdf->Cell(30,7,'Quick Code',0,0,'L',0);
-    $pdf->Cell(80,7,'Libellé',0,0,'L',0);
-    $pdf->Cell(20,7,'Débit',0,0,'R',0);
-    $pdf->Cell(20,7,'Crédit',0,0,'R',0);
-    $pdf->Cell(20,7,'Solde',0,0,'R',0);
-    $pdf->Cell(20,7,'D/C',0,0,'C',0);
-    $pdf->Ln();
-    $idx=0;
-    for ($i=0;$i < count($aCard);$i++)
-    {
-        if ( isDate($_REQUEST['start']) == null || isDate ($_REQUEST['end']) 
== null )          exit;
-        $filter= " (j_date >= to_date('".$_REQUEST['start']."','DD.MM.YYYY') ".
-                 " and  j_date <= 
to_date('".$_REQUEST['end']."','DD.MM.YYYY')) ";
-        $oCard=new Fiche($cn,$aCard[$i]['f_id']);
-        $solde=$oCard->get_solde_detail($filter);
-        if ( $solde['debit'] == 0 && $solde['credit']==0) continue;
-
-        if ( $idx % 2 == 0 )
-        {
-            $pdf->SetFillColor(220,221,255);
-            $fill=1;
-        }
-        else
-        {
-            $pdf->SetFillColor(0,0,0);
-            $fill=0;
-        }
-        $idx++;
-
-        $pdf->Cell(30,7,$oCard->strAttribut(ATTR_DEF_QUICKCODE),0,0,'L',$fill);
-        $pdf->Cell(80,7,$oCard->strAttribut(ATTR_DEF_NAME),0,0,'L',$fill);
-        $pdf->Cell(20,7,sprintf('%.02f',$solde['debit']),0,0,'R',$fill);
-        $pdf->Cell(20,7,sprintf('%.02f',$solde['credit']),0,0,'R',$fill);
-        $pdf->Cell(20,7,sprintf('%.02f',abs($solde['solde'])),0,0,'R',$fill);
-        $pdf->Cell(20,7,(($solde['solde']<0)?'CRED':'DEB'),0,0,'C',$fill);
-        $pdf->Ln();
-    }
-}
-else
-{
-    $array=Fiche::get_fiche_def($cn,$_GET['cat'],'name_asc');
-    /*
-     * You show now the result
-     */
-    if ($array == null  )
-    {
-        exit();
-    }
-    $tab=array(13,25,55,20,20,12,20);
-    $align=array('L','L','L','R','R','R','R');
-
-    foreach($array as $row_fiche)
-    {
-      $row=new Fiche($cn,$row_fiche['f_id']);
-        $letter=new Lettering_Card($cn);
-        
$letter->set_parameter('quick_code',$row->strAttribut(ATTR_DEF_QUICKCODE));
-        $letter->set_parameter('start',$_GET['start']);
-        $letter->set_parameter('end',$_GET['end']);
-        // all
-        if ( $_GET['histo'] == 0 )
-        {
-            $letter->get_all();
-        }
-
-        // lettered
-        if ( $_GET['histo'] == 1 )
-        {
-            $letter->get_letter();
-        }
-        // unlettered
-        if ( $_GET['histo'] == 2 )
-        {
-            $letter->get_unletter();
-        }
-        /* skip if nothing to display */
-        if (count($letter->content) == 0 ) continue;
-        $pdf->SetFont('DejaVuCond','',10);
-       $fiche=new Fiche($cn,$row_fiche['f_id']);
-        $pdf->Cell(0,7,$fiche->strAttribut(ATTR_DEF_NAME),1,1,'C');
-
-        $pdf->SetFont('DejaVuCond','',7);
-
-        $pdf->Cell($tab[0],7,'Date');
-        $pdf->Cell($tab[1],7,'ref');
-        $pdf->Cell($tab[1],7,'Int.');
-        $pdf->Cell($tab[2],7,'Comm');
-        $pdf->Cell(40,7,'Montant',0,0,'C');
-        $pdf->Cell($tab[5],7,'Let.',0,0,'R');
-        $pdf->Cell($tab[6],7,'Som. Let.',0,0,'R');
-        $pdf->ln();
-
-        $amount_deb=0;
-        $amount_cred=0;
-        for ($i=0;$i<count($letter->content);$i++)
-        {
-            if ( $i % 2 == 0 )
-            {
-                $pdf->SetFillColor(220,221,255);
-                $fill=1;
-            }
-            else
-            {
-                $pdf->SetFillColor(0,0,0);
-                $fill=0;
-            }
-            $pdf->SetFont('DejaVuCond','',7);
-            $row=$letter->content[$i];
-            $str_date=shrink_date($row['j_date_fmt']);
-
-            $pdf->Cell($tab[0],4,$str_date,0,0,$align[0],$fill);
-            $pdf->Cell($tab[1],4,$row['jr_pj_number'],0,0,$align[1],$fill);
-            $pdf->Cell($tab[1],4,$row['jr_internal'],0,0,$align[1],$fill);
-            $pdf->Cell($tab[2],4,$row['jr_comment'],0,0,$align[2],$fill);
-            if ( $row['j_debit'] == 't')
-            {
-                
$pdf->Cell($tab[3],4,sprintf('%10.2f',$row['j_montant']),0,0,$align[4],$fill);
-                $amount_deb+=$row['j_montant'];
-                $pdf->Cell($tab[4],4,"",0,0,'C',$fill);
-            }
-            else
-            {
-                $pdf->Cell($tab[3],4,"",0,0,'C',$fill);
-                
$pdf->Cell($tab[4],4,sprintf('%10.2f',$row['j_montant']),0,0,$align[4],$fill);
-                $amount_cred+=$row['j_montant'];
-            }
-            if ($row['letter'] != -1 )
-            {
-                
$pdf->Cell($tab[5],4,strtoupper(base_convert($row['letter'],10,36)),0,0,$align[5],$fill);
-                // get sum for this lettering
-                $sql="select sum(j_montant) from jrnx where j_debit=$1 and 
j_id in ".
-                     " (select j_id from jnt_letter join letter_deb using 
(jl_id) where jl_id=$2 union ".
-                     "  select j_id from jnt_letter join letter_cred using 
(jl_id) where jl_id=$3)";
-                
$sum=$cn->get_value($sql,array($row['j_debit'],$row['letter'],$row['letter']));
-                $pdf->Cell($tab[6],4,sprintf('%.2f',$sum),'0','0','R',$fill);
-            }
-            else
-                $pdf->Cell($tab[5],4,"",0,0,'R',$fill);
-            $pdf->Ln();
-        }
-        $pdf->SetFillColor(0,0,0);
-        $pdf->SetFont('DejaVuCond','B',8);
-        $debit =sprintf('Debit  : % 12.2f',$amount_deb);
-        $credit=sprintf('Credit : % 12.2f',$amount_cred);
-        if ( $amount_deb>$amount_cred) $s='solde débiteur';
-        else $s='solde crediteur';
-        $solde =sprintf('%s  : % 
12.2f',$s,(abs(round($amount_cred-$amount_deb,2))));
-
-        $pdf->Cell(0,6,$debit,0,0,'R');
-        $pdf->ln(4);
-        $pdf->Cell(0,6,$credit,0,0,'R');
-        $pdf->ln(4);
-        $pdf->Cell(0,6,$solde,0,0,'R');
-        $pdf->ln(4);
-
-        $pdf->Ln();
-    }
-}
-//Save PDF to file
-$fDate=date('dmy-Hi');
-$pdf->Output("category-$fDate.pdf", 'D');
-exit;
diff --git a/include/export_follow_up_csv.php b/include/export_follow_up_csv.php
deleted file mode 100644
index 0fa1323..0000000
--- a/include/export_follow_up_csv.php
+++ /dev/null
@@ -1,42 +0,0 @@
-<?php
-
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/**
- * @file
- * @brief export Action Gestion to csv, taking in account the search
- *
- */
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_follow_up.php';
-header('Pragma: public');
-header('Content-type: application/csv');
-header('Content-Disposition: attachment;filename="action-gestion.csv"',FALSE);
-
-$follow=new Follow_Up($cn);
-$array=$_GET;
-if ( isset ($_POST['query']) ) $p_array['query']=$_POST['query'];
-
-echo $follow->export_csv($_GET);
-
-exit();
-
-?>
diff --git a/include/export_form_csv.php b/include/export_form_csv.php
deleted file mode 100644
index 6fb205c..0000000
--- a/include/export_form_csv.php
+++ /dev/null
@@ -1,105 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-// Copyright Author Dany De Bontridder address@hidden
-/*! \file
- * \brief Send a report in CSV format
- */
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once  NOALYSS_INCLUDE.'/ac_common.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once  NOALYSS_INCLUDE.'/class_user.php';
-require_once NOALYSS_INCLUDE.'/class_acc_report.php';
-require_once NOALYSS_INCLUDE.'/class_impress.php';
-header('Pragma: public');
-header('Content-type: application/csv');
-header('Content-Disposition: attachment;filename="rapport.csv"',FALSE);
-
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-$gDossier=dossier::id();
-
-/* Admin. Dossier */
-$cn=new Database($gDossier);
-
-$Form=new Acc_Report($cn,$_GET['form_id']);
-$Form->get_name();
-// Step ?
-//--
-$step=HtmlInput::default_value_get("p_step", 0);
-if (  $step == 0 )
-{
-    if ( $_GET ['type_periode'] == 0 )
-        $array=$Form->get_row( $_GET['from_periode'],$_GET['to_periode'], 
$_GET['type_periode']);
-    else
-        $array=$Form->get_row( $_GET['from_date'],$_GET['to_date'], 
$_GET['type_periode']);
-
-
-    if ( count($Form->row ) == 0 )
-        exit;
-
-    echo       "\"Description\";".
-    "\"Montant\"\n";
-
-
-
-    foreach ( $Form->row as $op )
-    {
-        echo '"'.$op['desc'].'"'.";".
-        nb($op['montant']).
-        "\n";
-
-    }
-}
-elseif ($step == 1)
-{
-    // Gather all the data
-    //---
-    for ($e=$_GET['from_periode'];$e<=$_GET['to_periode'];$e+=$_GET['p_step'])
-    {
-        $periode=getPeriodeName($cn,$e);
-        if ( $periode == null ) continue;
-        $array[]=$Form->get_row($e,$e,$_GET['type_periode']);
-        $periode_name[]=$periode;
-    }
-    // Display column heading
-    //--
-    $x="";
-    printf ("Mois;");
-    foreach ($array[0] as $e)
-    {
-        printf("%s%s",$x,$e['desc']);
-        $x=";";
-
-    }
-    printf("\n");
-    // Display value for each line
-    //--
-    $a=0;
-    foreach ($array as $e )
-    {
-        print $periode_name[$a];
-        $a++;
-        foreach ($e as $elt)
-        {
-            printf(";%s",nb($elt['montant']));
-        }
-        printf("\n");
-    }
-}
-exit;
-?>
diff --git a/include/export_form_pdf.php b/include/export_form_pdf.php
deleted file mode 100644
index 5bb8e12..0000000
--- a/include/export_form_pdf.php
+++ /dev/null
@@ -1,130 +0,0 @@
-<?php
-
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-/*! \file
- * \brief Send a report in PDF
- */
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-include_once("class_acc_report.php");
-include_once("ac_common.php");
-require_once NOALYSS_INCLUDE.'/class_database.php';
-include_once("class_impress.php");
-require_once NOALYSS_INCLUDE.'/class_user.php';
-require_once  NOALYSS_INCLUDE.'/header_print.php';
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-require_once NOALYSS_INCLUDE.'/class_acc_report.php';
-require_once NOALYSS_INCLUDE.'/class_pdf.php';
-
-$gDossier=dossier::id();
-
-$cn=new Database($gDossier);
-
-extract($_GET);
-$ret="";
-$Form=new Acc_Report($cn,$form_id);
-$Libelle=sprintf("%s ",$Form->get_name());
-$pdf= new PDF($cn);
-$pdf->setDossierInfo($Libelle);
-$pdf->AliasNbPages();
-$pdf->AddPage();
-$pdf->SetAuthor('NOALYSS');
-$pdf->setTitle("Rapport ".$Libelle,true);
-
-// Step ??
-//--
-$step=HtmlInput::default_value_get("p_step", 0);
-
-if ( $step == 0 )
-{
-    // No step asked
-    //--
-    if ( $_GET ['type_periode'] == 0 )
-        $array=$Form->get_row( $_GET['from_periode'],$_GET['to_periode'], 
$_GET['type_periode']);
-    else
-        $array=$Form->get_row( $_GET['from_date'],$_GET['to_date'], 
$_GET['type_periode']);
-
-}
-else
-{
-    // yes with step
-    //--
-    for ($e=$_GET['from_periode'];$e<=$_GET['to_periode'];$e+=$_GET['p_step'])
-    {
-        $periode=getPeriodeName($cn,$e);
-        if ( $periode == null ) continue;
-        $array[]=$Form->get_row($e,$e,'periode');
-        $periode_name[]=$periode;
-    }
-
-}
-
-
-$pdf->SetFont('DejaVuCond','',8);
-
-// without step
-if ( $step == 0 )
-{
-    if ( $_GET['type_periode'] == 0 )
-    {
-        $q=getPeriodeName($cn,$from_periode);
-        if ( $from_periode != $to_periode)
-        {
-            $periode=sprintf("Période %s à 
%s",$q,getPeriodeName($cn,$to_periode));
-        }
-        else
-        {
-            $periode=sprintf("Période %s",$q);
-        }
-    }
-    else
-    {
-        $periode=sprintf("Date %s jusque 
%s",$_GET['from_date'],$_GET['to_date']);
-    }
-    $pdf->Cell(0,7,$periode,'B');
-    $pdf->Ln();
-    for ($i=0;$i<count($array);$i++)
-    {
-        $pdf->Cell(160,6,$array[$i]['desc']);
-        $pdf->Cell(30,6,sprintf('% 12.2f',$array[$i]['montant']),0,0,'R');
-        $pdf->Ln();
-    }
-}
-else
-{ // With Step
-    $a=0;
-    foreach ($array as $e)
-    {
-        $pdf->Cell(0,7,$periode_name[$a],'B');
-        $pdf->Ln();
-        $a++;
-        for ($i=0;$i<count($e);$i++)
-        {
-            $pdf->Cell(160,6,$e[$i]['desc']);
-            $pdf->Cell(30,6,sprintf('% 12.2f',$e[$i]['montant']),0,0,'R');
-            $pdf->Ln();
-        }
-    }
-}
-
-$fDate=date('dmy-Hi');
-$pdf->Output('rapport-'.$fDate.'.pdf','D');
-
-?>
diff --git a/include/export_gl_csv.php b/include/export_gl_csv.php
deleted file mode 100644
index 2e40e61..0000000
--- a/include/export_gl_csv.php
+++ /dev/null
@@ -1,214 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*! \file
- * \brief create GL comptes as PDF
- */
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-include_once('class_acc_account_ledger.php');
-include_once('ac_common.php');
-require_once NOALYSS_INCLUDE.'/class_database.php';
-include_once('class_impress.php');
-require_once NOALYSS_INCLUDE.'/class_own.php';
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-require_once NOALYSS_INCLUDE.'/class_user.php';
-
-header('Content-type: application/csv');
-header('Content-Disposition: attachment;filename="gl_comptes.csv"',FALSE);
-header('Pragma: public');
-
-
-$gDossier=dossier::id();
-
-/* Security */
-$cn=new Database($gDossier);
-
-
-extract($_GET);
-
-if ( isset($poste_id) && strlen(trim($poste_id)) != 0 && isNumber($poste_id) )
-{
-    if ( isset ($poste_fille) )
-    {
-        $parent=$poste_id;
-        $a_poste=$cn->get_array("select pcm_val from tmp_pcmn where 
pcm_val::text like '$parent%' order by pcm_val::text");
-    }
-    elseif ( $cn->count_sql('select * from tmp_pcmn where 
pcm_val='.sql_string($poste_id)) != 0 )
-    {
-        $a_poste=array('pcm_val' => $poste_id);
-    }
-}
-else
-{
-  $cond_poste='';
-  $sql="select pcm_val from tmp_pcmn ";
-    if ($from_poste != '')
-      {
-       $cond_poste = '  where ';
-       $cond_poste .=" pcm_val >= upper 
('".Database::escape_string($from_poste)."')";
-      }
-
-    if ( $to_poste != '')
-      {
-       if  ( $cond_poste == '')
-         {
-           $cond_poste =  " where pcm_val <= upper 
('".Database::escape_string($to_poste)."')";
-         }
-       else
-         {
-           $cond_poste.=" and pcm_val <= upper 
('".Database::escape_string($to_poste)."')";
-         }
-      }
-
-    $sql=$sql.$cond_poste.'  order by pcm_val::text';
-
-    $a_poste=$cn->get_array($sql);
-
-}
-
-if ( count($a_poste) == 0 )
-{
-    echo 'Rien à rapporter.';
-    printf("\n");
-    exit;
-}
-
-// Header
-$header = array( "Date", "Référence", "Libellé", "Pièce","Lettrage", "Débit", 
"Crédit", "Solde" );
-
-$l=(isset($_GET['letter']))?2:0;
-$s=(isset($_REQUEST['solded']))?1:0;
-
-foreach ($a_poste as $poste)
-{
-
-
-  $Poste=new Acc_Account_Ledger($cn,$poste['pcm_val']);
-
-  $array1=$Poste->get_row_date($from_periode,$to_periode,$l,$s);
-  // don't print empty account
-  if ( count($array1) == 0 )
-    {
-      continue;
-    }
-  $array=$array1[0];
-  $tot_deb=$array1[1];
-  $tot_cred=$array1[2];
-
-    // don't print empty account
-    if ( count($array) == 0 )
-    {
-        continue;
-    }
-
-    echo sprintf("%s - %s ",$Poste->id,$Poste->get_name());
-    printf("\n");
-
-    for($i=0;$i<count($header);$i++)
-        echo $header[$i].";";
-    printf("\n");
-
-    $solde = 0.0;
-    $solde_d = 0.0;
-    $solde_c = 0.0;
-    $current_exercice="";
-    foreach ($Poste->row as $detail)
-    {
-
-        /*
-               [0] => 1 [jr_id] => 1
-               [1] => 01.02.2009 [j_date_fmt] => 01.02.2009
-               [2] => 2009-02-01 [j_date] => 2009-02-01
-               [3] => 0 [deb_montant] => 0
-               [4] => 12211.9100 [cred_montant] => 12211.9100
-               [5] => Ecriture douverture [description] => Ecriture douverture
-               [6] => Opération Diverses [jrn_name] => Opération Diverses
-               [7] => f [j_debit] => f
-               [8] => 17OD-01-1 [jr_internal] => 17OD-01-1
-               [9] => ODS1 [jr_pj_number] => ODS1 ) 1
-         */
-/*
-             * separation per exercice
-             */
-        if ( $current_exercice == "") $current_exercice=$detail['p_exercice'];
-
-        if ( $current_exercice != $detail['p_exercice']) {
-            echo ";";
-            echo '"'.$current_exercice.'";';
-            echo ";";
-            echo ";";
-            echo 'Total du compte '.$Poste->id.";";
-            echo ($solde_d  > 0 ? nb($solde_d)  : '').";";
-            echo ($solde_c  > 0 ? nb( $solde_c)  : '').";";
-            echo nb(abs($solde_c-$solde_d)).";";
-            echo ($solde_c > $solde_d ? 'C' : 'D').";";
-            printf("\n");
-            printf("\n");
-            /*
-            * reset total and current_exercice
-            */
-            $current_exercice=$detail['p_exercice'];
-            $solde = 0.0;
-            $solde_d = 0.0;
-            $solde_c = 0.0;
-
-        }
-        if ($detail['cred_montant'] > 0)
-        {
-            $solde   -= $detail['cred_montant'];
-            $solde_c += $detail['cred_montant'];
-        }
-        if ($detail['deb_montant'] > 0)
-        {
-            $solde   += $detail['deb_montant'];
-            $solde_d += $detail['deb_montant'];
-        }
-
-        echo $detail['j_date_fmt'].";";
-        echo $detail['jr_internal'].";";
-        echo $detail['description'].";";
-        echo $detail['jr_pj_number'].";";
-        if ($detail['letter'] == -1) { echo ';'; } else { echo 
$detail['letter'].";";}
-        echo ($detail['deb_montant']  > 0 ? nb($detail['deb_montant'])  : 
'').";";
-        echo ($detail['cred_montant'] > 0 ? nb($detail['cred_montant']) : 
'').";";
-        echo nb(abs($solde)).";";
-               echo $Poste->get_amount_side($solde);
-        printf("\n");
-
-    }
-
-
-    echo ";";
-    echo '"'.$current_exercice.'";';
-    echo ";";
-    echo ";";
-    echo 'Total du compte '.$Poste->id.";";
-    echo ($solde_d  > 0 ? nb($solde_d)  : '').";";
-    echo ($solde_c  > 0 ? nb( $solde_c)  : '').";";
-    echo nb(abs($solde_c-$solde_d)).";";
-    echo ($solde_c > $solde_d ? 'C' : 'D').";";
-    printf("\n");
-    printf("\n");
-}
-
-exit;
-
-?>
diff --git a/include/export_gl_pdf.php b/include/export_gl_pdf.php
deleted file mode 100644
index eed2fe5..0000000
--- a/include/export_gl_pdf.php
+++ /dev/null
@@ -1,239 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*! \file
- * \brief create GL comptes as PDF
- */
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-include_once('class_acc_account_ledger.php');
-include_once('ac_common.php');
-require_once NOALYSS_INCLUDE.'/class_database.php';
-include_once('class_impress.php');
-require_once NOALYSS_INCLUDE.'/class_own.php';
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-require_once NOALYSS_INCLUDE.'/class_user.php';
-require_once NOALYSS_INCLUDE.'/class_pdf.php';
-bcscale(2);
-
-$gDossier=dossier::id();
-
-/* Security */
-$cn=new Database($gDossier);
-$g_user->Check();
-$g_user->check_dossier($gDossier);
-
-$sql="select pcm_val from tmp_pcmn ";
-
-extract($_GET);
-$cond_poste="";
-if ($from_poste != '')
-  {
-    $cond_poste = '  where ';
-    $cond_poste .=' pcm_val >= upper 
(\''.Database::escape_string($from_poste).'\')';
-  }
-
-if ( $to_poste != '')
-  {
-    if  ( $cond_poste == '')
-      {
-       $cond_poste =  ' where pcm_val <= upper 
(\''.Database::escape_string($to_poste).'\')';
-      }
-    else
-      {
-       $cond_poste.=' and pcm_val <= upper 
(\''.Database::escape_string($to_poste).'\')';
-      }
-  }
-
-$sql=$sql.$cond_poste.'  order by pcm_val::text';
-$a_poste=$cn->get_array($sql);
-
-$pdf = new PDF($cn);
-$pdf->setDossierInfo("  Periode : ".$from_periode." - ".$to_periode);
-$pdf->AliasNbPages();
-$pdf->AddPage();
-$pdf->setTitle("Grand Livre",true);
-$pdf->SetAuthor('NOALYSS');
-
-if ( count($a_poste) == 0 )
-{
-    $pdf->Output();
-    return;
-}
-
-// Header
-$header = array( "Date", "Référence", "Libellé", "Pièce","Let", "Débit", 
"Crédit", "Solde" );
-// Left or Right aligned
-$lor    = array( "L"   , "L"        , "L"      , "L"    , "R",   "R"    , "R"  
   , "R"     );
-// Column widths (in mm)
-$width  = array( 13    , 20         , 60       , 15     ,  12     , 20     , 
20      , 20      );
-$l=(isset($_REQUEST['letter']))?2:0;
-$s=(isset($_REQUEST['solded']))?1:0;
-
-foreach ($a_poste as $poste)
-{
-
-  $Poste=new Acc_Account_Ledger($cn,$poste['pcm_val']);
-
-
-  $array1=$Poste->get_row_date($from_periode,$to_periode,$l,$s);
-  // don't print empty account
-  if ( count($array1) == 0 )
-    {
-        continue;
-    }
-  $array=$array1[0];
-  $tot_deb=$array1[1];
-  $tot_cred=$array1[2];
-
-    $pdf->SetFont('DejaVuCond','',10);
-    $Libelle=sprintf("%s - %s ",$Poste->id,$Poste->get_name());
-    $pdf->Cell(0, 7, $Libelle, 1, 1, 'C');
-
-    $pdf->SetFont('DejaVuCond','',6);
-    for($i=0;$i<count($header);$i++)
-        $pdf->Cell($width[$i], 4, $header[$i], 0, 0, $lor[$i]);
-    $pdf->Ln();
-
-    $pdf->SetFont('DejaVuCond','',7);
-
-
-    $solde = 0.0;
-    $solde_d = 0.0;
-    $solde_c = 0.0;
-    $current_exercice="";
-    foreach ($Poste->row as $detail)
-    {
-
-        /*
-               [0] => 1 [jr_id] => 1
-               [1] => 01.02.2009 [j_date_fmt] => 01.02.2009
-               [2] => 2009-02-01 [j_date] => 2009-02-01
-               [3] => 0 [deb_montant] => 0
-               [4] => 12211.9100 [cred_montant] => 12211.9100
-               [5] => Ecriture douverture [description] => Ecriture douverture
-               [6] => Opération Diverses [jrn_name] => Opération Diverses
-               [7] => f [j_debit] => f
-               [8] => 17OD-01-1 [jr_internal] => 17OD-01-1
-               [9] => ODS1 [jr_pj_number] => ODS1 ) 1
-         */
-         /*
-             * separation per exercice
-             */
-            if ( $current_exercice == "") 
$current_exercice=$detail['p_exercice'];
-            
-            if ( $current_exercice != $detail['p_exercice']) {
-                
-                $pdf->SetFont('DejaVuCond','B',8);
-                $i=0;
-                $pdf->Cell($width[$i], 6, $current_exercice, 0, 0, $lor[$i]);
-                $i++;
-                $pdf->Cell($width[$i], 6, '', 0, 0, $lor[$i]);
-                $i++;
-                $pdf->Cell($width[$i], 6, '', 0, 0, $lor[$i]);
-                $i++;
-                $pdf->Cell($width[$i], 6, '', 0, 0, $lor[$i]);
-                $i++;
-                $pdf->Cell($width[$i], 6, 'Total du compte '.$Poste->id, 0, 0, 
'R');
-                $i++;
-                $pdf->Cell($width[$i], 6, ($solde_d  > 0 ? nbm($solde_d)  : 
''), 0, 0, $lor[$i]);
-                $i++;
-                $pdf->Cell($width[$i], 6, ($solde_c  > 0 ? nbm( $solde_c)  : 
''), 0, 0, $lor[$i]);
-                $i++;
-                $pdf->Cell($width[$i], 6, nbm(abs($solde_c-$solde_d)), 0, 0, 
$lor[$i]);
-                $i++;
-                $pdf->Cell(5, 6, ($solde_c > $solde_d ? 'C' : 'D'), 0, 0, 'L');
-                /*
-                * reset total and current_exercice
-                */
-                $current_exercice=$detail['p_exercice'];
-                $solde = 0.0;
-                $solde_d = 0.0;
-                $solde_c = 0.0;
-                $pdf->Ln();
-                $pdf->SetFont('DejaVuCond','',7);
-
-            }
-
-        if ($detail['cred_montant'] > 0)
-        {
-            $solde   = bcsub ($solde,$detail['cred_montant']);
-            $solde_c = bcadd($solde_c,$detail['cred_montant']);
-        }
-        if ($detail['deb_montant'] > 0)
-        {
-            $solde   = bcadd($solde,$detail['deb_montant']);
-            $solde_d = bcadd($solde_d,$detail['deb_montant']);
-        }
-
-        $i = 0;
-               $side=" ".$Poste->get_amount_side($solde);
-        $pdf->LongLine($width[$i], 6, shrink_date($detail['j_date_fmt']), 0, 
$lor[$i]);
-        $i++;
-        $pdf->LongLine($width[$i], 6, $detail['jr_internal'], 0, $lor[$i] );
-        $i++;
-        /* limit set to 40 for the substring */
-        $triple_point = (mb_strlen($detail['description']) > 40 ) ? '...':'';
-        $pdf->LongLine($width[$i], 6, 
mb_substr($detail['description'],0,40).$triple_point, 0,$lor[$i]);
-        $i++;
-        $pdf->Cell($width[$i], 6, $detail['jr_pj_number'], 0, 0, $lor[$i]);
-        $i++;
-        $pdf->Cell($width[$i], 6, 
($detail['letter']!=-1)?$detail['letter']:'', 0, 0, $lor[$i]);
-        $i++;
-        $pdf->Cell($width[$i], 6, ($detail['deb_montant']  > 0 ? nbm( 
$detail['deb_montant'])  : ''), 0, 0, $lor[$i]);
-        $i++;
-        $pdf->Cell($width[$i], 6, ($detail['cred_montant'] > 0 ? nbm( 
$detail['cred_montant']) : ''), 0, 0, $lor[$i]);
-        $i++;
-        $pdf->Cell($width[$i], 6, nbm(abs( $solde)).$side, 0, 0, $lor[$i]);
-        $i++;
-        $pdf->Ln();
-
-    }
-
-
-    $pdf->SetFont('DejaVuCond','B',8);
-
-    $i = 0;
-    $pdf->Cell($width[$i], 6, $current_exercice, 0, 0, $lor[$i]);
-    $i++;
-    $pdf->Cell($width[$i], 6, '', 0, 0, $lor[$i]);
-    $i++;
-    $pdf->Cell($width[$i], 6, '', 0, 0, $lor[$i]);
-    $i++;
-    $pdf->Cell($width[$i], 6, '', 0, 0, $lor[$i]);
-    $i++;
-    $pdf->Cell($width[$i], 6, 'Total du compte '.$Poste->id, 0, 0, 'R');
-    $i++;
-    $pdf->Cell($width[$i], 6, ($solde_d  > 0 ? nbm($solde_d)  : ''), 0, 0, 
$lor[$i]);
-    $i++;
-    $pdf->Cell($width[$i], 6, ($solde_c  > 0 ? nbm( $solde_c)  : ''), 0, 0, 
$lor[$i]);
-    $i++;
-    $pdf->Cell($width[$i], 6, nbm(abs($solde_c-$solde_d)), 0, 0, $lor[$i]);
-    $i++;
-    $pdf->Cell(5, 6, ($solde_c > $solde_d ? 'C' : 'D'), 0, 0, 'L');
-
-    $pdf->Ln();
-    $pdf->Ln();
-
-}
-//Save PDF to file
-$pdf->Output("gl_comptes.pdf", 'D');
-exit;
-?>
diff --git a/include/export_ledger_csv.php b/include/export_ledger_csv.php
deleted file mode 100644
index a7f94ab..0000000
--- a/include/export_ledger_csv.php
+++ /dev/null
@@ -1,284 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-// Copyright Author Dany De Bontridder address@hidden
-/*! \file
- * \brief Send a ledger in CSV format
- */
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-$fDate = date('dmy-Hi');
-header('Pragma: public');
-header('Content-type: application/csv');
-header('Content-Disposition: attachment;filename="jrn-'.$fDate.'.csv"',FALSE);
-include_once ("ac_common.php");
-require_once NOALYSS_INCLUDE.'/class_own.php';
-require_once NOALYSS_INCLUDE.'/class_acc_ledger_sold.php';
-require_once NOALYSS_INCLUDE.'/class_acc_ledger_purchase.php';
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-$gDossier=dossier::id();
-
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_acc_ledger.php';
-
-/*
- * Variable from $_GET
- */
-$get_jrn=HtmlInput::default_value_get('jrn_id', -1);
-$get_option=HtmlInput::default_value_get('p_simple', -1);
-$get_from_periode=  HtmlInput::default_value_get('from_periode', null);
-$get_to_periode=HtmlInput::default_value_get('to_periode', NULL);
-
-//--- Check validity
-if ( $get_jrn ==-1  || $get_option == -1 || $get_from_periode == null || 
$get_to_periode == null)
-{
-    die (_('Options invalides'));
-}
-
-
-require_once  NOALYSS_INCLUDE.'/class_user.php';
-$g_user->Check();
-$g_user->check_dossier($gDossier);
-
-//----------------------------------------------------------------------------
-// $get_jrn == 0 when request for all ledger, in that case, we must filter
-// the legder with the security in Acc_Ledger::get_row
-//----------------------------------------------------------------------------
-if ($get_jrn!=0 &&  $g_user->check_jrn($get_jrn) =='X')
-{
-    NoAccess();
-    exit();
-}
-
-$Jrn=new Acc_Ledger($cn,$get_jrn);
-
-$Jrn->get_name();
-$jrn_type=$Jrn->get_type();
-
-//
-// With Detail per item which is possible only for VEN or ACH
-// 
-if ($get_option == 2)
-{
-    if ($jrn_type != 'ACH' && $jrn_type != 'VEN' || $Jrn->id == 0)
-    {
-        $get_option = 0;
-    }
-    else
-    {
-        switch ($jrn_type)
-        {
-            case 'VEN':
-                $ledger = new Acc_Ledger_Sold($cn, $get_jrn);
-                $ret_detail = $ledger->get_detail_sale($get_from_periode, 
$get_to_periode);
-                $a_heading= Acc_Ledger_Sold::heading_detail_sale();
-                
-                break;
-            case 'ACH':
-                $ledger = new Acc_Ledger_Purchase($cn, $get_jrn);
-                $ret_detail = $ledger->get_detail_purchase($get_from_periode, 
$get_to_periode);
-                $a_heading=  Acc_Ledger_Purchase::heading_detail_purchase();
-                break;
-            default:
-                die(__FILE__ . ":" . __LINE__ . 'Journal invalide');
-                break;
-        }
-        if ($ret_detail == null)
-            return;
-        $nb = Database::num_row($ret_detail);
-        $output=fopen("php://output","w");
-        
-        for ($i = 0;$i < $nb ; $i++) {
-            $row=Database::fetch_array($ret_detail, $i);
-            if ( $i == 0 ) {
-              fputcsv($output,$a_heading,';');
-            }
-            $a_row=array();
-            for ($j=0;$j < count($row) / 2;$j++) {
-                $a_row[]=$row[$j];
-            }
-            fputcsv($output,$a_row,';');
-            unset($a_row);
-        }
-    }
-}
-//-----------------------------------------------------------------------------
-// Detailled printing
-// For miscellaneous legder or all ledgers
-//-----------------------------------------------------------------------------
-if  ( $get_option == 0 )
-{
-    $Jrn->get_row( $get_from_periode, $get_to_periode );
-
-    if ( count($Jrn->row) == 0)
-        exit;
-    foreach ( $Jrn->row as $op )
-    {
-        // should clean description : remove <b><i> tag and '; char
-        $desc=$op['description'];
-        $desc=str_replace("<b>","",$desc);
-        $desc=str_replace("</b>","",$desc);
-        $desc=str_replace("<i>","",$desc);
-        $desc=str_replace("</i>","",$desc);
-        $desc=str_replace('"',"'",$desc);
-        $desc=str_replace(";",",",$desc);
-
-        printf("\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";%s;%s\n",
-               $op['j_id'],
-               $op['jr_pj_number'],
-               $op['internal'],
-               $op['j_date'],
-               $op['poste'],
-               $desc,
-               nb($op['deb_montant']),
-               nb($op['cred_montant'])
-              );
-
-    }
-    exit;
-}
-//-----------------------------------------------------------------------------
-// Detail printing for ACH or VEN : 1 row resume the situation with VAT, DNA
-// for Misc the amount 
-// For Financial only the tiers and the sign of the amount
-//-----------------------------------------------------------------------------
-if  ($get_option == 1)
-{
-   
-//-----------------------------------------------------
-     if ( $jrn_type == 'ODS' || $jrn_type == 'FIN' || $jrn_type=='GL')
-       {
-          $Row=$Jrn->get_rowSimple($get_from_periode,
-                             $get_to_periode,
-                             0);
-        printf ('" operation";'.
-                '"Date";'.
-                '"N° Pièce";'.
-                '"Tiers";'.
-                '"commentaire";'.
-                '"internal";'.
-                '"montant";'.
-                "\r\n");
-        foreach ($Row as $line)
-          {
-
-            echo $line['num'].";";
-            echo $line['date'].";";
-            echo $line['jr_pj_number'].";";
-            echo $Jrn->get_tiers($line['jrn_def_type'],$line['jr_id']).";";
-            echo $line['comment'].";";
-            echo $line['jr_internal'].";";
-            //   echo "<TD>".$line['pj'].";";
-            // If the ledger is financial :
-            // the credit must be negative and written in red
-            // Get the jrn type
-            if ( $line['jrn_def_type'] == 'FIN' ) {
-              $positive = $cn->get_value("select qf_amount from quant_fin  ".
-                                         " where jr_id=".$line['jr_id']);
-
-              echo nb($positive);
-              echo ";";
-            }
-            else
-              {
-                echo nb($line['montant']).";";
-              }
-
-            printf("\r\n");
-          }
-       }
-
-//------------------------------------------------------------------------------
-// One line summary with tiers, amount VAT, DNA, tva code ....
-// 
-//------------------------------------------------------------------------------
-    if ( $jrn_type=='ACH' || $jrn_type=='VEN')
-    {
-        $Row=$Jrn->get_rowSimple($get_from_periode,
-                             $get_to_periode,
-                             0);
-        $cn->prepare('reconcile_date',"select to_char(jr_date,'DD.MM.YY') as 
str_date,* "
-                . "from jrn "
-                . "where "
-                . "jr_id in (select jra_concerned from jrn_rapt where jr_id = 
$1 union all select jr_id from jrn_rapt where jra_concerned=$1)");
-
-        $own=new Own($cn);
-        $col_tva="";
-
-        if ( $own->MY_TVA_USE=='Y')
-        {
-            $a_Tva=$cn->get_array("select tva_id,tva_label from tva_rate order 
by tva_rate,tva_label,tva_id");
-            foreach($a_Tva as $line_tva)
-            {
-                $col_tva.='"Tva '.$line_tva['tva_label'].'";';
-            }
-        }
-        echo 
'"Date";"Paiement";"operation";"Pièce";"Client/Fourn.";"Commentaire";"inter.";"HTVA";"privé";"DNA";"tva
 non ded.";"TVA NP";'.$col_tva.'"TVAC";"opérations liées"'."\n\r";
-        foreach ($Row as $line)
-        {
-            printf('"%s";"%s";"%s";"%s";"%s";%s;%s;%s;%s;%s;%s;%s;',
-                   $line['date'],
-                   $line['date_paid'],
-                   $line['num'],
-                   $line['jr_pj_number'],
-                   $Jrn->get_tiers($line['jrn_def_type'],$line['jr_id']),
-                   $line['comment'],
-                   $line['jr_internal'],
-                   nb($line['HTVA']),
-                   nb($line['dep_priv']),
-                   nb($line['dna']),
-                   nb($line['tva_dna']),
-                    nb($line['tva_np'])
-                   );
-            $a_tva_amount=array();
-            //- set all TVA to 0
-            foreach ($a_Tva as $l) {
-                $t_id=$l["tva_id"];
-                $a_tva_amount[$t_id]=0;
-            }
-            foreach ($line['TVA'] as $lineTVA)
-            {
-                $idx_tva=$lineTVA[1][0];
-                $a_tva_amount[$idx_tva]=$lineTVA[1][2];
-             }
-            if ($own->MY_TVA_USE == 'Y' )
-            {
-                foreach ($a_Tva as $line_tva)
-                {
-                    $a=$line_tva['tva_id'];
-                    echo nb($a_tva_amount[$a]).';';
-                }
-            }
-            echo nb ($line['TVAC']);
-            /**
-             * Retrieve payment if any
-             */
-             
$ret_reconcile=$cn->execute('reconcile_date',array($line['jr_id']));
-             $max=Database::num_row($ret_reconcile);
-            if ($max > 0) {
-                $sep=";";
-                for ($e=0;$e<$max;$e++) {
-                    $row=Database::fetch_array($ret_reconcile, $e);
-                    echo $sep.$row['str_date'].'; '. $row['jr_internal'];
-                }
-            }
-           printf("\r\n");
-
-        }
-    }
-}
-?>
diff --git a/include/export_ledger_pdf.php b/include/export_ledger_pdf.php
deleted file mode 100644
index 52f5ea9..0000000
--- a/include/export_ledger_pdf.php
+++ /dev/null
@@ -1,79 +0,0 @@
-<?php
-
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-
-// Copyright Author Dany De Bontridder address@hidden
-/* ! \file
- * \brief Send a ledger in a pdf format
- *
- */
-if (!defined('ALLOWED'))
-    die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-$gDossier = dossier::id();
-require_once NOALYSS_INCLUDE.'/class_pdf.php';
-require_once NOALYSS_INCLUDE.'/class_user.php';
-require_once NOALYSS_INCLUDE.'/ac_common.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_impress.php';
-require_once NOALYSS_INCLUDE.'/class_acc_ledger.php';
-require_once NOALYSS_INCLUDE.'/class_own.php';
-require_once NOALYSS_INCLUDE.'/class_periode.php';
-require_once NOALYSS_INCLUDE.'/class_print_ledger.php';
-
-
-$cn = new Database($gDossier);
-$periode = new Periode($cn);
-
-$l_type = "JRN";
-$own = new Own($cn);
-
-$Jrn = new Acc_Ledger($cn, $_GET['jrn_id']);
-
-$Jrn->get_name();
-$g_user->Check();
-$g_user->check_dossier($gDossier);
-
-// Security
-if ($_GET['jrn_id'] != 0 && $g_user->check_jrn($_GET['jrn_id']) == 'X') {
-    /* Cannot Access */
-    NoAccess();
-}
-
-$ret = "";
-
-$jrn_type = $Jrn->get_type();
-
-$pdf = Print_Ledger::factory($cn, $_REQUEST['p_simple'], "PDF", $Jrn);
-
-$pdf->setDossierInfo($Jrn->name);
-$pdf->AliasNbPages();
-$pdf->AddPage();
-$pdf->SetAuthor('NOALYSS');
-$pdf->setTitle(_("Journal"), true);
-
-$pdf->export();
-
-$fDate = date('dmy-Hi');
-$pdf->Output('journal-' . $fDate . '.pdf', 'D');
-exit(0);
-
-
-?>
diff --git a/include/export_poste_detail_csv.php 
b/include/export_poste_detail_csv.php
deleted file mode 100644
index c781a28..0000000
--- a/include/export_poste_detail_csv.php
+++ /dev/null
@@ -1,194 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-// Copyright Author Dany De Bontridder address@hidden
-/*! \file
- * \brief Send the poste list in csv
- */
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/ac_common.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_acc_account_ledger.php';
-require_once  NOALYSS_INCLUDE.'/class_acc_operation.php';
-$fDate=date('dmy-Hi');
-header('Pragma: public');
-header('Content-type: application/csv');
-header('Content-Disposition: 
attachment;filename="poste-'.$fDate.'-'.$_REQUEST['poste_id'].'.csv"',FALSE);
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-$gDossier=dossier::id();
-
-/* Admin. Dossier */
-$cn=new Database($gDossier);
-
-if ( isset ( $_REQUEST['poste_fille']) )
-{ //choisit de voir tous les postes
-  $a_poste=$cn->get_array("select pcm_val from tmp_pcmn where pcm_val::text 
like $1||'%'",array($_REQUEST["poste_id"]));
-}
-else
-{
-  $a_poste=$cn->get_array("select pcm_val from tmp_pcmn where pcm_val = 
$1",array($_REQUEST['poste_id']));
-}
-bcscale(2);
-if ( ! isset ($_REQUEST['oper_detail']))
-{
-    if ( count($a_poste) == 0 )
-        exit;
-
-    foreach ($a_poste as $pos)
-    {
-        $Poste=new Acc_Account_Ledger($cn,$pos['pcm_val']);
-        $name=$Poste->get_name();
-        list($array,$tot_deb,$tot_cred)=$Poste->get_row_date( 
$_REQUEST['from_periode'],
-                                                             
$_REQUEST['to_periode'],
-                                                             $_GET['ople']
-                                                             );
-        if ( count($Poste->row ) == 0 )
-            continue;
-
-        echo '"Poste";'.
-         '"n° pièce";'.
-         '"Code journal";'.
-         '"Nom journal";'.
-         '"Lib.";'.
-        "\"Code interne\";".
-        "\"Date\";".
-        "\"Description\";".
-        "\"Débit\";".
-        "\"Crédit\";".
-        "\"Prog.\";".
-               "\"Let.\"";
-        printf("\n");
-
-        $prog=0;
-        $current_exercice="";
-        $tot_cred=0;
-        $tot_deb=0;
-        $diff=0;
-        foreach ( $Poste->row as $op )
-        {
-           /*
-             * separation per exercice
-             */
-            if ( $current_exercice == "") $current_exercice=$op['p_exercice'];
-            
-            if ( $current_exercice != $op['p_exercice']) {
-                $solde_type=($tot_deb>$tot_cred)?"solde débiteur":"solde 
créditeur";
-                $diff=abs($tot_deb-$tot_cred);
-                printf(
-                     ";;;".
-                     '"'._('total').'";'.
-                     '"'.$current_exercice.'";'.
-                '"'."$solde_type".'"'.";".
-                nb($tot_deb).";".
-                nb($tot_cred).";".
-                nb($diff).";"."\n");
-                /*
-                * reset total and current_exercice
-                */
-                $prog=0;
-                $current_exercice=$op['p_exercice'];
-                $tot_deb=0;$tot_cred=0;    
-            }
-          $tot_deb=bcadd($tot_deb,$op['deb_montant']);
-          $tot_cred=bcadd($tot_cred,$op['cred_montant']);
-         $diff=bcsub($op['deb_montant'],$op['cred_montant']);
-         $prog=bcadd($prog,$diff);
-         echo '"'.$pos['pcm_val'].'";'.
-           '"'.$op['jr_pj_number'].'"'.";".
-           '"'.$op['jrn_def_code'].'"'.";".
-           '"'.$op['jrn_def_name'].'"'.";".
-            '"'.$name.'";'.
-            '"'.$op['jr_internal'].'"'.";".
-            '"'.$op['j_date_fmt'].'"'.";".
-            '"'.$op['description'].'";'.
-            nb($op['deb_montant']).";".
-            nb($op['cred_montant']).";".
-            nb(abs($prog)).";".
-                       
(($op['letter']!=-1)?strtoupper(base_convert($op['letter'],10,36)):"");
-            printf("\n");
-
-
-        }
-        $solde_type=($tot_deb>$tot_cred)?"solde débiteur":"solde créditeur";
-        $diff=abs($tot_deb-$tot_cred);
-       printf(
-                         ";;;".
-                         '"'._('total').'";'.
-                         '"'.$current_exercice.'";'.
-            '"'."$solde_type".'"'.";".
-            nb($tot_deb).";".
-            nb($tot_cred).";".
-            nb($diff).";"."\n");
-    }
-}
-else
-{
-    /* detail of all operation */
-    if ( count($a_poste) == 0 )
-        exit;
-
-    foreach ($a_poste as $pos)
-    {
-        $Poste=new Acc_Account_Ledger($cn,$pos['pcm_val']);
-        $Poste->get_name();
-        list($array,$tot_deb,$tot_cred)=$Poste->get_row_date( 
$_REQUEST['from_periode'],
-                                        $_REQUEST['to_periode'],
-                                                                             
$_GET['ople']
-                                                            );
-        if ( count($Poste->row ) == 0 )
-            continue;
-
-        echo '"Poste";'.
-        '"Lib.";'.
-        '"QuickCode";'.
-        "\"Code interne\";".
-        "\"Date\";".
-        "\"Description\";".
-        "\"Montant\";".
-        "\"D/C\"";
-        printf("\n");
-
-
-        foreach ( $Poste->row as $a )
-        {
-            $op=new Acc_Operation($cn);
-            $op->jr_id=$a['jr_id'];
-            $result=$op->get_jrnx_detail();
-            foreach ( $result as $r)
-            {
-                printf('"%s";"%s";"%s";"%s";"%s";"%s";"%s";%12.2f;"%s"',
-                       $r['j_poste'],
-                       $r['pcm_lib'],
-                       $r['j_qcode'],
-                       $r['jr_internal'],
-                       $r['jr_date'],
-                       $a['description'],
-                       $a['jr_pj_number'],
-                       nb($r['j_montant']),
-                       $r['debit']);
-                printf("\r\n");
-
-            }
-
-
-
-        }
-    }
-    exit;
-}
-?>
diff --git a/include/export_poste_detail_pdf.php 
b/include/export_poste_detail_pdf.php
deleted file mode 100644
index 3d055cb..0000000
--- a/include/export_poste_detail_pdf.php
+++ /dev/null
@@ -1,241 +0,0 @@
-<?php
-
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-/*! \file
- * \brief send the account list in PDF
- */
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_acc_account_ledger.php';
-require_once NOALYSS_INCLUDE.'/ac_common.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_impress.php';
-require_once NOALYSS_INCLUDE.'/header_print.php';
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-require_once NOALYSS_INCLUDE.'/class_user.php';
-require_once NOALYSS_INCLUDE.'/class_pdf.php';
-
-$gDossier=dossier::id();
-
-/* Security */
-$cn=new Database($gDossier);
-extract($_GET);
-
-if ( isset ( $poste_fille) )
-{ //choisit de voir tous les postes
-    $a_poste=$cn->get_array("select pcm_val from tmp_pcmn where pcm_val::text 
like '$poste_id%' order by pcm_val");
-}
-else
-    $a_poste=$cn->get_array("select pcm_val from tmp_pcmn where pcm_val::text 
= '$poste_id'");
-
-
-$ret="";
-
-$pdf=new PDF($cn);
-$pdf->setDossierInfo("  Periode : ".$_GET['from_periode']." - 
".$_GET['to_periode']);
-$pdf->AliasNbPages();
-$pdf->AddPage();
-$pdf->SetAuthor('NOALYSS');
-$pdf->setTitle("Détail poste comptable",true);
-
-
-if ( count($a_poste) == 0 )
-{
-    $pdf->Output('poste.pdf','D');
-    exit;
-}
-$size=array(13,25,13,65,12,20,20,20);
-$align=array('L','C','C','L','R','R','R','R');
-
-foreach ($a_poste as $poste)
-{
-    $Poste=new Acc_Account_Ledger($cn,$poste['pcm_val']);
-    
list($array,$tot_deb,$tot_cred)=$Poste->get_row_date($from_periode,$to_periode,$_GET['ople']);
-    // don't print empty account
-    if ( count($array) == 0 )
-    {
-        continue;
-    }
-    $Libelle=sprintf("(%s) %s ",$Poste->id,$Poste->get_name());
-    $pdf->SetFont('DejaVuCond','',10);
-    $pdf->Cell(0,8,$Libelle,1,0,'C');
-    $pdf->Ln();
-
-    $pdf->SetFont('DejaVuCond','',8);
-    $l=0;
-    $pdf->Cell($size[$l],6,'Date',0,0,'L');
-    $l++;
-    $pdf->Cell($size[$l],6,'Ref',0,0,'C');
-    $l++;
-    $pdf->Cell($size[$l],6,'Journal',0,0,'C');
-    $l++;
-    $pdf->LongLine($size[$l],6,'Libellé',0,'L');
-    $l++;
-    $pdf->Cell($size[$l],6,'Let',0,0,'R');
-    $l++;
-    $pdf->Cell($size[$l],6,'Debit',0,0,'R');
-    $l++;
-    $pdf->Cell($size[$l],6,'Credit',0,0,'R');
-    $l++;
-    $pdf->Cell($size[$l],6,'Prog',0,0,'R');
-    $l++;
-    $pdf->ln();
-    $tot_deb=0;
-    $tot_cred=0;
-    $prog=0;
-    $current_exercice="";
-    bcscale(2);
-    for ($e=0;$e<count($array);$e++)
-    {
-        $row=$array[$e];
-         /*
-             * separation per exercice
-             */
-            if ( $current_exercice == "") $current_exercice=$row['p_exercice'];
-            
-            if ( $current_exercice != $row['p_exercice']) {
-                    $str_debit=sprintf("% 12.2f €",$tot_deb);
-                    $str_credit=sprintf("% 12.2f €",$tot_cred);
-                    $diff_solde=bcsub($tot_deb,$tot_cred);
-                    if ( $diff_solde < 0 )
-                    {
-                        $solde=" créditeur ";
-                        $diff_solde=bcmul($diff_solde,-1);
-                    }
-                    else
-                    {
-                         $solde=" débiteur ";
-                    }
-                    $str_diff_solde=sprintf("%12.2f €",$diff_solde);
-
-                    $pdf->SetFont('DejaVu','B',8);
-                    $pdf->Cell(15,6,_('totaux'),0,0,'L');
-                    $pdf->Cell(15,6,$current_exercice,0,0,'L');
-                    $pdf->Cell(40,6,$solde,0,'L');
-                    $pdf->Cell(40,6,$str_debit,0,0,'R');
-                    $pdf->Cell(40,6,$str_credit,0,0,'R');
-                    $pdf->Cell(40,6,$str_diff_solde,0,0,'R');
-                    $pdf->Ln();
-                    /*
-                    * reset total and current_exercice
-                    */
-                    $prog=0;
-                    $current_exercice=$row['p_exercice'];
-                    $tot_deb=0;$tot_cred=0;    
-                    $pdf->SetFont('DejaVuCond','',8);
-            }
-        $l=0;
-        $diff=bcsub($row['deb_montant'],$row['cred_montant']);
-        $prog=bcadd($row['deb_montant'],$row['cred_montant']);
-
-        $date=shrink_date($row['j_date_fmt']);
-        $pdf->Cell($size[$l],6,$date,0,0,$align[$l]);
-        $l++;
-       if ( $row['jr_pj_number'] == '')
-         $pdf->Cell($size[$l],6,$row['jr_internal'],0,0,$align[$l]);
-       else
-         $pdf->Cell($size[$l],6,$row['jr_pj_number'],0,0,$align[$l]);
-        $l++;
-        
$pdf->Cell($size[$l],6,mb_substr($row['jrn_def_code'],0,14),0,0,$align[$l]);
-        $l++;
-        $pdf->LongLine($size[$l],6,  $row['description'],0,$align[$l]);
-        $l++;
-        
$pdf->Cell($size[$l],6,(($row['letter']!=-1)?$row['letter']:''),0,0,$align[$l]);
-        $l++;
-        $pdf->Cell($size[$l],6,(sprintf('% 
12.2f',$row['deb_montant'])),0,0,$align[$l]);
-        $l++;
-        $pdf->Cell($size[$l],6,(sprintf('% 
12.2f',$row['cred_montant'])),0,0,$align[$l]);
-        $l++;
-        $pdf->Cell($size[$l],6,(sprintf('% 12.2f',abs($prog))),0,0,$align[$l]);
-        $l++;
-        $pdf->ln();
-        $tot_deb=bcadd($tot_deb,$row['deb_montant']);
-        $tot_cred=bcadd($tot_deb,$row['cred_montant']);
-        /* -------------------------------------- */
-        /* if details are asked we show them here */
-        /* -------------------------------------- */
-        if ( isset($_GET['oper_detail']))
-        {
-            $detail=new Acc_Operation($cn);
-            $detail->jr_id=$row['jr_id'];
-            $a_detail=$detail->get_jrnx_detail();
-            for ($f=0;$f<count($a_detail);$f++)
-            {
-                $l=0;
-                $pdf->Cell($size[$l],6,'',0,0,$align[$l]);
-                $l++;
-                
$pdf->Cell($size[$l],6,$a_detail[$f]['j_qcode'],0,0,$align[$l]);
-                $l++;
-                
$pdf->Cell($size[$l],6,$a_detail[$f]['j_poste'],0,0,$align[$l]);
-                $l++;
-                if ( $a_detail[$f]['j_qcode']=='')
-                    $lib=$a_detail[$f]['pcm_lib'];
-                else
-                {
-                    $f_id=$cn->get_value('select f_id from vw_poste_qcode 
where j_qcode=$1',array($a_detail[$f]['j_qcode'])) ;
-                    $lib=$cn->get_value('select ad_value from fiche_detail 
where ad_id=$1 and f_id=$2',
-                                        array(ATTR_DEF_NAME,$f_id));
-                }
-                $pdf->Cell($size[$l],6,$lib,0,0,$align[$l]);
-                $l++;
-                
$pdf->Cell($size[$l],6,(($a_detail[$f]['letter']!=-1)?$a_detail[$f]['letter']:''),0,0,$align[$l]);
-                $l++;
-
-                
$deb=($a_detail[$f]['debit']=='D')?$a_detail[$f]['j_montant']:'';
-                
$cred=($a_detail[$f]['debit']=='C')?$a_detail[$f]['j_montant']:'';
-
-                $pdf->Cell($size[$l],6,(sprintf('% 
12.2f',$deb)),0,0,$align[$l]);
-                $l++;
-                $pdf->Cell($size[$l],6,(sprintf('% 
12.2f',$cred)),0,0,$align[$l]);
-                $l++;
-                $pdf->ln();
-            }
-        }
-    }
-    $str_debit=sprintf("% 12.2f €",$tot_deb);
-    $str_credit=sprintf("% 12.2f €",$tot_cred);
-    $diff_solde=$tot_deb-$tot_cred;
-    if ( $diff_solde < 0 )
-    {
-        $solde=" créditeur ";
-        $diff_solde=bcmul($diff_solde,-1);
-    }
-    else
-    {
-        $solde=" débiteur ";
-    }
-    $str_diff_solde=sprintf("%12.2f €",$diff_solde);
-
-    $pdf->SetFont('DejaVu','B',8);
-
-    $pdf->Cell(160,5,'Débit',0,0,'R');
-    $pdf->Cell(30,5,$str_debit,0,0,'R');
-    $pdf->Ln();
-    $pdf->Cell(160,5,'Crédit',0,0,'R');
-    $pdf->Cell(30,5,$str_credit,0,0,'R');
-    $pdf->Ln();
-    $pdf->Cell(160,5,'Solde '.$solde,0,0,'R');
-    $pdf->Cell(30,5,$str_diff_solde,0,0,'R');
-    $pdf->Ln();
-
-}
-$fDate=date('dmy-Hi');
-$pdf->Output('poste-'.$fDate.'-'.$poste_id.'.pdf','D');
-?>
diff --git a/include/export_rec_csv.php b/include/export_rec_csv.php
deleted file mode 100644
index da719f5..0000000
--- a/include/export_rec_csv.php
+++ /dev/null
@@ -1,39 +0,0 @@
-<?php
-//This file is part of NOALYSS and is under GPL 
-//see licence.txt
-
-/**
- * Export to CSV the operations asked in impress_rec.inc.php
- * variable set $g_user,$cn
- * @see impress_rec.inc.php
- */
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-$Date=date('Ymd');
-$filename="reconcialed_operation-".$Date;
-
-header('Pragma: public');
-header('Content-type: application/csv');
-header('Content-Disposition: attachment;filename="'.$filename.'.csv"',FALSE);
-
-require_once NOALYSS_INCLUDE.'/class_acc_reconciliation.php';
-require_once NOALYSS_INCLUDE.'/ac_common.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-// --------------------------
-// Check if all mandatory arg are passed
-foreach (array('choice','p_end','p_start') as $arg)
-{
-    if ( ! isset ($_GET[$arg])) {
-        die ("argument [".$arg."] is missing");
-    }
-}
-extract($_GET);
-$r_jrn=(isset($r_jrn))?$r_jrn:'';
-// -------------------------
-// Create object and export
-$acc_reconciliation=new Acc_Reconciliation($cn);
-$acc_reconciliation->a_jrn=$r_jrn;
-$acc_reconciliation->start_day=$p_start;
-$acc_reconciliation->end_day=$p_end;
-
-$array=$acc_reconciliation->export_csv($choice);
\ No newline at end of file
diff --git a/include/export_reportinit_csv.php 
b/include/export_reportinit_csv.php
deleted file mode 100644
index a078693..0000000
--- a/include/export_reportinit_csv.php
+++ /dev/null
@@ -1,56 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*!\file
- * \brief export definition of a report
- */
-
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once   NOALYSS_INCLUDE.'/constant.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once  NOALYSS_INCLUDE.'/user_common.php';
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-require_once NOALYSS_INCLUDE.'/class_acc_report.php';
-require_once NOALYSS_INCLUDE.'/class_user.php';
-if ( ! isset($_GET['gDossier']) ||
-        ! isset($_GET['f']) )
-{
-    $a='Paramètre manquant';
-    header("Content-type: text/html; charset: utf8",true);
-    print $a;
-    exit();
-}
-
-$gDossier=dossier::id();
-if ( ! is_dir('tmp') )
-{
-    mkdir ('tmp');
-}
-
-$cn=new Database($gDossier);
-$rap=new Acc_Report($cn,$_GET['f']);
-
-$file= fopen('php://output',"a+");
-header('Pragma: public');
-header('Content-type: application/bin');
-header('Content-Disposition: attachment;filename="export.bin"',FALSE);
-$rap->export_csv($file);
-?>
diff --git a/include/export_security_pdf.php b/include/export_security_pdf.php
deleted file mode 100755
index 667b6e0..0000000
--- a/include/export_security_pdf.php
+++ /dev/null
@@ -1,178 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-// Copyright Stanislas Pinte address@hidden
-
-/*! \file
- * \brief Print the user security in pdf
- */
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-$gDossier=dossier::id();
-require_once NOALYSS_INCLUDE.'/ac_common.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_pdf.php';
-$cn=new Database($gDossier);
-//-----------------------------------------------------
-// Security
-
-// Check User
-$rep=new Database();
-require_once  NOALYSS_INCLUDE.'/class_user.php';
-$User=new User($rep);
-
-//-----------------------------------------------------
-// Get User's info
-if ( ! isset($_GET['user_id']) )
-    return;
-
-$SecUser=new User($rep,$_GET['user_id']);
-$admin=0;
-$access=$SecUser->get_folder_access($gDossier);
-
-if ( $access == 'L')
-{
-    $str='Local Admin';
-    $admin=1;
-}
-elseif ($access=='R')
-{
-    $str=' Utilisateur normal';
-}
-elseif ($access=='P')
-{
-    $str=' Extension uniquement';
-}
-
-
-if ( $SecUser->admin==1 )
-{
-    $str=' Super Admin';
-    $admin=1;
-}
-
-
-//-----------------------------------------------------
-// Print result
-
-$pdf=new PDF($cn);
-$pdf->setDossierInfo(dossier::name().' Sécurité');
-$pdf->AliasNbPages();
-$pdf->AddPage();
-$pdf->SetAuthor('NOALYSS');
-$pdf->setTitle("Sécurité",true);
-
-$str_user=sprintf("( %d ) %s %s [ %s ] - %s",
-                  $SecUser->id,
-                  $SecUser->first_name,
-                  $SecUser->name,
-                  $SecUser->login,
-                  $str);
-
-$pdf->SetFont('DejaVu','B',9);
-$pdf->Cell(0,7,$str_user,'B',0,'C');
-$pdf->Ln();
-if ( $SecUser->active==0)
-{
-    $pdf->SetTextColor(255,0,34);
-    $pdf->Cell(0,7,'Bloqué',0,0,'R');
-    $pdf->Ln();
-}
-
-if ( $SecUser->admin==1)
-{
-    $pdf->SetTextColor(0,0,0);
-    $pdf->setFillColor(239,251,255);
-    $pdf->Cell(40,7,'Administrateur',1,1,'R');
-    $pdf->Ln();
-}
-$pdf->SetTextColor(0,0,0);
-
-//-----------------------------------------------------
-// Journal
-$pdf->Cell(0,7,'Accès journaux',1,0,'C');
-$pdf->Ln();
-$pdf->SetFont('DejaVu','',6);
-$Res=$cn->exec_sql("select jrn_def_id,jrn_def_name  from jrn_def ");
-$SecUser->db=$cn;
-for ($e=0;$e < Database::num_row($Res);$e++)
-{
-    $row=Database::fetch_array($Res,$e);
-    $pdf->Cell(40,6,$row['jrn_def_name']);
-    $priv=$SecUser->check_jrn($row['jrn_def_id']);
-    switch($priv)
-    {
-    case 'X':
-            $pdf->SetTextColor(255,0,34);
-        $pdf->Cell(30,6,"Pas d'accès");
-        break;
-    case 'R':
-        $pdf->SetTextColor(54,233,0);
-        $pdf->Cell(30,6,"Lecture");
-        break;
-    case 'O':
-        /**
-         *non implemente
-         */
-        $pdf->Cell(30,6,"Opérations prédéfinies uniquement");
-        break;
-    case 'W':
-        $pdf->SetTextColor(54,233,0);
-        $pdf->Cell(30,6,'Ecriture');
-        break;
-    }
-    $pdf->SetTextColor(0);
-    $pdf->Ln();
-}
-
-//-----------------------------------------------------
-// Follow_Up
-$pdf->SetFont('DejaVu','B',9);
-$pdf->Cell(0,7,'Accès action',1,0,'C');
-$pdf->Ln();
-$pdf->SetFont('DejaVu','',6);
-$Res=$cn->exec_sql(
-         "select ac_id, ac_description from action   order by ac_description 
");
-
-$Max=Database::num_row($Res);
-
-for ( $i =0 ; $i < $Max; $i++ )
-{
-    $l_line=Database::fetch_array($Res,$i);
-    $pdf->Cell(90,6,$l_line['ac_description']);
-    $right=$SecUser->check_action($l_line['ac_id']);
-    switch ($right)
-    {
-    case 0:
-        $pdf->SetTextColor(255,0,34);
-
-        $pdf->Cell(30,6,"Pas d'accès");
-        break;
-    case 1:
-    case 2:
-        $pdf->SetTextColor(54,233,0);
-        $pdf->Cell(30,6,"Accès");
-        break;
-    }
-    $pdf->SetTextColor(0);
-
-    $pdf->Ln();
-}
-$fDate=date('dmy-HI');
-$pdf->Output('security-'.$fDate.'pdf','D');
-?>
diff --git a/include/export_stock_histo_csv.php 
b/include/export_stock_histo_csv.php
deleted file mode 100644
index e47b9a1..0000000
--- a/include/export_stock_histo_csv.php
+++ /dev/null
@@ -1,63 +0,0 @@
-<?php
-
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/**
- * @file
- * @brief export in CSV the export of history
- *
- */
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_stock.php';
-
-$stock=new Stock($cn);
-$sql = $stock->create_query_histo($_GET);
-$sql .= " order by  real_date asc";
-
-$res=$cn->exec_sql($sql);
-$max_row=Database::num_row($res);
-header('Pragma: public');
-header('Content-type: application/csv');
-header('Content-Disposition: attachment;filename="histo-stock.csv"',FALSE);
-printf('"Date";');
-       printf('"%s";','Code Stock');
-       printf('"%s";','Depot');
-       printf('"%s";','Fiche');
-       printf('"%s";','Commentaire');
-       printf('%s;','Quantité');
-       printf('"%s";','IN/OUT');
-               printf("\n\r");
-for ($i=0;$i<$max_row;$i++)
-{
-       $row=Database::fetch_array($res,$i);
-       printf('"%s";',$row['cdate']);
-       printf('"%s";',$row['sg_code']);
-       printf('"%s";',$row['r_name']);
-       printf('"%s";',$row['qcode']);
-       $row['ccomment']=str_replace('"','',$row['ccomment']);
-       printf('"%s";',$row['ccomment']);
-       printf('%s;',nbm($row['sg_quantity']));
-       printf('"%s";',$row['direction']);
-       printf("\n\r");
-
-}
-
-?>
\ No newline at end of file
diff --git a/include/export_stock_resume_list.php 
b/include/export_stock_resume_list.php
deleted file mode 100644
index eccd5e7..0000000
--- a/include/export_stock_resume_list.php
+++ /dev/null
@@ -1,91 +0,0 @@
-<?php
-
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/**
- * @file
- * @brief export in CSV the summary of stock in list
- *
- */
-if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_stock.php';
-global $cn;
-// var_dump($_GET);
-$stock=new Stock($cn);
-$tmp_id = $stock->build_tmp_table($_GET);
-
-header('Pragma: public');
-header('Content-type: application/csv');
-header('Content-Disposition: 
attachment;filename="stock-summary-list.csv"',FALSE);
-
-?>
-"Depot";"Adresse";"Ville";"Pays";"Code Stock";"Fiches";"IN";"OUT";"DIFF"
-<?php 
-$a_repo=$cn->get_array("select distinct 
t.r_id,r_name,r_adress,r_city,r_country from stock_repository as s join 
tmp_stockgood_detail as t
-       on (s.r_id=t.r_id)
-       where
-       s_id=$1
-       order by 2
-       ",array($tmp_id));
- for ($r=0;$r<count($a_repo);$r++):
-
-               $a_stock=$cn->get_array(
-                               "
-                                       select coalesce(sum(s_qin),0) as 
qin,coalesce(sum(s_qout),0) as qout,sg_code
-                                               from tmp_stockgood_detail  
where r_id=$1 and s_id=$2
-                                               group by sg_code
-                                               order by sg_code
-
-                                       ",array($a_repo[$r]['r_id'],$tmp_id));
-               for ($s=0;$s<count($a_stock);$s++):
-
-                       $a_card=$cn->get_array(
-                                       "
-                                               select f_id,vw_name,quick_code
-                                               from vw_fiche_attr
-                                               where
-                                        f_id in (
-                                               select distinct f_id from 
fiche_detail
-                                                       where
-                                                       ad_id=19 and
-                                                       ad_value=$1)
-                                               order by vw_name,quick_code
-                                       ",array($a_stock[$s]['sg_code']));
-
-printf ('"%s";',$a_repo[$r]['r_name']);
-printf ('"%s";',$a_repo[$r]['r_adress']);
-printf ('"%s";',$a_repo[$r]['r_city']);
-printf ('"%s";',$a_repo[$r]['r_country']);
-printf('"%s";',$a_stock[$s]['sg_code']);
-       $sep="";
-                               for ( $c=0;$c<count($a_card);$c++):
-                                       $a=sprintf('[%s] 
%s',$a_card[$c]['quick_code'], $a_card[$c]['vw_name']);
-                                       $sep="  / ";
-                               endfor; // for C
-                               if ( count($a_card)== 0 ) $a= ' Erreur Code non 
utilisé';
- printf('"%s";',$a);
- printf('%s;',nbm($a_stock[$s]['qin']));
- printf('%s;',nbm($a_stock[$s]['qout']));
- printf ('%s',nbm(bcsub($a_stock[$s]['qin'],$a_stock[$s]['qout'])));
- printf("\r\n");
- endfor;
- endfor;
-
diff --git a/include/ext/dummy/dummy.php b/include/ext/dummy/dummy.php
index 5def22b..8e4308c 100755
--- a/include/ext/dummy/dummy.php
+++ b/include/ext/dummy/dummy.php
@@ -1,10 +1,10 @@
 <?php
-require_once ('class_icard.php');
-require_once('class_ifile.php');
-require_once('class_database.php');
-require_once('class_iselect.php');
-require_once('class_dossier.php');
-require_once('class_fiche.php');
+require_once ('lib/class_icard.php');
+require_once('lib/class_ifile.php');
+require_once('lib/class_database.php');
+require_once('lib/class_iselect.php');
+require_once('class/class_dossier.php');
+require_once('class/class_fiche.php');
 
 /* 
 Ma première extension, intégrer un fichier de client dans une catégorie 
diff --git a/include/extension_choice.inc.php b/include/extension_choice.inc.php
index 12b975f..26acca1 100644
--- a/include/extension_choice.inc.php
+++ b/include/extension_choice.inc.php
@@ -3,16 +3,16 @@
 //see licence.txt
 
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-require_once NOALYSS_INCLUDE.'/ac_common.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
 require_once NOALYSS_INCLUDE.'/constant.php';
-require_once NOALYSS_INCLUDE.'/function_javascript.php';
-require_once NOALYSS_INCLUDE.'/class_extension.php';
-require_once  NOALYSS_INCLUDE.'/class_html_input.php';
-require_once NOALYSS_INCLUDE.'/class_iselect.php';
+require_once NOALYSS_INCLUDE.'/lib/function_javascript.php';
+require_once NOALYSS_INCLUDE.'/class/class_extension.php';
+require_once  NOALYSS_INCLUDE.'/lib/class_html_input.php';
+require_once NOALYSS_INCLUDE.'/lib/class_iselect.php';
 require_once  NOALYSS_INCLUDE.'/constant.security.php';
-require_once  NOALYSS_INCLUDE.'/class_user.php';
+require_once  NOALYSS_INCLUDE.'/class/class_user.php';
 echo '<div class="topmenu">';
 @html_page_start($_SESSION['g_theme']);
 
diff --git a/include/extension_get.inc.php b/include/extension_get.inc.php
index 8ae3d4f..f98d406 100644
--- a/include/extension_get.inc.php
+++ b/include/extension_get.inc.php
@@ -3,16 +3,16 @@
 //see licence.txt
 
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-require_once NOALYSS_INCLUDE.'/ac_common.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
 require_once NOALYSS_INCLUDE.'/constant.php';
-require_once NOALYSS_INCLUDE.'/function_javascript.php';
-require_once NOALYSS_INCLUDE.'/class_extension.php';
-require_once  NOALYSS_INCLUDE.'/class_html_input.php';
-require_once NOALYSS_INCLUDE.'/class_iselect.php';
+require_once NOALYSS_INCLUDE.'/lib/function_javascript.php';
+require_once NOALYSS_INCLUDE.'/class/class_extension.php';
+require_once  NOALYSS_INCLUDE.'/lib/class_html_input.php';
+require_once NOALYSS_INCLUDE.'/lib/class_iselect.php';
 require_once  NOALYSS_INCLUDE.'/constant.security.php';
-require_once  NOALYSS_INCLUDE.'/class_user.php';
+require_once  NOALYSS_INCLUDE.'/class/class_user.php';
 
 /**
  * included from do.php + extension_choice.inc.php
diff --git a/include/fiche.inc.php b/include/fiche.inc.php
index 36b97cb..199e405 100644
--- a/include/fiche.inc.php
+++ b/include/fiche.inc.php
@@ -22,9 +22,9 @@
  * \brief printing of category of card  : balance, historic
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_fiche.php';
-require_once NOALYSS_INCLUDE.'/class_lettering.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/class/class_fiche.php';
+require_once NOALYSS_INCLUDE.'/class/class_lettering.php';
 
 $gDossier = dossier::id();
 $cn = new Database($gDossier);
@@ -282,7 +282,7 @@ if (isDate($_REQUEST['start']) == null || 
isDate($_REQUEST['end']) == null)
 
/*************************************************************************************************************************/
 if ( $_GET['histo'] == 6)
 {
-    require_once NOALYSS_INCLUDE.'/class_balance_age.php';
+    require_once NOALYSS_INCLUDE.'/class/class_balance_age.php';
     $bal=new Balance_Age($cn);
     $export_csv = '<FORM METHOD="get" ACTION="export.php" 
style="display:inline">';
     $export_csv 
.=HtmlInput::request_to_hidden(array('gDossier','ac','p_let','p_date_start'));
@@ -318,7 +318,7 @@ if ( $_GET['histo'] == 6)
 
/*************************************************************************************************************************/
 if ( $_GET['histo'] == 7)
 {
-    require_once NOALYSS_INCLUDE.'/class_balance_age.php';
+    require_once NOALYSS_INCLUDE.'/class/class_balance_age.php';
     $bal=new Balance_Age($cn);
        $export_csv = '<FORM METHOD="get" ACTION="export.php" 
style="display:inline">';
     $export_csv 
.=HtmlInput::request_to_hidden(array('gDossier','ac','p_let','p_date_start'));
diff --git a/include/fiche_def.inc.php b/include/fiche_def.inc.php
index 789b83e..6200eb2 100644
--- a/include/fiche_def.inc.php
+++ b/include/fiche_def.inc.php
@@ -18,8 +18,8 @@
 */
 // Copyright Author Dany De Bontridder address@hidden
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_ihidden.php';
-require_once NOALYSS_INCLUDE.'/class_fiche_def.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ihidden.php';
+require_once NOALYSS_INCLUDE.'/class/class_fiche_def.php';
 
 /*! \file
  * \brief Let customise the fiche_def_ref for the user
diff --git a/include/forecast.inc.php b/include/forecast.inc.php
index 18836cc..db7cfcf 100644
--- a/include/forecast.inc.php
+++ b/include/forecast.inc.php
@@ -25,7 +25,7 @@
  */
 
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_anticipation.php';
+require_once NOALYSS_INCLUDE.'/class/class_anticipation.php';
 $action=HtmlInput::default_value_get('action','');
 
 echo '<div class="content">';
diff --git a/include/header_print.php b/include/header_print.php
index d940f2b..382407f 100644
--- a/include/header_print.php
+++ b/include/header_print.php
@@ -24,9 +24,9 @@
  *
  */
 
-require_once  NOALYSS_INCLUDE.'/class_database.php';
-require_once  NOALYSS_INCLUDE.'/class_own.php';
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
+require_once  NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once  NOALYSS_INCLUDE.'/class/class_own.php';
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
 
 
 date_default_timezone_set ('Europe/Brussels');
diff --git a/include/history_operation.inc.php 
b/include/history_operation.inc.php
index e08fca2..8e615ae 100644
--- a/include/history_operation.inc.php
+++ b/include/history_operation.inc.php
@@ -28,10 +28,10 @@
  *
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_acc_ledger_purchase.php';
-require_once NOALYSS_INCLUDE.'/class_acc_ledger_fin.php';
-require_once NOALYSS_INCLUDE.'/class_acc_ledger_sold.php';
-require_once NOALYSS_INCLUDE.'/class_acc_ledger.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_ledger_purchase.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_ledger_fin.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_ledger_sold.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_ledger.php';
 global $g_user,$cn;
 $p_array = $_GET;
 $ledger_type=HtmlInput::default_value_get("ledger_type", 'ALL');
diff --git a/include/impress_bilan.inc.php b/include/impress_bilan.inc.php
index 5eb2560..0a946ee 100644
--- a/include/impress_bilan.inc.php
+++ b/include/impress_bilan.inc.php
@@ -17,8 +17,8 @@
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once  NOALYSS_INCLUDE.'/class_acc_bilan.php';
-require_once NOALYSS_INCLUDE.'/class_exercice.php';
+require_once  NOALYSS_INCLUDE.'/class/class_acc_bilan.php';
+require_once NOALYSS_INCLUDE.'/class/class_exercice.php';
 
 //ini_set("memory_limit","150M");
 /*! \file
@@ -31,7 +31,7 @@ require_once NOALYSS_INCLUDE.'/class_exercice.php';
 //-----------------------------------------------------
 // Show the jrn and date
 //-----------------------------------------------------
-require_once NOALYSS_INCLUDE.'/class_database.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
 global $g_user;
 //-----------------------------------------------------
 // Form
diff --git a/include/impress_gl_comptes.inc.php 
b/include/impress_gl_comptes.inc.php
index 015d62a..4fdc77c 100644
--- a/include/impress_gl_comptes.inc.php
+++ b/include/impress_gl_comptes.inc.php
@@ -18,11 +18,11 @@
 */
 // Copyright Author Dany De Bontridder address@hidden
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_ispan.php';
-require_once NOALYSS_INCLUDE.'/class_icard.php';
-require_once NOALYSS_INCLUDE.'/class_iselect.php';
-require_once NOALYSS_INCLUDE.'/class_icheckbox.php';
-require_once NOALYSS_INCLUDE.'/class_acc_operation.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ispan.php';
+require_once NOALYSS_INCLUDE.'/lib/class_icard.php';
+require_once NOALYSS_INCLUDE.'/lib/class_iselect.php';
+require_once NOALYSS_INCLUDE.'/lib/class_icheckbox.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_operation.php';
 /*! \file
  * \brief Print account (html or pdf)
  *        file included from user_impress
@@ -33,7 +33,7 @@ require_once NOALYSS_INCLUDE.'/class_acc_operation.php';
 //-----------------------------------------------------
 // Show the jrn and date
 //-----------------------------------------------------
-require_once NOALYSS_INCLUDE.'/class_database.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
 global $g_user;
 //-----------------------------------------------------
 // Form
@@ -110,7 +110,7 @@ echo '</div>';
 //-----------------------------------------------------
 if ( isset( $_REQUEST['bt_html'] ) )
 {
-  require_once NOALYSS_INCLUDE.'/class_acc_account_ledger.php';
+  require_once NOALYSS_INCLUDE.'/class/class_acc_account_ledger.php';
   echo '<div class="content">';
     echo Acc_Account_Ledger::HtmlTableHeader("gl_comptes");
     echo '</div>';
diff --git a/include/impress_jrn.inc.php b/include/impress_jrn.inc.php
index aefb0e5..fbfcc51 100644
--- a/include/impress_jrn.inc.php
+++ b/include/impress_jrn.inc.php
@@ -22,18 +22,18 @@
  * \brief ask for Printing the ledger (pdf,html)
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_ihidden.php';
-require_once NOALYSS_INCLUDE.'/class_iselect.php';
-require_once NOALYSS_INCLUDE.'/class_icheckbox.php';
-require_once NOALYSS_INCLUDE.'/class_exercice.php';
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ihidden.php';
+require_once NOALYSS_INCLUDE.'/lib/class_iselect.php';
+require_once NOALYSS_INCLUDE.'/lib/class_icheckbox.php';
+require_once NOALYSS_INCLUDE.'/class/class_exercice.php';
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
 load_all_script();
 $gDossier = dossier::id();
 global $g_user;
 //-----------------------------------------------------
 // Show the jrn and date
 //-----------------------------------------------------
-require_once NOALYSS_INCLUDE.'/class_database.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
 
 if ($g_user->Admin() == 0 && $g_user->is_local_admin() == 0)
 {
@@ -145,7 +145,7 @@ echo '<hr>';
 //-----------------------------------------------------
 if (isset($_REQUEST['bt_html']))
 {
-       require_once NOALYSS_INCLUDE.'/class_acc_ledger.php';
+       require_once NOALYSS_INCLUDE.'/class/class_acc_ledger.php';
 
        $d = var_export($_GET, true);
        $Jrn = new Acc_Ledger($cn, $_GET['jrn_id']);
diff --git a/include/impress_poste.inc.php b/include/impress_poste.inc.php
index 9301503..8edf1fe 100644
--- a/include/impress_poste.inc.php
+++ b/include/impress_poste.inc.php
@@ -18,11 +18,11 @@
 */
 // Copyright Author Dany De Bontridder address@hidden
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_ispan.php';
-require_once NOALYSS_INCLUDE.'/class_icard.php';
-require_once NOALYSS_INCLUDE.'/class_iselect.php';
-require_once NOALYSS_INCLUDE.'/class_icheckbox.php';
-require_once NOALYSS_INCLUDE.'/class_acc_operation.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ispan.php';
+require_once NOALYSS_INCLUDE.'/lib/class_icard.php';
+require_once NOALYSS_INCLUDE.'/lib/class_iselect.php';
+require_once NOALYSS_INCLUDE.'/lib/class_icheckbox.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_operation.php';
 /*! \file
  * \brief Print account (html or pdf)
  *        file included from user_impress
@@ -33,8 +33,8 @@ require_once NOALYSS_INCLUDE.'/class_acc_operation.php';
 //-----------------------------------------------------
 // Show the jrn and date
 //-----------------------------------------------------
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_ipopup.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ipopup.php';
 global $g_user;
 
 //-----------------------------------------------------
@@ -129,7 +129,7 @@ if ( isset( $_REQUEST['bt_html'] ) )
         echo alert(_('Date malformée, désolée'));
         return;
     }
-    require_once NOALYSS_INCLUDE.'/class_acc_account_ledger.php';
+    require_once NOALYSS_INCLUDE.'/class/class_acc_account_ledger.php';
     $go=0;
 // we ask a poste_id
     if ( isset($_GET['poste_id']) && strlen(trim($_GET['poste_id'])) != 0 )
@@ -149,7 +149,7 @@ if ( isset( $_REQUEST['bt_html'] ) )
     }
     if ( strlen(trim($_GET['f_id'])) != 0 )
     {
-        require_once NOALYSS_INCLUDE.'/class_fiche.php';
+        require_once NOALYSS_INCLUDE.'/class/class_fiche.php';
         // thanks the qcode we found the poste account
         $fiche=new Fiche($cn);
         $qcode=$fiche->get_by_qcode($_GET['f_id']);
diff --git a/include/impress_rapport.inc.php b/include/impress_rapport.inc.php
index d7dae64..39a5245 100644
--- a/include/impress_rapport.inc.php
+++ b/include/impress_rapport.inc.php
@@ -23,11 +23,11 @@
  * some variable are already defined ($cn, $g_user ...)
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_ihidden.php';
-require_once NOALYSS_INCLUDE.'/class_iselect.php';
-require_once NOALYSS_INCLUDE.'/class_idate.php';
-require_once NOALYSS_INCLUDE.'/class_acc_report.php';
-require_once NOALYSS_INCLUDE.'/class_exercice.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ihidden.php';
+require_once NOALYSS_INCLUDE.'/lib/class_iselect.php';
+require_once NOALYSS_INCLUDE.'/lib/class_idate.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_report.php';
+require_once NOALYSS_INCLUDE.'/class/class_exercice.php';
 global $g_user;
 //-----------------------------------------------------
 // If print is asked
@@ -161,7 +161,7 @@ if ( isset( $_GET['bt_html'] ) )
 //-----------------------------------------------------
 // Show the jrn and date
 //-----------------------------------------------------
-require_once NOALYSS_INCLUDE.'/class_database.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
 $ret=$cn->make_array("select fr_id,fr_label
                      from formdef
                      order by fr_label");
diff --git a/include/impress_rec.inc.php b/include/impress_rec.inc.php
index 608f09d..f244673 100644
--- a/include/impress_rec.inc.php
+++ b/include/impress_rec.inc.php
@@ -23,8 +23,8 @@
  * \brief print the all the operation reconciled or not, with or without the 
same amount
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once  NOALYSS_INCLUDE.'/class_acc_reconciliation.php';
-require_once NOALYSS_INCLUDE.'/function_javascript.php';
+require_once  NOALYSS_INCLUDE.'/class/class_acc_reconciliation.php';
+require_once NOALYSS_INCLUDE.'/lib/function_javascript.php';
 global $g_user;
 
 /**
diff --git a/include/lettering.account.inc.php 
b/include/lettering.account.inc.php
index 6755924..8072259 100644
--- a/include/lettering.account.inc.php
+++ b/include/lettering.account.inc.php
@@ -24,7 +24,7 @@
  */
 
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_lettering.php';
+require_once NOALYSS_INCLUDE.'/class/class_lettering.php';
 
 echo '<div class="content">';
 echo '<div id="search">';
diff --git a/include/lettering.card.inc.php b/include/lettering.card.inc.php
index 53adde7..41006b0 100644
--- a/include/lettering.card.inc.php
+++ b/include/lettering.card.inc.php
@@ -23,8 +23,8 @@
  * \brief show the lettering by account
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once  NOALYSS_INCLUDE.'/class_ipopup.php';
-require_once NOALYSS_INCLUDE.'/class_lettering.php';
+require_once  NOALYSS_INCLUDE.'/lib/class_ipopup.php';
+require_once NOALYSS_INCLUDE.'/class/class_lettering.php';
 
 
 echo '<div class="content">';
diff --git a/include/lettering.gestion.inc.php 
b/include/lettering.gestion.inc.php
index 3e19306..1ca1f41 100644
--- a/include/lettering.gestion.inc.php
+++ b/include/lettering.gestion.inc.php
@@ -3,7 +3,7 @@
 //see licence.txt
 
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_lettering.php';
+require_once NOALYSS_INCLUDE.'/class/class_lettering.php';
 global $g_user;
 echo '<div class="content">';
 
diff --git a/include/lib/ac_common.php b/include/lib/ac_common.php
new file mode 100644
index 0000000..6a9f4b6
--- /dev/null
+++ b/include/lib/ac_common.php
@@ -0,0 +1,1254 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/**
+ * @file
+ * @brief common utilities for a lot of procedure, classe
+ */
+
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/class/class_periode.php';
+require_once NOALYSS_INCLUDE.'/lib/class_html_input.php';
+require_once NOALYSS_INCLUDE.'/lib/function_javascript.php';
+
+/**
+ * \brief to protect again bad characters which can lead to a cross scripting 
attack
+  the string to be diplayed must be protected
+ */
+
+function h($p_string)
+{
+    return htmlspecialchars($p_string);
+}
+
+function span($p_string, $p_extra='')
+{
+    return '<span ' . $p_extra . '>' . $p_string . '</span>';
+}
+
+function hi($p_string)
+{
+    return '<i>' . htmlspecialchars($p_string) . '</i>';
+}
+
+function hb($p_string)
+{
+    return '<b>' . htmlspecialchars($p_string) . '</b>';
+}
+
+function th($p_string, $p_extra='',$raw='')
+{
+    return '<th  ' . $p_extra . '>' . htmlspecialchars($p_string).$raw . 
'</th>';
+}
+
+function h2info($p_string)
+{
+    return '<h2 class="info">' . htmlspecialchars($p_string) . '</h2>';
+}
+
+function h2($p_string, $p_class="",$raw="")
+{
+    return '<h2 ' . $p_class . '>' . $raw.htmlspecialchars($p_string) . 
'</h2>';
+}
+function h1($p_string, $p_class="")
+{
+    return '<h1 ' . $p_class . '>' . htmlspecialchars($p_string) . '</h1>';
+}
+/**
+ * \brief surround the string with td
+ * \param $p_string string to surround by TD
+ * \param $p_extra extra info (class, style, javascript...)
+ * \return string surrounded by td
+ */
+
+function td($p_string='', $p_extra='')
+{
+    return '<td  ' . $p_extra . '>' . $p_string . '</td>';
+}
+
+function tr($p_string, $p_extra='')
+{
+    return '<tr  ' . $p_extra . '>' . $p_string . '</tr>';
+}
+
+/**
+ * @brief escape correctly php string to javascript 
+ */
+function j($p_string)
+{
+    $a = preg_replace("/\r?\n/", "\\n", addslashes($p_string));
+    $a = str_replace("'", '\'', $a);
+    return $a;
+}
+
+/**
+ * format the number for the CSV export
+ * @param $p_number number
+ */
+function nb($p_number)
+{
+    $r = sprintf('%.2f', $p_number);
+    $r = str_replace('.', ',', $r);
+
+    return $r;
+}
+
+/**
+ * format the number with a sep. for the thousand
+ * @param $p_number number
+ */
+function nbm($p_number)
+{
+
+    if (trim($p_number) == '')
+       return '';
+    if ($p_number == 0)
+       return "0,00";
+    
+    $a = doubleval($p_number);
+    $r = number_format($a, 2, ",", ".");
+    if (trim($r) == '')
+    {
+       var_dump($r);
+       var_dump($p_number);
+       var_dump($a);
+       exit();
+    }
+
+    return $r;
+}
+
+/**
+ * \brief  log error into the /tmp/noalyss_error.log it doesn't work on windows
+ *
+ * \param p_log message
+ * \param p_line line number
+ * \param p_message is the message
+ *
+ * \return nothing
+ *
+ */
+
+function echo_error($p_log, $p_line="", $p_message="")
+{
+    echo "ERREUR :" . $p_log . " " . $p_line . " " . $p_message;
+    $fdebug = fopen($_ENV['TMP'] . DIRECTORY_SEPARATOR . "noalyss_error.log", 
"a+");
+    if ($fdebug != null)
+    {
+       fwrite($fdebug, date("Ymd H:i:s") . $p_log . " " . $p_line . " " . 
$p_message . "\n");
+       fclose($fdebug);
+    }
+}
+
+/**
+ * \brief  Compare 2 dates
+ * \param p_date
+ * \param p_date_oth
+ *
+ * \return
+ *      - == 0 les dates sont identiques
+ *      - > 0 date1 > date2
+ *      - < 0 date1 < date2
+ */
+
+function cmpDate($p_date, $p_date_oth)
+{
+    date_default_timezone_set('Europe/Brussels');
+
+    $l_date = isDate($p_date);
+    $l2_date = isDate($p_date_oth);
+    if ($l_date == null || $l2_date == null)
+    {
+       throw new Exception("erreur date [$p_date] [$p_date_oth]");
+    }
+    $l_adate = explode(".", $l_date);
+    $l2_adate = explode(".", $l2_date);
+    $l_mkdate = mktime(0, 0, 0, $l_adate[1], $l_adate[0], $l_adate[2]);
+    $l2_mkdate = mktime(0, 0, 0, $l2_adate[1], $l2_adate[0], $l2_adate[2]);
+    // si $p_date > $p_date_oth return > 0
+    return $l_mkdate - $l2_mkdate;
+}
+
+/***!
+ * @brief check if the argument is a number
+ *
+ * \param $p_int number to test
+ *
+ * \return
+ *        - 1 it's a number
+ *        - 0 it is not
+ */
+function isNumber(&$p_int)
+{
+    if (strlen(trim($p_int)) == 0)
+       return 0;
+    if (is_numeric($p_int) === true)
+       return 1;
+    else
+       return 0;
+}
+
+/***
+ * \brief Verifie qu'une date est bien formaté
+ *           en d.m.y et est valable
+ * \param $p_date
+ *
+ * \return
+ *     - null si la date est invalide ou malformaté
+ *      - $p_date si tout est bon
+ *
+ */
+
+function isDate($p_date)
+{
+    if (strlen(trim($p_date)) == 0)
+       return null;
+    if (preg_match("/^[0-9]{1,2}\.[0-9]{1,2}\.20[0-9]{2}$/", $p_date) == 0)
+    {
+
+       return null;
+    }
+    else
+    {
+       $l_date = explode(".", $p_date);
+
+       if (sizeof($l_date) != 3)
+           return null;
+
+       if ($l_date[2] > COMPTA_MAX_YEAR || $l_date[2] < COMPTA_MIN_YEAR)
+       {
+           return null;
+       }
+
+       if (checkdate($l_date[1], $l_date[0], $l_date[2]) == false)
+       {
+           return null;
+       }
+    }
+    return $p_date;
+}
+
+/**
+ * \brief Default page header for each page
+ *
+ * \param p_theme default theme
+ * \param $p_script
+ * \param $p_script2  another js script
+ * Must be called only once
+ * \return none
+ */
+
+function html_page_start($p_theme="", $p_script="", $p_script2="")
+{
+    // check not called twiced
+    static  $already_call=0;
+    if ( $already_call==1)return;
+    $already_call=1;
+
+    $cn = new Database();
+    if ($p_theme != "")
+    {
+       $Res = $cn->exec_sql("select the_filestyle from theme
+                           where the_name='" . $p_theme . "'");
+       if (Database::num_row($Res) == 0)
+           $style = "style-classic.css";
+       else
+       {
+           $s = Database::fetch_array($Res, 0);
+           $style = $s['the_filestyle'];
+       }
+    }
+    else
+    {
+       $style = "style-classic.css";
+    } // end if
+       $title="NOALYSS";
+
+       if ( isset ($_REQUEST['ac'])) {
+               if (strpos($_REQUEST['ac'],'/') <> 0)
+               {
+                       $m=  explode('/',$_REQUEST['ac']);
+                       $title=$m[count($m)-1]."  ".$title;
+               }
+               else
+                       $title=$_REQUEST['ac']."  ".$title;
+       }
+    $is_msie=is_msie();
+    
+    if ($is_msie == 0 ) 
+    {
+        echo '<!doctype html>';
+        printf("\n");
+        echo '<meta name="viewport" content="width=device-width, 
initial-scale=1.0">';
+        printf("\n");
+    }
+    else {
+        echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 FINAL//EN" >';
+        printf("\n");
+    }
+    echo "<HTML>";
+
+    if ($p_script2 != "")
+       $p_script2 = '<script src="' . $p_script2 . '?version='.SVNINFO.'" 
type="text/javascript"></script>';
+    $style=trim($style);
+    echo "<HEAD>";
+    if ( $is_msie == 1 )echo '      <meta http-equiv="x-ua-compatible" 
content="IE=edge"/>';
+    echo "
+    <TITLE>$title</TITLE>
+       <link rel=\"icon\" type=\"image/ico\" href=\"favicon.ico\" />
+    <META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
+    <LINK REL=\"stylesheet\" type=\"text/css\" 
href=\"".$style."?version=".SVNINFO."\" media=\"screen\"/>
+    <link rel=\"stylesheet\" type=\"text/css\" 
href=\"./style-print.css?version=".SVNINFO."\" media=\"print\"/>" .
+    $p_script2 . "
+    ";
+    echo '<script language="javascript" src="js/calendar.js"></script>
+    <script type="text/javascript" src="js/lang/calendar-en.js"></script>
+    <script language="javascript" src="js/calendar-setup.js"></script>
+    <LINK REL="stylesheet" type="text/css" href="./calendar-blue.css" 
media="screen">
+    ';
+    echo load_all_script();
+    echo '    </HEAD>    ';
+
+    echo "<BODY $p_script>";
+    echo '<div id="info_div"></div>';
+    echo '<div id="error_div">'.
+            HtmlInput::title_box(_("Erreur"), 'error_div','hide').
+            '<div id="error_content_div">'.
+            '</div>'.
+            '<p style="text-align:center">'.
+            
HtmlInput::button_action('Valider','$(\'error_div\').style.visibility=\'hidden\';$(\'error_content_div\').innerHTML=\'\';').
+            '</p>'.
+            '</div>';
+// language
+    if (isset($_SESSION['g_lang']))
+    {
+               set_language();
+    }
+
+}
+
+/**
+ * \brief Minimal  page header for each page, used for small popup window
+ *
+ * \param p_theme default theme
+ * \param $p_script
+ * \param $p_script2  another js script
+ *
+ * \return none
+ */
+
+function html_min_page_start($p_theme="", $p_script="", $p_script2="")
+{
+
+    $cn = new Database();
+    if ($p_theme != "")
+    {
+       $Res = $cn->exec_sql("select the_filestyle from theme
+                           where the_name='" . $p_theme . "'");
+       if (Database::num_row($Res) == 0)
+           $style = "style-classic.css";
+       else
+       {
+           $s = Database::fetch_array($Res, 0);
+           $style = $s['the_filestyle'];
+       }
+    }
+    else
+    {
+       $style = "style-classic.css";
+    } // end if
+    echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 FINAL//EN">';
+    echo "<HTML>";
+
+
+    if ($p_script2 != "")
+       $p_script2 = '<script src="' . $p_script2 . '" 
type="text/javascript"></script>';
+
+    echo "<HEAD>
+    <TITLE>NOALYSS</TITLE>
+    <META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF8\">
+    <LINK REL=\"stylesheet\" type=\"text/css\" href=\"$style\" 
media=\"screen\">
+    <link rel=\"stylesheet\" type=\"text/css\" href=\"style-print.css\" 
media=\"print\">" .
+    $p_script2 . "
+    <script src=\"js/scripts.js\" type=\"text/javascript\"></script>
+    <script src=\"js/acc_ledger.js\" type=\"text/javascript\"></script>
+    <script src=\"js/smoke.js\" type=\"text/javascript\"></script>";
+    echo '</HEAD>
+    ';
+
+    echo "<BODY $p_script>";
+    /* If we are on the user_login page */
+    if (basename($_SERVER['PHP_SELF']) == 'user_login.php')
+    {
+       return;
+    }
+}
+
+/**
+ * \brief end tag
+ *
+ */
+
+function html_page_stop()
+{
+    echo "</BODY>";
+    echo "</HTML>";
+}
+
+/**
+ * \brief Echo no access and stop
+ *
+ * \return nothing
+ */
+
+function NoAccess($js=1)
+{
+    if ($js == 1)
+    {
+       echo "<script>";
+       echo "alert ('" . _('Cette action ne vous est pas autorisée Contactez 
votre responsable') . "');";
+       echo "</script>";
+    }
+    else
+    {
+       echo '<div class="redcontent">';
+       echo '<h2 class="error">' . _(' Cette action ne vous est pas autorisée 
Contactez votre responsable') . '</h2>';
+       echo '</div>';
+    }
+    exit - 1;
+}
+/**
+ * replaced by sql_string
+ * @deprecated
+ */
+function FormatString($p_string)
+{
+    return sql_string($p_string);
+}
+/**
+ * \brief Fix the problem with the quote char for the database
+ *
+ * \param $p_string
+ * \return a string which won't let strange char for the database
+ */
+
+function sql_string($p_string)
+{
+    $p_string = trim($p_string);
+    if (strlen($p_string) == 0)
+       return null;
+    $p_string = str_replace("'", "''", $p_string);
+    $p_string = str_replace('\\', '\\\\', $p_string);
+    return $p_string;
+}
+
+/**
+  /* \brief store the string which print
+ *           the content of p_array in a table
+ *           used to display the menu
+ * \param  $p_array array like ( 0=>HREF reference, 1=>visible item 
(name),2=>Help(opt),
+ * 3=>selected (opt) 4=>javascript (normally a onclick event) (opt)
+ * \param $p_dir direction of the menu (H Horizontal  V vertical)
+ * \param $class CSS for TD tag
+ * \param $class_ref CSS for the A tag
+ * \param $default selected item
+ * \param $p_extra extra code for the table tag (CSS or javascript)
+ *
+  /* \return : string */
+
+function ShowItem($p_array, $p_dir='V', $class="mtitle", $class_ref="mtitle", 
$default="", $p_extra="")
+{
+
+    $ret = "<TABLE $p_extra>";
+    // direction Vertical
+    if ($p_dir == 'V')
+    {
+       foreach ($p_array as $all => $href)
+       {
+           $javascript = (isset($href[4])) ? $href[4] : "";
+           $title = "";
+           $set = "XX";
+           if (isset($href[2]))
+               $title = $href[2];
+           if (isset($href[3]))
+               $set = $href[3];
+
+           if ($set == $default)
+               $ret.='<TR><TD CLASS="selectedcell"><A class="' . $class_ref . 
'" HREF="' . $href[0] . '" title="' . $title . '" ' . $javascript . '>' . 
$href[1] . '</A></TD></TR>';
+           else
+               $ret.='<TR><TD CLASS="' . $class . '"><A class="' . $class_ref 
. '" HREF="' . $href[0] . '" title="' . $title . '" ' . $javascript . '>' . 
$href[1] . '</A></TD></TR>';
+       }
+    }
+    //direction Horizontal
+    else if ($p_dir == 'H')
+    {
+
+       $ret.="<TR>";
+       foreach ($p_array as $all => $href)
+       {
+           $title = "";
+           $javascript = (isset($href[4])) ? $href[4] : "";
+
+           $set = "A";
+           if (isset($href[2]))
+               $title = $href[2];
+
+           if (isset($href[3]))
+               $set = $href[3];
+
+           if ($default === $href[0] || $set === $default)
+           {
+               $ret.='<TD CLASS="selectedcell"><A class="' . $class_ref . '" 
HREF="' . $href[0] . '" title="' . $title . '" ' . $javascript . '>' . $href[1] 
. '</A></TD>';
+           }
+           else
+           {
+               $ret.='<TD CLASS="' . $class . '"><A class="' . $class_ref . '" 
HREF="' . $href[0] . '" title="' . $title . '" ' . $javascript . '>' . $href[1] 
. '</A></TD>';
+           }
+       }
+       $ret.="</TR>";
+    }
+    $ret.="</TABLE>";
+    return $ret;
+}
+
+/**
+ * \brief warns
+ *
+ * \param p_string error message
+ * gen :
+ *     - none
+ * \return:
+ *      - none
+ */
+
+function echo_warning($p_string)
+{
+    echo '<H2 class="error">' . $p_string . "</H2>";
+}
+
+/**
+ * \brief Show the periode which found thanks its id
+ *
+ *
+ * \param  $p_cn database connection
+ * \param p_id
+ * \param pos Start or end
+ *
+ * \return: string
+ */
+
+function getPeriodeName($p_cn, $p_id, $pos='p_start')
+{
+    if ($pos != 'p_start' and
+           $pos != 'p_end')
+       echo_error('lib/ac_common.php' . "-" . __LINE__ . '  UNDEFINED 
PERIODE');
+    $ret = $p_cn->get_value("select to_char($pos,'Mon YYYY') as t from 
parm_periode where p_id=$p_id");
+    return $ret;
+}
+
+/**
+ * \brief Return the period corresponding to the
+ *           date
+ *
+ * \param p_cn database connection
+ * \param p_date the month + year 'MM.YYYY'
+ *
+ * \return:
+ *       parm_periode.p_id
+ */
+
+function getPeriodeFromMonth($p_cn, $p_date)
+{
+    $R = $p_cn->get_value("select p_id from parm_periode where
+                        to_char(p_start,'DD.MM.YYYY') = '01.$p_date'");
+    if ($R == "")
+       return -1;
+    return $R;
+}
+
+/**\brief Decode the html for the widegt richtext and remove newline
+ * \param $p_html string to decode
+ * \return the html code without new line
+ */
+
+function Decode($p_html)
+{
+    $p_html = str_replace('%0D', '', $p_html);
+    $p_html = str_replace('%0A', '', $p_html);
+    $p_html = urldecode($p_html);
+    return $p_html;
+}
+
+/**\brief Create the condition to filter on the j_tech_per
+ *        thanks a from and to date.
+ * \param $p_cn database conx
+ * \param $p_from start date (date)
+ * \param $p_to  end date (date)
+ * \param $p_form if the p_from and p_to are date or p_id
+ * \param $p_field column name
+ * \return a string containg the query
+ */
+
+function sql_filter_per($p_cn, $p_from, $p_to, $p_form='p_id', 
$p_field='jr_tech_per')
+{
+
+    if ($p_form != 'p_id' &&
+           $p_form != 'date')
+    {
+       echo_error(__FILE__, __LINE__, 'Mauvais parametres ');
+       exit(-1);
+    }
+    if ($p_form == 'p_id')
+    {
+       // retrieve the date
+       $pPeriode = new Periode($p_cn);
+       $a_start = $pPeriode->get_date_limit($p_from);
+       $a_end = $pPeriode->get_date_limit($p_to);
+       if ($a_start == null || $a_end == null)
+           throw new Exception(__FILE__ . __LINE__ . sprintf(_('Attention 
periode 
+                    non trouvee periode p_from= %s p_to_periode = %s'), 
$p_from ,
+                   $p_to));
+
+
+       $p_from = $a_start['p_start'];
+       $p_to = $a_end['p_end'];
+    }
+    if ($p_from == $p_to)
+       $periode = " $p_field = (select p_id from parm_periode " .
+               " where " .
+               " p_start = to_date('$p_from','DD.MM.YYYY')) ";
+    else
+       $periode = "$p_field in (select p_id from parm_periode " .
+               " where p_start >= to_date('$p_from','DD.MM.YYYY') and p_end <= 
to_date('$p_to','DD.MM.YYYY')) ";
+    return $periode;
+}
+
+/**\brief alert in javascript
+ * \param $p_msg is the message
+ * \param $buffer if false, echo directly and execute the javascript, if 
$buffer is true, the alert javascript
+ * is in the return string
+ * \return string with alert javascript if $buffer is true
+ */
+
+function alert($p_msg, $buffer=false)
+{
+    $r = '<script>';
+    $r.= 'alert_box(\'' . j($p_msg) . '\')';
+    $r.= '</script>';
+
+    if ($buffer)
+       return $r;
+    echo $r;
+}
+
+/**
+ * @brief set the lang thanks the _SESSION['g_lang'] var.
+ */
+function set_language()
+{
+    // desactivate local check
+    if ( defined("LOCALE") && LOCALE==0 ) return;
+    if ( ! isset ($_SESSION['g_lang'])) return;
+    $dir = "";
+    // set differently the language depending of the operating system
+    if (what_os() == 1)
+    {
+       $dir = setlocale(LC_MESSAGES, $_SESSION['g_lang']);
+       if ($dir == "")
+       {
+           $g_lang = 'fr_FR.utf8';
+           $dir = setlocale(LC_MESSAGES, $g_lang);
+          // echo '<span class="notice">' . $_SESSION['g_lang'] . ' domaine 
non supporté</h2>';
+       }
+       bindtextdomain('messages', './lang');
+       textdomain('messages');
+       bind_textdomain_codeset('messages', 'UTF8');
+
+       return;
+    }
+    // for windows
+    putenv('LANG=' . $_SESSION['g_lang']);
+    $dir = setlocale(LC_ALL, $_SESSION['g_lang']);
+    bindtextdomain('messages', '.\\lang');
+    textdomain('messages');
+    bind_textdomain_codeset('messages', 'UTF8');
+}
+
+/**
+ * @brief try to determine on what os you are running the pĥpcompte
+ * server
+ * @return
+ *  0 it is a windows
+ *  1 it is a Unix like
+ */
+function what_os()
+{
+    $inc_path = get_include_path();
+
+    if (strpos($inc_path, ";") != 0)
+    {
+       $os = 0;   /* $os is 0 for windoz */
+    }
+    else
+    {
+       $os = 1;   /* $os is 1 for unix */
+    }
+    return $os;
+}
+
+/**
+ * @brief shrink the date, make a date shorter for the printing
+ * @param $p_date format DD.MM.YYYY
+ * @return date in the format DDMMYY (size = 13 mm in arial 8)
+ */
+function shrink_date($p_date)
+{
+    $date = str_replace('.', '', $p_date);
+    $str_date = substr($date, 0, 4) . substr($date, 6, 2);
+    return $str_date;
+}
+/**
+ * @brief shrink the date, make a date shorter for the printing
+ * @param $p_date format DD.MM.YYYY
+ * @return date in the format DDMMYY (size = 13 mm in arial 8)
+ */
+function smaller_date($p_date)
+{
+    $str_date = substr($p_date, 0, 6) . substr($p_date, 8, 2);
+    return $str_date;
+}
+
+/**
+ * @brief format the date, when taken from the database the format
+ * is MM-DD-YYYY
+ * @param $p_date format
+ * @param
+ * @return date in the format DD.MM.YYYY
+ */
+function format_date($p_date, $p_from_format = 
'YYYY-MM-DD',$p_to_format='DD.MM.YYYY')
+{
+    if ($p_from_format == 'YYYY-MM-DD')
+    {
+        $date = explode('-', $p_date);
+        if (count($date) != 3)
+            return $p_date;
+    }
+    if ($p_from_format == 'DD.MM.YYYY')
+    {
+        $temp_date = explode('.', $p_date);
+        if (count($temp_date) != 3)
+            return $p_date;
+        $date[0] = $temp_date[2]; // 0 is year
+        $date[1] = $temp_date[1]; // 1 for month
+        $date[2] = $temp_date[0]; // 2 for day
+    }
+
+    switch ($p_to_format)
+    {
+        case 'DD.MM.YYYY':
+            $str_date = $date[2] . '.' . $date[1] . '.' . $date[0];
+            break;
+        case 'YYYY-MM-DD':
+            $str_date = $date[0] . '-' . $date[1] . '-' . $date[2];
+            break;
+       case 'YYYYMMDD':
+            $str_date = $date[0] . $date[1] . $date[2];
+            break;
+                case 'YYYY/MM/DD':
+            $str_date = $date[0] . '/' . $date[1] . '/' . $date[2];
+            break;
+
+               }
+    return $str_date;
+}
+
+
+
+/**
+ * Should a dialog box when you are disconnected from an ajax call
+ * propose to reload or to connect in another tab
+ */
+function ajax_disconnected($div)
+{
+    /**
+     * if $_SESSION['g_user'] is not set : echo a warning
+     */
+    if (!isset($_SESSION['g_user']))
+    {
+       $script = 'var a=$("' . $div . 
'");a.style.height="70%";a.style.width="60%";';
+       $script.='a.style.top=posY-20+offsetY;a.style.left=posX+offsetX;';
+       $script = create_script($script);
+       $html = $script;
+       $html.=HtmlInput::anchor_close($div);
+       $html.='<div>';
+       $html.=h2(_('Données non disponibles'), 'class="title" 
style="width:auto"');
+       $html.=h2(_('Veuillez vous reconnecter soit dans une autre fenêtre soit 
'
+                . ' en cliquant sur le lien'), 'class="error"');
+        // Reload button
+        $reload=new IButton("reload");
+        $reload->value=_("Se reconnecter pour revenir ici");
+        $reload->class="button";
+        $reload->javascript='window.location.reload()';
+        // Link to log in another tab
+        $html.='<p style="text-align:center">';
+        $html.='<a href="index.php" class="button" target="_blank">'.
+                _('Cliquez ici pour vous reconnecter dans une autre page').
+                '</a>';
+        $html.=$reload->input();
+        $html.='</p>';
+       $html = escape_xml($html);
+       header('Content-type: text/xml; charset=UTF-8');
+       echo <<<EOF
+<?xml version="1.0" encoding="UTF-8"?>
+<data>
+<ctl>$div</ctl>
+<code>$html</code>
+</data>
+EOF;
+       exit();
+    }
+}
+
+/**
+ *Show the modules
+ * @param int $selected module selected profile_menu.pm_id
+ */
+function show_module($selected)
+{
+    global $g_user;
+    $cn = Dossier::connect();
+    $amodule = $cn->get_array("select
+       me_code,me_menu,me_url,me_javascript,p_order,me_type,me_description
+       from v_all_menu
+       where
+       p_id=$1
+       and p_type_display='M'
+       order by p_order", array($g_user->get_profile()));
+
+    if ($selected != -1)
+    {
+        $selected_module=$cn->get_value('select me_code from profile_menu 
where'
+                . ' pm_id = $1 ', array($selected));
+       require_once NOALYSS_INCLUDE.'/template/module.php';
+       $file = $cn->get_array("select 
me_file,me_parameter,me_javascript,me_type,me_description from v_all_menu
+           where pm_id=$1 and p_id=$2", 
array($selected,$g_user->get_profile()));
+       if ( count($file ) == 0 )
+       {
+               echo '</div>';
+               echo '</div>';
+               echo '<div class="content">';
+               echo_warning(_("Module inexistant")."[ $selected ] ");
+               echo '</div>';
+               exit();
+       }
+       if ($file[0]['me_file'] != '')
+       {
+           if ($file[0]['me_parameter'] != "")
+           {
+               // if there are paramter put them in superglobal
+               $array=compute_variable($file[0]['me_parameter']);
+               put_global($array);
+           }
+
+               // if file is not a plugin, include the file, otherwise
+               // include the plugin launcher
+               if ($file[0]['me_type'] != 'PL')
+                       {
+                               require_once $file[0]['me_file'];
+                       }
+                       else
+                       {
+                               // nothing  : direct call to plugin
+                       }
+       }
+       if ( $file[0]['me_javascript'] != '')
+       {
+               create_script($file[0]['me_javascript']);
+       }
+    }
+}
+/**
+ * Find the default module or the first one
+ * @global $g_user $g_user
+ * @return default module (string)
+ */
+function find_default_module()
+{
+    global $g_user;
+    $cn = Dossier::connect();
+
+    $default_module = $cn->get_array("select me_code
+           from profile_menu join profile_user using (p_id)
+           where
+           p_type_display='M' and
+           user_name=$1 and pm_default=1", array($g_user->login));
+
+       /*
+        * Try to find the smallest order for module
+        */
+    if (empty($default_module))
+    {
+               $default_module = $cn->get_array("select me_code
+           from profile_menu join profile_user using (p_id)
+           where
+           p_type_display='M' and
+           user_name=$1 order by p_order limit 1", array($g_user->login));
+
+               // if no default try to find the default menu
+               if ( empty ($default_module))
+               {
+                       $default_module = $cn->get_array("select me_code
+                        from profile_menu join profile_user using (p_id)
+                          where
+                          p_type_display='E' and
+                          user_name=$1 and pm_default=1 ", 
array($g_user->login));
+                       /*
+                        * Try to find a default menu by order
+                        */
+                       if (empty ($default_module))
+                       {
+                               $default_module = $cn->get_array("select me_code
+                               from profile_menu join profile_user using (p_id)
+                               where
+                               user_name=$1 and p_order=(select min(p_order) 
from profile_menu join profile_user using (p_id)
+                               where user_name=$2) limit 1", 
array($g_user->login, $g_user->login));
+                       }
+
+                       /*
+                       * if nothing found, there is no profile for this user 
=> exit
+                       */
+                       if (empty ($default_module))
+                       {
+                            /* 
+                             * If administrateur, then we insert a default 
profile (1)
+                             * for him
+                             */
+                            if ( $g_user->admin == 1 )
+                            {
+                                $cn->exec_sql('insert into 
profile_user(user_name,p_id) values ($1,1) ',array($g_user->login));
+                                return find_default_module();
+                            }
+                            echo_warning(_("Utilisateur n'a pas de profil, 
votre administrateur doit en configurer un dans CFGSEC"));
+                            exit();
+                       }
+               }
+               return $default_module[0]['me_code'];
+    }
+
+    if (count($default_module) > 1)
+    {
+               // return the first module found
+               return $default_module[0]['me_code'];
+    }
+    elseif (count($default_module) == 1)
+    {
+       return $default_module[0]['me_code'];
+    }
+}
+
+/**
+ * show the module
+ * @global $g_user
+ * @param $module the $_REQUEST['ac'] exploded into an array
+ * @param  $idx the index of the array : the AD code is splitted into an array 
thanks the slash
+ */
+function show_menu($module)
+{
+    if ($module == 0)return;
+    static $level=0;
+    global $g_user;
+    
+    $cn = Dossier::connect();
+    /**
+     * Show the submenus
+     */
+    $amenu = $cn->get_array("
+        select 
+            pm_id,
+            me_code,
+            pm_id_dep,
+            me_file,
+            me_javascript,
+            me_url,
+            me_menu,
+            me_description,
+            me_description_etendue
+            from profile_menu 
+            join menu_ref using (me_code) 
+            where pm_id_dep=$1 and p_id=$2
+        order by p_order", array($module, $g_user->get_profile()));
+    
+    // There are submenuS, so show them
+    if (!empty($amenu) && count($amenu) > 1)
+    {
+        $a_style_menu=array('topmenu','menu2','menu3');
+        if ( $level > count($a_style_menu))
+            $style_menu='menu3';
+        else {
+            $style_menu=$a_style_menu[$level];
+        }
+               require 'template/menu.php';
+    } // there is only one submenu so we include the code or javascript 
+      // or we show the submenu
+    elseif (count($amenu) == 1)
+    {
+        if ( trim($amenu[0]['me_url']) != "" ||
+             trim ($amenu[0]['me_file']) != "" ||
+             trim ($amenu[0]['me_javascript']) != "" )
+        {
+               echo '<div class="topmenu">';
+               echo h2info(_($amenu[0]['me_menu']));
+               echo '</div>';
+               $module = $amenu[0]['pm_id'];
+        } else {
+           $url=$_REQUEST['ac'].'/'.$amenu[0]['me_code'];
+           echo '<a href="do.php?gDossier='.Dossier::id().'&ac='.$url.'">';
+           echo _($amenu[0]['me_menu']);
+           echo '</a>';
+           $level++;
+           return;
+        }
+    }
+    
+    // There is no submenu or only one
+    if (empty($amenu) || count($amenu) == 1)
+    {
+               $file = $cn->get_array("select 
me_file,me_parameter,me_javascript,me_type
+               from menu_ref
+               join profile_menu using (me_code)
+               join profile_user using (p_id)
+               where
+               pm_id=$1 and
+               user_name=$2 and
+               (me_file is not null or trim(me_file) <>'' or
+               me_javascript is not null or trim (me_javascript) <> '')", 
array($module,$g_user->login));
+
+               if (count($file)==0)
+               {
+                        return;
+               }
+
+               if ($file[0]['me_file'] != "")
+               {
+                       if ($file[0]['me_parameter'] !== "")
+                       {
+                               // if there are paramter put them in superglobal
+                               
$array=compute_variable($file[0]['me_parameter']);
+                               put_global($array);
+                       }
+                        if ( DEBUG ) echo  $file[0]['me_file']," param : 
",$file[0]['me_parameter'] ;
+                        /*
+                         * Log the file we input to put in the folder 
test-noalyss for replaying it
+                         */
+                        if (LOGINPUT) {
+                                
$file_loginput=fopen($_ENV['TMP'].'/scenario-'.$_SERVER['REQUEST_TIME'].'.php','a+');
+                                fwrite($file_loginput, "include 
'".$file[0]['me_file']."';");
+                                fwrite($file_loginput,"\n");
+                                fclose($file_loginput);
+                        }
+                       // if file is not a plugin, include the file, otherwise
+                       // include the plugin launcher
+                       if ( $file[0]['me_type'] != 'PL')
+                               require_once $file[0]['me_file'];
+                       else
+                               require 'extension_get.inc.php';
+
+                       exit();
+               }
+               if ( $file[0]['me_javascript'] != '')
+               {
+                    $js=  str_replace('<DOSSIER>', dossier::id(), 
$file[0]['me_javascript']);
+                    echo create_script($js);
+               }
+    }
+    $level++;
+}
+/**
+ * Put in superglobal (get,post,request) the value contained in
+ * the parameter field (me_parameter)
+ * @param $array [key] [value]
+ */
+function put_global($array)
+{
+    for ($i=0;$i<count($array);$i++)
+    {
+       $key=$array[$i]['key'];
+       $value=$array[$i]['value'];
+       $_GET[$key]=$value;
+       $_POST[$key]=$value;
+       $_REQUEST[$key]=$value;
+    }
+}
+/**
+ * the string has the format a=b&c=d, it is parsed and an array[][key,value]
+ * is returned
+ * @param $p_string
+ * @return $array usable in put_global
+ */
+function compute_variable($p_string)
+{
+    $array=array();
+    if ($p_string == '') return $array;
+
+    $var=explode("&",$p_string);
+    if (empty ($var))  return $array;
+    for ($i=0;$i < count($var);$i++)
+    {
+       $var2=explode('=',$var[$i]);
+       $array[$i]['key']=$var2[0];
+       $array[$i]['value']=$var2[1];
+    }
+    return $array;
+}
+function ajax_xml_error($p_code,$p_string)
+{
+    $html = escape_xml($p_string);
+    header('Content-type: text/xml; charset=UTF-8');
+               echo <<<EOF
+<?xml version="1.0" encoding="UTF-8"?>
+<data>
+<code>$p_code</code>
+<value>$html</value>
+</data>
+EOF;
+}
+/**
+ * @brief Display a box with the contains
+ * @param type $p_array Data to display
+ * @param type $p_title Title of the box
+ * @param type $p_div id of the box
+ */
+function display_dashboard_operation($p_array,$p_title,$p_div)
+{
+       ?>
+<div id="<?php echo $p_div;?>" class="inner_box" 
style="display:none;position:fixed;top:250px;left:12%;width: 
75%;min-height:50%;overflow:auto;">
+       <?php
+       echo HtmlInput::title_box($p_title, $p_div, "hide");
+       ?>
+       <?php if (count($p_array)>0) :?>
+       <table class="result">
+               <tr>
+                       <th><?php echo _('Date')?></th>
+                       <th><?php echo _('Code Interne')?></th>
+                       <th><?php echo _('Pièce')?></th>
+                       <th><?php echo _('Description')?></th>
+                       <th>
+                               <?php echo _('Montant')?>
+                       </th>
+
+               </tr>
+               <?php
+                       for ($i=0;$i<count($p_array);$i++):
+               ?>
+               <tr class="<?php echo (($i%2)==0)?'odd':'even';?>">
+                       <td>
+                               <?php echo 
smaller_date(format_date($p_array[$i]['jr_date']) );?>
+                       </td>
+                       <td>
+                               <?php echo 
HtmlInput::detail_op($p_array[$i]['jr_id'], $p_array[$i]['jr_internal']) ?>
+                       </td>
+                        <td>
+                            <?php echo h($p_array[$i]['jr_pj_number'])?>
+                        </td>
+                       <td>
+                               <?php echo h($p_array[$i]['jr_comment']) ?>
+                       </td>
+                       <td>
+                               <?php echo nbm($p_array[$i]['jr_montant']) ?>
+                       </td>
+               </tr>
+               <?php
+               endfor;
+               ?>
+       </table>
+       <?php else: ?>
+       <h2 class="notice"><?php echo _('Aucune donnée')?></h2>
+       <?php
+       endif;
+       ?>
+</div>
+<?php
+}
+function get_array_column($p_array,$key)
+{
+    $array=array();
+    for ($i=0;$i<count($p_array);$i++)
+    {
+        $r=$p_array[$i];
+        if ( isset($r[$key])) {
+            $array[]=$r[$key];
+        }
+    }
+    return $array;
+}
+
+/**
+ * This function create a ledger object and return the right one.
+ * It uses the factory pattern
+ * @param Database $p_cn
+ * @param type $ledger_id 
+ * @return Acc_Ledger
+ * @throws Exception
+ */
+function factory_Ledger(Database &$p_cn, $ledger_id)
+{
+    include_once 'class/class_acc_ledger_sold.php';
+    include_once 'class/class_acc_ledger_purchase.php';
+    include_once 'class/class_acc_ledger_fin.php';
+    
+    $ledger=new Acc_Ledger($p_cn, $ledger_id);
+    $type=$ledger->get_type();
+
+    switch ($type)
+    {
+        case 'VEN':
+            $obj=new Acc_Ledger_Sold($p_cn, $ledger_id);
+            break;
+        case 'ACH':
+            $obj=new Acc_Ledger_Purchase($p_cn, $ledger_id);
+            break;
+        case 'FIN':
+            $obj= new Acc_Ledger_Fin($p_cn, $ledger_id);
+            break;
+        case 'ODS':
+            $obj=$ledger;
+            break;
+
+        default:
+            throw new Exception('Ledger type not found');
+    }
+    return $obj;
+}
+/**
+ * Check if we use IE 8 or 9
+ * @return int 1 for IE8-9;0 otherwise
+ */
+function is_msie()
+{
+    if ( strpos ($_SERVER['HTTP_USER_AGENT'],'MSIE 8.0')  != 0 ||
+         strpos ($_SERVER['HTTP_USER_AGENT'],'MSIE 9.0')  != 0 )
+       $is_msie=1;
+    else
+        $is_msie=0;
+    return $is_msie;
+}
+?>
\ No newline at end of file
diff --git a/include/lib/class_database.php b/include/lib/class_database.php
new file mode 100644
index 0000000..87ad5fa
--- /dev/null
+++ b/include/lib/class_database.php
@@ -0,0 +1,1051 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/**\file
+ * \brief contains the class for connecting to a postgresql database
+ */
+require_once NOALYSS_INCLUDE.'/constant.php';
+require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
+
+/**\brief
+ * This class allow you to connect to the postgresql database, execute sql, 
retrieve data
+ *
+ */
+
+class Database
+{
+
+    private $db;    /**< database connection */
+    private $ret;   /**< return value  */
+    private $is_open;                   /*!< true is connected */
+    /**\brief constructor
+     * \param $p_database_id is the id of the dossier, or the modele following 
the
+     * p_type if = 0 then connect to the repository
+     * \param $p_type is 'DOS' (defaut) for dossier or 'MOD'
+     */
+
+    function __construct($p_database_id=0, $p_type='dos')
+    {
+        if (IsNumber($p_database_id)==false||strlen($p_database_id)>5)
+            die("-->Dossier invalide [$p_database_id]");
+        $noalyss_user=(defined("noalyss_user"))?noalyss_user:phpcompta_user;
+        
$password=(defined("noalyss_password"))?noalyss_password:phpcompta_password;
+        
$port=(defined("noalyss_psql_port"))?noalyss_psql_port:phpcompta_psql_port;
+        $host=(!defined("noalyss_psql_host") )?'127.0.0.1':noalyss_psql_host;
+        if (defined("MULTI")&&MULTI=="0")
+        {
+            $l_dossier=dbname;
+        }
+        else
+        {
+
+            if ($p_database_id==0)
+            { /* connect to the repository */
+                $l_dossier=sprintf("%saccount_repository", 
strtolower(domaine));
+            }
+            else if ($p_type=='dos')
+            { /* connect to a folder (dossier) */
+                $l_dossier=sprintf("%sdossier%d", strtolower(domaine), 
$p_database_id);
+            }
+            else if ($p_type=='mod')
+            { /* connect to a template (modele) */
+                $l_dossier=sprintf("%smod%d", strtolower(domaine), 
$p_database_id);
+            }
+            else if ($p_type=='template')
+            {
+                $l_dossier='template1';
+            }
+            else
+            {
+                throw new Exception('Connection invalide');
+            }
+        }
+
+        ob_start();
+        $a=pg_connect("dbname=$l_dossier host='$host' user='$noalyss_user'
+                      password='$password' port=$port");
+
+        if ($a==false)
+        {
+            if (DEBUG)
+            {
+                ob_end_clean();
+                echo '<h2 class="error">Impossible de se connecter &agrave; 
postgreSql !</h2>';
+                echo '<p>';
+                echo "Vos param&egrave;tres sont incorrectes : <br>";
+                echo "<br>";
+                echo "base de donn&eacute;e : $l_dossier<br>";
+                echo "Domaine : ".domaine."<br>";
+                echo "Port $port <br>";
+                echo "Utilisateur : $noalyss_user <br>";
+                echo '</p>';
+
+                die("Connection impossible : v&eacute;rifiez vos 
param&egrave;tres de base
+                  de donn&eacute;es");
+            }
+            else
+            {
+                echo '<h2 class="error">Erreur de connexion !</h2>';
+            }
+        }
+        $this->db=$a;
+        $this->is_open=TRUE;
+        if ($this->exist_schema('comptaproc'))
+        pg_exec($this->db, 'set search_path to public,comptaproc;');
+        pg_exec($this->db, 'set DateStyle to ISO, MDY;');
+        ob_end_clean();
+    }
+
+    public function verify()
+    {
+        // Verify that the elt we want to add is correct
+    }
+
+    function set_encoding($p_charset)
+    {
+        pg_set_client_encoding($this->db, $p_charset);
+    }
+
+    /**
+     * \brief send a sql string to the database
+     * \param $p_string     sql string
+     * \param $p_array array for the SQL string (see pg_query_params)
+     * \return the result of the query, a resource or false if an
+     * error occured
+     */
+
+    function exec_sql($p_string, $p_array=null)
+    {
+        try
+        {
+            if ( ! $this->is_open ) throw new Exception(' Database is closed');
+            $this->sql=$p_string;
+            $this->array=$p_array;
+
+            if ($p_array==null)
+            {
+                if (!DEBUG)
+                    $this->ret=pg_query($this->db, $p_string);
+                else
+                    $this->address@hidden($this->db, $p_string);
+            }
+            else
+            {
+                $a=is_array($p_array);
+                if (!is_array($p_array))
+                {
+                    throw new Exception("Erreur : exec_sql attend un array");
+                }
+                if (!DEBUG) 
+                    $this->ret=pg_query_params($this->db, $p_string, $p_array);
+                else
+                    $this->address@hidden($this->db, $p_string, $p_array);
+            }
+            if (!$this->ret)
+            {
+                
$str_error=pg_last_error($this->db).pg_result_error($this->ret);
+                throw new Exception("  SQL ERROR $p_string ".$str_error, 1);
+            }
+        }
+        catch (Exception $a)
+        {
+            if (DEBUG)
+            {
+                print_r($p_string);
+                print_r($p_array);
+                echo $a->getMessage();
+                echo $a->getTrace();
+                echo $a->getTraceAsString();
+                echo pg_last_error($this->db);
+            }
+            $this->rollback();
+            
+            throw ($a);
+        }
+
+        return $this->ret;
+    }
+
+    /** \brief Count the number of row returned by a sql statement
+     *
+     * \param $p_sql sql string
+     * \param $p_array if not null we use the safer pg_query_params
+     */
+
+    function count_sql($p_sql, $p_array=null)
+    {
+        $r_sql=$this->exec_sql($p_sql, $p_array);
+        return pg_NumRows($r_sql);
+    }
+
+    /**\brief get the current sequence value
+     */
+
+    function get_current_seq($p_seq)
+    {
+        $Res=$this->get_value("select currval('$p_seq') as seq");
+        return $Res;
+    }
+
+    /**\brief  get the next sequence value
+     */
+
+    function get_next_seq($p_seq)
+    {
+        $Res=$this->exec_sql("select nextval('$p_seq') as seq");
+        $seq=pg_fetch_array($Res, 0);
+        return $seq['seq'];
+    }
+
+    /**
+     * @ brief : start a transaction
+     *
+     */
+    function start()
+    {
+        $Res=$this->exec_sql("start transaction");
+    }
+
+    /**
+     * Commit the transaction
+     *
+     */
+    function commit()
+    {
+        if ( ! $this->is_open) return;
+        $Res=$this->exec_sql("commit");
+    }
+
+    /**
+     * rollback the current transaction
+     */
+    function rollback()
+    {
+        if ( ! $this->is_open) return;
+        $Res=$this->exec_sql("rollback");
+    }
+
+    /**
+     * @brief alter the sequence value
+     * @param $p_name name of the sequence
+     * @param $min the start value of the sequence
+     */
+    function alter_seq($p_name, $min)
+    {
+        if ($min<1)
+            $min=1;
+        $Res=$this->exec_sql("alter sequence $p_name restart $min");
+    }
+
+    /**
+     * \brief Execute a sql script
+     * \param $script script name
+     */
+
+    function execute_script($script)
+    {
+
+        if (!DEBUG)
+            ob_start();
+        $hf=fopen($script, 'r');
+        if ($hf==false)
+        {
+            throw new Exception ( 'Ne peut ouvrir '.$script);
+        }
+        $sql="";
+        $flag_function=false;
+        while (!feof($hf))
+        {
+            $buffer=fgets($hf);
+            $buffer=str_replace("$", "\$", $buffer);
+            print $buffer."<br>";
+            // comment are not execute
+            if (substr($buffer, 0, 2)=="--")
+            {
+                //echo "comment $buffer";
+                continue;
+            }
+            // Blank Lines Are Skipped
+            If (Strlen($buffer)==0)
+            {
+                //echo "Blank $buffer";
+                Continue;
+            }
+            if (strpos(strtolower($buffer), "create function")===0)
+            {
+                echo "found a function";
+                $flag_function=true;
+                $sql=$buffer;
+                continue;
+            }
+            if (strpos(strtolower($buffer), "create or replace function")===0)
+            {
+                echo "found a function";
+                $flag_function=true;
+                $sql=$buffer;
+                continue;
+            }
+            // No semi colon -> multiline command
+            if ($flag_function==false&&strpos($buffer, ';')==false)
+            {
+                $sql.=$buffer;
+                continue;
+            }
+            if ($flag_function)
+            {
+                if (strpos(strtolower($buffer), "language plpgsql")===false&&
+                        strpos(strtolower($buffer), "language 
'plpgsql'")===false)
+                {
+                    $sql.=$buffer;
+                    continue;
+                }
+            }
+            else
+            {
+                // cut the semi colon
+                $buffer=str_replace(';', '', $buffer);
+            }
+            $sql.=$buffer;
+            if ($this->exec_sql($sql)==false)
+            {
+                $this->rollback();
+                if (!DEBUG)
+                    ob_end_clean();
+                print "ERROR : $sql";
+                throw new Exception("ERROR : $sql");
+            }
+            $sql="";
+            $flag_function=false;
+            print "<hr>";
+        } // while (feof)
+        fclose($hf);
+        if (!DEBUG)
+            ob_end_clean();
+    }
+
+    /**
+     * \brief Get version of a database, the content of the
+     *        table version
+     *
+     * \return version number
+     *
+     */
+
+    function get_version()
+    {
+        $Res=$this->get_value("select val from version");
+        return $Res;
+    }
+
+    /**
+     * @brief fetch the $p_indice array from the last query
+     * @param $p_indice index
+     *
+     */
+    function fetch($p_indice)
+    {
+        if ($this->ret==false)
+            throw new Exception('this->ret is empty');
+        return pg_fetch_array($this->ret, $p_indice);
+    }
+
+    /**
+     * 
+     * @brief return the number of rows found by the last query, or the number
+     * of rows from $p_ret
+     * @param $p_ret is the result of a query, the default value is null, in 
that case
+     * it is related to the last query
+     * @note synomym for count()
+     */
+
+    function size($p_ret=null)
+    {
+        if ($p_ret==null)
+            return pg_NumRows($this->ret);
+        else
+            return pg_NumRows($p_ret);
+    }
+
+    /**
+     * @brief       synomym for size() 
+     */
+
+    function count($p_ret=null)
+    {
+        return $this->size($p_ret);
+    }
+
+    /**
+     * \brief loop to apply all the path to a folder or
+     *         a template
+     * \param $p_name database name
+     * \param $from_setup == 1 if called from setup.php
+     *
+     */
+
+    function apply_patch($p_name, $from_setup=1)
+    {
+        if ( ! $this->exist_table('version')) {
+            echo _('Base de donnée vide');
+            return;
+        }
+        $MaxVersion=DBVERSION-1;
+        $succeed="<span style=\"font-size:18px;color:green\">&#x2713;</span>";
+        echo '<ul style="list-type-style:square">';
+        $add=($from_setup==0)?'admin/':'';
+        for ($i=4; $i<=$MaxVersion; $i++)
+        {
+            $to=$i+1;
+
+            if ($this->get_version()<=$i)
+            {
+                if ($this->get_version()==97)
+                {
+                    if ($this->exist_schema("amortissement"))
+                    {
+                        $this->exec_sql('ALTER TABLE 
amortissement.amortissement_histo
+                                                       ADD CONSTRAINT 
internal_fk FOREIGN KEY (jr_internal) REFERENCES jrn (jr_internal)
+                                                       ON UPDATE CASCADE ON 
DELETE SET NULL');
+                    }
+                }
+                echo "<li>Patching ".$p_name.
+                " from the version ".$this->get_version()." to $to ";
+
+                $this->execute_script($add.'sql/patch/upgrade'.$i.'.sql');
+                echo $succeed;
+
+                if (!DEBUG)
+                    ob_start();
+                // specific for version 4
+                if ($i==4)
+                {
+                    $sql="select jrn_def_id from jrn_def ";
+                    $Res=$this->exec_sql($sql);
+                    $Max=$this->size();
+                    for ($seq=0; $seq<$Max; $seq++)
+                    {
+                        $row=pg_fetch_array($Res, $seq);
+                        $sql=sprintf("create sequence s_jrn_%d", 
$row['jrn_def_id']);
+                        $this->exec_sql($sql);
+                    }
+                }
+                // specific to version 7
+                if ($i==7)
+                {
+                    // now we use sequence instead of computing a max
+                    //
+                    $Res2=$this->exec_sql('select coalesce(max(jr_grpt_id),1) 
as l from jrn');
+                    $Max2=pg_NumRows($Res2);
+                    if ($Max2==1)
+                    {
+                        $Row=pg_fetch_array($Res2, 0);
+                        var_dump($Row);
+                        $M=$Row['l'];
+                        $this->exec_sql("select setval('s_grpt',$M,true)");
+                    }
+                }
+                // specific to version 17
+                if ($i==17)
+                {
+                    $this->execute_script($add.'sql/patch/upgrade17.sql');
+                    $max=$this->get_value('select last_value from 
s_jnt_fic_att_value');
+                    $this->alter_seq($p_cn, 's_jnt_fic_att_value', $max+1);
+                } // version
+                // reset sequence in the modele
+                //--
+                if ($i==30&&$p_name=="mod")
+                {
+                    $a_seq=array('s_jrn', 's_jrn_op', 's_centralized',
+                        's_stock_goods', 'c_order', 's_central');
+                    foreach ($a_seq as $seq)
+                    {
+                        $sql=sprintf("select setval('%s',1,false)", $seq);
+                        $Res=$this->exec_sql($sql);
+                    }
+                    $sql="select jrn_def_id from jrn_def ";
+                    $Res=$this->exec_sql($sql);
+                    $Max=pg_NumRows($Res);
+                    for ($seq=0; $seq<$Max; $seq++)
+                    {
+                        $row=pg_fetch_array($Res, $seq);
+                        $sql=sprintf("select setval('s_jrn_%d',1,false)", 
$row['jrn_def_id']);
+                        $this->exec_sql($sql);
+                    }
+                }
+                if ($i==36)
+                {
+                    /* check the country and apply the path */
+                    $res=$this->exec_sql("select pr_value from parameter where 
pr_id='MY_COUNTRY'");
+                    $country=pg_fetch_result($res, 0, 0);
+                    
$this->execute_script($add."sql/patch/upgrade36.".$country.".sql");
+                    $this->exec_sql('update tmp_pcmn set 
pcm_type=find_pcm_type(pcm_val)');
+                }
+                if ($i==59)
+                {
+                    $res=$this->exec_sql("select pr_value from parameter where 
pr_id='MY_COUNTRY'");
+                    $country=pg_fetch_result($res, 0, 0);
+                    if ($country=='BE')
+                        $this->exec_sql("insert into parm_code values 
('SUPPLIER',440,'Poste par défaut pour les fournisseurs')");
+                    if ($country=='FR')
+                        $this->exec_sql("insert into parm_code values 
('SUPPLIER',400,'Poste par défaut pour les fournisseurs')");
+                }
+                if ($i==61)
+                {
+                    $country=$this->get_value("select pr_value from parameter 
where pr_id='MY_COUNTRY'");
+                    
$this->execute_script($add."sql/patch/upgrade61.".$country.".sql");
+                }
+
+                if (!DEBUG)
+                    ob_end_clean();
+            }
+        }
+        echo '</ul>';
+    }
+
+    /**
+     * 
+     * \brief return the value of the sql, the sql will return only one value
+     *        with the value
+     * \param $p_sql the sql stmt example :select s_value from
+      document_state where s_id=2
+     * \param $p_array if array is not null we use the ExecSqlParm (safer)
+     * \see exec_sql
+     * \note print a warning if several value are found, if only the first 
value is needed
+     * consider using a LIMIT clause
+     * \return only the first value or an empty string if nothing is found
+     */
+
+    function get_value($p_sql, $p_array=null)
+    {
+        $this->ret=$this->exec_sql($p_sql, $p_array);
+        $r=pg_NumRows($this->ret);
+        if ($r==0)
+            return "";
+        if ($r>1)
+        {
+            $array=pg_fetch_all($this->ret);
+            throw new Exception("Attention $p_sql retourne 
".pg_NumRows($this->ret)."  valeurs ".
+            var_export($p_array, true)." values=".var_export($array, true));
+        }
+        $r=pg_fetch_row($this->ret, 0);
+        return $r[0];
+    }
+    /**
+     * @brief return the number of rows affected by the previous query
+     */
+    function get_affected()
+    {
+        return Database::num_row($this->ret);
+    }
+
+    /**
+     * \brief  purpose return the result of a sql statment
+     * in a array
+     * \param $p_sql sql query
+     * \param $p_array if not null we use ExecSqlParam
+     * \return an empty array if nothing is found
+     */
+
+    function get_array($p_sql, $p_array=null)
+    {
+        $r=$this->exec_sql($p_sql, $p_array);
+
+        if (($Max=pg_NumRows($r))==0)
+            return array();
+        $array=pg_fetch_all($r);
+        return $array;
+    }
+
+    function create_sequence($p_name, $min=1)
+    {
+        if ($min<1)
+            $min=1;
+        $sql="create sequence ".$p_name." minvalue $min";
+        $this->exec_sql($sql);
+    }
+
+    /**
+     * \brief test if a sequence exist */
+    /* \return true if the seq. exist otherwise false
+     */
+
+    function exist_sequence($p_name)
+    {
+        $r=$this->count_sql("select relname from pg_class where 
relname=lower($1)", array($p_name));
+        if ($r==0)
+            return false;
+        return true;
+    }
+
+    /**\brief test if a table exist
+     * \param $p_name table name
+     * \param  $schema name of the schema default public
+     * \return true if a table exist otherwise false
+     */
+
+    function exist_table($p_name, $p_schema='public')
+    {
+        $r=$this->count_sql("select table_name from information_schema.tables 
where table_schema=$1 and table_name=lower($2)", array($p_schema, $p_name));
+        if ($r==0)
+            return false;
+        return true;
+    }
+
+    /**
+     * Check if a column exists in a table
+     * @param $col : column name
+     * @param $table :table name
+     * @param $schema :schema name, default public
+     * @return true or false
+     */
+    function exist_column($col, $table, $schema)
+    {
+        $r=$this->get_value('select count(*) from information_schema.columns 
where table_name=lower($1) and column_name=lower($2) and 
table_schema=lower($3)', array($col, $table, $schema));
+        if ($r>0)
+            return true;
+        return false;
+    }
+
+    /**
+     * return the name of the database with the domain name
+     * @param $p_id of the folder WITHOUT the domain name
+     * @param $p_type dos for folder mod for template
+     * @return formatted name
+     */
+    function format_name($p_id, $p_type)
+    {
+        switch ($p_type)
+        {
+            case 'dos':
+                $sys_name=sprintf("%sdossier%d", strtolower(domaine), $p_id);
+                break;
+            case 'mod':
+                $sys_name=sprintf("%smod%d", strtolower(domaine), $p_id);
+                break;
+            default:
+                echo_error(__FILE__." format_name invalid type ".$p_type, 
__LINE__);
+                throw new Exception(__FILE__." format_name invalid type 
".$p_type. __LINE__);
+        }
+        return $sys_name;
+    }
+
+    /**
+     * Count the database name in a system view
+     * @param $p_name string database name
+     * @return number of database found (normally 0 or 1)
+     */
+    function exist_database($p_name)
+    {
+        $database_exist=$this->get_value('select count(*)
+                from pg_catalog.pg_database where datname = lower($1)', 
array($p_name));
+        return $database_exist;
+    }
+
+    /**
+     * @brief check if the large object exists
+     * @param $p_oid of the large object
+     * @return return true if the large obj exist or false if not
+     */
+    function exist_blob($p_oid)
+    {
+        $r=$this->get_value('select count(loid) from pg_largeobject where 
loid=$1'
+                , array($p_oid));
+        if ($r>0)
+            return true;
+        else
+            return false;
+    }
+
+    /*
+     * !\brief test if a view exist
+     * \return true if the view. exist otherwise false
+     */
+
+    function exist_view($p_name)
+    {
+        $r=$this->count_sql("select viewname from pg_views where 
viewname=lower($1)", array($p_name));
+        if ($r==0)
+            return false;
+        return true;
+    }
+
+    /*
+     * !\brief test if a schema exists
+     * \return true if the schemas exists otherwise false
+     */
+
+    function exist_schema($p_name)
+    {
+        $r=$this->count_sql("select nspname from pg_namespace where 
nspname=lower($1)", array($p_name));
+        if ($r==0)
+            return false;
+        return true;
+    }
+
+    /**
+     * \brief create a string containing the value separated by comma
+     * for use in a SQL in statement
+     * \return the string or empty if nothing is found
+     * \see fid_card.php
+     */
+
+    function make_list($sql, $p_array=null)
+    {
+        if ($p_array==null)
+        {
+            $aArray=$this->get_array($sql);
+        }
+        else
+        {
+            $aArray=$this->get_array($sql, $p_array);
+        }
+        if (empty($aArray))
+            return "";
+        $aIdx=array_keys($aArray[0]);
+        $idx=$aIdx[0];
+        $ret="";
+        $f="";
+        for ($i=0; $i<count($aArray); $i++)
+        {
+            $row=$aArray[$i];
+            $ret.=$f.$aArray[$i][$idx];
+            $f=',';
+        }
+        $ret=trim($ret, ',');
+        return $ret;
+    }
+
+    /**
+     * \brief make a array with the sql.
+     *
+     * \param $p_sql  sql statement, only the first two column will be 
returned in
+     *  an array. The first col. is the label and the second the value
+     *  \param $p_null if the array start with a null value
+     *  \param $p_array is the array with the bind value
+     * \note this function is used with ISelect when it is needed to have a 
list of
+     * options.
+     * \return: a double array like
+      \verbatim
+      Array
+      (
+        [0] => Array
+                (
+                [value] => 1
+                [label] => Marchandise A
+               )
+
+      [1] => Array
+            (
+            [value] => 2
+            [label] => Marchandise B
+            )
+
+      [2] => Array
+            (
+            [value] => 3
+            [label] => Marchandise C
+            )
+      )
+      \endverbatim
+     * \see ISelect
+     */
+
+    function make_array($p_sql, $p_null=0,$p_array=null)
+    {
+        $a=$this->exec_sql($p_sql,$p_array);
+        $max=pg_NumRows($a);
+        if ($max==0&&$p_null==0)
+            return null;
+        for ($i=0; $i<$max; $i++)
+        {
+            $row=pg_fetch_row($a);
+            $r[$i]['value']=$row[0];
+            $r[$i]['label']=h($row[1]);
+        }
+        // add a blank item ?
+        if ($p_null==1)
+        {
+            for ($i=$max; $i!=0; $i--)
+            {
+                $r[$i]['value']=$r[$i-1]['value'];
+                $r[$i]['label']=h($r[$i-1]['label']);
+            }
+            $r[0]['value']=-1;
+            $r[0]['label']=" ";
+        } //   if ( $p_null == 1 )
+
+        return $r;
+    }
+
+    /**
+     * \brief Save a "piece justificative"
+     *
+     * \param $seq jr_grpt_id
+     * \return $oid of the lob file if success
+     *         null if a error occurs
+     *
+     */
+
+    function save_upload_document($seq)
+    {
+        /* there is
+          no file to
+          upload */
+        if ($_FILES["pj"]["error"]==UPLOAD_ERR_NO_FILE)
+        {
+            return;
+        }
+
+        $new_name=tempnam($_ENV['TMP'], 'pj');
+        if ($_FILES["pj"]["error"]>0)
+        {
+            print_r($_FILES);
+            echo_error(__FILE__.":".__LINE__."Error: ".$_FILES["pj"]["error"]);
+        }
+        if (strlen($_FILES['pj']['tmp_name'])!=0)
+        {
+            if (move_uploaded_file($_FILES['pj']['tmp_name'], $new_name))
+            {
+                // echo "Image saved";
+                $oid=pg_lo_import($this->db, $new_name);
+                if ($oid==false)
+                {
+                    echo_error('postgres.php', __LINE__, "cannot upload 
document");
+                    $this->rollback();
+                    return;
+                }
+                // Remove old document
+                $ret=$this->exec_sql("select jr_pj from jrn where 
jr_grpt_id=$seq");
+                if (pg_num_rows($ret)!=0)
+                {
+                    $r=pg_fetch_array($ret, 0);
+                    $old_oid=$r['jr_pj'];
+                    if (strlen($old_oid)!=0)
+                        pg_lo_unlink($cn, $old_oid);
+                }
+                // Load new document
+               $this->exec_sql("update jrn set jr_pj=$1 , jr_pj_name=$2,
+                                        jr_pj_type=$3  where jr_grpt_id=$4",
+                                        array($oid,$_FILES['pj']['name'] 
,$_FILES['pj']['type'],$seq));
+                return $oid;
+            }
+            else
+            {
+                echo "<H1>Error</H1>";
+                $this->rollback();
+            }
+        }
+        return 0;
+    }
+
+    /**\brief wrapper for the function pg_NumRows
+     * \param $ret is the result of a exec_sql
+     * \return number of line affected
+     */
+
+    static function num_row($ret)
+    {
+        return pg_NumRows($ret);
+    }
+
+    /**\brief wrapper for the function pg_fetch_array
+     * \param $ret is the result of a pg_exec
+     * \param $p_indice is the index
+     * \return $array of column
+     */
+
+    static function fetch_array($ret, $p_indice=0)
+    {
+        return pg_fetch_array($ret, $p_indice);
+    }
+
+    /**\brief wrapper for the function pg_fetch_all
+     * \param $ret is the result of pg_exec (exec_sql)
+     * \return double array (row x col )
+     */
+
+    static function fetch_all($ret)
+    {
+        return pg_fetch_all($ret);
+    }
+
+    /**\brief wrapper for the function pg_fetch_all
+     * \param $ret is the result of pg_exec (exec_sql)
+     * \param $p_row is the indice of the row
+     * \param $p_col is the indice of the col
+     * \return a string or an integer
+     */
+
+    static function fetch_result($ret, $p_row=0, $p_col=0)
+    {
+        return pg_fetch_result($ret, $p_row, $p_col);
+    }
+
+    /**\brief wrapper for the function pg_fetch_row
+     * \param $ret is the result of pg_exec (exec_sql)
+     * \param $p_row is the indice of the row
+     * \return an array indexed from 0
+     */
+
+    static function fetch_row($ret, $p_row)
+    {
+        return pg_fetch_row($ret, $p_row);
+    }
+
+    /**\brief wrapper for the function pg_lo_unlink
+     * \param $p_oid is the of oid
+     * \return return the result of the operation
+     */
+
+    function lo_unlink($p_oid)
+    {
+        return pg_lo_unlink($this->db, $p_oid);
+    }
+
+    /**\brief wrapper for the function pg_prepare
+     * \param $p_string string name for pg_prepare function
+     * \param $p_sql  is the sql to prepare
+     * \return return the result of the operation
+     */
+
+    function prepare($p_string, $p_sql)
+    {
+        return pg_prepare($this->db, $p_string, $p_sql);
+    }
+
+    /**\brief wrapper for the function pg_execute
+     * \param $p_string string name of the stmt given in pg_prepare function
+     * \param $p_array contains the variables
+     * \note set this->ret to the return of pg_execute
+     * \return return the result of the operation,
+     */
+
+    function execute($p_string, $p_array)
+    {
+        $this->ret=pg_execute($this->db, $p_string, $p_array);
+        return $this->ret;
+    }
+
+    /**\brief wrapper for the function pg_lo_export
+     * \param $p_oid is the oid of the log
+     * \param $tmp  is the file
+     * \return result of the operation
+     */
+
+    function lo_export($p_oid, $tmp)
+    {
+        return pg_lo_export($this->db, $p_oid, $tmp);
+    }
+
+    /**\brief wrapper for the function pg_lo_export
+     * \param $p_oid is the oid of the log
+     * \param $tmp  is the file
+     * \return result of the operation
+     */
+
+    function lo_import($p_oid)
+    {
+        return pg_lo_import($this->db, $p_oid);
+    }
+
+    /**\brief wrapper for the function pg_escape_string
+     * \param $p_string is the string to escape
+     * \return escaped string
+     */
+
+    static function escape_string($p_string)
+    {
+        return pg_escape_string($p_string);
+    }
+
+    /**\brief wrapper for the function pg_close
+     */
+
+    function close()
+    {
+        if ( $this->is_open ) pg_close($this->db);
+        $this->is_open=FALSE;
+    }
+
+    /**\brief
+     * \param
+     * \return
+     * \note
+     * \see
+     */
+
+    function __toString()
+    {
+        return "database ";
+    }
+
+    static function test_me()
+    {
+        
+    }
+
+    function status()
+    {
+        return pg_transaction_status($this->db);
+    }
+
+    /**
+     * with the handle of a successull query, echo each row into CSV and
+     * send it directly
+     * @param type $ret handle to a query
+     * @param type $aheader  double array, each item of the array contains
+     * a key type (num) and a key title
+     */
+    function query_to_csv($ret, $aheader)
+    {
+        $seq="";
+        for ($i=0; $i<count($aheader); $i++)
+        {
+            echo $seq.'"'.$aheader[$i]['title'].'"';
+            $seq=";";
+        }
+        printf("\n\r");
+        // fetch all the rows
+        for ($i=0; $i<Database::num_row($ret); $i++)
+        {
+            $row=Database::fetch_array($ret, $i);
+            $sep2="";
+            // for each rows, for each value
+            for ($e=0; $e<count($row)/2; $e++)
+            {
+                switch ($aheader[$e]['type'])
+                {
+                    case 'num':
+                        echo $sep2.nb($row[$e]);
+                        break;
+                    default:
+                        echo $sep2.'"'.$row[$e].'"';
+                }
+                $sep2=";";
+            }
+            printf("\n\r");
+        }
+    }
+
+}
+
+/* test::test_me(); */
diff --git a/include/class_filetosend.php b/include/lib/class_filetosend.php
similarity index 100%
rename from include/class_filetosend.php
rename to include/lib/class_filetosend.php
diff --git a/include/lib/class_html_input.php b/include/lib/class_html_input.php
new file mode 100755
index 0000000..2fca3fa
--- /dev/null
+++ b/include/lib/class_html_input.php
@@ -0,0 +1,929 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*! \file
+ * \brief This class is used to create all the HTML INPUT TYPE
+ */
+
+/*!
+ * \brief class widget This class is used to create all the HTML INPUT TYPE
+ *        and some specials which works with javascript like
+ *        js_search.
+ *
+ * special value
+ *    js_search and js_search_only :you need to add a span widget the name
+ *    of the js_* widget + '_label' , the member extra contains cred,deb to
+ *    filter the search of cred of deb of a jrn or contains a string with
+ *    a list of frd_id.
+ *    Possible type
+ *    $type
+ *      - TEXT
+ *      - HIDDEN
+ *      - BUTTON in this->js you have the javascript code
+ *      - SELECT the options are passed via this->value, this array is
+ *        build thanks the make_array function, each array (of the
+ *        array) aka row must contains a field value and a field label
+ *      - PASSWORD
+ *      - CHECKBOX
+ *      - RADIO
+ *      - TEXTAREA
+ *      - RICHTEXT
+ *      - FILE
+ *      - SPAN
+ */
+class HtmlInput
+{
+
+    var $type;                      /*!<  $type type of the widget */
+    var $name;                      /*!<  $name field NAME of the INPUT */
+    var $value;                     /*!<  $value what the INPUT contains */
+    var $readOnly;                  /*!<  $readonly true : we cannot change 
value */
+    var $size;                      /*!<  $size size of the input */
+    var $selected;                  /*!<  $selected for SELECT RADIO and 
CHECKBOX the selected value */
+    var $table;                     /*!<  $table =1 add the table tag */
+    var $label;                     /*!<  $label the question before the input 
*/
+    var $disabled;                  /*!<  $disabled poss. value == true or 
nothing, to disable INPUT*/
+    var $extra;                     /*!<  $extra different usage, it depends 
of the $type */
+    var $extra2;                    /*!<  $extra2 different usage,
+                                                                               
it depends of the $type */
+    var $javascript;                              /*!< $javascript  is the 
javascript to add to the widget */
+    var $ctrl;                                         /*!<$ctrl is the 
control to update (see js_search_card_control) */
+
+    var $tabindex;
+    function __construct($p_name="",$p_value="",$p_id="")
+    {
+        $this->name=$p_name;
+        $this->readOnly=false;
+        $this->size=20;
+        $this->width=50;
+        $this->heigh=20;
+        $this->value=$p_value;
+        $this->selected="";
+        $this->table=0;
+        $this->disabled=false;
+        $this->javascript="";
+        $this->extra2="all";
+        $this->attribute=array();
+        $this->id=$p_id;
+
+    }
+    function setReadOnly($p_read)
+    {
+        $this->readOnly=$p_read;
+    }
+    /*!\brief set the extra javascript property for the INPUT field
+     *\param $p_name name of the parameter
+     *\param $p_value default value of this parameter
+     */
+    public function set_attribute($p_name,$p_value)
+    {
+        $this->attribute[]=array($p_name,$p_value);
+        $this->$p_name=$p_value;
+    }
+    /**
+     address@hidden you can add attribute to this in javascript
+     * this function is a wrapper and create a script (in js) to modify
+     * "this" (in javascript) with the value of obj->attribute from PHP
+     address@hidden return string with the javascript code
+     */
+    public function get_js_attr()
+    {
+        require_once NOALYSS_INCLUDE.'/lib/function_javascript.php';
+        $attr="";
+        if ( count($this->attribute) == 0) return "";
+
+        /* Add properties at the widget */
+        for ($i=0;$i< count($this->attribute);$i++)
+        {
+            list($name,$value)=$this->attribute[$i];
+            $tmp1=sprintf("$('%s').%s='%s';",
+                          $this->name,
+                          $name,
+                          $value);
+            $attr.=$tmp1;
+        }
+        $attr=create_script($attr);
+        return $attr;
+    }
+    /**
+     * Make a JSON object, this method create a javascript object
+     * with the attribute set, it returns a javascript string with the object
+     * @param $p_name : name of the object, can be null. If the name is not 
null, return
+     * $p_name={} otherwise only the object {}
+     * @return javascript string with the object
+     * @note: there is not check on the key->value, so you could need to escape
+     * special char as quote, single-quote...
+     * @code
+    $a=new IButton()
+    $a->set_attribute('prop','1');
+    $a->set_attribute('prop','2');
+    $a->set_attribute('prop','3');
+    $string = $a->make_object('property');
+    echo $string => property={'prop':'1','prop2':'2','prop3':'3'};
+    $string = $a->make_object(null);
+    echo $string => {'prop':'1','prop2':'2','prop3':'3'};
+    @endcode
+    */
+    public function make_object($p_name=null)
+    {
+        $name=($p_name != null)?$p_name.'=':'';
+        if ( count($this->attribute) == 0) return $name."{}";
+        $ret=$name."{";
+        $and='';
+
+        for ($i=0;$i< count($this->attribute);$i++)
+        {
+            list($name,$value)=$this->attribute[$i];
+            $tmp1=sprintf($and."'%s':'%s'",
+                          $name,
+                          $value);
+            $ret.=$tmp1;
+            $and=',';
+        }
+
+        $ret.='}';
+        return $ret;
+    }
+    //#####################################################################
+    /* Debug
+     */
+    function debug()
+    {
+        echo "Type ".$this->type."<br>";
+        echo "name ".$this->name."<br>";
+        echo "value". $this->value."<br>";
+        $readonly=($this->readonly==false)?"false":"true";
+        echo "read only".$readonly."<br>";
+    }
+    static   function submit 
($p_name,$p_value,$p_javascript="",$p_class="smallbutton")
+    {
+
+        return '<INPUT TYPE="SUBMIT" class="'.$p_class.'" NAME="'.$p_name.'" 
ID="'.$p_name.'_submit_id"  VALUE="'.$p_value.'" '.$p_javascript.'>';
+    }
+    static   function button 
($p_name,$p_value,$p_javascript="",$p_class="smallbutton")
+    {
+
+        return '<INPUT TYPE="button" class="'.$p_class.'" NAME="'.$p_name.'" 
ID="'.$p_name.'" VALUE="'.$p_value.'" '.$p_javascript.'>';
+    }
+
+    static function reset ($p_value)
+    {
+        return '<INPUT TYPE="RESET" class="smallbutton" VALUE="'.$p_value.'">';
+    }
+    static function hidden($p_name,$p_value,$p_id="")
+    {
+               if ($p_id=="") $p_id=$p_name;
+        return '<INPUT TYPE="hidden" id="'.$p_id.'" NAME="'.$p_name.'" 
VALUE="'.$p_value.'">';
+    }
+
+    static function extension()
+    {
+        return self::hidden('plugin_code',$_REQUEST['plugin_code']);
+    }
+
+    /*!\brief create a button with a ref
+     *\param $p_label the text
+     *\param $p_value the location of the window,
+     *\param $p_name the id of the span
+     *\param $p_javascript javascript for this button
+     *\return string with htmlcode
+     */
+    static function 
button_anchor($p_label,$p_value,$p_name="",$p_javascript="",$p_class="button")
+    {
+        $r=sprintf('<span id="%s" > <A class="'.$p_class.'" 
style="display:inline;"  href="%s" %s >%s</A></span>',
+                   $p_name,
+                   $p_value,
+                   $p_javascript,
+                   $p_label);
+        return $r;
+    }
+    static function infobulle($p_comment)
+    {
+        $r='<A HREF="#" tabindex="-1" 
style="display:inline;color:black;background-color:yellow;padding-left:4px;width:2em;padding-right:4px;text-decoration:none;"
 onmouseover="showBulle(\''.$p_comment.'\')"  
onclick="showBulle(\''.$p_comment.'\')" onmouseout="hideBulle(0)">?</A>';
+        return $r;
+    }
+    static function warnbulle($p_comment)
+    {
+        $r='<A HREF="#" tabindex="-1" 
style="display:inline;color:red;background-color:white;padding-left:4px;padding-right:4px;text-decoration:none;"
 onmouseover="showBulle(\''.$p_comment.'\')"  
onclick="showBulle(\''.$p_comment.'\')" onmouseout="hideBulle(0)">&Delta;</A>';
+        return $r;
+    }
+    /**
+     * return a string containing the html code for calling the modifyOperation
+     */
+    static function detail_op($p_jr_id,$p_mesg)
+    {
+        return sprintf('<A class="detail" 
style="text-decoration:underline;display:inline" 
HREF="javascript:modifyOperation(%d,%d)">%s</A>',
+                       $p_jr_id,dossier::id(),$p_mesg);
+    }
+       /**
+        * @brief return an anchor to view the detail of an action
+        * @param $ag_id
+        * @param $p_mesg
+        * @param $p_modify let you modify an operation
+        *
+        */
+    static function detail_action($ag_id,$p_mesg,$p_modify=1)
+    {
+        return sprintf('<A class="detail" 
style="text-decoration:underline;display:inline" 
HREF="javascript:view_action(%d,%d,%d)">%s</A>',
+                       $ag_id,dossier::id(),$p_modify,$p_mesg);
+    }
+    /**
+     * return a string containing the html code for calling the 
modifyModeleDocument
+     */
+    static function detail_modele_document($p_id,$p_mesg)
+    {
+        return sprintf('<A class="detail" style="text-decoration:underline" 
HREF="javascript:modifyModeleDocument(%d,%d)">%s</A>',
+                       $p_id,dossier::id(),$p_mesg);
+    }
+
+    /**
+     * return a string containing the html code for calling the removeStock
+     */
+    static function remove_stock($p_id,$p_mesg)
+    {
+        return sprintf('<A class="detail" style="text-decoration:underline" 
HREF="javascript:removeStock(%d,%d)">%s</A>',
+                       $p_id,dossier::id(),$p_mesg);
+    }
+
+    /**
+     * display a div with the history of the card
+     */
+    static function history_card($f_id,$p_mesg,$p_style="")
+    {
+        $view_history= sprintf('<A class="detail"  
style="text-decoration:underline;%s" 
HREF="javascript:view_history_card(\'%s\',\'%s\')" >%s</A>',
+                               $p_style,$f_id, dossier::id(), $p_mesg);
+        return $view_history;
+    }
+    /**
+     * display a div with the history of the card
+     */
+    static function history_card_button($f_id,$p_mesg)
+    {
+      static $e=0;
+      $e++;
+      $js= sprintf('onclick="view_history_card(\'%s\',\'%s\')"',
+                               $f_id, dossier::id());
+      $view_history=HtmlInput::button("hcb"+$e,$p_mesg,$js);
+      return $view_history;
+    }
+
+    /**
+     * display a div with the history of the account
+     */
+    static function history_account($p_account,$p_mesg,$p_style="")
+    {
+        $view_history= sprintf('<A class="detail" 
style="text-decoration:underline;%s" 
HREF="javascript:view_history_account(\'%s\',\'%s\')" >%s</A>',
+                               $p_style,$p_account, dossier::id(), $p_mesg);
+        return $view_history;
+    }
+
+    /**
+     * return the html code to create an hidden div and a button
+     * to show this DIV. This contains all the available ledgers
+     * for the user in READ or RW
+     address@hidden $selected is an array of checkbox
+     address@hidden $div div suffix
+     address@hidden the choosen ledger are stored in the array r_jrn (_GET)
+     */
+    static function select_ledger($p_type,$p_selected,$div='')
+    {
+        global $g_user;
+       $r = '';
+       /* security : filter ledger on user */
+       $p_array = $g_user->get_ledger($p_type, 3);
+        
+        ob_start();
+        
+
+        /* create a hidden div for the ledger */
+        echo '<div id="div_jrn'.$div.'" >';
+        echo HtmlInput::title_box(_("Journaux"), $div."jrn_search");
+        echo '<div style="padding:5px">';
+        echo '<form method="GET" id="'.$div.'search_frm" onsubmit="return 
hide_ledger_choice(\''.$div.'search_frm\')">';
+        echo HtmlInput::hidden('nb_jrn', count($p_array));
+        echo _('Filtre ').HtmlInput::filter_table($div.'tb_jrn', '0,1,2', 2);
+        echo '<table class="result" id="'.$div.'tb_jrn">';
+        echo '<tr>';
+        echo th(_('Nom'));
+        echo th(_('Description'));
+        echo th(_('Type'));
+        echo '</tr>';
+        echo '<tr>';
+        echo '<td>';
+        echo HtmlInput::button('sel_'.$div,_('Inverser la sélection'),' 
onclick = "toggle_checkbox(\''."{$div}search_frm".'\')"');
+        echo '</td>';
+        echo '</tr>';
+        for ($e=0;$e<count($p_array);$e++)
+        {
+            $row=$p_array[$e];
+            $r=new ICheckBox($div.'r_jrn'.$e,$row['jrn_def_id']);
+            $idx=$row['jrn_def_id'];
+            if ( $p_selected != null &&  
in_array($row['jrn_def_id'],$p_selected))
+            {
+                $r->selected=true;
+            }
+            $class=($e%2==0)?' class="even" ':' class="odd" ';
+            echo '<tr '.$class.'>';
+            echo '<td style="white-space: 
nowrap">'.$r->input().$row['jrn_def_name'].'</td>';
+            echo '<td >'.$row['jrn_def_description'].'</td>';
+            echo '<td >'.$row['jrn_def_type'].'</td>';
+            echo '</tr>';
+
+        }
+        echo '</table>';
+        echo HtmlInput::hidden('div',$div);
+        echo HtmlInput::submit('save',_('Valider'));
+        echo HtmlInput::button_close($div."jrn_search");
+        echo '</form>';
+        echo '</div>';
+        echo '</div>';
+  
+        $ret=ob_get_contents();
+        ob_end_clean();
+        return $ret;
+    }
+    /**
+     *create a hidden plus button to select the cat of ledger
+     address@hidden the selected value is stored in the array p_cat
+     */
+    static function select_cat($array_cat)
+    {
+        ob_start();
+        $ledger=new ISmallButton('l');
+        $ledger->label=_("Catégorie");
+        $ledger->javascript=" show_cat_choice()";
+        echo $ledger->input();
+
+        /* create a hidden div for the ledger */
+        echo '<div id="div_cat">';
+        echo '<h2 class="info">'._('Choix des categories').'</h2>';
+        $selected=(isset($_GET['r_cat']))?$_GET['r_cat']:null;
+
+        echo '<ul>';
+        for ($e=0;$e<count($array_cat);$e++)
+        {
+            $row=$array_cat[$e];
+            $re=new ICheckBox('r_cat['.$e.']',$row['cat']);
+
+            if ( $selected != null && isset($selected[$e]))
+            {
+                $re->selected=true;
+            }
+            echo '<li style="list-style-type: 
none;">'.$re->input().$row['name'].'('.$row['cat'].')</li>';
+
+        }
+        echo '</ul>';
+        $hide=new IButton('l2');
+        $hide->label=_("Valider");
+        $hide->javascript=" hide_cat_choice() ";
+        echo $hide->input();
+
+        echo '</div>';
+        $r=ob_get_contents();
+        ob_end_clean();
+        return $r;
+    }
+    static function display_periode($p_id)
+    {
+      $r=sprintf('<a href="javascript:void(0)" 
onclick="display_periode(%d,%d)">Modifier</a>',
+                dossier::id(),
+                $p_id);
+      return $r;
+    }
+    /**
+     *close button for the HTML popup
+     address@hidden add_div modify_operation
+     address@hidden $div_name is the name of the div to remove
+     */
+    static function button_close($div_name)
+    {
+      $a=new IButton('Fermer');
+      $a->label=_("Fermer");
+      $a->javascript="removeDiv('".$div_name."')";
+      $html=$a->input();
+
+      return $html;
+
+    }
+    /**
+     * Return a html string with an anchor which close the inside popup. 
(top-right corner)
+     address@hidden name of the DIV to close
+     */
+    static function anchor_close($div,$p_js="")
+    {
+       $r='';
+       $r.='<div style="position:absolute;right:2px;margin:2px;padding:0px;">';
+       $r.= '<A id="close_div" class="input_text" 
onclick="removeDiv(\''.$div.'\');'.$p_js.'">&#10761;</A>';
+       $r.='</div>';
+       return $r;
+    }
+    /**
+     * button Html
+     address@hidden $action action action to perform (message) without onclick
+     address@hidden $javascript javascript to execute
+     */
+    static function 
button_action($action,$javascript,$id="xx",$p_class="button")
+    {
+        if ($id=="xx"){
+            $id=HtmlInput::generate_id("xx");
+        }
+               $r="";
+               $r.='<input type="button" id="'.$id.'" class="'.$p_class.'" 
onclick="'.$javascript.'" value="'.h($action).'">';
+               return $r;
+
+    }
+    /**
+     * button Html image
+     address@hidden $javascript javascript to execute
+     * @param $id id of the button
+     * @param  $class class of the button
+     * @param $p_image image
+     */
+    static function 
button_image($javascript,$id="xx",$p_class='class="button"',$p_image="")
+    {
+        if ($id=="xx"){
+            $id=HtmlInput::generate_id("xx");
+        }
+        $r="";
+        $r.='<image id="'.$id.'" '.$p_class.' onclick="'.$javascript.'"  
src="'.$p_image.'" />';
+        return $r;
+
+    }
+    /**
+     * Return a html string with an anchor to hide a div, put it in the right 
corner
+     address@hidden $action action action to perform (message)
+     address@hidden $javascript javascript
+     address@hidden not protected against html
+     address@hidden Acc_Ledger::display_search_form
+     */
+    static function anchor_hide($action,$javascript)
+    {
+       $r='';
+       $r.='<div style="position:absolute;margin:2px;right:2px">';
+       $r.= '<span id="close_div" class="input_text"  
onclick="'.$javascript.'">'.$action.'</span>';
+       $r.='</div>';
+       return $r;
+    }
+
+    /**
+     * Javascript to print the current window
+     */
+    static function print_window()
+    {
+       $r='';
+       $r.=HtmlInput::button('print','Imprimer','onclick="window.print();"');
+       return $r;
+    }
+    /**
+     *show the detail of a card
+     */
+    static function 
card_detail($p_qcode,$pname='',$p_style="",$p_nohistory=false)
+    {
+      //if ($pname=='')$pname=$p_qcode;
+      $r="";
+      $histo=($p_nohistory==true)?' ,nohistory:1':"";
+      $r.=sprintf('<a href="javascript:void(0)" %s 
onclick="fill_ipopcard({qcode:\'%s\' %s})">%s [%s]</a>',
+                 $p_style,$p_qcode,$histo,$pname,$p_qcode);
+      return $r;
+    }
+    /**
+     *transform request data  to hidden
+     address@hidden $array is an of indices
+     address@hidden $request name of the superglobal $_POST $_GET 
$_REQUEST(default)
+     address@hidden html string with the hidden data
+     */
+    static function array_to_hidden($array,$global_array )
+    {
+
+      $r="";
+
+      if ( count($global_array )==0) return '';
+      foreach ($array  as $a)
+       {
+         if (isset($global_array [$a])) 
+          if (is_array($global_array[$a]) == false ) {
+                $r.=HtmlInput::hidden($a,$global_array [$a]);
+              } else {
+                  if (count($global_array[$a]) > 0)
+                  {
+                      foreach ($global_array[$a] as $value)
+                      {
+                          $r.=HtmlInput::hidden($a."[]",$value);
+                    }
+                  }
+              }
+       }
+
+      return $r;
+    }
+    /**
+     *transform $_GET   data  to hidden
+     address@hidden $array is an of indices
+     address@hidden HtmlInput::request_to_hidden
+     address@hidden html string with the hidden data
+     */
+    static function get_to_hidden($array)
+    {
+      $r=self::array_to_hidden($array,$_GET );
+      return $r;
+    }
+
+    /**
+     *transform $_POST  data  to hidden
+     address@hidden $array is an of indices
+     address@hidden HtmlInput::request_to_hidden
+     address@hidden html string with the hidden data
+     */
+    static function post_to_hidden($array)
+    {
+      $r=self::array_to_hidden($array,$_POST );
+      return $r;
+    }
+
+    /**
+     *transform $_REQUEST   data  to hidden
+     address@hidden $array is an of indices
+     address@hidden HtmlInput::request_to_hidden
+     address@hidden html string with the hidden data
+     */
+    static function request_to_hidden($array)
+    {
+      $r=self::array_to_hidden($array,$_REQUEST  );
+      return $r;
+    }
+
+    /**
+     *transform request data  to string
+     address@hidden $array is an of indices
+     address@hidden $request name of the superglobal $_POST $_GET 
$_REQUEST(default)
+     address@hidden html string with the string data
+     */
+    static function array_to_string($array,$global_array,$start="?" )
+    {
+
+      $r=$start;
+
+      if ( count($global_array )==0) return '';
+      $and="";
+      foreach ($array  as $a)
+       {
+         if (isset($global_array [$a]))
+          {
+              if (is_array($global_array[$a]) == false ) {
+                $r.=$and."$a=".$global_array [$a];
+              } else {
+                  for ($i=0;$i<count($global_array[$a]);$i++) {
+                      $r.=$and."$a"."[]=".$global_array[$a][$i];
+                      $and="&amp;";
+                  }
+              }
+          }
+         $and="&amp;";
+       }
+
+      return $r;
+    }
+    /**
+     *transform $_GET   data  to string
+     address@hidden $array is an of indices
+     address@hidden HtmlInput::request_to_string
+     address@hidden html string with the string data
+     */
+    static function get_to_string($array,$start="?")
+    {
+      $r=self::array_to_string($array,$_GET ,$start);
+      return $r;
+    }
+
+    /**
+     *transform $_POST  data  to string
+     address@hidden $array is an of indices
+     address@hidden HtmlInput::request_to_string
+     address@hidden html string with the string data
+     */
+    static function post_to_string($array)
+    {
+      $r=self::array_to_string($array,$_POST );
+      return $r;
+    }
+
+    /**
+     *transform $_REQUEST   data  to string
+     address@hidden $array is an of indices
+     address@hidden HtmlInput::request_to_string
+     address@hidden html string with the string data
+     */
+    static function request_to_string($array,$start="?")
+    {
+      $r=self::array_to_string($array,$_REQUEST,$start  );
+      return $r;
+    }
+
+    /**
+     * generate an unique id for a widget,
+     address@hidden $p_prefix prefix
+     address@hidden HtmlInput::IDate
+     address@hidden string with a unique id
+     */
+    static function generate_id($p_prefix)
+    {
+      $r=sprintf('%s_%d',$p_prefix,mt_rand(0,999999));
+      return $r;
+    }
+    /**
+     * return default if the value if the value doesn't exist in the array
+     address@hidden $ind the index to check
+     address@hidden $default the value to return
+     address@hidden $array the array
+     */
+    static function default_value($ind,$default,$array)
+    {
+      if ( ! isset($array[$ind]))
+       {
+         return $default;
+       }
+      return $array[$ind];
+    }
+       /**
+        *  return default if the value if the value doesn't exist in $_GET
+        * @param  $ind name of the variable
+        * @param type $default
+        * @return type
+        */
+       static function default_value_get($ind, $default)
+       {
+               if (!isset($_GET[$ind]))
+               {
+                       return $default;
+               }
+               return $_GET[$ind];
+       }
+       /**
+        *  return default if the value if the value doesn't exist in $_POST
+        * @param  $ind name of the variable
+        * @param type $default
+        * @return type
+        */
+       static function default_value_post($ind, $default)
+       {
+               if (!isset($_POST[$ind]))
+               {
+                       return $default;
+               }
+               return $_POST[$ind];
+       }
+       /**
+        *  return default if the value if the value doesn't exist in $_REQUEST
+        * @param  $ind name of the variable
+        * @param type $default
+        * @return type
+        */
+       static function default_value_request($ind, $default)
+       {
+               if (!isset($_REQUEST[$ind]))
+               {
+                       return $default;
+               }
+               return $_REQUEST[$ind];
+       }
+        /**
+         * Title for boxes, you can customize the symbol thanks symbol with
+         * the mode "custom"
+         * @param type $name Title
+         * @param type $div element id, except for mode none or custom
+         * @param type $mod hide , close , zoom , custom or none, with
+         * custom , the $name contains all the code
+         * @param type $p_js contains the javascript with "custom" contains 
button + code 
+         * @return type
+         */
+       static function title_box($name,$div,$mod="close",$p_js="")
+       {
+               if ($mod=='close')      
{$r=HtmlInput::anchor_close($div,$p_js); }else
+               if ($mod=='hide')       
{$r=HtmlInput::anchor_hide("&#10761;","$('$div').hide();$p_js");} else
+               if ($mod=='zoom')       {$r='<span  id="span_'.$div.'" 
style="float:right;margin-right:5px">'.HtmlInput::anchor("&#11036;","",$p_js,' 
name="small'.$div.'" id="close_div" class="input_text"  ').'</span>'; } else
+                if ( $mod == 'custom')  {$r='<span  id="span_'.$div.'" 
style="float:right;margin-right:5px">'.$p_js."</span>";} else
+                if ( $mod == 'none')    {$r="" ; }
+                    else 
+                            die (__FILE__.":".__LINE__._('Paramètre invaide'));
+               $r.=h2($name,' class="title" ');
+               return $r;
+       }
+        /**
+         * @brief let you create only a link and set an id on it.
+         * After create a javascript for getting the event 
+         * onclick = function() {...}
+         * @param type $p_text Text to display
+         * @param type $p_id id of the link
+         * @param type $type title of the link
+         * @code
+         * echo HtmlInput::anchor_empty('go','go_id');
+         * <script>$("go_id").onclick=function (e) { ...}</script>
+         * @endcode
+         */
+        static  function anchor_empty($p_text,$p_id,$p_title="")
+        {
+            $p_url="javascript:void(0)";
+            $str=sprintf('<a id="%s" href="javascript:void(0)" class="line" 
title="%s">%s</a>',
+            $p_id,$p_title,$p_text);
+            return $str;
+        }
+        /**
+         *Return a simple anchor with a url or a javascript
+         * if $p_js is not null then p_url will be javascript:void(0)
+         * we don't add the event onclick. You must give p_url OR p_js
+         * default CSS class=line
+         * @param string $p_text text of the anchor
+         * @param string $p_url  url
+         * @param string $p_js javascript
+         * @param string $p_style is the visuable effect (class, style...)
+         */
+      static function anchor($p_text,$p_url="",$p_js="",$p_style=' 
class="line" ')
+      {
+          if ($p_js != "")
+          {
+              $p_url="javascript:void(0)";
+          }
+
+
+          $str=sprintf('<a %s href="%s" %s>%s</a>',
+                  $p_style,$p_url,$p_js,$p_text);
+          return $str;
+      }
+      /**
+       *Create an ISelect object containing the available repository for 
reading
+       * or writing
+       * @global $g_user
+       * @param $p_cn db object
+       * @param $p_name name of the select
+       * @param $p_mode is 'R' for reading, 'W' for writinh
+       * @return ISelect
+       * @throws Exception if p_mode is wrong
+       */
+      static function select_stock( $p_cn, $p_name,$p_mode)
+      {
+          global $g_user;
+          if ( ! in_array($p_mode,array('R','W') ) )
+          {
+              throw  new Exception  (__FILE__.":".__LINE__." $p_mode 
invalide");
+          }
+          $profile=$g_user->get_profile();
+          $sel=new ISelect($p_name);
+
+                 if ($p_mode == 'W')
+                       {
+                         $sel->value=$p_cn->make_array("
+                select r_id,r_name
+                                 from stock_repository join 
profile_sec_repository using (r_id)
+                where
+                 ur_right='W' and  p_id=".sql_string($profile).
+                " order by 2" );
+                     return $sel;
+                       }
+                         if ($p_mode == 'R')
+                       {
+                         $sel->value=$p_cn->make_array("
+                select r_id,r_name
+                                 from stock_repository join 
profile_sec_repository using (r_id)
+                where
+                  p_id=".sql_string($profile).
+                " order by 2" );
+                     return $sel;
+                       }
+       }
+       static function filter_table($p_table_id,$p_col,$start_row)
+       {
+               $r= "
+                       <span>
+                       <input id=\"lk_".$p_table_id."\" autocomplete=\"off\" 
class=\"input_text\" name=\"filter\" onkeyup=\"filter_table(this, 
'$p_table_id','$p_col',$start_row )\" type=\"text\">
+                       <input type=\"button\" class=\"smallbutton\" 
onclick=\"$('lk_".$p_table_id."').value='';filter_table($('lk_".$p_table_id."'),
 '$p_table_id','$p_col',$start_row );\" value=\"X\">
+                       </span>
+                       ";
+                $r.=' <span class="notice" id="info_'.$p_table_id.'"></span>';
+               return $r;
+       }
+
+       static function show_reconcile($p_div, $let,$span="")
+       {
+               $r = '<A  style="color:red;text-decoration:underline" 
href="javascript:void(0)" onclick="show_reconcile(\'' . $p_div . '\',\'' . $let 
. '\')">' . $let.$span . '</A>';
+               return $r;
+       }
+        /**
+         * Zoom the calendar
+         * @param type $obj objet json for the javascript
+         * @see calendar_zoom in scripts.js 
+         */
+        static function calendar_zoom($obj)
+        {
+            $button=new ISmallButton("calendar", _("Calendrier"));
+            $button->javascript="calendar_zoom($obj)";
+            return $button->input();
+        }
+        /**
+         * 
+         * @param type $p_array indice
+         *   - div div name
+         *   - type ALL, VEN, ACH or ODS
+         *   - all_type 1 yes 0 no
+         * 
+         */
+        static function button_choice_ledger($p_array)
+        {
+            extract ($p_array);
+            $bledger_param = json_encode(array(
+                'dossier' => $_REQUEST['gDossier'],
+                'type' => $type,
+                'all_type' => $all_type,
+                'div' => $div,
+                'class'=>'inner_box'
+            ));
+
+            $bledger_param = str_replace('"', "'", $bledger_param);
+            $bledger = new ISmallButton('l');
+            $bledger->label = _("choix des journaux");
+            $bledger->javascript = " show_ledger_choice($bledger_param)";
+            $f_ledger = $bledger->input();
+            $hid_jrn = "";
+            if (isset($_REQUEST[$div . 'nb_jrn']))
+            {
+                for ($i = 0; $i < $_REQUEST[$div . 'nb_jrn']; $i++)
+                {
+                    if (isset($_REQUEST[$div . "r_jrn"][$i]))
+                        $hid_jrn.=HtmlInput::hidden($div . 'r_jrn[' . $i . 
']', $_REQUEST[$div . "r_jrn"][$i]);
+                }
+                $hid_jrn.=HtmlInput::hidden($div . 'nb_jrn', $_REQUEST[$div . 
'nb_jrn']);
+            } else
+            {
+                $hid_jrn = HtmlInput::hidden($div . 'nb_jrn', 0);
+            }
+            echo $f_ledger;
+            echo '<span id="ledger_id' . $div . '">';
+            echo $hid_jrn;
+            echo '</span>';
+        }
+        /**
+         * Returns HTML code for displaying a icon with a link to a receipt 
document from
+         * the ledger 
+         * @global $cn database connx
+         * @param $p_jr_id jrn.jr_id
+         * @return nothing or HTML Code for a link to the document
+         */
+        static function show_receipt_document($p_jr_id)
+        {
+            global $cn;
+            
+            $array=$cn->get_array('select jr_def_id,jr_pj_name,jr_grpt_id from 
jrn where jr_id=$1',array($p_jr_id));
+            if (count($array)==0) return "";
+            if ($array[0]['jr_pj_name'] == "") return "";
+            $str_dossier=Dossier::get();
+            $image='<IMG style="width:24px;height:24px;border:0px" 
SRC="image/documents.png" title="' . $array[0]['jr_pj_name'] . '" >';
+            $r=sprintf('<A class="detail" 
HREF="show_pj.php?jrn=%s&jr_grpt_id=%s&%s">%s</A>', $array[0]['jr_def_id'], 
$array[0]['jr_grpt_id'], $str_dossier, $image);
+            return $r;
+            
+        }
+        /**
+         * 
+         * @param type $p_operation_jr_id action_gestion_operation.ago_id
+         */
+        static function  button_action_remove_operation($p_operation) 
+        {
+            
$rmOperation=sprintf("javascript:confirm_box(null,'"._('Voulez-vous effacer 
cette relation ')."',function ()  {remove_operation('%s','%s');});",
+                                                       dossier::id(),
+                                                       $p_operation);
+            $js= '<a class="tinybutton" id="acop'.$p_operation.'" 
href="javascript:void(0)" onclick="'.$rmOperation.'">'.SMALLX.'</a>';
+            return $js;
+        }
+        static function button_action_add_concerned_card($p_agid)
+        {
+            $dossier=Dossier::id();
+            $javascript= <<<EOF
+                    
obj={dossier:$dossier,ag_id:$p_agid};action_add_concerned_card(obj);
+EOF;
+            $js=HtmlInput::button_action(_('Ajout autres'), 
$javascript,'xx','smallbutton');
+            return $js;
+        }
+        static function button_action_add()
+        {
+            $dossier=Dossier::id();
+            $js=HtmlInput::button_action(_('Nouvel 
événement'),'action_add('.$dossier.')','xx','smallbutton');
+            return $js;
+        }
+}
diff --git a/include/class_html_table.php b/include/lib/class_html_table.php
similarity index 100%
rename from include/class_html_table.php
rename to include/lib/class_html_table.php
diff --git a/include/lib/class_iaction.php b/include/lib/class_iaction.php
new file mode 100644
index 0000000..e55bf3d
--- /dev/null
+++ b/include/lib/class_iaction.php
@@ -0,0 +1,61 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief Html Input show just a ref to an action
+ * create a button with a link, if you want to use a javascript
+ * value must be empty
+ */
+require_once NOALYSS_INCLUDE.'/lib/class_html_input.php';
+class IAction_deprecated extends HtmlInput
+{
+    /*!\brief show the html  input of the widget*/
+    public function input($p_name="",$p_value="")
+    {
+        $this->name=($p_name=="")?$this->name:$p_name;
+        $this->value=($p_value=="")?$this->value:$p_value;
+        $this->id=($this->id=="")?$this->name:$this->id;
+        if ( $this->readOnly==true) return $this->display();
+        $this->javascript= (!isset ($this->javascript))?"":$this->javascript;
+        if ( $this->value !="")
+            $r=sprintf('<span id="%s" class="action"> <A class="action" 
HREF="%s" %s>%s</A></span>',
+                       $this->id,
+                       $this->value,
+                       $this->javascript,
+                       $this->label);
+        else
+            $r=sprintf('<span id="%s" class="action"> <A class="action" 
href="javascript: %s">%s</A></span>',
+                       $this->id,
+                       $this->javascript,
+                       $this->label);
+
+        return $r;
+
+    }
+    /*!\brief print in html the readonly value of the widget*/
+    public function display()
+    {
+        return;
+    }
+    static public function test_me()
+    {
+    }
+}
diff --git a/include/lib/class_ianccard.php b/include/lib/class_ianccard.php
new file mode 100644
index 0000000..3ab7c2a
--- /dev/null
+++ b/include/lib/class_ianccard.php
@@ -0,0 +1,200 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief Input HTML for the card show buttons
+ *
+ */
+
+/*!
+ * \brief
+*/
+require_once NOALYSS_INCLUDE.'/lib/class_html_input.php';
+require_once NOALYSS_INCLUDE.'/lib/function_javascript.php';
+
+class IAncCard extends HtmlInput
+{
+    function __construct($name="",$value="",$p_id="")
+    {
+        parent::__construct($name,$value,$p_id);
+        $this->fct='update_value';
+        $this->dblclick='';
+        $this->callback='null';
+        $this->javascript='';
+        // the pa_id to filter
+        $this->plan=0;
+        // or the container of the Plan Analytic which contains the pa_id
+        $this->plan_ctl="";
+    }
+    /*!\brief set the javascript callback function
+     * by default it is update_value called BEFORE the querystring is send
+     * If you use the plan ctl must be set to filter_anc
+     *\param $p_name callback function name
+     */
+    function set_callback($p_name)
+    {
+        $this->callback=$p_name;
+    }
+
+    /*!\brief set the javascript callback function
+     * by default it is update_value called AFTER an item has been selected
+     *\param $p_name callback function name
+     */
+    function set_function($p_name)
+    {
+        $this->fct=$p_name;
+    }
+
+    /*!\brief set the extra javascript property for a double click on
+     *  INPUT field
+     *\param $p_action action when a double click happens
+     *\note the $p_action cannot contain a double quote
+     */
+    function set_dblclick($p_action)
+    {
+        $this->dblclick=$p_action;
+    }
+    /*!\brief show the html  input of the widget*/
+    public function input($p_name=null,$p_value=null)
+    {
+        if ( $p_name == null && $this->name == "")
+            throw (new Exception('Le nom d une icard doit être donne'));
+
+        $this->value=($p_value==null)?$this->value:$p_value;
+        if ( $this->readOnly==true) return $this->display();
+
+        $this->id=($this->id=="")?$this->name:$this->id;
+
+
+
+        $label='';
+        if ( $this->dblclick != '')
+        {
+            $e=sprintf(' ondblclick="%s" ',
+                       $this->dblclick);
+            $this->dblclick=$e;
+        }
+        $input=sprintf('<INPUT TYPE="Text"  class="input_text"  '.
+                       ' NAME="%s" ID="%s" VALUE="%s" SIZE="%d" %s %s>',
+                       $this->name,
+                       $this->name,
+                       $this->value,
+                       $this->size,
+                       $this->dblclick,
+                       $this->javascript
+                      );
+
+
+        $div=sprintf('<div id="%s_choices"  class="autocomplete"></div>',
+                     $this->name);
+        $query="op=autoanc&".dossier::get();
+
+        // add parameter to search into a plan (pa_id) or get the value from
+        // a HtmlObject
+        if ($this->plan <> 0)
+        {
+            $query.="&pa_id=".$this->plan;
+        } elseif ( $this->plan_ctl <> '')
+        {
+               $this->set_attribute("plan_ctl", $this->plan_ctl);
+        }
+        $attr=$this->get_js_attr();
+        $javascript=sprintf('try { new 
Ajax.Autocompleter("%s","%s_choices","ajax_misc.php?%s",'.
+                            '{paramName:"anccard",minChars:1,indicator:null, '.
+                            'callback:%s, '.
+                            ' afterUpdateElement:%s});} catch 
(e){alert(e.message);};',
+                            $this->name,
+                            $this->name,
+                            $query,
+                            $this->callback,
+                            $this->fct);
+
+        $javascript=create_script($javascript.$this->dblclick);
+
+        $r=$label.$input.$attr.$div.$javascript;
+        if ( $this->table == 1 )
+            $r=td($r);
+        return $r;
+
+    }
+    /*!\brief print in html the readonly value of the widget*/
+    public function display()
+    {
+        $r=sprintf('
+                    <INPUT TYPE="hidden" NAME="%s" VALUE="%s" SIZE="8">',
+                   $this->name,
+                   $this->value
+                  );
+        $r.='<span>'.$this->value.'</span>';
+        return $r;
+
+    }
+    /**
+     address@hidden return a string containing the button for displaying
+     * a search form. When clicking on the result, update the input text file
+     * the common used attribute as
+     *   - jrn   the ledger
+     *   - label the field to update
+     *   - name name of the input text
+     *   - price amount
+     *   - tvaid
+     *   - typecard (deb, cred, filter or list of value)
+     * will be set
+     * if ICard is in readOnly, the button disappears, so the return string is 
empty
+    \code
+      // search ipopup
+    $search_card=new IPopup('ipop_card');
+    $search_card->title=_('Recherche de fiche');
+    $search_card->value='';
+    echo $search_card->input();
+
+    $a=new ICard('test');
+    $a->search();
+
+    \endcode
+     *\see ajax_card.php
+     *\note the ipopup id is hard coded : ipop_card
+     address@hidden HTML string with the button
+     */
+    function search()
+    {
+        if ( $this->readOnly==true) return '';
+
+        $button=new IButton($this->name.'_bt');
+        $a="";
+        foreach (array('typecard','jrn','label','price','tvaid') as $att)
+        {
+            if (isset($this->$att) )
+                $a.="this.".$att."='".$this->$att."';";
+        }
+        if (isset($this->name))
+            $a.="this.inp='".$this->name."';";
+        $a.="this.popup='ipop_card';";
+
+        $button->javascript=$a.' search_card(this)';
+        return $button->input();
+    }
+
+    static public function test_me()
+    {
+
+    }
+}
diff --git a/include/lib/class_ibutton.php b/include/lib/class_ibutton.php
new file mode 100644
index 0000000..d8a16d6
--- /dev/null
+++ b/include/lib/class_ibutton.php
@@ -0,0 +1,118 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief Html Input
+ */
+require_once NOALYSS_INCLUDE.'/lib/class_html_input.php';
+class IButton extends HtmlInput
+{
+    var $label;
+    var $class;
+    /*!\brief show the html  input of the widget*/
+    public function input($p_name=null,$p_value=null,$p_class="")
+    {
+        $this->name=($p_name==null)?$this->name:$p_name;
+        $this->value=($p_value==null)?$this->value:$p_value;
+       $this->label=(trim($this->label) != '')?$this->label:$this->value;
+        $this->class=($p_class != "")?$p_class:$this->class;
+        $this->class=($this->class=="")?"smallbutton ":$this->class;
+        if ( $this->readOnly==true) return $this->display();
+        $extra= ( isset($this->extra))?$this->extra:"";
+        $this->id=($this->id=="")?$this->name:$this->id;
+               $tab=(isset($this->tabindex))?' 
tabindex="'.$this->tabindex.'"':"";
+        $r='<input type="BUTTON" name="'.$this->name.'"'.
+           ' class="'.$this->class.'" '.
+                $this->extra.
+                               $tab.
+           ' id="'.$this->id.'"'.
+           ' value="'.$this->label.'"'.
+           ' onClick="'.$this->javascript.'"'.$extra.'>';
+        $attr=$this->get_js_attr();
+        $r.=$attr;
+        return $r;
+
+    }
+
+    /*!\brief print in html the readonly value of the widget*/
+    public function display()
+    {
+        return "";
+    }
+    static function tooggle_checkbox($p_form)
+    {
+        $select_all=new IButton('select_all');
+        $select_all->label=_('Inverser la sélection');
+        $select_all->javascript="toggle_checkbox('$p_form')";
+        return $select_all->input();
+    }
+    static function select_checkbox($p_form)
+    {
+        $select_all=new IButton('select_all');
+        $select_all->label=_('Cocher tous');
+        $select_all->javascript="select_checkbox('$p_form')";
+        return $select_all->input();
+    }
+    static function unselect_checkbox($p_form)
+    {
+        $select_all=new IButton('select_all');
+        $select_all->label=_('Décocher tous');
+        $select_all->javascript="unselect_checkbox('$p_form')";
+        return $select_all->input();
+    }
+    static function show_calc()
+    {
+        $calc=new IButton('shcalc');
+        $calc->label=_('Calculatrice');
+        $calc->javascript="show_calc()";
+        return $calc->input();
+
+    }
+    static public function test_me()
+    {
+    }
+}
+class ISmallButton extends IButton
+{
+    var $label;
+    /*!\brief show the html  input of the widget*/
+    public function input($p_name=null,$p_value=null,$p_style=null)
+    {
+        $this->name=($p_name==null)?$this->name:$p_name;
+        $this->value=($p_value==null)?$this->value:$p_value;
+               $this->label=(trim($this->label) != 
'')?$this->label:$this->value;
+        if ( $this->readOnly==true) return $this->display();
+        $extra= ( isset($this->extra))?$this->extra:"";
+        $this->id=($this->id=="")?$this->name:$this->id;
+               $tab=(isset($this->tabindex))?' 
tabindex="'.$this->tabindex.'"':"";
+        $r='<input type="BUTTON" name="'.$this->name.'"'.
+           ' class="smallbutton" '.
+                $this->extra.
+                               $tab.
+           ' id="'.$this->id.'"'.
+           ' value="'.$this->label.'"'.
+           ' onClick="'.$this->javascript.'"'.$extra.'>';
+        $attr=$this->get_js_attr();
+        $r.=$attr;
+        return $r;
+
+    }
+}
\ No newline at end of file
diff --git a/include/lib/class_icard.php b/include/lib/class_icard.php
new file mode 100644
index 0000000..437f150
--- /dev/null
+++ b/include/lib/class_icard.php
@@ -0,0 +1,394 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief Input HTML for the card show buttons
+ *
+ */
+
+/*!
+ * \brief Input HTML for the card show buttons, in the file, you have to add 
card.js
+ * How to use :
+ * - label is the label in the button
+ * - extra contents the type (all, deb or cred, a list of FD_ID between 
parent.  or a SQL clause
+ * - attribute are the attribute to set (via ajax). The ledger is either a 
attribute (jrn) or a
+ *  hidden field in the document, if none are set, there is no filter on the 
ledger
+ *\note you must in a hidden field gDossier (dossier::hidden)
+ *\see ajaxFid
+ *\see card.js
+ *\see fid.php
+ *\see fid_card.php
+ *\see ajax_card.php
+ *
+ * Set the hidden field or input field to be set by javascript with the 
function set_attribute
+ * call the input method. After selecting a value the update_value function is 
called. If you need
+ * to modify the queryString before the request is sent, you'll use the 
set_callback; the first
+ * parameter is the INPUT field and the second the queryString, the function 
must returns a
+ * queryString
+ *\code
+// insert all the javascript files
+  echo js_include('prototype.js');
+  echo js_include('scriptaculous.js');
+  echo js_include('effects.js');
+  echo js_include('controls.js');
+
+//
+  $W1=new ICard();
+  $W1->label="Client ".HtmlInput::infobulle(0) ;
+  $W1->name="e_client";
+  $W1->tabindex=3;
+  $W1->value=$e_client;
+  $W1->table=0;
+// If double click call the javascript fill_ipopcard
+  $W1->set_dblclick("fill_ipopcard(this);");
+
+  // Type of card : deb, cred or all
+  $W1->set_attribute('typecard','deb');
+
+  $W1->extra='deb';
+
+// Add the callback function to filter the card on the jrn
+  $W1->set_callback('filter_card');
+
+// when value selected in the autcomplete
+  $W1->set_function('fill_data');
+
+// when the data change
+  $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
+           $W1->name);
+
+ // name of the field to update with the name of the card
+  $W1->set_attribute('label','e_client_label');
+  $client_label=new ISpan();
+  $client_label->table=0;
+  $f_client=$client_label->input("e_client_label",$e_client_label);
+
+  $f_client_qcode=$W1->input();
+
+// Search button for card
+  $f_client_bt=$W1->search();
+* \endcode
+For searching a card, you need a popup, the script card.js and set
+the values for card, popup filter_card callback
address@hidden
+$card=new ICard('acc');
+$card->name="acc";
+$card->extra="all";
+$card->set_attribute('typecard','all');
+$card->set_callback('filter_card');
+
+echo $card->input();
+echo $card->search();
+// example 2
+$w=new ICard("av_text".$attr->ad_id);
+// filter on frd_id
+$sql=' select fd_id from fiche_def where frd_id in 
('.FICHE_TYPE_CLIENT.','.FICHE_TYPE_FOURNISSEUR.','.FICHE_TYPE_ADM_TAX.')';
+$filter=$this->cn->make_list($sql);
+$w->set_attribute('ipopup','ipopcard');
+$w->set_attribute('typecard',$filter);
+$w->set_attribute('inp',"av_text".$attr->ad_id);
+$w->set_attribute('label',"av_text".$attr->ad_id."_label");
+
+$w->extra=$filter;
+$w->extra2=0;
+$label=new ISpan();
+$label->name="av_text".$attr->ad_id."_label";
+$msg.=td($w->search().$label->input());
address@hidden
+*/
+require_once NOALYSS_INCLUDE.'/lib/class_html_input.php';
+require_once NOALYSS_INCLUDE.'/lib/function_javascript.php';
+
+class ICard extends HtmlInput
+{
+    function __construct($name="",$value="",$p_id="")
+    {
+        parent::__construct($name,$value);
+        $this->fct='update_value';
+        $this->dblclick='';
+        $this->callback='null';
+        $this->javascript='';
+       $this->id=($p_id != "")?$p_id:$name;
+        $this->choice=null;
+        $this->indicator=null;
+        $this->choice_create=1;
+       $this->autocomplete=1;
+        $this->style=' style="vertical-align:50%"';
+    }
+    /*!\brief set the javascript callback function
+     * by default it is update_value called BEFORE the querystring is send
+     *
+     *\param $p_name callback function name
+     */
+    function set_callback($p_name)
+    {
+        $this->callback=$p_name;
+    }
+
+    /*!\brief set the javascript callback function
+     * by default it is update_value called AFTER an item has been selected
+     *\param $p_name callback function name
+     */
+    function set_function($p_name)
+    {
+        $this->fct=$p_name;
+    }
+    /*!\brief return the html string for creating the ipopup, this ipopup
+     * can be used for adding, modifying or display a card
+     address@hidden ipopup is obsolete, the popin is created by javascript
+     *\param $p_name name of the ipopup, must be set after with set_attribute
+    \code
+      $f_add_button=new IButton('add_card');
+      $f_add_button->label='Créer une nouvelle fiche';
+      $f_add_button->set_attribute('ipopup','ipop_newcard');
+      $f_add_button->set_attribute('filter',$this->get_all_fiche_def ());
+      $f_add_button->javascript=" select_card_type(this);";
+      $str_add_button=$f_add_button->input();
+
+    \endcode
+     *\return html string
+     *\note must be one of first instruction on a new page, to avoid problem
+     * of position with IE
+     */
+    static function ipopup($p_name)
+    {
+        $ip_card=new IPopup ($p_name);
+        $ip_card->drag=true;
+               $ip_card->set_width('45%');
+        $ip_card->title='Fiche ';
+        $ip_card->value='';
+        
+        return $ip_card->input();
+    }
+    /*!\brief set the extra javascript property for a double click on
+     *  INPUT field
+     *\param $p_action action when a double click happens
+     *\note the $p_action cannot contain a double quote
+     */
+    function set_dblclick($p_action)
+    {
+        $this->dblclick=$p_action;
+    }
+    /*!\brief show the html  input of the widget*/
+    public function input($p_name=null,$p_value=null)
+    {
+        if ( $p_name == null && $this->name == "")
+            throw (new Exception('Le nom d une icard doit être donne'));
+
+        $this->value=($p_value==null)?$this->value:$p_value;
+        if ( $this->readOnly==true) return $this->display();
+
+                $this->id=($this->id=="")?$this->name:$this->id;
+        
$this->choice=($this->choice==null)?sprintf("%s_choices",$this->id):$this->choice;
+        
$this->indicator=($this->indicator==null)?sprintf("%s_ind",$this->id):$this->indicator;
+        $attr=$this->get_js_attr();
+
+        $label='';
+        if ( $this->dblclick != '')
+        {
+            $e=sprintf(' ondblclick="%s" ',
+                       $this->dblclick);
+            $this->dblclick=$e;
+        }
+        $input=sprintf('<INPUT TYPE="Text"  class="input_text"  '.
+                       ' NAME="%s" ID="%s" VALUE="%s" SIZE="%d" %s %s  %s>',
+                       $this->name,
+                       $this->id,
+                       $this->value,
+                       $this->size,
+                       $this->dblclick,
+                       $this->javascript,
+                       $this->style
+                      );
+               if ( $this->autocomplete == 1)
+               {
+                    $this->indicator="ind_".$this->id;
+                       $ind=sprintf('<span id="%s" class="autocomplete" 
style="position:absolute;display:none">Un instant... <img 
src="image/loading.gif" alt="Chargement..."/>'.
+                                               '</span>',
+                                               $this->indicator);
+                        $this->indicator="null";
+                       $div=($this->choice_create == 1) ? sprintf('<div 
id="%s"  class="autocomplete"></div>',$this->choice):"";
+
+                       $query=dossier::get().'&e='.urlencode($this->typecard);
+
+                       $javascript=sprintf('try { new 
Ajax.Autocompleter("%s","%s","fid_card.php?%s",'.
+                                                               
'{paramName:"FID",minChars:1,indicator:%s, '.
+                                                               'callback:%s, '.
+                                                               ' 
afterUpdateElement:%s});} catch (e){alert(e.message);};',
+                                                               $this->id,
+                                                                $this->choice,
+                                                                $query,
+                                                               
$this->indicator,
+                                                               $this->callback,
+                                                               $this->fct);
+
+                       $javascript=create_script($javascript.$this->dblclick);
+
+                       $r=$label.$input.$attr.$ind.$div.$javascript;
+               }
+               else
+               {
+                       $r=$label.$input;
+               }
+        if ( $this->table == 1 )
+            $r=td($r);
+        return $r;
+
+    }
+    /*!\brief print in html the readonly value of the widget*/
+    public function display()
+    {
+        $r=sprintf('         <INPUT TYPE="hidden" NAME="%s" id="%s" VALUE="%s" 
SIZE="8">',
+                   $this->name,
+                   $this->name,
+                   $this->value
+                  );
+        $r.='<span>'.$this->value.'</span>';
+        return $r;
+
+    }
+    /**
+     address@hidden return a string containing the button for displaying
+     * a search form. When clicking on the result, update the input text file
+     * the common used attribute as
+     *   - jrn   the ledger
+     *   - label the field to update
+     *   - name name of the input text
+     *   - price amount
+     *   - tvaid
+     *   - typecard (deb, cred, filter or list of value)
+     * will be set
+     * if ICard is in readOnly, the button disappears, so the return string is 
empty
+    \code
+      // search ipopup
+    $search_card=new IPopup('ipop_card');
+    $search_card->title=_('Recherche de fiche');
+    $search_card->value='';
+    echo $search_card->input();
+
+    $a=new ICard('test');
+    $a->search();
+
+    \endcode
+     *\see ajax_card.php
+     *\note the ipopup id is hard coded : ipop_card
+     address@hidden HTML string with the button
+     */
+    function search()
+    {
+        if ( $this->readOnly==true) return '';
+               if ( ! isset($this->id )) $this->id=$this->name;
+        $a="";
+        foreach (array('typecard','jrn','label','price','tvaid') as $att)
+        {
+            if (isset($this->$att) )
+                $a.="this.".$att."='".$this->$att."';";
+        }
+        if (isset($this->id) && $this->id != "")
+            $a.="this.inp='".$this->id."';";
+               else
+            $a.="this.inp='".$this->name."';";
+        $a.="this.popup='ipop_card';";
+        $javascript=$a.' search_card(this);return false;';
+        
+        $button=HtmlInput::button_image($javascript,$this->name."_bt", 
'alt="'._('Recherche').'" class="image_search"',"image/magnifier13.png");
+        return $button;
+    }
+
+    static public function test_me()
+    {
+        require_once NOALYSS_INCLUDE.'/lib/class_itext.php';
+        $_SESSION['isValid']=1;
+        $a=new ICard('testme');
+        $a->extra="all";
+        $a->set_attribute('label','ctl_label');
+        $a->set_attribute('tvaid','ctl_tvaid');
+        $a->set_attribute('price','ctl_price');
+        $a->set_attribute('purchase','ctl_purchase');
+        $a->set_attribute('type','all');
+        echo <<<EOF
+         <div id="debug" style="border:solid 1px black;overflow:auto"></div>
+         <script type="text/javascript" language="javascript"  
src="js/prototype.js">
+         </script>
+         <script type="text/javascript" language="javascript"  
src="js/scriptaculous.js">
+         </script>
+         <script type="text/javascript" language="javascript"  
src="js/effects.js">
+         </script>
+         <script type="text/javascript" language="javascript"  
src="js/controls.js">
+         </script>
+         <script type="text/javascript" language="javascript"  
src="js/ajax_fid.js">
+         </script>
+         <script type="text/javascript" language="javascript"  >
+         function test_value(text,li)
+         {
+           alert("premier"+li.id);
+
+           str="";
+           str=text.id+'<hr>';
+           if ( text.js_attr1)
+             {
+               str+=text.js_attr1;
+               str+='<hr>';
+             }
+           if ( text.js_attr2)
+             {
+               str+=text.js_attr2;
+               str+='<hr>';
+             }
+           if ( text.js_attr3)
+             {
+               str+=text.js_attr3;
+               str+='<hr>';
+             }
+           for (var i in text)
+             {
+               str+=i+'<br>';
+             }
+
+           // $('debug').innerHTML=str;
+           ajaxFid(text);
+         }
+       </script>
+
+EOF;
+        echo "<form>";
+        $l=new IText('ctl_label');
+        $t=new IText('ctl_tvaid');
+        $p=new IText('ctl_price');
+        $b=new IText('ctl_purchase');
+
+        echo "Label ".$l->input().'<br>';
+        echo "Tva id  ".$t->input().'<br>';
+        echo "Price ".$p->input().'<br>';
+        echo "Purchase ".$b->input().'<br>';
+
+        if ( isset($_REQUEST['test_select']) )
+            echo HtmlInput::hidden('test_select',$_REQUEST['test_select']);
+        $a->set_function('test_value');
+        $a->javascript=' onchange="alert(\'onchange\');" 
onblur="alert(\'onblur\');" ';
+        echo $a->input();
+        echo dossier::hidden();
+        echo HtmlInput::submit('Entree','entree');
+        echo '</form>';
+        echo <<<EOF
+EOF;
+    }
+}
diff --git a/include/lib/class_icheckbox.php b/include/lib/class_icheckbox.php
new file mode 100644
index 0000000..a896e2d
--- /dev/null
+++ b/include/lib/class_icheckbox.php
@@ -0,0 +1,74 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief Html Input
+ */
+require_once NOALYSS_INCLUDE.'/lib/class_html_input.php';
+class ICheckBox extends HtmlInput
+{
+    /*!\brief show the html  input of the widget*/
+    public function input($p_name=null,$p_value=null)
+    {
+        $this->name=($p_name==null)?$this->name:$p_name;
+        $this->value=($p_value==null)?$this->value:$p_value;
+        if ( $this->readOnly==true) return $this->display();
+                $this->id=($this->id=="")?$this->name:$this->id;
+
+        $check=( $this->selected==true )?"checked":"unchecked";
+        $r='<input type="CHECKBOX" id="'.$this->id.'" 
name="'.$this->name.'"'.' value="'.$this->value.'"';
+        $r.="  $check";
+        $r.=' '.$this->disabled."  ".$this->javascript.'>';
+
+        $r=$r." $this->label";
+
+        return $r;
+
+
+    }
+    /*!\brief print in html the readonly value of the widget*/
+    public function display()
+    {
+        $check=( $this->selected==true )?"checked":"unchecked";
+        $r='<input type="CHECKBOX" id="'.$this->name.'" 
name="'.$this->name.'"';
+        $r.="  $check";
+        $r.=' disabled>';
+
+        return $r;
+
+    }
+    /**
+     *set selected to true (checked) if the value equal the parameter
+     * @param $p_value value to compare
+     */
+    public function set_check($p_value)
+        {
+        if ($this->value==$p_value)$this->selected=true;
+        }
+    static function toggle_checkbox($p_name,$p_form) {
+            $a=new ICheckBox($p_name);
+            $a->javascript='onclick="toggle_checkbox(\''.$p_form.'\')"';
+            return $a->input();
+        }
+    static public function test_me()
+    {
+    }
+}
diff --git a/include/lib/class_iconcerned.php b/include/lib/class_iconcerned.php
new file mode 100644
index 0000000..429ca9e
--- /dev/null
+++ b/include/lib/class_iconcerned.php
@@ -0,0 +1,80 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief Html Input
+ *  - name is the name and id of the input
+ *  - extra amount of the operation to reconcile
+ *  - extra2 ledger paid
+ */
+require_once NOALYSS_INCLUDE.'/lib/class_html_input.php';
+class IConcerned extends HtmlInput
+{
+
+       public function __construct($p_name='',$p_value='',$p_id="")
+       {
+               $this->name=$p_name;
+               $this->value=$p_value;
+               $this->amount_id=null;
+               $this->paid='';
+               $this->id=$p_id;
+                $this->tiers=""; // id of the field for the tiers to be updated
+       }
+    /*!\brief show the html  input of the widget*/
+    public function input($p_name=null,$p_value=null)
+    {
+        $this->name=($p_name==null)?$this->name:$p_name;
+        $this->value=($p_value==null)?$this->value:$p_value;
+        if ( $this->readOnly==true) return $this->display();
+
+           $this->id=($this->id=="")?$this->name:$this->id;
+
+
+        $r=sprintf("
+                    <image 
onclick=\"search_reconcile(".dossier::id().",'%s','%s','%s','%s')\" 
class=\"image_search\" src=\"image/magnifier13.png\" />
+                   
+                   <INPUT TYPE=\"text\"  
style=\"color:black;background:lightyellow;border:solid 1px grey;\"  
NAME=\"%s\" ID=\"%s\" VALUE=\"%s\" SIZE=\"8\" readonly>
+                                  <INPUT class=\"smallbutton\"  
TYPE=\"button\" onClick=\"$('%s').value=''\" value=\"X\">
+
+                   ",
+                   $this->name,
+                   $this->amount_id,
+                   $this->paid,
+                   $this->tiers,
+                   $this->name,
+                   $this->id,
+                   $this->value,
+                   $this->id
+                  );
+        return $r;
+    }
+    /*!\brief print in html the readonly value of the widget*/
+    public function display()
+    {
+        $r=sprintf("<span><b>%s</b></span>",$this->value);
+        $r.=sprintf('<input type="hidden" name="%s" value="%s">', 
$this->name,$this->value);
+        return $r;
+
+    }
+    static public function test_me()
+    {
+    }
+}
diff --git a/include/lib/class_idate.php b/include/lib/class_idate.php
new file mode 100644
index 0000000..a0bf95b
--- /dev/null
+++ b/include/lib/class_idate.php
@@ -0,0 +1,71 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief Html Input
+ */
+require_once NOALYSS_INCLUDE.'/lib/class_html_input.php';
+class IDate extends HtmlInput
+{
+    /*!\brief show the html  input of the widget*/
+    public function input($p_name=null,$p_value=null)
+    {
+        $this->name=($p_name==null)?$this->name:$p_name;
+        $this->value=($p_value==null)?$this->value:$p_value;
+        if ( $this->readOnly==true) return $this->display();
+       if( $this->id=="")
+         $this->id=self::generate_id($this->name);
+        $r='<input type="text" name="'.$this->name.'" id="'.$this->id.'" '.
+           ' class="input_text" '.
+           'size="10" style="width:6em" '.
+           ' value ="'.$this->value.'" '.
+           '/>'.
+           '<img src="image/x-office-calendar.png" id="'.$this->id.'_trigger"'.
+           ' style="cursor: pointer" '.
+           'onmouseover="this.style.background=\'red\';" 
onmouseout="this.style.background=\'\'" />';
+        $r.='<script type="text/javascript">'.
+            'Calendar.setup({'.
+            // 'date : "'.$this->value.'",
+            'inputField     :    "'.$this->id.'",     // id of the input field
+            ifFormat       :    "%d.%m.%Y",      // format of the input field
+            button         :    "'.$this->id.'_trigger",  // trigger for the 
calendar (button ID)
+            align          :    "Bl",           // alignment (defaults to "Bl")
+            singleClick    :    true
+        });
+            </script>
+            ';
+        return $r;
+
+    }
+    /*!\brief print in html the readonly value of the widget*/
+    public function display()
+    {
+        $r="<span>  : ".$this->value;
+        $r.='<input type="hidden" name="'.$this->name.'"'.
+            'id="'.$this->name.'"'.
+            ' value = "'.$this->value.'"></span>';
+        return $r;
+
+    }
+    static public function test_me()
+    {
+    }
+}
diff --git a/include/lib/class_ifile.php b/include/lib/class_ifile.php
new file mode 100644
index 0000000..0633df1
--- /dev/null
+++ b/include/lib/class_ifile.php
@@ -0,0 +1,46 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief Html Input 
+ */
+require_once NOALYSS_INCLUDE.'/lib/class_html_input.php';
+class IFile extends HtmlInput
+{
+    /*!\brief show the html  input of the widget*/
+    public function input($p_name=null,$p_value=null)
+    {
+        $this->name=($p_name==null)?$this->name:$p_name;
+        $this->value=($p_value==null)?$this->value:$p_value;
+        if ( $this->readOnly==true) return $this->display();
+        $r='<INPUT class="inp" TYPE="file" name="'.$this->name.'" 
VALUE="'.$this->value.'">';
+        return $r;
+
+    }
+    /*!\brief print in html the readonly value of the widget*/
+    public function display()
+    {
+
+    }
+    static public function test_me()
+    {
+    }
+}
diff --git a/include/lib/class_ihidden.php b/include/lib/class_ihidden.php
new file mode 100644
index 0000000..a2165bc
--- /dev/null
+++ b/include/lib/class_ihidden.php
@@ -0,0 +1,42 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief Html Input
+ */
+require_once NOALYSS_INCLUDE.'/lib/class_html_input.php';
+class IHidden extends HtmlInput
+{
+    /*!\brief show the html  input of the widget*/
+    public function input($p_name=null,$p_value=null)
+    {
+        $this->name=($p_name==null)?$this->name:$p_name;
+        $this->value=($p_value==null)?$this->value:$p_value;
+               $this->id=($this->id=="")?$this->name:$this->id;
+
+        $r='<INPUT TYPE="HIDDEN" id="'.$this->id.'" name="'.$this->name.'" 
value="'.$this->value.'">';
+        return $r;
+
+    }
+    static public function test_me()
+    {
+    }
+}
diff --git a/include/lib/class_impress.php b/include/lib/class_impress.php
new file mode 100644
index 0000000..fc016e2
--- /dev/null
+++ b/include/lib/class_impress.php
@@ -0,0 +1,293 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+/*!\file
+ * \brief contains function for the printing
+*/
+require_once NOALYSS_INCLUDE.'/class/class_periode.php';
+
+
+class Impress
+{
+    /*! \brief   Purpose Parse a formula
+     *
+     * \param $p_cn connexion
+     * \param $p_label
+     * \param $p_formula
+     * \param $p_eval  true if we eval here otherwise the function returns
+     *                 a string which must be evaluated
+     * \param $p_type_date : type of the date 0 for accountant period or 1
+     * for calendar
+     * \return array
+     *
+     *
+     */
+    static function 
parse_formula($p_cn,$p_label,$p_formula,$p_start,$p_end,$p_eval=true,$p_type_date=0,$p_sql="")
+    {
+        global $g_user;
+        if ( Impress::check_formula($p_formula) == false)
+        {
+            if ( $p_eval == true)
+                return array('desc'=>$p_label.'  Erreur Formule!',
+                             'montant'=>0);
+            else
+                return $p_formula;
+
+        }
+        if ( $p_type_date == 0 )
+            $cond=sql_filter_per($p_cn,$p_start,$p_end,'p_id','j_tech_per');
+        else
+            $cond="( j_date >= to_date('$p_start','DD.MM.YYYY') and j_date <= 
to_date('$p_end','DD.MM.YYYY'))";
+
+        include_once("class/class_acc_account_ledger.php");
+
+        while (preg_match_all("(\[[0-9]*[A-Z]*%*c*d*s*\])",$p_formula,$e) == 
true)
+          {
+
+            // remove the [ ]
+            $x=$e[0];
+            foreach ($x as $line)
+              {
+                $compute='all';
+                if ( strpos($line,'d') != 0 )
+                  $compute='deb';
+                if ( strpos($line,'c') != 0 )
+                  $compute='cred';
+                if ( strpos($line,'s') != 0 )
+                  $compute='signed';
+                $line=str_replace ("[","",$line);
+                $line=str_replace ("]","",$line);
+                $line=str_replace ("d","",$line);
+                $line=str_replace ("c","",$line);
+                $line=str_replace ("s","",$line);
+                // If there is a FROM clause we must recompute
+                // the time cond
+
+                if ($p_type_date == 0 && preg_match ("/FROM=[0-9]+\.[0-9]+/", 
$p_formula,$afrom) == 1 )
+                  {
+                    // There is a FROM clause
+                    // then we must modify the cond for the periode
+                    $from=str_replace("FROM=","",$afrom[0]);
+
+                    // Get the periode
+                    /*! \note special value for the clause FROM=00.0000
+                     */
+                    if ( $from == '00.0000' )
+                      {
+
+                        // retrieve the first month of this periode
+                        $user_periode=$g_user->get_periode();
+                        $oPeriode=new Periode($p_cn);
+                        $periode=$oPeriode->get_exercice($user_periode);
+                        list($first,$last)=$oPeriode->get_limit($periode);
+                        $ret=$first->get_date_limit();
+                        $end_date=$oPeriode->get_date_limit($p_end);
+                        if ($ret == null ) throw new Exception ('Pas de limite 
à cette période',1);
+                        
$cond=sql_filter_per($p_cn,$ret['p_start'],$end_date['p_end'],'date','j_tech_per');
+
+
+                      }
+                    else
+                      {
+                        $oPeriode=new Periode($p_cn);
+                        try
+                          {
+                            $pfrom=$oPeriode->find_periode('01.'.$from);
+                            $cond=  sql_filter_per($p_cn, $pfrom, 
$p_end,'p_id','j_tech_per');
+                          }
+                        catch (Exception $exp)
+                          {
+                            /* if none periode is found
+                               then we take the first periode of the year
+                            */
+                            $user_periode=$g_user->get_periode();
+
+                            $year=$oPeriode->get_exercice($user_periode);
+                            list($first,$last)=$oPeriode->get_limit($year);
+                            $ret=$first->get_date_limit();
+                            $end_date=$oPeriode->get_date_limit($p_end);
+                            if ($ret == null ) throw new Exception ('Pas de 
limite à cette période',1);
+                            
$cond=sql_filter_per($p_cn,$ret['p_start'],$end_date['p_end'],'date','j_tech_per');
+                          }
+                      }
+                  }
+
+                if ( strpos($p_formula,"FROM") != 0)
+                  {
+                    // We remove FROM out of the p_formula
+                    
$p_formula=substr_replace($p_formula,"",strpos($p_formula,"FROM"));
+                  }
+
+                // Get sum of account
+                $P=new Acc_Account_Ledger($p_cn,$line);
+                $detail=$P->get_solde_detail($cond.$p_sql);
+
+
+                if ( $compute=='all')
+                  $i=$detail['solde'];
+                if ( $compute=='deb')
+                  $i=$detail['debit'];
+                if ( $compute=='cred')
+                  $i=$detail['credit'];
+                if ( $compute=='signed')
+                  $i=$detail['debit']-$detail['credit'];
+                $p_formula=str_replace($x[0],$i,$p_formula);
+              }
+          }
+
+        // $p_eval is true then we eval and returns result
+        if ( $p_eval == true)
+        {
+            $p_formula="\$result=".$p_formula.";";
+            eval("$p_formula");
+
+            while (preg_match("/\[([0-9]+)([Tt]*)\]/",trim($p_label),$e) == 1)
+            {
+                $nom = "!!".$e[1]."!!";
+                if (Impress::check_formula($e[0]))
+                {
+                    $nom = $p_cn->get_value ( "SELECT pcm_lib AS acct_name 
FROM tmp_pcmn WHERE pcm_val::text LIKE $1||'%' ORDER BY pcm_val ASC LIMIT 
1",array($e[1]));
+                    if($nom)
+                    {
+                        if($e[2] == 'T') $nom = strtoupper($nom);
+                        if($e[2] == 't') $nom = strtolower($nom);
+                    }
+                }
+                $p_label = str_replace($e[0], $nom, $p_label);
+            }
+
+            $aret=array('desc'=>$p_label,
+                        'montant'=>$result);
+            return $aret;
+        }
+        else
+        {
+            // $p_eval is false we returns only the string
+            return $p_formula;
+        }
+    }
+    /*!
+     * \brief  Check if formula doesn't contain
+     *           php injection
+     * \param string
+     *
+     * \return true if the formula is good otherwise false
+     */
+    static function check_formula($p_string)
+    {
+        // the preg_match gets too complex if we want to add a test
+        // for parenthesis, math function...
+        // So I prefer remove them before testing
+        $p_string=str_replace("round","",$p_string);
+        $p_string=str_replace("abs","",$p_string);
+        $p_string=str_replace("(","",$p_string);
+        $p_string=str_replace(")","",$p_string);
+        // for  the inline test like $a=(cond)?value:other;
+        $p_string=str_replace("?","+",$p_string);
+        $p_string=str_replace(":","+",$p_string);
+        $p_string=str_replace(">=","+",$p_string);
+        $p_string=str_replace("<=","+",$p_string);
+        $p_string=str_replace(">","+",$p_string);
+        $p_string=str_replace("<","+",$p_string);
+        // eat Space + comma
+        $p_string=str_replace(" ","",$p_string);
+        $p_string=str_replace(",","",$p_string);
+        // Remove D/C/S
+        $p_string=str_replace("c","",$p_string);
+        $p_string=str_replace("d","",$p_string);
+        $p_string=str_replace("s","",$p_string);
+        // Remove T,t
+        $p_string=str_replace("t","",$p_string);
+
+               // remove date
+               $p_string=  preg_replace("/FROM*=*[0-9]+/", "", $p_string);
+               // remove comment
+               $p_string=  preg_replace("/#.*/", "", $p_string);
+               // remove $C=
+               $p_string=  preg_replace('/\$[a-z]*[A-Z]*[0-9]*[A-Z]*[a-z]*/', 
"", $p_string);
+               $p_string=  preg_replace('/=/', "", $p_string);
+
+               // remove account
+               $p_string=  preg_replace("/\[[0-9]*[A-Z]*%*\]/", "", $p_string);
+
+               $p_string=  preg_replace("/\+|-|\/|\*/", "", $p_string);
+               $p_string=  preg_replace("/[0-9]*\.*[0-9]/", "", $p_string);
+
+               
//********************************************************************************************************************
+               // If the string is empty then formula should be good
+               //
+               
//********************************************************************************************************************
+               if ($p_string == '')
+        {
+            return true;
+        }
+        else
+        {
+            return false;
+        }
+    }
+     /**
+     * with the handle of a successull query, echo each row into CSV and
+     * send it directly
+     * @param type $array of data
+     * @param type $aheader  double array, each item of the array contains
+     * a key type (num) and a key title
+     */
+    static function array_to_csv($array,$aheader)
+    {
+        $seq="";
+        for ($i=0;$i<count($aheader);$i++)
+        {
+            echo $seq.'"'.$aheader[$i]['title'].'"';
+            $seq=";";
+        }
+        printf("\r");
+
+        $seq="";
+        // fetch all the rows
+        for ($i=0;$i<count($array);$i++)
+        {
+            $row=$array[$i];
+            $sep2="";
+                       $e=0;
+            // for each rows, for each value
+            foreach ($array[$i] as $key=>$value)
+            {
+                               if ($e > count($aheader)) $e=0;
+
+                               if ( isset ($aheader[$e]['type']))
+                               {
+                                       switch ($aheader[$e]['type'])
+                                       {
+                                               case 'num':
+                                                       echo $sep2.nb($value);
+                                                       break;
+                                               default:
+                                                       echo 
$sep2.'"'.$value.'"';
+                                       }
+                               } else {
+                                       echo '"'.$value.'"'.$sep2;
+                               }
+                $sep2=";";$e++;
+            }
+            printf("\r");
+        }
+    }
+}
\ No newline at end of file
diff --git a/include/lib/class_inum.php b/include/lib/class_inum.php
new file mode 100644
index 0000000..adde9fb
--- /dev/null
+++ b/include/lib/class_inum.php
@@ -0,0 +1,111 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief for the numeric input text field
+ */
+require_once NOALYSS_INCLUDE.'/lib/class_itext.php';
+/*!\brief
+ * This class handles only the numeric input, the input will
+ * call a javascript
+ * to change comma to period  and will round it (2 decimal), the precision is 
given by
+ * the attribute prec
+ * attribute
+ *  extra = extra code (free)
+ *  size = size of the field
+ *  prec = precision default = 2
+ *  name = name of the html object
+ *  javascript = javascript to execute (default = 
onchange="format_number(this,2);)
+ *  value = value of the widget
+ *
+ */
+class INum extends IText
+{
+    function __construct($name='',$value='')
+    {
+        parent::__construct($name,$value);
+
+        $this->size=9;
+        $this->style='class="inum"';
+       $this->javascript= 'onchange="format_number(this,2);"';
+    }
+    /*!\brief print in html the readonly value of the widget*/
+    public function display()
+    {
+
+        $readonly=" readonly ";
+               $this->id=($this->id=="")?$this->name:$this->id;
+
+        //$style='style="border:solid 1px 
blue;color:black;background:#EDEDED;text-align:right"';
+        $style=' class="inum input_text_ro"';
+        $this->value=str_replace('"','',$this->value);
+        $r='<INPUT '.$style.' TYPE="TEXT" id="'.
+           $this->id.'"'.
+           'NAME="'.$this->name.'" VALUE="'.$this->value.'"  '.
+           'SIZE="'.$this->size.'" '.$this->javascript." $readonly 
$this->extra >";
+
+        /* add tag for column if inside a table */
+        if ( $this->table == 1 )                 $r='<td>'.$r.'</td>';
+
+        return $r;
+
+    }
+        /*!\brief show the html  input of the widget*/
+    public function input($p_name=null,$p_value=null)
+    {
+               if ( isset ($this->prec)) {
+                       $this->javascript= 
'onchange="format_number(this,'.$this->prec.');"';
+               }
+        $this->name=($p_name==null)?$this->name:$p_name;
+        $this->value=($p_value==null)?$this->value:$p_value;
+               $this->id=($this->id=="")?$this->name:$this->id;
+
+        if ( $this->readOnly==true) return $this->display();
+
+        $t= ((isset($this->title)))?'title="'.$this->title.'"   ':' ';
+
+        $extra=(isset($this->extra))?$this->extra:"";
+
+        $this->value=str_replace('"','',$this->value);
+        if ( ! isset ($this->css_size))
+        {
+        $r='<INPUT '.$this->style.' TYPE="TEXT" id="'.
+           $this->id.'"'.$t.
+           'NAME="'.$this->name.'" VALUE="'.$this->value.'"  '.
+           'SIZE="'.$this->size.'" '.$this->javascript."  $this->extra >";
+        /* add tag for column if inside a table */
+        } else {
+           $r='<INPUT '.$this->style.' TYPE="TEXT" id="'.
+           $this->id.'"'.$t.
+           'NAME="'.$this->name.'" VALUE="'.$this->value.'"  '.
+           ' style="width:'.$this->css_size.';" '.$this->javascript."  
$this->extra >";
+
+        }
+
+        if ( $this->table == 1 )                 $r='<td>'.$r.'</td>';
+
+        return $r;
+
+    }
+
+}
+
+
diff --git a/include/lib/class_iperiod.php b/include/lib/class_iperiod.php
new file mode 100644
index 0000000..9852c89
--- /dev/null
+++ b/include/lib/class_iperiod.php
@@ -0,0 +1,171 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief Html Input
+ */
+/*! \brief          Generate the form for the periode
+* Data Members
+ *   - $cn connexion to the current folder
+ *   - $type the type of the periode OPEN CLOSE NOTCENTRALIZED or ALL, IT MUST 
BE SET
+ *   - $filter_year make a filter on the default exercice by default true
+ *   - $user if a filter_year is required then we need who is the user (object 
User)
+ *   - $show_end_date; $show_end_date is not set or false, do not show the end 
date  default = true
+ *   - $show_start_date; $show_start_date is not set or false, do not show the 
start date  default=true
+*/
+require_once NOALYSS_INCLUDE.'/lib/class_html_input.php';
+class IPeriod extends HtmlInput
+{
+    var $type; /*!< $type the type of the periode OPEN CLOSE NOTCENTRALIZED or 
ALL */
+    var $cn;  /*!< $cn is the database connection */
+    var $show_end_date; /*!< $show_end_date is not set or false, do not show 
the end date */
+    var $show_start_date; /*!< $show_start_date is not set or false, do not 
show the start date */
+    var $filter_year; /*!< $filter_year make a filter on the default exercice 
by default yes */
+    var $user;  /*! $user if a filter is required then we need who is the user 
(object User)*/
+    function __construct($p_name="",$p_value="",$p_exercice='')
+    {
+        $this->name=$p_name;
+        $this->readOnly=false;
+        $this->size=20;
+        $this->width=50;
+        $this->heigh=20;
+        $this->value=$p_value;
+        $this->selected="";
+        $this->table=0;
+        $this->disabled=false;
+        $this->javascript="";
+        $this->extra2="all";
+        $this->show_start_date=true;
+        $this->show_end_date=true;
+               $this->exercice=$p_exercice;
+    }
+    /*!
+     * \brief show the input html for a periode
+     *\param $p_name is the name of the widget
+     *\param $p_value is the default value
+     *\param $p_exercice is the exercice, if not set then the user preference 
is used
+     * \return string containing html code for the HTML
+     *
+     *
+     */
+    public function input($p_name=null,$p_value=null)
+    {
+        foreach (array('type','cn') as $a)
+        {
+            if ( ! isset ($this->$a) ) throw new Exception('Variable non 
définie [ '.$a.']');
+        }
+        $this->name=($p_name==null)?$this->name:$p_name;
+        $this->value=($p_value==null)?$this->value:$p_value;
+        if ( $this->readOnly==true) return $this->display();
+
+        switch ($this->type)
+        {
+        case CLOSED:
+            $sql_closed="where p_closed=true and p_central = false ";
+            break;
+        case OPEN:
+            $sql_closed="where p_closed=false";
+            break;
+        case NOTCENTRALIZED:
+            $sql_closed="where p_closed=true and p_central = false ";
+            break;
+        case ALL:
+            $sql_closed="";
+            break;
+        default:
+            throw new Exception("invalide p_type in ".__FILE__.':'.__LINE__);
+        }
+        $sql="select p_id,to_char(p_start,'DD.MM.YYYY') as p_start_string,
+             to_char(p_end,'DD.MM.YYYY') as p_end_string
+             from parm_periode
+             $sql_closed ";
+
+       $cond="";
+
+
+        /* Create a filter on the current exercice */
+        if ( ! isset($this->filter_year) || (isset($this->filter_year) && 
$this->filter_year==true))
+        {
+         if ( $this->exercice=='')
+           {
+             if (! isset($this->user) ) throw new Exception 
(__FILE__.':'.__LINE__.' user is not set');
+             $this->exercice=$this->user->get_exercice();
+           }
+
+            $cond='';
+           if ( $sql_closed=="") $and=" where " ; else $and=" and ";
+            if ($this->type == 'all' ) $cond=$and.'   true ';
+            $cond.=" $and p_exercice='".sql_string($this->exercice)."'";
+        }
+
+        $sql.=$cond."  order by p_start,p_end";
+
+        $Res=$this->cn->exec_sql($sql);
+        $Max=$this->cn->size($Res);
+        if ( $Max == 0 )  throw new Exception(_('Aucune periode trouvée'),1);
+        $ret='<SELECT NAME="'.$this->name.'" '.$this->javascript.'>';
+        for ( $i = 0; $i < $Max;$i++)
+        {
+            $l_line=$this->cn->fetch($i);
+            if ( $this->value==$l_line['p_id'] )
+                $sel="SELECTED";
+            else
+                $sel="";
+
+            if ( $this->show_start_date == true && $this->show_end_date==true )
+            {
+                $ret.=sprintf('<OPTION VALUE="%s" %s>%s - %s',$l_line['p_id']
+                              ,$sel
+                              ,$l_line['p_start_string']
+                              ,$l_line['p_end_string']);
+            }
+            else if ($this->show_start_date == true )
+            {
+                $ret.=sprintf('<OPTION VALUE="%s" %s>%s ',$l_line['p_id']
+                              ,$sel
+                              ,$l_line['p_start_string']
+                             );
+            }
+            else if ( $this->show_end_date == true )
+            {
+                $ret.=sprintf('<OPTION VALUE="%s" %s>%s ',$l_line['p_id']
+                              ,$sel
+                              ,$l_line['p_end_string']
+                             );
+            }
+
+        }
+        $ret.="</SELECT>";
+        return $ret;
+
+
+    }
+    /*!\brief print in html the readonly value of the widget*/
+    public function display()
+    {
+        $r="not implemented ".__FILE__.":".__LINE__;
+        return $r;
+
+    }
+    static public function test_me()
+    {
+    }
+}
diff --git a/include/lib/class_ipopup.php b/include/lib/class_ipopup.php
new file mode 100644
index 0000000..8506ac7
--- /dev/null
+++ b/include/lib/class_ipopup.php
@@ -0,0 +1,191 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief create a popup in html above the current layer
+ * the html inside the popup cannot contain any floating elt as div..
+ *
+ */
+require_once NOALYSS_INCLUDE.'/lib/function_javascript.php';
+require_once NOALYSS_INCLUDE.'/lib/class_html_input.php';
+
+class IPopup extends HtmlInput
+{
+    var $name;                 /*!< name name and id of the div */
+    function __construct($p_name)
+    {
+        $this->name=$p_name;
+        $this->parameter='';
+        $this->attribute=array();
+        $this->drag=false;
+        $this->blocking=true;
+    }
+    function set_width($p_val)
+    {
+        $js=sprintf('$("%s'.'_border").style.width="%s";',
+                    $this->name,$p_val);
+        $this->parameter.=$js;
+
+    }
+    function set_height($p_val)
+    {
+        $js=sprintf('$("%s'.'_border").style.height="%s";',
+                    $this->name,$p_val);
+        $this->parameter.=$js;
+
+    }
+    /**
+     address@hidden set or not a blocking fond
+     address@hidden $p_block if true if you want to avoid access to background,
+     *accept true or false
+     */
+    function set_block($p_block)
+    {
+        $this->blocking=$p_block;
+    }
+
+    function set_zindex($p_val)
+    {
+        $js=sprintf('$("%s'.'_border").style.zIndex=%d;',
+                    $this->name,$p_val);
+        $js=sprintf('$("%s'.'_content").style.zIndex=%d;',
+                    $this->name,$p_val);
+        $this->parameter.=$js;
+    }
+    function set_dragguable($p_value)
+    {
+        $this->drag=$p_value;
+    }
+    /*!\brief set the attribute thanks javascript as the width, the position 
...
+     *\param $p_name attribute name
+     *\param $p_val val of the attribute
+     *\note add to  the this->attribut, it will be used in input()
+     */
+    function set_attribute($p_name,$p_val)
+    {
+        $this->attribute[]=array($p_name,$p_val);
+    }
+    /*!\brief set the title of a ipopup thanks javascript and php mode
+     *\param title of the IPopup
+     *\return html string with js script
+     */
+    function set_title($p_title)
+    {
+        $this->title=$p_title;
+        $s=sprintf('$("%s_"+"title")="%s"',
+                   $this->name,$this->title);
+        return create_script($s);
+    }
+    function input()
+    {
+        $r="";
+        if ($this->blocking)
+        {
+            $r.=sprintf('<div id="%s_fond" class="popup_back">',$this->name);
+            $r.="</div>";
+        }
+        $javascript=sprintf("javascript:hideIPopup('%s')",
+                            $this->name);
+
+
+        if ( isset($this->title) && trim($this->title) != "" )
+        {
+            $r.=sprintf('<div id="%s_border" id="%s_border" 
class="popup_border_title">',
+                        $this->name,
+                        $this->name);
+            $r.=sprintf('<span id="%s_">%s</span>',$this->name,$this->title);
+        }
+        else
+        {
+            $r.=sprintf('<div id ="%s_border" id="%s_border" 
class="popup_border_notitle">',
+                        $this->name,
+                        $this->name);
+        }
+        $r.='<div 
style="position:absolute;top:0px;right:10px;font-weight:normal;font-size:9px;color:black;text-align:right">';
+        $r.=sprintf('<a 
style="background-color:blue;color:white;text-decoration:none" 
href="%s">&#10761;</a></div>',
+                    $javascript);
+
+        $r.=sprintf('<div id ="%s_content" id="%s_content" class="inner_box"> 
%s </div></div>',
+                    $this->name,
+                    $this->name,
+                    $this->value);
+
+
+        /* Add properties at the widget */
+        $attr=$this->parameter;
+        for ($i=0;$i< count($this->attribute);$i++)
+        {
+            list($name,$value)=$this->attribute[$i];
+            $tmp1=sprintf("$('%s').%s='%s';",
+                          $this->name,
+                          $name,
+                          $value);
+            $attr.=$tmp1;
+        }
+        $draggable='';
+        if ($this->drag==true)
+        {
+            /* add draggable possibility */
+            $draggable=sprintf("  new 
Draggable('%s_border',{starteffect:function(){
+                               new 
Effect.Highlight('%s_border',{scroll:window,queue:'end'});  } });"
+                               ,$this->name
+                               ,$this->name);
+
+        }
+        $attr=create_script($attr.$draggable);
+        $r.=$attr;
+        return $r;
+    }
+
+    static function test_me()
+    {
+        require_once NOALYSS_INCLUDE.'/lib/class_iselect.php';
+        $select=new ISelect('a');
+        $select->value=array(array ('value'=>0,'label'=>'Première valeur'),
+                             array ('value'=>0,'label'=>'Première valeur'),
+                             array ('value'=>0,'label'=>'Première valeur'));
+        for ($e=0;$e<5;$e++)
+        {
+            echo $select->input();
+            if ($e%10 == 0 ) echo '<hr>';
+        }
+        $a=new IPopup('pop1');
+        $a->value="";
+        for ($e=0;$e<500;$e++)
+        {
+            $a->value.="<p>Il etait une fois dans  un pays vraiment lointain 
où même plus loin que ça</p>";
+        }
+        echo $a->input();
+        echo '
+        <input type="button" onclick="hide(\'pop1\');hide(\'pop1_border\')" 
value="cacher">
+                                     <input type="button" 
onclick="showIPopup(\'pop1\')" value="montrer">
+              ';
+        $a=new IPopup('pop2');
+        $a->value='';
+        $a->title="Retrouvez une saucisse";
+        echo $a->input();
+        echo '
+        <input type="button" onclick="hide(\'pop2\');hide(\'pop2_border\')" 
value="cacher">
+                        <input type="button" onclick="showIPopup(\'pop2\')" 
value="montrer">
+              ';
+
+    }
+}
diff --git a/include/lib/class_iposte.php b/include/lib/class_iposte.php
new file mode 100644
index 0000000..a8d887f
--- /dev/null
+++ b/include/lib/class_iposte.php
@@ -0,0 +1,203 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief Html Input
+ *
+ */
+require_once NOALYSS_INCLUDE.'/lib/class_html_input.php';
+require_once NOALYSS_INCLUDE.'/lib/class_itext.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ibutton.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ipopup.php';
+require_once NOALYSS_INCLUDE.'/lib/function_javascript.php';
+/**
+ address@hidden show a button, for selecting a account and a input text for 
manually inserting an account
+ * the different value of table are
+ * - 0 no table, it means no TD tags
+ * - 1 the button and the text are separated by TD tags
+ * - 2 the button and the text are in the same column (TD)
+ * - 3 the button and the text are in the table (TD)
+ *\note we use the set_attribute for giving parameter to search_account
+ * attribute are
+ *  - gDossier
+ *  - jrn  if set there is a filter on a ledger, in  that case, contains the 
jrn_id (0 for no filter)
+ *  - account field to update with the account_number,
+ *  - label  field to update  control with account_label,
+ *  - bracket if true return the account_number between bracket
+ *  - noquery don't start a search with the content
+ *  - no_overwrite do not overwrite the existant content
+ *  - query value to seek
+ address@hidden needed javascript are
+ - echo js_include('prototype.js');
+ - echo js_include('scriptaculous.js');
+ - echo js_include('effects.js');
+ - echo js_include('controls.js');
+ - echo js_include('dragdrop.js');
+ - echo js_include('accounting_item.js');
+ *\see ajax_poste.php
+ *\code
+// must be done BEFORE any FORM
+ echo js_include('prototype.js');
+ echo js_include('scriptaculous.js');
+ echo js_include('effects.js');
+ echo js_include('controls.js');
+ echo js_include('dragdrop.js');
+ echo js_include('accounting_item.js');
+
+
+require_once NOALYSS_INCLUDE.'/lib/class_iposte.php';
+
+// In the FORM
+$text=new IPoste();
+$text->name('field');
+$text->value=$p_res[$i]['pvalue'];
+$text->set_attribute('gDossier',Dossier::id());
+$text->set_attribute('jrn',0);
+$text->set_attribute('account','field');
+
+
+\endcode
+ */
+class IPoste extends HtmlInput
+{
+
+    function __construct($p_name="",$p_value="",$p_id="")
+    {
+        $this->name=$p_name;
+        $this->readOnly=false;
+        $this->size=10;
+        $this->value=$p_value;
+        $this->selected="";
+        $this->table=0;
+        $this->disabled=false;
+        $this->javascript="";
+        $this->extra2="all";
+        $this->attribute=array();
+       $this->id=$p_id;
+       
+
+    }
+
+    static function ipopup($p_name)
+    {
+        $ip=new IPopup($p_name);
+        $ip->title='Plan comptable';
+        $ip->value='';
+        $ip->set_height('80%');
+        $ip->set_zindex(20);
+        return $ip->input();
+    }
+    /*!\brief create the javascript for adding the javascript properties
+     * onto the *button*
+     *\return a javascript surrounded by the tag <SCRIPT>
+     */
+    public function get_js_attr()
+    {
+        $attr="";
+        /* Add properties at the widget */
+        for ($i=0;$i< count($this->attribute);$i++)
+        {
+            list($name,$value)=$this->attribute[$i];
+            $tmp1=sprintf("$('%s_bt').%s='%s';",
+                          $this->id,
+                          $name,
+                          $value);
+            $attr.=$tmp1;
+        }
+        $attr=create_script($attr);
+        return $attr;
+    }
+
+    public function dsp_button()
+    {
+               $this->id=($this->id=="")?$this->name:$this->id;
+        $javascript='search_poste(this)';
+        $button=HtmlInput::button_image($javascript,$this->id."_bt", 
'alt="'._('Recherche').'" class="image_search"',"image/magnifier13.png");
+        /*  add the property */
+        $sc=$this->get_js_attr();
+        return $button.$sc;
+    }
+    /*!\brief show the html  input of the widget*/
+    public function input($p_name=null,$p_value=null)
+    {
+        $this->name=($p_name==null)?$this->name:$p_name;
+        $this->value=($p_value==null)?$this->value:$p_value;
+        if ( $this->readOnly==true) return $this->display();
+        //--
+        if ( ! isset($this->ctrl) ) $this->ctrl='none';
+
+        if ( ! isset($this->javascript)) $this->javascript="";
+               $this->id=($this->id=="")?$this->name:$this->id;
+
+        /* create the text  */
+        $itext=new IText($this->name,$this->value,$this->id);
+
+       if ( isset ($this->css_size))
+            $itext->css_size=$this->css_size;
+       else
+            $itext->size=$this->size;
+
+                $itext->javascript=$this->javascript;
+        /* create the button */
+        $ibutton=$this->dsp_button();
+        if ( $this->table==3)
+        {
+            $r='<table>'.tr(td($itext->input()).td($ibutton));
+            $r.='</table>';
+            return $r;
+        }
+        $r=$itext->input().$ibutton;
+        if ( $this->table==1) $r=td($r);
+
+        return $r;
+
+
+        //--
+
+    }
+    /*!\brief print in html the readonly value of the widget*/
+    public function display()
+    {
+        $r=sprintf('<TD><input type="hidden" name="%s" value="%s">
+                   %s
+
+                   </TD>',
+                   $this->name,
+                   $this->value ,
+                   $this->value
+                  );
+
+        return $r;
+
+    }
+       /**
+        *add a double click to poste to see his history
+        address@hidden change $this->javascript
+        */
+       public function dbl_click_history()
+       {
+               $r=' 
ondblclick="get_history_account(\''.$this->name.'\',\''.dossier::id().'\')"';
+               $this->javascript=$r;
+       }
+    static public function test_me()
+    {
+    }
+}
diff --git a/include/lib/class_iradio.php b/include/lib/class_iradio.php
new file mode 100644
index 0000000..47f7337
--- /dev/null
+++ b/include/lib/class_iradio.php
@@ -0,0 +1,73 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/**\file
+ * \brief Html Input 
+ */
+require_once NOALYSS_INCLUDE.'/lib/class_html_input.php';
+
+class IRadio extends HtmlInput
+    {
+    /**\brief show the html  input of the widget */
+
+    public function input($p_name=null, $p_value=null)
+        {
+        $this->name = ($p_name == null) ? $this->name : $p_name;
+        $this->value = ($p_value == null) ? $this->value : $p_value;
+        if ($this->readOnly == true)
+            return $this->display();
+
+        $check = ( $this->selected == true || $this->selected == 't' ) ? 
"checked" : "unchecked";
+        $r = '<input type="RADIO" name="' . $this->name . '"';
+        $r.=" VALUE=\"$this->value\"";
+        $r.=' class="css-checkbox" ';
+        $r.=($this->javascript != '') ? 'onclick="' . $this->javascript . '"' 
: '';
+        $r.="  $check > ";
+        return $r;
+        }
+
+    /**\brief print in html the readonly value of the widget */
+
+    public function display()
+        {
+
+        $check = ( $this->selected == true || $this->selected == 't' ) ? "Yes" 
: "no";
+        $r = $check;
+        return $r;
+        }
+
+    /**
+     * set selected to true (checked) if the value equal the parameter
+     * @param $p_value value to compare
+     */
+    public function set_check($p_value)
+        {
+        if ($this->value == $p_value)
+            $this->selected = true;
+        }
+
+    static public function test_me()
+        {
+        
+        }
+       
+    }
diff --git a/include/lib/class_irelated_action.php 
b/include/lib/class_irelated_action.php
new file mode 100644
index 0000000..e3e6ca5
--- /dev/null
+++ b/include/lib/class_irelated_action.php
@@ -0,0 +1,73 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief Html Input
+ *  - name is the name and id of the input
+ */
+require_once NOALYSS_INCLUDE.'/lib/class_html_input.php';
+class IRelated_Action extends HtmlInput
+{
+
+       public function __construct($p_name='',$p_value='')
+       {
+               $this->name=$p_name;
+               $this->value=$p_value;
+               $this->amount_id=null;
+               $this->paid='';
+               $this->id=$p_name;
+       }
+    /*!\brief show the html  input of the widget*/
+    public function input($p_name=null,$p_value=null)
+    {
+        $this->name=($p_name==null)?$this->name:$p_name;
+        $this->value=($p_value==null)?$this->value:$p_value;
+        if ( $this->readOnly==true) return $this->display();
+
+               $this->id=($this->id=="")?$this->name:$this->id;
+
+
+        $r=sprintf("
+                   <INPUT class=\"smallbutton\" TYPE=\"button\" 
onClick=\"search_action(".dossier::id().",'%s')\" value=\"?\">
+                   <INPUT TYPE=\"text\"  
style=\"color:black;background:lightyellow;border:solid 1px grey;\"  
NAME=\"%s\" ID=\"%s\" VALUE=\"%s\" SIZE=\"8\" readonly>
+                                  <INPUT class=\"smallbutton\"  
TYPE=\"button\" onClick=\"$('%s').value=''\" value=\"X\">
+
+                   ",
+                   $this->id,
+                   $this->name,
+                   $this->id,
+                   $this->value,
+                   $this->id
+                  );
+        return $r;
+    }
+    /*!\brief print in html the readonly value of the widget*/
+    public function display()
+    {
+        $r=sprintf("<span><b>%s</b></span>",$this->value);
+        $r.=sprintf('<input type="hidden" name="%s" value="%s">', 
$this->name,$this->value);
+        return $r;
+
+    }
+    static public function test_me()
+    {
+    }
+}
diff --git a/include/lib/class_iselect.php b/include/lib/class_iselect.php
new file mode 100644
index 0000000..60d781c
--- /dev/null
+++ b/include/lib/class_iselect.php
@@ -0,0 +1,76 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief Html Input
+ * @see Database::make_array
+ */
+require_once NOALYSS_INCLUDE.'/lib/class_html_input.php';
+class ISelect extends HtmlInput
+{
+    /*!\brief show the html  input of the widget*/
+    public function input($p_name=null,$p_value=null)
+    {
+        $this->name=($p_name==null)?$this->name:$p_name;
+        $this->value=($p_value==null)?$this->value:$p_value;
+        if ( $this->readOnly==true) return $this->display();
+        $style=(isset($this->style))?$this->style:"";
+               $this->id=($this->id=="")?$this->name:$this->id;
+
+        $disabled=($this->disabled==true)?"disabled":"";
+        $rowsize = (isset ($this->rowsize)) ? ' size = 
"'.$this->rowsize.'"':"";
+        $r="";
+
+        $a="<SELECT  id=\"$this->id\" NAME=\"$this->name\" $style 
$this->javascript $disabled $rowsize>";
+
+        if (empty($this->value)) return '';
+        for ( $i=0;$i<sizeof($this->value);$i++)
+        {
+            
$checked=($this->selected==$this->value[$i]['value'])?"SELECTED":"";
+            $a.='<OPTION VALUE="'.$this->value[$i]['value'].'" '.$checked.'>';
+            $a.=$this->value[$i]['label'];
+        }
+        $a.="</SELECT>";
+        if ( $this->table == 1 )                 $a='<td>'.$a.'</td>';
+
+        return $r.$a;
+    }
+    /*!\brief print in html the readonly value of the widget*/
+    public function display()
+    {
+        $r="";
+        for ( $i=0;$i<sizeof($this->value);$i++)
+        {
+            if ($this->selected==$this->value[$i]['value'] )
+            {
+                $r=h($this->value[$i]['label']);
+
+            }
+        }
+               if ( $this->table == 1 )                  $a='<td>'.$r.'</td>';
+        return $r;
+    }
+
+
+    static public function test_me()
+    {
+    }
+}
diff --git a/include/lib/class_ispan.php b/include/lib/class_ispan.php
new file mode 100644
index 0000000..c377dbf
--- /dev/null
+++ b/include/lib/class_ispan.php
@@ -0,0 +1,53 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief Html Input
+ */
+require_once NOALYSS_INCLUDE.'/lib/class_html_input.php';
+class ISpan extends HtmlInput
+{
+    public function __construct($p_name="",$p_value="")
+    {
+        parent::__construct($p_name,$p_value);
+        $this->style="display:inline";
+
+    }
+    /*!\brief show the html  input of the widget, the span is always readonly 
*/
+    public function input($p_name=null,$p_value=null)
+    {
+        $this->name=($p_name==null)?$this->name:$p_name;
+        $this->value=($p_value==null)?$this->value:$p_value;
+
+
+        $r=sprintf('<span style="%s" id="%s">%s </span>',
+                   $this->style,
+                   $this->name,
+                   $this->value
+                  );
+
+        return $r;
+    }
+
+    static public function test_me()
+    {
+    }
+}
diff --git a/include/lib/class_itext.php b/include/lib/class_itext.php
new file mode 100644
index 0000000..c249462
--- /dev/null
+++ b/include/lib/class_itext.php
@@ -0,0 +1,98 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief Html Input
+ */
+require_once NOALYSS_INCLUDE.'/lib/class_html_input.php';
+class IText extends HtmlInput
+{
+    function __construct($name='',$value='',$p_id="")
+    {
+        parent::__construct($name,$value,$p_id);
+        $this->style=' class="input_text" ';
+    }
+    /*!\brief show the html  input of the widget*/
+    public function input($p_name=null,$p_value=null)
+    {
+        $this->name=($p_name==null)?$this->name:$p_name;
+        $this->value=($p_value==null)?$this->value:$p_value;
+        if ( $this->readOnly==true) return $this->display();
+               $this->id=($this->id=="")?$this->name:$this->id;
+
+        $t= ((isset($this->title)))?'title="'.$this->title.'"   ':' ';
+
+        $extra=(isset($this->extra))?$this->extra:"";
+
+        $this->value=str_replace('"','',$this->value);
+        if ( ! isset ($this->css_size))
+        {
+        $r='<INPUT '.$this->style.' TYPE="TEXT" id="'.
+           $this->id.'"'.$t.
+           'NAME="'.$this->name.'" VALUE="'.$this->value.'"  '.
+           'SIZE="'.$this->size.'" '.$this->javascript."  $this->extra >";
+        /* add tag for column if inside a table */
+        } else {
+           $r='<INPUT '.$this->style.' TYPE="TEXT" id="'.
+           $this->id.'"'.$t.
+           'NAME="'.$this->name.'" VALUE="'.$this->value.'"  '.
+           ' style="width:'.$this->css_size.';" '.$this->javascript."  
$this->extra >";
+
+        }
+
+        if ( $this->table == 1 )                 $r='<td>'.$r.'</td>';
+
+        return $r;
+
+    }
+    /*!\brief print in html the readonly value of the widget*/
+    public function display()
+    {
+        $t= ((isset($this->title)))?'title="'.$this->title.'"   ':' ';
+
+        $extra=(isset($this->extra))?$this->extra:"";
+
+        $readonly=" readonly ";
+        $this->value=str_replace('"','',$this->value);
+                $this->style=' class="input_text_ro" ';
+         if ( ! isset ($this->css_size))
+        {
+        $r='<INPUT '.$this->style.' TYPE="TEXT" id="'.
+           $this->id.'"'.$t.
+           'NAME="'.$this->name.'" VALUE="'.$this->value.'"  '.
+           'SIZE="'.$this->size.'" '.$this->javascript." $readonly 
$this->extra >";
+        } else {
+               $r='<INPUT '.$this->style.' TYPE="TEXT" id="'.
+           $this->id.'"'.$t.
+           'NAME="'.$this->name.'" VALUE="'.$this->value.'"  '.
+           ' style="width:'.$this->css_size.'" '.$this->javascript." $readonly 
 $this->extra >";
+        }
+
+        /* add tag for column if inside a table */
+        if ( $this->table == 1 )                 $r='<td>'.$r.'</td>';
+
+        return $r;
+
+    }
+    static public function test_me()
+    {
+    }
+}
diff --git a/include/lib/class_itextarea.php b/include/lib/class_itextarea.php
new file mode 100644
index 0000000..4d00b8f
--- /dev/null
+++ b/include/lib/class_itextarea.php
@@ -0,0 +1,61 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief Html Input
+ */
+require_once NOALYSS_INCLUDE.'/lib/class_html_input.php';
+class ITextarea extends HtmlInput
+{
+    /*!\brief show the html  input of the widget*/
+    public function input($p_name=null,$p_value=null)
+    {
+        $this->name=($p_name==null)?$this->name:$p_name;
+        $this->value=($p_value==null)?$this->value:$p_value;
+       if ( !isset ($this->style )) $this->style=' class="itextarea" ';
+       $this->id=($this->id=="")?$this->name:$this->id;
+
+        if ( $this->readOnly==true) return $this->display();
+
+        $r="";
+        $r.='<TEXTAREA '.$this->style.'  name="'.$this->name.'" 
id="'.$this->id.'"';
+        $r.='>';
+        $r.=$this->value;
+
+        $r.="</TEXTAREA>";
+        return $r;
+    }
+
+
+    /*!\brief print in html the readonly value of the widget*/
+    public function display()
+    {
+        $r='<p>';
+        $r.=h($this->value);
+        $r.=sprintf('<input type="hidden" name="%s" value="%s">',
+                    $this->name,h($this->value));
+        $r.='</p>';
+
+    }
+    static public function test_me()
+    {
+    }
+}
diff --git a/include/lib/class_itva_popup.php b/include/lib/class_itva_popup.php
new file mode 100644
index 0000000..906cc91
--- /dev/null
+++ b/include/lib/class_itva_popup.php
@@ -0,0 +1,177 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/*!\file
+ * \brief Html Input
+ */
+require_once  NOALYSS_INCLUDE.'/lib/class_ipopup.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ibutton.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ispan.php';
+/**
+ address@hidden let you choose a TVA in a popup
+ address@hidden
+    $a=new IPopup('popup_tva');
+    $a->set_title('Choix de la tva');
+    echo $a->input();
+    $tva=new ITva_Popup("tva1");
+    $tva->with_button(true);
+    // You must add the attributes gDossier, popup
+    $tva->set_attribute('popup','popup_tva');
+    $tva->set_attribute('gDossier',dossier::id());
+
+    // We can add a label for the code
+    $tva->add_label('code');
+    $tva->js='onchange="set_tva_label(this);"';
+    echo $tva->input();
address@hidden
+*/
+class ITva_Popup extends HtmlInput
+{
+    /**
+     address@hidden by default, the p_name is the name/id of the input type
+     * the this->button is false (control if a button is visible) and
+     * this->in_table=false (return the widget inside a table)
+     * this->code is a span widget to display the code (in this case, you will
+     * to set this->cn as database connexion)
+     * to have its own javascript for the button you can use 
this->but_javascript)
+     * by default it is 'popup_select_tva(this)';
+     */
+    public function __construct($p_name=null,$p_value="",$p_id="")
+    {
+        $this->name=$p_name;
+        $this->button=true;
+        $this->in_table=false;
+               $this->value=$p_value;
+               $this->id=$p_id;
+    }
+    function with_button($p)
+    {
+        if ($p == true )
+            $this->button=true;
+        else
+            $this->button=false;
+    }
+    /*!\brief show the html  input of the widget*/
+    public function input($p_name=null,$p_value=null)
+    {
+        $this->name=($p_name==null)?$this->name:$p_name;
+        $this->value=($p_value==null)?$this->value:$p_value;
+        
$this->js=(isset($this->js))?$this->js:'onchange="format_number(this);"';
+               $this->id=($this->id=="")?$this->name:$this->id;
+
+        if ( $this->readOnly==true) return $this->display();
+
+        $str='<input type="TEXT"  class="input_text" name="%s" value="%s" 
id="%s" size="3" %s>';
+        $r=sprintf($str,$this->name,$this->value,$this->id,$this->js);
+
+        if ($this->in_table)
+            $table='<table>'.'<tr>'.td($r);
+
+        if ( $this->button==true && ! $this->in_table)
+            $r.=$this->dbutton();
+
+        if ( $this->button==true &&  $this->in_table)
+            $r=$table.td($this->dbutton()).'</tr></table>';
+
+        if ( isset($this->code))
+        {
+            if ( $this->cn != NULL)
+            {
+                /* check if tva_id == integer */
+                if (trim($this->value)!='' &&  isNumber($this->value)==1 && 
strpos($this->value,',') === false)
+                    $this->code->value=$this->cn->get_value('select tva_label 
from tva_rate where tva_id=$1',
+                                                            
array($this->value));
+                ;
+            }
+            $r.=$this->code->input();
+            if ($this->table==1) $r=td($r);
+            $this->set_attribute('jcode',$this->code->name);
+            $this->set_attribute('gDossier',dossier::id());
+            $this->set_attribute('ctl',$this->name);
+            $r.=$this->get_js_attr();
+
+        }
+
+        return $r;
+
+    }
+    /**
+     address@hidden show a button, if it is pushed show a popup to select the 
need vat
+     address@hidden
+     * - a ipopup must be created before with the name popup_tva
+     * - the javascript scripts.js must be loaded
+     address@hidden string with html code
+     */
+    function dbutton()
+    {
+        if( trim($this->name)=='') throw new Exception (_('Le nom ne peut être 
vide'));
+               $this->id=($this->id=="")?$this->name:$this->id;
+
+        // button
+        $bt=new ISmallButton('bt_'.$this->id);
+               $bt->tabindex="-1";
+        $bt->label=_(' TVA ');
+        $bt->set_attribute('gDossier',dossier::id());
+        $bt->set_attribute('ctl',$this->id);
+        $bt->set_attribute('popup','popup_tva');
+        if ( isset($this->code))
+            $bt->set_attribute('jcode',$this->code->name);
+        if ( isset($this->compute))
+            $bt->set_attribute('compute',$this->compute);
+        
$bt->javascript=(isset($this->but_javascript))?$this->but_javascript:'popup_select_tva(this)';
+        $r=$bt->input();
+        return $r;
+    }
+
+    /*!\brief print in html the readonly value of the widget*/
+    public function display()
+    {
+        $cn=  new Database(Dossier::id());
+        $tva=new Acc_Tva($cn, $this->value);
+        
+        $comment=($tva->load()  != "-1")? $tva->tva_label:"";
+       $res=sprintf('<input type="text" name="%s" size="6" 
class="input_text_ro" value="%s" id="%s" 
readonly="">%s',$this->name,$this->value,$this->name,$comment);
+        return $res;
+    }
+    /**
+     address@hidden add a field to show the selected tva's label
+     address@hidden $p_code is the name of the label where you can see the 
label of VAT
+     address@hidden $p_cn is a database connection if NULL it doesn't seek in 
the database
+     */
+    public function add_label($p_code,$p_cn=null)
+    {
+        $this->cn=$p_cn;
+        $this->code=new ISpan($p_code);
+    }
+    static public function test_me()
+    {
+        $a=new IPopup('popup_tva');
+        $a->set_title('Choix de la tva');
+        echo $a->input();
+        $tva=new ITva_Popup("tva1");
+        $tva->with_button(true);
+        // We can add a label for the code
+        $tva->add_label('code');
+        $tva->js='onchange="set_tva_label(this);"';
+        echo $tva->input();
+        echo $tva->dbutton();
+    }
+}
diff --git a/include/class_pdf.php b/include/lib/class_pdf.php
similarity index 100%
rename from include/class_pdf.php
rename to include/lib/class_pdf.php
diff --git a/include/lib/class_sendmail.php b/include/lib/class_sendmail.php
new file mode 100644
index 0000000..d98e726
--- /dev/null
+++ b/include/lib/class_sendmail.php
@@ -0,0 +1,160 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+// Copyright Author Dany De Bontridder address@hidden
+
+
+/**
+ * Description of class_sendmail
+ *
+ * @author dany
+ */
+require_once NOALYSS_INCLUDE.'/lib/class_filetosend.php';
+
+class Sendmail
+{
+
+    private $mailto;
+    private $afile;
+    private $subject;
+    private $message;
+    private $from;
+    private $content;
+
+    /**
+     * set the from
+     * @parameter $p_from has the form name <address@hidden>
+     */
+    function set_from($p_from)
+    {
+        $this->from = $p_from;
+    }
+
+    /**
+     * 
+     * @param $p_subject set the subject
+     */
+    function set_subject($p_subject)
+    {
+        $this->subject = $p_subject;
+    }
+
+    /**
+     * set the recipient
+     * @param type $p_mailto has the form name <address@hidden>
+     */
+    function mailto($p_mailto)
+    {
+        $this->mailto = $p_mailto;
+    }
+
+    /**
+     * body of the message (utf8)
+     * @param type $p_message
+     */
+    function set_message($p_message)
+    {
+        $this->message = $p_message;
+    }
+
+    /**
+     * Add file to the message
+     * @param FileToSend $file file to add to the message
+     */
+    function add_file(FileToSend $file)
+    {
+        $this->afile[] = $file;
+    }
+
+    /**
+     *  verify that the message is ready to go
+     * @throws Exception
+     */
+    function verify()
+    {
+        $array = explode(",", "from,subject,mailto,message");
+        for ($i = 0; $i < count($array); $i++)
+        {
+            $name = $array[$i];
+            if (trim($this->$name) == "")
+            {
+                throw new Exception($name ._(" est vide"));
+            }
+        }
+    }
+    /**
+    * create the message before sending
+    */
+    function compose()
+    {
+        $this->verify();
+        $uid = md5(uniqid(time()));
+
+        // a random hash will be necessary to send mixed content
+        $separator = md5(time());
+
+        // carriage return type (we use a PHP end of line constant)
+        $eol = PHP_EOL;
+
+        // main header (multipart mandatory)
+        $headers = "From: " . $this->from . $eol;
+        $headers .= "MIME-Version: 1.0" . $eol;
+        $headers .= "Content-Type: multipart/mixed; boundary=\"" . $separator 
. "\"" . $eol . $eol;
+        $headers .= "Content-Transfer-Encoding: 7bit" . $eol;
+        $headers .= "This is a MIME encoded message." . $eol . $eol;
+        $headers .= $eol . $eol;
+
+        // message
+        $headers .= "--" . $separator . $eol;
+        $headers .= "Content-Type: text/plain; charset=\"utf-8\"" . $eol;
+        $headers .= "Content-Transfer-Encoding: 7bit" . $eol . $eol;
+        $headers .= $this->message . $eol . $eol;
+
+        // attachment
+        for ($i = 0; $i < count($this->afile); $i++)
+        {
+            $file = $this->afile[$i];
+            $file_size = filesize($file->full_name);
+            $handle = fopen($file->full_name, "r");
+            $content = fread($handle, $file_size);
+            fclose($handle);
+            $content = chunk_split(base64_encode($content));
+            $headers .= "--" . $separator . $eol;
+            $headers .= "Content-Type: " . $file->type . "; name=\"" . 
$file->filename . "\"" . $eol;
+            $headers .= "Content-Disposition: attachment; filename=\"" . 
$file->filename . "\"" . $eol;
+            $headers .= "Content-Transfer-Encoding: base64" . $eol;
+            $headers.=$eol;
+            $headers .= $content . $eol . $eol;
+        }
+        $headers .= "--" . $separator . "--";
+        $this->content = $headers;
+    }
+    /**
+     * Send the message 
+     * @throws Exception
+     */
+    function send()
+    {
+        //SEND Mail
+        if (!mail($this->mailto, $this->subject, "", $this->content))
+        {
+            throw new Exception('send failed');
+        }
+    }
+
+}
diff --git a/include/class_sort_table.php b/include/lib/class_sort_table.php
similarity index 100%
rename from include/class_sort_table.php
rename to include/lib/class_sort_table.php
diff --git a/include/lib/class_tool_uos.php b/include/lib/class_tool_uos.php
new file mode 100644
index 0000000..1a1cf50
--- /dev/null
+++ b/include/lib/class_tool_uos.php
@@ -0,0 +1,107 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+/**
+ * @file
+ * @brief Objec to check a double insert into the database, this duplicate 
occurs after
+ * a refresh of the web page
+ */
+// Copyright Author Dany De Bontridder address@hidden
+
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+define ('CODE_EXCP_DUPLICATE',901);
+/**
+ * @brief Objec to check a double insert into the database, this duplicate 
occurs after
+ * a refresh of the web page
+ * in
+ */
+
+class Tool_Uos
+{
+    /**
+     * Constructor $p_name will be set to $this->name, it is also the name
+     * of the tag hidden in a form
+     * @global $cn Db connxion
+     * @param $p_name
+     */
+    function __construct($p_name)
+    {
+        $this->name=$p_name;
+    }
+    /**
+     * @brief return a string with a tag hidden and a uniq value
+     * @param $hHidden is the name of the tag hidden
+     * @return string : tag hidden
+     */
+    function hidden()
+    {
+               global $cn;
+        $this->id=$cn->get_next_seq('uos_pk_seq');
+        return HtmlInput::hidden($this->name,$this->id);
+    }
+    /**
+     * @brief Try to insert into the table tool_uos
+     * @global $cn Database connx
+     * @throws Exception if the value $p_id is not unique
+     */
+    function save($p_array=null)
+    {
+        global $cn;
+               if ( $p_array == null ) $p_array=$_POST;
+               $this->id=$p_array[$this->name];
+        $sql="insert into tool_uos(uos_value) values ($1)";
+        try {
+            $cn->exec_sql($sql,array($this->id));
+        } catch (Exception $e)
+        {
+            throw new Exception('Duplicate value');
+        }
+    }
+    /**
+     * Count how many time we have this->id into the table tool_uos
+     * @global $cn Database connx
+     * @param $p_array is the array where to find the key name, usually it is
+     * $_POST. The default value is $_POST
+     * @return integer : 0 or 1
+     */
+    function get_count($p_array=null)
+    {
+        global $cn;
+        if ( $p_array == null ) $p_array=$_POST;
+        $this->id=$p_array[$this->name];
+        $count=$cn->get_value('select count(*) from tool_uos where 
uos_value=$1',
+                array($this->id));
+        return $count;
+    }
+    function check ($p_array=null)
+    {
+        global $cn;
+        if ( $p_array == null ) $p_array=$_POST;
+        $this->id=$p_array[$this->name];
+        try
+        {
+            $count=$cn->get_value('select count(*) from tool_uos where 
uos_value=$1',
+                    array($this->id));
+            if ($count != 0 ) throw new Exception 
('DUPLICATE',CODE_EXCP_DUPLICATE);
+        }catch (Exception $e)
+        {
+            throw $e;
+        }
+    }
+}
+?>
diff --git a/include/class_zip_extended.php b/include/lib/class_zip_extended.php
similarity index 100%
rename from include/class_zip_extended.php
rename to include/lib/class_zip_extended.php
diff --git a/include/function_javascript.php 
b/include/lib/function_javascript.php
similarity index 100%
rename from include/function_javascript.php
rename to include/lib/function_javascript.php
diff --git a/include/lib/user_common.php b/include/lib/user_common.php
new file mode 100644
index 0000000..7475f1a
--- /dev/null
+++ b/include/lib/user_common.php
@@ -0,0 +1,248 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+
+
+
+
+// Copyright Author Dany De Bontridder address@hidden
+
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/lib/class_icheckbox.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ihidden.php';
+require_once NOALYSS_INCLUDE.'/class/class_document.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_operation.php';
+/*! \file
+ * \brief Common functions
+ */
+
+/*!
+ *\brief   test if a jrn op is valid
+ *
+ * \param $p_cn db
+ * \param $p_grpt_id
+ * \return:
+ *        - 1 is valid
+ *        - 0 is not valid
+ */
+function isValid_deprecrated ($p_cn,$p_grpt_id)
+{
+    $Res=$p_cn->exec_sql("select jr_valid from jrn where 
jr_grpt_id=$p_grpt_id");
+
+    if ( ( $M = Database::num_row($Res)) == 0 ) return 0;
+
+    $a=Database::fetch_array($Res,0);
+
+    if ( $a['jr_valid'] == 't') return 1;
+    if ( $a['jr_valid'] == 'f') return 0;
+
+    echo_error ("Invalid result = ".$a['result']);
+
+
+}
+
+/*!
+ **************************************************
+ *\brief
+ *     Create a navigation_bar (pagesize)
+ *
+ * \param $p_offset first record number
+ * \param $p_line total of returned row
+ * \param $p_size current g_pagesize user's preference
+ * \param $p_page number of the page where the user is
+ * \param $p_javascript javascript code to add
+ * \note example :
+\verbatim
+   $step=$_SESSION['g_pagesize'];
+   $page=(isset($_GET['offset']))?$_GET['page']:1;
+   $offset=(isset($_GET['offset']))?$_GET['offset']:0;
+
+   list ($max_ligne,$list)=ListJrn($cn,$_GET['p_jrn'],$sql,null,$offset,1);
+   $bar=navigation_bar($offset,$max_ligne,$step,$page);
+\endverbatim
+ * \return   string with the nav. bar
+ */
+function navigation_bar($p_offset,$p_line,$p_size=0,$p_page=1,$p_javascript="")
+{
+    // if the pagesize is unlimited return ""
+    // in that case there is no nav. bar
+    if ( $_SESSION['g_pagesize'] == -1  ) return "";
+    if ( $p_size==0)
+    {
+        $p_size= $_SESSION['g_pagesize'];
+    }
+    // if there is no row return an empty string
+    if ( $p_line == 0 ) return "";
+
+    // Clean url, cut away variable coming frm here
+    $url=cleanUrl();
+    // action to clean
+    $url=str_replace('&p_action=delete','',$url);
+
+    // compute max of page
+    $nb_page=($p_line-($p_line%$p_size))/$p_size;
+    // if something remains
+    if ( $p_line % $p_size != 0 ) $nb_page+=1;
+
+    // if max page == 1 then return a empty string
+    if ( $nb_page == 1) return "";
+
+    // restore the sort
+    if ( isset($_GET['o']))
+        $url=$url.'&o='.$_GET['o'];
+
+    $r="";
+    // previous
+    if ($p_page !=1)
+    {
+        $e=$p_page-1;
+        $step=$p_size;
+        $offset=($e-1)*$step;
+
+        $r='<A class="mtitle" 
href="'.basename($_SERVER['SCRIPT_FILENAME'])."?".$url."&offset=$offset&step=$step&page=$e&size=$step".'"
 '.$p_javascript.'>';
+        $r.="  &larr;";
+        // $r.='<INPUT TYPE="IMAGE" width="12" SRC="image/go-previous.png">';
+        $r.="</A>&nbsp;&nbsp;";
+    }
+    //----------------------------------------------------------------------
+    // Create a partial bar
+    // if current page < 11 show 1 to 20
+    // otherwise            show $p_page -10 to $p_page + 10
+    //----------------------------------------------------------------------
+    $start_bar=($p_page < 11 )?1:$p_page-10;
+    $end_bar  =($p_page < 11 )?20:$p_page+10;
+    $end_bar  =($end_bar > $nb_page )?$nb_page:$end_bar;
+
+       $sep="";
+    // Create the bar
+    for ($e=$start_bar;$e<=$end_bar;$e++)
+    {
+        // do not included current page
+        if ( $e != $p_page )
+        {
+            $step=$p_size;
+            $offset=($e-1)*$step;
+
+            
$go=$_SERVER['PHP_SELF']."?".$url."&offset=$offset&step=$step&page=$e&size=$step";
+                       $r.=$sep;
+            $r.=sprintf('<A class="nav" HREF="%s"  %s 
>%d</A>&nbsp;',$go,$p_javascript,$e);
+                       $sep=" &#8231;  ";
+        }
+        else
+        {
+                       $r.=$sep;
+            $r.="<b> [ $e ] </b>";
+                       $sep=" &#8231;  ";
+        } //else
+    } //for
+    // next
+
+    if ($p_page !=$nb_page)
+    {
+        // If we are not at the last page show the button next
+        $e=$p_page+1;
+        $step=$p_size;
+        $offset=($e-1)*$step;
+
+        $r.='&nbsp;<A class="mtitle" 
href="'.$_SERVER['PHP_SELF']."?".$url."&offset=$offset&step=$step&page=$e&size=$step".'"
 '.$p_javascript.' >';
+        $r.="&rarr;";
+        //$r.='<INPUT TYPE="IMAGE" width="12" SRC="image/go-next.png">';
+        $r.="</A>";
+    }
+
+
+    return $r;
+}
+
+/*!
+ * \brief Clean the url, remove the $_GET offset,step, page and size
+ * \param none
+ *
+ * \return the cleaned url
+ */
+
+function CleanUrl()
+{
+    // Compute the url
+    $url="";
+    $and="";
+    $get=$_GET;
+    if ( isset ($get) )
+    {
+        foreach ($get as $name=>$value )
+        {
+            // we clean the parameter offset, step, page and size
+            if (  ! 
in_array($name,array('offset','step','page','size','s','o','r_jrn')))
+            {
+                $url.=$and.$name."=".$value;
+                $and="&";
+            }// if
+        }//foreach
+        if ( isset($_GET['r_jrn']))
+        {
+            $r_jrn=$_GET['r_jrn'];
+            if (count($r_jrn) > 0 )
+            {
+                foreach ($r_jrn as $key=>$value)
+                {
+                    $url.=$and."r_jrn[$key]=".$value;
+                    $and="&";
+                }
+            }
+        }
+    }// if
+    return $url;
+}
+function redirect($p_string,$p_time=0)
+{
+    if (strpos( $p_string,'?') == 0 ) {
+        $p_string = $p_string.'?v='.microtime(true);
+    }
+    echo '<HTML><head><META HTTP-EQUIV="REFRESH" 
content="'.$p_time.';url='.$p_string.'"></head><body> Connecting... 
</body></html>';
+}
+/*!\brief remove the useless space, change comma by period and try to return
+ * a number
+ *\param $p_num number to format
+ *\return the formatted number
+ */
+function toNumber($p_num)
+{
+    $p_num=trim($p_num);
+    if ($p_num=='') return 0;
+    $p_num=str_replace("'",'',$p_num);
+    $p_num=str_replace(',','.',$p_num);
+    return $p_num;
+}
+/**
+ * Check that all the index are in the array, used by function to check if
+ * the array contains the needed variables before an extract
+ * @param type $p_array array to check
+ * @param type $needed string containing variable separated by comma
+ * @throws Exception
+ */
+function check_parameter($p_array,$p_needed)
+{
+    $needed =explode(',',$p_needed);
+    for ($e=0;$e<count($needed);$e++) {
+            if ( ! isset($p_array[$needed[$e]])) {
+                throw new Exception (_('Paramètre manquant')." ".$needed[$e]);
+            }
+        }
+}
+?>
diff --git a/include/manager.inc.php b/include/manager.inc.php
index f3ca9fd..20e2eb8 100644
--- a/include/manager.inc.php
+++ b/include/manager.inc.php
@@ -22,14 +22,14 @@
  */
 if (!defined('ALLOWED'))
     die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_iselect.php';
-require_once NOALYSS_INCLUDE.'/class_ihidden.php';
-require_once NOALYSS_INCLUDE.'/class_manager.php';
-require_once NOALYSS_INCLUDE.'/class_ibutton.php';
-require_once NOALYSS_INCLUDE.'/class_iaction.php';
-require_once NOALYSS_INCLUDE.'/class_fiche_def.php';
-require_once NOALYSS_INCLUDE.'/class_iaction.php';
-require_once NOALYSS_INCLUDE.'/class_fiche_def.php';
+require_once NOALYSS_INCLUDE.'/lib/class_iselect.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ihidden.php';
+require_once NOALYSS_INCLUDE.'/class/class_manager.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ibutton.php';
+require_once NOALYSS_INCLUDE.'/lib/class_iaction.php';
+require_once NOALYSS_INCLUDE.'/class/class_fiche_def.php';
+require_once NOALYSS_INCLUDE.'/lib/class_iaction.php';
+require_once NOALYSS_INCLUDE.'/class/class_fiche_def.php';
 
 global $g_user;
 
diff --git a/include/menu.inc.php b/include/menu.inc.php
index 9adba89..7f58108 100644
--- a/include/menu.inc.php
+++ b/include/menu.inc.php
@@ -27,9 +27,9 @@
  *
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_menu_ref.php';
-require_once NOALYSS_INCLUDE.'/class_sort_table.php';
-require_once NOALYSS_INCLUDE.'/class_extension.php';
+require_once NOALYSS_INCLUDE.'/class/class_menu_ref.php';
+require_once NOALYSS_INCLUDE.'/lib/class_sort_table.php';
+require_once NOALYSS_INCLUDE.'/class/class_extension.php';
 
 
 echo '<div class="content">';
diff --git a/include/modele.inc.php b/include/modele.inc.php
index 8175b73..760c5a3 100644
--- a/include/modele.inc.php
+++ b/include/modele.inc.php
@@ -27,9 +27,9 @@
  *
  */
 if ( !defined ('ALLOWED')) die('Forbidden');
-require_once NOALYSS_INCLUDE.'/class_itext.php';
-require_once NOALYSS_INCLUDE.'/class_icheckbox.php';
-require_once  NOALYSS_INCLUDE.'/class_extension.php';
+require_once NOALYSS_INCLUDE.'/lib/class_itext.php';
+require_once NOALYSS_INCLUDE.'/lib/class_icheckbox.php';
+require_once  NOALYSS_INCLUDE.'/class/class_extension.php';
 
 $sa = (isset($_REQUEST['sa'])) ? $_REQUEST['sa'] : 'list';
 if (isset($_POST['upd']) &&
@@ -217,7 +217,7 @@ if (isset($_POST["FMOD_NAME"]))
 
 }
 // Show all available templates
-require_once NOALYSS_INCLUDE.'/class_sort_table.php';
+require_once NOALYSS_INCLUDE.'/lib/class_sort_table.php';
 $url=$_SERVER['PHP_SELF']."?sa=list&action=".$_REQUEST['action'];
 
 $header=new Sort_Table();
diff --git a/include/opening.inc.php b/include/opening.inc.php
index c27044c..ff52dd0 100644
--- a/include/opening.inc.php
+++ b/include/opening.inc.php
@@ -29,8 +29,8 @@
  *
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_iselect.php';
-require_once NOALYSS_INCLUDE.'/class_acc_ledger.php';
+require_once NOALYSS_INCLUDE.'/lib/class_iselect.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_ledger.php';
 
 $p_mesg="";
 
diff --git a/include/operation_ods_new.inc.php 
b/include/operation_ods_new.inc.php
index 6b817b0..5e637d7 100644
--- a/include/operation_ods_new.inc.php
+++ b/include/operation_ods_new.inc.php
@@ -25,8 +25,8 @@
  * \brief to write into the ledgers ODS a new operation
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_pre_op_ods.php';
-require_once NOALYSS_INCLUDE.'/class_iconcerned.php';
+require_once NOALYSS_INCLUDE.'/class/class_pre_op_ods.php';
+require_once NOALYSS_INCLUDE.'/lib/class_iconcerned.php';
 
 global $g_user,$g_parameter;
 $cn=new Database(dossier::id());
diff --git a/include/param_pcmn.inc.php b/include/param_pcmn.inc.php
index 6444bf0..2f01b4c 100644
--- a/include/param_pcmn.inc.php
+++ b/include/param_pcmn.inc.php
@@ -21,20 +21,20 @@
  * \brief concerns the management of the "Plan Comptable"
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once  NOALYSS_INCLUDE.'/class_acc_account.php';
-require_once  NOALYSS_INCLUDE.'/ac_common.php';
+require_once  NOALYSS_INCLUDE.'/class/class_acc_account.php';
+require_once  NOALYSS_INCLUDE.'/lib/ac_common.php';
 require_once NOALYSS_INCLUDE.'/constant.php';
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-require_once NOALYSS_INCLUDE.'/function_javascript.php';
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+require_once NOALYSS_INCLUDE.'/lib/function_javascript.php';
 
 $gDossier=dossier::id();
 
-require_once NOALYSS_INCLUDE.'/class_database.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
 
 /* Admin. Dossier */
 $cn=new Database($gDossier);
 
-require_once  NOALYSS_INCLUDE.'/class_user.php';
+require_once  NOALYSS_INCLUDE.'/class/class_user.php';
 
 require_once  NOALYSS_INCLUDE.'/user_menu.php';
 echo '<div id="acc_update" class="inner_box" 
style="display:none;position:absolute;text-align:left;z-index:1"></div>';
diff --git a/include/param_sec.inc.php b/include/param_sec.inc.php
index 6487051..06ed9ba 100644
--- a/include/param_sec.inc.php
+++ b/include/param_sec.inc.php
@@ -23,12 +23,12 @@
  * \brief Set the security for an user
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once  NOALYSS_INCLUDE.'/ac_common.php';
-require_once NOALYSS_INCLUDE.'/class_iselect.php';
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-require_once  NOALYSS_INCLUDE.'/class_user.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_sort_table.php';
+require_once  NOALYSS_INCLUDE.'/lib/ac_common.php';
+require_once NOALYSS_INCLUDE.'/lib/class_iselect.php';
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+require_once  NOALYSS_INCLUDE.'/class/class_user.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/lib/class_sort_table.php';
 
 $gDossier=dossier::id();
 $str_dossier=dossier::get();
diff --git a/include/payment_middle.inc.php b/include/payment_middle.inc.php
index 7bfd365..36886ec 100644
--- a/include/payment_middle.inc.php
+++ b/include/payment_middle.inc.php
@@ -19,8 +19,8 @@
 
 // Copyright Author Dany De Bontridder address@hidden
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_acc_payment.php';
-require_once NOALYSS_INCLUDE.'/class_sort_table.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_payment.php';
+require_once NOALYSS_INCLUDE.'/lib/class_sort_table.php';
 //---------------------------------------------------------------------------
 // Common variable
 $td='<TD>';
diff --git a/include/periode.inc.php b/include/periode.inc.php
index f7e285a..b5cea54 100644
--- a/include/periode.inc.php
+++ b/include/periode.inc.php
@@ -22,8 +22,8 @@
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
 $gDossier=dossier::id();
-require_once NOALYSS_INCLUDE.'/class_iselect.php';
-require_once  NOALYSS_INCLUDE.'/class_periode.php';
+require_once NOALYSS_INCLUDE.'/lib/class_iselect.php';
+require_once  NOALYSS_INCLUDE.'/class/class_periode.php';
 echo '<div class="content">';
 $cn=new Database($gDossier);
 //-----------------------------------------------------
diff --git a/include/poste.inc.php b/include/poste.inc.php
index d140855..b9fee74 100644
--- a/include/poste.inc.php
+++ b/include/poste.inc.php
@@ -22,8 +22,8 @@
  *  action contains the sub action 
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_ihidden.php';
-require_once NOALYSS_INCLUDE.'/class_acc_parm_code.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ihidden.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_parm_code.php';
 echo '<div class="content">';
 
 $gDossier=dossier::id();
diff --git a/include/preod.inc.php b/include/preod.inc.php
index b2c8028..4cc88b6 100644
--- a/include/preod.inc.php
+++ b/include/preod.inc.php
@@ -23,12 +23,12 @@
  * \brief included file for managing the predefined operation
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_iselect.php';
-require_once NOALYSS_INCLUDE.'/class_icheckbox.php';
-require_once NOALYSS_INCLUDE.'/class_ihidden.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/ac_common.php';
-require_once NOALYSS_INCLUDE.'/class_pre_operation.php';
+require_once NOALYSS_INCLUDE.'/lib/class_iselect.php';
+require_once NOALYSS_INCLUDE.'/lib/class_icheckbox.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ihidden.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
+require_once NOALYSS_INCLUDE.'/class/class_pre_operation.php';
 
 /*
  * Value from $_GET or $_REQUEST
diff --git a/include/profile.inc.php b/include/profile.inc.php
index 958b886..e590df6 100644
--- a/include/profile.inc.php
+++ b/include/profile.inc.php
@@ -20,7 +20,7 @@
 // Copyright Author Dany De Bontridder address@hidden
 if (!defined('ALLOWED'))
     die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_profile_sql.php';
+require_once NOALYSS_INCLUDE.'/database/class_profile_sql.php';
 global $cn;
 
 //**********************************************
@@ -400,7 +400,7 @@ echo '</div>';
 echo '<div id="detail_profile" class="content">';
 if (isset($_POST['p_id']))
 {
-    require_once NOALYSS_INCLUDE.'/ajax_get_profile.php';
+    require_once NOALYSS_INCLUDE.'/ajax/ajax_get_profile.php';
     ?>
     <script>
         $('list_profile').hide()
diff --git a/include/recover.php b/include/recover.php
index 2d2db0e..8b4fb3a 100644
--- a/include/recover.php
+++ b/include/recover.php
@@ -23,7 +23,7 @@ if (!defined('RECOVER'))
 define('SIZE_REQUEST', 70);
 
 
-require_once NOALYSS_INCLUDE.'/class_html_input.php';
+require_once NOALYSS_INCLUDE.'/lib/class_html_input.php';
 /**
  * @brief generate a random string of char
  * @param $car int length of the string
@@ -62,8 +62,8 @@ if ($action=="") :
     </form>
     <?php
 elseif ($action=="send_email") :
-    require_once NOALYSS_INCLUDE.'/class_sendmail.php';
-    require_once NOALYSS_INCLUDE.'/class_database.php';
+    require_once NOALYSS_INCLUDE.'/lib/class_sendmail.php';
+    require_once NOALYSS_INCLUDE.'/lib/class_database.php';
     /*
      * Check if user exists, if yes save a recover request
      */
@@ -137,7 +137,7 @@ L\'email a été envoyé avec un lien et le nouveau mot de 
passe, vérifiez vos
 elseif ($action=="req") :
     $request_id=HtmlInput::default_value_request("req", "");
     if (strlen(trim($request_id))==SIZE_REQUEST) :
-        require_once NOALYSS_INCLUDE.'/class_database.php';
+        require_once NOALYSS_INCLUDE.'/lib/class_database.php';
         $cn=new Database(0);
 
         $value=$cn->get_value("select password from recover_pass where 
request=$1 and created_on > now() - interval '12 hours' and recover_on is 
null", array($request_id));
diff --git a/include/report.inc.php b/include/report.inc.php
index 88a1b40..5656d4c 100644
--- a/include/report.inc.php
+++ b/include/report.inc.php
@@ -23,16 +23,16 @@
  */
 if (!defined('ALLOWED'))
     die('Appel direct ne sont pas permis');
-require_once  NOALYSS_INCLUDE.'/ac_common.php';
+require_once  NOALYSS_INCLUDE.'/lib/ac_common.php';
 require_once  NOALYSS_INCLUDE.'/user_menu.php';
-require_once NOALYSS_INCLUDE.'/class_ifile.php';
-require_once NOALYSS_INCLUDE.'/class_ibutton.php';
-require_once NOALYSS_INCLUDE.'/class_acc_report.php';
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once  NOALYSS_INCLUDE.'/class_user.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ifile.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ibutton.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_report.php';
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
+require_once  NOALYSS_INCLUDE.'/class/class_user.php';
 require_once  NOALYSS_INCLUDE.'/user_menu.php';
-require_once NOALYSS_INCLUDE.'/class_ipopup.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ipopup.php';
 
 
 $gDossier=dossier::id();
diff --git a/include/restore.inc.php b/include/restore.inc.php
index de044b0..a3ae807 100644
--- a/include/restore.inc.php
+++ b/include/restore.inc.php
@@ -19,8 +19,8 @@
 
 // Copyright Author Dany De Bontridder address@hidden
 if ( !defined ('ALLOWED')) die('Forbidden');
-require_once NOALYSS_INCLUDE.'/class_iradio.php';
-require_once NOALYSS_INCLUDE.'/class_ifile.php';
+require_once NOALYSS_INCLUDE.'/lib/class_iradio.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ifile.php';
 
 /*!\file
  * \brief restaure a database
diff --git a/include/search.inc.php b/include/search.inc.php
index 1251c65..4098237 100644
--- a/include/search.inc.php
+++ b/include/search.inc.php
@@ -21,18 +21,18 @@
  * \brief Search module
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_dossier.php';
-require_once NOALYSS_INCLUDE.'/ac_common.php';
-require_once NOALYSS_INCLUDE.'/class_acc_ledger.php';
+require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
+require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_ledger.php';
 
 
 $gDossier=dossier::id();
 
-require_once NOALYSS_INCLUDE.'/class_database.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
 /* Admin. Dossier */
 
 $cn=new Database($gDossier);
-require_once  NOALYSS_INCLUDE.'/class_user.php';
+require_once  NOALYSS_INCLUDE.'/class/class_user.php';
 // display a search box
 
 
diff --git a/include/stock_cfg.inc.php b/include/stock_cfg.inc.php
index 3a133bc..871ced6 100644
--- a/include/stock_cfg.inc.php
+++ b/include/stock_cfg.inc.php
@@ -26,8 +26,8 @@
  *
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_stock_sql.php';
-require_once NOALYSS_INCLUDE.'/class_sort_table.php';
+require_once NOALYSS_INCLUDE.'/database/class_stock_sql.php';
+require_once NOALYSS_INCLUDE.'/lib/class_sort_table.php';
 
 global $g_user, $cn,$g_parameter;
 
diff --git a/include/stock_histo.inc.php b/include/stock_histo.inc.php
index 7481f8c..ea8c100 100644
--- a/include/stock_histo.inc.php
+++ b/include/stock_histo.inc.php
@@ -27,8 +27,8 @@
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
 global $g_user,$cn,$g_parameter;
-require_once NOALYSS_INCLUDE.'/class_stock.php';
-require_once NOALYSS_INCLUDE.'/class_periode.php';
+require_once NOALYSS_INCLUDE.'/class/class_stock.php';
+require_once NOALYSS_INCLUDE.'/class/class_periode.php';
 
 $stock=new Stock($cn);
 $array=$_GET;
diff --git a/include/stock_inv.inc.php b/include/stock_inv.inc.php
index 42cd1bd..5f2a4a8 100644
--- a/include/stock_inv.inc.php
+++ b/include/stock_inv.inc.php
@@ -26,8 +26,8 @@
  *
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_stock_goods.php';
-require_once NOALYSS_INCLUDE.'/class_stock.php';
+require_once NOALYSS_INCLUDE.'/class/class_stock_goods.php';
+require_once NOALYSS_INCLUDE.'/class/class_stock.php';
 global $cn;
 
 $inv=new Stock_Goods($cn);
diff --git a/include/stock_inv_histo.inc.php b/include/stock_inv_histo.inc.php
index 30279cf..60327ab 100644
--- a/include/stock_inv_histo.inc.php
+++ b/include/stock_inv_histo.inc.php
@@ -25,7 +25,7 @@
  *
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_exercice.php';
+require_once NOALYSS_INCLUDE.'/class/class_exercice.php';
 
 if ( isset($_POST['del']))
 {
diff --git a/include/stock_state.inc.php b/include/stock_state.inc.php
index f5d4ca2..46f1c23 100644
--- a/include/stock_state.inc.php
+++ b/include/stock_state.inc.php
@@ -27,7 +27,7 @@
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
 global $cn,$g_parameter,$g_user;
-require_once NOALYSS_INCLUDE.'/class_stock.php';
+require_once NOALYSS_INCLUDE.'/class/class_stock.php';
 
 // Show the form
 // Get by exercice
diff --git a/include/supplier.inc.php b/include/supplier.inc.php
index 4472e96..cb6a133 100644
--- a/include/supplier.inc.php
+++ b/include/supplier.inc.php
@@ -21,15 +21,15 @@
  * the supplier category
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_iselect.php';
-require_once NOALYSS_INCLUDE.'/class_ihidden.php';
-require_once NOALYSS_INCLUDE.'/class_supplier.php';
-require_once NOALYSS_INCLUDE.'/class_ibutton.php';
-require_once NOALYSS_INCLUDE.'/class_iaction.php';
-require_once NOALYSS_INCLUDE.'/class_fiche_def.php';
-require_once NOALYSS_INCLUDE.'/class_iaction.php';
-require_once NOALYSS_INCLUDE.'/class_fiche_def.php';
-require_once NOALYSS_INCLUDE.'/class_ipopup.php';
+require_once NOALYSS_INCLUDE.'/lib/class_iselect.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ihidden.php';
+require_once NOALYSS_INCLUDE.'/class/class_supplier.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ibutton.php';
+require_once NOALYSS_INCLUDE.'/lib/class_iaction.php';
+require_once NOALYSS_INCLUDE.'/class/class_fiche_def.php';
+require_once NOALYSS_INCLUDE.'/lib/class_iaction.php';
+require_once NOALYSS_INCLUDE.'/class/class_fiche_def.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ipopup.php';
 global $g_user;
 
 $low_action=(isset($_REQUEST['sb']))?$_REQUEST['sb']:"list";
diff --git a/include/template/action_show.php b/include/template/action_show.php
index 45fef3e..5286cee 100644
--- a/include/template/action_show.php
+++ b/include/template/action_show.php
@@ -25,7 +25,7 @@
  * @brief display the last action
  * inherited parameter  : $cn database connection, $array
  */
-require_once NOALYSS_INCLUDE.'/class_default_menu.php';
+require_once NOALYSS_INCLUDE.'/class/class_default_menu.php';
 $a_default=new Default_Menu();
 
 echo HtmlInput::title_box(_('Suivi'), 'action_list_div');
diff --git a/include/template/dashboard.php b/include/template/dashboard.php
index b182c67..a81bb1a 100644
--- a/include/template/dashboard.php
+++ b/include/template/dashboard.php
@@ -293,7 +293,7 @@ for($i=0;$i<count($last_ledger);$i++):
      echo 
HtmlInput::title_box(_('Suivi'),"last_operation_management_div",'zoom','onclick="action_show('.dossier::id().')"');
     ?>
     <?php
-    require_once NOALYSS_INCLUDE.'/class_follow_up.php';
+    require_once NOALYSS_INCLUDE.'/class/class_follow_up.php';
     $gestion=new Follow_Up($cn);
     $array=$gestion->get_last(MAX_ACTION_SHOW);
     $len_array=count($array);
diff --git a/include/template/document_mod_change.php 
b/include/template/document_mod_change.php
index c5a8423..66b7072 100644
--- a/include/template/document_mod_change.php
+++ b/include/template/document_mod_change.php
@@ -21,7 +21,7 @@
 /**\file
  * \brief this file respond to an ajax request to modify a type of document
  */
-require_once NOALYSS_INCLUDE.'/class_document_type.php';
+require_once NOALYSS_INCLUDE.'/class/class_document_type.php';
 echo HtmlInput::title_box(_('Type de document'),'change_doc_div');
 
 $doc_type=new Document_type($cn,$dt_id);
diff --git a/include/template/ledger_detail_ach.php 
b/include/template/ledger_detail_ach.php
index 9ead4ec..64a922a 100644
--- a/include/template/ledger_detail_ach.php
+++ b/include/template/ledger_detail_ach.php
@@ -5,7 +5,7 @@ $str_anc="";
 ?><?php require_once NOALYSS_INCLUDE.'/template/ledger_detail_top.php'; ?>
 <div class="content" style="padding:0;">
     <?php
-    require_once NOALYSS_INCLUDE.'/class_own.php';
+    require_once NOALYSS_INCLUDE.'/class/class_own.php';
     $owner = new Own($cn);
     ?>
 
diff --git a/include/template/ledger_detail_fin.php 
b/include/template/ledger_detail_fin.php
index e3b5fcd..51b4187 100644
--- a/include/template/ledger_detail_fin.php
+++ b/include/template/ledger_detail_fin.php
@@ -5,10 +5,10 @@ $str_anc="";
 ?><?php require_once NOALYSS_INCLUDE.'/template/ledger_detail_top.php'; ?>
 <div class="content" style="padding:0;">
 <?php 
-  require_once NOALYSS_INCLUDE.'/class_own.php';
+  require_once NOALYSS_INCLUDE.'/class/class_own.php';
   $owner=new Own($cn);
-require_once  NOALYSS_INCLUDE.'/class_anc_plan.php';
-require_once NOALYSS_INCLUDE.'/class_anc_operation.php';
+require_once  NOALYSS_INCLUDE.'/class/class_anc_plan.php';
+require_once NOALYSS_INCLUDE.'/class/class_anc_operation.php';
 
 ?>
     <?php if ( $access=='W') : ?>
diff --git a/include/template/ledger_detail_misc.php 
b/include/template/ledger_detail_misc.php
index 8e2bcbc..ecdd8f6 100644
--- a/include/template/ledger_detail_misc.php
+++ b/include/template/ledger_detail_misc.php
@@ -3,13 +3,13 @@
 //see licence.txt
 ?><?php 
 require_once NOALYSS_INCLUDE.'/template/ledger_detail_top.php';
-require_once NOALYSS_INCLUDE.'/class_anc_operation.php';
-require_once NOALYSS_INCLUDE.'/class_anc_plan.php';
+require_once NOALYSS_INCLUDE.'/class/class_anc_operation.php';
+require_once NOALYSS_INCLUDE.'/class/class_anc_plan.php';
  $str_anc="";
 ?>
 <?php 
-require_once NOALYSS_INCLUDE.'/class_own.php';
-require_once  NOALYSS_INCLUDE.'/class_anc_plan.php';
+require_once NOALYSS_INCLUDE.'/class/class_own.php';
+require_once  NOALYSS_INCLUDE.'/class/class_anc_plan.php';
 ?>
 <div class="content" style="padding:0">
 
@@ -86,7 +86,7 @@ require_once  NOALYSS_INCLUDE.'/class_anc_plan.php';
 
 <div class="myfieldset">
 <?php 
-  require_once NOALYSS_INCLUDE.'/class_own.php';
+  require_once NOALYSS_INCLUDE.'/class/class_own.php';
   $owner=new Own($cn);
 ?>
 <table class="result">
diff --git a/include/template/ledger_detail_top.php 
b/include/template/ledger_detail_top.php
index 7f6ca24..6be296a 100644
--- a/include/template/ledger_detail_top.php
+++ b/include/template/ledger_detail_top.php
@@ -26,5 +26,5 @@
 </div>
 <?php echo _("Opération ID")."=".hb($obj->det->jr_internal); ?>
 <div id="<?php echo $div.'info'?>" class="divinfo"></div>
-<?php require_once NOALYSS_INCLUDE.'/class_itextarea.php';
+<?php require_once NOALYSS_INCLUDE.'/lib/class_itextarea.php';
 ?>
\ No newline at end of file
diff --git a/include/template/ledger_detail_ven.php 
b/include/template/ledger_detail_ven.php
index 4ba39d4..34689af 100644
--- a/include/template/ledger_detail_ven.php
+++ b/include/template/ledger_detail_ven.php
@@ -11,7 +11,7 @@
  ?>
 <div class="content" style="padding:0;">
     <?php
-    require_once NOALYSS_INCLUDE.'/class_own.php';
+    require_once NOALYSS_INCLUDE.'/class/class_own.php';
     $owner = new Own($cn);
     ?>
 
diff --git a/include/template/letter_all.php b/include/template/letter_all.php
index 836809f..a27c030 100644
--- a/include/template/letter_all.php
+++ b/include/template/letter_all.php
@@ -2,8 +2,8 @@
 //This file is part of NOALYSS and is under GPL 
 //see licence.txt
 ?><?php
-require_once  NOALYSS_INCLUDE.'/class_acc_operation.php';
-require_once  NOALYSS_INCLUDE.'/class_acc_reconciliation.php';
+require_once  NOALYSS_INCLUDE.'/class/class_acc_operation.php';
+require_once  NOALYSS_INCLUDE.'/class/class_acc_reconciliation.php';
 $amount_deb=0;$amount_cred=0;
 $gDossier=dossier::id();
 global $g_failed;
diff --git a/include/template/letter_prop.php b/include/template/letter_prop.php
index 6ff77de..b2136da 100644
--- a/include/template/letter_prop.php
+++ b/include/template/letter_prop.php
@@ -2,8 +2,8 @@
 //This file is part of NOALYSS and is under GPL 
 //see licence.txt
 ?><?php
-require_once  NOALYSS_INCLUDE.'/class_acc_operation.php';
-require_once  NOALYSS_INCLUDE.'/class_acc_reconciliation.php';
+require_once  NOALYSS_INCLUDE.'/class/class_acc_operation.php';
+require_once  NOALYSS_INCLUDE.'/class/class_acc_reconciliation.php';
 
 $gDossier=dossier::id();
 if ( count($this->content) == 0 ) :
diff --git a/include/template/menu_detail.php b/include/template/menu_detail.php
index 954a10f..c415e4f 100644
--- a/include/template/menu_detail.php
+++ b/include/template/menu_detail.php
@@ -2,8 +2,8 @@
 //This file is part of NOALYSS and is under GPL 
 //see licence.txt
 ?><?php
-require_once NOALYSS_INCLUDE.'/class_html_input.php';
-require_once NOALYSS_INCLUDE.'/class_itext.php';
+require_once NOALYSS_INCLUDE.'/lib/class_html_input.php';
+require_once NOALYSS_INCLUDE.'/lib/class_itext.php';
 echo HtmlInput::title_box($msg,"divmenu");
 $str_code=new IText('me_code',$m->me_code);
 if ( $m->me_code != -1) $str_code->setReadOnly (true);
diff --git a/include/tva.inc.php b/include/tva.inc.php
index cebfc9c..4477b42 100644
--- a/include/tva.inc.php
+++ b/include/tva.inc.php
@@ -21,10 +21,10 @@
  * \brief included file for customizing with the vat (account,rate...)
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/class_own.php';
-require_once NOALYSS_INCLUDE.'/class_html_input.php';
-require_once NOALYSS_INCLUDE.'/class_ihidden.php';
-require_once NOALYSS_INCLUDE.'/class_itextarea.php';
+require_once NOALYSS_INCLUDE.'/class/class_own.php';
+require_once NOALYSS_INCLUDE.'/lib/class_html_input.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ihidden.php';
+require_once NOALYSS_INCLUDE.'/lib/class_itextarea.php';
 echo '<div class="content">';
 // Confirm remove
 if (isset($_POST['confirm_rm']))
diff --git a/include/user.inc.php b/include/user.inc.php
index 0d75f2a..9915e7f 100644
--- a/include/user.inc.php
+++ b/include/user.inc.php
@@ -26,7 +26,7 @@ if ( !defined ('ALLOWED')) die('Forbidden');
  * action=user_mgt
  *
  */
-require_once NOALYSS_INCLUDE.'/class_sort_table.php';
+require_once NOALYSS_INCLUDE.'/lib/class_sort_table.php';
 echo '<div class="content" style="width:80%;margin-left:10%">';
 /******************************************************/
 // Add user
diff --git a/include/user_common.php b/include/user_common.php
deleted file mode 100644
index aa8f67b..0000000
--- a/include/user_common.php
+++ /dev/null
@@ -1,248 +0,0 @@
-<?php
-/*
- *   This file is part of NOALYSS.
- *
- *   NOALYSS is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   NOALYSS is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with NOALYSS; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-
-
-
-
-// Copyright Author Dany De Bontridder address@hidden
-
-require_once NOALYSS_INCLUDE.'/class_database.php';
-require_once NOALYSS_INCLUDE.'/class_icheckbox.php';
-require_once NOALYSS_INCLUDE.'/class_ihidden.php';
-require_once NOALYSS_INCLUDE.'/class_document.php';
-require_once NOALYSS_INCLUDE.'/class_acc_operation.php';
-/*! \file
- * \brief Common functions
- */
-
-/*!
- *\brief   test if a jrn op is valid
- *
- * \param $p_cn db
- * \param $p_grpt_id
- * \return:
- *        - 1 is valid
- *        - 0 is not valid
- */
-function isValid_deprecrated ($p_cn,$p_grpt_id)
-{
-    $Res=$p_cn->exec_sql("select jr_valid from jrn where 
jr_grpt_id=$p_grpt_id");
-
-    if ( ( $M = Database::num_row($Res)) == 0 ) return 0;
-
-    $a=Database::fetch_array($Res,0);
-
-    if ( $a['jr_valid'] == 't') return 1;
-    if ( $a['jr_valid'] == 'f') return 0;
-
-    echo_error ("Invalid result = ".$a['result']);
-
-
-}
-
-/*!
- **************************************************
- *\brief
- *     Create a navigation_bar (pagesize)
- *
- * \param $p_offset first record number
- * \param $p_line total of returned row
- * \param $p_size current g_pagesize user's preference
- * \param $p_page number of the page where the user is
- * \param $p_javascript javascript code to add
- * \note example :
-\verbatim
-   $step=$_SESSION['g_pagesize'];
-   $page=(isset($_GET['offset']))?$_GET['page']:1;
-   $offset=(isset($_GET['offset']))?$_GET['offset']:0;
-
-   list ($max_ligne,$list)=ListJrn($cn,$_GET['p_jrn'],$sql,null,$offset,1);
-   $bar=navigation_bar($offset,$max_ligne,$step,$page);
-\endverbatim
- * \return   string with the nav. bar
- */
-function navigation_bar($p_offset,$p_line,$p_size=0,$p_page=1,$p_javascript="")
-{
-    // if the pagesize is unlimited return ""
-    // in that case there is no nav. bar
-    if ( $_SESSION['g_pagesize'] == -1  ) return "";
-    if ( $p_size==0)
-    {
-        $p_size= $_SESSION['g_pagesize'];
-    }
-    // if there is no row return an empty string
-    if ( $p_line == 0 ) return "";
-
-    // Clean url, cut away variable coming frm here
-    $url=cleanUrl();
-    // action to clean
-    $url=str_replace('&p_action=delete','',$url);
-
-    // compute max of page
-    $nb_page=($p_line-($p_line%$p_size))/$p_size;
-    // if something remains
-    if ( $p_line % $p_size != 0 ) $nb_page+=1;
-
-    // if max page == 1 then return a empty string
-    if ( $nb_page == 1) return "";
-
-    // restore the sort
-    if ( isset($_GET['o']))
-        $url=$url.'&o='.$_GET['o'];
-
-    $r="";
-    // previous
-    if ($p_page !=1)
-    {
-        $e=$p_page-1;
-        $step=$p_size;
-        $offset=($e-1)*$step;
-
-        $r='<A class="mtitle" 
href="'.basename($_SERVER['SCRIPT_FILENAME'])."?".$url."&offset=$offset&step=$step&page=$e&size=$step".'"
 '.$p_javascript.'>';
-        $r.="  &larr;";
-        // $r.='<INPUT TYPE="IMAGE" width="12" SRC="image/go-previous.png">';
-        $r.="</A>&nbsp;&nbsp;";
-    }
-    //----------------------------------------------------------------------
-    // Create a partial bar
-    // if current page < 11 show 1 to 20
-    // otherwise            show $p_page -10 to $p_page + 10
-    //----------------------------------------------------------------------
-    $start_bar=($p_page < 11 )?1:$p_page-10;
-    $end_bar  =($p_page < 11 )?20:$p_page+10;
-    $end_bar  =($end_bar > $nb_page )?$nb_page:$end_bar;
-
-       $sep="";
-    // Create the bar
-    for ($e=$start_bar;$e<=$end_bar;$e++)
-    {
-        // do not included current page
-        if ( $e != $p_page )
-        {
-            $step=$p_size;
-            $offset=($e-1)*$step;
-
-            
$go=$_SERVER['PHP_SELF']."?".$url."&offset=$offset&step=$step&page=$e&size=$step";
-                       $r.=$sep;
-            $r.=sprintf('<A class="nav" HREF="%s"  %s 
>%d</A>&nbsp;',$go,$p_javascript,$e);
-                       $sep=" &#8231;  ";
-        }
-        else
-        {
-                       $r.=$sep;
-            $r.="<b> [ $e ] </b>";
-                       $sep=" &#8231;  ";
-        } //else
-    } //for
-    // next
-
-    if ($p_page !=$nb_page)
-    {
-        // If we are not at the last page show the button next
-        $e=$p_page+1;
-        $step=$p_size;
-        $offset=($e-1)*$step;
-
-        $r.='&nbsp;<A class="mtitle" 
href="'.$_SERVER['PHP_SELF']."?".$url."&offset=$offset&step=$step&page=$e&size=$step".'"
 '.$p_javascript.' >';
-        $r.="&rarr;";
-        //$r.='<INPUT TYPE="IMAGE" width="12" SRC="image/go-next.png">';
-        $r.="</A>";
-    }
-
-
-    return $r;
-}
-
-/*!
- * \brief Clean the url, remove the $_GET offset,step, page and size
- * \param none
- *
- * \return the cleaned url
- */
-
-function CleanUrl()
-{
-    // Compute the url
-    $url="";
-    $and="";
-    $get=$_GET;
-    if ( isset ($get) )
-    {
-        foreach ($get as $name=>$value )
-        {
-            // we clean the parameter offset, step, page and size
-            if (  ! 
in_array($name,array('offset','step','page','size','s','o','r_jrn')))
-            {
-                $url.=$and.$name."=".$value;
-                $and="&";
-            }// if
-        }//foreach
-        if ( isset($_GET['r_jrn']))
-        {
-            $r_jrn=$_GET['r_jrn'];
-            if (count($r_jrn) > 0 )
-            {
-                foreach ($r_jrn as $key=>$value)
-                {
-                    $url.=$and."r_jrn[$key]=".$value;
-                    $and="&";
-                }
-            }
-        }
-    }// if
-    return $url;
-}
-function redirect($p_string,$p_time=0)
-{
-    if (strpos( $p_string,'?') == 0 ) {
-        $p_string = $p_string.'?v='.microtime(true);
-    }
-    echo '<HTML><head><META HTTP-EQUIV="REFRESH" 
content="'.$p_time.';url='.$p_string.'"></head><body> Connecting... 
</body></html>';
-}
-/*!\brief remove the useless space, change comma by period and try to return
- * a number
- *\param $p_num number to format
- *\return the formatted number
- */
-function toNumber($p_num)
-{
-    $p_num=trim($p_num);
-    if ($p_num=='') return 0;
-    $p_num=str_replace("'",'',$p_num);
-    $p_num=str_replace(',','.',$p_num);
-    return $p_num;
-}
-/**
- * Check that all the index are in the array, used by function to check if
- * the array contains the needed variables before an extract
- * @param type $p_array array to check
- * @param type $needed string containing variable separated by comma
- * @throws Exception
- */
-function check_parameter($p_array,$p_needed)
-{
-    $needed =explode(',',$p_needed);
-    for ($e=0;$e<count($needed);$e++) {
-            if ( ! isset($p_array[$needed[$e]])) {
-                throw new Exception (_('Paramètre manquant')." ".$needed[$e]);
-            }
-        }
-}
-?>
diff --git a/include/user_detail.inc.php b/include/user_detail.inc.php
index 52e4901..0ea2630 100644
--- a/include/user_detail.inc.php
+++ b/include/user_detail.inc.php
@@ -21,10 +21,10 @@
  * \brief Users Security
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
-require_once NOALYSS_INCLUDE.'/ac_common.php';
-require_once NOALYSS_INCLUDE.'/class_database.php';
+require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
+require_once NOALYSS_INCLUDE.'/lib/class_database.php';
 require_once NOALYSS_INCLUDE.'/user_menu.php';
-require_once  NOALYSS_INCLUDE.'/class_user.php';
+require_once  NOALYSS_INCLUDE.'/class/class_user.php';
 
 $rep = new Database();
 
@@ -92,7 +92,7 @@ else if ($sbaction == "delete")
     $Res = $cn->exec_sql("delete from ac_users where use_id=$1", array($uid));
 
     echo "<center><H2 class=\"info\"> Utilisateur " . h($_POST['fname']) . " " 
. h($_POST['lname']) . " est effacé</H2></CENTER>";
-    require_once NOALYSS_INCLUDE.'/class_iselect.php';
+    require_once NOALYSS_INCLUDE.'/lib/class_iselect.php';
     require_once NOALYSS_INCLUDE.'/user.inc.php';
     return;
 }
diff --git a/include/user_menu.php b/include/user_menu.php
index 76b8a37..add9409 100644
--- a/include/user_menu.php
+++ b/include/user_menu.php
@@ -23,9 +23,9 @@
 
 // Copyright Author Dany De Bontridder address@hidden
 
-require_once NOALYSS_INCLUDE.'/class_idate.php';
-require_once NOALYSS_INCLUDE.'/class_icard.php';
-require_once NOALYSS_INCLUDE.'/class_ispan.php';
+require_once NOALYSS_INCLUDE.'/lib/class_idate.php';
+require_once NOALYSS_INCLUDE.'/lib/class_icard.php';
+require_once NOALYSS_INCLUDE.'/lib/class_ispan.php';
 
 
 
diff --git a/include/verif_bilan.inc.php b/include/verif_bilan.inc.php
index 8e75136..a11c5aa 100644
--- a/include/verif_bilan.inc.php
+++ b/include/verif_bilan.inc.php
@@ -24,8 +24,8 @@
  */
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
 
-require_once  NOALYSS_INCLUDE.'/class_user.php';
-require_once NOALYSS_INCLUDE.'/class_acc_bilan.php';
+require_once  NOALYSS_INCLUDE.'/class/class_user.php';
+require_once NOALYSS_INCLUDE.'/class/class_acc_bilan.php';
 
 global $g_captcha,$g_failed,$g_succeed;
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]