From d39ac28002bc42abc8e9ee648ff1f15832409785 Mon Sep 17 00:00:00 2001 From: sparkyx Date: Sun, 29 Dec 2024 14:53:45 +0100 Subject: [PATCH] =?UTF-8?q?Task=20#0002402:=20TVA=20:=20pr=C3=A9f=C3=A9ren?= =?UTF-8?q?ce=20,=20permettre=20de=20choisir=20l'ID=20ou=20le=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- html/ajax.php | 2 ++ html/ajax_misc.php | 1 + html/do.php | 2 ++ include/ajax/ajax_preference.php | 18 ++++++++++++++++++ include/class/noalyss_user.class.php | 21 ++++++++++++++++++++- include/lib/itva_popup.class.php | 26 ++++++++++++++++++++++++-- 6 files changed, 67 insertions(+), 3 deletions(-) diff --git a/html/ajax.php b/html/ajax.php index 2d32d7521..a58f7a40b 100644 --- a/html/ajax.php +++ b/html/ajax.php @@ -37,6 +37,8 @@ $g_parameter=new Noalyss_Parameter_Folder($cn); $g_user=new Noalyss_user($cn); $g_user->check(true); IDate::set_firstDate($g_user->get_first_week_day()); +ITva_Popup::set_vat_code($g_user->get_vat_code_preference()); + set_language(); /* if a code has been asked */ if (isset($_REQUEST['plugin_code']) ) diff --git a/html/ajax_misc.php b/html/ajax_misc.php index 7f40a9c42..ce27ce175 100644 --- a/html/ajax_misc.php +++ b/html/ajax_misc.php @@ -98,6 +98,7 @@ else } IDate::set_firstDate($g_user->get_first_week_day()); +ITva_Popup::set_vat_code($g_user->get_vat_code_preference()); // For progress bar, for saving time , we check and answer directly if ($op == "progressBar") { diff --git a/html/do.php b/html/do.php index 88ad76d4d..cfbedb552 100644 --- a/html/do.php +++ b/html/do.php @@ -58,7 +58,9 @@ $cn = Dossier::connect(); global $g_user, $cn,$g_parameter,$http; $g_user = new Noalyss_user($cn); $http=new HttpInput(); + IDate::set_firstDate($g_user->get_first_week_day()); +ITva_Popup::set_vat_code($g_user->get_vat_code_preference()); // check that the current user is saved into PostgreSQL setting in order to use it in PLPGSQL \Noalyss\Dbg::echo_var(1,sprintf("current user is [%s]",$cn->get_value("select current_setting('noalyss.user_login')"))); diff --git a/include/ajax/ajax_preference.php b/include/ajax/ajax_preference.php index e170e949e..f0374f5ec 100644 --- a/include/ajax/ajax_preference.php +++ b/include/ajax/ajax_preference.php @@ -192,6 +192,22 @@ if ( $action == 'display_form' ) + + + + + + value=array( + ['label'=>'numérique','value'=>0], + ['label'=>'Code','value'=>1] + ); + $selVATCode->selected=$g_user->get_vat_code_preference(); + echo $selVATCode->input(); + ?> + +
@@ -305,6 +321,7 @@ if ($action == 'save') $csv_decimal=$http->post("csv_decimal","number"); $csv_encoding=$http->post("csv_encoding"); $firstday=$http->post("selFirstDay","number"); + $vatCode=$http->post("selVATCode","number"); $password="OK"; $msg =""; if (noalyss_strlentrim($pass_1) != 0 && noalyss_strlentrim($pass_2) != 0) @@ -344,6 +361,7 @@ if ($action == 'save') $g_user->save_global_preference('csv_decimal', $csv_decimal); $g_user->save_global_preference('csv_encoding', $csv_encoding); $g_user->save_global_preference('first_week_day', $firstday); + $g_user->save_global_preference('vat_code', $vatCode); $g_user->save_email($p_email); $_SESSION[SESSION_KEY.'g_theme']=$style_user; diff --git a/include/class/noalyss_user.class.php b/include/class/noalyss_user.class.php index d05ae8d53..09a46557d 100644 --- a/include/class/noalyss_user.class.php +++ b/include/class/noalyss_user.class.php @@ -1819,7 +1819,8 @@ class Noalyss_User } /** - * + *@brief first day in calendar + * @see IDate::set_firstDate( */ function get_first_week_day() { @@ -1849,6 +1850,24 @@ class Noalyss_User } } } + /** + *@brief Get preference , either the user see the numeric id for VAT or its code, if the preference doesn't exist + * by default , 0 is saved in ACCOUNT_REPOSITORY + * @see ITva_Popup::set_vat_code() + * @see ITva_Popup + */ + function get_vat_code_preference():int + { + $repocn=new Database(); + $result=$repocn->get_value("select parameter_value from user_global_pref where parameter_type=$1 and user_id=$2 ", + array("vat_code", $this->login)); + if ($repocn->count()==0) + { + $this->save_global_preference("vat_code", 0); + return 0; + } + return $result; + } } ?> diff --git a/include/lib/itva_popup.class.php b/include/lib/itva_popup.class.php index 13bb6b3bc..8b373afa6 100644 --- a/include/lib/itva_popup.class.php +++ b/include/lib/itva_popup.class.php @@ -53,6 +53,7 @@ class ITva_Popup extends HtmlInput * by default it is 'popup_select_tva(this)'; */ private $filter; //!< filter the VAT by ledger PURCHASE or SALE or NO FILTER, default=NO + static $vat_code=0; //code)) { if ($this->cn != NULL) { + $cnx=Dossier::connect(); /* 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', + $this->code->value = $cnx->get_value('select tva_label from tva_rate where tva_id=$1', array($this->value));; } $this->set_attribute('jcode', $this->code->name); @@ -139,7 +141,13 @@ class ITva_Popup extends HtmlInput } $strAttribut = $this->get_node_attribute(); - + // show tva code + if ( self::$vat_code == 1) { + if ( isNumber($this->value ) == 1) { + $cnx=Dossier::connect(); + $this->value=$cnx->get_value('select tva_code from tva_rate where tva_id=$1',[$this->value]); + } + } $str = ''; @@ -226,6 +234,19 @@ list="dl_tva_%s" autocomplete="off">'; $this->code = new ISpan($p_code); } + /** + * @brief show the Numeric ID or the code + * @param int $vat_code 0 for numeric , 1 for Code + * @return void + * @throws Exception if $vat_code is + */ + static function set_vat_code(int $vat_code) + { + if (isNumber($vat_code)==0){ + throw new Exception("VAT_CODE [{$vat_code}]: invalide data",EXC_INVALID); + } + self::$vat_code= $vat_code; + } static public function test_me() { @@ -240,4 +261,5 @@ list="dl_tva_%s" autocomplete="off">'; echo $tva->dbutton(); } + }