From f082ccb7ab29fd8536f1e06bd5c4676d0bf40b94 Mon Sep 17 00:00:00 2001 From: sparkyx Date: Wed, 10 Dec 2025 17:45:20 +0100 Subject: [PATCH] Acc_Ledger_Search : let you add you own column --- include/class/acc_ledger_search.class.php | 43 +++++++++++++++++++---- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/include/class/acc_ledger_search.class.php b/include/class/acc_ledger_search.class.php index bf211a5b3..60ef7d600 100644 --- a/include/class/acc_ledger_search.class.php +++ b/include/class/acc_ledger_search.class.php @@ -38,10 +38,12 @@ class Acc_Ledger_Search private $all; //!< Flag to indicate if all ledgers must be searched (1 for yes) private $div; //!< prefix for id of DOM id var $id ; //!< id of the ledger - private $inject_col; //< inject_code (string) code into list_operation + public $inject_col; //!< inject_code (callback function ) into list_operation // to add an extra column // (see Acc_Ledger_Search::list_operation). // All the HTML code must be in inject_code, including the TD tag + // example $this->inject_col = function() {echo "} + /** * @brief return a HTML string with the form for the search @@ -108,7 +110,6 @@ class Acc_Ledger_Search * @see build_search_sql * @see display_search_form * @see list_operation - * @example search_acc_operation.php */ function search_form() { @@ -797,10 +798,34 @@ class Acc_Ledger_Search * \see display_search_form * \see search_form @note $this->inject_code (string) code into Acc_Ledger_Search::list_operation - // to add an extra column - // (see Acc_Ledger_Search::list_operation). - // All the HTML code must be in inject_code, including the TD tag - * \return HTML string + * Example of using inject_col to inject a new column + * @code + %s // %s", $param['jr_id'], $param['jr_montant']); + } elseif ($param == 'header') + { + + return ' Operation & montant'; + } +} + +$acc_ledger_search = new Acc_Ledger_Search('VEN', 1, 1); +$acc_ledger_search->inject_col = "inject_col"; + +list($sql, $where) = $acc_ledger_search->build_search_sql($_GET); +list($nb_count, $html) = $acc_ledger_search->list_operation($sql . " and " . $where, 0); + +printf("There are %s rows", $nb_count); +print $html; + + * @endcode + * \return array($count, $html_code); */ public function list_operation($sql, $offset, $p_paid=0) { @@ -888,6 +913,10 @@ class Acc_Ledger_Search } $r.=""._('Concerne').""; $r.=""._('Document').""; + if ( $this->inject_col != null) + { + $r.=call_user_func($this->inject_col,"header"); + } $r.=""; // Total Amount $tot=0.0; @@ -1055,7 +1084,7 @@ class Acc_Ledger_Search // All the HTML code must be in inject_code, including the TD tag if ( $this->inject_col != null) { - $r.=$this->inject_col; + $r.=call_user_func($this->inject_col,$row); } // end row $r.="";