diff --git a/html/ajax_card.php b/html/ajax_card.php
index dc919297d..b3e81bdb2 100644
--- a/html/ajax_card.php
+++ b/html/ajax_card.php
@@ -133,13 +133,17 @@ case 'bc':
/* ------------------------------------------------------------ */
case 'st':
$sql="select fd_id,fd_label from fiche_def";
- if ( isset($cat)) {
- $sql=$sql.sprintf(' where frd_id = '.FormatString ($cat));
- }
- if ( !isset($cat) && isset($fil) && strlen(trim($fil)) > 0 ){
- $sql=$sql.sprintf(" where fd_id in (%s)",
- FormatString($fil));
- }
+ if ( $ledger != -1 ) {
+ $l=new Acc_Ledger($cn,$ledger);
+ $sql.=' where fd_id in ('.$l->get_all_fiche_def().')';
+ } else
+ if ( isset($cat)) {
+ $sql=$sql.sprintf(' where frd_id = '.FormatString ($cat));
+ } else
+ if ( isset($fil) && strlen(trim($fil)) > 0 ){
+ $sql=$sql.sprintf(" where fd_id in (%s)",
+ FormatString($fil));
+ }
$array=$cn->make_array($sql);
if ( empty($array)) {
$html=_("Aucune catégorie de fiche ne correspondant à".
diff --git a/html/js/card.js b/html/js/card.js
index 7ee775f3c..24a632289 100644
--- a/html/js/card.js
+++ b/html/js/card.js
@@ -269,13 +269,23 @@ function select_card_type(obj) {
$(content).innerHTML='';
showIPopup($(obj).ipopup);
var dossier=$('gDossier').value;
+
+ // give a filter, -1 if not
var filter=$(obj).filter;
if ( filter==undefined) {filter=-1;}
+
+
var queryString='?gDossier='+dossier;
queryString+='&ctl='+content;
queryString+='&op=st'; // st for selecting type
if ( $(obj).win_refresh!=undefined) { queryString+='&ref';}
queryString+='&fil='+filter;
+ // filter on the ledger, -1 if not
+ var oledger=$(obj).jrn;
+ if (oledger==undefined) {ledger=-1;} else {ledger=g('p_jrn').value;}
+
+ queryString+='&ledger='+ledger;
+
if ( obj.type_cat) { queryString+='&cat='+obj.type_cat;}
var action=new Ajax.Request ( 'ajax_card.php',
diff --git a/include/class_acc_ledger.php b/include/class_acc_ledger.php
index 24b82e3f0..ed91707e0 100644
--- a/include/class_acc_ledger.php
+++ b/include/class_acc_ledger.php
@@ -1314,8 +1314,7 @@ jr_comment||' ('||jr_internal||')'||case when jr_pj_number is not null and jr_pj
$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->set_attribute('jrn',$this->id);
+ $f_add_button->set_attribute('jrn',$this->id);
$f_add_button->javascript=" select_card_type(this);";
$ret.=$f_add_button->input();
// show compute
@@ -1854,9 +1853,9 @@ jr_comment||' ('||jr_internal||')'||case when jr_pj_number is not null and jr_pj
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_type = $1 ";
+ " jrn_def_id = $1 ";
- $r=$this->db->exec_sql($sql,array($this->type));
+ $r=$this->db->exec_sql($sql,array($this->id));
$res=Database::fetch_all($r);
if ( empty($res) ) return null;
diff --git a/include/class_acc_ledger_fin.php b/include/class_acc_ledger_fin.php
index 5c005101c..d7993f779 100644
--- a/include/class_acc_ledger_fin.php
+++ b/include/class_acc_ledger_fin.php
@@ -181,7 +181,7 @@ class Acc_Ledger_Fin extends Acc_Ledger {
$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->set_attribute('jrn',$this->id);
$f_add_button->javascript=" select_card_type(this);";
$str_add_button=$f_add_button->input();
diff --git a/include/class_acc_ledger_purchase.php b/include/class_acc_ledger_purchase.php
index 4ef4a5de4..8f486eacd 100644
--- a/include/class_acc_ledger_purchase.php
+++ b/include/class_acc_ledger_purchase.php
@@ -727,8 +727,7 @@ array
$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->set_attribute('jrn',$this->id);
+ $f_add_button->set_attribute('jrn',$this->id);
$f_add_button->javascript=" select_card_type(this);";
$f_add_button2=new IButton('add_card2');
diff --git a/include/class_acc_ledger_sold.php b/include/class_acc_ledger_sold.php
index 317677510..dd3d3e8b0 100644
--- a/include/class_acc_ledger_sold.php
+++ b/include/class_acc_ledger_sold.php
@@ -858,8 +858,7 @@ class Acc_Ledger_Sold extends Acc_Ledger {
$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->set_attribute('jrn',$this->id);
+ $f_add_button->set_attribute('jrn',$this->id);
$f_add_button->javascript=" select_card_type(this);";
$f_add_button2=new IButton('add_card2');