0002360: TVA : permet utilisation code TVA plutôt que nombre

This commit is contained in:
Dany wm 2024-06-15 18:12:35 +02:00 committed by sparkyx
parent aa8e3b0b2e
commit cdec0e8d7e
17 changed files with 182 additions and 72 deletions

View file

@ -575,6 +575,7 @@ EOF;
$r.='<div >';
$r.=_('Cherche')." ".HtmlInput::filter_table("tva_select_table",'0,1,2,3' , 1);
$r.= '<TABLE class="sortable" style="width:100%" id="tva_select_table">';
$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.='<tr'.$class. $script.' style="cursor : pointer">';
$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']);

View file

@ -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();

View file

@ -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) )

View file

@ -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);

View file

@ -167,13 +167,10 @@ 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'}) )
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'});
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
*/
@ -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.='<tr><td>Total HTVA</td>';
$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.='<tr><td> TVA ' . $oTva->get_parameter('label').'</td>';

View file

@ -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
*/
@ -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.='<tr><td>Total HTVA</td>';
$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.='<tr><td> TVA ' . $oTva->get_parameter('label').'</td>';

View file

@ -688,15 +688,19 @@ class Acc_Ledger_Search
}
// VAT Code
if ( isset($tva_id_search) && ! empty (trim($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($tva_id_search).
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($tva_id_search).")";
where qs_vat_code=".sql_string($acc_tva->tva_id ).")";
}
}
$where=$fil_ledger.$fil_amount.$fil_date.$fil_desc.$fil_sec.

View file

@ -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

View file

@ -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;

View file

@ -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);
}
}

View file

@ -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');

View file

@ -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;

View file

@ -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")],

View file

@ -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"
@ -57,6 +58,7 @@ class V_Tva_Rate_SQL extends Table_Data_SQL
*/
$this->type=array(
"tva_id"=>"numeric"
,'tva_code'=>'text'
, "tva_label"=>"text"
, "tva_rate"=>"numeric"
, "tva_comment"=>"text"

View file

@ -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');

View file

@ -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;
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;