From bec8b39afa1dcc0a21320b1adf8743aac9920966 Mon Sep 17 00:00:00 2001 From: sparkyx Date: Fri, 1 Aug 2025 17:43:04 +0200 Subject: [PATCH] E-Invoice : adapt VAT, add code for Peppol --- include/class/tva_rate_mtable.class.php | 42 +++++++++++++++++------ include/database/tva_rate_sql.class.php | 2 ++ include/database/v_tva_rate_sql.class.php | 2 ++ sql/upgrade.sql | 27 +++++++++++++-- 4 files changed, 61 insertions(+), 12 deletions(-) diff --git a/include/class/tva_rate_mtable.class.php b/include/class/tva_rate_mtable.class.php index 8d7897868..c722c27a5 100644 --- a/include/class/tva_rate_mtable.class.php +++ b/include/class/tva_rate_mtable.class.php @@ -46,6 +46,7 @@ class Tva_Rate_MTable extends Manage_Table_SQL function __construct(V_Tva_rate_SQL $p_table) { parent::__construct($p_table); + $this->icon_mod='left'; $this->set_col_label("tva_id", _("id")); $this->set_col_label("tva_code", _("Code")); $this->set_col_label("tva_label", _("label")); @@ -55,8 +56,10 @@ class Tva_Rate_MTable extends Manage_Table_SQL $this->set_col_label("tva_reverse_account", _('Poste comptable autoliquidation')); $this->set_col_label("tva_sale", _("TVA Vente (C)")); $this->set_col_label("tva_purchase", _("TVA Achat (D)")); + $this->set_col_label("tva_peppol_code", _("Code Facture électronique")); $this->set_property_visible('tva_reverse_account', false); + $this->set_property_visible('tva_peppol_code', false); $this->set_col_type("tva_both_side", "select", array( @@ -89,7 +92,8 @@ class Tva_Rate_MTable extends Manage_Table_SQL 'tva_sale'=>_("Ne donnez pas ce poste comptable si ce code n'est pas utilisé à la vente"), 'tva_payment_purchase'=>_('TVA due ou récupérable quand l\'opération est payée ou exécutée'), 'tva_payment_sale'=>_('TVA due ou récupérable quand l\'opération est payée ou exécutée'), - 'tva_reverse_account'=>_("Forcer ce poste comptable pour autoliquidation : par défault, le poste d'autoliquidation est calculé : soit celui qui est en contrepartie, soit le même (voir manuel)") + 'tva_reverse_account'=>_("Forcer ce poste comptable pour autoliquidation : par défault, le poste d'autoliquidation est calculé : soit celui qui est en contrepartie, soit le même (voir manuel)"), + 'tva_peppol_code'=>_("Code TVA est utilisé pour les factures électroniques, plus d'information dans le manuel") ); } @@ -120,6 +124,7 @@ class Tva_Rate_MTable extends Manage_Table_SQL { $nb_order=count($this->a_order); $this->set_property_visible('tva_reverse_account', true); + $this->set_property_visible('tva_peppol_code', true); echo ""; for ($i=0; $i<$nb_order; $i++) { @@ -181,15 +186,21 @@ class Tva_Rate_MTable extends Manage_Table_SQL $text->set_attribute('account', 'tva_sale'); $text->size=$min_size; echo $text->input(); - } - elseif ($this->a_type[$key]=="text") - { - $text=new IText($key); - $text->value=$value; - $min_size=(strlen($value??"")<30)?30:strlen($value)+5; - $text->size=$min_size; + }elseif ($key=='tva_peppol_code') { + $text=new ISelect('tva_peppol_code'); + $text->selected=$value; + $text->transform(array( + null=>_('-') + ,"S"=>_('Taux standard') + ,'AE'=>_('Autoliquidate mais pas INTRACOMM.') + ,'Z'=>_("TVA à 0%") + ,'K'=>_('Autoliquidation INTRACOMM.') + ,'G'=>_('TVA exempt pour export hors Europe') + ,'O'=>_('TVA Hors périmètre application') + ,'E'=>_('Exempté de TVA') + )); echo $text->input(); - } elseif ($key == "tva_id") { + }elseif ($key == "tva_id") { $inum=new INum($key,$value); echo $inum->input(); echo \HtmlInput::hidden("old_tva_id",$value); @@ -204,6 +215,13 @@ class Tva_Rate_MTable extends Manage_Table_SQL $text->set_attribute('account', 'tva_reverse_account'); $text->size=$min_size; echo $text->input(); + }elseif ($this->a_type[$key]=="text") + { + $text=new IText($key); + $text->value=$value; + $min_size=(strlen($value??"")<30)?30:strlen($value)+5; + $text->size=$min_size; + echo $text->input(); } echo ""; } @@ -233,6 +251,7 @@ class Tva_Rate_MTable extends Manage_Table_SQL parent::from_request(); $http=new \HttpInput(); $this->table->tva_reverse_account=$http->request('tva_reverse_account'); + $this->table->tva_peppol_code=$http->request('tva_peppol_code'); } /** @@ -270,6 +289,7 @@ class Tva_Rate_MTable extends Manage_Table_SQL $tva_rate->setp("tva_comment", $this->table->tva_comment); $tva_rate->setp("tva_both_side", $this->table->tva_both_side); $tva_rate->setp("tva_reverse_account", $this->table->tva_reverse_account); + $tva_rate->setp("tva_peppol_code", $this->table->tva_peppol_code); // TVA accounting must be joined and separated with a comma $tva_purchase=(trim($this->table->tva_purchase)=="")?"#":$this->table->tva_purchase; @@ -285,7 +305,9 @@ class Tva_Rate_MTable extends Manage_Table_SQL if ( $this->previous_id != - 1 && $this->previous_id != $new_tva_id) { $cn->exec_sql("update tva_rate set tva_id = $1 where tva_id = $2",[$new_tva_id,$this->previous_id]); $this->table->setp("tva_id",$new_tva_id); - }else $this->table->setp("tva_id",$tva_rate->getp("tva_id")); + }else { + $this->table->setp("tva_id",$tva_rate->getp("tva_id")); + } } /** diff --git a/include/database/tva_rate_sql.class.php b/include/database/tva_rate_sql.class.php index 9043d0605..f236ad6b0 100644 --- a/include/database/tva_rate_sql.class.php +++ b/include/database/tva_rate_sql.class.php @@ -52,6 +52,7 @@ class Tva_Rate_SQL extends Table_Data_SQL ,"tva_payment_sale"=>"tva_payment_sale" ,"tva_code"=>"tva_code" ,'tva_reverse_account'=>'tva_reverse_account' + ,'tva_peppol_code'=>'tva_peppol_code' ); /* * Type of columns @@ -67,6 +68,7 @@ class Tva_Rate_SQL extends Table_Data_SQL ,"tva_payment_sale"=>"text" ,"tva_code"=>"text" ,'tva_reverse_account'=>'text' + ,'tva_peppol_code'=>'text' ); diff --git a/include/database/v_tva_rate_sql.class.php b/include/database/v_tva_rate_sql.class.php index 5d74a662b..962fa3bd5 100644 --- a/include/database/v_tva_rate_sql.class.php +++ b/include/database/v_tva_rate_sql.class.php @@ -52,6 +52,7 @@ class V_Tva_Rate_SQL extends Table_Data_SQL ,'tva_reverse_account'=>'tva_reverse_account' ,'tva_payment_purchase'=>'tva_payment_purchase' ,'tva_payment_sale'=>'tva_payment_sale' + ,'tva_peppol_code'=>'tva_peppol_code' ); /* @@ -69,6 +70,7 @@ class V_Tva_Rate_SQL extends Table_Data_SQL ,'tva_reverse_account'=>'text' , 'tva_payment_purchase'=>'text' , 'tva_payment_sale'=>'text' + ,'tva_peppol_code'=>'text' ); diff --git a/sql/upgrade.sql b/sql/upgrade.sql index 1b13d358b..50aa9df51 100644 --- a/sql/upgrade.sql +++ b/sql/upgrade.sql @@ -16,7 +16,7 @@ update "parameter" set pr_id='MY_POSTCODE' where pr_id='MY_CP'; update "parameter" set pr_id='MY_CITY' where pr_id='MY_COMMUNE'; update "parameter" set pr_id='MY_COUNTRY' where pr_id='MY_PAYS'; -insert into attr_def (ad_id,ad_text,ad_type,ad_size,ad_search_followup,ad_default_order) values(55,'SIREN','text',20,1,14); +insert into attr_def (ad_id,ad_text,ad_type,ad_size,ad_search_followup,ad_default_order) values(55,'SIRENE','text',20,1,14); insert into attr_def (ad_id,ad_text,ad_type,ad_size,ad_search_followup,ad_default_order) values(56,'SIRET','text',20,1,15); insert into attr_def (ad_id,ad_text,ad_type,ad_size,ad_search_followup,ad_default_order) values(58,'PEPPOL ID','text',20,1,15); @@ -233,7 +233,30 @@ insert into parameter_extra(pe_code,pe_label) values ('COMPANY_LEGAL_ENTITY','Fo insert into parameter_extra(pe_code,pe_label) values ('COMPANY_BANK_IBAN','Compte en banque (IBAN)') on conflict do nothing; insert into parameter_extra(pe_code,pe_label) values ('COMPANY_BANK_BIC','BIC Bank Identification Code') on conflict do nothing; insert into parameter_extra(pe_code,pe_label) values ('COMPANY_UBL_ID','ID PEPPOL') on conflict do nothing; -insert into parameter_extra(pe_code,pe_label) values ('SIREN','n° SIREN') on conflict do nothing; +insert into parameter_extra(pe_code,pe_label) values ('SIRENE','n° SIRENE') on conflict do nothing; insert into parameter_extra(pe_code,pe_label) values ('SIRET','n° SIRET') on conflict do nothing; +-- for all customers and suppliers add new attribut : FICHE_DEF_REF.FRD_ID 8 and 9 ?? +-- TVA , PEPPOL ID , SIRENE , SIRET ?? + +ALTER TABLE TVA_RATE ADD TVA_PEPPOL_CODE varchar(3); +comment on column tva_rate.Tva_peppol_code is 'Code for Peppol : S standard,Z zéro, AE Autoliquidation ,K autoliquidation intra, G : exempté TVA pour export'; + +drop VIEW public.v_tva_rate; + +CREATE OR REPLACE VIEW public.v_tva_rate +AS SELECT tva_id, + tva_rate, + tva_code, + tva_label, + tva_comment, + tva_reverse_account, + split_part(tva_poste, ','::text, 1) AS tva_purchase, + split_part(tva_poste, ','::text, 2) AS tva_sale, + tva_both_side, + tva_payment_purchase, + tva_payment_sale, + tva_peppol_code +FROM tva_rate; +