diff --git a/html/ajax_misc.php b/html/ajax_misc.php index 22c4fb2c3..efdf3ab08 100644 --- a/html/ajax_misc.php +++ b/html/ajax_misc.php @@ -575,6 +575,7 @@ EOF; $r.='
'; $r.=_('Cherche')." ".HtmlInput::filter_table("tva_select_table",'0,1,2,3' , 1); $r.= ''; + $r.=th(_('id')); $r.=th(_('code')); $r.=th(_('Taux'),'class="sorttable_sorted_reverse"'); $r.=th(_('Symbole')); @@ -609,6 +610,7 @@ EOF; $class=($i%2 == 0)?' class="odd" ':' class="even" '; $r.=''; $r.=td($row['tva_id']); + $r.=td($row['tva_code']); $r.=td($row['tva_rate']); $r.=td($row['tva_label']); $r.=td($row['tva_comment']); diff --git a/html/compute.php b/html/compute.php index 01570b029..ccbadc33a 100644 --- a/html/compute.php +++ b/html/compute.php @@ -40,18 +40,19 @@ require_once NOALYSS_INCLUDE . '/class/noalyss_user.class.php'; require_once NOALYSS_INCLUDE.'/lib/ac_common.php'; MaintenanceMode("block.html"); -// Check if the needed field does exist -extract ($_GET, EXTR_SKIP ); -foreach (array('t','c','p','q','n','gDossier') as $a) -{ - if ( ! isset (${$a}) ) - { - echo "error $a is not set "; - exit(); - } -} $http=new HttpInput(); +// TVA id or TVA code +$t=$http->get("t"); +// string qcode card +$c=$http->get("c"); +// Price +$p=$http->get("p"); +// quantity +$q=$http->get("q"); +// row number (from 0) used to identify the row +$n=$http->get("n"); + $tax_ac_id=$http->request("other_tax_id","number",-1); // sometime number uses coma instead of dot for dec $p=noalyss_str_replace(",",".",$p); @@ -63,10 +64,10 @@ $User->Check(); $User->check_dossier(Dossier::id()); // Retrieve the rate of vat, it $t == -1 it means no VAT -if ( $t != -1 && isNumber($t) == 1 ) +if ( $t != -1 ) { - $tva_rate=new Acc_Tva($cn); - $tva_rate->set_parameter('id',$t); + $tva_rate=Acc_Tva::build($cn, $t); + /** *if the tva_rate->load failed we don't compute tva */ @@ -89,7 +90,7 @@ if ( $tax_ac_id !=-1) { $other_tax=new Acc_Other_Tax_SQL($cn,$tax_ac_id); $other_tax_amount=round(bcmul($amount,$other_tax->getp("ac_rate"),4)/100,2); } -if ( $t != -1 && isNumber($t) == 1 ) +if ( $t != -1 ) { $total->set_parameter('amount_vat_rate',$tva_rate->get_parameter('rate')); $total->compute_vat(); diff --git a/include/ajax/ajax_search_filter.php b/include/ajax/ajax_search_filter.php index e895707ad..9f8b55a37 100644 --- a/include/ajax/ajax_search_filter.php +++ b/include/ajax/ajax_search_filter.php @@ -61,7 +61,9 @@ if ($op=='save_filter') $new->setp("operation_filter", $http->post("operation_filter", 'string', NULL)); $new->setp("filter_name", h($http->post("filter_name", 'string'))); $new->setp("uf_currency_code", h($http->post("p_currency_code", 'number',-1))); - $new->setp("tva_id_search", h($http->post("tva_id_search", 'string',null))); + $acc_tva=Acc_Tva::build($cn, $http->post("tva_id_search", 'string',-1)); + $tva_id=($acc_tva->tva_id===-1)?null:$acc_tva->tva_id; + $new->setp("tva_id_search",$tva_id); $tag=$http->post("tag","string",''); if (is_array($tag) ) diff --git a/include/class/acc_compute.class.php b/include/class/acc_compute.class.php index d9c8e0df6..e6a390548 100644 --- a/include/class/acc_compute.class.php +++ b/include/class/acc_compute.class.php @@ -51,7 +51,7 @@ */ - +#[AllowDynamicProperties] class Acc_Compute { private static $variable=array( 'amount'=>'amount', @@ -78,6 +78,8 @@ class Acc_Compute var $check; // activate the check of the // order, valid value are // false or true + + function __construct () { bcscale(4); diff --git a/include/class/acc_ledger_purchase.class.php b/include/class/acc_ledger_purchase.class.php index cc1f2cdd6..06e2f3baa 100644 --- a/include/class/acc_ledger_purchase.class.php +++ b/include/class/acc_ledger_purchase.class.php @@ -167,21 +167,18 @@ class Acc_Ledger_Purchase extends Acc_Ledger // Check if the given tva id is valid if ( $g_parameter->MY_TVA_USE=='Y') { - if ( empty(${'e_march'.$i.'_tva_id'}) ) + $tva_rate = Acc_Tva::build($this->db,${'e_march' . $i . '_tva_id'}); + if ($tva_rate === null) 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'}); + $tva_rate->load(); + /* + * check if the accounting for VAT are valid + */ + $a_poste=explode(',',$tva_rate->tva_poste); - 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 ) - throw new Exception(_(" La TVA ".$tva_rate->tva_label." utilise des postes comptables inexistants")); + if ( + $this->db->get_value('select count(*) from tmp_pcmn where pcm_val=$1',array($a_poste[0])) == 0 ) + throw new Exception(_(" La TVA ".$tva_rate->tva_label." utilise des postes comptables inexistants")); } /* check if all card has a ATTR_DEF_ACCOUNT*/ @@ -571,8 +568,8 @@ class Acc_Ledger_Purchase extends Acc_Ledger { $idx_tva=trim(${'e_march'.$i.'_tva_id'}); \Noalyss\Dbg::echo_var(1," idx_tva [$idx_tva]",); - $oTva=new Acc_Tva($this->db); - $oTva->set_parameter('id',$idx_tva); + $oTva=Acc_Tva::build($this->db,$idx_tva); + $oTva->load(); $tva_both=$oTva->get_parameter("both_side"); } @@ -846,8 +843,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger */ foreach ($tva as $i => $value) { - $oTva=new Acc_Tva($this->db); - $oTva->set_parameter('id',$i); + $oTva=Acc_Tva::build($this->db,$i); $oTva->load(); $poste_vat=$oTva->get_side('d'); @@ -1675,8 +1671,8 @@ class Acc_Ledger_Purchase extends Acc_Ledger 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=Acc_Tva::build($this->db,$idx_tva); + $oTva->load(); $op=new Acc_Compute(); @@ -1878,7 +1874,7 @@ EOF; $r.=''; $r.=td(hb($tot_amount ),'class="num"'); foreach ($tva as $i => $value) { - $oTva->set_parameter('id', $i); + $oTva=Acc_Tva::build($this->db,$i); $oTva->load(); $r.=''; diff --git a/include/class/acc_ledger_sale.class.php b/include/class/acc_ledger_sale.class.php index c05dafb2a..369c782bb 100644 --- a/include/class/acc_ledger_sale.class.php +++ b/include/class/acc_ledger_sale.class.php @@ -45,7 +45,6 @@ class Acc_Ledger_Sale extends Acc_Ledger { * \return String * \throw Exception if an error occurs */ - public function verify_operation($p_array) { global $g_parameter, $g_user; @@ -156,13 +155,12 @@ class Acc_Ledger_Sale extends Acc_Ledger { // 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) + $tva_rate = Acc_Tva::build($this->db,${'e_march' . $i . '_tva_id'}); + $tva_rate->load(); + if ($tva_rate === null) throw new Exception(_('La fiche ') . ${'e_march' . $i} . _('a un code tva invalide') . ' [' . ${'e_march' . $i . '_tva_id'} . ']', 13); + $tva_rate->load(); /* * check if the accounting for VAT are valid */ @@ -171,7 +169,7 @@ class Acc_Ledger_Sale extends Acc_Ledger { if ( $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")); + 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 */ @@ -357,15 +355,16 @@ class Acc_Ledger_Sale extends Acc_Ledger { if ($g_parameter->MY_TVA_USE == 'Y') { /* Compute sum vat */ - $oTva = new Acc_Tva($this->db); - $idx_tva = trim(${'e_march' . $i . '_tva_id'}); - $tva_item_currency = ${'e_march' . $i . '_tva_amount'}; - $oTva->set_parameter("id", $idx_tva); + $oTva = Acc_Tva::build($this->db, trim(${'e_march' . $i . '_tva_id'})); $oTva->load(); + $idx_tva =$oTva->get_parameter("id"); + + $tva_item_currency = ${'e_march' . $i . '_tva_amount'}; + /* if empty then we need to compute it */ if (trim($tva_item_currency) == '' || ${'e_march'.$i.'_tva_amount'} == 0) { /* retrieve tva */ - $l = new Acc_Tva($this->db, $idx_tva); + $l = Acc_Tva::build($this->db, $idx_tva); $l->load(); $tva_item_currency = bcmul($amount, $l->get_parameter('rate')); $tva_item=round($tva_item_currency,2); @@ -434,7 +433,7 @@ class Acc_Ledger_Sale extends Acc_Ledger { ${'e_quant' . $i}, /* 4 */ round($amount, 2), /* 5 */ $tva_item, /* 6 */ - $idx_tva, /* 7 */ + $oTva->get_parameter("id"), /* 7 */ $e_client, /* 8 */ $n_both, /* 9 */ $price_euro/* Price /unit */ @@ -548,8 +547,8 @@ class Acc_Ledger_Sale extends Acc_Ledger { var_dump($tva); } foreach ($tva as $i => $value) { - $oTva = new Acc_Tva($this->db); - $oTva->set_parameter('id', $i); + $oTva = Acc_Tva::build($this->db,$i); + $oTva->load(); $poste_vat = $oTva->get_side('c'); @@ -948,10 +947,8 @@ class Acc_Ledger_Sale extends Acc_Ledger { 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 = Acc_Tva::build($this->db,$idx_tva); $oTva->load(); } $op = new Acc_Compute(); @@ -1144,7 +1141,7 @@ EOF; $r.=''; $r.=td(hb($tot_amount ),'class="num"'); foreach ($tva as $i => $value) { - $oTva->set_parameter('id', $i); + $oTva=Acc_Tva::build($this->cn, $i); $oTva->load(); $r.=''; diff --git a/include/class/acc_ledger_search.class.php b/include/class/acc_ledger_search.class.php index c1c22fd17..d94dd2a37 100644 --- a/include/class/acc_ledger_search.class.php +++ b/include/class/acc_ledger_search.class.php @@ -689,14 +689,18 @@ class Acc_Ledger_Search // VAT Code if ( isset($tva_id_search) && ! empty (trim($tva_id_search??""))) { - $fil_vat = $and." jr_internal in - ( select distinct qp_internal - from quant_purchase - where qp_vat_code=".sql_string($tva_id_search). - " union all - select distinct qs_internal - from quant_sold - where qs_vat_code=".sql_string($tva_id_search).")"; + $acc_tva=Acc_Tva::build($this->cn, $tva_id_search); + if ($acc_tva->tva_id != -1 ) + { + $fil_vat = $and." jr_internal in + ( select distinct qp_internal + from quant_purchase + where qp_vat_code=".sql_string($acc_tva->tva_id ). + " union all + select distinct qs_internal + from quant_sold + where qs_vat_code=".sql_string($acc_tva->tva_id ).")"; + } } $where=$fil_ledger.$fil_amount.$fil_date.$fil_desc.$fil_sec. diff --git a/include/class/acc_operation.class.php b/include/class/acc_operation.class.php index e63da2903..bc236d354 100644 --- a/include/class/acc_operation.class.php +++ b/include/class/acc_operation.class.php @@ -53,6 +53,13 @@ class Acc_Operation //!< internal code from jrn var $jr_internal; var $signature; + var $desc; + var $type; + var $jrnx_id; + var $echeance; + var $pj; + var $mt; + var $f_id; /*! * \brief constructor set automatically the attributes user and periode * \param $p_cn the databse connection diff --git a/include/class/acc_payment.class.php b/include/class/acc_payment.class.php index d73f17bc7..8b3fa5420 100644 --- a/include/class/acc_payment.class.php +++ b/include/class/acc_payment.class.php @@ -33,9 +33,10 @@ require_once NOALYSS_INCLUDE.'/constant.php'; - mp_qcode ==> qcode (quick_code of the card) * */ + +#[AllowDynamicProperties] class Acc_Payment { - private static $variable=array("id"=>"mp_id", "lib"=>"mp_lib", "qcode"=>"mp_qcode", @@ -43,13 +44,13 @@ class Acc_Payment "ledger_source"=>"jrn_def_id", "fiche_def"=>"mp_fd_id"); - + private $mp_id; private $mp_lib; private $mp_qcode; private $mp_jrn_def_if; private $jrn_def_id; private $mp_fd_id; - + private $cn; //!< Database connection function __construct ($p_cn,$p_init=0) { $this->cn=$p_cn; diff --git a/include/class/acc_tva.class.php b/include/class/acc_tva.class.php index 144ce1e85..6868788cf 100644 --- a/include/class/acc_tva.class.php +++ b/include/class/acc_tva.class.php @@ -47,6 +47,7 @@ class Acc_Tva $tva_comment, $tva_poste, $tva_both_side; + private $cn; //!< Database connection private Tva_Rate_SQL $tva_rate_sql; @@ -135,4 +136,25 @@ class Acc_Tva throw (new Exception (__FILE__.':'.__LINE__." param est d ou c, on a recu [ $p_side ]")); } } + + /** + * @brief retrieve TVA rate thanks the code that could be the tva_id or tva_code + * @param $db Database connection + * @param $p_code either tva_id or tva_code + * @return Acc_Tva or null + */ + static function build($db,$p_code):Acc_Tva { + if (empty($p_code)) return new Acc_Tva($db,-1); + $tva_id = $db->get_value("select tva_id from public.tva_rate where tva_code=upper(trim($1))",[$p_code]); + if ( $db->size() == 1) { + return new Acc_Tva($db,$tva_id); + } + + $exist = $db->get_value("select count(*) from public.tva_rate where tva_id=$1",[$p_code]); + if ( $db->size() == 1) { + return new Acc_Tva($db,$p_code); + } + new Acc_Tva($db,-1); + + } } diff --git a/include/class/document.class.php b/include/class/document.class.php index 82b0b8055..072788674 100644 --- a/include/class/document.class.php +++ b/include/class/document.class.php @@ -37,8 +37,9 @@ class Document var $d_description; /*!< Description of the file */ var $d_number; /*!< $d_number number of the document */ var $md_id; /*!< $md_id document's template */ + var $f_id; /*!< fiche.f_id */ private $counter; /*!< counter for the items ( goods ) */ - + var $d_name; /*!< document name */ /*! * @brief Constructor * \param $p_cn Database connection @@ -1152,7 +1153,7 @@ class Document return ''; if ($p_array[$march_id]==0) return ''; - $tva=new Acc_Tva($this->db, $p_array[$id]); + $tva= Acc_Tva::build($this->db, $p_array[$id]); if ($tva->load()==-1) return ""; $r=$tva->get_parameter('label'); diff --git a/include/class/pre_operation.class.php b/include/class/pre_operation.class.php index 710977027..366b9790c 100644 --- a/include/class/pre_operation.class.php +++ b/include/class/pre_operation.class.php @@ -27,6 +27,7 @@ * and op_def_detail * */ +#[AllowDynamicProperties] class Pre_operation { private $db; /*!< $db database connection */ @@ -516,12 +517,17 @@ class Pre_operation } } -/*!\brief mother of the pre_op_XXX, it contains only one data : an +/*! +@class +@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 + * */ +#[AllowDynamicProperties] class Pre_operation_detail { + protected $db; function __construct($p_cn) { $this->db=$p_cn; diff --git a/include/class/tva_rate_mtable.class.php b/include/class/tva_rate_mtable.class.php index 0eb277a8f..bb4c40917 100644 --- a/include/class/tva_rate_mtable.class.php +++ b/include/class/tva_rate_mtable.class.php @@ -47,12 +47,15 @@ class Tva_Rate_MTable extends Manage_Table_SQL { parent::__construct($p_table); $this->set_col_label("tva_id", _("id")); + $this->set_col_label("tva_code", _("Code")); $this->set_col_label("tva_label", _("label")); $this->set_col_label("tva_rate", _("taux")); $this->set_col_label("tva_comment", _("Description")); $this->set_col_label("tva_both_side", _("Autoliquidation")); $this->set_col_label("tva_sale", _("TVA Vente (C)")); $this->set_col_label("tva_purchase", _("TVA Achat (D)")); + + $this->set_col_type("tva_both_side", "select", array( ["value"=>0, "label"=>_("Non")], diff --git a/include/database/v_tva_rate_sql.class.php b/include/database/v_tva_rate_sql.class.php index b8df366b9..f336b6433 100644 --- a/include/database/v_tva_rate_sql.class.php +++ b/include/database/v_tva_rate_sql.class.php @@ -42,6 +42,7 @@ class V_Tva_Rate_SQL extends Table_Data_SQL */ $this->name=array( "tva_id"=>"tva_id" + ,'tva_code'=>"tva_code" , "tva_label"=>"tva_label" , "tva_rate"=>"tva_rate" , "tva_comment"=>"tva_comment" @@ -50,13 +51,14 @@ class V_Tva_Rate_SQL extends Table_Data_SQL , "tva_both_side"=>"tva_both_side" ,'tva_payment_purchase'=>'tva_payment_purchase' ,'tva_payment_sale'=>'tva_payment_sale' - + ); /* * Type of columns */ $this->type=array( "tva_id"=>"numeric" + ,'tva_code'=>'text' , "tva_label"=>"text" , "tva_rate"=>"numeric" , "tva_comment"=>"text" diff --git a/include/history_operation.inc.php b/include/history_operation.inc.php index a983cd50a..1ba4d6769 100644 --- a/include/history_operation.inc.php +++ b/include/history_operation.inc.php @@ -24,7 +24,7 @@ * \file * * - * \brief + * \brief display history of accountant , and let search into * */ if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis'); diff --git a/sql/upgrade.sql b/sql/upgrade.sql index 1c160ec67..b2a93704b 100644 --- a/sql/upgrade.sql +++ b/sql/upgrade.sql @@ -1,2 +1,66 @@ with correct_periode as (select jr_tech_per, jr_grpt_id from jrn) -update jrnx set j_tech_per = jr_tech_per from correct_periode where correct_periode.jr_grpt_id=j_grpt and correct_periode.jr_tech_per != j_tech_per; \ No newline at end of file +update jrnx set j_tech_per = jr_tech_per from correct_periode where correct_periode.jr_grpt_id=j_grpt and correct_periode.jr_tech_per != j_tech_per; + + + +ALTER TABLE public.tva_rate ADD tva_code text ; +ALTER TABLE public.tva_rate ADD CONSTRAINT tva_code_unique UNIQUE (tva_code); +update tva_rate set tva_code=tva_id::text||'-'||(tva_rate*100)::text; + +alter table public.tva_rate alter tva_code set not null; + +drop VIEW public.v_tva_rate; + +CREATE OR REPLACE VIEW public.v_tva_rate +AS SELECT tva_rate.tva_id, + tva_rate.tva_rate, + tva_rate.tva_code, + tva_rate.tva_label, + tva_rate.tva_comment, + split_part(tva_rate.tva_poste, ','::text, 1) AS tva_purchase, + split_part(tva_rate.tva_poste, ','::text, 2) AS tva_sale, + tva_rate.tva_both_side, + tva_rate.tva_payment_purchase, + tva_rate.tva_payment_sale + FROM tva_rate; + +-- update tva_rate set tva_code=(round(tva_rate*100))::text||'-'||tva_id::text; + + +CREATE OR REPLACE FUNCTION update_tva_code () + returns int4 +AS +$BODY$ +declare +/* + * Section for variables + */ + counter int:=0; + letter int; + x record; + e record; + str_tva_code text; +begin + -- basic loop + for x in select distinct tva_rate from public.tva_rate order by tva_rate + loop + letter :=65; + for e in select * from public.tva_rate where tva_rate = x.tva_rate loop + str_tva_code := round(e.tva_rate*100)::text||chr(letter); + -- raise notice 'rate % letter % => tva_code %',e.tva_rate,chr(letter),str_tva_code ; + update tva_rate set tva_code=str_tva_code where tva_id=e.tva_id; + letter := letter+1; + counter := counter+1; + end loop; + + end loop; + return counter; +end; +$BODY$ +LANGUAGE plpgsql; + +select update_tva_code(); + +drop function update_tva_code(); + +ALTER TABLE public.op_predef_detail ALTER COLUMN opd_tva_id TYPE text USING opd_tva_id::text; diff --git a/unit-test/test-file.sh b/unit-test/test-file.sh-example similarity index 100% rename from unit-test/test-file.sh rename to unit-test/test-file.sh-example
Total HTVA
TVA ' . $oTva->get_parameter('label').'
Total HTVA
TVA ' . $oTva->get_parameter('label').'